@app-vitals/agent-admin 1.84.1 → 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 +11 -2
- package/src/github-installation-wiring.unit.test.ts +90 -0
- package/src/github-installation.fixtures.ts +42 -0
- package/src/github-repo-cache.ts +2 -0
- package/src/github-sync-cache.integration.test.ts +57 -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
|
|
@@ -13,6 +13,7 @@ import type { GithubAccessPreviewFn } from "./github-access-preview.ts";
|
|
|
13
13
|
import type { Clock } from "./clock.ts";
|
|
14
14
|
import type { GitHubEnterpriseAppService } from "./github-enterprise-apps.ts";
|
|
15
15
|
import { GithubEnterpriseClient } from "./github-enterprise-client.ts";
|
|
16
|
+
import { DEPLOYMENT_WIDE_ACCOUNT_KEY } from "./github-agent-installation-crawler.ts";
|
|
16
17
|
import { GithubLookupClient } from "./github-lookup-client.ts";
|
|
17
18
|
import { GitHubRepoCacheService } from "./github-repo-cache.ts";
|
|
18
19
|
import type { CrawlStore } from "./github-repo-crawler.ts";
|
|
@@ -158,14 +159,22 @@ export function createGithubSync(
|
|
|
158
159
|
lookupRepos: async (accountId) => {
|
|
159
160
|
const lookup = await lookupClient(accountId);
|
|
160
161
|
if (!lookup) return [];
|
|
161
|
-
// The crawler files a deployment-wide App's snapshots under
|
|
162
|
+
// The crawler files a deployment-wide App's snapshots under
|
|
163
|
+
// DEPLOYMENT_WIDE_ACCOUNT_KEY, so a null-account agent reads that key and
|
|
164
|
+
// an account agent reads its own account plus that key.
|
|
165
|
+
// Note: a real account literally named "deployment" would collide with
|
|
166
|
+
// this fallback key; that is known and deliberately not fixed here.
|
|
162
167
|
const snapshots = await cache.listLookupOrgSnapshots(
|
|
163
|
-
accountId
|
|
168
|
+
accountId
|
|
169
|
+
? [accountId, DEPLOYMENT_WIDE_ACCOUNT_KEY]
|
|
170
|
+
: [DEPLOYMENT_WIDE_ACCOUNT_KEY],
|
|
164
171
|
lookup.appId,
|
|
165
172
|
);
|
|
166
173
|
return snapshots.map((s) => ({
|
|
167
174
|
org: s.org,
|
|
168
175
|
completedAt: s.completedAt,
|
|
176
|
+
lastError: s.lastError,
|
|
177
|
+
rateLimitResetAt: s.rateLimitResetAt,
|
|
169
178
|
repos: s.repos.map((r) => r.fullName),
|
|
170
179
|
}));
|
|
171
180
|
},
|