@app-vitals/agent-admin 1.120.1 → 1.122.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.
Files changed (79) hide show
  1. package/openapi.platform.json +20 -0
  2. package/package.json +2 -2
  3. package/src/account-repo-lookup-api.integration.test.ts +1 -1
  4. package/src/admin-boot-config.ts +2 -2
  5. package/src/admin-boot-config.unit.test.ts +1 -1
  6. package/src/admin-boot.ts +1 -1
  7. package/src/admin-ui-account.ts +2 -2
  8. package/src/admin-ui-agent-template.smoke.test.ts +1 -1
  9. package/src/admin-ui-github-identity-pages.ts +2 -2
  10. package/src/admin-ui-push-test.smoke.test.ts +7 -5
  11. package/src/admin-ui-styles.unit.test.ts +3 -1
  12. package/src/admin-ui-templates-pages.ts +5 -5
  13. package/src/agent-cron-run-stats.integration.test.ts +11 -2
  14. package/src/agent-deletion-checklist.unit.test.ts +1 -1
  15. package/src/agent-manifest.unit.test.ts +3 -3
  16. package/src/agent-marketplaces-api.integration.test.ts +9 -7
  17. package/src/agent-members.integration.test.ts +1 -1
  18. package/src/agent-pod-labels.unit.test.ts +2 -2
  19. package/src/agent-provisioner.unit.test.ts +4 -4
  20. package/src/agent-setup.unit.test.ts +14 -3
  21. package/src/agent-template-items.ts +1 -1
  22. package/src/agent-templates.ts +1 -1
  23. package/src/agent-tools-token.integration.test.ts +3 -3
  24. package/src/api-auth.ts +10 -4
  25. package/src/brand-tokens.json +23 -4
  26. package/src/brand-tokens.unit.test.ts +11 -4
  27. package/src/chat-credential-config.unit.test.ts +6 -2
  28. package/src/chat-markers.unit.test.ts +5 -2
  29. package/src/cron-run-now.smoke.test.ts +1 -1
  30. package/src/cron-run-now.ts +1 -1
  31. package/src/errors.unit.test.ts +7 -4
  32. package/src/fixtures/github-agent-installation-cassette.json +35 -5
  33. package/src/github-access-backfill.ts +1 -1
  34. package/src/github-access-backfill.unit.test.ts +1 -1
  35. package/src/github-agent-installation-crawler.integration.test.ts +29 -12
  36. package/src/github-agent-installation-crawler.ts +2 -2
  37. package/src/github-agent-installation-crawler.unit.test.ts +28 -7
  38. package/src/github-app-api.ts +1 -1
  39. package/src/github-app-jwt.unit.test.ts +2 -1
  40. package/src/github-cache-roundtrip.integration.test.ts +4 -4
  41. package/src/github-enterprise-api.integration.test.ts +4 -4
  42. package/src/github-enterprise-api.ts +6 -6
  43. package/src/github-enterprise-client-page.unit.test.ts +18 -6
  44. package/src/github-enterprise-client.integration.test.ts +97 -32
  45. package/src/github-enterprise-client.ts +81 -22
  46. package/src/github-enterprise-client.unit.test.ts +1 -1
  47. package/src/github-enterprise-warnings.unit.test.ts +19 -6
  48. package/src/github-installation-selection.integration.test.ts +4 -1
  49. package/src/github-installation-wiring.unit.test.ts +1 -1
  50. package/src/github-repo-refresh-discovery.unit.test.ts +1 -1
  51. package/src/github-repo-refresher.unit.test.ts +11 -5
  52. package/src/github-sync-cache.integration.test.ts +1 -1
  53. package/src/github-sync-cached-access.ts +1 -1
  54. package/src/github-sync-reverify.unit.test.ts +1 -1
  55. package/src/github-sync-snapshot-refresh.integration.test.ts +1 -1
  56. package/src/github-sync.unit.test.ts +6 -6
  57. package/src/installation-ports-fixture.integration.test.ts +2 -2
  58. package/src/installation-repos-service.ts +5 -5
  59. package/src/kubernetes-client.integration.test.ts +1 -2
  60. package/src/openapi-schemas.ts +9 -0
  61. package/src/platform-routes.ts +1 -1
  62. package/src/principal-lookup.ts +26 -4
  63. package/src/principal-lookup.unit.test.ts +61 -4
  64. package/src/principals-api.integration.test.ts +9 -1
  65. package/src/principals-api.smoke.test.ts +96 -0
  66. package/src/push-content.unit.test.ts +2 -2
  67. package/src/push-sender.unit.test.ts +1 -1
  68. package/src/push-service.integration.test.ts +1 -1
  69. package/src/pwa-icons.unit.test.ts +1 -1
  70. package/src/slack-config-token-resolve.unit.test.ts +25 -7
  71. package/src/slack-provisioning-client.integration.test.ts +10 -8
  72. package/src/slack-provisioning-client.ts +2 -6
  73. package/src/tools-token-policy.integration.test.ts +48 -6
  74. package/src/tools-token-policy.smoke.test.ts +11 -5
  75. package/src/tools-token-policy.ts +85 -8
  76. package/src/tools-token-policy.unit.test.ts +111 -4
  77. package/src/trial-expiry-sweeper.unit.test.ts +1 -1
  78. package/src/user-prefs.integration.test.ts +1 -1
  79. package/src/user-repo-access-resolver.unit.test.ts +1 -1
