@app-vitals/agent-admin 1.106.1 → 1.107.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 +0 -280
- package/openapi.platform.json +0 -280
- package/package.json +2 -2
- package/prisma/client/browser.ts +0 -10
- package/prisma/client/client.ts +0 -10
- package/prisma/client/internal/class.ts +4 -24
- package/prisma/client/internal/prismaNamespace.ts +1 -181
- package/prisma/client/internal/prismaNamespaceBrowser.ts +0 -30
- package/prisma/client/models.ts +0 -2
- package/prisma/migrations/20261129000000_drop_cron_run_transcripts/migration.sql +9 -0
- package/prisma/schema/schema.prisma +0 -34
- package/src/account-member-removal.integration.test.ts +190 -0
- package/src/account-members.ts +7 -1
- package/src/admin-boot.ts +0 -11
- package/src/admin-ui-account-pages.ts +15 -2
- package/src/admin-ui-account-pages.unit.test.ts +4 -0
- package/src/admin-ui-accounts-pages.ts +14 -2
- package/src/admin-ui-accounts-pages.unit.test.ts +1 -0
- package/src/admin-ui.smoke.test.ts +163 -1
- package/src/admin-ui.ts +35 -1
- package/src/agents-api.ts +0 -13
- package/src/api.smoke.test.ts +6 -73
- package/src/api.ts +0 -17
- package/src/cron-run-now.integration.test.ts +163 -0
- package/src/cron-run-transcripts-removed.smoke.test.ts +82 -0
- package/src/drop-cron-run-transcripts-migration.integration.test.ts +114 -0
- package/src/member-id-stamp.ts +26 -0
- package/src/openapi-schemas.ts +0 -55
- package/src/push-service.integration.test.ts +12 -0
- package/src/push-service.ts +7 -4
- package/src/push-service.unit.test.ts +24 -0
- package/src/push-toggle.ts +10 -0
- package/src/repo-access-config.ts +1 -1
- package/prisma/client/models/AgentCronRunTranscript.ts +0 -1339
- package/prisma/client/models/AgentTranscriptRead.ts +0 -1177
- package/src/cron-run-transcripts.integration.test.ts +0 -220
- package/src/cron-run-transcripts.smoke.test.ts +0 -286
- package/src/cron-run-transcripts.ts +0 -314
- package/src/transcript-config.ts +0 -30
- package/src/transcript-config.unit.test.ts +0 -50
|
@@ -85,6 +85,7 @@ describe("renderAccountDetailPage", () => {
|
|
|
85
85
|
|
|
86
86
|
test("edit form, suspend button, agents, members, invites", () => {
|
|
87
87
|
const html = renderAccountDetailPage(base);
|
|
88
|
+
expect(html).toContain("notification settings are removed");
|
|
88
89
|
expect(html).toContain('action="/admin/accounts/a1/update"');
|
|
89
90
|
expect(html).toContain('name="maxAgents"');
|
|
90
91
|
expect(html).toContain('value="2026-03-05"');
|
|
@@ -7491,7 +7491,8 @@ function makeFakePushService(
|
|
|
7491
7491
|
p256dh: string,
|
|
7492
7492
|
auth: string,
|
|
7493
7493
|
) => Promise<
|
|
7494
|
-
|
|
7494
|
+
| { ok: true }
|
|
7495
|
+
| { ok: false; reason: "unavailable" | "store_failed" | "no_member" }
|
|
7495
7496
|
> = async () => ({ ok: true }),
|
|
7496
7497
|
unsubscribe: (
|
|
7497
7498
|
userEmail: string,
|
|
@@ -7569,6 +7570,27 @@ describe("admin UI — POST /admin/chat/:agentId/push/subscribe", () => {
|
|
|
7569
7570
|
expect(await res.json()).toEqual({ error: "bad_request" });
|
|
7570
7571
|
});
|
|
7571
7572
|
|
|
7573
|
+
it("returns 409 no_member when the user has no account member record", async () => {
|
|
7574
|
+
const deps = makeMockDeps({
|
|
7575
|
+
pushService: makeFakePushService(undefined, async () => ({
|
|
7576
|
+
ok: false,
|
|
7577
|
+
reason: "no_member",
|
|
7578
|
+
})),
|
|
7579
|
+
vapidPublicKey: "test-vapid-public-key",
|
|
7580
|
+
});
|
|
7581
|
+
const app = createAdminUIApp(deps);
|
|
7582
|
+
const res = await app.request(`/admin/chat/${AGENT_ID}/push/subscribe`, {
|
|
7583
|
+
method: "POST",
|
|
7584
|
+
body: JSON.stringify(PUSH_SUBSCRIPTION_BODY),
|
|
7585
|
+
headers: {
|
|
7586
|
+
"Content-Type": "application/json",
|
|
7587
|
+
Cookie: `admin_session=${cookie}`,
|
|
7588
|
+
},
|
|
7589
|
+
});
|
|
7590
|
+
expect(res.status).toBe(409);
|
|
7591
|
+
expect(await res.json()).toEqual({ error: "no_member" });
|
|
7592
|
+
});
|
|
7593
|
+
|
|
7572
7594
|
it("upserts the subscription and returns ok:true when push is enabled", async () => {
|
|
7573
7595
|
let subscribeCalledWith: unknown;
|
|
7574
7596
|
const deps = makeMockDeps({
|
|
@@ -7992,3 +8014,143 @@ describe("agent create requires owner or admin (ACM-7.3)", () => {
|
|
|
7992
8014
|
expect(res.status).toBe(200);
|
|
7993
8015
|
});
|
|
7994
8016
|
});
|
|
8017
|
+
|
|
8018
|
+
// ─── Admin sign-in ensures an account member record ──────────────────────────
|
|
8019
|
+
|
|
8020
|
+
describe("admin UI — admin sign-in ensures an AccountMember", () => {
|
|
8021
|
+
type EnsureFn = NonNullable<
|
|
8022
|
+
Parameters<typeof makeMockDeps>[0]
|
|
8023
|
+
>["ensureAccountMember"];
|
|
8024
|
+
|
|
8025
|
+
function googleCb(nonce = "n1"): Request {
|
|
8026
|
+
const oauthState = encodeURIComponent(JSON.stringify({ nonce }));
|
|
8027
|
+
return new Request(
|
|
8028
|
+
`https://example.com/admin/auth/callback?state=${nonce}&code=c`,
|
|
8029
|
+
{ headers: { Cookie: `oauth_state=${oauthState}` } },
|
|
8030
|
+
);
|
|
8031
|
+
}
|
|
8032
|
+
function oktaCb(nonce = "n1"): Request {
|
|
8033
|
+
const oauthState = encodeURIComponent(JSON.stringify({ nonce }));
|
|
8034
|
+
return new Request(
|
|
8035
|
+
`https://example.com/admin/auth/okta/callback?state=${nonce}&code=c`,
|
|
8036
|
+
{ headers: { Cookie: `oauth_state=${oauthState}` } },
|
|
8037
|
+
);
|
|
8038
|
+
}
|
|
8039
|
+
const okResult = {
|
|
8040
|
+
ok: true,
|
|
8041
|
+
created: true,
|
|
8042
|
+
member: { id: "m1" },
|
|
8043
|
+
} as unknown as Awaited<ReturnType<NonNullable<EnsureFn>>>;
|
|
8044
|
+
|
|
8045
|
+
for (const [name, mk] of [
|
|
8046
|
+
["Google", googleCb],
|
|
8047
|
+
["Okta", oktaCb],
|
|
8048
|
+
] as const) {
|
|
8049
|
+
it(`${name}: an allowlisted admin gets ensured with no agent, role via admin creator`, async () => {
|
|
8050
|
+
const calls: unknown[] = [];
|
|
8051
|
+
const app = createAdminUIApp(
|
|
8052
|
+
makeMockDeps({
|
|
8053
|
+
ensureAccountMember: async (input) => {
|
|
8054
|
+
calls.push(input);
|
|
8055
|
+
return okResult;
|
|
8056
|
+
},
|
|
8057
|
+
}),
|
|
8058
|
+
);
|
|
8059
|
+
const res = await app.request(mk());
|
|
8060
|
+
expect(res.status).toBe(302);
|
|
8061
|
+
expect(res.headers.get("Location")).toBe("/admin/agents");
|
|
8062
|
+
expect(res.headers.get("Set-Cookie") ?? "").toContain("admin_session=");
|
|
8063
|
+
expect(calls).toEqual([
|
|
8064
|
+
{
|
|
8065
|
+
email: "admin@example.com",
|
|
8066
|
+
agentAccountId: null,
|
|
8067
|
+
creator: { platformAdmin: true, ownerOfAccountId: null },
|
|
8068
|
+
},
|
|
8069
|
+
]);
|
|
8070
|
+
});
|
|
8071
|
+
|
|
8072
|
+
it(`${name}: sign-in succeeds when no account can be chosen`, async () => {
|
|
8073
|
+
for (const code of ["no_account", "ambiguous_account"] as const) {
|
|
8074
|
+
const app = createAdminUIApp(
|
|
8075
|
+
makeMockDeps({
|
|
8076
|
+
ensureAccountMember: async () => ({
|
|
8077
|
+
ok: false,
|
|
8078
|
+
code,
|
|
8079
|
+
message: "nope",
|
|
8080
|
+
}),
|
|
8081
|
+
}),
|
|
8082
|
+
);
|
|
8083
|
+
const res = await app.request(mk());
|
|
8084
|
+
expect(res.status).toBe(302);
|
|
8085
|
+
expect(res.headers.get("Location")).toBe("/admin/agents");
|
|
8086
|
+
expect(res.headers.get("Set-Cookie") ?? "").toContain("admin_session=");
|
|
8087
|
+
}
|
|
8088
|
+
});
|
|
8089
|
+
|
|
8090
|
+
it(`${name}: sign-in succeeds when ensure throws`, async () => {
|
|
8091
|
+
const app = createAdminUIApp(
|
|
8092
|
+
makeMockDeps({
|
|
8093
|
+
ensureAccountMember: async () => {
|
|
8094
|
+
throw new Error("db down");
|
|
8095
|
+
},
|
|
8096
|
+
}),
|
|
8097
|
+
);
|
|
8098
|
+
const res = await app.request(mk());
|
|
8099
|
+
expect(res.status).toBe(302);
|
|
8100
|
+
expect(res.headers.get("Location")).toBe("/admin/agents");
|
|
8101
|
+
expect(res.headers.get("Set-Cookie") ?? "").toContain("admin_session=");
|
|
8102
|
+
});
|
|
8103
|
+
|
|
8104
|
+
it(`${name}: a non-admin sign-in does not run ensure`, async () => {
|
|
8105
|
+
let called = false;
|
|
8106
|
+
const app = createAdminUIApp(
|
|
8107
|
+
makeMockDeps({
|
|
8108
|
+
adminAllowedEmails: ["someone-else@example.com"],
|
|
8109
|
+
ensureAccountMember: async () => {
|
|
8110
|
+
called = true;
|
|
8111
|
+
return okResult;
|
|
8112
|
+
},
|
|
8113
|
+
}),
|
|
8114
|
+
);
|
|
8115
|
+
const res = await app.request(mk());
|
|
8116
|
+
expect(called).toBe(false);
|
|
8117
|
+
// Unchanged behavior: no AgentMember rows -> the existing outcome.
|
|
8118
|
+
const baseline = await createAdminUIApp(
|
|
8119
|
+
makeMockDeps({ adminAllowedEmails: ["someone-else@example.com"] }),
|
|
8120
|
+
).request(mk());
|
|
8121
|
+
expect(res.status).toBe(baseline.status);
|
|
8122
|
+
});
|
|
8123
|
+
}
|
|
8124
|
+
|
|
8125
|
+
it("an existing record is passed through unchanged (created:false)", async () => {
|
|
8126
|
+
const app = createAdminUIApp(
|
|
8127
|
+
makeMockDeps({
|
|
8128
|
+
ensureAccountMember: async () =>
|
|
8129
|
+
({
|
|
8130
|
+
ok: true,
|
|
8131
|
+
created: false,
|
|
8132
|
+
member: { id: "m1" },
|
|
8133
|
+
}) as unknown as Awaited<ReturnType<NonNullable<EnsureFn>>>,
|
|
8134
|
+
}),
|
|
8135
|
+
);
|
|
8136
|
+
const res = await app.request(googleCb());
|
|
8137
|
+
expect(res.status).toBe(302);
|
|
8138
|
+
});
|
|
8139
|
+
|
|
8140
|
+
it("dev-login ensures the dev admin and still signs in when ensure throws", async () => {
|
|
8141
|
+
const emails: string[] = [];
|
|
8142
|
+
const app = createAdminUIApp(
|
|
8143
|
+
makeMockDeps({
|
|
8144
|
+
devAuthEnabled: true,
|
|
8145
|
+
ensureAccountMember: async (input) => {
|
|
8146
|
+
emails.push(input.email);
|
|
8147
|
+
throw new Error("boom");
|
|
8148
|
+
},
|
|
8149
|
+
}),
|
|
8150
|
+
);
|
|
8151
|
+
const res = await app.request("/admin/dev-login");
|
|
8152
|
+
expect(res.status).toBe(302);
|
|
8153
|
+
expect(res.headers.get("Set-Cookie") ?? "").toContain("admin_session=");
|
|
8154
|
+
expect(emails).toEqual(["dev@localhost"]);
|
|
8155
|
+
});
|
|
8156
|
+
});
|
package/src/admin-ui.ts
CHANGED
|
@@ -1139,6 +1139,34 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
1139
1139
|
|
|
1140
1140
|
// ─── Login / OAuth / Logout ───────────────────────────────────────────────
|
|
1141
1141
|
|
|
1142
|
+
/**
|
|
1143
|
+
* Best-effort: an allowlisted platform admin signs in with an AccountMember
|
|
1144
|
+
* record (role member; admin powers come from the allowlist), so push
|
|
1145
|
+
* subscriptions and other member-keyed rows attach to them. Never blocks
|
|
1146
|
+
* sign-in: no/ambiguous account or any error is logged and ignored (the
|
|
1147
|
+
* ensure operation runs in one transaction, so a failure writes nothing).
|
|
1148
|
+
*/
|
|
1149
|
+
async function ensureAdminMemberRecord(email: string): Promise<void> {
|
|
1150
|
+
if (!ensureAccountMember) return;
|
|
1151
|
+
try {
|
|
1152
|
+
const ensured = await ensureAccountMember({
|
|
1153
|
+
email: email.toLowerCase(),
|
|
1154
|
+
agentAccountId: null,
|
|
1155
|
+
creator: { platformAdmin: true, ownerOfAccountId: null },
|
|
1156
|
+
});
|
|
1157
|
+
if (!ensured.ok) {
|
|
1158
|
+
console.warn(
|
|
1159
|
+
`[admin] sign-in: no account member created for admin (${ensured.code})`,
|
|
1160
|
+
);
|
|
1161
|
+
}
|
|
1162
|
+
} catch (err) {
|
|
1163
|
+
console.error(
|
|
1164
|
+
"[admin] sign-in: ensuring admin account member failed",
|
|
1165
|
+
err,
|
|
1166
|
+
);
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1142
1170
|
/**
|
|
1143
1171
|
* Shared post-authentication step for every OAuth provider (Google, Okta):
|
|
1144
1172
|
* checks the verified-email + admin-allowlist/AgentMember-fallback rules,
|
|
@@ -1171,7 +1199,9 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
1171
1199
|
.map((e) => e.toLowerCase())
|
|
1172
1200
|
.includes(userInfo.email.toLowerCase());
|
|
1173
1201
|
|
|
1174
|
-
if (
|
|
1202
|
+
if (isAdmin) {
|
|
1203
|
+
await ensureAdminMemberRecord(userInfo.email);
|
|
1204
|
+
} else {
|
|
1175
1205
|
const memberships = await agentMemberService.listByEmail(
|
|
1176
1206
|
userInfo.email.toLowerCase(),
|
|
1177
1207
|
);
|
|
@@ -1540,6 +1570,7 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
1540
1570
|
"dev@localhost",
|
|
1541
1571
|
true,
|
|
1542
1572
|
);
|
|
1573
|
+
await ensureAdminMemberRecord("dev@localhost");
|
|
1543
1574
|
setCookie(c, SESSION_COOKIE, token, {
|
|
1544
1575
|
httpOnly: true,
|
|
1545
1576
|
secure: appBaseUrl.startsWith("https://"),
|
|
@@ -5339,6 +5370,9 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
5339
5370
|
auth,
|
|
5340
5371
|
);
|
|
5341
5372
|
if (!result?.ok) {
|
|
5373
|
+
if (result?.reason === "no_member") {
|
|
5374
|
+
return c.json({ error: "no_member" }, 409);
|
|
5375
|
+
}
|
|
5342
5376
|
if (result?.reason === "store_failed") {
|
|
5343
5377
|
return c.json({ error: "store_failed" }, 500);
|
|
5344
5378
|
}
|
package/src/agents-api.ts
CHANGED
|
@@ -98,10 +98,6 @@ import {
|
|
|
98
98
|
type CronRunNowDeps,
|
|
99
99
|
registerCronRunNowRoutes,
|
|
100
100
|
} from "./cron-run-now.ts";
|
|
101
|
-
import {
|
|
102
|
-
type CronRunTranscriptDeps,
|
|
103
|
-
registerCronRunTranscriptRoutes,
|
|
104
|
-
} from "./cron-run-transcripts.ts";
|
|
105
101
|
import {
|
|
106
102
|
creatorFromScope,
|
|
107
103
|
type MemberCreator,
|
|
@@ -396,11 +392,6 @@ export interface AdminDeps {
|
|
|
396
392
|
* route 503s, even with the flag on.
|
|
397
393
|
*/
|
|
398
394
|
chatClient?: AskChatClient;
|
|
399
|
-
/**
|
|
400
|
-
* Cron-run transcripts (COS-43.1): flag config + store. Absent or flag off
|
|
401
|
-
* -> the transcript routes 404. See cron-run-transcripts.ts.
|
|
402
|
-
*/
|
|
403
|
-
transcripts?: CronRunTranscriptDeps;
|
|
404
395
|
}
|
|
405
396
|
|
|
406
397
|
export type { AdminApiKey };
|
|
@@ -3311,10 +3302,6 @@ export function createAdminApp(deps: AdminDeps): OpenAPIHono<AdminAuthEnv> {
|
|
|
3311
3302
|
|
|
3312
3303
|
registerCronRunNowRoutes(app, { cronRunNow: deps.cronRunNow });
|
|
3313
3304
|
|
|
3314
|
-
// ─── Cron-run transcripts (COS-43.1) ──────────────────────────────────────
|
|
3315
|
-
|
|
3316
|
-
registerCronRunTranscriptRoutes(app, { transcripts: deps.transcripts });
|
|
3317
|
-
|
|
3318
3305
|
// ─── Plugins ───────────────────────────────────────────────────────────────
|
|
3319
3306
|
|
|
3320
3307
|
// POST /agents/:id/plugins — add a plugin
|
package/src/api.smoke.test.ts
CHANGED
|
@@ -246,8 +246,6 @@ function buildApp(opts?: {
|
|
|
246
246
|
maxFindings?: number;
|
|
247
247
|
cleanupMergedWorktrees?: boolean;
|
|
248
248
|
cleanupAfterDays?: number;
|
|
249
|
-
transcriptUploadEnabled?: boolean;
|
|
250
|
-
loopTranscriptAgentIds?: string[];
|
|
251
249
|
repoAccessCheckEnabled?: boolean;
|
|
252
250
|
}) {
|
|
253
251
|
const hasAgent = opts?.hasAgent ?? true;
|
|
@@ -322,8 +320,6 @@ function buildApp(opts?: {
|
|
|
322
320
|
agentTokenService: { validate: async () => null },
|
|
323
321
|
sessionSecret: SESSION_SECRET,
|
|
324
322
|
anthropicFederationEnabled: opts?.anthropicFederationEnabled,
|
|
325
|
-
transcriptUploadEnabled: opts?.transcriptUploadEnabled,
|
|
326
|
-
loopTranscriptAgentIds: opts?.loopTranscriptAgentIds,
|
|
327
323
|
repoAccessCheckEnabled: opts?.repoAccessCheckEnabled,
|
|
328
324
|
});
|
|
329
325
|
}
|
|
@@ -358,72 +354,13 @@ describe("GET /:id/config deprecated typeName alias (AGR-6.3)", () => {
|
|
|
358
354
|
});
|
|
359
355
|
});
|
|
360
356
|
|
|
361
|
-
describe("GET /:id/config features
|
|
362
|
-
|
|
363
|
-
|
|
357
|
+
describe("GET /:id/config features", () => {
|
|
358
|
+
test("features default to all off and carry no transcript flags", async () => {
|
|
359
|
+
const res = await buildApp().request(`/${KNOWN_AGENT_ID}/config`, {
|
|
364
360
|
headers: { Authorization: `Bearer ${VALID_ADMIN_KEY}` },
|
|
365
361
|
});
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
const body = await (await get(buildApp())).json();
|
|
369
|
-
expect(body.features).toEqual({
|
|
370
|
-
transcriptUpload: false,
|
|
371
|
-
repoAccessCheck: false,
|
|
372
|
-
loopTranscriptUpload: false,
|
|
373
|
-
});
|
|
374
|
-
});
|
|
375
|
-
|
|
376
|
-
test("features.transcriptUpload follows the transcript flag", async () => {
|
|
377
|
-
const body = await (
|
|
378
|
-
await get(buildApp({ transcriptUploadEnabled: true }))
|
|
379
|
-
).json();
|
|
380
|
-
expect(body.features).toEqual({
|
|
381
|
-
transcriptUpload: true,
|
|
382
|
-
repoAccessCheck: false,
|
|
383
|
-
loopTranscriptUpload: false,
|
|
384
|
-
});
|
|
385
|
-
});
|
|
386
|
-
});
|
|
387
|
-
|
|
388
|
-
describe("GET /:id/config features.loopTranscriptUpload", () => {
|
|
389
|
-
const loopFlag = async (opts: Parameters<typeof buildApp>[0]) => {
|
|
390
|
-
const res = await buildApp(opts).request(`/${KNOWN_AGENT_ID}/config`, {
|
|
391
|
-
headers: { Authorization: `Bearer ${VALID_ADMIN_KEY}` },
|
|
392
|
-
});
|
|
393
|
-
return (await res.json()).features.loopTranscriptUpload;
|
|
394
|
-
};
|
|
395
|
-
|
|
396
|
-
test("truth table: only a listed agent with the transcript flag on is true", async () => {
|
|
397
|
-
expect(await loopFlag({})).toBe(false);
|
|
398
|
-
expect(await loopFlag({ loopTranscriptAgentIds: [] })).toBe(false);
|
|
399
|
-
expect(
|
|
400
|
-
await loopFlag({
|
|
401
|
-
transcriptUploadEnabled: true,
|
|
402
|
-
loopTranscriptAgentIds: ["other-agent"],
|
|
403
|
-
}),
|
|
404
|
-
).toBe(false);
|
|
405
|
-
expect(
|
|
406
|
-
await loopFlag({
|
|
407
|
-
transcriptUploadEnabled: false,
|
|
408
|
-
loopTranscriptAgentIds: [KNOWN_AGENT_ID],
|
|
409
|
-
}),
|
|
410
|
-
).toBe(false);
|
|
411
|
-
expect(
|
|
412
|
-
await loopFlag({
|
|
413
|
-
transcriptUploadEnabled: true,
|
|
414
|
-
loopTranscriptAgentIds: [KNOWN_AGENT_ID],
|
|
415
|
-
}),
|
|
416
|
-
).toBe(true);
|
|
417
|
-
});
|
|
418
|
-
|
|
419
|
-
test("leaves features.transcriptUpload untouched", async () => {
|
|
420
|
-
const res = await buildApp({
|
|
421
|
-
transcriptUploadEnabled: false,
|
|
422
|
-
loopTranscriptAgentIds: [KNOWN_AGENT_ID],
|
|
423
|
-
}).request(`/${KNOWN_AGENT_ID}/config`, {
|
|
424
|
-
headers: { Authorization: `Bearer ${VALID_ADMIN_KEY}` },
|
|
425
|
-
});
|
|
426
|
-
expect((await res.json()).features.transcriptUpload).toBe(false);
|
|
362
|
+
const body = await res.json();
|
|
363
|
+
expect(body.features).toEqual({ repoAccessCheck: false });
|
|
427
364
|
});
|
|
428
365
|
});
|
|
429
366
|
|
|
@@ -433,11 +370,7 @@ describe("GET /:id/config features.repoAccessCheck (COS-44.1)", () => {
|
|
|
433
370
|
const res = await app.request(`/${KNOWN_AGENT_ID}/config`, {
|
|
434
371
|
headers: { Authorization: `Bearer ${VALID_ADMIN_KEY}` },
|
|
435
372
|
});
|
|
436
|
-
expect((await res.json()).features).toEqual({
|
|
437
|
-
transcriptUpload: false,
|
|
438
|
-
repoAccessCheck: true,
|
|
439
|
-
loopTranscriptUpload: false,
|
|
440
|
-
});
|
|
373
|
+
expect((await res.json()).features).toEqual({ repoAccessCheck: true });
|
|
441
374
|
});
|
|
442
375
|
});
|
|
443
376
|
|
package/src/api.ts
CHANGED
|
@@ -109,9 +109,7 @@ export interface AgentConfigResponse {
|
|
|
109
109
|
* before it keep compiling; the live handler always populates it.
|
|
110
110
|
*/
|
|
111
111
|
features?: {
|
|
112
|
-
transcriptUpload: boolean;
|
|
113
112
|
repoAccessCheck: boolean;
|
|
114
|
-
loopTranscriptUpload?: boolean;
|
|
115
113
|
};
|
|
116
114
|
}
|
|
117
115
|
|
|
@@ -206,17 +204,6 @@ export interface AgentRuntimeDeps {
|
|
|
206
204
|
agentTokenService: Pick<AgentTokenService, "validate">;
|
|
207
205
|
/** WIF-2.1: Anthropic federation is enabled; defaults to false. */
|
|
208
206
|
anthropicFederationEnabled?: boolean;
|
|
209
|
-
/**
|
|
210
|
-
* COS-43.1: SHIPWRIGHT_TRANSCRIPT_API_ENABLED is on — surfaced to the runtime
|
|
211
|
-
* as `features.transcriptUpload` in the config bundle. Defaults to false.
|
|
212
|
-
*/
|
|
213
|
-
transcriptUploadEnabled?: boolean;
|
|
214
|
-
/**
|
|
215
|
-
* SHIPWRIGHT_LOOP_TRANSCRIPT_AGENT_IDS: agent ids whose coding-loop runs
|
|
216
|
-
* upload transcripts. Combined with `transcriptUploadEnabled` into
|
|
217
|
-
* `features.loopTranscriptUpload`. Defaults to none.
|
|
218
|
-
*/
|
|
219
|
-
loopTranscriptAgentIds?: readonly string[];
|
|
220
207
|
/**
|
|
221
208
|
* COS-44.1: SHIPWRIGHT_AGENT_REPO_ACCESS_CHECK_ENABLED is on — surfaced to the
|
|
222
209
|
* runtime as `features.repoAccessCheck` in the config bundle. Defaults to false.
|
|
@@ -410,10 +397,6 @@ export function createAgentRuntimeApp(deps: AgentRuntimeDeps): OpenAPIHono {
|
|
|
410
397
|
cleanupMergedWorktrees: agent.cleanupMergedWorktrees,
|
|
411
398
|
cleanupAfterDays: agent.cleanupAfterDays,
|
|
412
399
|
features: {
|
|
413
|
-
transcriptUpload: deps.transcriptUploadEnabled === true,
|
|
414
|
-
loopTranscriptUpload:
|
|
415
|
-
deps.transcriptUploadEnabled === true &&
|
|
416
|
-
(deps.loopTranscriptAgentIds ?? []).includes(agent.id),
|
|
417
400
|
repoAccessCheck: deps.repoAccessCheckEnabled === true,
|
|
418
401
|
},
|
|
419
402
|
};
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* admin/src/cron-run-now.integration.test.ts
|
|
3
|
+
* CronRunNowService against a real Postgres (COS-42.1): cron lookup scoping
|
|
4
|
+
* and the atomic stamp + audit-row write, including expiry of a superseded
|
|
5
|
+
* pending request.
|
|
6
|
+
*
|
|
7
|
+
* Requires DATABASE_URL_ADMIN_TEST to be set; skips otherwise.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { afterEach, beforeEach, describe, expect, it } from "bun:test";
|
|
11
|
+
import type { PrismaClient } from "../prisma/client/client.ts";
|
|
12
|
+
import { CronRunNowService } from "./cron-run-now.ts";
|
|
13
|
+
import { createAdminPrismaClient } from "./prisma-client.ts";
|
|
14
|
+
|
|
15
|
+
const TEST_DB = process.env.DATABASE_URL_ADMIN_TEST;
|
|
16
|
+
const describeOrSkip = TEST_DB ? describe : describe.skip;
|
|
17
|
+
|
|
18
|
+
describeOrSkip("CronRunNowService (integration)", () => {
|
|
19
|
+
let prisma: PrismaClient;
|
|
20
|
+
let service: CronRunNowService;
|
|
21
|
+
let agentId: string;
|
|
22
|
+
let otherAgentId: string;
|
|
23
|
+
let cronId: string;
|
|
24
|
+
|
|
25
|
+
beforeEach(async () => {
|
|
26
|
+
prisma = createAdminPrismaClient(TEST_DB as string);
|
|
27
|
+
service = new CronRunNowService(prisma);
|
|
28
|
+
agentId = (await prisma.agent.create({ data: { name: "RunNowA" } })).id;
|
|
29
|
+
otherAgentId = (await prisma.agent.create({ data: { name: "RunNowB" } }))
|
|
30
|
+
.id;
|
|
31
|
+
cronId = (
|
|
32
|
+
await prisma.agentCronJob.create({
|
|
33
|
+
data: { agentId, name: "c", schedule: "* * * * *", prompt: "p" },
|
|
34
|
+
})
|
|
35
|
+
).id;
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
afterEach(async () => {
|
|
39
|
+
await prisma.agentCronRunRequest.deleteMany({
|
|
40
|
+
where: { agentId: { in: [agentId, otherAgentId] } },
|
|
41
|
+
});
|
|
42
|
+
await prisma.agent.deleteMany({
|
|
43
|
+
where: { id: { in: [agentId, otherAgentId] } },
|
|
44
|
+
});
|
|
45
|
+
await prisma.$disconnect();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe("findCron", () => {
|
|
49
|
+
it("returns the cron's id, agent and lockdown state — never the prompt", async () => {
|
|
50
|
+
const cron = await service.findCron(agentId, cronId);
|
|
51
|
+
expect(cron).toEqual({ id: cronId, agentId, lockdownDisabledAt: null });
|
|
52
|
+
expect(cron).not.toHaveProperty("prompt");
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("surfaces lockdownDisabledAt when the lockdown disabled the cron", async () => {
|
|
56
|
+
const at = new Date("2026-01-02T03:04:05.000Z");
|
|
57
|
+
await prisma.agentCronJob.update({
|
|
58
|
+
where: { id: cronId },
|
|
59
|
+
data: { lockdownDisabledAt: at },
|
|
60
|
+
});
|
|
61
|
+
const cron = await service.findCron(agentId, cronId);
|
|
62
|
+
expect(cron?.lockdownDisabledAt?.toISOString()).toBe(at.toISOString());
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("returns null for another agent's cron", async () => {
|
|
66
|
+
expect(await service.findCron(otherAgentId, cronId)).toBeNull();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("returns null for an unknown cron id", async () => {
|
|
70
|
+
expect(await service.findCron(agentId, "no-such-cron")).toBeNull();
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
describe("recordRequest", () => {
|
|
75
|
+
it("stamps the cron and writes a requested audit row", async () => {
|
|
76
|
+
const requestedAt = new Date("2026-03-04T05:06:07.000Z");
|
|
77
|
+
const row = await service.recordRequest({
|
|
78
|
+
cronId,
|
|
79
|
+
agentId,
|
|
80
|
+
requestedBy: "root",
|
|
81
|
+
requestedAt,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
expect(row).toMatchObject({
|
|
85
|
+
cronId,
|
|
86
|
+
agentId,
|
|
87
|
+
requestedBy: "root",
|
|
88
|
+
status: "requested",
|
|
89
|
+
honouredRunId: null,
|
|
90
|
+
});
|
|
91
|
+
expect(row.requestedAt.toISOString()).toBe(requestedAt.toISOString());
|
|
92
|
+
|
|
93
|
+
const job = await prisma.agentCronJob.findUniqueOrThrow({
|
|
94
|
+
where: { id: cronId },
|
|
95
|
+
});
|
|
96
|
+
expect(job.runRequestedAt?.toISOString()).toBe(requestedAt.toISOString());
|
|
97
|
+
expect(job.runRequestedBy).toBe("root");
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("expires a still-pending request when a newer one overwrites the stamp", async () => {
|
|
101
|
+
const first = await service.recordRequest({
|
|
102
|
+
cronId,
|
|
103
|
+
agentId,
|
|
104
|
+
requestedBy: "root",
|
|
105
|
+
requestedAt: new Date("2026-03-04T05:00:00.000Z"),
|
|
106
|
+
});
|
|
107
|
+
const second = await service.recordRequest({
|
|
108
|
+
cronId,
|
|
109
|
+
agentId,
|
|
110
|
+
requestedBy: "ops",
|
|
111
|
+
requestedAt: new Date("2026-03-04T05:01:00.000Z"),
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
const rows = await prisma.agentCronRunRequest.findMany({
|
|
115
|
+
where: { cronId },
|
|
116
|
+
});
|
|
117
|
+
const byId = new Map(rows.map((r) => [r.id, r.status]));
|
|
118
|
+
expect(byId.get(first.id)).toBe("expired");
|
|
119
|
+
expect(byId.get(second.id)).toBe("requested");
|
|
120
|
+
|
|
121
|
+
const job = await prisma.agentCronJob.findUniqueOrThrow({
|
|
122
|
+
where: { id: cronId },
|
|
123
|
+
});
|
|
124
|
+
expect(job.runRequestedBy).toBe("ops");
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("leaves non-pending rows untouched", async () => {
|
|
128
|
+
const honoured = await prisma.agentCronRunRequest.create({
|
|
129
|
+
data: {
|
|
130
|
+
cronId,
|
|
131
|
+
agentId,
|
|
132
|
+
requestedBy: "root",
|
|
133
|
+
requestedAt: new Date("2026-03-04T04:00:00.000Z"),
|
|
134
|
+
status: "honoured",
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
await service.recordRequest({
|
|
138
|
+
cronId,
|
|
139
|
+
agentId,
|
|
140
|
+
requestedBy: "root",
|
|
141
|
+
requestedAt: new Date("2026-03-04T05:00:00.000Z"),
|
|
142
|
+
});
|
|
143
|
+
const after = await prisma.agentCronRunRequest.findUniqueOrThrow({
|
|
144
|
+
where: { id: honoured.id },
|
|
145
|
+
});
|
|
146
|
+
expect(after.status).toBe("honoured");
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("rolls back the audit row when the cron does not exist", async () => {
|
|
150
|
+
await expect(
|
|
151
|
+
service.recordRequest({
|
|
152
|
+
cronId: "no-such-cron",
|
|
153
|
+
agentId,
|
|
154
|
+
requestedBy: "root",
|
|
155
|
+
requestedAt: new Date(),
|
|
156
|
+
}),
|
|
157
|
+
).rejects.toThrow();
|
|
158
|
+
expect(
|
|
159
|
+
await prisma.agentCronRunRequest.count({ where: { agentId } }),
|
|
160
|
+
).toBe(0);
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* admin/src/cron-run-transcripts-removed.smoke.test.ts
|
|
3
|
+
*
|
|
4
|
+
* The cron-run transcript API (PUT/GET
|
|
5
|
+
* /agents/{id}/crons/{cronId}/runs/{runId}/transcript) was removed
|
|
6
|
+
* (prompt-audit-removal 2.3). The routes are no longer registered, so every
|
|
7
|
+
* caller gets 404 — including on a deployment that still sets the old
|
|
8
|
+
* SHIPWRIGHT_TRANSCRIPT_API_ENABLED / SHIPWRIGHT_LOOP_TRANSCRIPT_AGENT_IDS envs.
|
|
9
|
+
* Uses app.request() — no real server, no real DB.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { afterEach, beforeEach, describe, expect, it } from "bun:test";
|
|
13
|
+
import {
|
|
14
|
+
type AdminDeps,
|
|
15
|
+
createAdminApp,
|
|
16
|
+
parseAdminApiKeys,
|
|
17
|
+
} from "./agents-api.ts";
|
|
18
|
+
|
|
19
|
+
const ADMIN = "admin-key";
|
|
20
|
+
const READ = "platform-read-token";
|
|
21
|
+
const OPS = "platform-ops-token";
|
|
22
|
+
const AGENT_KEY = "agent-1-key";
|
|
23
|
+
const PATH = "/agents/agent-1/crons/cron-1/runs/run-1/transcript";
|
|
24
|
+
|
|
25
|
+
const LEGACY_ENV = {
|
|
26
|
+
SHIPWRIGHT_TRANSCRIPT_API_ENABLED: "enabled",
|
|
27
|
+
SHIPWRIGHT_LOOP_TRANSCRIPT_AGENT_IDS: "agent-1",
|
|
28
|
+
} as const;
|
|
29
|
+
|
|
30
|
+
function makeApp() {
|
|
31
|
+
const deps = {
|
|
32
|
+
agentService: { exists: async () => true },
|
|
33
|
+
agentTokenService: { validate: async () => null },
|
|
34
|
+
agentMemberService: { listByEmail: async () => [] },
|
|
35
|
+
adminApiKeys: parseAdminApiKeys(
|
|
36
|
+
`root:${ADMIN}:*,reader:${READ}:platform.read,operator:${OPS}:platform.ops,a1:${AGENT_KEY}:agent-1`,
|
|
37
|
+
),
|
|
38
|
+
sessionSecret: "s".repeat(32),
|
|
39
|
+
} as unknown as AdminDeps;
|
|
40
|
+
return createAdminApp(deps);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
describe("removed cron-run transcript routes", () => {
|
|
44
|
+
const saved: Record<string, string | undefined> = {};
|
|
45
|
+
|
|
46
|
+
beforeEach(() => {
|
|
47
|
+
for (const [k, v] of Object.entries(LEGACY_ENV)) {
|
|
48
|
+
saved[k] = process.env[k];
|
|
49
|
+
process.env[k] = v;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
afterEach(() => {
|
|
54
|
+
for (const k of Object.keys(LEGACY_ENV)) {
|
|
55
|
+
if (saved[k] === undefined) delete process.env[k];
|
|
56
|
+
else process.env[k] = saved[k];
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("registers no transcript route", () => {
|
|
61
|
+
const app = makeApp();
|
|
62
|
+
expect(app.routes.some((r) => r.path.endsWith("/transcript"))).toBe(false);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("404s GET for every caller and PUT for every write-capable caller, even with the legacy envs set", async () => {
|
|
66
|
+
const app = makeApp();
|
|
67
|
+
for (const token of [ADMIN, READ, OPS, AGENT_KEY]) {
|
|
68
|
+
const auth = { Authorization: `Bearer ${token}` };
|
|
69
|
+
expect((await app.request(PATH, { headers: auth })).status).toBe(404);
|
|
70
|
+
// platform.read and platform.ops are refused this write by the scope
|
|
71
|
+
// middleware (403) before routing, as for any unknown agent path, so
|
|
72
|
+
// only write-capable callers can observe the 404.
|
|
73
|
+
if (token === READ || token === OPS) continue;
|
|
74
|
+
const put = await app.request(PATH, {
|
|
75
|
+
method: "PUT",
|
|
76
|
+
body: JSON.stringify({ body: "x", truncated: false, redactions: 0 }),
|
|
77
|
+
headers: { ...auth, "Content-Type": "application/json" },
|
|
78
|
+
});
|
|
79
|
+
expect(put.status).toBe(404);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
});
|