@app-vitals/agent-admin 1.129.1 → 1.131.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/package.json +2 -2
- package/src/admin-boot.ts +2 -0
- package/src/admin-ui-info-tip.ts +31 -0
- package/src/admin-ui-info-tip.unit.test.ts +59 -0
- package/src/admin-ui-pages.ts +20 -6
- package/src/admin-ui-pages.unit.test.ts +23 -0
- package/src/admin-ui-styles.ts +34 -0
- package/src/admin-ui-styles.unit.test.ts +16 -0
- package/src/admin-ui.ts +36 -2
- package/src/agent-github-apps-api.smoke.test.ts +155 -0
- package/src/agent-github-apps.integration.test.ts +168 -0
- package/src/agent-github-apps.ts +157 -0
- package/src/agent-github-apps.unit.test.ts +34 -0
- package/src/agents-api.smoke.test.ts +101 -0
- package/src/agents-api.ts +76 -1
- package/src/github-enterprise-api.ts +14 -1
- package/src/github-provisioning-service.integration.test.ts +189 -0
- package/src/github-provisioning-service.ts +66 -29
- package/src/github-provisioning-service.unit.test.ts +114 -6
- package/src/github-sync-multi-app.integration.test.ts +122 -0
- package/src/github-sync-multi-app.unit.test.ts +156 -0
- package/src/github-sync.ts +59 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@app-vitals/agent-admin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.131.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.131.0",
|
|
48
48
|
"@hono/zod-openapi": "^1.0.0",
|
|
49
49
|
"@prisma/adapter-pg": "^7.10.0",
|
|
50
50
|
"@prisma/client": "^7.10.0",
|
package/src/admin-boot.ts
CHANGED
|
@@ -669,6 +669,7 @@ export async function startAdmin(
|
|
|
669
669
|
appService: githubEnterpriseAppService,
|
|
670
670
|
agentService,
|
|
671
671
|
agentEnvService,
|
|
672
|
+
agentGitHubAppService,
|
|
672
673
|
sessionSecret,
|
|
673
674
|
adminApiKeys,
|
|
674
675
|
agentTokenService,
|
|
@@ -707,6 +708,7 @@ export async function startAdmin(
|
|
|
707
708
|
const adminUIApp = createAdminUIApp({
|
|
708
709
|
prisma: prisma as never,
|
|
709
710
|
agentEnvService,
|
|
711
|
+
agentGitHubAppService,
|
|
710
712
|
agentCronJobService,
|
|
711
713
|
agentToolService,
|
|
712
714
|
agentTokenService,
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* admin/src/admin-ui-info-tip.ts
|
|
3
|
+
*
|
|
4
|
+
* Shared CSS-only info tooltip: a focusable ⓘ button plus a popover that opens
|
|
5
|
+
* on hover and keyboard focus. Styles live in baseStyles() (admin-ui-styles.ts).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { escapeHtml } from "@app-vitals/agent-lib/web/toolbar.ts";
|
|
9
|
+
|
|
10
|
+
/** Base URL for product docs links shown in info tooltips. */
|
|
11
|
+
export const ADMIN_DOCS_BASE_URL = "https://shipwrightharness.com/docs/";
|
|
12
|
+
|
|
13
|
+
export interface InfoTipOptions {
|
|
14
|
+
/** Unique id; becomes the popover element id (aria-describedby target). */
|
|
15
|
+
id: string;
|
|
16
|
+
/** Short subject name, used in the button's aria-label ("About {label}"). */
|
|
17
|
+
label: string;
|
|
18
|
+
/** Plain-text summary shown in the popover (escaped). */
|
|
19
|
+
summary: string;
|
|
20
|
+
/** Absolute URL for the "Learn more →" link. */
|
|
21
|
+
docsHref: string;
|
|
22
|
+
/** "end" opens the popover leftward (anchored to the right edge). */
|
|
23
|
+
align?: "start" | "end";
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Focusable info button + CSS popover with a docs link. */
|
|
27
|
+
export function renderInfoTip(opts: InfoTipOptions): string {
|
|
28
|
+
const id = escapeHtml(opts.id);
|
|
29
|
+
const alignClass = opts.align === "end" ? " info-tip-end" : "";
|
|
30
|
+
return `<span class="info-tip${alignClass}"><button type="button" class="info-tip-btn" onclick="event.preventDefault();event.stopPropagation()" aria-label="About ${escapeHtml(opts.label)}" aria-describedby="${id}">ⓘ</button><span role="tooltip" id="${id}" class="info-tip-pop">${escapeHtml(opts.summary)}<a href="${escapeHtml(opts.docsHref)}" target="_blank" rel="noopener">Learn more →</a></span></span>`;
|
|
31
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { ADMIN_DOCS_BASE_URL, renderInfoTip } from "./admin-ui-info-tip.ts";
|
|
3
|
+
|
|
4
|
+
const base = {
|
|
5
|
+
id: "tip-1",
|
|
6
|
+
label: "Widgets",
|
|
7
|
+
summary: "Explains widgets.",
|
|
8
|
+
docsHref: `${ADMIN_DOCS_BASE_URL}widgets`,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
describe("renderInfoTip", () => {
|
|
12
|
+
test("renders a button with aria wiring and a tooltip popover", () => {
|
|
13
|
+
const html = renderInfoTip(base);
|
|
14
|
+
expect(html).toContain('<button type="button" class="info-tip-btn"');
|
|
15
|
+
expect(html).toContain("ⓘ</button>");
|
|
16
|
+
expect(html).toContain('aria-label="About Widgets"');
|
|
17
|
+
expect(html).toContain('aria-describedby="tip-1"');
|
|
18
|
+
expect(html).toContain('role="tooltip" id="tip-1"');
|
|
19
|
+
expect(html).toContain("Explains widgets.");
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test("link opens a new tab safely", () => {
|
|
23
|
+
const html = renderInfoTip(base);
|
|
24
|
+
expect(html).toContain(
|
|
25
|
+
`<a href="https://shipwrightharness.com/docs/widgets" target="_blank" rel="noopener">Learn more →</a>`,
|
|
26
|
+
);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test("activating the button does not trigger its container", () => {
|
|
30
|
+
const html = renderInfoTip(base);
|
|
31
|
+
expect(html).toContain("event.preventDefault()");
|
|
32
|
+
expect(html).toContain("event.stopPropagation()");
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test("escapes < \" ' in summary, label and id", () => {
|
|
36
|
+
const html = renderInfoTip({
|
|
37
|
+
...base,
|
|
38
|
+
id: `a"b`,
|
|
39
|
+
label: `<b>"x"</b>'`,
|
|
40
|
+
summary: `<script>alert("x")</script>'`,
|
|
41
|
+
});
|
|
42
|
+
expect(html).not.toContain("<script>");
|
|
43
|
+
expect(html).not.toContain("<b>");
|
|
44
|
+
expect(html).toContain("<script>");
|
|
45
|
+
expect(html).toContain(""");
|
|
46
|
+
expect(html).not.toContain(`id="a"b"`);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test("align end adds the leftward modifier; default does not", () => {
|
|
50
|
+
expect(renderInfoTip({ ...base, align: "end" })).toContain(
|
|
51
|
+
'class="info-tip info-tip-end"',
|
|
52
|
+
);
|
|
53
|
+
expect(renderInfoTip(base)).not.toContain("info-tip-end");
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("docs base constant is the product docs URL", () => {
|
|
57
|
+
expect(ADMIN_DOCS_BASE_URL).toBe("https://shipwrightharness.com/docs/");
|
|
58
|
+
});
|
|
59
|
+
});
|
package/src/admin-ui-pages.ts
CHANGED
|
@@ -32,6 +32,10 @@ import {
|
|
|
32
32
|
renderAdminToolbar,
|
|
33
33
|
} from "./admin-ui-styles.ts";
|
|
34
34
|
import type { ManualStep } from "./agent-deletion-checklist.ts";
|
|
35
|
+
import {
|
|
36
|
+
type GitHubAppEnvSource,
|
|
37
|
+
overlayGitHubAppEnv,
|
|
38
|
+
} from "./agent-github-apps.ts";
|
|
35
39
|
import { isAudioFilename } from "./attachment-validation.ts";
|
|
36
40
|
import { parseChatMarkers } from "./chat-markers.ts";
|
|
37
41
|
import type { GithubAppsState } from "./github-apps-state.ts";
|
|
@@ -1098,7 +1102,9 @@ export interface AgentSetupStep {
|
|
|
1098
1102
|
export function deriveAgentSetupSteps(
|
|
1099
1103
|
agentId: string,
|
|
1100
1104
|
envVars: Record<string, unknown>,
|
|
1105
|
+
githubApp?: GitHubAppEnvSource | null,
|
|
1101
1106
|
): AgentSetupStep[] {
|
|
1107
|
+
const hasApp = githubApp != null || "GH_APP_ID" in envVars;
|
|
1102
1108
|
const href = agentSectionPath(agentId, "access");
|
|
1103
1109
|
return [
|
|
1104
1110
|
{
|
|
@@ -1110,7 +1116,7 @@ export function deriveAgentSetupSteps(
|
|
|
1110
1116
|
{
|
|
1111
1117
|
id: "github",
|
|
1112
1118
|
label: "Connect GitHub",
|
|
1113
|
-
connected:
|
|
1119
|
+
connected: hasApp || "GH_TOKEN" in envVars,
|
|
1114
1120
|
href,
|
|
1115
1121
|
},
|
|
1116
1122
|
];
|
|
@@ -1286,6 +1292,12 @@ export function renderAgentDetailPage(
|
|
|
1286
1292
|
userName: string,
|
|
1287
1293
|
isAdmin: boolean,
|
|
1288
1294
|
opts?: {
|
|
1295
|
+
/**
|
|
1296
|
+
* The agent's primary AgentGitHubApp row (multi-github-apps 1.5). When
|
|
1297
|
+
* present it, not the env keys, decides whether the agent has an App and
|
|
1298
|
+
* which slug it has; omitted/null falls back to the env keys.
|
|
1299
|
+
*/
|
|
1300
|
+
githubApp?: GitHubAppEnvSource | null;
|
|
1289
1301
|
/** Section to render (SGL-1.2). Defaults to "general". */
|
|
1290
1302
|
section?: AgentSection;
|
|
1291
1303
|
/**
|
|
@@ -1379,6 +1391,8 @@ export function renderAgentDetailPage(
|
|
|
1379
1391
|
typeof (envResult as { env: unknown }).env === "object"
|
|
1380
1392
|
? (envResult as { env: Record<string, string>; secretKeys: string[] }).env
|
|
1381
1393
|
: (envResult as Record<string, string>);
|
|
1394
|
+
// The GH_APP_* view readers branch on: table primary first, env fallback.
|
|
1395
|
+
const appEnv = overlayGitHubAppEnv(envVars, opts?.githubApp ?? null);
|
|
1382
1396
|
const secretKeySet = new Set<string>(
|
|
1383
1397
|
envResult && "secretKeys" in envResult
|
|
1384
1398
|
? (envResult as { secretKeys: string[] }).secretKeys
|
|
@@ -1532,15 +1546,15 @@ export function renderAgentDetailPage(
|
|
|
1532
1546
|
</div>`;
|
|
1533
1547
|
const slackConnectActionsHtml = connectActionsDiv(
|
|
1534
1548
|
slackConnectActionConfigs
|
|
1535
|
-
.map((cfg) => renderConnectAction(
|
|
1549
|
+
.map((cfg) => renderConnectAction(appEnv, cfg))
|
|
1536
1550
|
.filter(Boolean),
|
|
1537
1551
|
);
|
|
1538
1552
|
const githubConnectActionsHtml = connectActionsDiv(
|
|
1539
1553
|
[
|
|
1540
1554
|
...githubConnectActionConfigs.map((cfg) =>
|
|
1541
|
-
renderConnectAction(
|
|
1555
|
+
renderConnectAction(appEnv, cfg),
|
|
1542
1556
|
),
|
|
1543
|
-
renderAddAnotherOrgAction(agent.id,
|
|
1557
|
+
renderAddAnotherOrgAction(agent.id, appEnv),
|
|
1544
1558
|
].filter(Boolean),
|
|
1545
1559
|
);
|
|
1546
1560
|
|
|
@@ -2312,7 +2326,7 @@ export function renderAgentDetailPage(
|
|
|
2312
2326
|
|
|
2313
2327
|
// One GitHub card: connect actions plus (admin + enterprise GitHub) the
|
|
2314
2328
|
// GitHub sync fragments.
|
|
2315
|
-
const githubCardBody = `${githubConnectActionsHtml}${showGithubCards ? renderGithubSyncCard(agent.id, { hasAppId: "GH_APP_ID" in
|
|
2329
|
+
const githubCardBody = `${githubConnectActionsHtml}${showGithubCards ? renderGithubSyncCard(agent.id, { hasAppId: "GH_APP_ID" in appEnv, githubUsername: agent.githubUsername, ...(appsState === "both" ? {} : { appsState }) }) : ""}${showGithubIdentity ? renderGithubInstallCard(agent.id, appsState) : ""}`;
|
|
2316
2330
|
const githubSection =
|
|
2317
2331
|
canManage && githubCardBody.trim() !== ""
|
|
2318
2332
|
? `<div class="card">
|
|
@@ -2325,7 +2339,7 @@ export function renderAgentDetailPage(
|
|
|
2325
2339
|
// is the SHIPWRIGHT_SIGNED_COMMITS env row; when the box is hidden the field
|
|
2326
2340
|
// is absent from the submission, so the settings route leaves it untouched.
|
|
2327
2341
|
const signedCommitsHtml =
|
|
2328
|
-
"GH_APP_ID" in
|
|
2342
|
+
"GH_APP_ID" in appEnv
|
|
2329
2343
|
? `<div class="form-group" style="display:flex;align-items:center;gap:6px">
|
|
2330
2344
|
<input
|
|
2331
2345
|
id="signedCommits"
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
type AgentListItem,
|
|
15
15
|
agentSectionPath,
|
|
16
16
|
type CronJobItem,
|
|
17
|
+
deriveAgentSetupSteps,
|
|
17
18
|
ERROR_KIND_LABELS,
|
|
18
19
|
type MemberItem,
|
|
19
20
|
type PluginItem,
|
|
@@ -4811,3 +4812,25 @@ describe("GitHub App install pages (SWI-16.1)", () => {
|
|
|
4811
4812
|
).not.toContain("/setup");
|
|
4812
4813
|
});
|
|
4813
4814
|
});
|
|
4815
|
+
|
|
4816
|
+
describe("deriveAgentSetupSteps with the GitHub App table (multi-github-apps 1.5)", () => {
|
|
4817
|
+
const github = (steps: ReturnType<typeof deriveAgentSetupSteps>) =>
|
|
4818
|
+
steps.find((st) => st.id === "github")?.connected;
|
|
4819
|
+
|
|
4820
|
+
test("a table row counts as connected with no GH_APP_ID env", () => {
|
|
4821
|
+
const row = {
|
|
4822
|
+
appId: "1",
|
|
4823
|
+
slug: null,
|
|
4824
|
+
clientId: null,
|
|
4825
|
+
installationId: null,
|
|
4826
|
+
};
|
|
4827
|
+
expect(github(deriveAgentSetupSteps("a1", {}, row))).toBe(true);
|
|
4828
|
+
});
|
|
4829
|
+
|
|
4830
|
+
test("no row and no env is not connected; env alone still is (fallback)", () => {
|
|
4831
|
+
expect(github(deriveAgentSetupSteps("a1", {}, null))).toBe(false);
|
|
4832
|
+
expect(github(deriveAgentSetupSteps("a1", { GH_APP_ID: "1" }, null))).toBe(
|
|
4833
|
+
true,
|
|
4834
|
+
);
|
|
4835
|
+
});
|
|
4836
|
+
});
|
package/src/admin-ui-styles.ts
CHANGED
|
@@ -397,6 +397,40 @@ export function baseStyles(): string {
|
|
|
397
397
|
pointer-events: none;
|
|
398
398
|
}
|
|
399
399
|
|
|
400
|
+
/* ─── Info tip (ⓘ button + CSS popover; hover and focus-within) ─── */
|
|
401
|
+
.info-tip { position: relative; display: inline-block; vertical-align: middle; }
|
|
402
|
+
.info-tip-btn {
|
|
403
|
+
border: 0;
|
|
404
|
+
background: none;
|
|
405
|
+
padding: 0 4px;
|
|
406
|
+
cursor: pointer;
|
|
407
|
+
font-size: 14px;
|
|
408
|
+
line-height: 1;
|
|
409
|
+
color: var(--vos-text-muted);
|
|
410
|
+
}
|
|
411
|
+
.info-tip-pop {
|
|
412
|
+
display: none;
|
|
413
|
+
position: absolute;
|
|
414
|
+
left: 0;
|
|
415
|
+
top: 100%;
|
|
416
|
+
z-index: 10;
|
|
417
|
+
width: 260px;
|
|
418
|
+
padding: 10px 12px;
|
|
419
|
+
border: 1px solid var(--vos-border);
|
|
420
|
+
border-radius: 6px;
|
|
421
|
+
background: var(--vos-surface);
|
|
422
|
+
color: var(--vos-text);
|
|
423
|
+
font-size: 12px;
|
|
424
|
+
font-weight: normal;
|
|
425
|
+
line-height: 1.4;
|
|
426
|
+
text-align: left;
|
|
427
|
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
|
428
|
+
}
|
|
429
|
+
.info-tip-end .info-tip-pop { left: auto; right: 0; }
|
|
430
|
+
.info-tip:hover .info-tip-pop,
|
|
431
|
+
.info-tip:focus-within .info-tip-pop { display: block; }
|
|
432
|
+
.info-tip-pop a { display: block; margin-top: 6px; }
|
|
433
|
+
|
|
400
434
|
/* ─── Heartbeat status dots (fresh/aging/stale) ─────── */
|
|
401
435
|
.heartbeat-dot {
|
|
402
436
|
display: inline-block;
|
|
@@ -148,3 +148,19 @@ describe("baseStyles — SGL-1.1 settings layout", () => {
|
|
|
148
148
|
expect(block).toContain("var(--vos-");
|
|
149
149
|
});
|
|
150
150
|
});
|
|
151
|
+
|
|
152
|
+
describe("baseStyles — info tip", () => {
|
|
153
|
+
const css = baseStyles();
|
|
154
|
+
test("contains the info tip rules with hover and focus-within reveal", () => {
|
|
155
|
+
expect(css).toContain(".info-tip-pop");
|
|
156
|
+
expect(css).toContain(".info-tip:hover .info-tip-pop");
|
|
157
|
+
expect(css).toContain(".info-tip:focus-within .info-tip-pop");
|
|
158
|
+
expect(css).toContain(".info-tip-end .info-tip-pop");
|
|
159
|
+
});
|
|
160
|
+
test("uses theme variables, and the old header tooltip is unchanged", () => {
|
|
161
|
+
expect(css).toContain("background: var(--vos-surface)");
|
|
162
|
+
expect(css).toContain("color: var(--vos-text)");
|
|
163
|
+
expect(css).toContain(".header-tooltip[data-tip]:hover::after");
|
|
164
|
+
expect(css).toContain("content: attr(data-tip)");
|
|
165
|
+
});
|
|
166
|
+
});
|
package/src/admin-ui.ts
CHANGED
|
@@ -120,6 +120,7 @@ import type { DeleteAgentFullyDeps } from "./agent-deletion.ts";
|
|
|
120
120
|
import { deleteAgentFully } from "./agent-deletion.ts";
|
|
121
121
|
import type { ManualStep } from "./agent-deletion-checklist.ts";
|
|
122
122
|
import type { AgentEnvService } from "./agent-envs.ts";
|
|
123
|
+
import type { AgentGitHubAppService } from "./agent-github-apps.ts";
|
|
123
124
|
import type { AgentMarketplaceService } from "./agent-marketplaces.ts";
|
|
124
125
|
import {
|
|
125
126
|
type AgentMemberService,
|
|
@@ -360,6 +361,15 @@ interface PrismaLike {
|
|
|
360
361
|
|
|
361
362
|
export interface AdminUIDeps {
|
|
362
363
|
prisma: PrismaLike;
|
|
364
|
+
/**
|
|
365
|
+
* multi-github-apps 1.5: the AgentGitHubApp table. Pages and provisioning
|
|
366
|
+
* read the agent's GitHub App from it (env fallback when absent or empty)
|
|
367
|
+
* and write it alongside env. Optional so existing wiring stays valid.
|
|
368
|
+
*/
|
|
369
|
+
agentGitHubAppService?: Pick<
|
|
370
|
+
AgentGitHubAppService,
|
|
371
|
+
"getPrimary" | "applyLegacyEnvPatch"
|
|
372
|
+
>;
|
|
363
373
|
agentEnvService: Pick<
|
|
364
374
|
AgentEnvService,
|
|
365
375
|
"getByAgentId" | "upsert" | "patch" | "deleteKey" | "getConfigBundle"
|
|
@@ -1212,6 +1222,9 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
1212
1222
|
slackClient,
|
|
1213
1223
|
agentService,
|
|
1214
1224
|
agentEnvService,
|
|
1225
|
+
...(deps.agentGitHubAppService
|
|
1226
|
+
? { agentGitHubAppService: deps.agentGitHubAppService }
|
|
1227
|
+
: {}),
|
|
1215
1228
|
agentCronJobService,
|
|
1216
1229
|
sessionSecret,
|
|
1217
1230
|
appBaseUrl,
|
|
@@ -1236,6 +1249,20 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
1236
1249
|
secretEnvVars: new Set(SECRET_ENV_VARS),
|
|
1237
1250
|
});
|
|
1238
1251
|
|
|
1252
|
+
/**
|
|
1253
|
+
* The agent's primary GitHub App from the table, for pages that branch on
|
|
1254
|
+
* "has an App". Null when the table is not wired, empty for the agent, or
|
|
1255
|
+
* unreadable (best effort: callers fall back to the env keys).
|
|
1256
|
+
*/
|
|
1257
|
+
const primaryGithubApp = async (agentId: string) => {
|
|
1258
|
+
try {
|
|
1259
|
+
return (await deps.agentGitHubAppService?.getPrimary(agentId)) ?? null;
|
|
1260
|
+
} catch (err) {
|
|
1261
|
+
console.error("[admin-ui] could not read the agent's GitHub App:", err);
|
|
1262
|
+
return null;
|
|
1263
|
+
}
|
|
1264
|
+
};
|
|
1265
|
+
|
|
1239
1266
|
const html = createHtmlResponder(appBaseUrl);
|
|
1240
1267
|
|
|
1241
1268
|
// ─── Login / OAuth / Logout ───────────────────────────────────────────────
|
|
@@ -2885,12 +2912,13 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
2885
2912
|
// list's coverage warning. Best effort: unknown means no warning.
|
|
2886
2913
|
const appsState = await githubAppsState(c);
|
|
2887
2914
|
const enterpriseConfigured = appsState === "both";
|
|
2915
|
+
const githubApp = await primaryGithubApp(agentId);
|
|
2888
2916
|
let installationRepos: string[] | undefined;
|
|
2889
2917
|
let installationSync: InstallationSyncView | undefined;
|
|
2890
2918
|
if (
|
|
2891
2919
|
enterpriseConfigured &&
|
|
2892
2920
|
agentsApi &&
|
|
2893
|
-
"GH_APP_ID" in (envResult.env ?? {})
|
|
2921
|
+
(githubApp !== null || "GH_APP_ID" in (envResult.env ?? {}))
|
|
2894
2922
|
) {
|
|
2895
2923
|
const res = await callApi(
|
|
2896
2924
|
c,
|
|
@@ -2933,6 +2961,7 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
2933
2961
|
c.var.userEmail,
|
|
2934
2962
|
c.var.isAdmin,
|
|
2935
2963
|
{
|
|
2964
|
+
githubApp,
|
|
2936
2965
|
section,
|
|
2937
2966
|
canManage,
|
|
2938
2967
|
error,
|
|
@@ -2987,7 +3016,11 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
2987
3016
|
return new Response("Forbidden", { status: 403 });
|
|
2988
3017
|
}
|
|
2989
3018
|
const envResult = await agentEnvService.getByAgentId(agentId);
|
|
2990
|
-
const steps = deriveAgentSetupSteps(
|
|
3019
|
+
const steps = deriveAgentSetupSteps(
|
|
3020
|
+
agentId,
|
|
3021
|
+
envResult?.env ?? {},
|
|
3022
|
+
await primaryGithubApp(agentId),
|
|
3023
|
+
);
|
|
2991
3024
|
// SWI-17.3: read-and-clear the Slack hand-off cookie. Anything invalid,
|
|
2992
3025
|
// expired or for another agent degrades to the plain checklist.
|
|
2993
3026
|
const rawResume = getCookie(c, SETUP_RESUME_COOKIE);
|
|
@@ -3967,6 +4000,7 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
3967
4000
|
c.var.userEmail,
|
|
3968
4001
|
c.var.isAdmin,
|
|
3969
4002
|
{
|
|
4003
|
+
githubApp: await primaryGithubApp(agentId),
|
|
3970
4004
|
section: "access",
|
|
3971
4005
|
canManage,
|
|
3972
4006
|
newToken: rawToken,
|
|
@@ -328,3 +328,158 @@ describe("config bundle apps", () => {
|
|
|
328
328
|
expect(text).not.toContain('privateKey"');
|
|
329
329
|
});
|
|
330
330
|
});
|
|
331
|
+
|
|
332
|
+
describe("env routes mirror GH_APP_* into the table", () => {
|
|
333
|
+
function makeEnvApp(service: AgentGitHubAppService) {
|
|
334
|
+
return createAdminApp({
|
|
335
|
+
agentGitHubAppService: service,
|
|
336
|
+
agentEnvService: {
|
|
337
|
+
upsert: async () => {},
|
|
338
|
+
patch: async () => {},
|
|
339
|
+
deleteKey: async () => {},
|
|
340
|
+
},
|
|
341
|
+
sessionSecret: SESSION_SECRET,
|
|
342
|
+
adminApiKeys: adminKeys,
|
|
343
|
+
agentTokenService: { validate: async () => null },
|
|
344
|
+
agentMemberService: {
|
|
345
|
+
exists: async () => false,
|
|
346
|
+
listByEmail: async () => [],
|
|
347
|
+
},
|
|
348
|
+
agentService: { exists: async () => true },
|
|
349
|
+
} as never);
|
|
350
|
+
}
|
|
351
|
+
const envs = `/agents/${AGENT_ID}/envs`;
|
|
352
|
+
|
|
353
|
+
it("replace-all without the GH_APP_* keys removes the primary app", async () => {
|
|
354
|
+
const service = makeService();
|
|
355
|
+
const app = makeEnvApp(service);
|
|
356
|
+
expect(
|
|
357
|
+
(
|
|
358
|
+
await call(app, "POST", envs, {
|
|
359
|
+
GH_APP_ID: "12345",
|
|
360
|
+
GH_APP_PRIVATE_KEY: PEM,
|
|
361
|
+
GH_APP_SLUG: "my-app",
|
|
362
|
+
})
|
|
363
|
+
).status,
|
|
364
|
+
).toBe(201);
|
|
365
|
+
expect((await service.getPrimary(AGENT_ID))?.slug).toBe("my-app");
|
|
366
|
+
|
|
367
|
+
expect((await call(app, "POST", envs, { FOO: "bar" })).status).toBe(201);
|
|
368
|
+
expect(await service.getPrimary(AGENT_ID)).toBeNull();
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
it("replace-all without the GH_APP_* keys removes only the primary of several apps", async () => {
|
|
372
|
+
const service = makeService();
|
|
373
|
+
const app = makeEnvApp(service);
|
|
374
|
+
await service.create(AGENT_ID, {
|
|
375
|
+
appId: "11111",
|
|
376
|
+
privateKey: PEM,
|
|
377
|
+
slug: "app-a",
|
|
378
|
+
installationId: "101",
|
|
379
|
+
});
|
|
380
|
+
await service.create(AGENT_ID, {
|
|
381
|
+
appId: "22222",
|
|
382
|
+
privateKey: "K2",
|
|
383
|
+
slug: "app-b",
|
|
384
|
+
clientId: "Iv1.b",
|
|
385
|
+
clientSecret: "secret-b",
|
|
386
|
+
installationId: "202",
|
|
387
|
+
});
|
|
388
|
+
await service.create(AGENT_ID, {
|
|
389
|
+
appId: "33333",
|
|
390
|
+
privateKey: "K3",
|
|
391
|
+
slug: "app-c",
|
|
392
|
+
installationId: "303",
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
expect((await call(app, "POST", envs, { FOO: "bar" })).status).toBe(201);
|
|
396
|
+
|
|
397
|
+
const remaining = await service.list(AGENT_ID);
|
|
398
|
+
expect(remaining.map((r) => r.appId)).toEqual(["22222", "33333"]);
|
|
399
|
+
expect(remaining[0]).toMatchObject({
|
|
400
|
+
slug: "app-b",
|
|
401
|
+
clientId: "Iv1.b",
|
|
402
|
+
installationId: "202",
|
|
403
|
+
});
|
|
404
|
+
expect(remaining[1]).toMatchObject({
|
|
405
|
+
slug: "app-c",
|
|
406
|
+
installationId: "303",
|
|
407
|
+
});
|
|
408
|
+
const creds = await service.listCredentials(AGENT_ID);
|
|
409
|
+
expect(creds[0]?.clientSecret).toBe("secret-b");
|
|
410
|
+
expect(creds[0]?.privateKey).toBe("K2");
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
it("replace-all omitting an optional GH_APP_* key clears its column", async () => {
|
|
414
|
+
const service = makeService();
|
|
415
|
+
const app = makeEnvApp(service);
|
|
416
|
+
await call(app, "POST", envs, {
|
|
417
|
+
GH_APP_ID: "12345",
|
|
418
|
+
GH_APP_PRIVATE_KEY: PEM,
|
|
419
|
+
GH_APP_SLUG: "my-app",
|
|
420
|
+
GH_APP_INSTALLATION_ID: "999",
|
|
421
|
+
});
|
|
422
|
+
await call(app, "POST", envs, {
|
|
423
|
+
GH_APP_ID: "12345",
|
|
424
|
+
GH_APP_PRIVATE_KEY: PEM,
|
|
425
|
+
});
|
|
426
|
+
const primary = await service.getPrimary(AGENT_ID);
|
|
427
|
+
expect(primary?.appId).toBe("12345");
|
|
428
|
+
expect(primary?.slug).toBeNull();
|
|
429
|
+
expect(primary?.installationId).toBeNull();
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
it("replace-all naming a non-primary GH_APP_ID clears that app's omitted columns, not the primary's", async () => {
|
|
433
|
+
const service = makeService();
|
|
434
|
+
const app = makeEnvApp(service);
|
|
435
|
+
await service.create(AGENT_ID, {
|
|
436
|
+
appId: "11111",
|
|
437
|
+
privateKey: PEM,
|
|
438
|
+
slug: "app-a",
|
|
439
|
+
clientId: "Iv1.a",
|
|
440
|
+
clientSecret: "secret-a",
|
|
441
|
+
installationId: "101",
|
|
442
|
+
});
|
|
443
|
+
await service.create(AGENT_ID, {
|
|
444
|
+
appId: "22222",
|
|
445
|
+
privateKey: "K2",
|
|
446
|
+
slug: "app-b",
|
|
447
|
+
clientId: "Iv1.b",
|
|
448
|
+
clientSecret: "secret-b",
|
|
449
|
+
installationId: "202",
|
|
450
|
+
});
|
|
451
|
+
await service.create(AGENT_ID, {
|
|
452
|
+
appId: "33333",
|
|
453
|
+
privateKey: "K3",
|
|
454
|
+
slug: "app-c",
|
|
455
|
+
installationId: "303",
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
expect(
|
|
459
|
+
(
|
|
460
|
+
await call(app, "POST", envs, {
|
|
461
|
+
GH_APP_ID: "22222",
|
|
462
|
+
GH_APP_PRIVATE_KEY: "K2-rotated",
|
|
463
|
+
})
|
|
464
|
+
).status,
|
|
465
|
+
).toBe(201);
|
|
466
|
+
|
|
467
|
+
const rows = await service.list(AGENT_ID);
|
|
468
|
+
expect(rows.map((r) => r.appId)).toEqual(["11111", "22222", "33333"]);
|
|
469
|
+
expect(rows[0]).toMatchObject({
|
|
470
|
+
slug: "app-a",
|
|
471
|
+
clientId: "Iv1.a",
|
|
472
|
+
installationId: "101",
|
|
473
|
+
});
|
|
474
|
+
expect(rows[1]).toMatchObject({
|
|
475
|
+
slug: null,
|
|
476
|
+
clientId: null,
|
|
477
|
+
installationId: null,
|
|
478
|
+
});
|
|
479
|
+
expect(rows[2]).toMatchObject({ slug: "app-c", installationId: "303" });
|
|
480
|
+
const creds = await service.listCredentials(AGENT_ID);
|
|
481
|
+
expect(creds[0]?.clientSecret).toBe("secret-a");
|
|
482
|
+
expect(creds[1]?.clientSecret).toBeNull();
|
|
483
|
+
expect(creds[1]?.privateKey).toBe("K2-rotated");
|
|
484
|
+
});
|
|
485
|
+
});
|