@app-vitals/agent-admin 1.84.2 → 1.85.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/openapi.platform.json +71 -0
- package/package.json +2 -2
- package/src/admin-ui-installation-repos-pages.ts +75 -9
- package/src/admin-ui-installation-repos-pages.unit.test.ts +180 -0
- package/src/admin-ui-installation-repos.smoke.test.ts +24 -0
- package/src/agents-api.smoke.test.ts +39 -0
- package/src/agents-api.ts +31 -1
- package/src/github-installation-wiring.ts +2 -0
- package/src/github-installation-wiring.unit.test.ts +1 -1
- package/src/github-repo-cache.ts +2 -0
- package/src/github-sync-cache.integration.test.ts +1 -1
- package/src/github-sync-cached-access.ts +53 -1
- package/src/github-sync-cached-access.unit.test.ts +114 -0
- package/src/github-sync.ts +30 -4
- package/src/github-sync.unit.test.ts +195 -0
- package/src/repo-access-rules.ts +3 -0
- package/src/user-repo-access-resolver.ts +27 -0
package/openapi.platform.json
CHANGED
|
@@ -3702,6 +3702,9 @@
|
|
|
3702
3702
|
},
|
|
3703
3703
|
"reason": {
|
|
3704
3704
|
"type": "string"
|
|
3705
|
+
},
|
|
3706
|
+
"detail": {
|
|
3707
|
+
"$ref": "#/components/schemas/GithubSyncOrgSkipDetail"
|
|
3705
3708
|
}
|
|
3706
3709
|
},
|
|
3707
3710
|
"required": [
|
|
@@ -3744,6 +3747,71 @@
|
|
|
3744
3747
|
"status"
|
|
3745
3748
|
]
|
|
3746
3749
|
},
|
|
3750
|
+
"GithubSyncOrgSkipDetail": {
|
|
3751
|
+
"type": "object",
|
|
3752
|
+
"properties": {
|
|
3753
|
+
"lookupSnapshotFound": {
|
|
3754
|
+
"type": "boolean"
|
|
3755
|
+
},
|
|
3756
|
+
"crawls": {
|
|
3757
|
+
"type": "array",
|
|
3758
|
+
"items": {
|
|
3759
|
+
"type": "object",
|
|
3760
|
+
"properties": {
|
|
3761
|
+
"completedAt": {
|
|
3762
|
+
"type": [
|
|
3763
|
+
"string",
|
|
3764
|
+
"null"
|
|
3765
|
+
]
|
|
3766
|
+
},
|
|
3767
|
+
"lastError": {
|
|
3768
|
+
"type": [
|
|
3769
|
+
"string",
|
|
3770
|
+
"null"
|
|
3771
|
+
]
|
|
3772
|
+
},
|
|
3773
|
+
"rateLimitResetAt": {
|
|
3774
|
+
"type": [
|
|
3775
|
+
"string",
|
|
3776
|
+
"null"
|
|
3777
|
+
]
|
|
3778
|
+
}
|
|
3779
|
+
},
|
|
3780
|
+
"required": [
|
|
3781
|
+
"completedAt"
|
|
3782
|
+
]
|
|
3783
|
+
}
|
|
3784
|
+
},
|
|
3785
|
+
"totalRepos": {
|
|
3786
|
+
"type": "integer"
|
|
3787
|
+
},
|
|
3788
|
+
"reposWithOkAccess": {
|
|
3789
|
+
"type": "integer"
|
|
3790
|
+
},
|
|
3791
|
+
"reposMissingAnswer": {
|
|
3792
|
+
"type": "integer"
|
|
3793
|
+
},
|
|
3794
|
+
"errorRows": {
|
|
3795
|
+
"type": "integer"
|
|
3796
|
+
},
|
|
3797
|
+
"terminalRows": {
|
|
3798
|
+
"type": "integer"
|
|
3799
|
+
},
|
|
3800
|
+
"maxAttempts": {
|
|
3801
|
+
"type": "integer"
|
|
3802
|
+
},
|
|
3803
|
+
"rowErrors": {
|
|
3804
|
+
"type": "array",
|
|
3805
|
+
"items": {
|
|
3806
|
+
"type": "string"
|
|
3807
|
+
}
|
|
3808
|
+
},
|
|
3809
|
+
"oldestCheckedAt": {
|
|
3810
|
+
"type": "string"
|
|
3811
|
+
}
|
|
3812
|
+
},
|
|
3813
|
+
"description": "Why the org was skipped, for cached data: whether the lookup snapshot was found, each crawl's completedAt/lastError/rateLimitResetAt, repo and access-row counts, and the oldest-checked time when stale."
|
|
3814
|
+
},
|
|
3747
3815
|
"GithubSyncApplyResult": {
|
|
3748
3816
|
"type": "object",
|
|
3749
3817
|
"properties": {
|
|
@@ -3808,6 +3876,9 @@
|
|
|
3808
3876
|
},
|
|
3809
3877
|
"reason": {
|
|
3810
3878
|
"type": "string"
|
|
3879
|
+
},
|
|
3880
|
+
"detail": {
|
|
3881
|
+
"$ref": "#/components/schemas/GithubSyncOrgSkipDetail"
|
|
3811
3882
|
}
|
|
3812
3883
|
},
|
|
3813
3884
|
"required": [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@app-vitals/agent-admin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.85.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/app-vitals/agent.git",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@anthropic-ai/sdk": "0.137.0",
|
|
47
|
-
"@app-vitals/agent-lib": "1.
|
|
47
|
+
"@app-vitals/agent-lib": "1.85.0",
|
|
48
48
|
"@hono/zod-openapi": "^1.0.0",
|
|
49
49
|
"@prisma/adapter-pg": "^7.10.0",
|
|
50
50
|
"@prisma/client": "^7.10.0",
|
|
@@ -11,12 +11,15 @@
|
|
|
11
11
|
* dynamic value is escaped. Inputs carry repo names and ids only.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
+
import type { components } from "@app-vitals/agent-lib/admin-types";
|
|
14
15
|
import { escapeHtml } from "./admin-ui-styles.ts";
|
|
15
16
|
import {
|
|
16
17
|
MAX_UNCONFIRMED_REMOVALS,
|
|
17
18
|
MISSING_APP_ID_REASON,
|
|
18
19
|
} from "./installation-ports.ts";
|
|
19
20
|
|
|
21
|
+
type SkipDetail = components["schemas"]["GithubSyncOrgSkipDetail"];
|
|
22
|
+
|
|
20
23
|
export interface OpenWorkView {
|
|
21
24
|
id: string;
|
|
22
25
|
repo: string;
|
|
@@ -177,7 +180,7 @@ export interface GithubSyncPreviewView {
|
|
|
177
180
|
appAdds?: string[];
|
|
178
181
|
appRemoves?: string[];
|
|
179
182
|
agentRemoves?: string[];
|
|
180
|
-
skippedOrgs?: { org: string; reason: string }[];
|
|
183
|
+
skippedOrgs?: { org: string; reason: string; detail?: SkipDetail }[];
|
|
181
184
|
openWork?: OpenWorkView[];
|
|
182
185
|
warnings?: string[];
|
|
183
186
|
}
|
|
@@ -190,7 +193,7 @@ export interface GithubSyncApplyView {
|
|
|
190
193
|
appRemoves?: string[];
|
|
191
194
|
agentRemoves?: string[];
|
|
192
195
|
notApplied?: { repo: string; reason: string }[];
|
|
193
|
-
skippedOrgs?: { org: string; reason: string }[];
|
|
196
|
+
skippedOrgs?: { org: string; reason: string; detail?: SkipDetail }[];
|
|
194
197
|
warnings?: string[];
|
|
195
198
|
}
|
|
196
199
|
|
|
@@ -415,12 +418,68 @@ const repoList = (kind: string, title: string, repos: readonly string[]) =>
|
|
|
415
418
|
? ""
|
|
416
419
|
: `<div data-list="${kind}" style="margin-top:8px"><div style="font-weight:600">${escapeHtml(title)} (${repos.length})</div><ul style="margin:4px 0 0 18px">${repos.map((r) => `<li class="mono">${escapeHtml(r)}</li>`).join("")}</ul></div>`;
|
|
417
420
|
|
|
418
|
-
const
|
|
421
|
+
const plural = (n: number, one: string, many: string) =>
|
|
422
|
+
`${n} ${n === 1 ? one : many}`;
|
|
423
|
+
|
|
424
|
+
/** One readable sentence-list describing why an org's cached access was skipped. */
|
|
425
|
+
function skipDetailText(d: SkipDetail): string {
|
|
426
|
+
const out: string[] = [];
|
|
427
|
+
const crawls = d.crawls ?? [];
|
|
428
|
+
const failed = crawls.filter((c) => c.lastError);
|
|
429
|
+
if (d.lookupSnapshotFound === false) {
|
|
430
|
+
out.push("Lookup crawl not found for this App");
|
|
431
|
+
} else if (failed.length > 0) {
|
|
432
|
+
for (const c of failed) {
|
|
433
|
+
out.push(
|
|
434
|
+
`Lookup crawl failed: ${c.lastError}${c.rateLimitResetAt ? `; next attempt ${c.rateLimitResetAt}` : ""}`,
|
|
435
|
+
);
|
|
436
|
+
}
|
|
437
|
+
} else if (crawls.some((c) => c.completedAt === null)) {
|
|
438
|
+
out.push("Lookup crawl not complete yet");
|
|
439
|
+
} else if (crawls.length > 0) {
|
|
440
|
+
out.push(
|
|
441
|
+
`Lookup crawl complete${d.totalRepos === undefined ? "" : ` (${plural(d.totalRepos, "repo", "repos")})`}`,
|
|
442
|
+
);
|
|
443
|
+
}
|
|
444
|
+
if (d.reposMissingAnswer) {
|
|
445
|
+
out.push(
|
|
446
|
+
`${plural(d.reposMissingAnswer, "repo has", "repos have")} no access answer yet`,
|
|
447
|
+
);
|
|
448
|
+
}
|
|
449
|
+
if (d.errorRows) out.push(`${plural(d.errorRows, "repo", "repos")} errored`);
|
|
450
|
+
if (d.terminalRows) {
|
|
451
|
+
out.push(
|
|
452
|
+
`${plural(d.terminalRows, "repo", "repos")} gave up${d.maxAttempts ? ` (max ${d.maxAttempts} attempts)` : ""}`,
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
if (d.rowErrors?.length) out.push(`Row errors: ${d.rowErrors.join("; ")}`);
|
|
456
|
+
if (d.oldestCheckedAt) out.push(`Oldest check ${d.oldestCheckedAt}`);
|
|
457
|
+
return out
|
|
458
|
+
.map((x) => `${x}.`)
|
|
459
|
+
.join(" ")
|
|
460
|
+
.replace(/\.\.$/, ".");
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
/** Drop the `<org>: skipped (<reason>)` warnings the skippedOrgs block already shows. */
|
|
464
|
+
const withoutSkipWarnings = (
|
|
465
|
+
warnings: readonly string[] | undefined,
|
|
419
466
|
skipped: readonly { org: string; reason: string }[],
|
|
467
|
+
): string[] =>
|
|
468
|
+
(warnings ?? []).filter(
|
|
469
|
+
(w) => !skipped.some((s) => w === `${s.org}: skipped (${s.reason})`),
|
|
470
|
+
);
|
|
471
|
+
|
|
472
|
+
const skippedOrgsHtml = (
|
|
473
|
+
skipped: readonly { org: string; reason: string; detail?: SkipDetail }[],
|
|
420
474
|
) =>
|
|
421
475
|
skipped.length === 0
|
|
422
476
|
? ""
|
|
423
|
-
: `<div class="alert alert-warning" data-skipped-orgs="1"><div style="font-weight:600">Skipped orgs (nothing added or removed there)</div>${skipped
|
|
477
|
+
: `<div class="alert alert-warning" data-skipped-orgs="1"><div style="font-weight:600">Skipped orgs (nothing added or removed there)</div>${skipped
|
|
478
|
+
.map((s) => {
|
|
479
|
+
const text = s.detail ? skipDetailText(s.detail) : "";
|
|
480
|
+
return `<div><span class="mono">${escapeHtml(s.org)}</span>: ${escapeHtml(s.reason)}${text ? `<div class="muted" data-skip-detail="1" style="font-size:0.9em">${escapeHtml(text)}</div>` : ""}</div>`;
|
|
481
|
+
})
|
|
482
|
+
.join("")}</div>`;
|
|
424
483
|
|
|
425
484
|
/**
|
|
426
485
|
* The single confirm step of Sync: the installation adds, installation
|
|
@@ -438,10 +497,16 @@ export function renderSyncConfirm(
|
|
|
438
497
|
const appAdds = preview.appAdds ?? [];
|
|
439
498
|
const appRemoves = preview.appRemoves ?? [];
|
|
440
499
|
const agentRemoves = preview.agentRemoves ?? [];
|
|
441
|
-
const
|
|
442
|
-
const
|
|
500
|
+
const skippedList = preview.skippedOrgs ?? [];
|
|
501
|
+
const skipped = skippedOrgsHtml(skippedList);
|
|
502
|
+
const warnings = warningsHtml(
|
|
503
|
+
withoutSkipWarnings(preview.warnings, skippedList),
|
|
504
|
+
);
|
|
443
505
|
if (appAdds.length + appRemoves.length + agentRemoves.length === 0) {
|
|
444
|
-
|
|
506
|
+
if (skippedList.length > 0) {
|
|
507
|
+
return `<div class="alert alert-warning" data-sync="nothing-synced">Nothing was synced: ${skippedList.length} org(s) skipped, see below.</div>${skipped}${warnings}`;
|
|
508
|
+
}
|
|
509
|
+
return `<div class="alert alert-success" data-sync="in-sync">Already in sync: nothing to add or remove.</div>${warnings}`;
|
|
445
510
|
}
|
|
446
511
|
const removals = new Set([...appRemoves, ...agentRemoves].map(lc)).size;
|
|
447
512
|
const overCap = removals > MAX_UNCONFIRMED_REMOVALS;
|
|
@@ -468,7 +533,8 @@ export function renderSyncResult(
|
|
|
468
533
|
return `<div class="alert alert-warning" data-sync="skipped">Sync was skipped: ${escapeHtml(result.reason ?? "unknown reason")}</div>`;
|
|
469
534
|
}
|
|
470
535
|
if (result.status === "noop") {
|
|
471
|
-
|
|
536
|
+
const skippedList = result.skippedOrgs ?? [];
|
|
537
|
+
return `<div class="alert alert-success" data-sync="noop">Nothing was changed.</div>${skippedOrgsHtml(skippedList)}${warningsHtml(withoutSkipWarnings(result.warnings, skippedList))}`;
|
|
472
538
|
}
|
|
473
539
|
const notApplied = result.notApplied ?? [];
|
|
474
540
|
return `<div class="alert alert-success" data-sync="applied">Sync applied. Reload the page to refresh the lists.</div>${repoList("app-adds", "Added to the agent App installation", result.appAdds ?? [])}${repoList("app-removes", "Removed from the agent App installation", result.appRemoves ?? [])}${repoList("agent-removes", "Removed from the agent's repos", result.agentRemoves ?? [])}${
|
|
@@ -479,5 +545,5 @@ export function renderSyncResult(
|
|
|
479
545
|
blocked,
|
|
480
546
|
"Open tasks and PRs that were blocked",
|
|
481
547
|
"No open tasks or PRs were blocked.",
|
|
482
|
-
)}${warningsHtml(result.warnings)}`;
|
|
548
|
+
)}${warningsHtml(withoutSkipWarnings(result.warnings, result.skippedOrgs ?? []))}`;
|
|
483
549
|
}
|
|
@@ -256,6 +256,186 @@ describe("renderSyncResult", () => {
|
|
|
256
256
|
});
|
|
257
257
|
});
|
|
258
258
|
|
|
259
|
+
describe("skipped orgs and the in-sync state", () => {
|
|
260
|
+
const skipped = [{ org: "zed", reason: "access listing is incomplete" }];
|
|
261
|
+
const dupe = "zed: skipped (access listing is incomplete)";
|
|
262
|
+
|
|
263
|
+
it("warns, not in-sync, when every org was skipped and nothing changes", () => {
|
|
264
|
+
const html = renderSyncConfirm("a1", {
|
|
265
|
+
status: "previewed",
|
|
266
|
+
appAdds: [],
|
|
267
|
+
appRemoves: [],
|
|
268
|
+
agentRemoves: [],
|
|
269
|
+
skippedOrgs: skipped,
|
|
270
|
+
warnings: [dupe],
|
|
271
|
+
});
|
|
272
|
+
expect(html).toContain('data-sync="nothing-synced"');
|
|
273
|
+
expect(html).toContain("Nothing was synced: 1 org(s) skipped, see below");
|
|
274
|
+
expect(html).not.toContain('data-sync="in-sync"');
|
|
275
|
+
expect(html).not.toContain("Already in sync");
|
|
276
|
+
expect(html).toContain('data-skipped-orgs="1"');
|
|
277
|
+
expect(html).not.toContain("github-sync-confirm-btn");
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
it("still confirms changes when some orgs were skipped", () => {
|
|
281
|
+
const html = renderSyncConfirm("a1", {
|
|
282
|
+
status: "previewed",
|
|
283
|
+
appAdds: ["acme/new"],
|
|
284
|
+
skippedOrgs: skipped,
|
|
285
|
+
warnings: [dupe],
|
|
286
|
+
});
|
|
287
|
+
expect(html).toContain('data-sync="confirm"');
|
|
288
|
+
expect(html).toContain('data-skipped-orgs="1"');
|
|
289
|
+
expect(html).not.toContain('data-sync="nothing-synced"');
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
it("keeps the green in-sync state when no org was skipped", () => {
|
|
293
|
+
const html = renderSyncConfirm("a1", {
|
|
294
|
+
status: "previewed",
|
|
295
|
+
appAdds: [],
|
|
296
|
+
appRemoves: [],
|
|
297
|
+
agentRemoves: [],
|
|
298
|
+
skippedOrgs: [],
|
|
299
|
+
});
|
|
300
|
+
expect(html).toContain('data-sync="in-sync"');
|
|
301
|
+
expect(html).not.toContain("nothing-synced");
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
it("reports a skipped org once in the preview, keeping other warnings", () => {
|
|
305
|
+
const html = renderSyncConfirm("a1", {
|
|
306
|
+
status: "previewed",
|
|
307
|
+
appAdds: ["acme/new"],
|
|
308
|
+
skippedOrgs: skipped,
|
|
309
|
+
warnings: [dupe, "other warning"],
|
|
310
|
+
});
|
|
311
|
+
expect(html).not.toContain(dupe);
|
|
312
|
+
expect(html).toContain("other warning");
|
|
313
|
+
expect(html.match(/zed/g)).toHaveLength(1);
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
it("reports a skipped org once in the apply result, keeping other warnings", () => {
|
|
317
|
+
const html = renderSyncResult(
|
|
318
|
+
{
|
|
319
|
+
status: "applied",
|
|
320
|
+
skippedOrgs: skipped,
|
|
321
|
+
warnings: [dupe, "other warning"],
|
|
322
|
+
},
|
|
323
|
+
[],
|
|
324
|
+
);
|
|
325
|
+
expect(html).not.toContain(dupe);
|
|
326
|
+
expect(html).toContain("other warning");
|
|
327
|
+
expect(html).toContain('data-skipped-orgs="1"');
|
|
328
|
+
});
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
describe("skipped-org detail", () => {
|
|
332
|
+
const render = (detail?: Record<string, unknown>, org = "zed") =>
|
|
333
|
+
renderSyncConfirm("a1", {
|
|
334
|
+
status: "previewed",
|
|
335
|
+
appAdds: ["acme/new"],
|
|
336
|
+
skippedOrgs: [{ org, reason: "access listing is incomplete", detail }],
|
|
337
|
+
} as never);
|
|
338
|
+
const line = (html: string) =>
|
|
339
|
+
/data-skip-detail="1"[^>]*>([^<]*)</.exec(html)?.[1] ?? "";
|
|
340
|
+
|
|
341
|
+
it("renders exactly as before without detail", () => {
|
|
342
|
+
const html = render(undefined);
|
|
343
|
+
expect(html).toContain(
|
|
344
|
+
'<div><span class="mono">zed</span>: access listing is incomplete</div>',
|
|
345
|
+
);
|
|
346
|
+
expect(html).not.toContain("data-skip-detail");
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
it("renders a complete crawl with repos missing an answer", () => {
|
|
350
|
+
const html = render({
|
|
351
|
+
lookupSnapshotFound: true,
|
|
352
|
+
crawls: [{ completedAt: "2026-01-01T00:00:00.000Z" }],
|
|
353
|
+
totalRepos: 31,
|
|
354
|
+
reposWithOkAccess: 1,
|
|
355
|
+
reposMissingAnswer: 30,
|
|
356
|
+
});
|
|
357
|
+
expect(line(html)).toBe(
|
|
358
|
+
"Lookup crawl complete (31 repos). 30 repos have no access answer yet.",
|
|
359
|
+
);
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
it("renders a missing lookup snapshot", () => {
|
|
363
|
+
const html = render({ lookupSnapshotFound: false, crawls: [] });
|
|
364
|
+
expect(line(html)).toBe("Lookup crawl not found for this App.");
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
it("renders a failed crawl with the next attempt", () => {
|
|
368
|
+
const html = render({
|
|
369
|
+
lookupSnapshotFound: true,
|
|
370
|
+
crawls: [
|
|
371
|
+
{
|
|
372
|
+
completedAt: null,
|
|
373
|
+
lastError: "rate limited",
|
|
374
|
+
rateLimitResetAt: "2026-01-01T01:00:00.000Z",
|
|
375
|
+
},
|
|
376
|
+
],
|
|
377
|
+
});
|
|
378
|
+
expect(line(html)).toBe(
|
|
379
|
+
"Lookup crawl failed: rate limited; next attempt 2026-01-01T01:00:00.000Z.",
|
|
380
|
+
);
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
it("renders an incomplete crawl without an error", () => {
|
|
384
|
+
const html = render({ crawls: [{ completedAt: null }] });
|
|
385
|
+
expect(line(html)).toBe("Lookup crawl not complete yet.");
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
it("renders error rows, terminal rows, row errors and oldest check", () => {
|
|
389
|
+
const html = render({
|
|
390
|
+
lookupSnapshotFound: true,
|
|
391
|
+
crawls: [{ completedAt: "2026-01-01T00:00:00.000Z" }],
|
|
392
|
+
totalRepos: 5,
|
|
393
|
+
reposWithOkAccess: 2,
|
|
394
|
+
reposMissingAnswer: 3,
|
|
395
|
+
errorRows: 2,
|
|
396
|
+
terminalRows: 1,
|
|
397
|
+
maxAttempts: 4,
|
|
398
|
+
rowErrors: ["boom", "bang"],
|
|
399
|
+
oldestCheckedAt: "2025-12-01T00:00:00.000Z",
|
|
400
|
+
});
|
|
401
|
+
const t = line(html);
|
|
402
|
+
expect(t).toContain("Lookup crawl complete (5 repos).");
|
|
403
|
+
expect(t).toContain("3 repos have no access answer yet.");
|
|
404
|
+
expect(t).toContain("2 repos errored.");
|
|
405
|
+
expect(t).toContain("1 repo gave up (max 4 attempts).");
|
|
406
|
+
expect(t).toContain("Row errors: boom; bang.");
|
|
407
|
+
expect(t).toContain("Oldest check 2025-12-01T00:00:00.000Z.");
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
it("escapes lastError, rowErrors and org", () => {
|
|
411
|
+
const html = render(
|
|
412
|
+
{
|
|
413
|
+
crawls: [{ completedAt: null, lastError: "<script>x</script>" }],
|
|
414
|
+
rowErrors: ["<img onerror=1>"],
|
|
415
|
+
},
|
|
416
|
+
"<b>o</b>",
|
|
417
|
+
);
|
|
418
|
+
expect(html).not.toContain("<script>x");
|
|
419
|
+
expect(html).not.toContain("<img onerror");
|
|
420
|
+
expect(html).not.toContain("<b>o</b>");
|
|
421
|
+
expect(html).toContain("<script>x");
|
|
422
|
+
expect(html).toContain("<img onerror=1>");
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
it("renders in the apply result too", () => {
|
|
426
|
+
const html = renderSyncResult(
|
|
427
|
+
{
|
|
428
|
+
status: "applied",
|
|
429
|
+
skippedOrgs: [
|
|
430
|
+
{ org: "zed", reason: "r", detail: { lookupSnapshotFound: false } },
|
|
431
|
+
],
|
|
432
|
+
},
|
|
433
|
+
[],
|
|
434
|
+
);
|
|
435
|
+
expect(line(html)).toBe("Lookup crawl not found for this App.");
|
|
436
|
+
});
|
|
437
|
+
});
|
|
438
|
+
|
|
259
439
|
describe("renderInstallationSyncStatus debug detail", () => {
|
|
260
440
|
it("shows attempts, next attempt, lease holder and last tick on a failed snapshot, as an error", () => {
|
|
261
441
|
const html = renderInstallationSyncStatus({
|
|
@@ -305,6 +305,30 @@ describe("admin UI — GitHub sync card (IRM-3.2)", () => {
|
|
|
305
305
|
expect(html.match(/id="github-sync-confirm-btn"/g)?.length).toBe(1);
|
|
306
306
|
});
|
|
307
307
|
|
|
308
|
+
it("renders skipped-org detail in the preview", async () => {
|
|
309
|
+
const { app } = setup({
|
|
310
|
+
agentsApi: () =>
|
|
311
|
+
json({
|
|
312
|
+
...PREVIEW,
|
|
313
|
+
skippedOrgs: [
|
|
314
|
+
{
|
|
315
|
+
org: "zed",
|
|
316
|
+
reason: "access listing is incomplete",
|
|
317
|
+
detail: {
|
|
318
|
+
lookupSnapshotFound: true,
|
|
319
|
+
crawls: [{ completedAt: "2026-01-01T00:00:00.000Z" }],
|
|
320
|
+
totalRepos: 31,
|
|
321
|
+
reposMissingAnswer: 30,
|
|
322
|
+
},
|
|
323
|
+
},
|
|
324
|
+
],
|
|
325
|
+
}),
|
|
326
|
+
});
|
|
327
|
+
const html = await (await get(app, "/github-sync/confirm")).text();
|
|
328
|
+
expect(html).toContain("Lookup crawl complete (31 repos).");
|
|
329
|
+
expect(html).toContain("30 repos have no access answer yet.");
|
|
330
|
+
});
|
|
331
|
+
|
|
308
332
|
it("shows the reason for a skipped preview", async () => {
|
|
309
333
|
const { app } = setup({
|
|
310
334
|
agentsApi: () => json({ status: "skipped", reason: "user not found" }),
|
|
@@ -7722,6 +7722,45 @@ describe("admin API — agent App installation repos and GitHub Sync (IRM-1.2, I
|
|
|
7722
7722
|
expect(state.repos).toEqual(["acme-eng/repo-2"]);
|
|
7723
7723
|
});
|
|
7724
7724
|
|
|
7725
|
+
it("sync preview and apply carry skippedOrgs detail next to the unchanged reason", async () => {
|
|
7726
|
+
const accessRows = [
|
|
7727
|
+
{ ...accessRow("repo-1", "ok", true), checkedAt: T0, attempts: 0 },
|
|
7728
|
+
{
|
|
7729
|
+
...accessRow("repo-2", "error"),
|
|
7730
|
+
checkedAt: T0,
|
|
7731
|
+
attempts: 2,
|
|
7732
|
+
lastError: "rate limited",
|
|
7733
|
+
},
|
|
7734
|
+
];
|
|
7735
|
+
const expected = {
|
|
7736
|
+
org: "acme-eng",
|
|
7737
|
+
reason: "access data is incomplete",
|
|
7738
|
+
detail: {
|
|
7739
|
+
lookupSnapshotFound: true,
|
|
7740
|
+
totalRepos: 3,
|
|
7741
|
+
reposWithOkAccess: 1,
|
|
7742
|
+
reposMissingAnswer: 2,
|
|
7743
|
+
errorRows: 1,
|
|
7744
|
+
terminalRows: 0,
|
|
7745
|
+
maxAttempts: 2,
|
|
7746
|
+
rowErrors: ["rate limited"],
|
|
7747
|
+
},
|
|
7748
|
+
};
|
|
7749
|
+
const { app } = setup({ accessRows });
|
|
7750
|
+
const pre = (await (
|
|
7751
|
+
await app.request(previewUrl, { headers: asAdmin })
|
|
7752
|
+
).json()) as { skippedOrgs: unknown[]; warnings: string[] };
|
|
7753
|
+
expect(pre.skippedOrgs).toMatchObject([expected]);
|
|
7754
|
+
expect(pre.warnings).toEqual([
|
|
7755
|
+
"acme-eng: skipped (access data is incomplete)",
|
|
7756
|
+
]);
|
|
7757
|
+
const { app: app2 } = setup({ accessRows });
|
|
7758
|
+
const applied = (await (
|
|
7759
|
+
await apply(app2, { appRemoves: ["acme-eng/repo-2"] })
|
|
7760
|
+
).json()) as { skippedOrgs: unknown[] };
|
|
7761
|
+
expect(applied.skippedOrgs).toMatchObject([expected]);
|
|
7762
|
+
});
|
|
7763
|
+
|
|
7725
7764
|
it("sync preview reports a failing open-work port as a warning", async () => {
|
|
7726
7765
|
const { app } = setup({
|
|
7727
7766
|
openWork: {
|
package/src/agents-api.ts
CHANGED
|
@@ -722,8 +722,38 @@ const OpenWorkItemSchema = z.object({
|
|
|
722
722
|
title: z.string().optional(),
|
|
723
723
|
});
|
|
724
724
|
|
|
725
|
+
const OrgSkipDetailSchema = z
|
|
726
|
+
.object({
|
|
727
|
+
lookupSnapshotFound: z.boolean().optional(),
|
|
728
|
+
crawls: z
|
|
729
|
+
.array(
|
|
730
|
+
z.object({
|
|
731
|
+
completedAt: z.string().nullable(),
|
|
732
|
+
lastError: z.string().nullable().optional(),
|
|
733
|
+
rateLimitResetAt: z.string().nullable().optional(),
|
|
734
|
+
}),
|
|
735
|
+
)
|
|
736
|
+
.optional(),
|
|
737
|
+
totalRepos: z.number().int().optional(),
|
|
738
|
+
reposWithOkAccess: z.number().int().optional(),
|
|
739
|
+
reposMissingAnswer: z.number().int().optional(),
|
|
740
|
+
errorRows: z.number().int().optional(),
|
|
741
|
+
terminalRows: z.number().int().optional(),
|
|
742
|
+
maxAttempts: z.number().int().optional(),
|
|
743
|
+
rowErrors: z.array(z.string()).optional(),
|
|
744
|
+
oldestCheckedAt: z.string().optional(),
|
|
745
|
+
})
|
|
746
|
+
.openapi("GithubSyncOrgSkipDetail");
|
|
747
|
+
|
|
725
748
|
const SkippedOrgsSchema = z.array(
|
|
726
|
-
z.object({
|
|
749
|
+
z.object({
|
|
750
|
+
org: z.string(),
|
|
751
|
+
reason: z.string(),
|
|
752
|
+
detail: OrgSkipDetailSchema.optional().openapi({
|
|
753
|
+
description:
|
|
754
|
+
"Why the org was skipped, for cached data: whether the lookup snapshot was found, each crawl's completedAt/lastError/rateLimitResetAt, repo and access-row counts, and the oldest-checked time when stale.",
|
|
755
|
+
}),
|
|
756
|
+
}),
|
|
727
757
|
);
|
|
728
758
|
|
|
729
759
|
const GithubSyncPreviewSchema = z
|
|
@@ -254,7 +254,7 @@ describe("createGithubSync lookup snapshot read", () => {
|
|
|
254
254
|
const { svc } = build(null, [lookupAcme("some-other-account")]);
|
|
255
255
|
const preview = await svc.preview("a1");
|
|
256
256
|
if (preview.status !== "previewed") throw new Error(preview.status);
|
|
257
|
-
expect(preview.plan.skippedOrgs).
|
|
257
|
+
expect(preview.plan.skippedOrgs).toMatchObject([
|
|
258
258
|
{ org: "acme", reason: "access data is incomplete" },
|
|
259
259
|
]);
|
|
260
260
|
});
|
package/src/github-repo-cache.ts
CHANGED
|
@@ -69,7 +69,7 @@ describe("sync preview over the cache", () => {
|
|
|
69
69
|
const r = await preview(cache, now);
|
|
70
70
|
if (r.status !== "previewed") throw new Error(r.status);
|
|
71
71
|
expect(r.plan.removedRepos).toEqual([]);
|
|
72
|
-
expect(r.plan.skippedOrgs).
|
|
72
|
+
expect(r.plan.skippedOrgs).toMatchObject([
|
|
73
73
|
{ org: "acme", reason: "access data is incomplete" },
|
|
74
74
|
]);
|
|
75
75
|
});
|
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
import {
|
|
22
22
|
canPushForRole,
|
|
23
23
|
type OrgAccessResult,
|
|
24
|
+
type OrgSkipDetail,
|
|
24
25
|
type ResolvedRepoAccess,
|
|
25
26
|
type UserRepoAccessResult,
|
|
26
27
|
} from "./user-repo-access-resolver.ts";
|
|
@@ -29,7 +30,13 @@ import type { RepoRole } from "./github-lookup-client.ts";
|
|
|
29
30
|
export interface CachedOrgInput {
|
|
30
31
|
org: string;
|
|
31
32
|
/** completedAt of each crawl snapshot this org depends on; null = not completed. Empty = none needed. */
|
|
32
|
-
crawls: {
|
|
33
|
+
crawls: {
|
|
34
|
+
completedAt: Date | null;
|
|
35
|
+
lastError?: string | null;
|
|
36
|
+
rateLimitResetAt?: Date | null;
|
|
37
|
+
}[];
|
|
38
|
+
/** Whether the lookup crawl snapshot was found (omit when no lookup source is wired). */
|
|
39
|
+
lookupSnapshotFound?: boolean;
|
|
33
40
|
/** True when a crawl snapshot that must exist does not. */
|
|
34
41
|
crawlMissing?: boolean;
|
|
35
42
|
/** Every repo (full name) that needs an answer. */
|
|
@@ -50,6 +57,49 @@ const ROLES = new Set<string>([
|
|
|
50
57
|
const nameOf = (fullName: string): string =>
|
|
51
58
|
fullName.slice(fullName.indexOf("/") + 1).toLowerCase();
|
|
52
59
|
|
|
60
|
+
function skipDetail(
|
|
61
|
+
o: CachedOrgInput,
|
|
62
|
+
answers: { row?: CachedAccessRow }[],
|
|
63
|
+
oldest?: Date,
|
|
64
|
+
): OrgSkipDetail {
|
|
65
|
+
const rows = answers.flatMap((a) => (a.row ? [a.row] : []));
|
|
66
|
+
const ok = rows.filter((r) => r.status === "ok").length;
|
|
67
|
+
const attempts = rows.flatMap((r) =>
|
|
68
|
+
r.attempts === undefined ? [] : [r.attempts],
|
|
69
|
+
);
|
|
70
|
+
const rowErrors = [
|
|
71
|
+
...new Set(
|
|
72
|
+
rows.flatMap((r) =>
|
|
73
|
+
r.status !== "ok" && r.lastError ? [r.lastError] : [],
|
|
74
|
+
),
|
|
75
|
+
),
|
|
76
|
+
].slice(0, 3);
|
|
77
|
+
return {
|
|
78
|
+
...(o.lookupSnapshotFound === undefined
|
|
79
|
+
? {}
|
|
80
|
+
: { lookupSnapshotFound: o.lookupSnapshotFound }),
|
|
81
|
+
crawls: o.crawls.map((c) => ({
|
|
82
|
+
completedAt: c.completedAt ? c.completedAt.toISOString() : null,
|
|
83
|
+
...(c.lastError === undefined ? {} : { lastError: c.lastError }),
|
|
84
|
+
...(c.rateLimitResetAt === undefined
|
|
85
|
+
? {}
|
|
86
|
+
: {
|
|
87
|
+
rateLimitResetAt: c.rateLimitResetAt
|
|
88
|
+
? c.rateLimitResetAt.toISOString()
|
|
89
|
+
: null,
|
|
90
|
+
}),
|
|
91
|
+
})),
|
|
92
|
+
totalRepos: o.repos.length,
|
|
93
|
+
reposWithOkAccess: ok,
|
|
94
|
+
reposMissingAnswer: answers.length - ok,
|
|
95
|
+
errorRows: rows.filter((r) => r.status === "error").length,
|
|
96
|
+
terminalRows: rows.filter((r) => r.status === "terminal").length,
|
|
97
|
+
...(attempts.length > 0 ? { maxAttempts: Math.max(...attempts) } : {}),
|
|
98
|
+
...(rowErrors.length > 0 ? { rowErrors } : {}),
|
|
99
|
+
...(oldest ? { oldestCheckedAt: oldest.toISOString() } : {}),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
53
103
|
export function buildCachedAccess(opts: {
|
|
54
104
|
username: string;
|
|
55
105
|
now: Date;
|
|
@@ -76,6 +126,7 @@ export function buildCachedAccess(opts: {
|
|
|
76
126
|
repos: [],
|
|
77
127
|
unresolved: missing.length,
|
|
78
128
|
reason: INCOMPLETE_ACCESS_REASON,
|
|
129
|
+
detail: skipDetail(o, answers),
|
|
79
130
|
});
|
|
80
131
|
continue;
|
|
81
132
|
}
|
|
@@ -93,6 +144,7 @@ export function buildCachedAccess(opts: {
|
|
|
93
144
|
repos: [],
|
|
94
145
|
unresolved: 0,
|
|
95
146
|
reason: staleAccessReason(unknownTime ? undefined : oldest),
|
|
147
|
+
detail: skipDetail(o, answers, unknownTime ? undefined : oldest),
|
|
96
148
|
});
|
|
97
149
|
continue;
|
|
98
150
|
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { describe, expect, it } from "bun:test";
|
|
2
|
+
import { buildCachedAccess } from "./github-sync-cached-access.ts";
|
|
3
|
+
|
|
4
|
+
const NOW = new Date("2026-11-20T12:00:00.000Z");
|
|
5
|
+
const HOUR = 3_600_000;
|
|
6
|
+
const build = (o: Parameters<typeof buildCachedAccess>[0]["orgs"][number]) =>
|
|
7
|
+
buildCachedAccess({
|
|
8
|
+
username: "octo",
|
|
9
|
+
now: NOW,
|
|
10
|
+
maxAgeMs: 24 * HOUR,
|
|
11
|
+
orgs: [o],
|
|
12
|
+
}).orgs[0];
|
|
13
|
+
|
|
14
|
+
const row = (repo: string, over: Record<string, unknown> = {}) => ({
|
|
15
|
+
repo,
|
|
16
|
+
status: "ok",
|
|
17
|
+
canPush: true,
|
|
18
|
+
checkedAt: new Date(NOW.getTime() - HOUR),
|
|
19
|
+
...over,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe("buildCachedAccess skip detail", () => {
|
|
23
|
+
it("reports a missing lookup snapshot", () => {
|
|
24
|
+
const r = build({
|
|
25
|
+
org: "acme",
|
|
26
|
+
crawls: [],
|
|
27
|
+
crawlMissing: true,
|
|
28
|
+
lookupSnapshotFound: false,
|
|
29
|
+
repos: [],
|
|
30
|
+
rows: [],
|
|
31
|
+
});
|
|
32
|
+
expect(r?.reason).toBe("access data is incomplete");
|
|
33
|
+
expect(r?.detail).toMatchObject({
|
|
34
|
+
lookupSnapshotFound: false,
|
|
35
|
+
totalRepos: 0,
|
|
36
|
+
reposWithOkAccess: 0,
|
|
37
|
+
reposMissingAnswer: 0,
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("reports an incomplete crawl with its lastError and rateLimitResetAt", () => {
|
|
42
|
+
const reset = new Date("2026-11-20T13:00:00.000Z");
|
|
43
|
+
const r = build({
|
|
44
|
+
org: "acme",
|
|
45
|
+
crawls: [
|
|
46
|
+
{ completedAt: null, lastError: "boom", rateLimitResetAt: reset },
|
|
47
|
+
],
|
|
48
|
+
lookupSnapshotFound: true,
|
|
49
|
+
repos: ["acme/a"],
|
|
50
|
+
rows: [row("a")],
|
|
51
|
+
});
|
|
52
|
+
expect(r?.detail?.lookupSnapshotFound).toBe(true);
|
|
53
|
+
expect(r?.detail?.crawls).toEqual([
|
|
54
|
+
{
|
|
55
|
+
completedAt: null,
|
|
56
|
+
lastError: "boom",
|
|
57
|
+
rateLimitResetAt: reset.toISOString(),
|
|
58
|
+
},
|
|
59
|
+
]);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("counts repos without an ok row, error and terminal rows", () => {
|
|
63
|
+
const r = build({
|
|
64
|
+
org: "acme",
|
|
65
|
+
crawls: [{ completedAt: NOW }],
|
|
66
|
+
repos: ["acme/a", "acme/b", "acme/c", "acme/d"],
|
|
67
|
+
rows: [
|
|
68
|
+
row("a"),
|
|
69
|
+
row("b", { status: "error", attempts: 3, lastError: "rate limited" }),
|
|
70
|
+
row("c", { status: "terminal", attempts: 5, lastError: "gone" }),
|
|
71
|
+
],
|
|
72
|
+
});
|
|
73
|
+
expect(r?.reason).toBe("access data is incomplete");
|
|
74
|
+
expect(r?.detail).toMatchObject({
|
|
75
|
+
totalRepos: 4,
|
|
76
|
+
reposWithOkAccess: 1,
|
|
77
|
+
reposMissingAnswer: 3,
|
|
78
|
+
errorRows: 1,
|
|
79
|
+
terminalRows: 1,
|
|
80
|
+
maxAttempts: 5,
|
|
81
|
+
rowErrors: ["rate limited", "gone"],
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("reports the oldest-checked time for stale data", () => {
|
|
86
|
+
const old = new Date(NOW.getTime() - 48 * HOUR);
|
|
87
|
+
const r = build({
|
|
88
|
+
org: "acme",
|
|
89
|
+
crawls: [{ completedAt: NOW }],
|
|
90
|
+
repos: ["acme/a"],
|
|
91
|
+
rows: [row("a", { checkedAt: old })],
|
|
92
|
+
});
|
|
93
|
+
expect(r?.reason).toBe(
|
|
94
|
+
`access data is stale (checked ${old.toISOString()})`,
|
|
95
|
+
);
|
|
96
|
+
expect(r?.detail).toMatchObject({
|
|
97
|
+
oldestCheckedAt: old.toISOString(),
|
|
98
|
+
totalRepos: 1,
|
|
99
|
+
reposWithOkAccess: 1,
|
|
100
|
+
reposMissingAnswer: 0,
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it("has no detail for a usable org", () => {
|
|
105
|
+
const r = build({
|
|
106
|
+
org: "acme",
|
|
107
|
+
crawls: [{ completedAt: NOW }],
|
|
108
|
+
repos: ["acme/a"],
|
|
109
|
+
rows: [row("a")],
|
|
110
|
+
});
|
|
111
|
+
expect(r?.status).toBe("ok");
|
|
112
|
+
expect(r?.detail).toBeUndefined();
|
|
113
|
+
});
|
|
114
|
+
});
|
package/src/github-sync.ts
CHANGED
|
@@ -56,7 +56,10 @@ import {
|
|
|
56
56
|
previewRepoRemovalWork,
|
|
57
57
|
repoLostAccessBlockReason,
|
|
58
58
|
} from "./repo-removal-open-work.ts";
|
|
59
|
-
import type {
|
|
59
|
+
import type {
|
|
60
|
+
OrgSkipDetail,
|
|
61
|
+
UserRepoAccessResult,
|
|
62
|
+
} from "./user-repo-access-resolver.ts";
|
|
60
63
|
|
|
61
64
|
/** `planHash` of the audit row a sync apply writes. */
|
|
62
65
|
export const GITHUB_SYNC_AUDIT_PLAN_HASH = "sync:apply";
|
|
@@ -163,6 +166,7 @@ export function planGithubSync(input: GithubSyncPlanInput): GithubSyncPlan {
|
|
|
163
166
|
: [...configured.values()];
|
|
164
167
|
|
|
165
168
|
const skipReasons = new Map<string, string>();
|
|
169
|
+
const skipDetails = new Map<string, OrgSkipDetail>();
|
|
166
170
|
const notApplied = new Map<string, NotAppliedRepo>();
|
|
167
171
|
const leave = (repo: string, reason: string) => {
|
|
168
172
|
if (requested)
|
|
@@ -171,9 +175,11 @@ export function planGithubSync(input: GithubSyncPlanInput): GithubSyncPlan {
|
|
|
171
175
|
// Unknown is never none: false (with the reason recorded) for a skipped org.
|
|
172
176
|
const orgUsable = (repo: string): boolean => {
|
|
173
177
|
const org = repoOrg(repo);
|
|
174
|
-
const
|
|
178
|
+
const result = orgResults.get(lower(org));
|
|
179
|
+
const reason = orgSkipReason(result);
|
|
175
180
|
if (!reason) return true;
|
|
176
181
|
skipReasons.set(org, reason);
|
|
182
|
+
if (result?.detail) skipDetails.set(org, result.detail);
|
|
177
183
|
leave(repo, `skipped for org: ${reason}`);
|
|
178
184
|
return false;
|
|
179
185
|
};
|
|
@@ -224,6 +230,7 @@ export function planGithubSync(input: GithubSyncPlanInput): GithubSyncPlan {
|
|
|
224
230
|
const skippedOrgs = sorted(skipReasons.keys()).map((org) => ({
|
|
225
231
|
org,
|
|
226
232
|
reason: skipReasons.get(org) as string,
|
|
233
|
+
...(skipDetails.has(org) ? { detail: skipDetails.get(org) } : {}),
|
|
227
234
|
}));
|
|
228
235
|
return {
|
|
229
236
|
skipped: false,
|
|
@@ -244,6 +251,8 @@ export interface CachedLookupOrg {
|
|
|
244
251
|
org: string;
|
|
245
252
|
completedAt: Date | null;
|
|
246
253
|
repos: readonly string[];
|
|
254
|
+
lastError?: string | null;
|
|
255
|
+
rateLimitResetAt?: Date | null;
|
|
247
256
|
}
|
|
248
257
|
|
|
249
258
|
/** Default freshness bound: the refresher's staleness cap (the longest data is left unrefreshed). */
|
|
@@ -501,8 +510,22 @@ export class GithubSyncService {
|
|
|
501
510
|
repos.set(key(r), r);
|
|
502
511
|
}
|
|
503
512
|
const crawls = [
|
|
504
|
-
...(inst && snap
|
|
505
|
-
|
|
513
|
+
...(inst && snap
|
|
514
|
+
? [
|
|
515
|
+
{
|
|
516
|
+
completedAt: snap.completedAt,
|
|
517
|
+
lastError: snap.lastError,
|
|
518
|
+
rateLimitResetAt: snap.rateLimitResetAt,
|
|
519
|
+
},
|
|
520
|
+
]
|
|
521
|
+
: []),
|
|
522
|
+
...lk.map((l) => ({
|
|
523
|
+
completedAt: l.completedAt,
|
|
524
|
+
...(l.lastError === undefined ? {} : { lastError: l.lastError }),
|
|
525
|
+
...(l.rateLimitResetAt === undefined
|
|
526
|
+
? {}
|
|
527
|
+
: { rateLimitResetAt: l.rateLimitResetAt }),
|
|
528
|
+
})),
|
|
506
529
|
];
|
|
507
530
|
let rows: Awaited<ReturnType<InstallationCachePort["getAccessRows"]>> =
|
|
508
531
|
[];
|
|
@@ -522,6 +545,9 @@ export class GithubSyncService {
|
|
|
522
545
|
inputs.push({
|
|
523
546
|
org,
|
|
524
547
|
crawls,
|
|
548
|
+
...(this.deps.lookupRepos !== undefined
|
|
549
|
+
? { lookupSnapshotFound: lk.length > 0 }
|
|
550
|
+
: {}),
|
|
525
551
|
// A read failure, an installed org with no crawl, or a lookup source with no crawl of this org.
|
|
526
552
|
crawlMissing:
|
|
527
553
|
failed ||
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { describe, expect, it, test } from "bun:test";
|
|
2
|
+
import type {
|
|
3
|
+
CachedAccessRow,
|
|
4
|
+
InstallationSnapshotRow,
|
|
5
|
+
} from "./installation-repos-service.ts";
|
|
2
6
|
import type { GithubAccessPreviewFn } from "./github-access-preview.ts";
|
|
3
7
|
import {
|
|
4
8
|
GITHUB_SYNC_AUDIT_PLAN_HASH,
|
|
9
|
+
type CachedLookupOrg,
|
|
5
10
|
GithubSyncService,
|
|
6
11
|
NOT_ADDABLE_REASON,
|
|
7
12
|
NOT_PRESENT_REASON,
|
|
@@ -603,3 +608,193 @@ describe("GithubSyncService.apply", () => {
|
|
|
603
608
|
expect(repos()).toEqual(["acme/a"]);
|
|
604
609
|
});
|
|
605
610
|
});
|
|
611
|
+
|
|
612
|
+
describe("skippedOrgs detail", () => {
|
|
613
|
+
const detail = {
|
|
614
|
+
lookupSnapshotFound: true,
|
|
615
|
+
totalRepos: 3,
|
|
616
|
+
reposWithOkAccess: 1,
|
|
617
|
+
reposMissingAnswer: 2,
|
|
618
|
+
errorRows: 1,
|
|
619
|
+
terminalRows: 1,
|
|
620
|
+
};
|
|
621
|
+
|
|
622
|
+
test("planGithubSync carries the org's detail next to the unchanged reason", () => {
|
|
623
|
+
const p = planGithubSync(
|
|
624
|
+
base({
|
|
625
|
+
access: access([
|
|
626
|
+
org("acme", [], {
|
|
627
|
+
status: "partial",
|
|
628
|
+
reason: "access data is incomplete",
|
|
629
|
+
detail,
|
|
630
|
+
}),
|
|
631
|
+
]),
|
|
632
|
+
}),
|
|
633
|
+
);
|
|
634
|
+
expect(p.skippedOrgs).toEqual([
|
|
635
|
+
{ org: "acme", reason: "access data is incomplete", detail },
|
|
636
|
+
]);
|
|
637
|
+
expect(p.warnings).toEqual(["acme: skipped (access data is incomplete)"]);
|
|
638
|
+
});
|
|
639
|
+
|
|
640
|
+
test("an org with no detail has no detail key", () => {
|
|
641
|
+
const p = planGithubSync(base({ access: access([]) }));
|
|
642
|
+
expect(p.skippedOrgs[0]).toEqual({
|
|
643
|
+
org: "acme",
|
|
644
|
+
reason: "org was not checked",
|
|
645
|
+
});
|
|
646
|
+
});
|
|
647
|
+
|
|
648
|
+
function cachedSvc(
|
|
649
|
+
lookup: Parameters<typeof lookupDeps>[0],
|
|
650
|
+
over: {
|
|
651
|
+
snap?: Partial<InstallationSnapshotRow>;
|
|
652
|
+
rows?: CachedAccessRow[];
|
|
653
|
+
} = {},
|
|
654
|
+
) {
|
|
655
|
+
return new GithubSyncService({
|
|
656
|
+
agents: {
|
|
657
|
+
get: async () => ({
|
|
658
|
+
id: "ag",
|
|
659
|
+
githubUsername: "octo",
|
|
660
|
+
appId: 7,
|
|
661
|
+
repos: ["acme/a"],
|
|
662
|
+
}),
|
|
663
|
+
setRepos: async () => {},
|
|
664
|
+
},
|
|
665
|
+
access: async () => {
|
|
666
|
+
throw new Error("live resolver must not be used");
|
|
667
|
+
},
|
|
668
|
+
installation: {
|
|
669
|
+
listInstalled: async () => ({
|
|
670
|
+
status: "found",
|
|
671
|
+
orgs: [{ org: "acme", repos: ["acme/a", "acme/b"] }],
|
|
672
|
+
}),
|
|
673
|
+
addRepos: async () => {},
|
|
674
|
+
removeRepos: async () => {},
|
|
675
|
+
},
|
|
676
|
+
audit: { write: async () => "a" },
|
|
677
|
+
now: () => new Date("2026-11-20T12:00:00.000Z"),
|
|
678
|
+
...(() => {
|
|
679
|
+
const d = lookupDeps(lookup);
|
|
680
|
+
return {
|
|
681
|
+
...d,
|
|
682
|
+
cache: {
|
|
683
|
+
listAgentSnapshots: async () => [
|
|
684
|
+
{ ...(await d.cache.listAgentSnapshots())[0], ...over.snap },
|
|
685
|
+
],
|
|
686
|
+
getAccessRows: async () =>
|
|
687
|
+
over.rows ?? (await d.cache.getAccessRows()),
|
|
688
|
+
},
|
|
689
|
+
};
|
|
690
|
+
})(),
|
|
691
|
+
});
|
|
692
|
+
}
|
|
693
|
+
const lookupDeps = (lookup: CachedLookupOrg[]) => ({
|
|
694
|
+
cache: {
|
|
695
|
+
listAgentSnapshots: async () => [
|
|
696
|
+
{
|
|
697
|
+
org: "acme",
|
|
698
|
+
completedAt: new Date("2026-11-20T11:00:00.000Z"),
|
|
699
|
+
totalCount: 2,
|
|
700
|
+
lastError: null,
|
|
701
|
+
rateLimitResetAt: null,
|
|
702
|
+
repos: [{ fullName: "acme/a" }, { fullName: "acme/b" }],
|
|
703
|
+
},
|
|
704
|
+
],
|
|
705
|
+
getAccessRows: async () => [
|
|
706
|
+
{ repo: "a", status: "ok", canPush: true },
|
|
707
|
+
{ repo: "b", status: "terminal", canPush: false, attempts: 4 },
|
|
708
|
+
],
|
|
709
|
+
},
|
|
710
|
+
lookupRepos: async () => lookup,
|
|
711
|
+
});
|
|
712
|
+
|
|
713
|
+
it("reports a missing lookup snapshot", async () => {
|
|
714
|
+
const r = await cachedSvc([]).preview("ag");
|
|
715
|
+
if (r.status !== "previewed") throw new Error(r.status);
|
|
716
|
+
expect(r.plan.skippedOrgs[0]).toMatchObject({
|
|
717
|
+
org: "acme",
|
|
718
|
+
reason: "access data is incomplete",
|
|
719
|
+
detail: { lookupSnapshotFound: false },
|
|
720
|
+
});
|
|
721
|
+
});
|
|
722
|
+
|
|
723
|
+
it("reports the lookup crawl's completedAt, lastError and rateLimitResetAt plus row counts", async () => {
|
|
724
|
+
const reset = new Date("2026-11-20T13:00:00.000Z");
|
|
725
|
+
const r = await cachedSvc([
|
|
726
|
+
{
|
|
727
|
+
org: "acme",
|
|
728
|
+
completedAt: null,
|
|
729
|
+
repos: ["acme/a", "acme/b"],
|
|
730
|
+
lastError: "secondary rate limit",
|
|
731
|
+
rateLimitResetAt: reset,
|
|
732
|
+
},
|
|
733
|
+
]).preview("ag");
|
|
734
|
+
if (r.status !== "previewed") throw new Error(r.status);
|
|
735
|
+
expect(r.plan.skippedOrgs[0]?.detail).toMatchObject({
|
|
736
|
+
lookupSnapshotFound: true,
|
|
737
|
+
totalRepos: 2,
|
|
738
|
+
reposWithOkAccess: 1,
|
|
739
|
+
reposMissingAnswer: 1,
|
|
740
|
+
terminalRows: 1,
|
|
741
|
+
errorRows: 0,
|
|
742
|
+
maxAttempts: 4,
|
|
743
|
+
});
|
|
744
|
+
expect(r.plan.skippedOrgs[0]?.detail?.crawls).toContainEqual({
|
|
745
|
+
completedAt: null,
|
|
746
|
+
lastError: "secondary rate limit",
|
|
747
|
+
rateLimitResetAt: reset.toISOString(),
|
|
748
|
+
});
|
|
749
|
+
});
|
|
750
|
+
|
|
751
|
+
it("reports the installation crawl's lastError and rateLimitResetAt", async () => {
|
|
752
|
+
const r = await cachedSvc(
|
|
753
|
+
[
|
|
754
|
+
{
|
|
755
|
+
org: "acme",
|
|
756
|
+
completedAt: new Date("2026-11-20T11:00:00.000Z"),
|
|
757
|
+
repos: ["acme/a", "acme/b"],
|
|
758
|
+
},
|
|
759
|
+
],
|
|
760
|
+
{
|
|
761
|
+
snap: { completedAt: null, lastError: "boom", rateLimitResetAt: null },
|
|
762
|
+
},
|
|
763
|
+
).preview("ag");
|
|
764
|
+
if (r.status !== "previewed") throw new Error(r.status);
|
|
765
|
+
expect(r.plan.skippedOrgs[0]?.detail?.crawls).toContainEqual({
|
|
766
|
+
completedAt: null,
|
|
767
|
+
lastError: "boom",
|
|
768
|
+
rateLimitResetAt: null,
|
|
769
|
+
});
|
|
770
|
+
});
|
|
771
|
+
|
|
772
|
+
it("reports the oldest-checked time and error row count for stale data", async () => {
|
|
773
|
+
const old = new Date("2026-01-01T00:00:00.000Z");
|
|
774
|
+
const r = await cachedSvc(
|
|
775
|
+
[
|
|
776
|
+
{
|
|
777
|
+
org: "acme",
|
|
778
|
+
completedAt: new Date("2026-11-20T11:00:00.000Z"),
|
|
779
|
+
repos: ["acme/a", "acme/b"],
|
|
780
|
+
},
|
|
781
|
+
],
|
|
782
|
+
{
|
|
783
|
+
rows: [
|
|
784
|
+
{ repo: "a", status: "ok", canPush: true, checkedAt: old },
|
|
785
|
+
{ repo: "b", status: "ok", canPush: true, checkedAt: old },
|
|
786
|
+
],
|
|
787
|
+
},
|
|
788
|
+
).preview("ag");
|
|
789
|
+
if (r.status !== "previewed") throw new Error(r.status);
|
|
790
|
+
expect(r.plan.skippedOrgs[0]).toMatchObject({
|
|
791
|
+
detail: {
|
|
792
|
+
oldestCheckedAt: old.toISOString(),
|
|
793
|
+
reposWithOkAccess: 2,
|
|
794
|
+
reposMissingAnswer: 0,
|
|
795
|
+
errorRows: 0,
|
|
796
|
+
terminalRows: 0,
|
|
797
|
+
},
|
|
798
|
+
});
|
|
799
|
+
});
|
|
800
|
+
});
|
package/src/repo-access-rules.ts
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
import {
|
|
13
13
|
type OrgAccessResult,
|
|
14
|
+
type OrgSkipDetail,
|
|
14
15
|
SELECTED_REPOS_REASON,
|
|
15
16
|
type UserRepoAccessResult,
|
|
16
17
|
} from "./user-repo-access-resolver.ts";
|
|
@@ -18,6 +19,8 @@ import {
|
|
|
18
19
|
export interface OrgSkip {
|
|
19
20
|
org: string;
|
|
20
21
|
reason: string;
|
|
22
|
+
/** Why the org was skipped, when known (cached-data orgs). */
|
|
23
|
+
detail?: OrgSkipDetail;
|
|
21
24
|
}
|
|
22
25
|
|
|
23
26
|
export function repoOrg(fullName: string): string {
|
|
@@ -51,6 +51,31 @@ export interface ResolvedRepoAccess {
|
|
|
51
51
|
canPush: boolean;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
/** Why a cached-data org was skipped: what the cache did and did not answer. All members optional. */
|
|
55
|
+
export interface OrgSkipDetail {
|
|
56
|
+
/** Whether the lookup-App crawl snapshot for the org exists (undefined when not applicable). */
|
|
57
|
+
lookupSnapshotFound?: boolean;
|
|
58
|
+
/** Each crawl snapshot the org depends on. */
|
|
59
|
+
crawls?: {
|
|
60
|
+
completedAt: string | null;
|
|
61
|
+
lastError?: string | null;
|
|
62
|
+
rateLimitResetAt?: string | null;
|
|
63
|
+
}[];
|
|
64
|
+
totalRepos?: number;
|
|
65
|
+
/** Repos with an ok access row. */
|
|
66
|
+
reposWithOkAccess?: number;
|
|
67
|
+
/** Repos without an ok access row. */
|
|
68
|
+
reposMissingAnswer?: number;
|
|
69
|
+
errorRows?: number;
|
|
70
|
+
terminalRows?: number;
|
|
71
|
+
/** Highest attempts count among the access rows. */
|
|
72
|
+
maxAttempts?: number;
|
|
73
|
+
/** Distinct lastError values of the error/terminal rows (at most 3). */
|
|
74
|
+
rowErrors?: string[];
|
|
75
|
+
/** Oldest check time (ISO) when the data is stale. */
|
|
76
|
+
oldestCheckedAt?: string;
|
|
77
|
+
}
|
|
78
|
+
|
|
54
79
|
export interface OrgAccessResult {
|
|
55
80
|
org: string;
|
|
56
81
|
status: OrgAccessStatus;
|
|
@@ -60,6 +85,8 @@ export interface OrgAccessResult {
|
|
|
60
85
|
unresolved: number;
|
|
61
86
|
/** Why the org is not "ok" when the cause is the lookup install scope. */
|
|
62
87
|
reason?: string;
|
|
88
|
+
/** Extra context for a partial org built from cached data. */
|
|
89
|
+
detail?: OrgSkipDetail;
|
|
63
90
|
}
|
|
64
91
|
|
|
65
92
|
/** Shown when the lookup App is installed on selected repositories only. */
|