@app-vitals/agent-admin 1.54.1 → 1.56.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.json +12 -0
- package/openapi.platform.json +12 -0
- package/package.json +2 -2
- package/prisma/client/internal/class.ts +4 -4
- package/prisma/client/internal/prismaNamespace.ts +4 -0
- package/prisma/client/internal/prismaNamespaceBrowser.ts +4 -0
- package/prisma/client/models/Account.ts +156 -0
- package/prisma/client/models/AgentMarketplace.ts +71 -1
- package/prisma/client/models/GitHubEnterpriseApp.ts +338 -12
- package/prisma/migrations/20261116000000_github_enterprise_app_account_id/migration.sql +21 -0
- package/prisma/migrations/20261116100000_add_agent_marketplace_row_source/migration.sql +5 -0
- package/prisma/schema/schema.prisma +20 -4
- package/src/agent-marketplaces-api.integration.test.ts +112 -0
- package/src/agent-marketplaces.integration.test.ts +9 -0
- package/src/agent-marketplaces.ts +52 -2
- package/src/agents-api.ts +3 -0
- package/src/api.ts +16 -8
- package/src/github-enterprise-api.integration.test.ts +5 -5
- package/src/github-enterprise-apps.integration.test.ts +101 -3
- package/src/github-enterprise-apps.ts +68 -23
- package/src/github-enterprise-isolation.unit.test.ts +10 -0
- package/src/openapi-schemas.ts +5 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
-- Surrogate primary key: existing rows (the deployment-wide pair) get a
|
|
2
|
+
-- deterministic id derived from their role; no data is otherwise touched.
|
|
3
|
+
ALTER TABLE "GitHubEnterpriseApp" DROP CONSTRAINT "GitHubEnterpriseApp_pkey";
|
|
4
|
+
ALTER TABLE "GitHubEnterpriseApp" ADD COLUMN "id" TEXT;
|
|
5
|
+
UPDATE "GitHubEnterpriseApp" SET "id" = 'ghe_' || "role";
|
|
6
|
+
ALTER TABLE "GitHubEnterpriseApp" ALTER COLUMN "id" SET NOT NULL;
|
|
7
|
+
ALTER TABLE "GitHubEnterpriseApp" ADD CONSTRAINT "GitHubEnterpriseApp_pkey" PRIMARY KEY ("id");
|
|
8
|
+
|
|
9
|
+
-- Nullable account scope; existing rows stay NULL (deployment-wide).
|
|
10
|
+
ALTER TABLE "GitHubEnterpriseApp" ADD COLUMN "accountId" TEXT;
|
|
11
|
+
|
|
12
|
+
-- CreateIndex
|
|
13
|
+
CREATE UNIQUE INDEX "GitHubEnterpriseApp_accountId_role_key" ON "GitHubEnterpriseApp"("accountId", "role");
|
|
14
|
+
|
|
15
|
+
-- AddForeignKey
|
|
16
|
+
ALTER TABLE "GitHubEnterpriseApp" ADD CONSTRAINT "GitHubEnterpriseApp_accountId_fkey" FOREIGN KEY ("accountId") REFERENCES "Account"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
17
|
+
|
|
18
|
+
-- Partial unique index (not expressible in Prisma; see the GitHubEnterpriseApp
|
|
19
|
+
-- comment in schema.prisma). The plain (accountId, role) index above cannot
|
|
20
|
+
-- enforce one deployment-wide row per role because NULLs compare distinct.
|
|
21
|
+
CREATE UNIQUE INDEX "GitHubEnterpriseApp_role_global_key" ON "GitHubEnterpriseApp"("role") WHERE "accountId" IS NULL;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
-- TMK-2.1: AgentMarketplace provenance and tombstones. Additive only: existing
|
|
2
|
+
-- rows get rowSource = 'custom' and enabled = true.
|
|
3
|
+
-- AlterTable
|
|
4
|
+
ALTER TABLE "AgentMarketplace" ADD COLUMN "enabled" BOOLEAN NOT NULL DEFAULT true,
|
|
5
|
+
ADD COLUMN "rowSource" TEXT NOT NULL DEFAULT 'custom';
|
|
@@ -130,12 +130,23 @@ model AgentEnv {
|
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
// ─── GitHub Enterprise Apps ───────────────────────────────────────────────────
|
|
133
|
-
// Optional admin-level GitHub Apps, one per
|
|
134
|
-
//
|
|
135
|
-
//
|
|
133
|
+
// Optional admin-level GitHub Apps, one per (accountId, role) where role is
|
|
134
|
+
// 'installer' | 'lookup'. accountId null = the deployment-wide pair (at most two
|
|
135
|
+
// rows); an account row overrides it for that account. No rows means the feature
|
|
136
|
+
// is off. Deliberately NOT in AgentEnv so the private key can never reach the
|
|
137
|
+
// agent config bundle.
|
|
138
|
+
//
|
|
139
|
+
// UNIQUENESS: NULLs compare distinct in a plain unique index, so the
|
|
140
|
+
// deployment-wide (accountId NULL) uniqueness is a partial unique index
|
|
141
|
+
// hand-written in 20261116000000_github_enterprise_app_account_id/migration.sql:
|
|
142
|
+
// GitHubEnterpriseApp_role_global_key (accountId NULL)
|
|
143
|
+
// Prisma's schema diff does not see it; keep it when editing this model.
|
|
136
144
|
|
|
137
145
|
model GitHubEnterpriseApp {
|
|
138
|
-
|
|
146
|
+
id String @id @default(cuid())
|
|
147
|
+
accountId String?
|
|
148
|
+
account Account? @relation(fields: [accountId], references: [id], onDelete: Cascade)
|
|
149
|
+
role String // 'installer' | 'lookup'
|
|
139
150
|
appId String
|
|
140
151
|
slug String
|
|
141
152
|
enterpriseSlug String? // installer only
|
|
@@ -145,6 +156,8 @@ model GitHubEnterpriseApp {
|
|
|
145
156
|
lastValidationError String?
|
|
146
157
|
createdAt DateTime @default(now())
|
|
147
158
|
updatedAt DateTime @updatedAt
|
|
159
|
+
|
|
160
|
+
@@unique([accountId, role])
|
|
148
161
|
}
|
|
149
162
|
|
|
150
163
|
// ─── Agent Cron Jobs ──────────────────────────────────────────────────────────
|
|
@@ -279,6 +292,7 @@ model Account {
|
|
|
279
292
|
members AccountMember[]
|
|
280
293
|
invites AccountInvite[]
|
|
281
294
|
templates AgentTemplate[]
|
|
295
|
+
githubEnterpriseApps GitHubEnterpriseApp[]
|
|
282
296
|
}
|
|
283
297
|
|
|
284
298
|
// ─── Agent Templates ──────────────────────────────────────────────────────────
|
|
@@ -667,6 +681,8 @@ model AgentMarketplace {
|
|
|
667
681
|
name String
|
|
668
682
|
source String
|
|
669
683
|
ref String?
|
|
684
|
+
rowSource String @default("custom") // TMK-2.1: 'template' | 'custom'; named rowSource because source is the git URL
|
|
685
|
+
enabled Boolean @default(true) // TMK-2.1: false = tombstone of a deleted template row; hidden from the config bundle
|
|
670
686
|
createdAt DateTime @default(now())
|
|
671
687
|
updatedAt DateTime @updatedAt
|
|
672
688
|
|
|
@@ -238,6 +238,118 @@ describeOrSkip("AgentMarketplaceService + routes (integration)", () => {
|
|
|
238
238
|
});
|
|
239
239
|
});
|
|
240
240
|
|
|
241
|
+
describe("row source and tombstones (TMK-2.1)", () => {
|
|
242
|
+
const seedTemplate = (agentId: string, name = "tpl") =>
|
|
243
|
+
prisma.agentMarketplace.create({
|
|
244
|
+
data: {
|
|
245
|
+
agentId,
|
|
246
|
+
name,
|
|
247
|
+
source: "o/r",
|
|
248
|
+
rowSource: "template",
|
|
249
|
+
enabled: true,
|
|
250
|
+
},
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it("upsert writes custom/enabled and overrides a template row", async () => {
|
|
254
|
+
const tpl = await seedTemplate(agentA);
|
|
255
|
+
const res = await adminApp.request(
|
|
256
|
+
`/agents/${agentA}/marketplaces`,
|
|
257
|
+
json(tokenA, { name: "tpl", source: "o/other" }),
|
|
258
|
+
);
|
|
259
|
+
expect(res.status).toBe(201);
|
|
260
|
+
const body = (await res.json()).marketplace;
|
|
261
|
+
expect(body.rowSource).toBe("custom");
|
|
262
|
+
expect(body.enabled).toBe(true);
|
|
263
|
+
const row = await prisma.agentMarketplace.findUnique({
|
|
264
|
+
where: { id: tpl.id },
|
|
265
|
+
});
|
|
266
|
+
expect(row?.rowSource).toBe("custom");
|
|
267
|
+
expect(row?.source).toBe("o/other");
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it("DELETE tombstones a template row and removes a custom row", async () => {
|
|
271
|
+
const tpl = await seedTemplate(agentA);
|
|
272
|
+
const custom = await service.upsert(agentA, {
|
|
273
|
+
name: "mine",
|
|
274
|
+
source: "o/m",
|
|
275
|
+
});
|
|
276
|
+
for (const id of [tpl.id, custom.id]) {
|
|
277
|
+
const res = await adminApp.request(
|
|
278
|
+
`/agents/${agentA}/marketplaces/${id}`,
|
|
279
|
+
json(tokenA, undefined, "DELETE"),
|
|
280
|
+
);
|
|
281
|
+
expect(res.status).toBe(204);
|
|
282
|
+
}
|
|
283
|
+
const tomb = await prisma.agentMarketplace.findUnique({
|
|
284
|
+
where: { id: tpl.id },
|
|
285
|
+
});
|
|
286
|
+
expect(tomb?.enabled).toBe(false);
|
|
287
|
+
expect(tomb?.rowSource).toBe("custom");
|
|
288
|
+
expect(
|
|
289
|
+
await prisma.agentMarketplace.findUnique({ where: { id: custom.id } }),
|
|
290
|
+
).toBeNull();
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
it("addFromTemplate creates a template row, refreshes it, and leaves custom rows alone", async () => {
|
|
294
|
+
const created = await service.addFromTemplate(agentA, {
|
|
295
|
+
name: "tpl",
|
|
296
|
+
source: "o/r",
|
|
297
|
+
ref: "v1",
|
|
298
|
+
});
|
|
299
|
+
expect(created.rowSource).toBe("template");
|
|
300
|
+
expect(created.enabled).toBe(true);
|
|
301
|
+
const refreshed = await service.addFromTemplate(agentA, {
|
|
302
|
+
name: "tpl",
|
|
303
|
+
source: "o/r2",
|
|
304
|
+
ref: null,
|
|
305
|
+
});
|
|
306
|
+
expect(refreshed.id).toBe(created.id);
|
|
307
|
+
expect(refreshed.source).toBe("o/r2");
|
|
308
|
+
expect(refreshed.rowSource).toBe("template");
|
|
309
|
+
|
|
310
|
+
const custom = await service.upsert(agentA, {
|
|
311
|
+
name: "mine",
|
|
312
|
+
source: "o/m",
|
|
313
|
+
});
|
|
314
|
+
const untouched = await service.addFromTemplate(agentA, {
|
|
315
|
+
name: "mine",
|
|
316
|
+
source: "o/x",
|
|
317
|
+
});
|
|
318
|
+
expect(untouched.source).toBe("o/m");
|
|
319
|
+
expect(untouched.rowSource).toBe("custom");
|
|
320
|
+
expect(untouched.id).toBe(custom.id);
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
it("addFromTemplate validates input like upsert", async () => {
|
|
324
|
+
await expect(
|
|
325
|
+
(async () =>
|
|
326
|
+
service.addFromTemplate(agentA, { name: "m", source: "../etc" }))(),
|
|
327
|
+
).rejects.toThrow(UnprocessableEntityError);
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
it("GET lists rowSource/enabled and the config bundle omits tombstones", async () => {
|
|
331
|
+
const tpl = await seedTemplate(agentA, "gone");
|
|
332
|
+
await service.upsert(agentA, { name: "kept", source: "o/k" });
|
|
333
|
+
await adminApp.request(
|
|
334
|
+
`/agents/${agentA}/marketplaces/${tpl.id}`,
|
|
335
|
+
json(tokenA, undefined, "DELETE"),
|
|
336
|
+
);
|
|
337
|
+
const list = await adminApp.request(
|
|
338
|
+
`/agents/${agentA}/marketplaces`,
|
|
339
|
+
get(tokenA),
|
|
340
|
+
);
|
|
341
|
+
const rows = (await list.json()).marketplaces;
|
|
342
|
+
expect(rows.map((r: { enabled: boolean }) => r.enabled).sort()).toEqual([
|
|
343
|
+
false,
|
|
344
|
+
true,
|
|
345
|
+
]);
|
|
346
|
+
const cfg = await runtimeApp.request(`/${agentA}/config`, get(tokenA));
|
|
347
|
+
expect((await cfg.json()).marketplaces).toEqual([
|
|
348
|
+
{ name: "kept", source: "o/k", ref: null },
|
|
349
|
+
]);
|
|
350
|
+
});
|
|
351
|
+
});
|
|
352
|
+
|
|
241
353
|
describe("GET /agents/:id/config", () => {
|
|
242
354
|
it("includes marketplaces: [] when none", async () => {
|
|
243
355
|
const res = await runtimeApp.request(`/${agentA}/config`, get(tokenA));
|
|
@@ -79,4 +79,13 @@ describeOrSkip("AgentMarketplace (integration)", () => {
|
|
|
79
79
|
await prisma.agent.delete({ where: { id: agentId } });
|
|
80
80
|
expect(await prisma.agentMarketplace.count({ where: { agentId } })).toBe(0);
|
|
81
81
|
});
|
|
82
|
+
|
|
83
|
+
it("defaults rowSource to custom and enabled to true", async () => {
|
|
84
|
+
const agentId = await createAgent();
|
|
85
|
+
const row = await prisma.agentMarketplace.create({
|
|
86
|
+
data: { agentId, name: "d", source: "o/r" },
|
|
87
|
+
});
|
|
88
|
+
expect(row.rowSource).toBe("custom");
|
|
89
|
+
expect(row.enabled).toBe(true);
|
|
90
|
+
});
|
|
82
91
|
});
|
|
@@ -20,6 +20,7 @@ import type {
|
|
|
20
20
|
PrismaClient,
|
|
21
21
|
} from "../prisma/client/client.ts";
|
|
22
22
|
import { NotFoundError, UnprocessableEntityError } from "./errors.ts";
|
|
23
|
+
import type { PrismaTransactionClient } from "./prisma-tx.ts";
|
|
23
24
|
|
|
24
25
|
export type { AgentMarketplace };
|
|
25
26
|
|
|
@@ -99,8 +100,49 @@ export class AgentMarketplaceService {
|
|
|
99
100
|
validateMarketplaceRef(ref);
|
|
100
101
|
return this.prisma.agentMarketplace.upsert({
|
|
101
102
|
where: { agentId_name: { agentId, name } },
|
|
102
|
-
create: {
|
|
103
|
-
|
|
103
|
+
create: {
|
|
104
|
+
agentId,
|
|
105
|
+
name,
|
|
106
|
+
source,
|
|
107
|
+
ref,
|
|
108
|
+
rowSource: "custom",
|
|
109
|
+
enabled: true,
|
|
110
|
+
},
|
|
111
|
+
update: { source, ref, rowSource: "custom", enabled: true },
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Internal reconcile write path (TMK-2.1); never exposed over HTTP.
|
|
117
|
+
* Creates a template-owned marketplace, or refreshes one that is still
|
|
118
|
+
* template-owned. A custom row (user edit or tombstone) is returned
|
|
119
|
+
* untouched. Validates input as upsert() does.
|
|
120
|
+
*/
|
|
121
|
+
async addFromTemplate(
|
|
122
|
+
agentId: string,
|
|
123
|
+
input: { name: string; source: string; ref?: string | null },
|
|
124
|
+
client: PrismaTransactionClient = this.prisma,
|
|
125
|
+
): Promise<AgentMarketplace> {
|
|
126
|
+
const { name, source } = input;
|
|
127
|
+
const ref = input.ref ?? null;
|
|
128
|
+
validateMarketplaceName(name);
|
|
129
|
+
validateMarketplaceSource(source);
|
|
130
|
+
validateMarketplaceRef(ref);
|
|
131
|
+
const existing = await client.agentMarketplace.findUnique({
|
|
132
|
+
where: { agentId_name: { agentId, name } },
|
|
133
|
+
});
|
|
134
|
+
if (existing?.rowSource === "custom") return existing;
|
|
135
|
+
return client.agentMarketplace.upsert({
|
|
136
|
+
where: { agentId_name: { agentId, name } },
|
|
137
|
+
create: {
|
|
138
|
+
agentId,
|
|
139
|
+
name,
|
|
140
|
+
source,
|
|
141
|
+
ref,
|
|
142
|
+
rowSource: "template",
|
|
143
|
+
enabled: true,
|
|
144
|
+
},
|
|
145
|
+
update: { source, ref, rowSource: "template", enabled: true },
|
|
104
146
|
});
|
|
105
147
|
}
|
|
106
148
|
|
|
@@ -115,6 +157,14 @@ export class AgentMarketplaceService {
|
|
|
115
157
|
if (!existing || existing.agentId !== agentId) {
|
|
116
158
|
throw new NotFoundError(`marketplace ${marketplaceId} not found`);
|
|
117
159
|
}
|
|
160
|
+
if (existing.rowSource === "template") {
|
|
161
|
+
// Tombstone so a later reconcile does not re-add the row.
|
|
162
|
+
await this.prisma.agentMarketplace.update({
|
|
163
|
+
where: { id: marketplaceId },
|
|
164
|
+
data: { enabled: false, rowSource: "custom" },
|
|
165
|
+
});
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
118
168
|
await this.prisma.agentMarketplace.delete({ where: { id: marketplaceId } });
|
|
119
169
|
}
|
|
120
170
|
}
|
package/src/agents-api.ts
CHANGED
|
@@ -3741,11 +3741,14 @@ function serializeMarketplace(row: {
|
|
|
3741
3741
|
name: string;
|
|
3742
3742
|
source: string;
|
|
3743
3743
|
ref: string | null;
|
|
3744
|
+
rowSource?: string;
|
|
3745
|
+
enabled?: boolean;
|
|
3744
3746
|
createdAt: Date;
|
|
3745
3747
|
updatedAt: Date;
|
|
3746
3748
|
}): z.infer<typeof AgentMarketplaceSchema> {
|
|
3747
3749
|
return {
|
|
3748
3750
|
...row,
|
|
3751
|
+
rowSource: row.rowSource === "template" ? "template" : "custom",
|
|
3749
3752
|
createdAt: row.createdAt.toISOString(),
|
|
3750
3753
|
updatedAt: row.updatedAt.toISOString(),
|
|
3751
3754
|
};
|
package/src/api.ts
CHANGED
|
@@ -166,9 +166,15 @@ interface AgentPluginServiceLike {
|
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
interface AgentMarketplaceServiceLike {
|
|
169
|
-
list(
|
|
170
|
-
|
|
171
|
-
|
|
169
|
+
list(agentId: string): Promise<
|
|
170
|
+
Array<{
|
|
171
|
+
name: string;
|
|
172
|
+
source: string;
|
|
173
|
+
ref: string | null;
|
|
174
|
+
/** TMK-2.1: false marks a tombstone, which the config bundle omits. */
|
|
175
|
+
enabled?: boolean;
|
|
176
|
+
}>
|
|
177
|
+
>;
|
|
172
178
|
}
|
|
173
179
|
|
|
174
180
|
export interface AgentPhaseMethodologyServiceLike {
|
|
@@ -370,11 +376,13 @@ export function createAgentRuntimeApp(deps: AgentRuntimeDeps): OpenAPIHono {
|
|
|
370
376
|
? { marketplace: "shipwright", plugin: p.name }
|
|
371
377
|
: { plugin: p.name.slice(0, at), marketplace: p.name.slice(at + 1) };
|
|
372
378
|
}),
|
|
373
|
-
marketplaces: (marketplaceRows ?? [])
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
379
|
+
marketplaces: (marketplaceRows ?? [])
|
|
380
|
+
.filter((m) => m.enabled !== false)
|
|
381
|
+
.map((m) => ({
|
|
382
|
+
name: m.name,
|
|
383
|
+
source: m.source,
|
|
384
|
+
ref: m.ref,
|
|
385
|
+
})),
|
|
378
386
|
repos: agent.repos,
|
|
379
387
|
reviewAuthorAllowlist: agent.reviewAuthorAllowlist,
|
|
380
388
|
patchAuthorAllowlist: agent.patchAuthorAllowlist,
|
|
@@ -145,7 +145,7 @@ describeOrSkip("github-enterprise API (integration)", () => {
|
|
|
145
145
|
const base = "/admin/settings/github-enterprise/apps/lookup";
|
|
146
146
|
const fields = { appId: "777", slug: "example-lookup" };
|
|
147
147
|
const snapshot = async () => {
|
|
148
|
-
const row = await prisma.gitHubEnterpriseApp.
|
|
148
|
+
const row = await prisma.gitHubEnterpriseApp.findFirst({
|
|
149
149
|
where: { role: "lookup" },
|
|
150
150
|
});
|
|
151
151
|
return {
|
|
@@ -169,7 +169,7 @@ describeOrSkip("github-enterprise API (integration)", () => {
|
|
|
169
169
|
const res = await ui.request(base, { method: "POST", body: upload });
|
|
170
170
|
expect(res.status).toBe(302);
|
|
171
171
|
expect(await snapshot()).toEqual(pasted);
|
|
172
|
-
const row = await prisma.gitHubEnterpriseApp.
|
|
172
|
+
const row = await prisma.gitHubEnterpriseApp.findFirst({
|
|
173
173
|
where: { role: "lookup" },
|
|
174
174
|
});
|
|
175
175
|
expect(row?.privateKeyEncrypted).not.toContain(PEM_BODY);
|
|
@@ -194,7 +194,7 @@ describeOrSkip("github-enterprise API (integration)", () => {
|
|
|
194
194
|
expect(text).not.toContain("ghs_cassette");
|
|
195
195
|
expect(JSON.parse(text)).toMatchObject({ ok: true, status: "valid" });
|
|
196
196
|
|
|
197
|
-
const row = await prisma.gitHubEnterpriseApp.
|
|
197
|
+
const row = await prisma.gitHubEnterpriseApp.findFirst({
|
|
198
198
|
where: { role: "installer" },
|
|
199
199
|
});
|
|
200
200
|
expect(row?.lastValidationStatus).toBe("valid");
|
|
@@ -223,7 +223,7 @@ describeOrSkip("github-enterprise API (integration)", () => {
|
|
|
223
223
|
},
|
|
224
224
|
);
|
|
225
225
|
expect(await res.json()).toMatchObject({ ok: false, status: "error" });
|
|
226
|
-
const row = await prisma.gitHubEnterpriseApp.
|
|
226
|
+
const row = await prisma.gitHubEnterpriseApp.findFirst({
|
|
227
227
|
where: { role: "installer" },
|
|
228
228
|
});
|
|
229
229
|
expect(row?.lastValidationStatus).toBe("error");
|
|
@@ -304,7 +304,7 @@ describeOrSkip("github-enterprise API (integration)", () => {
|
|
|
304
304
|
const envService = new AgentEnvService(prisma, identityCrypto);
|
|
305
305
|
await envService.upsert(agent.id, { GH_APP_SLUG: "example-agent-app" });
|
|
306
306
|
await put(build());
|
|
307
|
-
const row = await prisma.gitHubEnterpriseApp.
|
|
307
|
+
const row = await prisma.gitHubEnterpriseApp.findFirst({
|
|
308
308
|
where: { role: "installer" },
|
|
309
309
|
});
|
|
310
310
|
const needles = [
|
|
@@ -88,7 +88,7 @@ describeOrSkip("GitHubEnterpriseAppService (integration)", () => {
|
|
|
88
88
|
|
|
89
89
|
it("stores the key encrypted and round-trips it via getPrivateKey", async () => {
|
|
90
90
|
await service.save(installer);
|
|
91
|
-
const row = await prisma.gitHubEnterpriseApp.
|
|
91
|
+
const row = await prisma.gitHubEnterpriseApp.findFirst({
|
|
92
92
|
where: { role: "installer" },
|
|
93
93
|
});
|
|
94
94
|
expect(row?.privateKeyEncrypted).not.toContain("SUPERSECRETPEMBODY");
|
|
@@ -134,14 +134,14 @@ describeOrSkip("GitHubEnterpriseAppService (integration)", () => {
|
|
|
134
134
|
|
|
135
135
|
it("strict decrypt: tampered and legacy plain-text values throw", async () => {
|
|
136
136
|
await service.save(installer);
|
|
137
|
-
const row = await prisma.gitHubEnterpriseApp.
|
|
137
|
+
const row = await prisma.gitHubEnterpriseApp.findFirst({
|
|
138
138
|
where: { role: "installer" },
|
|
139
139
|
});
|
|
140
140
|
const [iv, ct, tag] = (row?.privateKeyEncrypted ?? "").split(":");
|
|
141
141
|
const flipped = (ct[0] === "0" ? "1" : "0") + ct.slice(1);
|
|
142
142
|
for (const bad of [`${iv}:${flipped}:${tag}`, PEM]) {
|
|
143
143
|
await prisma.gitHubEnterpriseApp.update({
|
|
144
|
-
where: {
|
|
144
|
+
where: { id: row?.id },
|
|
145
145
|
data: { privateKeyEncrypted: bad },
|
|
146
146
|
});
|
|
147
147
|
const err = await service.getPrivateKey("installer").catch((e) => e);
|
|
@@ -149,4 +149,102 @@ describeOrSkip("GitHubEnterpriseAppService (integration)", () => {
|
|
|
149
149
|
expect(err.message).not.toContain("SUPERSECRETPEMBODY");
|
|
150
150
|
}
|
|
151
151
|
});
|
|
152
|
+
|
|
153
|
+
describe("account scope", () => {
|
|
154
|
+
const lookup = { ...installer, role: "lookup" as const, appId: "900" };
|
|
155
|
+
let acctA: string;
|
|
156
|
+
let acctB: string;
|
|
157
|
+
|
|
158
|
+
beforeEach(async () => {
|
|
159
|
+
await prisma.account.deleteMany({
|
|
160
|
+
where: { name: { in: ["ghe-a", "ghe-b"] } },
|
|
161
|
+
});
|
|
162
|
+
acctA = (await prisma.account.create({ data: { name: "ghe-a" } })).id;
|
|
163
|
+
acctB = (await prisma.account.create({ data: { name: "ghe-b" } })).id;
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
afterEach(async () => {
|
|
167
|
+
await prisma.gitHubEnterpriseApp.deleteMany();
|
|
168
|
+
await prisma.account.deleteMany({
|
|
169
|
+
where: { id: { in: [acctA, acctB] } },
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it("get(role, accountId) prefers the account row, else falls back to deployment-wide", async () => {
|
|
174
|
+
await service.save(lookup);
|
|
175
|
+
expect((await service.get("lookup", acctA))?.appId).toBe("900");
|
|
176
|
+
await service.save({ ...lookup, accountId: acctA, appId: "901" });
|
|
177
|
+
const own = await service.get("lookup", acctA);
|
|
178
|
+
expect(own?.appId).toBe("901");
|
|
179
|
+
expect(own?.accountId).toBe(acctA);
|
|
180
|
+
expect((await service.get("lookup", acctB))?.appId).toBe("900");
|
|
181
|
+
expect((await service.get("lookup"))?.appId).toBe("900");
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it("get(role) without accountId never sees an account row", async () => {
|
|
185
|
+
await service.save({ ...lookup, accountId: acctA });
|
|
186
|
+
expect(await service.get("lookup")).toBeNull();
|
|
187
|
+
expect(await service.list()).toEqual([]);
|
|
188
|
+
expect(await service.list(acctA)).toHaveLength(1);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it("accounts are isolated: save/delete/recordValidation hit only the targeted row", async () => {
|
|
192
|
+
await service.save(lookup);
|
|
193
|
+
await service.save({ ...lookup, accountId: acctA, appId: "A" });
|
|
194
|
+
await service.save({ ...lookup, accountId: acctB, appId: "B" });
|
|
195
|
+
await service.recordValidation("lookup", { status: "ok" }, acctA);
|
|
196
|
+
expect((await service.get("lookup", acctA))?.lastValidationStatus).toBe(
|
|
197
|
+
"ok",
|
|
198
|
+
);
|
|
199
|
+
expect((await service.get("lookup", acctB))?.lastValidationStatus).toBe(
|
|
200
|
+
null,
|
|
201
|
+
);
|
|
202
|
+
expect((await service.get("lookup"))?.lastValidationStatus).toBe(null);
|
|
203
|
+
await service.delete("lookup", acctA);
|
|
204
|
+
expect((await service.get("lookup", acctA))?.appId).toBe("900");
|
|
205
|
+
expect((await service.get("lookup", acctB))?.appId).toBe("B");
|
|
206
|
+
expect(await prisma.gitHubEnterpriseApp.count()).toBe(2);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it("getPrivateKey follows the same fallback and decrypts the right row", async () => {
|
|
210
|
+
await service.save(lookup);
|
|
211
|
+
await service.save({
|
|
212
|
+
...lookup,
|
|
213
|
+
accountId: acctA,
|
|
214
|
+
privateKey: `${PEM}-ACCT`,
|
|
215
|
+
});
|
|
216
|
+
expect(await service.getPrivateKey("lookup", acctA)).toBe(`${PEM}-ACCT`);
|
|
217
|
+
expect(await service.getPrivateKey("lookup", acctB)).toBe(PEM);
|
|
218
|
+
expect(await service.getPrivateKey("lookup")).toBe(PEM);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it("save is idempotent per (accountId, role), including the NULL scope", async () => {
|
|
222
|
+
await service.save(lookup);
|
|
223
|
+
await service.save({ ...lookup, appId: "again" });
|
|
224
|
+
await service.save({ ...lookup, accountId: acctA });
|
|
225
|
+
await service.save({ ...lookup, accountId: acctA, appId: "again" });
|
|
226
|
+
expect(await prisma.gitHubEnterpriseApp.count()).toBe(2);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it("the database rejects a second deployment-wide row for a role", async () => {
|
|
230
|
+
await service.save(lookup);
|
|
231
|
+
const dup = async () =>
|
|
232
|
+
prisma.gitHubEnterpriseApp.create({
|
|
233
|
+
data: {
|
|
234
|
+
role: "lookup",
|
|
235
|
+
appId: "x",
|
|
236
|
+
slug: "x",
|
|
237
|
+
privateKeyEncrypted: "x",
|
|
238
|
+
},
|
|
239
|
+
});
|
|
240
|
+
await expect(dup()).rejects.toThrow();
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it("deleting an account cascades to its apps only", async () => {
|
|
244
|
+
await service.save(lookup);
|
|
245
|
+
await service.save({ ...lookup, accountId: acctA });
|
|
246
|
+
await prisma.account.delete({ where: { id: acctA } });
|
|
247
|
+
expect(await prisma.gitHubEnterpriseApp.count()).toBe(1);
|
|
248
|
+
});
|
|
249
|
+
});
|
|
152
250
|
});
|