@app-vitals/agent-admin 1.82.0 → 1.84.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 +115 -1
- package/package.json +2 -2
- package/src/admin-boot.ts +14 -3
- package/src/admin-ui-github-refresh.smoke.test.ts +96 -0
- package/src/admin-ui-installation-repos-pages.ts +51 -3
- package/src/admin-ui-installation-repos-pages.unit.test.ts +49 -1
- package/src/admin-ui-pages.ts +1 -0
- package/src/admin-ui.ts +40 -5
- package/src/agents-api.smoke.test.ts +39 -2
- package/src/agents-api.ts +28 -1
- package/src/github-enterprise-api.smoke.test.ts +73 -0
- package/src/github-enterprise-api.ts +51 -0
- package/src/github-installation-wiring.ts +61 -1
- package/src/github-installation-wiring.unit.test.ts +55 -3
- package/src/github-installation.fixtures.ts +44 -3
- package/src/github-refresh-action.ts +45 -0
- package/src/github-refresh-action.unit.test.ts +121 -0
- package/src/github-repo-cache.ts +52 -0
- package/src/github-repo-refresher.ts +5 -0
- package/src/github-sync-cache.integration.test.ts +134 -0
- package/src/github-sync-cached-access.ts +125 -0
- package/src/github-sync-reverify.unit.test.ts +138 -0
- package/src/github-sync.ts +174 -8
- package/src/installation-repos-service.ts +70 -1
- package/src/installation-repos-service.unit.test.ts +34 -0
- package/src/repo-access-rules.ts +13 -1
package/openapi.platform.json
CHANGED
|
@@ -3551,6 +3551,22 @@
|
|
|
3551
3551
|
"type": "string",
|
|
3552
3552
|
"description": "When the GitHub rate limit resets (ISO 8601)."
|
|
3553
3553
|
},
|
|
3554
|
+
"attempts": {
|
|
3555
|
+
"type": "integer",
|
|
3556
|
+
"description": "Failed refresh attempts; absent when zero."
|
|
3557
|
+
},
|
|
3558
|
+
"nextAttemptAt": {
|
|
3559
|
+
"type": "string",
|
|
3560
|
+
"description": "Next refresh attempt while backing off (ISO 8601)."
|
|
3561
|
+
},
|
|
3562
|
+
"leaseHolder": {
|
|
3563
|
+
"type": "string",
|
|
3564
|
+
"description": "Holder of a live refresh lease, if any."
|
|
3565
|
+
},
|
|
3566
|
+
"lastTickAt": {
|
|
3567
|
+
"type": "string",
|
|
3568
|
+
"description": "Last refresh tick on the snapshot (ISO 8601)."
|
|
3569
|
+
},
|
|
3554
3570
|
"orgs": {
|
|
3555
3571
|
"type": "array",
|
|
3556
3572
|
"items": {
|
|
@@ -3582,6 +3598,22 @@
|
|
|
3582
3598
|
"type": "string",
|
|
3583
3599
|
"description": "When the GitHub rate limit resets (ISO 8601)."
|
|
3584
3600
|
},
|
|
3601
|
+
"attempts": {
|
|
3602
|
+
"type": "integer",
|
|
3603
|
+
"description": "Failed refresh attempts; absent when zero."
|
|
3604
|
+
},
|
|
3605
|
+
"nextAttemptAt": {
|
|
3606
|
+
"type": "string",
|
|
3607
|
+
"description": "Next refresh attempt while backing off (ISO 8601)."
|
|
3608
|
+
},
|
|
3609
|
+
"leaseHolder": {
|
|
3610
|
+
"type": "string",
|
|
3611
|
+
"description": "Holder of a live refresh lease, if any."
|
|
3612
|
+
},
|
|
3613
|
+
"lastTickAt": {
|
|
3614
|
+
"type": "string",
|
|
3615
|
+
"description": "Last refresh tick on the snapshot (ISO 8601)."
|
|
3616
|
+
},
|
|
3585
3617
|
"repos": {
|
|
3586
3618
|
"type": "array",
|
|
3587
3619
|
"items": {
|
|
@@ -3593,6 +3625,18 @@
|
|
|
3593
3625
|
"userCanPush": {
|
|
3594
3626
|
"type": "boolean",
|
|
3595
3627
|
"description": "Whether the agent's bound GitHub user can push, from cached access rows. Omitted when no username is bound or the org's access data is incomplete (a missing or errored pair is never reported as false)."
|
|
3628
|
+
},
|
|
3629
|
+
"accessCheckedAt": {
|
|
3630
|
+
"type": "string",
|
|
3631
|
+
"description": "When the bound user's access to this repo was last checked (ISO 8601), when a cached row exists."
|
|
3632
|
+
},
|
|
3633
|
+
"accessAttempts": {
|
|
3634
|
+
"type": "integer",
|
|
3635
|
+
"description": "Failed access checks for this repo since the last success, when any."
|
|
3636
|
+
},
|
|
3637
|
+
"accessError": {
|
|
3638
|
+
"type": "string",
|
|
3639
|
+
"description": "Last access-check error for this repo, when any."
|
|
3596
3640
|
}
|
|
3597
3641
|
},
|
|
3598
3642
|
"required": [
|
|
@@ -3665,7 +3709,7 @@
|
|
|
3665
3709
|
"reason"
|
|
3666
3710
|
]
|
|
3667
3711
|
},
|
|
3668
|
-
"description": "Orgs whose access listing is missing, partial or failed, or whose lookup App is not installed or installed on selected repositories only; nothing there is added or removed."
|
|
3712
|
+
"description": "Orgs whose access listing is missing, partial or failed, whose cached access data is incomplete or stale, or whose lookup App is not installed or installed on selected repositories only; nothing there is added or removed. `reason` says why (for stale data, when it was checked)."
|
|
3669
3713
|
},
|
|
3670
3714
|
"openWork": {
|
|
3671
3715
|
"type": "array",
|
|
@@ -8454,6 +8498,76 @@
|
|
|
8454
8498
|
}
|
|
8455
8499
|
}
|
|
8456
8500
|
},
|
|
8501
|
+
"/github-enterprise/refresh": {
|
|
8502
|
+
"post": {
|
|
8503
|
+
"tags": [
|
|
8504
|
+
"github-enterprise"
|
|
8505
|
+
],
|
|
8506
|
+
"summary": "Request a refresh of the GitHub cache",
|
|
8507
|
+
"description": "Admin-only. Marks the cached GitHub repo lists stale and clears retry waits so the background refresher works them next, then returns at once. It makes no GitHub call and does not wait for the refresher; reload the page to see progress. The refresher still honours its per-org lease and rate-limit window.",
|
|
8508
|
+
"responses": {
|
|
8509
|
+
"202": {
|
|
8510
|
+
"description": "Refresh requested",
|
|
8511
|
+
"content": {
|
|
8512
|
+
"application/json": {
|
|
8513
|
+
"schema": {
|
|
8514
|
+
"type": "object",
|
|
8515
|
+
"properties": {
|
|
8516
|
+
"status": {
|
|
8517
|
+
"type": "string",
|
|
8518
|
+
"enum": [
|
|
8519
|
+
"accepted"
|
|
8520
|
+
]
|
|
8521
|
+
},
|
|
8522
|
+
"snapshots": {
|
|
8523
|
+
"type": "integer"
|
|
8524
|
+
},
|
|
8525
|
+
"accessPairs": {
|
|
8526
|
+
"type": "integer"
|
|
8527
|
+
}
|
|
8528
|
+
},
|
|
8529
|
+
"required": [
|
|
8530
|
+
"status",
|
|
8531
|
+
"snapshots",
|
|
8532
|
+
"accessPairs"
|
|
8533
|
+
]
|
|
8534
|
+
}
|
|
8535
|
+
}
|
|
8536
|
+
}
|
|
8537
|
+
},
|
|
8538
|
+
"401": {
|
|
8539
|
+
"description": "Unauthorized",
|
|
8540
|
+
"content": {
|
|
8541
|
+
"application/json": {
|
|
8542
|
+
"schema": {
|
|
8543
|
+
"$ref": "#/components/schemas/Error"
|
|
8544
|
+
}
|
|
8545
|
+
}
|
|
8546
|
+
}
|
|
8547
|
+
},
|
|
8548
|
+
"403": {
|
|
8549
|
+
"description": "Forbidden (non-admin caller)",
|
|
8550
|
+
"content": {
|
|
8551
|
+
"application/json": {
|
|
8552
|
+
"schema": {
|
|
8553
|
+
"$ref": "#/components/schemas/Error"
|
|
8554
|
+
}
|
|
8555
|
+
}
|
|
8556
|
+
}
|
|
8557
|
+
},
|
|
8558
|
+
"503": {
|
|
8559
|
+
"description": "Refresh is not available",
|
|
8560
|
+
"content": {
|
|
8561
|
+
"application/json": {
|
|
8562
|
+
"schema": {
|
|
8563
|
+
"$ref": "#/components/schemas/Error"
|
|
8564
|
+
}
|
|
8565
|
+
}
|
|
8566
|
+
}
|
|
8567
|
+
}
|
|
8568
|
+
}
|
|
8569
|
+
}
|
|
8570
|
+
},
|
|
8457
8571
|
"/github-enterprise/apps/{role}/validate": {
|
|
8458
8572
|
"post": {
|
|
8459
8573
|
"tags": [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@app-vitals/agent-admin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.84.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/app-vitals/agent.git",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@anthropic-ai/sdk": "0.137.0",
|
|
46
|
-
"@app-vitals/agent-lib": "1.
|
|
46
|
+
"@app-vitals/agent-lib": "1.84.0",
|
|
47
47
|
"@hono/zod-openapi": "^1.0.0",
|
|
48
48
|
"@prisma/adapter-pg": "^7.10.0",
|
|
49
49
|
"@prisma/client": "^7.10.0",
|
package/src/admin-boot.ts
CHANGED
|
@@ -116,18 +116,19 @@ import {
|
|
|
116
116
|
createGithubSync,
|
|
117
117
|
createStoredAppRefreshDiscovery,
|
|
118
118
|
} from "./github-installation-wiring.ts";
|
|
119
|
+
import { createGithubRefreshAction } from "./github-refresh-action.ts";
|
|
119
120
|
import { GitHubRepoCacheService } from "./github-repo-cache.ts";
|
|
120
121
|
import {
|
|
121
122
|
GithubRepoRefresher,
|
|
122
123
|
resolveRefreshConfig,
|
|
123
124
|
} from "./github-repo-refresher.ts";
|
|
124
|
-
import { PrincipalLookupService } from "./principal-lookup.ts";
|
|
125
|
-
import { createPrincipalsApp } from "./principals-api.ts";
|
|
126
125
|
import { HttpGoogleAuthClient } from "./google-auth-client.ts";
|
|
127
126
|
import { HttpChatClient } from "./http-chat-client.ts";
|
|
128
127
|
import { HttpOktaAuthClient } from "./okta-auth-client.ts";
|
|
129
128
|
import { mountPlatformDoc } from "./platform-doc-route.ts";
|
|
130
129
|
import { parsePodServiceAccountConfig } from "./pod-service-account-config.ts";
|
|
130
|
+
import { PrincipalLookupService } from "./principal-lookup.ts";
|
|
131
|
+
import { createPrincipalsApp } from "./principals-api.ts";
|
|
131
132
|
import { createAdminPrismaClient } from "./prisma-client.ts";
|
|
132
133
|
import { isPushEnabled } from "./push-sender.ts";
|
|
133
134
|
import { PushService } from "./push-service.ts";
|
|
@@ -649,7 +650,17 @@ export async function startAdmin(
|
|
|
649
650
|
// 3b'. GitHub Enterprise Apps API — /github-enterprise/* — admin-only,
|
|
650
651
|
// optional (GHE-1.3). With no rows configured it reports unconfigured
|
|
651
652
|
// and does nothing else. Strict crypto: no plain-text key storage.
|
|
653
|
+
// GLC-2.4: the Refresh action marks the cache stale (DB only). It asks the
|
|
654
|
+
// refresher (created further down) to re-discover through this hook.
|
|
655
|
+
const githubRefreshConfig = resolveRefreshConfig(process.env);
|
|
656
|
+
let invalidateGithubDiscovery: () => void = () => {};
|
|
657
|
+
const githubRefreshAction = createGithubRefreshAction({
|
|
658
|
+
cache: githubRepoCache,
|
|
659
|
+
stalenessCapMs: githubRefreshConfig.stalenessCapMs,
|
|
660
|
+
onMarked: () => invalidateGithubDiscovery(),
|
|
661
|
+
});
|
|
652
662
|
const githubEnterpriseApp = createGithubEnterpriseApp({
|
|
663
|
+
refreshAction: githubRefreshAction,
|
|
653
664
|
appService: githubEnterpriseAppService,
|
|
654
665
|
agentService,
|
|
655
666
|
agentEnvService,
|
|
@@ -860,7 +871,6 @@ export async function startAdmin(
|
|
|
860
871
|
// replica work an org at a time. Without stored GitHub Apps discovery finds
|
|
861
872
|
// nothing and every tick is idle.
|
|
862
873
|
{
|
|
863
|
-
const githubRefreshConfig = resolveRefreshConfig(process.env);
|
|
864
874
|
const githubRepoRefresher = new GithubRepoRefresher({
|
|
865
875
|
discovery: createStoredAppRefreshDiscovery({
|
|
866
876
|
prisma,
|
|
@@ -872,6 +882,7 @@ export async function startAdmin(
|
|
|
872
882
|
store: githubRepoCache,
|
|
873
883
|
config: githubRefreshConfig,
|
|
874
884
|
});
|
|
885
|
+
invalidateGithubDiscovery = () => githubRepoRefresher.invalidateDiscovery();
|
|
875
886
|
setInterval(() => {
|
|
876
887
|
githubRepoRefresher
|
|
877
888
|
.tick()
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* admin/src/admin-ui-github-refresh.smoke.test.ts
|
|
3
|
+
* GLC-2.4: the Refresh button on the agent GitHub card and its POST route:
|
|
4
|
+
* admin only, redirects at once, and makes no GitHub call (the enterprise API
|
|
5
|
+
* is a stub that records paths). No DB, no network.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { beforeAll, describe, expect, it } from "bun:test";
|
|
9
|
+
import {
|
|
10
|
+
AGENT_ID,
|
|
11
|
+
makeMockDeps,
|
|
12
|
+
makeSessionCookie,
|
|
13
|
+
} from "./admin-ui.fixtures.ts";
|
|
14
|
+
import { createAdminUIApp } from "./admin-ui.ts";
|
|
15
|
+
|
|
16
|
+
const json = (b: unknown, status = 200) =>
|
|
17
|
+
new Response(JSON.stringify(b), {
|
|
18
|
+
status,
|
|
19
|
+
headers: { "Content-Type": "application/json" },
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
function setup(refreshStatus = 202) {
|
|
23
|
+
const paths: string[] = [];
|
|
24
|
+
const deps = makeMockDeps({
|
|
25
|
+
githubEnterpriseApi: (path: string, init?: RequestInit) => {
|
|
26
|
+
paths.push(`${init?.method ?? "GET"} ${path}`);
|
|
27
|
+
if (path === "/github-enterprise/refresh") {
|
|
28
|
+
return refreshStatus === 202
|
|
29
|
+
? json({ status: "accepted", snapshots: 1, accessPairs: 0 }, 202)
|
|
30
|
+
: json({ error: "nope" }, refreshStatus);
|
|
31
|
+
}
|
|
32
|
+
return json({
|
|
33
|
+
configured: true,
|
|
34
|
+
installer: { role: "installer" },
|
|
35
|
+
lookup: { role: "lookup" },
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
agentsApi: () => json({ appId: 1, orgs: [] }),
|
|
39
|
+
} as never);
|
|
40
|
+
return { app: createAdminUIApp(deps), paths };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
describe("admin UI — GitHub cache Refresh (GLC-2.4)", () => {
|
|
44
|
+
let admin: string;
|
|
45
|
+
let member: string;
|
|
46
|
+
beforeAll(async () => {
|
|
47
|
+
admin = await makeSessionCookie();
|
|
48
|
+
member = await makeSessionCookie(
|
|
49
|
+
undefined,
|
|
50
|
+
"sub-2",
|
|
51
|
+
"other@example.com",
|
|
52
|
+
false,
|
|
53
|
+
);
|
|
54
|
+
});
|
|
55
|
+
const h = (cookie: string) => ({ Cookie: `admin_session=${cookie}` });
|
|
56
|
+
const refresh = (app: ReturnType<typeof setup>["app"], c = admin) =>
|
|
57
|
+
app.request(`/admin/agents/${AGENT_ID}/github-cache/refresh`, {
|
|
58
|
+
method: "POST",
|
|
59
|
+
headers: h(c),
|
|
60
|
+
redirect: "manual",
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("shows the Refresh button on the agent GitHub card", async () => {
|
|
64
|
+
const { app } = setup();
|
|
65
|
+
const html = await (
|
|
66
|
+
await app.request(`/admin/agents/${AGENT_ID}/access`, {
|
|
67
|
+
headers: h(admin),
|
|
68
|
+
})
|
|
69
|
+
).text();
|
|
70
|
+
expect(html).toContain('id="github-refresh-btn"');
|
|
71
|
+
expect(html).toContain(`/admin/agents/${AGENT_ID}/github-cache/refresh`);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("redirects an admin with 302 after one refresh call", async () => {
|
|
75
|
+
const { app, paths } = setup();
|
|
76
|
+
const res = await refresh(app);
|
|
77
|
+
expect(res.status).toBe(302);
|
|
78
|
+
expect(res.headers.get("location")).toContain(
|
|
79
|
+
"success=github_refresh_requested",
|
|
80
|
+
);
|
|
81
|
+
expect(paths).toEqual(["POST /github-enterprise/refresh"]);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("redirects with an error when the API refuses", async () => {
|
|
85
|
+
const { app } = setup(503);
|
|
86
|
+
const res = await refresh(app);
|
|
87
|
+
expect(res.status).toBe(302);
|
|
88
|
+
expect(res.headers.get("location")).toContain("error=");
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("is forbidden for a non-admin and calls nothing", async () => {
|
|
92
|
+
const { app, paths } = setup();
|
|
93
|
+
expect((await refresh(app, member)).status).toBe(403);
|
|
94
|
+
expect(paths).toEqual([]);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
@@ -32,13 +32,23 @@ export interface InstallationSyncView {
|
|
|
32
32
|
totalCount?: number;
|
|
33
33
|
lastError?: string;
|
|
34
34
|
rateLimitResetAt?: string;
|
|
35
|
+
attempts?: number;
|
|
36
|
+
nextAttemptAt?: string;
|
|
37
|
+
leaseHolder?: string;
|
|
38
|
+
lastTickAt?: string;
|
|
35
39
|
}
|
|
36
40
|
|
|
37
41
|
export interface InstallationReposView extends InstallationSyncView {
|
|
38
42
|
appId?: number;
|
|
39
43
|
orgs: ({
|
|
40
44
|
org: string;
|
|
41
|
-
repos: {
|
|
45
|
+
repos: {
|
|
46
|
+
fullName: string;
|
|
47
|
+
userCanPush?: boolean;
|
|
48
|
+
accessCheckedAt?: string;
|
|
49
|
+
accessAttempts?: number;
|
|
50
|
+
accessError?: string;
|
|
51
|
+
}[];
|
|
42
52
|
} & InstallationSyncView)[];
|
|
43
53
|
}
|
|
44
54
|
|
|
@@ -53,7 +63,14 @@ const hasSyncDetail = (v: InstallationSyncView): boolean =>
|
|
|
53
63
|
v.syncedAt !== undefined ||
|
|
54
64
|
v.reposSeen !== undefined ||
|
|
55
65
|
v.lastError !== undefined ||
|
|
56
|
-
v.rateLimitResetAt !== undefined
|
|
66
|
+
v.rateLimitResetAt !== undefined ||
|
|
67
|
+
v.attempts !== undefined ||
|
|
68
|
+
v.nextAttemptAt !== undefined ||
|
|
69
|
+
v.leaseHolder !== undefined ||
|
|
70
|
+
v.lastTickAt !== undefined;
|
|
71
|
+
|
|
72
|
+
const utc = (iso: string): string =>
|
|
73
|
+
`${escapeHtml(iso.slice(0, 16).replace("T", " "))} UTC`;
|
|
57
74
|
|
|
58
75
|
/**
|
|
59
76
|
* One-line sync status: synced-at, "N of M repos", last error and the rate-limit
|
|
@@ -83,6 +100,14 @@ export function renderInstallationSyncStatus(v: InstallationSyncView): string {
|
|
|
83
100
|
`GitHub rate limit resets ${escapeHtml(v.rateLimitResetAt.slice(0, 16).replace("T", " "))} UTC`,
|
|
84
101
|
);
|
|
85
102
|
}
|
|
103
|
+
if (v.attempts) {
|
|
104
|
+
parts.push(
|
|
105
|
+
`${v.attempts} failed ${v.attempts === 1 ? "attempt" : "attempts"}`,
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
if (v.nextAttemptAt) parts.push(`Next attempt ${utc(v.nextAttemptAt)}`);
|
|
109
|
+
if (v.leaseHolder) parts.push(`Refreshing (${escapeHtml(v.leaseHolder)})`);
|
|
110
|
+
if (v.lastTickAt) parts.push(`Last tick ${utc(v.lastTickAt)}`);
|
|
86
111
|
const cls = v.lastError || v.rateLimitResetAt ? "alert alert-warning" : "";
|
|
87
112
|
return `<div class="${cls}" data-installation-sync="${complete ? "complete" : "incomplete"}" style="color:#6b7280;font-size:12px;margin:8px 0">${parts.join(" · ")}</div>`;
|
|
88
113
|
}
|
|
@@ -197,9 +222,11 @@ export function renderGithubSyncCard(
|
|
|
197
222
|
const loader = state.hasAppId
|
|
198
223
|
? `<div id="github-installation-body">Loading...</div>`
|
|
199
224
|
: "";
|
|
225
|
+
const refresh = `<div style="margin:0 0 12px"><button type="button" class="btn btn-secondary" id="github-refresh-btn" data-url="/admin/agents/${id}/github-cache/refresh">Refresh</button> <span style="color:#6b7280;font-size:12px">Re-reads the cached repo lists in the background. Reload the page to see progress.</span></div>`;
|
|
200
226
|
return `<div id="github-installation-card" data-base-url="${base}" style="margin-top:20px">
|
|
201
227
|
<div class="form-label" style="font-weight:600;margin-bottom:6px">GitHub sync</div>
|
|
202
228
|
<p style="color:#6b7280;font-size:12px;margin:0 0 12px">Brings this agent's App installation and its repos in line with what the bound GitHub user can push to.</p>
|
|
229
|
+
${refresh}
|
|
203
230
|
${action}
|
|
204
231
|
${loader}
|
|
205
232
|
<script>
|
|
@@ -216,6 +243,15 @@ export function renderGithubSyncCard(
|
|
|
216
243
|
.then(function(t) { body.innerHTML = t; })
|
|
217
244
|
.catch(function() { body.textContent = 'The request failed.'; });
|
|
218
245
|
}
|
|
246
|
+
var refreshBtn = document.getElementById('github-refresh-btn');
|
|
247
|
+
if (refreshBtn) {
|
|
248
|
+
refreshBtn.addEventListener('click', function() {
|
|
249
|
+
refreshBtn.disabled = true;
|
|
250
|
+
fetch(refreshBtn.getAttribute('data-url'), { method: 'POST', credentials: 'same-origin' })
|
|
251
|
+
.then(function(r) { window.location.href = r.url; })
|
|
252
|
+
.catch(function() { refreshBtn.disabled = false; });
|
|
253
|
+
});
|
|
254
|
+
}
|
|
219
255
|
if (!out) return;
|
|
220
256
|
card.addEventListener('click', function(e) {
|
|
221
257
|
var t = e.target;
|
|
@@ -280,7 +316,19 @@ export function renderInstallationReposBody(
|
|
|
280
316
|
: r.userCanPush
|
|
281
317
|
? '<span class="badge badge-green" title="The bound user can push">user can push</span>'
|
|
282
318
|
: '<span class="badge badge-warning" title="The bound user cannot push">user cannot push</span>';
|
|
283
|
-
|
|
319
|
+
const detail = [
|
|
320
|
+
r.accessCheckedAt
|
|
321
|
+
? `checked ${escapeHtml(r.accessCheckedAt)}`
|
|
322
|
+
: "",
|
|
323
|
+
r.accessAttempts
|
|
324
|
+
? `${r.accessAttempts} failed attempts`
|
|
325
|
+
: "",
|
|
326
|
+
r.accessError ? `error: ${escapeHtml(r.accessError)}` : "",
|
|
327
|
+
].filter(Boolean);
|
|
328
|
+
const meta = detail.length
|
|
329
|
+
? ` <span style="color:#6b7280;font-size:12px">${detail.join("; ")}</span>`
|
|
330
|
+
: "";
|
|
331
|
+
return `<tr><td class="mono">${escapeHtml(r.fullName)}</td><td>${hint}${meta}</td></tr>`;
|
|
284
332
|
})
|
|
285
333
|
.join("");
|
|
286
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>`;
|
|
@@ -5,11 +5,12 @@
|
|
|
5
5
|
|
|
6
6
|
import { describe, expect, it } from "bun:test";
|
|
7
7
|
import {
|
|
8
|
-
actuallyBlockedWork,
|
|
9
8
|
APP_ID_MISMATCH_MESSAGE,
|
|
9
|
+
actuallyBlockedWork,
|
|
10
10
|
NO_USERNAME_REASON,
|
|
11
11
|
renderGithubSyncCard,
|
|
12
12
|
renderInstallationReposBody,
|
|
13
|
+
renderInstallationSyncStatus,
|
|
13
14
|
renderOpenWorkByRepo,
|
|
14
15
|
renderSyncConfirm,
|
|
15
16
|
renderSyncResult,
|
|
@@ -254,3 +255,50 @@ describe("renderSyncResult", () => {
|
|
|
254
255
|
).toContain("no user");
|
|
255
256
|
});
|
|
256
257
|
});
|
|
258
|
+
|
|
259
|
+
describe("renderInstallationSyncStatus debug detail", () => {
|
|
260
|
+
it("shows attempts, next attempt, lease holder and last tick on a failed snapshot, as an error", () => {
|
|
261
|
+
const html = renderInstallationSyncStatus({
|
|
262
|
+
complete: false,
|
|
263
|
+
reposSeen: 3,
|
|
264
|
+
totalCount: 10,
|
|
265
|
+
lastError: "boom <b>",
|
|
266
|
+
attempts: 3,
|
|
267
|
+
nextAttemptAt: "2026-11-21T10:30:00.000Z",
|
|
268
|
+
leaseHolder: "worker-1",
|
|
269
|
+
lastTickAt: "2026-11-21T10:00:00.000Z",
|
|
270
|
+
});
|
|
271
|
+
expect(html).toContain("alert alert-warning");
|
|
272
|
+
expect(html).toContain("Last error: boom <b>");
|
|
273
|
+
expect(html).toContain("3 failed attempts");
|
|
274
|
+
expect(html).toContain("Next attempt 2026-11-21 10:30 UTC");
|
|
275
|
+
expect(html).toContain("Refreshing (worker-1)");
|
|
276
|
+
expect(html).toContain("Last tick 2026-11-21 10:00 UTC");
|
|
277
|
+
expect(html).not.toContain("no access");
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
it("shows nothing misleading on a complete snapshot with unset fields", () => {
|
|
281
|
+
const html = renderInstallationSyncStatus({
|
|
282
|
+
complete: true,
|
|
283
|
+
syncedAt: "2026-11-21T10:00:00.000Z",
|
|
284
|
+
reposSeen: 2,
|
|
285
|
+
totalCount: 2,
|
|
286
|
+
});
|
|
287
|
+
expect(html).toContain("Synced 2026-11-21 10:00 UTC");
|
|
288
|
+
expect(html).toContain("2 of 2 repos");
|
|
289
|
+
expect(html).not.toMatch(/attempt|Refreshing|Last tick|error/i);
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
it("singularizes one attempt and ignores zero attempts", () => {
|
|
293
|
+
expect(
|
|
294
|
+
renderInstallationSyncStatus({ complete: true, attempts: 1 }),
|
|
295
|
+
).toContain("1 failed attempt<");
|
|
296
|
+
expect(
|
|
297
|
+
renderInstallationSyncStatus({ complete: true, attempts: 0 }),
|
|
298
|
+
).not.toContain("attempt");
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
it("renders nothing for an older API with no detail", () => {
|
|
302
|
+
expect(renderInstallationSyncStatus({})).toBe("");
|
|
303
|
+
});
|
|
304
|
+
});
|
package/src/admin-ui-pages.ts
CHANGED
|
@@ -1040,6 +1040,7 @@ export function agentSectionPath(
|
|
|
1040
1040
|
export const AGENT_POST_SECTIONS: Readonly<Record<string, AgentSection>> = {
|
|
1041
1041
|
"/github-username": "access",
|
|
1042
1042
|
"/github-sync/apply-confirmed": "access",
|
|
1043
|
+
"/github-cache/refresh": "access",
|
|
1043
1044
|
"/github-orgs/:org/install": "access",
|
|
1044
1045
|
"/repos/remove-confirmed": "configuration",
|
|
1045
1046
|
"/envs": "configuration",
|
package/src/admin-ui.ts
CHANGED
|
@@ -2139,6 +2139,35 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
2139
2139
|
);
|
|
2140
2140
|
});
|
|
2141
2141
|
|
|
2142
|
+
// GLC-2.4: fire-and-forget Refresh. Proxies the 202 API route and redirects
|
|
2143
|
+
// at once; a reload of the page shows progress.
|
|
2144
|
+
app.post("/admin/agents/:id/github-cache/refresh", requireAuth, async (c) => {
|
|
2145
|
+
const agentId = c.req.param("id");
|
|
2146
|
+
if (!c.var.isAdmin || !githubEnterpriseApi) {
|
|
2147
|
+
return new Response("Forbidden", { status: 403 });
|
|
2148
|
+
}
|
|
2149
|
+
const res = await callApi(
|
|
2150
|
+
c,
|
|
2151
|
+
githubEnterpriseApi,
|
|
2152
|
+
"/github-enterprise/refresh",
|
|
2153
|
+
{
|
|
2154
|
+
method: "POST",
|
|
2155
|
+
},
|
|
2156
|
+
);
|
|
2157
|
+
if (!res?.ok) {
|
|
2158
|
+
return c.redirect(
|
|
2159
|
+
agentSectionPath(agentId, "access", {
|
|
2160
|
+
error: await gheError(res, "Could not request a refresh."),
|
|
2161
|
+
}),
|
|
2162
|
+
302,
|
|
2163
|
+
);
|
|
2164
|
+
}
|
|
2165
|
+
return c.redirect(
|
|
2166
|
+
`${agentSectionPath(agentId, "access")}?success=github_refresh_requested`,
|
|
2167
|
+
302,
|
|
2168
|
+
);
|
|
2169
|
+
});
|
|
2170
|
+
|
|
2142
2171
|
app.post(
|
|
2143
2172
|
"/admin/agents/:id/github-orgs/:org/install",
|
|
2144
2173
|
requireAuth,
|
|
@@ -2467,11 +2496,13 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
2467
2496
|
? "GitHub username saved."
|
|
2468
2497
|
: successParam === "github_username_cleared"
|
|
2469
2498
|
? "GitHub username cleared."
|
|
2470
|
-
: successParam === "
|
|
2471
|
-
? "
|
|
2472
|
-
: successParam === "
|
|
2473
|
-
? "
|
|
2474
|
-
:
|
|
2499
|
+
: successParam === "github_refresh_requested"
|
|
2500
|
+
? "Refresh requested. Reload the page to see progress."
|
|
2501
|
+
: successParam === "github_app_installed"
|
|
2502
|
+
? "Agent app installed."
|
|
2503
|
+
: successParam === "github_app_already_installed"
|
|
2504
|
+
? "The agent app was already installed on that organization."
|
|
2505
|
+
: undefined;
|
|
2475
2506
|
const warningParam = c.req.query("warning");
|
|
2476
2507
|
const warning =
|
|
2477
2508
|
warningParam === "restrict_slack_no_members"
|
|
@@ -2537,6 +2568,10 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
2537
2568
|
totalCount: view.totalCount,
|
|
2538
2569
|
lastError: view.lastError,
|
|
2539
2570
|
rateLimitResetAt: view.rateLimitResetAt,
|
|
2571
|
+
attempts: view.attempts,
|
|
2572
|
+
nextAttemptAt: view.nextAttemptAt,
|
|
2573
|
+
leaseHolder: view.leaseHolder,
|
|
2574
|
+
lastTickAt: view.lastTickAt,
|
|
2540
2575
|
};
|
|
2541
2576
|
} catch {
|
|
2542
2577
|
// unknown: no coverage warning
|
|
@@ -7363,6 +7363,36 @@ describe("admin API — agent App installation repos and GitHub Sync (IRM-1.2, I
|
|
|
7363
7363
|
headers: { "Content-Type": "application/json" },
|
|
7364
7364
|
});
|
|
7365
7365
|
}) as typeof fetch;
|
|
7366
|
+
// Sync reads the cache (GLC-2.3): unless a test seeds its own rows, serve a
|
|
7367
|
+
// complete, fresh cache that mirrors `pushable` over the installed, agent
|
|
7368
|
+
// and pushable repos.
|
|
7369
|
+
const checkedAt = new Date();
|
|
7370
|
+
const pushableRepos = opts.pushable ?? [
|
|
7371
|
+
"acme-eng/repo-1",
|
|
7372
|
+
"acme-eng/repo-3",
|
|
7373
|
+
];
|
|
7374
|
+
const universe = [
|
|
7375
|
+
...new Set([...state.installed, ...state.repos, ...pushableRepos]),
|
|
7376
|
+
];
|
|
7377
|
+
const defaultSnapshots = [
|
|
7378
|
+
{
|
|
7379
|
+
org: "acme-eng",
|
|
7380
|
+
completedAt: checkedAt,
|
|
7381
|
+
totalCount: state.installed.length,
|
|
7382
|
+
lastError: null,
|
|
7383
|
+
rateLimitResetAt: null,
|
|
7384
|
+
repos: state.installed.map((fullName) => ({ fullName })),
|
|
7385
|
+
},
|
|
7386
|
+
];
|
|
7387
|
+
const defaultAccess = universe.map((f) => ({
|
|
7388
|
+
repo: f.split("/")[1],
|
|
7389
|
+
status: "ok",
|
|
7390
|
+
canPush: pushableRepos.includes(f),
|
|
7391
|
+
level: pushableRepos.includes(f) ? "write" : "none",
|
|
7392
|
+
checkedAt,
|
|
7393
|
+
attempts: 0,
|
|
7394
|
+
lastError: null,
|
|
7395
|
+
}));
|
|
7366
7396
|
const prisma = {
|
|
7367
7397
|
agent: {
|
|
7368
7398
|
findUnique: async () =>
|
|
@@ -7380,10 +7410,10 @@ describe("admin API — agent App installation repos and GitHub Sync (IRM-1.2, I
|
|
|
7380
7410
|
},
|
|
7381
7411
|
},
|
|
7382
7412
|
gitHubRepoSnapshot: {
|
|
7383
|
-
findMany: async () => opts.snapshots ??
|
|
7413
|
+
findMany: async () => opts.snapshots ?? defaultSnapshots,
|
|
7384
7414
|
},
|
|
7385
7415
|
gitHubRepoAccess: {
|
|
7386
|
-
findMany: async () => opts.accessRows ??
|
|
7416
|
+
findMany: async () => opts.accessRows ?? defaultAccess,
|
|
7387
7417
|
},
|
|
7388
7418
|
gitHubReconcileAudit: {
|
|
7389
7419
|
create: async (args: { data: Record<string, unknown> }) => {
|
|
@@ -7435,6 +7465,13 @@ describe("admin API — agent App installation repos and GitHub Sync (IRM-1.2, I
|
|
|
7435
7465
|
const githubSync = createGithubSync({
|
|
7436
7466
|
...wiring,
|
|
7437
7467
|
...(openWork ? { openWork } : {}),
|
|
7468
|
+
syncOverrides: {
|
|
7469
|
+
lookupRepos: async () => [
|
|
7470
|
+
{ org: "acme-eng", completedAt: checkedAt, repos: universe },
|
|
7471
|
+
],
|
|
7472
|
+
// The live permission call agrees with `pushable`.
|
|
7473
|
+
verifyPush: async (_user, repo) => pushableRepos.includes(repo),
|
|
7474
|
+
},
|
|
7438
7475
|
});
|
|
7439
7476
|
const base = makeMockDeps();
|
|
7440
7477
|
const app = createAdminApp({
|
package/src/agents-api.ts
CHANGED
|
@@ -665,6 +665,22 @@ const InstallationSyncDetailShape = {
|
|
|
665
665
|
.string()
|
|
666
666
|
.optional()
|
|
667
667
|
.openapi({ description: "When the GitHub rate limit resets (ISO 8601)." }),
|
|
668
|
+
attempts: z
|
|
669
|
+
.number()
|
|
670
|
+
.int()
|
|
671
|
+
.optional()
|
|
672
|
+
.openapi({ description: "Failed refresh attempts; absent when zero." }),
|
|
673
|
+
nextAttemptAt: z.string().optional().openapi({
|
|
674
|
+
description: "Next refresh attempt while backing off (ISO 8601).",
|
|
675
|
+
}),
|
|
676
|
+
leaseHolder: z
|
|
677
|
+
.string()
|
|
678
|
+
.optional()
|
|
679
|
+
.openapi({ description: "Holder of a live refresh lease, if any." }),
|
|
680
|
+
lastTickAt: z
|
|
681
|
+
.string()
|
|
682
|
+
.optional()
|
|
683
|
+
.openapi({ description: "Last refresh tick on the snapshot (ISO 8601)." }),
|
|
668
684
|
};
|
|
669
685
|
|
|
670
686
|
const GithubInstallationReposListSchema = z
|
|
@@ -682,6 +698,17 @@ const GithubInstallationReposListSchema = z
|
|
|
682
698
|
description:
|
|
683
699
|
"Whether the agent's bound GitHub user can push, from cached access rows. Omitted when no username is bound or the org's access data is incomplete (a missing or errored pair is never reported as false).",
|
|
684
700
|
}),
|
|
701
|
+
accessCheckedAt: z.string().optional().openapi({
|
|
702
|
+
description:
|
|
703
|
+
"When the bound user's access to this repo was last checked (ISO 8601), when a cached row exists.",
|
|
704
|
+
}),
|
|
705
|
+
accessAttempts: z.number().int().optional().openapi({
|
|
706
|
+
description:
|
|
707
|
+
"Failed access checks for this repo since the last success, when any.",
|
|
708
|
+
}),
|
|
709
|
+
accessError: z.string().optional().openapi({
|
|
710
|
+
description: "Last access-check error for this repo, when any.",
|
|
711
|
+
}),
|
|
685
712
|
}),
|
|
686
713
|
),
|
|
687
714
|
}),
|
|
@@ -719,7 +746,7 @@ const GithubSyncPreviewSchema = z
|
|
|
719
746
|
}),
|
|
720
747
|
skippedOrgs: SkippedOrgsSchema.optional().openapi({
|
|
721
748
|
description:
|
|
722
|
-
"Orgs whose access listing is missing, partial or failed, or whose lookup App is not installed or installed on selected repositories only; nothing there is added or removed.",
|
|
749
|
+
"Orgs whose access listing is missing, partial or failed, whose cached access data is incomplete or stale, or whose lookup App is not installed or installed on selected repositories only; nothing there is added or removed. `reason` says why (for stale data, when it was checked).",
|
|
723
750
|
}),
|
|
724
751
|
openWork: z.array(OpenWorkItemSchema).optional().openapi({
|
|
725
752
|
description:
|