@app-vitals/agent-admin 1.30.0 → 1.31.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 +19 -4
- package/src/admin-extension.ts +13 -0
- package/src/admin-extension.unit.test.ts +20 -0
- package/src/agents-api.smoke.test.ts +55 -0
- package/src/github-enterprise-isolation.unit.test.ts +8 -4
- package/src/github-reconcile-wiring.ts +95 -0
- package/src/github-reconcile-wiring.unit.test.ts +146 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@app-vitals/agent-admin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.31.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/app-vitals/agent.git",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@anthropic-ai/sdk": "0.135.0",
|
|
45
|
-
"@app-vitals/agent-lib": "1.
|
|
45
|
+
"@app-vitals/agent-lib": "1.31.0",
|
|
46
46
|
"@hono/zod-openapi": "^1.0.0",
|
|
47
47
|
"@prisma/adapter-pg": "^7.10.0",
|
|
48
48
|
"@prisma/client": "^7.10.0",
|
package/src/admin-boot.ts
CHANGED
|
@@ -99,12 +99,16 @@ import { CronRunNowService } from "./cron-run-now.ts";
|
|
|
99
99
|
import { parseCronRunNowConfig } from "./cron-run-now-config.ts";
|
|
100
100
|
import { CronRunTranscriptService } from "./cron-run-transcripts.ts";
|
|
101
101
|
import { isDevAuthAllowed } from "./dev-auth-guard.ts";
|
|
102
|
+
import { HttpGithubAppProvisioningClient } from "./github-app-provisioning-client.ts";
|
|
102
103
|
import {
|
|
103
104
|
createGithubAccessPreview,
|
|
104
105
|
createGithubEnterpriseApp,
|
|
105
106
|
} from "./github-enterprise-api.ts";
|
|
106
107
|
import { GitHubEnterpriseAppService } from "./github-enterprise-apps.ts";
|
|
107
|
-
import {
|
|
108
|
+
import {
|
|
109
|
+
createGithubReconcile,
|
|
110
|
+
parseAgentAppId,
|
|
111
|
+
} from "./github-reconcile-wiring.ts";
|
|
108
112
|
import { HttpGoogleAuthClient } from "./google-auth-client.ts";
|
|
109
113
|
import { HttpChatClient } from "./http-chat-client.ts";
|
|
110
114
|
import { HttpOktaAuthClient } from "./okta-auth-client.ts";
|
|
@@ -466,10 +470,21 @@ export async function startAdmin(
|
|
|
466
470
|
prisma,
|
|
467
471
|
makeStrictTokenCrypto(),
|
|
468
472
|
);
|
|
473
|
+
const githubAccessPreview = createGithubAccessPreview({
|
|
474
|
+
appService: githubEnterpriseAppService,
|
|
475
|
+
});
|
|
476
|
+
// GHE-3.9: the reconcile routes' service, with the extension's optional
|
|
477
|
+
// open-work port. Unwired (routes report `skipped`) without an agent App id.
|
|
478
|
+
const githubReconcile = createGithubReconcile({
|
|
479
|
+
prisma,
|
|
480
|
+
appService: githubEnterpriseAppService,
|
|
481
|
+
access: githubAccessPreview,
|
|
482
|
+
agentAppId: parseAgentAppId(process.env.SHIPWRIGHT_GITHUB_AGENT_APP_ID),
|
|
483
|
+
openWork: resolvedExtensions.openWork,
|
|
484
|
+
});
|
|
469
485
|
const adminApiApp = createAdminApp({
|
|
470
|
-
githubAccessPreview
|
|
471
|
-
|
|
472
|
-
}),
|
|
486
|
+
githubAccessPreview,
|
|
487
|
+
...(githubReconcile ? { githubReconcile } : {}),
|
|
473
488
|
agentService,
|
|
474
489
|
agentEnvService,
|
|
475
490
|
agentCronJobService,
|
package/src/admin-extension.ts
CHANGED
|
@@ -62,6 +62,7 @@ import type { AdminDeps, parseAdminApiKeys } from "./agents-api.ts";
|
|
|
62
62
|
import type { AgentPhaseMethodologyServiceLike } from "./api.ts";
|
|
63
63
|
import type { createCallerScopeResolver } from "./caller-scope.ts";
|
|
64
64
|
import type { PushService } from "./push-service.ts";
|
|
65
|
+
import type { OpenWorkPort } from "./reconcile-open-work.ts";
|
|
65
66
|
import type { ServiceIntegration } from "./service-integration.ts";
|
|
66
67
|
import type {
|
|
67
68
|
SpecialtyDefaults,
|
|
@@ -128,6 +129,12 @@ export interface AdminExtensionServices {
|
|
|
128
129
|
* the runtime app omits the field.
|
|
129
130
|
*/
|
|
130
131
|
agentPhaseMethodologyService?: AgentPhaseMethodologyServiceLike;
|
|
132
|
+
/**
|
|
133
|
+
* Supplies the GitHub reconcile's open-work port (GHE-3.9): plan lists the
|
|
134
|
+
* open work on repos it would remove and apply blocks it. Absent from every
|
|
135
|
+
* extension → nothing is listed or blocked.
|
|
136
|
+
*/
|
|
137
|
+
openWork?: OpenWorkPort;
|
|
131
138
|
}
|
|
132
139
|
|
|
133
140
|
export interface AgentDetailCardContext {
|
|
@@ -212,6 +219,7 @@ export interface ResolvedAdminExtensions {
|
|
|
212
219
|
apiDeps: Partial<AdminDeps>;
|
|
213
220
|
uiDeps: Partial<AdminUIDeps>;
|
|
214
221
|
agentPhaseMethodologyService?: AgentPhaseMethodologyServiceLike;
|
|
222
|
+
openWork?: OpenWorkPort;
|
|
215
223
|
apiRoutes: AdminRouteContribution[];
|
|
216
224
|
adminUiRoutes: AdminRouteContribution[];
|
|
217
225
|
agentDetailCards: AgentDetailCardSlot[];
|
|
@@ -238,8 +246,13 @@ export function resolveAdminExtensions(
|
|
|
238
246
|
.map((s) => s.agentPhaseMethodologyService)
|
|
239
247
|
.filter((svc) => svc !== undefined)
|
|
240
248
|
.at(-1);
|
|
249
|
+
const openWork = services
|
|
250
|
+
.map((s) => s.openWork)
|
|
251
|
+
.filter((port) => port !== undefined)
|
|
252
|
+
.at(-1);
|
|
241
253
|
return {
|
|
242
254
|
...(agentPhaseMethodologyService ? { agentPhaseMethodologyService } : {}),
|
|
255
|
+
...(openWork ? { openWork } : {}),
|
|
243
256
|
apiDeps: Object.assign({}, ...services.map((s) => s.api ?? {})),
|
|
244
257
|
uiDeps: Object.assign({}, ...services.map((s) => s.ui ?? {})),
|
|
245
258
|
apiRoutes,
|
|
@@ -18,12 +18,32 @@ import {
|
|
|
18
18
|
startBackgroundPasses,
|
|
19
19
|
withExtensionAgentTypes,
|
|
20
20
|
} from "./admin-extension.ts";
|
|
21
|
+
import type { OpenWorkPort } from "./reconcile-open-work.ts";
|
|
21
22
|
|
|
22
23
|
// The seam only hands the context through to hooks, so an opaque stand-in is
|
|
23
24
|
// enough — no hook under test reads from it.
|
|
24
25
|
const ctx = { env: {} } as unknown as AdminExtensionContext;
|
|
25
26
|
|
|
26
27
|
describe("resolveAdminExtensions", () => {
|
|
28
|
+
it("openWork: absent from every extension is omitted; the last supplier wins", () => {
|
|
29
|
+
const mk = (id: string): OpenWorkPort => ({
|
|
30
|
+
listOpenWork: async () => [{ id, repo: "acme/x" }],
|
|
31
|
+
blockOpenWork: async () => {},
|
|
32
|
+
});
|
|
33
|
+
expect("openWork" in resolveAdminExtensions([{}], ctx)).toBe(false);
|
|
34
|
+
const first = mk("first");
|
|
35
|
+
const last = mk("last");
|
|
36
|
+
const resolved = resolveAdminExtensions(
|
|
37
|
+
[
|
|
38
|
+
{ services: () => ({ openWork: first }) },
|
|
39
|
+
{ services: () => ({}) },
|
|
40
|
+
{ services: () => ({ openWork: last }) },
|
|
41
|
+
],
|
|
42
|
+
ctx,
|
|
43
|
+
);
|
|
44
|
+
expect(resolved.openWork).toBe(last);
|
|
45
|
+
});
|
|
46
|
+
|
|
27
47
|
it("no extensions resolves to empty contributions", () => {
|
|
28
48
|
expect(resolveAdminExtensions([], ctx)).toEqual({
|
|
29
49
|
apiDeps: {},
|
|
@@ -22,6 +22,12 @@ import type { AgentTokenService } from "./agent-tokens.ts";
|
|
|
22
22
|
import type { AdminDeps } from "./agents-api.ts";
|
|
23
23
|
import { createAdminApp, parseAdminApiKeys } from "./agents-api.ts";
|
|
24
24
|
import { PLATFORM_OPS_ROUTES } from "./api-auth.ts";
|
|
25
|
+
import { createGithubReconcile } from "./github-reconcile-wiring.ts";
|
|
26
|
+
import {
|
|
27
|
+
accessFor,
|
|
28
|
+
fakeOpenWork,
|
|
29
|
+
fakePrisma,
|
|
30
|
+
} from "./github-reconcile-wiring.unit.test.ts";
|
|
25
31
|
import type { SpecialtyType } from "./specialty-types.ts";
|
|
26
32
|
import { identityCrypto } from "./token-crypto.ts";
|
|
27
33
|
|
|
@@ -7178,3 +7184,52 @@ describe("admin API — GitHub reconcile routes (GHE-3.4)", () => {
|
|
|
7178
7184
|
expect((await post(app, "apply", asAdmin, {})).status).toBe(400);
|
|
7179
7185
|
});
|
|
7180
7186
|
});
|
|
7187
|
+
|
|
7188
|
+
describe("admin API — reconcile open-work seam, in-process composition (GHE-3.9)", () => {
|
|
7189
|
+
const compose = (openWork?: ReturnType<typeof fakeOpenWork>["port"]) => {
|
|
7190
|
+
const { prisma, state } = fakePrisma(["acme/old"]);
|
|
7191
|
+
const githubReconcile = createGithubReconcile({
|
|
7192
|
+
prisma,
|
|
7193
|
+
appService: { get: async () => null, getPrivateKey: async () => null },
|
|
7194
|
+
access: accessFor(["acme/api"]),
|
|
7195
|
+
agentAppId: 42,
|
|
7196
|
+
installation: {
|
|
7197
|
+
listRepos: async () => ({ acme: ["acme/old", "acme/api"] }),
|
|
7198
|
+
addRepos: async () => {},
|
|
7199
|
+
removeRepos: async () => {},
|
|
7200
|
+
},
|
|
7201
|
+
openWork,
|
|
7202
|
+
});
|
|
7203
|
+
const app = createAdminApp({
|
|
7204
|
+
...makeMockDeps(),
|
|
7205
|
+
adminApiKeys: parseAdminApiKeys(`root:${ADMIN_API_KEY}:*`),
|
|
7206
|
+
githubReconcile,
|
|
7207
|
+
});
|
|
7208
|
+
const plan = () =>
|
|
7209
|
+
app.request(`/agents/${AGENT_ID}/github-reconcile/plan`, {
|
|
7210
|
+
method: "POST",
|
|
7211
|
+
headers: { Authorization: `Bearer ${ADMIN_API_KEY}` },
|
|
7212
|
+
});
|
|
7213
|
+
return { plan, state };
|
|
7214
|
+
};
|
|
7215
|
+
|
|
7216
|
+
it("plan returns the port's items and retires nothing", async () => {
|
|
7217
|
+
const { port, calls } = fakeOpenWork();
|
|
7218
|
+
const { plan, state } = compose(port);
|
|
7219
|
+
const res = await plan();
|
|
7220
|
+
expect(res.status).toBe(200);
|
|
7221
|
+
const body = (await res.json()) as { affectedOpenWork: unknown[] };
|
|
7222
|
+
expect(body.affectedOpenWork).toEqual([
|
|
7223
|
+
{ id: "T-1", repo: "acme/old", title: "fix it" },
|
|
7224
|
+
]);
|
|
7225
|
+
expect(calls.map((c) => c.fn)).toEqual(["list"]);
|
|
7226
|
+
expect(state.repos).toEqual(["acme/old"]);
|
|
7227
|
+
});
|
|
7228
|
+
|
|
7229
|
+
it("without a port plan lists nothing", async () => {
|
|
7230
|
+
const res = await compose().plan();
|
|
7231
|
+
expect(res.status).toBe(200);
|
|
7232
|
+
const body = (await res.json()) as { affectedOpenWork: unknown[] };
|
|
7233
|
+
expect(body.affectedOpenWork).toEqual([]);
|
|
7234
|
+
});
|
|
7235
|
+
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* admin/src/github-enterprise-isolation.unit.test.ts
|
|
3
3
|
* Isolation exception guard (GHE-1.3): the GitHub Enterprise App private key
|
|
4
|
-
* is reachable only from the enterprise service, its admin API
|
|
5
|
-
* wiring. Agent config bundle, agent-bearer routes and env serialization must
|
|
4
|
+
* is reachable only from the enterprise service, its admin API, the boot
|
|
5
|
+
* wiring and the reconcile wiring. Agent config bundle, agent-bearer routes and env serialization must
|
|
6
6
|
* never import the service, touch its table or call getPrivateKey().
|
|
7
7
|
*/
|
|
8
8
|
|
|
@@ -17,6 +17,7 @@ const ALLOWED = new Set([
|
|
|
17
17
|
"admin/src/github-enterprise-apps.ts",
|
|
18
18
|
"admin/src/github-enterprise-api.ts",
|
|
19
19
|
"admin/src/admin-boot.ts",
|
|
20
|
+
"admin/src/github-reconcile-wiring.ts",
|
|
20
21
|
]);
|
|
21
22
|
|
|
22
23
|
function sources(dir: string, out: string[] = []): string[] {
|
|
@@ -66,13 +67,16 @@ describe("GitHub Enterprise key isolation", () => {
|
|
|
66
67
|
expect(offenders).toEqual([]);
|
|
67
68
|
});
|
|
68
69
|
|
|
69
|
-
it("getPrivateKey() is only called by the enterprise API", () => {
|
|
70
|
+
it("getPrivateKey() is only called by the enterprise API and reconcile wiring", () => {
|
|
70
71
|
const callers = files
|
|
71
72
|
.map((f) => relative(REPO, f))
|
|
72
73
|
.filter((rel) =>
|
|
73
74
|
/\.getPrivateKey\(/.test(readFileSync(join(REPO, rel), "utf-8")),
|
|
74
75
|
);
|
|
75
|
-
expect(callers).toEqual([
|
|
76
|
+
expect(callers.sort()).toEqual([
|
|
77
|
+
"admin/src/github-enterprise-api.ts",
|
|
78
|
+
"admin/src/github-reconcile-wiring.ts",
|
|
79
|
+
]);
|
|
76
80
|
});
|
|
77
81
|
|
|
78
82
|
it("the config bundle and env serializers never read the enterprise table", () => {
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* admin/src/github-reconcile-wiring.ts
|
|
3
|
+
* Composition of the GitHub reconcile service for admin boot (GHE-3.9).
|
|
4
|
+
* Builds ReconcileApplyService from the stored enterprise Apps and an
|
|
5
|
+
* optional host-supplied OpenWorkPort. Without an agent App id the reconcile
|
|
6
|
+
* is not wired (routes report `skipped`); without an open-work port nothing is
|
|
7
|
+
* listed or blocked.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { PrismaClient } from "../prisma/client/client.ts";
|
|
11
|
+
import type { GithubAccessPreviewFn } from "./github-access-preview.ts";
|
|
12
|
+
import type { GitHubEnterpriseAppService } from "./github-enterprise-apps.ts";
|
|
13
|
+
import { GithubEnterpriseClient } from "./github-enterprise-client.ts";
|
|
14
|
+
import {
|
|
15
|
+
createInstallationPort,
|
|
16
|
+
type InstallationRepoClient,
|
|
17
|
+
PrismaReconcileAgents,
|
|
18
|
+
PrismaReconcileAudit,
|
|
19
|
+
ReconcileApplyService,
|
|
20
|
+
type ReconcileInstallationPort,
|
|
21
|
+
} from "./reconcile-apply-service.ts";
|
|
22
|
+
import type { OpenWorkPort } from "./reconcile-open-work.ts";
|
|
23
|
+
|
|
24
|
+
export interface GithubReconcileWiringDeps {
|
|
25
|
+
prisma: PrismaClient;
|
|
26
|
+
appService: Pick<GitHubEnterpriseAppService, "get" | "getPrivateKey">;
|
|
27
|
+
access: GithubAccessPreviewFn;
|
|
28
|
+
/** Numeric id of the agent App whose installations are reconciled. */
|
|
29
|
+
agentAppId: number | undefined;
|
|
30
|
+
openWork?: OpenWorkPort;
|
|
31
|
+
/** Test seam: replaces the installer-App-backed installation port. */
|
|
32
|
+
installation?: ReconcileInstallationPort;
|
|
33
|
+
/** Test seams; default to the real GitHub API. */
|
|
34
|
+
fetchFn?: typeof fetch;
|
|
35
|
+
apiBase?: string;
|
|
36
|
+
now?: () => Date;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Parses SHIPWRIGHT_GITHUB_AGENT_APP_ID; unset or non-numeric -> undefined. */
|
|
40
|
+
export function parseAgentAppId(raw: string | undefined): number | undefined {
|
|
41
|
+
const n = Number(raw?.trim());
|
|
42
|
+
return Number.isInteger(n) && n > 0 ? n : undefined;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Builds the installer client per call so key rotations are picked up. */
|
|
46
|
+
function lazyInstallerClient(
|
|
47
|
+
deps: Pick<
|
|
48
|
+
GithubReconcileWiringDeps,
|
|
49
|
+
"appService" | "fetchFn" | "apiBase" | "now"
|
|
50
|
+
>,
|
|
51
|
+
): InstallationRepoClient {
|
|
52
|
+
const client = async (): Promise<GithubEnterpriseClient> => {
|
|
53
|
+
const [installer, privateKey] = await Promise.all([
|
|
54
|
+
deps.appService.get("installer"),
|
|
55
|
+
deps.appService.getPrivateKey("installer"),
|
|
56
|
+
]);
|
|
57
|
+
if (!installer?.enterpriseSlug || !privateKey) {
|
|
58
|
+
throw new Error("installer App is not configured");
|
|
59
|
+
}
|
|
60
|
+
return new GithubEnterpriseClient({
|
|
61
|
+
appId: installer.appId,
|
|
62
|
+
enterprise: installer.enterpriseSlug,
|
|
63
|
+
privateKey,
|
|
64
|
+
apiBase: deps.apiBase,
|
|
65
|
+
fetchFn: deps.fetchFn,
|
|
66
|
+
now: deps.now,
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
return {
|
|
70
|
+
listOrgInstallations: async (org) =>
|
|
71
|
+
(await client()).listOrgInstallations(org),
|
|
72
|
+
listInstallationRepositories: async (org, id) =>
|
|
73
|
+
(await client()).listInstallationRepositories(org, id),
|
|
74
|
+
addRepositories: async (org, id, names) =>
|
|
75
|
+
(await client()).addRepositories(org, id, names),
|
|
76
|
+
removeRepositories: async (org, id, names) =>
|
|
77
|
+
(await client()).removeRepositories(org, id, names),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** The `githubReconcile` dep for createAdminApp, or undefined when unwired. */
|
|
82
|
+
export function createGithubReconcile(
|
|
83
|
+
deps: GithubReconcileWiringDeps,
|
|
84
|
+
): ReconcileApplyService | undefined {
|
|
85
|
+
if (deps.agentAppId === undefined) return undefined;
|
|
86
|
+
return new ReconcileApplyService({
|
|
87
|
+
agents: new PrismaReconcileAgents(deps.prisma),
|
|
88
|
+
access: deps.access,
|
|
89
|
+
installation:
|
|
90
|
+
deps.installation ??
|
|
91
|
+
createInstallationPort(lazyInstallerClient(deps), deps.agentAppId),
|
|
92
|
+
audit: new PrismaReconcileAudit(deps.prisma),
|
|
93
|
+
...(deps.openWork ? { openWork: deps.openWork } : {}),
|
|
94
|
+
});
|
|
95
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { describe, expect, it } from "bun:test";
|
|
2
|
+
import type { PrismaClient } from "../prisma/client/client.ts";
|
|
3
|
+
import type { GithubAccessPreviewFn } from "./github-access-preview.ts";
|
|
4
|
+
import {
|
|
5
|
+
createGithubReconcile,
|
|
6
|
+
parseAgentAppId,
|
|
7
|
+
} from "./github-reconcile-wiring.ts";
|
|
8
|
+
import type { OpenWorkPort } from "./reconcile-open-work.ts";
|
|
9
|
+
|
|
10
|
+
export const accessFor = (pushable: string[]): GithubAccessPreviewFn => {
|
|
11
|
+
return async () => ({
|
|
12
|
+
status: "ok",
|
|
13
|
+
access: {
|
|
14
|
+
username: "dev",
|
|
15
|
+
outcome: "ok",
|
|
16
|
+
userVerified: true,
|
|
17
|
+
complete: true,
|
|
18
|
+
unresolved: 0,
|
|
19
|
+
checkedAt: "2026-11-11T00:00:00.000Z",
|
|
20
|
+
orgs: [
|
|
21
|
+
{
|
|
22
|
+
org: "acme",
|
|
23
|
+
status: "ok",
|
|
24
|
+
unresolved: 0,
|
|
25
|
+
repos: pushable.map((fullName) => ({
|
|
26
|
+
fullName,
|
|
27
|
+
level: "write" as const,
|
|
28
|
+
canPush: true,
|
|
29
|
+
})),
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export function fakePrisma(repos: string[]) {
|
|
37
|
+
const state = { repos: [...repos], audits: 0 };
|
|
38
|
+
const prisma = {
|
|
39
|
+
agent: {
|
|
40
|
+
findUnique: async () => ({
|
|
41
|
+
id: "a1",
|
|
42
|
+
repos: state.repos,
|
|
43
|
+
githubUsername: "dev",
|
|
44
|
+
}),
|
|
45
|
+
update: async (args: { data: { repos: string[] } }) => {
|
|
46
|
+
state.repos = args.data.repos;
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
gitHubReconcileAudit: {
|
|
50
|
+
create: async () => {
|
|
51
|
+
state.audits += 1;
|
|
52
|
+
return { id: "audit-1" };
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
} as unknown as PrismaClient;
|
|
56
|
+
return { prisma, state };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function fakeOpenWork() {
|
|
60
|
+
const calls: { fn: string; args: unknown[] }[] = [];
|
|
61
|
+
const port: OpenWorkPort = {
|
|
62
|
+
listOpenWork: async (...args) => {
|
|
63
|
+
calls.push({ fn: "list", args });
|
|
64
|
+
return [{ id: "T-1", repo: "acme/old", title: "fix it" }];
|
|
65
|
+
},
|
|
66
|
+
blockOpenWork: async (...args) => {
|
|
67
|
+
calls.push({ fn: "block", args });
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
return { port, calls };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const installation = {
|
|
74
|
+
listRepos: async () => ({ acme: ["acme/old", "acme/api"] }),
|
|
75
|
+
addRepos: async () => {},
|
|
76
|
+
removeRepos: async () => {},
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const build = (openWork?: OpenWorkPort) => {
|
|
80
|
+
const { prisma, state } = fakePrisma(["acme/old"]);
|
|
81
|
+
const svc = createGithubReconcile({
|
|
82
|
+
prisma,
|
|
83
|
+
appService: { get: async () => null, getPrivateKey: async () => null },
|
|
84
|
+
access: accessFor(["acme/api"]),
|
|
85
|
+
agentAppId: 42,
|
|
86
|
+
installation,
|
|
87
|
+
openWork,
|
|
88
|
+
});
|
|
89
|
+
if (!svc) throw new Error("expected a reconcile service");
|
|
90
|
+
return { svc, state };
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
describe("parseAgentAppId", () => {
|
|
94
|
+
it("parses a positive integer and rejects everything else", () => {
|
|
95
|
+
expect(parseAgentAppId(" 123 ")).toBe(123);
|
|
96
|
+
for (const bad of [undefined, "", "abc", "0", "-4", "1.5"]) {
|
|
97
|
+
expect(parseAgentAppId(bad)).toBeUndefined();
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
describe("createGithubReconcile", () => {
|
|
103
|
+
it("is unwired without an agent App id", () => {
|
|
104
|
+
const { prisma } = fakePrisma([]);
|
|
105
|
+
expect(
|
|
106
|
+
createGithubReconcile({
|
|
107
|
+
prisma,
|
|
108
|
+
appService: { get: async () => null, getPrivateKey: async () => null },
|
|
109
|
+
access: accessFor([]),
|
|
110
|
+
agentAppId: undefined,
|
|
111
|
+
}),
|
|
112
|
+
).toBeUndefined();
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it("with a port: plan lists affected open work and apply blocks it", async () => {
|
|
116
|
+
const { port, calls } = fakeOpenWork();
|
|
117
|
+
const { svc } = build(port);
|
|
118
|
+
const { plan, openWork } = await svc.planWithOpenWork("a1");
|
|
119
|
+
expect(plan.diff.configRemoves).toEqual(["acme/old"]);
|
|
120
|
+
expect(openWork).toEqual([
|
|
121
|
+
{ id: "T-1", repo: "acme/old", title: "fix it" },
|
|
122
|
+
]);
|
|
123
|
+
const res = await svc.apply({
|
|
124
|
+
agentId: "a1",
|
|
125
|
+
caller: "root",
|
|
126
|
+
planHash: plan.planHash,
|
|
127
|
+
});
|
|
128
|
+
expect(res.status).toBe("applied");
|
|
129
|
+
const block = calls.find((c) => c.fn === "block");
|
|
130
|
+
expect(block?.args[0]).toBe("a1");
|
|
131
|
+
expect(block?.args[1]).toEqual(["acme/old"]);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("without a port: nothing is listed or blocked, apply still works", async () => {
|
|
135
|
+
const { svc, state } = build();
|
|
136
|
+
const { plan, openWork } = await svc.planWithOpenWork("a1");
|
|
137
|
+
expect(openWork).toEqual([]);
|
|
138
|
+
const res = await svc.apply({
|
|
139
|
+
agentId: "a1",
|
|
140
|
+
caller: "root",
|
|
141
|
+
planHash: plan.planHash,
|
|
142
|
+
});
|
|
143
|
+
expect(res.status).toBe("applied");
|
|
144
|
+
expect(state.repos).toEqual([]);
|
|
145
|
+
});
|
|
146
|
+
});
|