@app-vitals/agent-admin 1.42.0 → 1.44.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@app-vitals/agent-admin",
3
- "version": "1.42.0",
3
+ "version": "1.44.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.42.0",
45
+ "@app-vitals/agent-lib": "1.44.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
@@ -578,14 +578,15 @@ export async function startAdmin(
578
578
  );
579
579
 
580
580
  // 3b''. Agent templates API — /templates/* — admin or account-scoped (ATP-1.3)
581
+ const templateService = new AgentTemplateService(
582
+ prisma,
583
+ crypto,
584
+ specialtyRegistry,
585
+ );
581
586
  root.route(
582
587
  "/",
583
588
  createAgentTemplatesApp({
584
- templateService: new AgentTemplateService(
585
- prisma,
586
- crypto,
587
- specialtyRegistry,
588
- ),
589
+ templateService,
589
590
  callerScopeResolver,
590
591
  sessionSecret,
591
592
  adminApiKeys,
@@ -639,6 +640,7 @@ export async function startAdmin(
639
640
  anthropicFederationEnabled,
640
641
  specialtyRegistry,
641
642
  specialtyDefaults,
643
+ templateService,
642
644
  serviceIntegrations,
643
645
  chatService: deletionChatService,
644
646
  slack: slackClient,
@@ -265,7 +265,7 @@ export function renderGithubEnterpriseSettingsPage(
265
265
  title: "GitHub Enterprise — Settings — Shipwright Admin",
266
266
  body: `${renderAdminToolbar(opts.userEmail, BASE)}
267
267
  <div class="vos-page">
268
- <div class="page-header"><h1 class="page-title">GitHub Enterprise apps</h1></div>
268
+ <div class="page-header"><h1 class="page-title">GitHub Enterprise apps</h1><a href="/admin/settings/templates" class="btn btn-secondary">Agent templates</a></div>
269
269
  ${error}${notice}${intro}
270
270
  ${appCard("installer", status.installer, opts.warnings)}
271
271
  ${appCard("lookup", status.lookup, opts.warnings)}
@@ -0,0 +1,155 @@
1
+ /**
2
+ * admin/src/admin-ui-templates-pages.ts
3
+ * Render function for the Settings > Templates editor (ATP-2.3).
4
+ * Pure string -> string; routes live in admin-ui-templates.ts.
5
+ *
6
+ * Secret env values arrive already masked ("***") from the template service;
7
+ * the page only ever echoes what it is given, and posting the mask back keeps
8
+ * the stored secret.
9
+ */
10
+
11
+ import { renderAdminPage } from "./admin-ui-layout.ts";
12
+ import { escapeHtml, renderAdminToolbar } from "./admin-ui-styles.ts";
13
+
14
+ export const ADMIN_TEMPLATES_PATH = "/admin/settings/templates";
15
+
16
+ const BASE = ADMIN_TEMPLATES_PATH;
17
+
18
+ export interface TemplateScopeOption {
19
+ value: string;
20
+ label: string;
21
+ }
22
+
23
+ export interface TemplateItemRow {
24
+ kind: "env" | "tool" | "plugin" | "cron";
25
+ key: string;
26
+ payload: Record<string, unknown>;
27
+ }
28
+
29
+ export interface TemplatesPageOpts {
30
+ userEmail: string;
31
+ /** Accounts the caller may pick; the deployment-wide option is included only for admins. */
32
+ accountOptions: TemplateScopeOption[];
33
+ specialtyOptions: TemplateScopeOption[];
34
+ /** Selected scope ("" = deployment-wide / all types). */
35
+ accountId: string;
36
+ specialty: string;
37
+ /** Items of the template at the selected scope (empty when none exists yet). */
38
+ items: TemplateItemRow[];
39
+ templateExists: boolean;
40
+ error?: string;
41
+ notice?: string;
42
+ }
43
+
44
+ const str = (v: unknown): string => (typeof v === "string" ? v : "");
45
+
46
+ function options(opts: TemplateScopeOption[], selected: string): string {
47
+ return opts
48
+ .map(
49
+ (o) =>
50
+ `<option value="${escapeHtml(o.value)}"${o.value === selected ? " selected" : ""}>${escapeHtml(o.label)}</option>`,
51
+ )
52
+ .join("");
53
+ }
54
+
55
+ function scopePicker(o: TemplatesPageOpts): string {
56
+ return `<form method="GET" action="${BASE}" class="template-scope" style="display:flex;gap:8px;align-items:end;flex-wrap:wrap">
57
+ <label>Account <select name="accountId" class="form-input">${options(o.accountOptions, o.accountId)}</select></label>
58
+ <label>Agent type <select name="specialty" class="form-input">${options(o.specialtyOptions, o.specialty)}</select></label>
59
+ <button type="submit" class="btn btn-secondary">Open template</button>
60
+ </form>`;
61
+ }
62
+
63
+ function scopeFields(o: TemplatesPageOpts): string {
64
+ return `<input type="hidden" name="accountId" value="${escapeHtml(o.accountId)}" /><input type="hidden" name="specialty" value="${escapeHtml(o.specialty)}" />`;
65
+ }
66
+
67
+ const checked = (b: unknown, dflt = true) =>
68
+ (b === undefined ? dflt : b !== false) ? " checked" : "";
69
+
70
+ /** The editable fields of one item (shared by the existing-item and add forms). */
71
+ function itemFields(
72
+ kind: TemplateItemRow["kind"],
73
+ p: Record<string, unknown>,
74
+ ): string {
75
+ switch (kind) {
76
+ case "env":
77
+ return `<label>Value <input name="value" class="form-input" autocomplete="off" value="${escapeHtml(str(p.value))}"/></label>
78
+ <label><input type="checkbox" name="secret" value="1"${p.secret === true ? " checked" : ""} /> Secret</label>`;
79
+ case "tool":
80
+ return `<label><input type="checkbox" name="enabled" value="1"${checked(p.enabled)} /> Enabled</label>`;
81
+ case "plugin":
82
+ return `<label>Version <input name="version" class="form-input" value="${escapeHtml(str(p.version))}" placeholder="latest" /></label>
83
+ <label><input type="checkbox" name="enabled" value="1"${checked(p.enabled)} /> Enabled</label>`;
84
+ case "cron":
85
+ return `<label>Schedule <input name="schedule" class="form-input" value="${escapeHtml(str(p.schedule))}" placeholder="0 9 * * 1-5" /></label>
86
+ <label>Prompt <textarea name="prompt" class="form-input" rows="2">${escapeHtml(str(p.prompt))}</textarea></label>
87
+ <label>Channel <input name="channel" class="form-input" value="${escapeHtml(str(p.channel))}" /></label>
88
+ <label>User <input name="user" class="form-input" value="${escapeHtml(str(p.user))}" /></label>
89
+ <label>Pre-check <input name="preCheck" class="form-input" value="${escapeHtml(str(p.preCheck))}" /></label>
90
+ <label><input type="checkbox" name="silent" value="1"${p.silent === true ? " checked" : ""} /> Silent</label>
91
+ <label><input type="checkbox" name="enabled" value="1"${checked(p.enabled)} /> Enabled</label>`;
92
+ }
93
+ }
94
+
95
+ const KIND_COPY = {
96
+ env: { title: "Environment variables", key: "Name", ph: "MY_SETTING" },
97
+ tool: { title: "Tools", key: "Tool pattern", ph: "Bash(git *)" },
98
+ plugin: { title: "Plugins", key: "Plugin", ph: "shipwright@shipwright" },
99
+ cron: { title: "Crons", key: "Name", ph: "daily-digest" },
100
+ } as const;
101
+
102
+ function kindCard(o: TemplatesPageOpts, kind: TemplateItemRow["kind"]): string {
103
+ const copy = KIND_COPY[kind];
104
+ const rows = o.items
105
+ .filter((i) => i.kind === kind)
106
+ .map(
107
+ (
108
+ i,
109
+ ) => `<form method="POST" action="${BASE}/items" class="template-item" data-kind="${kind}" data-key="${escapeHtml(i.key)}" style="display:grid;gap:6px;padding:8px 0;border-bottom:1px solid #e5e7eb">
110
+ ${scopeFields(o)}<input type="hidden" name="kind" value="${kind}" /><input type="hidden" name="key" value="${escapeHtml(i.key)}" />
111
+ <strong>${escapeHtml(i.key)}</strong>
112
+ ${itemFields(kind, i.payload)}
113
+ <div style="display:flex;gap:8px"><button type="submit" class="btn btn-primary" style="font-size:12px;padding:4px 10px">Save</button>
114
+ <button type="submit" formaction="${BASE}/items/delete" class="btn btn-danger" style="font-size:12px;padding:4px 10px">Remove</button></div>
115
+ </form>`,
116
+ )
117
+ .join("");
118
+ const empty = rows ? "" : `<p class="help-text empty-state">None yet.</p>`;
119
+ return `<div class="card" id="template-${kind}">
120
+ <div class="card-title">${copy.title}</div>
121
+ ${rows}${empty}
122
+ <form method="POST" action="${BASE}/items" class="template-add" style="display:grid;gap:6px;margin-top:12px;max-width:480px">
123
+ ${scopeFields(o)}<input type="hidden" name="kind" value="${kind}" />
124
+ <label>${copy.key} <input name="key" class="form-input" required placeholder="${escapeHtml(copy.ph)}" /></label>
125
+ ${itemFields(kind, {})}
126
+ <div><button type="submit" class="btn btn-primary">Add ${kind}</button></div>
127
+ </form>
128
+ </div>`;
129
+ }
130
+
131
+ export function renderTemplatesPage(o: TemplatesPageOpts): string {
132
+ const error = o.error
133
+ ? `<div class="alert alert-error">${escapeHtml(o.error)}</div>`
134
+ : "";
135
+ const notice = o.notice
136
+ ? `<div class="alert alert-success">${escapeHtml(o.notice)}</div>`
137
+ : "";
138
+ const del = o.templateExists
139
+ ? `<form method="POST" action="${BASE}/delete" style="margin:8px 0">${scopeFields(o)}<button type="submit" class="btn btn-danger">Delete this template</button></form>`
140
+ : `<p class="help-text">No template exists for this scope yet. Adding an item creates it.</p>`;
141
+ return renderAdminPage({
142
+ title: "Templates — Settings — Shipwright Admin",
143
+ body: `${renderAdminToolbar(o.userEmail, BASE)}
144
+ <div class="vos-page">
145
+ <div class="page-header"><h1 class="page-title">Agent templates</h1></div>
146
+ ${error}${notice}
147
+ <div class="card">
148
+ <p class="help-text">Default env vars, tools, plugins and crons for new agents in a scope. Secret values are masked after saving; leave <code>***</code> to keep the stored value.</p>
149
+ ${scopePicker(o)}
150
+ ${del}
151
+ </div>
152
+ ${(["env", "tool", "plugin", "cron"] as const).map((k) => kindCard(o, k)).join("\n")}
153
+ </div>`,
154
+ });
155
+ }
@@ -0,0 +1,54 @@
1
+ /**
2
+ * admin/src/admin-ui-templates-pages.unit.test.ts
3
+ * Unit tests for renderTemplatesPage (ATP-2.3).
4
+ */
5
+
6
+ import { describe, expect, it } from "bun:test";
7
+ import {
8
+ renderTemplatesPage,
9
+ type TemplatesPageOpts,
10
+ } from "./admin-ui-templates-pages.ts";
11
+
12
+ const base: TemplatesPageOpts = {
13
+ userEmail: "a@x.com",
14
+ accountOptions: [{ value: "", label: "Deployment-wide" }],
15
+ specialtyOptions: [{ value: "", label: "All agent types" }],
16
+ accountId: "",
17
+ specialty: "",
18
+ items: [],
19
+ templateExists: false,
20
+ };
21
+
22
+ describe("renderTemplatesPage", () => {
23
+ it("renders a card per kind and an add form each", () => {
24
+ const html = renderTemplatesPage(base);
25
+ for (const k of ["env", "tool", "plugin", "cron"]) {
26
+ expect(html).toContain(`id="template-${k}"`);
27
+ }
28
+ expect(html).toContain("No template exists for this scope yet");
29
+ expect(html).not.toContain("Delete this template");
30
+ });
31
+
32
+ it("escapes values and shows the selected scope", () => {
33
+ const html = renderTemplatesPage({
34
+ ...base,
35
+ accountOptions: [{ value: "a1", label: "<b>Acme</b>" }],
36
+ accountId: "a1",
37
+ templateExists: true,
38
+ error: "<script>x</script>",
39
+ items: [
40
+ {
41
+ kind: "env",
42
+ key: "K",
43
+ payload: { value: "***", secret: true },
44
+ },
45
+ ],
46
+ });
47
+ expect(html).toContain("&lt;b&gt;Acme&lt;/b&gt;");
48
+ expect(html).toContain('<option value="a1" selected>');
49
+ expect(html).toContain("&lt;script&gt;x&lt;/script&gt;");
50
+ expect(html).toContain('value="***"');
51
+ expect(html).toContain("Delete this template");
52
+ expect(html).toMatch(/name="secret" value="1" checked/);
53
+ });
54
+ });
@@ -0,0 +1,292 @@
1
+ /**
2
+ * admin/src/admin-ui-templates.smoke.test.ts
3
+ * Smoke tests for /admin/settings/templates (ATP-2.3) via app.request(), over
4
+ * a stateful in-memory template service that reuses the real item validation
5
+ * (denylist, payload shapes) and secret masking. No DB, no network.
6
+ */
7
+
8
+ import { describe, expect, it } from "bun:test";
9
+ import type { MiddlewareHandler } from "hono";
10
+ import { Hono } from "hono";
11
+ import type { AdminUIEnv } from "./admin-ui.ts";
12
+ import { registerAdminTemplatesRoutes } from "./admin-ui-templates.ts";
13
+ import {
14
+ type AgentTemplateService,
15
+ normalizeTemplateItem,
16
+ SECRET_MASK,
17
+ type TemplateActor,
18
+ type TemplateItemInput,
19
+ type TemplateView,
20
+ } from "./agent-templates.ts";
21
+ import type { CallerScope } from "./caller-scope.ts";
22
+ import { NotFoundError, UnprocessableEntityError } from "./errors.ts";
23
+
24
+ const now = new Date("2026-11-14T00:00:00Z");
25
+ const SPECIALTIES = ["specialist", "reviewer"];
26
+
27
+ function fakeService() {
28
+ const rows: TemplateView[] = [];
29
+ const secrets = new Map<string, string>();
30
+ let seq = 0;
31
+ const mask = (t: TemplateView): TemplateView => t;
32
+ const apply = (t: TemplateView, raw: TemplateItemInput) => {
33
+ const item = normalizeTemplateItem(raw);
34
+ const payload = { ...item.payload };
35
+ if (item.kind === "env" && payload.secret === true) {
36
+ secrets.set(`${t.id}:${item.key}`, String(payload.value));
37
+ payload.value = SECRET_MASK;
38
+ }
39
+ t.items = [
40
+ ...t.items.filter((i) => !(i.kind === item.kind && i.key === item.key)),
41
+ { kind: item.kind, key: item.key, payload, updatedAt: now },
42
+ ];
43
+ };
44
+ const visible = (a: TemplateActor, t: TemplateView) =>
45
+ a.kind === "admin" || t.accountId === a.accountId;
46
+ const service: Pick<
47
+ AgentTemplateService,
48
+ "list" | "replace" | "putItem" | "deleteItem" | "delete"
49
+ > = {
50
+ async list(actor, f = {}) {
51
+ return rows
52
+ .filter((t) => visible(actor, t))
53
+ .filter((t) => f.accountId === undefined || t.accountId === f.accountId)
54
+ .filter((t) => f.specialty === undefined || t.specialty === f.specialty)
55
+ .map(mask);
56
+ },
57
+ async replace(actor, scope, items) {
58
+ const accountId =
59
+ actor.kind === "account" ? actor.accountId : (scope.accountId ?? null);
60
+ const specialty = scope.specialty ?? null;
61
+ if (specialty !== null && !SPECIALTIES.includes(specialty)) {
62
+ throw new UnprocessableEntityError(`unknown specialty ${specialty}`);
63
+ }
64
+ const t: TemplateView = {
65
+ id: `t${++seq}`,
66
+ accountId,
67
+ specialty,
68
+ createdAt: now,
69
+ updatedAt: now,
70
+ items: [],
71
+ };
72
+ for (const i of items) apply(t, i);
73
+ rows.push(t);
74
+ return { template: t, created: true };
75
+ },
76
+ async putItem(actor, id, input) {
77
+ const t = rows.find((r) => r.id === id && visible(actor, r));
78
+ if (!t) throw new NotFoundError("nope");
79
+ apply(t, input);
80
+ return t;
81
+ },
82
+ async deleteItem(actor, id, kind, key) {
83
+ const t = rows.find((r) => r.id === id && visible(actor, r));
84
+ if (!t) throw new NotFoundError("nope");
85
+ t.items = t.items.filter((i) => !(i.kind === kind && i.key === key));
86
+ },
87
+ async delete(actor, id) {
88
+ const i = rows.findIndex((r) => r.id === id && visible(actor, r));
89
+ if (i < 0) throw new NotFoundError("nope");
90
+ rows.splice(i, 1);
91
+ },
92
+ };
93
+ return { service, rows, secrets };
94
+ }
95
+
96
+ function setup(
97
+ opts: { isAdmin?: boolean; scope?: CallerScope } = {},
98
+ ): { app: Hono<AdminUIEnv> } & ReturnType<typeof fakeService> {
99
+ const svc = fakeService();
100
+ const app = new Hono<AdminUIEnv>();
101
+ const requireAuth = (async (c, next) => {
102
+ c.set("userEmail", "u@x.com");
103
+ c.set("isAdmin", opts.isAdmin ?? true);
104
+ await next();
105
+ }) as MiddlewareHandler<AdminUIEnv>;
106
+ registerAdminTemplatesRoutes(app, {
107
+ requireAuth,
108
+ templateService: svc.service,
109
+ callerScopeResolver: async () =>
110
+ opts.scope ?? { kind: "scoped", accountId: null, agentIds: [] },
111
+ accounts: {
112
+ listWithCounts: async () =>
113
+ [
114
+ { id: "acct-1", name: "Acme" },
115
+ { id: "acct-2", name: "Globex" },
116
+ ] as never,
117
+ getWithCounts: async (id: string) =>
118
+ ({ id, name: id === "acct-1" ? "Acme" : "Globex" }) as never,
119
+ },
120
+ specialtyRegistry: {
121
+ listTypes: () =>
122
+ SPECIALTIES.map((name) => ({ name, displayName: `Type ${name}` })),
123
+ },
124
+ html: (content, o) =>
125
+ new Response(content, {
126
+ status: o?.status ?? 200,
127
+ headers: { "Content-Type": "text/html" },
128
+ }),
129
+ });
130
+ return { app, ...svc };
131
+ }
132
+
133
+ const BASE = "/admin/settings/templates";
134
+ const form = (fields: Record<string, string>) => ({
135
+ method: "POST",
136
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
137
+ body: new URLSearchParams(fields).toString(),
138
+ });
139
+ const member: CallerScope = {
140
+ kind: "scoped",
141
+ accountId: "acct-1",
142
+ agentIds: [],
143
+ };
144
+
145
+ describe("/admin/settings/templates smoke", () => {
146
+ it("renders the page with the scope picker for an admin", async () => {
147
+ const { app } = setup();
148
+ const res = await app.request(BASE);
149
+ expect(res.status).toBe(200);
150
+ const html = await res.text();
151
+ expect(html).toContain("Deployment-wide");
152
+ expect(html).toContain("Acme");
153
+ expect(html).toContain("Globex");
154
+ expect(html).toContain("All agent types");
155
+ expect(html).toContain("Type reviewer");
156
+ });
157
+
158
+ it("creates a deployment-wide secret env var and shows it masked", async () => {
159
+ const { app, rows, secrets } = setup();
160
+ const res = await app.request(
161
+ `${BASE}/items`,
162
+ form({
163
+ accountId: "",
164
+ specialty: "",
165
+ kind: "env",
166
+ key: "API_KEY",
167
+ value: "s3cr3t",
168
+ secret: "1",
169
+ }),
170
+ );
171
+ expect(res.status).toBe(302);
172
+ expect(rows[0]).toMatchObject({ accountId: null, specialty: null });
173
+ expect(secrets.get("t1:API_KEY")).toBe("s3cr3t");
174
+ const page = await app.request(res.headers.get("location") as string);
175
+ const html = await page.text();
176
+ expect(html).toContain("API_KEY");
177
+ expect(html).toContain('value="***"');
178
+ expect(html).not.toContain("s3cr3t");
179
+ });
180
+
181
+ it("updates, then removes an item, then deletes the template", async () => {
182
+ const { app, rows } = setup();
183
+ const scope = { accountId: "acct-2", specialty: "reviewer" };
184
+ await app.request(
185
+ `${BASE}/items`,
186
+ form({ ...scope, kind: "tool", key: "Bash", enabled: "1" }),
187
+ );
188
+ await app.request(
189
+ `${BASE}/items`,
190
+ form({ ...scope, kind: "plugin", key: "p@m", version: "1.2" }),
191
+ );
192
+ expect(rows).toHaveLength(1);
193
+ expect(rows[0]?.items.map((i) => i.key).sort()).toEqual(["Bash", "p@m"]);
194
+ const rm = await app.request(
195
+ `${BASE}/items/delete`,
196
+ form({ ...scope, kind: "tool", key: "Bash" }),
197
+ );
198
+ expect(rm.status).toBe(302);
199
+ expect(rows[0]?.items.map((i) => i.key)).toEqual(["p@m"]);
200
+ const del = await app.request(`${BASE}/delete`, form(scope));
201
+ expect(del.status).toBe(302);
202
+ expect(rows).toHaveLength(0);
203
+ });
204
+
205
+ it("creates a cron item", async () => {
206
+ const { app, rows } = setup();
207
+ await app.request(
208
+ `${BASE}/items`,
209
+ form({
210
+ accountId: "",
211
+ specialty: "",
212
+ kind: "cron",
213
+ key: "digest",
214
+ schedule: "0 9 * * *",
215
+ prompt: "Summarize",
216
+ enabled: "1",
217
+ }),
218
+ );
219
+ expect(rows[0]?.items[0]).toMatchObject({
220
+ kind: "cron",
221
+ key: "digest",
222
+ payload: { schedule: "0 9 * * *", prompt: "Summarize", enabled: true },
223
+ });
224
+ });
225
+
226
+ it("shows a denylisted env key error inline", async () => {
227
+ const { app, rows } = setup();
228
+ const res = await app.request(
229
+ `${BASE}/items`,
230
+ form({
231
+ accountId: "",
232
+ specialty: "",
233
+ kind: "env",
234
+ key: "SLACK_BOT_TOKEN",
235
+ value: "x",
236
+ }),
237
+ );
238
+ expect(res.status).toBe(422);
239
+ const html = await res.text();
240
+ expect(html).toContain("alert-error");
241
+ expect(html).toContain("per-agent credential");
242
+ expect(rows).toHaveLength(0);
243
+ });
244
+
245
+ it("shows an unknown specialty error inline", async () => {
246
+ const { app } = setup();
247
+ const res = await app.request(
248
+ `${BASE}/items`,
249
+ form({
250
+ accountId: "",
251
+ specialty: "ghost",
252
+ kind: "tool",
253
+ key: "Bash",
254
+ }),
255
+ );
256
+ expect(res.status).toBe(422);
257
+ expect(await res.text()).toContain("unknown specialty ghost");
258
+ });
259
+
260
+ it("offers an account member only their own account", async () => {
261
+ const { app } = setup({ isAdmin: false, scope: member });
262
+ const html = await (await app.request(BASE)).text();
263
+ expect(html).toContain("Acme");
264
+ expect(html).not.toContain("Globex");
265
+ expect(html).not.toContain("Deployment-wide");
266
+ });
267
+
268
+ it("pins member writes to their account and rejects other accounts", async () => {
269
+ const { app, rows } = setup({ isAdmin: false, scope: member });
270
+ const ok = await app.request(
271
+ `${BASE}/items`,
272
+ form({ accountId: "", specialty: "", kind: "tool", key: "Bash" }),
273
+ );
274
+ expect(ok.status).toBe(302);
275
+ expect(rows[0]?.accountId).toBe("acct-1");
276
+ const other = await app.request(
277
+ `${BASE}/items`,
278
+ form({ accountId: "acct-2", specialty: "", kind: "tool", key: "Bash" }),
279
+ );
280
+ expect(other.status).toBe(403);
281
+ expect((await app.request(`${BASE}?accountId=acct-2`)).status).toBe(403);
282
+ });
283
+
284
+ it("403s a non-admin without an account", async () => {
285
+ const { app } = setup({ isAdmin: false });
286
+ expect((await app.request(BASE)).status).toBe(403);
287
+ expect(
288
+ (await app.request(`${BASE}/items`, form({ kind: "tool", key: "x" })))
289
+ .status,
290
+ ).toBe(403);
291
+ });
292
+ });