@@ -15,7 +15,7 @@ import {
15
15
  DEPLOYMENT_WIDE_ACCOUNT_KEY,
16
16
  } from "./github-agent-installation-crawler.ts";
17
17
  import { GitHubRepoCacheService } from "./github-repo-cache.ts";
18
- import { GithubSyncService, type GithubSyncDeps } from "./github-sync.ts";
18
+ import { type GithubSyncDeps, GithubSyncService } from "./github-sync.ts";
19
19
  import type { InstallationReposPort } from "./installation-repos-service.ts";
20
20
  import { createAdminPrismaClient } from "./prisma-client.ts";
21
21
 
@@ -1,24 +1,24 @@
1
1
  import { describe, expect, it, test } from "bun:test";
2
- import type {
3
- CachedAccessRow,
4
- InstallationSnapshotRow,
5
- } from "./installation-repos-service.ts";
6
2
  import type { GithubAccessPreviewFn } from "./github-access-preview.ts";
7
3
  import {
8
4
  ARCHIVED_REASON,
9
- GITHUB_SYNC_AUDIT_PLAN_HASH,
10
5
  type CachedLookupOrg,
6
+ GITHUB_SYNC_AUDIT_PLAN_HASH,
7
+ type GithubSyncPlanInput,
11
8
  GithubSyncService,
12
9
  NOT_ADDABLE_REASON,
13
10
  NOT_PRESENT_REASON,
14
11
  planGithubSync,
15
12
  STILL_PUSHABLE_REASON,
16
- type GithubSyncPlanInput,
17
13
  } from "./github-sync.ts";
18
14
  import type {
19
15
  InstallationAgentRecord,
20
16
  InstallationAuditEntry,
21
17
  } from "./installation-ports.ts";
