@app-vitals/agent-admin 1.84.2 → 1.86.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 +114 -22
- package/src/admin-ui-installation-repos-pages.unit.test.ts +268 -0
- package/src/admin-ui-installation-repos.smoke.test.ts +26 -2
- package/src/admin-ui-pages.ts +1 -1
- package/src/admin-ui.ts +3 -1
- 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.86.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.86.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;
|
|
@@ -69,20 +72,43 @@ const hasSyncDetail = (v: InstallationSyncView): boolean =>
|
|
|
69
72
|
v.leaseHolder !== undefined ||
|
|
70
73
|
v.lastTickAt !== undefined;
|
|
71
74
|
|
|
72
|
-
|
|
73
|
-
|
|
75
|
+
/**
|
|
76
|
+
* Display text for a UTC ISO instant: "Nov 23, 5:02 PM PST" in the given IANA
|
|
77
|
+
* timezone, or "2026-11-23 17:02 UTC" when none is set. Unparseable input is
|
|
78
|
+
* returned as-is. Not HTML-escaped.
|
|
79
|
+
*/
|
|
80
|
+
export function formatSyncTime(iso: string, timezone?: string): string {
|
|
81
|
+
const d = new Date(iso);
|
|
82
|
+
if (!timezone || Number.isNaN(d.getTime())) {
|
|
83
|
+
return `${iso.slice(0, 16).replace("T", " ")} UTC`;
|
|
84
|
+
}
|
|
85
|
+
return new Intl.DateTimeFormat("en-US", {
|
|
86
|
+
timeZone: timezone,
|
|
87
|
+
month: "short",
|
|
88
|
+
day: "numeric",
|
|
89
|
+
hour: "numeric",
|
|
90
|
+
minute: "2-digit",
|
|
91
|
+
timeZoneName: "short",
|
|
92
|
+
}).format(d);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const fmt = (iso: string, timezone?: string): string =>
|
|
96
|
+
escapeHtml(formatSyncTime(iso, timezone));
|
|
74
97
|
|
|
75
98
|
/**
|
|
76
99
|
* One-line sync status: synced-at, "N of M repos", last error and the rate-limit
|
|
77
100
|
* reset. Empty when the view has no sync detail (older API).
|
|
78
101
|
*/
|
|
79
|
-
export function renderInstallationSyncStatus(
|
|
102
|
+
export function renderInstallationSyncStatus(
|
|
103
|
+
v: InstallationSyncView,
|
|
104
|
+
timezone?: string,
|
|
105
|
+
): string {
|
|
80
106
|
if (!hasSyncDetail(v)) return "";
|
|
81
107
|
const complete = installationSnapshotComplete(v);
|
|
82
108
|
const parts: string[] = [];
|
|
83
109
|
parts.push(
|
|
84
110
|
v.syncedAt
|
|
85
|
-
? `Synced ${
|
|
111
|
+
? `Synced ${fmt(v.syncedAt, timezone)}`
|
|
86
112
|
: complete
|
|
87
113
|
? "Synced"
|
|
88
114
|
: "Sync in progress",
|
|
@@ -96,18 +122,17 @@ export function renderInstallationSyncStatus(v: InstallationSyncView): string {
|
|
|
96
122
|
}
|
|
97
123
|
if (v.lastError) parts.push(`Last error: ${escapeHtml(v.lastError)}`);
|
|
98
124
|
if (v.rateLimitResetAt) {
|
|
99
|
-
parts.push(
|
|
100
|
-
`GitHub rate limit resets ${escapeHtml(v.rateLimitResetAt.slice(0, 16).replace("T", " "))} UTC`,
|
|
101
|
-
);
|
|
125
|
+
parts.push(`GitHub rate limit resets ${fmt(v.rateLimitResetAt, timezone)}`);
|
|
102
126
|
}
|
|
103
127
|
if (v.attempts) {
|
|
104
128
|
parts.push(
|
|
105
129
|
`${v.attempts} failed ${v.attempts === 1 ? "attempt" : "attempts"}`,
|
|
106
130
|
);
|
|
107
131
|
}
|
|
108
|
-
if (v.nextAttemptAt)
|
|
132
|
+
if (v.nextAttemptAt)
|
|
133
|
+
parts.push(`Next attempt ${fmt(v.nextAttemptAt, timezone)}`);
|
|
109
134
|
if (v.leaseHolder) parts.push(`Refreshing (${escapeHtml(v.leaseHolder)})`);
|
|
110
|
-
if (v.lastTickAt) parts.push(`Last tick ${
|
|
135
|
+
if (v.lastTickAt) parts.push(`Last tick ${fmt(v.lastTickAt, timezone)}`);
|
|
111
136
|
const cls = v.lastError || v.rateLimitResetAt ? "alert alert-warning" : "";
|
|
112
137
|
return `<div class="${cls}" data-installation-sync="${complete ? "complete" : "incomplete"}" style="color:#6b7280;font-size:12px;margin:8px 0">${parts.join(" · ")}</div>`;
|
|
113
138
|
}
|
|
@@ -177,7 +202,7 @@ export interface GithubSyncPreviewView {
|
|
|
177
202
|
appAdds?: string[];
|
|
178
203
|
appRemoves?: string[];
|
|
179
204
|
agentRemoves?: string[];
|
|
180
|
-
skippedOrgs?: { org: string; reason: string }[];
|
|
205
|
+
skippedOrgs?: { org: string; reason: string; detail?: SkipDetail }[];
|
|
181
206
|
openWork?: OpenWorkView[];
|
|
182
207
|
warnings?: string[];
|
|
183
208
|
}
|
|
@@ -190,7 +215,7 @@ export interface GithubSyncApplyView {
|
|
|
190
215
|
appRemoves?: string[];
|
|
191
216
|
agentRemoves?: string[];
|
|
192
217
|
notApplied?: { repo: string; reason: string }[];
|
|
193
|
-
skippedOrgs?: { org: string; reason: string }[];
|
|
218
|
+
skippedOrgs?: { org: string; reason: string; detail?: SkipDetail }[];
|
|
194
219
|
warnings?: string[];
|
|
195
220
|
}
|
|
196
221
|
|
|
@@ -287,9 +312,9 @@ export function renderGithubSyncCard(
|
|
|
287
312
|
/** The card body: read-only repos per org with the user-can-push hint (only when known). */
|
|
288
313
|
export function renderInstallationReposBody(
|
|
289
314
|
view: InstallationReposView,
|
|
290
|
-
opts: { appIdMismatch?: boolean } = {},
|
|
315
|
+
opts: { appIdMismatch?: boolean; timezone?: string } = {},
|
|
291
316
|
): string {
|
|
292
|
-
const sync = renderInstallationSyncStatus(view);
|
|
317
|
+
const sync = renderInstallationSyncStatus(view, opts.timezone);
|
|
293
318
|
if (view.orgs.length === 0 || view.orgs.every((o) => o.repos.length === 0)) {
|
|
294
319
|
if (opts.appIdMismatch) {
|
|
295
320
|
return `${sync}<div class="alert alert-warning" data-reason="app-id-mismatch">${escapeHtml(APP_ID_MISMATCH_MESSAGE)}</div>`;
|
|
@@ -331,7 +356,7 @@ export function renderInstallationReposBody(
|
|
|
331
356
|
return `<tr><td class="mono">${escapeHtml(r.fullName)}</td><td>${hint}${meta}</td></tr>`;
|
|
332
357
|
})
|
|
333
358
|
.join("");
|
|
334
|
-
return `<div class="github-installation-org" data-org="${escapeHtml(o.org)}" style="margin-bottom:16px"><div style="font-weight:600;margin-bottom:6px">${escapeHtml(o.org)}</div>${renderInstallationSyncStatus(o)}<table class="detail-table"><thead><tr><th>Repo</th><th>Bound user</th></tr></thead><tbody>${rows}</tbody></table></div>`;
|
|
359
|
+
return `<div class="github-installation-org" data-org="${escapeHtml(o.org)}" style="margin-bottom:16px"><div style="font-weight:600;margin-bottom:6px">${escapeHtml(o.org)}</div>${renderInstallationSyncStatus(o, opts.timezone)}<table class="detail-table"><thead><tr><th>Repo</th><th>Bound user</th></tr></thead><tbody>${rows}</tbody></table></div>`;
|
|
335
360
|
})
|
|
336
361
|
.join("")
|
|
337
362
|
);
|
|
@@ -415,12 +440,70 @@ const repoList = (kind: string, title: string, repos: readonly string[]) =>
|
|
|
415
440
|
? ""
|
|
416
441
|
: `<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
442
|
|
|
418
|
-
const
|
|
443
|
+
const plural = (n: number, one: string, many: string) =>
|
|
444
|
+
`${n} ${n === 1 ? one : many}`;
|
|
445
|
+
|
|
446
|
+
/** One readable sentence-list describing why an org's cached access was skipped. */
|
|
447
|
+
function skipDetailText(d: SkipDetail, timezone?: string): string {
|
|
448
|
+
const out: string[] = [];
|
|
449
|
+
const crawls = d.crawls ?? [];
|
|
450
|
+
const failed = crawls.filter((c) => c.lastError);
|
|
451
|
+
if (d.lookupSnapshotFound === false) {
|
|
452
|
+
out.push("Lookup crawl not found for this App");
|
|
453
|
+
} else if (failed.length > 0) {
|
|
454
|
+
for (const c of failed) {
|
|
455
|
+
out.push(
|
|
456
|
+
`Lookup crawl failed: ${c.lastError}${c.rateLimitResetAt ? `; next attempt ${formatSyncTime(c.rateLimitResetAt, timezone)}` : ""}`,
|
|
457
|
+
);
|
|
458
|
+
}
|
|
459
|
+
} else if (crawls.some((c) => c.completedAt === null)) {
|
|
460
|
+
out.push("Lookup crawl not complete yet");
|
|
461
|
+
} else if (crawls.length > 0) {
|
|
462
|
+
out.push(
|
|
463
|
+
`Lookup crawl complete${d.totalRepos === undefined ? "" : ` (${plural(d.totalRepos, "repo", "repos")})`}`,
|
|
464
|
+
);
|
|
465
|
+
}
|
|
466
|
+
if (d.reposMissingAnswer) {
|
|
467
|
+
out.push(
|
|
468
|
+
`${plural(d.reposMissingAnswer, "repo has", "repos have")} no access answer yet`,
|
|
469
|
+
);
|
|
470
|
+
}
|
|
471
|
+
if (d.errorRows) out.push(`${plural(d.errorRows, "repo", "repos")} errored`);
|
|
472
|
+
if (d.terminalRows) {
|
|
473
|
+
out.push(
|
|
474
|
+
`${plural(d.terminalRows, "repo", "repos")} gave up${d.maxAttempts ? ` (max ${d.maxAttempts} attempts)` : ""}`,
|
|
475
|
+
);
|
|
476
|
+
}
|
|
477
|
+
if (d.rowErrors?.length) out.push(`Row errors: ${d.rowErrors.join("; ")}`);
|
|
478
|
+
if (d.oldestCheckedAt)
|
|
479
|
+
out.push(`Oldest check ${formatSyncTime(d.oldestCheckedAt, timezone)}`);
|
|
480
|
+
return out
|
|
481
|
+
.map((x) => `${x}.`)
|
|
482
|
+
.join(" ")
|
|
483
|
+
.replace(/\.\.$/, ".");
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/** Drop the `<org>: skipped (<reason>)` warnings the skippedOrgs block already shows. */
|
|
487
|
+
const withoutSkipWarnings = (
|
|
488
|
+
warnings: readonly string[] | undefined,
|
|
419
489
|
skipped: readonly { org: string; reason: string }[],
|
|
490
|
+
): string[] =>
|
|
491
|
+
(warnings ?? []).filter(
|
|
492
|
+
(w) => !skipped.some((s) => w === `${s.org}: skipped (${s.reason})`),
|
|
493
|
+
);
|
|
494
|
+
|
|
495
|
+
const skippedOrgsHtml = (
|
|
496
|
+
skipped: readonly { org: string; reason: string; detail?: SkipDetail }[],
|
|
497
|
+
timezone?: string,
|
|
420
498
|
) =>
|
|
421
499
|
skipped.length === 0
|
|
422
500
|
? ""
|
|
423
|
-
: `<div class="alert alert-warning" data-skipped-orgs="1"><div style="font-weight:600">Skipped orgs (nothing added or removed there)</div>${skipped
|
|
501
|
+
: `<div class="alert alert-warning" data-skipped-orgs="1"><div style="font-weight:600">Skipped orgs (nothing added or removed there)</div>${skipped
|
|
502
|
+
.map((s) => {
|
|
503
|
+
const text = s.detail ? skipDetailText(s.detail, timezone) : "";
|
|
504
|
+
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>`;
|
|
505
|
+
})
|
|
506
|
+
.join("")}</div>`;
|
|
424
507
|
|
|
425
508
|
/**
|
|
426
509
|
* The single confirm step of Sync: the installation adds, installation
|
|
@@ -431,6 +514,7 @@ const skippedOrgsHtml = (
|
|
|
431
514
|
export function renderSyncConfirm(
|
|
432
515
|
agentId: string,
|
|
433
516
|
preview: GithubSyncPreviewView,
|
|
517
|
+
timezone?: string,
|
|
434
518
|
): string {
|
|
435
519
|
if (preview.status === "skipped") {
|
|
436
520
|
return `<div class="alert alert-warning" data-sync="skipped">Sync was skipped: ${escapeHtml(preview.reason ?? "unknown reason")}</div>`;
|
|
@@ -438,10 +522,16 @@ export function renderSyncConfirm(
|
|
|
438
522
|
const appAdds = preview.appAdds ?? [];
|
|
439
523
|
const appRemoves = preview.appRemoves ?? [];
|
|
440
524
|
const agentRemoves = preview.agentRemoves ?? [];
|
|
441
|
-
const
|
|
442
|
-
const
|
|
525
|
+
const skippedList = preview.skippedOrgs ?? [];
|
|
526
|
+
const skipped = skippedOrgsHtml(skippedList, timezone);
|
|
527
|
+
const warnings = warningsHtml(
|
|
528
|
+
withoutSkipWarnings(preview.warnings, skippedList),
|
|
529
|
+
);
|
|
443
530
|
if (appAdds.length + appRemoves.length + agentRemoves.length === 0) {
|
|
444
|
-
|
|
531
|
+
if (skippedList.length > 0) {
|
|
532
|
+
return `<div class="alert alert-warning" data-sync="nothing-synced">Nothing was synced: ${skippedList.length} org(s) skipped, see below.</div>${skipped}${warnings}`;
|
|
533
|
+
}
|
|
534
|
+
return `<div class="alert alert-success" data-sync="in-sync">Already in sync: nothing to add or remove.</div>${warnings}`;
|
|
445
535
|
}
|
|
446
536
|
const removals = new Set([...appRemoves, ...agentRemoves].map(lc)).size;
|
|
447
537
|
const overCap = removals > MAX_UNCONFIRMED_REMOVALS;
|
|
@@ -463,21 +553,23 @@ export function renderSyncConfirm(
|
|
|
463
553
|
export function renderSyncResult(
|
|
464
554
|
result: GithubSyncApplyView,
|
|
465
555
|
blocked: readonly OpenWorkView[],
|
|
556
|
+
timezone?: string,
|
|
466
557
|
): string {
|
|
467
558
|
if (result.status === "skipped") {
|
|
468
559
|
return `<div class="alert alert-warning" data-sync="skipped">Sync was skipped: ${escapeHtml(result.reason ?? "unknown reason")}</div>`;
|
|
469
560
|
}
|
|
470
561
|
if (result.status === "noop") {
|
|
471
|
-
|
|
562
|
+
const skippedList = result.skippedOrgs ?? [];
|
|
563
|
+
return `<div class="alert alert-success" data-sync="noop">Nothing was changed.</div>${skippedOrgsHtml(skippedList, timezone)}${warningsHtml(withoutSkipWarnings(result.warnings, skippedList))}`;
|
|
472
564
|
}
|
|
473
565
|
const notApplied = result.notApplied ?? [];
|
|
474
566
|
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 ?? [])}${
|
|
475
567
|
notApplied.length === 0
|
|
476
568
|
? ""
|
|
477
569
|
: `<div class="alert alert-warning" data-not-applied="1"><div style="font-weight:600">Left alone</div>${notApplied.map((n) => `<div><span class="mono">${escapeHtml(n.repo)}</span>: ${escapeHtml(n.reason)}</div>`).join("")}</div>`
|
|
478
|
-
}${skippedOrgsHtml(result.skippedOrgs ?? [])}${renderOpenWorkByRepo(
|
|
570
|
+
}${skippedOrgsHtml(result.skippedOrgs ?? [], timezone)}${renderOpenWorkByRepo(
|
|
479
571
|
blocked,
|
|
480
572
|
"Open tasks and PRs that were blocked",
|
|
481
573
|
"No open tasks or PRs were blocked.",
|
|
482
|
-
)}${warningsHtml(result.warnings)}`;
|
|
574
|
+
)}${warningsHtml(withoutSkipWarnings(result.warnings, result.skippedOrgs ?? []))}`;
|
|
483
575
|
}
|
|
@@ -7,6 +7,7 @@ import { describe, expect, it } from "bun:test";
|
|
|
7
7
|
import {
|
|
8
8
|
APP_ID_MISMATCH_MESSAGE,
|
|
9
9
|
actuallyBlockedWork,
|
|
10
|
+
formatSyncTime,
|
|
10
11
|
NO_USERNAME_REASON,
|
|
11
12
|
renderGithubSyncCard,
|
|
12
13
|
renderInstallationReposBody,
|
|
@@ -256,6 +257,186 @@ describe("renderSyncResult", () => {
|
|
|
256
257
|
});
|
|
257
258
|
});
|
|
258
259
|
|
|
260
|
+
describe("skipped orgs and the in-sync state", () => {
|
|
261
|
+
const skipped = [{ org: "zed", reason: "access listing is incomplete" }];
|
|
262
|
+
const dupe = "zed: skipped (access listing is incomplete)";
|
|
263
|
+
|
|
264
|
+
it("warns, not in-sync, when every org was skipped and nothing changes", () => {
|
|
265
|
+
const html = renderSyncConfirm("a1", {
|
|
266
|
+
status: "previewed",
|
|
267
|
+
appAdds: [],
|
|
268
|
+
appRemoves: [],
|
|
269
|
+
agentRemoves: [],
|
|
270
|
+
skippedOrgs: skipped,
|
|
271
|
+
warnings: [dupe],
|
|
272
|
+
});
|
|
273
|
+
expect(html).toContain('data-sync="nothing-synced"');
|
|
274
|
+
expect(html).toContain("Nothing was synced: 1 org(s) skipped, see below");
|
|
275
|
+
expect(html).not.toContain('data-sync="in-sync"');
|
|
276
|
+
expect(html).not.toContain("Already in sync");
|
|
277
|
+
expect(html).toContain('data-skipped-orgs="1"');
|
|
278
|
+
expect(html).not.toContain("github-sync-confirm-btn");
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
it("still confirms changes when some orgs were skipped", () => {
|
|
282
|
+
const html = renderSyncConfirm("a1", {
|
|
283
|
+
status: "previewed",
|
|
284
|
+
appAdds: ["acme/new"],
|
|
285
|
+
skippedOrgs: skipped,
|
|
286
|
+
warnings: [dupe],
|
|
287
|
+
});
|
|
288
|
+
expect(html).toContain('data-sync="confirm"');
|
|
289
|
+
expect(html).toContain('data-skipped-orgs="1"');
|
|
290
|
+
expect(html).not.toContain('data-sync="nothing-synced"');
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
it("keeps the green in-sync state when no org was skipped", () => {
|
|
294
|
+
const html = renderSyncConfirm("a1", {
|
|
295
|
+
status: "previewed",
|
|
296
|
+
appAdds: [],
|
|
297
|
+
appRemoves: [],
|
|
298
|
+
agentRemoves: [],
|
|
299
|
+
skippedOrgs: [],
|
|
300
|
+
});
|
|
301
|
+
expect(html).toContain('data-sync="in-sync"');
|
|
302
|
+
expect(html).not.toContain("nothing-synced");
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
it("reports a skipped org once in the preview, keeping other warnings", () => {
|
|
306
|
+
const html = renderSyncConfirm("a1", {
|
|
307
|
+
status: "previewed",
|
|
308
|
+
appAdds: ["acme/new"],
|
|
309
|
+
skippedOrgs: skipped,
|
|
310
|
+
warnings: [dupe, "other warning"],
|
|
311
|
+
});
|
|
312
|
+
expect(html).not.toContain(dupe);
|
|
313
|
+
expect(html).toContain("other warning");
|
|
314
|
+
expect(html.match(/zed/g)).toHaveLength(1);
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
it("reports a skipped org once in the apply result, keeping other warnings", () => {
|
|
318
|
+
const html = renderSyncResult(
|
|
319
|
+
{
|
|
320
|
+
status: "applied",
|
|
321
|
+
skippedOrgs: skipped,
|
|
322
|
+
warnings: [dupe, "other warning"],
|
|
323
|
+
},
|
|
324
|
+
[],
|
|
325
|
+
);
|
|
326
|
+
expect(html).not.toContain(dupe);
|
|
327
|
+
expect(html).toContain("other warning");
|
|
328
|
+
expect(html).toContain('data-skipped-orgs="1"');
|
|
329
|
+
});
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
describe("skipped-org detail", () => {
|
|
333
|
+
const render = (detail?: Record<string, unknown>, org = "zed") =>
|
|
334
|
+
renderSyncConfirm("a1", {
|
|
335
|
+
status: "previewed",
|
|
336
|
+
appAdds: ["acme/new"],
|
|
337
|
+
skippedOrgs: [{ org, reason: "access listing is incomplete", detail }],
|
|
338
|
+
} as never);
|
|
339
|
+
const line = (html: string) =>
|
|
340
|
+
/data-skip-detail="1"[^>]*>([^<]*)</.exec(html)?.[1] ?? "";
|
|
341
|
+
|
|
342
|
+
it("renders exactly as before without detail", () => {
|
|
343
|
+
const html = render(undefined);
|
|
344
|
+
expect(html).toContain(
|
|
345
|
+
'<div><span class="mono">zed</span>: access listing is incomplete</div>',
|
|
346
|
+
);
|
|
347
|
+
expect(html).not.toContain("data-skip-detail");
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
it("renders a complete crawl with repos missing an answer", () => {
|
|
351
|
+
const html = render({
|
|
352
|
+
lookupSnapshotFound: true,
|
|
353
|
+
crawls: [{ completedAt: "2026-01-01T00:00:00.000Z" }],
|
|
354
|
+
totalRepos: 31,
|
|
355
|
+
reposWithOkAccess: 1,
|
|
356
|
+
reposMissingAnswer: 30,
|
|
357
|
+
});
|
|
358
|
+
expect(line(html)).toBe(
|
|
359
|
+
"Lookup crawl complete (31 repos). 30 repos have no access answer yet.",
|
|
360
|
+
);
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
it("renders a missing lookup snapshot", () => {
|
|
364
|
+
const html = render({ lookupSnapshotFound: false, crawls: [] });
|
|
365
|
+
expect(line(html)).toBe("Lookup crawl not found for this App.");
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
it("renders a failed crawl with the next attempt", () => {
|
|
369
|
+
const html = render({
|
|
370
|
+
lookupSnapshotFound: true,
|
|
371
|
+
crawls: [
|
|
372
|
+
{
|
|
373
|
+
completedAt: null,
|
|
374
|
+
lastError: "rate limited",
|
|
375
|
+
rateLimitResetAt: "2026-01-01T01:00:00.000Z",
|
|
376
|
+
},
|
|
377
|
+
],
|
|
378
|
+
});
|
|
379
|
+
expect(line(html)).toBe(
|
|
380
|
+
"Lookup crawl failed: rate limited; next attempt 2026-01-01 01:00 UTC.",
|
|
381
|
+
);
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
it("renders an incomplete crawl without an error", () => {
|
|
385
|
+
const html = render({ crawls: [{ completedAt: null }] });
|
|
386
|
+
expect(line(html)).toBe("Lookup crawl not complete yet.");
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
it("renders error rows, terminal rows, row errors and oldest check", () => {
|
|
390
|
+
const html = render({
|
|
391
|
+
lookupSnapshotFound: true,
|
|
392
|
+
crawls: [{ completedAt: "2026-01-01T00:00:00.000Z" }],
|
|
393
|
+
totalRepos: 5,
|
|
394
|
+
reposWithOkAccess: 2,
|
|
395
|
+
reposMissingAnswer: 3,
|
|
396
|
+
errorRows: 2,
|
|
397
|
+
terminalRows: 1,
|
|
398
|
+
maxAttempts: 4,
|
|
399
|
+
rowErrors: ["boom", "bang"],
|
|
400
|
+
oldestCheckedAt: "2025-12-01T00:00:00.000Z",
|
|
401
|
+
});
|
|
402
|
+
const t = line(html);
|
|
403
|
+
expect(t).toContain("Lookup crawl complete (5 repos).");
|
|
404
|
+
expect(t).toContain("3 repos have no access answer yet.");
|
|
405
|
+
expect(t).toContain("2 repos errored.");
|
|
406
|
+
expect(t).toContain("1 repo gave up (max 4 attempts).");
|
|
407
|
+
expect(t).toContain("Row errors: boom; bang.");
|
|
408
|
+
expect(t).toContain("Oldest check 2025-12-01 00:00 UTC.");
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
it("escapes lastError, rowErrors and org", () => {
|
|
412
|
+
const html = render(
|
|
413
|
+
{
|
|
414
|
+
crawls: [{ completedAt: null, lastError: "<script>x</script>" }],
|
|
415
|
+
rowErrors: ["<img onerror=1>"],
|
|
416
|
+
},
|
|
417
|
+
"<b>o</b>",
|
|
418
|
+
);
|
|
419
|
+
expect(html).not.toContain("<script>x");
|
|
420
|
+
expect(html).not.toContain("<img onerror");
|
|
421
|
+
expect(html).not.toContain("<b>o</b>");
|
|
422
|
+
expect(html).toContain("<script>x");
|
|
423
|
+
expect(html).toContain("<img onerror=1>");
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
it("renders in the apply result too", () => {
|
|
427
|
+
const html = renderSyncResult(
|
|
428
|
+
{
|
|
429
|
+
status: "applied",
|
|
430
|
+
skippedOrgs: [
|
|
431
|
+
{ org: "zed", reason: "r", detail: { lookupSnapshotFound: false } },
|
|
432
|
+
],
|
|
433
|
+
},
|
|
434
|
+
[],
|
|
435
|
+
);
|
|
436
|
+
expect(line(html)).toBe("Lookup crawl not found for this App.");
|
|
437
|
+
});
|
|
438
|
+
});
|
|
439
|
+
|
|
259
440
|
describe("renderInstallationSyncStatus debug detail", () => {
|
|
260
441
|
it("shows attempts, next attempt, lease holder and last tick on a failed snapshot, as an error", () => {
|
|
261
442
|
const html = renderInstallationSyncStatus({
|
|
@@ -302,3 +483,90 @@ describe("renderInstallationSyncStatus debug detail", () => {
|
|
|
302
483
|
expect(renderInstallationSyncStatus({})).toBe("");
|
|
303
484
|
});
|
|
304
485
|
});
|
|
486
|
+
|
|
487
|
+
describe("installation sync timestamps in the admin timezone", () => {
|
|
488
|
+
const PT = "America/Los_Angeles";
|
|
489
|
+
|
|
490
|
+
it("formats Pacific time with the zone abbreviation (PST)", () => {
|
|
491
|
+
expect(formatSyncTime("2026-11-24T01:02:00.000Z", PT)).toBe(
|
|
492
|
+
"Nov 23, 5:02 PM PST",
|
|
493
|
+
);
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
it("uses PDT on the summer side of the DST boundary", () => {
|
|
497
|
+
expect(formatSyncTime("2026-03-08T09:59:00.000Z", PT)).toBe(
|
|
498
|
+
"Mar 8, 1:59 AM PST",
|
|
499
|
+
);
|
|
500
|
+
expect(formatSyncTime("2026-03-08T10:00:00.000Z", PT)).toBe(
|
|
501
|
+
"Mar 8, 3:00 AM PDT",
|
|
502
|
+
);
|
|
503
|
+
expect(formatSyncTime("2026-11-01T08:59:00.000Z", PT)).toBe(
|
|
504
|
+
"Nov 1, 1:59 AM PDT",
|
|
505
|
+
);
|
|
506
|
+
expect(formatSyncTime("2026-11-01T09:00:00.000Z", PT)).toBe(
|
|
507
|
+
"Nov 1, 1:00 AM PST",
|
|
508
|
+
);
|
|
509
|
+
});
|
|
510
|
+
|
|
511
|
+
it("falls back to labelled UTC when no timezone is set", () => {
|
|
512
|
+
expect(formatSyncTime("2026-11-24T01:02:00.000Z")).toBe(
|
|
513
|
+
"2026-11-24 01:02 UTC",
|
|
514
|
+
);
|
|
515
|
+
});
|
|
516
|
+
|
|
517
|
+
it("renders the sync status line in the timezone", () => {
|
|
518
|
+
const html = renderInstallationSyncStatus(
|
|
519
|
+
{
|
|
520
|
+
complete: false,
|
|
521
|
+
syncedAt: "2026-11-24T01:02:00.000Z",
|
|
522
|
+
rateLimitResetAt: "2026-11-24T02:00:00.000Z",
|
|
523
|
+
nextAttemptAt: "2026-11-24T02:30:00.000Z",
|
|
524
|
+
lastTickAt: "2026-11-24T01:00:00.000Z",
|
|
525
|
+
},
|
|
526
|
+
PT,
|
|
527
|
+
);
|
|
528
|
+
expect(html).toContain("Synced Nov 23, 5:02 PM PST");
|
|
529
|
+
expect(html).toContain("GitHub rate limit resets Nov 23, 6:00 PM PST");
|
|
530
|
+
expect(html).toContain("Next attempt Nov 23, 6:30 PM PST");
|
|
531
|
+
expect(html).toContain("Last tick Nov 23, 5:00 PM PST");
|
|
532
|
+
expect(html).not.toContain("UTC");
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
it("keeps UTC in the sync status line when unset", () => {
|
|
536
|
+
expect(
|
|
537
|
+
renderInstallationSyncStatus({
|
|
538
|
+
complete: true,
|
|
539
|
+
syncedAt: "2026-11-24T01:02:00.000Z",
|
|
540
|
+
}),
|
|
541
|
+
).toContain("Synced 2026-11-24 01:02 UTC");
|
|
542
|
+
});
|
|
543
|
+
|
|
544
|
+
it("renders skipped-org detail times in the timezone", () => {
|
|
545
|
+
const html = renderSyncConfirm(
|
|
546
|
+
"a1",
|
|
547
|
+
{
|
|
548
|
+
status: "previewed",
|
|
549
|
+
appAdds: ["acme/new"],
|
|
550
|
+
skippedOrgs: [
|
|
551
|
+
{
|
|
552
|
+
org: "zed",
|
|
553
|
+
reason: "access listing is incomplete",
|
|
554
|
+
detail: {
|
|
555
|
+
crawls: [
|
|
556
|
+
{
|
|
557
|
+
completedAt: null,
|
|
558
|
+
lastError: "rate limited",
|
|
559
|
+
rateLimitResetAt: "2026-11-24T01:02:00.000Z",
|
|
560
|
+
},
|
|
561
|
+
],
|
|
562
|
+
oldestCheckedAt: "2026-07-01T19:00:00.000Z",
|
|
563
|
+
},
|
|
564
|
+
},
|
|
565
|
+
],
|
|
566
|
+
} as never,
|
|
567
|
+
PT,
|
|
568
|
+
);
|
|
569
|
+
expect(html).toContain("next attempt Nov 23, 5:02 PM PST");
|
|
570
|
+
expect(html).toContain("Oldest check Jul 1, 12:00 PM PDT");
|
|
571
|
+
});
|
|
572
|
+
});
|