18
+ import type {
19
+ CachedAccessRow,
20
+ InstallationSnapshotRow,
21
+ } from "./installation-repos-service.ts";
22
22
  import {
23
23
  type InstallationReposPort,
24
24
  NO_INSTALLATION_REASON,
@@ -5,13 +5,13 @@
5
5
  */
6
6
 
7
7
  import { describe, expect, it } from "bun:test";
8
- import { toInstallation } from "./github-enterprise-client.ts";
9
8
  import enterpriseOrgInstallations from "./fixtures/enterprise-org-installations.json";
10
- import { createInstallationReposPort } from "./installation-repos-service.ts";
9
+ import { toInstallation } from "./github-enterprise-client.ts";
11
10
  import {
12
11
  AppNotInstalledError,
13
12
  createInstallationPort,
14
13
  } from "./installation-ports.ts";
14
+ import { createInstallationReposPort } from "./installation-repos-service.ts";
15
15
 
16
16
  const ORG = "example-org";
17
17
  const CLIENT_ID = "Iv1.0000000000000000";
@@ -7,16 +7,16 @@
7
7
  * through the installation port.
8
8
  */
9
9
 
10
- import {
11
- GITHUB_APPS_STATE_REASONS,
12
- type GithubAppsState,
13
- type GithubAppsStateFn,
14
- } from "./github-apps-state.ts";
15
10
  import type { GithubAccessPreviewFn } from "./github-access-preview.ts";
16
11
  import {
17
12
  DEPLOYMENT_WIDE_ACCOUNT_KEY,
18
13
  getAccessRowsAcrossKeys,
19
14
  } from "./github-agent-installation-crawler.ts";
15
+ import {
16
+ GITHUB_APPS_STATE_REASONS,
17
+ type GithubAppsState,
18
+ type GithubAppsStateFn,
19
+ } from "./github-apps-state.ts";
20
20
  import {
21
21
  type AppIdentity,
22
22
  type AppInstallationPort,
@@ -9,8 +9,7 @@
9
9
  */
10
10
 
11
11
  import { afterEach, describe, expect, it } from "bun:test";
12
- import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
13
- import { readFileSync } from "node:fs";
12
+ import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
14
13
  import { tmpdir } from "node:os";
15
14
  import { join } from "node:path";
16
15
  import {
@@ -1627,6 +1627,15 @@ export const PrincipalSchema = z
1627
1627
  .string()
1628
1628
  .nullable()
1629
1629
  .openapi({ description: "null for agents", example: "o@acme.com" }),
1630
+ accountId: z.string().nullable().optional().openapi({
1631
+ description:
1632
+ "Account the user belongs to; null for users without membership (e.g. platform admins), omitted for agents",
1633
+ example: "clx1acc",
1634
+ }),
1635
+ role: z.enum(["owner", "member"]).nullable().optional().openapi({
1636
+ description:
1637
+ "Membership role; null for users without membership (e.g. platform admins), omitted for agents",
1638
+ }),
1630
1639
  })
1631
1640
  .openapi("Principal");
1632
1641
 
@@ -14,13 +14,13 @@
14
14
 
15
15
  import type { OpenAPIHono } from "@hono/zod-openapi";
16
16
  import type { Hono, MiddlewareHandler } from "hono";
17
+ import { createAccountRepoLookupApp } from "./account-repo-lookup-api.ts";
17
18
  import { createAccountsApp } from "./accounts-api.ts";
18
19
  import { createAgentTemplatesApp } from "./agent-templates-api.ts";
19
20
  import { type AdminDeps, createAdminApp } from "./agents-api.ts";
20
21
  import { createAgentRuntimeApp } from "./api.ts";
21
22
  import { createGithubEnterpriseApp } from "./github-enterprise-api.ts";
22
23
  import { mountPlatformDoc } from "./platform-doc-route.ts";
23
- import { createAccountRepoLookupApp } from "./account-repo-lookup-api.ts";
24
24
  import { createPrincipalsApp } from "./principals-api.ts";
25
25
 
26
26
  type AgentRuntimeDeps = Parameters<typeof createAgentRuntimeApp>[0];
@@ -15,6 +15,14 @@ export interface Principal {
15
15
  id: string;
16
16
  type: "user" | "agent";
17
17
  email: string | null;
18
+ /** Owning account of a user principal; null with no membership, omitted for agents. */
19
+ accountId?: string | null;
20
+ /** Membership role of a user principal ("owner" | "member"); null with no membership. */
21
+ role?: "owner" | "member" | null;
22
+ }
23
+
24
+ function toRole(role: string | null | undefined): "owner" | "member" | null {
25
+ return role === "owner" || role === "member" ? role : null;
18
26
  }
19
27
 
20
28
  export interface PrincipalLookupResult {
@@ -33,7 +41,7 @@ export class PrincipalLookupService {
33
41
  const [members, agents] = await Promise.all([
34
42
  this.prisma.accountMember.findMany({
35
43
  where: { id: { in: unique } },
36
- select: { id: true, email: true },
44
+ select: { id: true, email: true, accountId: true, role: true },
37
45
  }),
38
46
  this.prisma.agent.findMany({
39
47
  where: { id: { in: unique } },
@@ -45,7 +53,13 @@ export class PrincipalLookupService {
45
53
  byId.set(a.id, { id: a.id, type: "agent", email: null });
46
54
  // Ids are cuids so collisions are not expected; a member wins if one occurs.
47
55
  for (const m of members)
48
- byId.set(m.id, { id: m.id, type: "user", email: m.email });
56
+ byId.set(m.id, {
57
+ id: m.id,
58
+ type: "user",
59
+ email: m.email,
60
+ accountId: m.accountId ?? null,
61
+ role: toRole(m.role),
62
+ });
49
63
 
50
64
  const principals: Principal[] = [];
51
65
  const notFound: string[] = [];
@@ -60,8 +74,16 @@ export class PrincipalLookupService {
60
74
  async findIdByEmail(email: string): Promise<Principal | null> {
61
75
  const member = await this.prisma.accountMember.findUnique({
62
76
  where: { email: normalizeEmail(email) },
63
- select: { id: true, email: true },
77
+ select: { id: true, email: true, accountId: true, role: true },
64
78
  });
65
- return member ? { id: member.id, type: "user", email: member.email } : null;
79
+ return member
80
+ ? {
81
+ id: member.id,
82
+ type: "user",
83
+ email: member.email,
84
+ accountId: member.accountId ?? null,
85
+ role: toRole(member.role),
86
+ }
87
+ : null;
66
88
  }
67
89
  }
@@ -7,7 +7,7 @@ import { describe, expect, it } from "bun:test";
7
7
  import { PrincipalLookupService } from "./principal-lookup.ts";
8
8
 
9
9
  function fakePrisma(
10
- members: { id: string; email: string }[],
10
+ members: { id: string; email: string; accountId?: string; role?: string }[],
11
11
  agents: { id: string }[],
12
12
  ) {
13
13
  const calls = { member: 0, agent: 0 };
@@ -33,7 +33,7 @@ function fakePrisma(
33
33
  describe("PrincipalLookupService.resolveMany", () => {
34
34
  it("resolves a mixed list of member and agent ids", async () => {
35
35
  const { prisma } = fakePrisma(
36
- [{ id: "m1", email: "a@x.com" }],
36
+ [{ id: "m1", email: "a@x.com", accountId: "acc1", role: "owner" }],
37
37
  [{ id: "a1" }],
38
38
  );
39
39
  const res = await new PrincipalLookupService(prisma).resolveMany([
@@ -41,7 +41,13 @@ describe("PrincipalLookupService.resolveMany", () => {
41
41
  "a1",
42
42
  ]);
43
43
  expect(res.principals).toEqual([
44
- { id: "m1", type: "user", email: "a@x.com" },
44
+ {
45
+ id: "m1",
46
+ type: "user",
47
+ email: "a@x.com",
48
+ accountId: "acc1",
49
+ role: "owner",
50
+ },
45
51
  { id: "a1", type: "agent", email: null },
46
52
  ]);
47
53
  expect(res.notFound).toEqual([]);
@@ -84,14 +90,65 @@ describe("PrincipalLookupService.resolveMany", () => {
84
90
  });
85
91
  });
86
92
 
93
+ describe("PrincipalLookupService account id and role", () => {
94
+ const members = [
95
+ { id: "m1", email: "o@x.com", accountId: "acc1", role: "owner" },
96
+ { id: "m2", email: "m@x.com", accountId: "acc1", role: "member" },
97
+ ];
98
+
99
+ it("resolveMany returns accountId and role for users, none for agents", async () => {
100
+ const { prisma } = fakePrisma(members, [{ id: "a1" }]);
101
+ const res = await new PrincipalLookupService(prisma).resolveMany([
102
+ "m1",
103
+ "m2",
104
+ "a1",
105
+ ]);
106
+ expect(res.principals).toEqual([
107
+ {
108
+ id: "m1",
109
+ type: "user",
110
+ email: "o@x.com",
111
+ accountId: "acc1",
112
+ role: "owner",
113
+ },
114
+ {
115
+ id: "m2",
116
+ type: "user",
117
+ email: "m@x.com",
118
+ accountId: "acc1",
119
+ role: "member",
120
+ },
121
+ { id: "a1", type: "agent", email: null },
122
+ ]);
123
+ });
124
+
125
+ it("findIdByEmail returns accountId and role", async () => {
126
+ const { prisma } = fakePrisma(members, []);
127
+ expect(
128
+ await new PrincipalLookupService(prisma).findIdByEmail("m@x.com"),
129
+ ).toEqual({
130
+ id: "m2",
131
+ type: "user",
132
+ email: "m@x.com",
133
+ accountId: "acc1",
134
+ role: "member",
135
+ });
136
+ });
137
+ });
138
+
87
139
  describe("PrincipalLookupService.findIdByEmail", () => {
88
140
  it("normalizes case and whitespace before matching", async () => {
89
- const { prisma } = fakePrisma([{ id: "m1", email: "a@x.com" }], []);
141
+ const { prisma } = fakePrisma(
142
+ [{ id: "m1", email: "a@x.com", accountId: "acc1", role: "member" }],
143
+ [],
144
+ );
90
145
  const svc = new PrincipalLookupService(prisma);
91
146
  expect(await svc.findIdByEmail(" A@X.com ")).toEqual({
92
147
  id: "m1",
93
148
  type: "user",
94
149
  email: "a@x.com",
150
+ accountId: "acc1",
151
+ role: "member",
95
152
  });
96
153
  });
97
154
 
@@ -56,7 +56,13 @@ describeOrSkip("/principals API (integration)", () => {
56
56
  expect(res.status).toBe(200);
57
57
  expect(await res.json()).toEqual({
58
58
  principals: [
59
- { id: member.id, type: "user", email: "owner@acme.com" },
59
+ {
60
+ id: member.id,
61
+ type: "user",
62
+ email: "owner@acme.com",
63
+ accountId: account.id,
64
+ role: "owner",
65
+ },
60
66
  { id: agent.id, type: "agent", email: null },
61
67
  ],
62
68
  notFound: ["missing"],
@@ -76,6 +82,8 @@ describeOrSkip("/principals API (integration)", () => {
76
82
  id: member.id,
77
83
  type: "user",
78
84
  email: "owner@acme.com",
85
+ accountId: account.id,
86
+ role: "owner",
79
87
  });
80
88
  const miss = await app.request(
81
89
  "/principals/by-email?email=nobody@acme.com",
@@ -0,0 +1,96 @@
1
+ /**
2
+ * admin/src/principals-api.smoke.test.ts
3
+ * Smoke tests for the admin-only /principals user lookup: accountId and role
4
+ * on the response. In-process app.request(), in-memory lookup double.
5
+ */
6
+
7
+ import { describe, expect, it } from "bun:test";
8
+ import { parseAdminApiKeys } from "./api-auth.ts";
9
+ import type { Principal } from "./principal-lookup.ts";
10
+ import { createPrincipalsApp } from "./principals-api.ts";
11
+
12
+ const KEY = "admin-key";
13
+ const headers = { Authorization: `Bearer ${KEY}` };
14
+
15
+ const users: Principal[] = [
16
+ {
17
+ id: "m1",
18
+ type: "user",
19
+ email: "owner@acme.test",
20
+ accountId: "acc1",
21
+ role: "owner",
22
+ },
23
+ {
24
+ id: "m2",
25
+ type: "user",
26
+ email: "member@acme.test",
27
+ accountId: "acc1",
28
+ role: "member",
29
+ },
30
+ {
31
+ id: "m3",
32
+ type: "user",
33
+ email: "admin@acme.test",
34
+ accountId: null,
35
+ role: null,
36
+ },
37
+ ];
38
+
39
+ function build() {
40
+ return createPrincipalsApp({
41
+ lookup: {
42
+ resolveMany: async (ids: string[]) => ({
43
+ principals: users.filter((u) => ids.includes(u.id)),
44
+ notFound: ids.filter((i) => !users.some((u) => u.id === i)),
45
+ }),
46
+ findIdByEmail: async (email: string) =>
47
+ users.find((u) => u.email === email) ?? null,
48
+ },
49
+ sessionSecret: "principals-smoke-secret-32-bytes!",
50
+ adminApiKeys: parseAdminApiKeys(`admin:${KEY}:*`),
51
+ agentTokenService: { validate: async () => null } as never,
52
+ });
53
+ }
54
+
55
+ describe("GET /principals/by-email account fields", () => {
56
+ it.each([
57
+ ["owner@acme.test", "acc1", "owner"],
58
+ ["member@acme.test", "acc1", "member"],
59
+ ["admin@acme.test", null, null],
60
+ ])("%s -> accountId %p, role %p", async (email, accountId, role) => {
61
+ const res = await build().request(
62
+ `/principals/by-email?email=${encodeURIComponent(email)}`,
63
+ { headers },
64
+ );
65
+ expect(res.status).toBe(200);
66
+ const body = (await res.json()) as Record<string, unknown>;
67
+ expect(body.id).toBeDefined();
68
+ expect(body.type).toBe("user");
69
+ expect(body.email).toBe(email);
70
+ expect(body.accountId).toBe(accountId);
71
+ expect(body.role).toBe(role);
72
+ });
73
+
74
+ it("unknown email is still 404", async () => {
75
+ const res = await build().request(
76
+ "/principals/by-email?email=nobody@acme.test",
77
+ { headers },
78
+ );
79
+ expect(res.status).toBe(404);
80
+ });
81
+ });
82
+
83
+ describe("POST /principals/lookup account fields", () => {
84
+ it("includes accountId and role per user", async () => {
85
+ const res = await build().request("/principals/lookup", {
86
+ method: "POST",
87
+ headers: { ...headers, "Content-Type": "application/json" },
88
+ body: JSON.stringify({ ids: ["m1", "m2", "m3", "zz"] }),
89
+ });
90
+ expect(res.status).toBe(200);
91
+ expect(await res.json()).toEqual({
92
+ principals: users,
93
+ notFound: ["zz"],
94
+ });
95
+ });
96
+ });
@@ -9,11 +9,11 @@
9
9
 
10
10
  import { describe, expect, it } from "bun:test";
11
11
  import {
12
- type PushDetailLevel,
13
- type SessionNotificationKind,
14
12
  buildNotificationPayload,
15
13
  buildSessionNotificationPayload,
14
+ type PushDetailLevel,
16
15
  resolveDetailLevel,
16
+ type SessionNotificationKind,
17
17
  } from "./push-content.ts";
18
18
 
19
19
  describe("resolveDetailLevel", () => {
@@ -5,7 +5,7 @@
5
5
  */
6
6
 
7
7
  import { describe, expect, it } from "bun:test";
8
- import { PushSender, isPushEnabled } from "./push-sender.ts";
8
+ import { isPushEnabled, PushSender } from "./push-sender.ts";
9
9
 
10
10
  // A minimal valid-shaped subscription. Keys are the RFC 8291 vector's UA keys
11
11
  // so the encryption path exercises real values.
@@ -8,9 +8,9 @@
8
8
 
9
9
  import { afterEach, beforeEach, describe, expect, it } from "bun:test";
10
10
  import type { PrismaClient } from "../prisma/client/client.ts";
11
- import { resetMemberIdFixture } from "./test-support/member-id-test-support.ts";
12
11
  import { createAdminPrismaClient } from "./prisma-client.ts";
13
12
  import { PushService } from "./push-service.ts";
13
+ import { resetMemberIdFixture } from "./test-support/member-id-test-support.ts";
14
14
 
15
15
  const TEST_DB = process.env.DATABASE_URL_ADMIN_TEST;
16
16
  const describeOrSkip = TEST_DB ? describe : describe.skip;
@@ -7,7 +7,7 @@
7
7
 
8
8
  import { describe, expect, it } from "bun:test";
9
9
  import { join } from "node:path";
10
- import { PWA_ICONS, PWA_ASSETS_DIR } from "./pwa.ts";
10
+ import { PWA_ASSETS_DIR, PWA_ICONS } from "./pwa.ts";
11
11
 
12
12
  const PNG_MAGIC = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
13
13
  const MAX_ICON_BYTES = 60 * 1024;
@@ -131,17 +131,35 @@ describe("resolveSlackConfigTokenRequirement", () => {
131
131
  { accountId: null, slackTeamId: "T-default" },
132
132
  { accountId: "a1", slackTeamId: "T-acct" },
133
133
  ]);
134
- expect(await resolveSlackConfigTokenRequirement(resolver, "a1", "T-acct")).toBe("optional");
135
- expect(await resolveSlackConfigTokenRequirement(resolver, "a1", "T-default")).toBe("required");
134
+ expect(
135
+ await resolveSlackConfigTokenRequirement(resolver, "a1", "T-acct"),
136
+ ).toBe("optional");
137
+ expect(
138
+ await resolveSlackConfigTokenRequirement(resolver, "a1", "T-default"),
139
+ ).toBe("required");
136
140
  });
137
141
  test("falls back to the default row", async () => {
138
142
  const { resolver } = fake([{ accountId: null, slackTeamId: "T-default" }]);
139
- expect(await resolveSlackConfigTokenRequirement(resolver, "a1", "T-other")).toBe("required");
140
- expect(await resolveSlackConfigTokenRequirement(resolver, "a1", "T-default")).toBe("optional");
143
+ expect(
144
+ await resolveSlackConfigTokenRequirement(resolver, "a1", "T-other"),
145
+ ).toBe("required");
146
+ expect(
147
+ await resolveSlackConfigTokenRequirement(resolver, "a1", "T-default"),
148
+ ).toBe("optional");
141
149
  });
142
150
  test("no resolver, no row, or null team ids -> optional", async () => {
143
- expect(await resolveSlackConfigTokenRequirement(undefined, "a1", "T1")).toBe("optional");
144
- expect(await resolveSlackConfigTokenRequirement(fake([]).resolver, "a1", "T1")).toBe("optional");
145
- expect(await resolveSlackConfigTokenRequirement(fake([{ accountId: null }]).resolver, "a1", "T1")).toBe("optional");
151
+ expect(
152
+ await resolveSlackConfigTokenRequirement(undefined, "a1", "T1"),
153
+ ).toBe("optional");
154
+ expect(
155
+ await resolveSlackConfigTokenRequirement(fake([]).resolver, "a1", "T1"),
156
+ ).toBe("optional");
157
+ expect(
158
+ await resolveSlackConfigTokenRequirement(
159
+ fake([{ accountId: null }]).resolver,
160
+ "a1",
161
+ "T1",
162
+ ),
163
+ ).toBe("optional");
146
164
  });
147
165
  });
@@ -15,8 +15,8 @@
15
15
 
16
16
  import { describe, expect, it } from "bun:test";
17
17
  import { readFileSync } from "node:fs";
18
- import { HttpSlackProvisioningClient } from "./slack-provisioning-client.ts";
19
18
  import type { AppManifest } from "./slack-provisioning-client.ts";
19
+ import { HttpSlackProvisioningClient } from "./slack-provisioning-client.ts";
20
20
 
21
21
  // ─── Cassette ───────────────────────────────────────────────────────────────
22
22
 
@@ -193,16 +193,16 @@ describe("HttpSlackProvisioningClient — deleteApp", () => {
193
193
 
194
194
  it("throws on an HTTP error response", async () => {
195
195
  const { client } = makeClient("deleteApp_http_error");
196
- await expect(
197
- client.deleteApp("xoxp-token", "A0123456789"),
198
- ).rejects.toThrow(/Slack apps\.manifest\.delete HTTP error: 500/);
196
+ await expect(client.deleteApp("xoxp-token", "A0123456789")).rejects.toThrow(
197
+ /Slack apps\.manifest\.delete HTTP error: 500/,
198
+ );
199
199
  });
200
200
 
201
201
  it("throws when Slack returns ok: false", async () => {
202
202
  const { client } = makeClient("deleteApp_slack_error");
203
- await expect(
204
- client.deleteApp("xoxp-token", "A0123456789"),
205
- ).rejects.toThrow(/Slack apps\.manifest\.delete failed: app_not_found/);
203
+ await expect(client.deleteApp("xoxp-token", "A0123456789")).rejects.toThrow(
204
+ /Slack apps\.manifest\.delete failed: app_not_found/,
205
+ );
206
206
  });
207
207
  });
208
208
 
@@ -369,7 +369,9 @@ describe("HttpSlackProvisioningClient — rotateConfigToken", () => {
369
369
  } catch (err: unknown) {
370
370
  expect(err instanceof Error).toBe(true);
371
371
  const error = err as Error;
372
- expect(error.message).toMatch(/Slack tooling\.tokens\.rotate HTTP error: 500/);
372
+ expect(error.message).toMatch(
373
+ /Slack tooling\.tokens\.rotate HTTP error: 500/,
374
+ );
373
375
  if (err && typeof err === "object" && "code" in err) {
374
376
  expect((err as any).code).toBe("http_error");
375
377
  }
@@ -142,9 +142,7 @@ export interface SlackConfigTokenClient {
142
142
  * Throws SlackConfigTokenError on Slack API errors (invalid_refresh_token, token_revoked, etc.)
143
143
  * or on HTTP errors.
144
144
  */
145
- rotateConfigToken(
146
- refreshToken: string,
147
- ): Promise<{
145
+ rotateConfigToken(refreshToken: string): Promise<{
148
146
  accessToken: string;
149
147
  refreshToken: string;
150
148
  teamId: string;
@@ -460,9 +458,7 @@ export class HttpSlackProvisioningClient
460
458
  };
461
459
  }
462
460
 
463
- async rotateConfigToken(
464
- refreshToken: string,
465
- ): Promise<{
461
+ async rotateConfigToken(refreshToken: string): Promise<{
466
462
  accessToken: string;
467
463
  refreshToken: string;
468
464
  teamId: string;
@@ -37,6 +37,7 @@ describeOrSkip("tools-kind token policy (integration)", () => {
37
37
  let agentId: string;
38
38
  let toolsToken: string;
39
39
  let runtimeToken: string;
40
+ let seedCrypto: ReturnType<typeof makeTokenCrypto>;
40
41
  let root: {
41
42
  request: (path: string, init?: RequestInit) => Response | Promise<Response>;
42
43
  };
@@ -62,6 +63,7 @@ describeOrSkip("tools-kind token policy (integration)", () => {
62
63
  const saved = process.env.SHIPWRIGHT_ENCRYPTION_KEY;
63
64
  process.env.SHIPWRIGHT_ENCRYPTION_KEY = REAL_KEY;
64
65
  const crypto = makeTokenCrypto();
66
+ seedCrypto = crypto;
65
67
  if (saved === undefined) delete process.env.SHIPWRIGHT_ENCRYPTION_KEY;
66
68
  else process.env.SHIPWRIGHT_ENCRYPTION_KEY = saved;
67
69
 
@@ -189,10 +191,10 @@ describeOrSkip("tools-kind token policy (integration)", () => {
189
191
  });
190
192
 
191
193
  it("config gives a tools token env {} and a runtime token its env", async () => {
192
- const write = await call(runtimeToken, "POST", `/agents/${agentId}/envs`, {
194
+ // Runtime tokens can no longer write env; seed it directly.
195
+ await new AgentEnvService(prisma, seedCrypto).upsert(agentId, {
193
196
  SECRET_KEY: "s3cr3t",
194
197
  });
195
- expect([200, 201]).toContain(write.status);
196
198
 
197
199
  const asTools = await call(toolsToken, "GET", `/agents/${agentId}/config`);
198
200
  expect(asTools.status).toBe(200);
@@ -211,10 +213,50 @@ describeOrSkip("tools-kind token policy (integration)", () => {
211
213
  });
212
214
  });
213
215
 
214
- it("runtime token can still mint a token", async () => {
215
- const res = await call(runtimeToken, "POST", `/agents/${agentId}/tokens`, {
216
- label: "x",
216
+ describe("runtime-kind denylist", () => {
217
+ it("runtime token is 403 on token mint and env write", async () => {
218
+ const mint = await call(
219
+ runtimeToken,
220
+ "POST",
221
+ `/agents/${agentId}/tokens`,
222
+ { label: "x" },
223
+ );
224
+ expect(mint.status).toBe(403);
225
+ const env = await call(runtimeToken, "POST", `/agents/${agentId}/envs`, {
226
+ A: "1",
227
+ });
228
+ expect(env.status).toBe(403);
229
+ });
230
+
231
+ it("runtime token is 200 on config, crons reconcile and cron run reports", async () => {
232
+ expect(
233
+ (await call(runtimeToken, "GET", `/agents/${agentId}/config`)).status,
234
+ ).toBe(200);
235
+ expect(
236
+ (await call(runtimeToken, "GET", `/agents/${agentId}/crons`)).status,
237
+ ).toBe(200);
238
+ const rec = await call(
239
+ runtimeToken,
240
+ "POST",
241
+ `/agents/${agentId}/crons/reconcile`,
242
+ { crons: [] },
243
+ );
244
+ expect(rec.status).not.toBe(403);
245
+ // A run report must pass the policy (the cron itself need not exist).
246
+ const run = await call(
247
+ runtimeToken,
248
+ "POST",
249
+ `/agents/${agentId}/crons/some-cron/runs`,
250
+ {},
251
+ );
252
+ expect(run.status).not.toBe(403);
253
+ const patch = await call(
254
+ runtimeToken,
255
+ "PATCH",
256
+ `/agents/${agentId}/crons/some-cron/runs/some-run`,
257
+ {},
258
+ );
259
+ expect(patch.status).not.toBe(403);
217
260
  });
218
- expect(res.status).toBe(201);
219
261
  });
220
262
  });
@@ -154,11 +154,17 @@ describe("tools-kind token through the in-process admin app", () => {
154
154
  expect(((await res.json()) as { env: unknown }).env).toEqual({});
155
155
  });
156
156
 
157
- it("runtime-kind token still mints a token and receives env", async () => {
158
- const mint = await send(root, RUNTIME, "POST", `/agents/${ID}/tokens`, {
159
- label: "x",
160
- });
161
- expect(mint.status).toBe(201);
157
+ it("runtime-kind token is denied credential writes but receives env", async () => {
158
+ {
159
+ const mint = await send(root, RUNTIME, "POST", `/agents/${ID}/tokens`, {
160
+ label: "x",
161
+ });
162
+ expect(mint.status).toBe(403);
163
+ expect(
164
+ (await send(root, RUNTIME, "POST", `/agents/${ID}/envs`, { env: {} }))
165
+ .status,
166
+ ).toBe(403);
167
+ }
162
168
  const cfg = await send(root, RUNTIME, "GET", `/agents/${ID}/config`);
163
169
  expect(((await cfg.json()) as { env: unknown }).env).toEqual({
164
170
  SECRET_KEY: "s3cr3t",