@app-vitals/agent-admin 1.108.1 → 1.109.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/Dockerfile +4 -0
- package/account-move.example.json +22 -0
- package/openapi.platform.json +5 -0
- package/package.json +2 -2
- package/src/account-agent-create.ts +18 -9
- package/src/account-agent-create.unit.test.ts +12 -14
- package/src/account-move.integration.test.ts +594 -0
- package/src/account-move.ts +867 -0
- package/src/account-move.unit.test.ts +206 -0
- package/src/admin-local-agent.smoke.test.ts +65 -0
- package/src/admin-ui-account-pages.ts +2 -3
- package/src/admin-ui-account-pages.unit.test.ts +5 -3
- package/src/admin-ui-pages.ts +16 -5
- package/src/admin-ui-pages.unit.test.ts +25 -20
- package/src/admin-ui.smoke.test.ts +6 -7
- package/src/admin-ui.ts +39 -27
- package/src/agents-api.smoke.test.ts +106 -8
- package/src/agents-api.ts +5 -3
- package/src/agents.integration.test.ts +112 -2
- package/src/agents.ts +37 -6
- package/src/github-enterprise-isolation.unit.test.ts +17 -0
- package/src/move-accounts.ts +201 -0
- package/src/openapi-schemas.ts +6 -0
- package/src/self-serve-config.ts +8 -8
- package/src/self-serve-config.unit.test.ts +3 -10
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* admin/src/account-move.unit.test.ts
|
|
3
|
+
*
|
|
4
|
+
* multi-account-2.6: mapping and receipt parsing, the CLI's argument handling
|
|
5
|
+
* (every case exits before any database use), the shipped example mapping,
|
|
6
|
+
* and the admin image guard that keeps the tool in the released image.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { describe, expect, it } from "bun:test";
|
|
10
|
+
import { mkdtempSync, readFileSync, writeFileSync } from "node:fs";
|
|
11
|
+
import { tmpdir } from "node:os";
|
|
12
|
+
import { join } from "node:path";
|
|
13
|
+
import {
|
|
14
|
+
formatPlan,
|
|
15
|
+
MoveInputError,
|
|
16
|
+
parseMapping,
|
|
17
|
+
parseReceipt,
|
|
18
|
+
} from "./account-move.ts";
|
|
19
|
+
import { runMoveAccountsCli, USAGE } from "./move-accounts.ts";
|
|
20
|
+
|
|
21
|
+
const ADMIN = join(import.meta.dir, "..");
|
|
22
|
+
const ROOT = join(ADMIN, "..");
|
|
23
|
+
|
|
24
|
+
describe("parseMapping", () => {
|
|
25
|
+
it("fills defaults and lowercases member emails", () => {
|
|
26
|
+
const m = parseMapping({
|
|
27
|
+
accounts: [
|
|
28
|
+
{ id: "example-a", members: [{ email: "Someone@Example.com" }] },
|
|
29
|
+
],
|
|
30
|
+
});
|
|
31
|
+
expect(m.accounts[0]).toEqual({
|
|
32
|
+
id: "example-a",
|
|
33
|
+
agents: [],
|
|
34
|
+
members: [{ email: "someone@example.com", role: "member" }],
|
|
35
|
+
});
|
|
36
|
+
expect(m.settings).toEqual([]);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it.each([
|
|
40
|
+
["an unknown top-level key", { agents: [] }],
|
|
41
|
+
["an unknown account key", { accounts: [{ id: "a", owner: "x" }] }],
|
|
42
|
+
["a bad account id", { accounts: [{ id: "has space" }] }],
|
|
43
|
+
["a negative agent limit", { accounts: [{ id: "a", maxAgents: -1 }] }],
|
|
44
|
+
[
|
|
45
|
+
"an unknown role",
|
|
46
|
+
{
|
|
47
|
+
accounts: [
|
|
48
|
+
{ id: "a", members: [{ email: "x@example.com", role: "admin" }] },
|
|
49
|
+
],
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
[
|
|
53
|
+
"an unknown setting",
|
|
54
|
+
{ settings: [{ setting: "nope", toAccountId: "a" }] },
|
|
55
|
+
],
|
|
56
|
+
[
|
|
57
|
+
"a specialty on a non-template setting",
|
|
58
|
+
{
|
|
59
|
+
settings: [
|
|
60
|
+
{ setting: "slackConfigToken", specialty: "x", toAccountId: "a" },
|
|
61
|
+
],
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
["a non-object", "nope"],
|
|
65
|
+
])("rejects %s", (_label, raw) => {
|
|
66
|
+
expect(() => parseMapping(raw)).toThrow(MoveInputError);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("accepts the shipped example mapping", () => {
|
|
70
|
+
const raw = JSON.parse(
|
|
71
|
+
readFileSync(join(ADMIN, "account-move.example.json"), "utf8"),
|
|
72
|
+
);
|
|
73
|
+
expect(parseMapping(raw).accounts.length).toBeGreaterThan(0);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
describe("parseReceipt", () => {
|
|
78
|
+
it("round-trips a receipt", () => {
|
|
79
|
+
const receipt = {
|
|
80
|
+
kind: "admin-account-move",
|
|
81
|
+
version: 1,
|
|
82
|
+
appliedAt: "2026-01-01T00:00:00.000Z",
|
|
83
|
+
changes: [
|
|
84
|
+
{
|
|
85
|
+
type: "moveAgent",
|
|
86
|
+
agentId: "a1",
|
|
87
|
+
name: "example-agent",
|
|
88
|
+
from: null,
|
|
89
|
+
to: "example-a",
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
};
|
|
93
|
+
expect(parseReceipt(receipt)).toEqual(receipt as never);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("rejects something that is not a receipt", () => {
|
|
97
|
+
expect(() => parseReceipt({ changes: [] })).toThrow(MoveInputError);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
describe("formatPlan", () => {
|
|
102
|
+
it("says when there is nothing to change", () => {
|
|
103
|
+
expect(formatPlan({ changes: [], warnings: [], skipped: [] })).toContain(
|
|
104
|
+
"nothing to change",
|
|
105
|
+
);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
describe("move-accounts CLI argument handling", () => {
|
|
110
|
+
async function cli(args: string[]) {
|
|
111
|
+
const out: string[] = [];
|
|
112
|
+
const err: string[] = [];
|
|
113
|
+
const db = new Proxy(
|
|
114
|
+
{},
|
|
115
|
+
{
|
|
116
|
+
get() {
|
|
117
|
+
throw new Error("the database must not be used");
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
);
|
|
121
|
+
const code = await runMoveAccountsCli(args, {
|
|
122
|
+
db: db as never,
|
|
123
|
+
stdout: (s) => out.push(s),
|
|
124
|
+
stderr: (s) => err.push(s),
|
|
125
|
+
});
|
|
126
|
+
return { code, out: out.join("\n"), err: err.join("\n") };
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
it("prints usage with --help", async () => {
|
|
130
|
+
const r = await cli(["--help"]);
|
|
131
|
+
expect(r.code).toBe(0);
|
|
132
|
+
expect(r.out).toBe(USAGE);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it.each([
|
|
136
|
+
[[]],
|
|
137
|
+
[["--mapping", "a.json", "--reverse", "b.json"]],
|
|
138
|
+
[["--mapping", "a.json", "--apply"]],
|
|
139
|
+
[["--reverse", "b.json", "--receipt", "c.json"]],
|
|
140
|
+
[["--bogus"]],
|
|
141
|
+
])("exits 2 on bad arguments %j", async (args) => {
|
|
142
|
+
expect((await cli(args)).code).toBe(2);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it("refuses to overwrite an existing receipt", async () => {
|
|
146
|
+
const dir = mkdtempSync(join(tmpdir(), "account-move-unit-"));
|
|
147
|
+
const receipt = join(dir, "r.json");
|
|
148
|
+
writeFileSync(receipt, "{}");
|
|
149
|
+
const r = await cli([
|
|
150
|
+
"--mapping",
|
|
151
|
+
"m.json",
|
|
152
|
+
"--apply",
|
|
153
|
+
"--receipt",
|
|
154
|
+
receipt,
|
|
155
|
+
]);
|
|
156
|
+
expect(r.code).toBe(2);
|
|
157
|
+
expect(r.err).toContain("already exists");
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it("exits 2 on an unreadable or invalid mapping", async () => {
|
|
161
|
+
const dir = mkdtempSync(join(tmpdir(), "account-move-unit-"));
|
|
162
|
+
expect((await cli(["--mapping", join(dir, "missing.json")])).code).toBe(2);
|
|
163
|
+
const bad = join(dir, "bad.json");
|
|
164
|
+
writeFileSync(bad, JSON.stringify({ accounts: [{ id: "has space" }] }));
|
|
165
|
+
expect((await cli(["--mapping", bad])).code).toBe(2);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
describe("account move tool in the admin image", () => {
|
|
170
|
+
const dockerfile = readFileSync(join(ADMIN, "Dockerfile"), "utf8");
|
|
171
|
+
const ignored = readFileSync(join(ROOT, ".dockerignore"), "utf8")
|
|
172
|
+
.split("\n")
|
|
173
|
+
.map((l) => l.trim())
|
|
174
|
+
.filter((l) => l !== "" && !l.startsWith("#"));
|
|
175
|
+
|
|
176
|
+
it("copies the whole build context into the image", () => {
|
|
177
|
+
expect(dockerfile).toMatch(/^COPY \. \.$/m);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it.each([
|
|
181
|
+
"admin/src/move-accounts.ts",
|
|
182
|
+
"admin/src/account-move.ts",
|
|
183
|
+
"admin/account-move.example.json",
|
|
184
|
+
])("keeps %s in the build context", (path) => {
|
|
185
|
+
for (const rule of ignored) {
|
|
186
|
+
const prefix = rule.replace(/^\*\*\//, "").replace(/\/$/, "");
|
|
187
|
+
const parts = path.split("/");
|
|
188
|
+
// .dockerignore here holds only plain names and **/name rules.
|
|
189
|
+
expect(
|
|
190
|
+
parts.some(
|
|
191
|
+
(p, i) => parts.slice(0, i + 1).join("/") === prefix || p === prefix,
|
|
192
|
+
),
|
|
193
|
+
).toBe(false);
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it("runs the tool's --help during the build, after prisma generate", () => {
|
|
198
|
+
const generate = dockerfile.indexOf("prisma generate");
|
|
199
|
+
const guard = dockerfile.indexOf(
|
|
200
|
+
"RUN bun admin/src/move-accounts.ts --help",
|
|
201
|
+
);
|
|
202
|
+
expect(generate).toBeGreaterThan(-1);
|
|
203
|
+
expect(guard).toBeGreaterThan(generate);
|
|
204
|
+
expect(guard).toBeLessThan(dockerfile.indexOf("USER 1000"));
|
|
205
|
+
});
|
|
206
|
+
});
|
|
@@ -1671,6 +1671,71 @@ describe("admin UI — account users create / delete agents (SSP-4.2)", () => {
|
|
|
1671
1671
|
});
|
|
1672
1672
|
});
|
|
1673
1673
|
|
|
1674
|
+
describe("platform admin account choice", () => {
|
|
1675
|
+
let adminCookie: string;
|
|
1676
|
+
beforeAll(async () => {
|
|
1677
|
+
adminCookie = await makeSessionCookie(true, "admin@example.com");
|
|
1678
|
+
});
|
|
1679
|
+
|
|
1680
|
+
const accountRows = (ids: string[]) =>
|
|
1681
|
+
ids.map((id) => ({ id, name: `Acct ${id}` }));
|
|
1682
|
+
|
|
1683
|
+
function adminDeps(ids: string[]) {
|
|
1684
|
+
const { deps, created } = depsCapturingCreate(null);
|
|
1685
|
+
return {
|
|
1686
|
+
created,
|
|
1687
|
+
deps: {
|
|
1688
|
+
...deps,
|
|
1689
|
+
accountServices: {
|
|
1690
|
+
accounts: {
|
|
1691
|
+
listWithCounts: async () => accountRows(ids),
|
|
1692
|
+
getByMemberEmail: async () => null,
|
|
1693
|
+
},
|
|
1694
|
+
members: { getByEmail: async () => null },
|
|
1695
|
+
} as never,
|
|
1696
|
+
} as AdminUIDeps,
|
|
1697
|
+
};
|
|
1698
|
+
}
|
|
1699
|
+
|
|
1700
|
+
it("GET /admin/agents/new — shows an account select only with several accounts", async () => {
|
|
1701
|
+
const several = await createAdminUIApp(
|
|
1702
|
+
adminDeps(["a1", "a2"]).deps,
|
|
1703
|
+
).request("/admin/agents/new", {
|
|
1704
|
+
headers: { Cookie: `admin_session=${adminCookie}` },
|
|
1705
|
+
});
|
|
1706
|
+
const severalHtml = await several.text();
|
|
1707
|
+
expect(severalHtml).toContain('name="accountId"');
|
|
1708
|
+
expect(severalHtml).toContain("Acct a2");
|
|
1709
|
+
expect(severalHtml).toMatch(/<select[^>]*name="type"/);
|
|
1710
|
+
|
|
1711
|
+
const one = await createAdminUIApp(adminDeps(["a1"]).deps).request(
|
|
1712
|
+
"/admin/agents/new",
|
|
1713
|
+
{ headers: { Cookie: `admin_session=${adminCookie}` } },
|
|
1714
|
+
);
|
|
1715
|
+
expect(await one.text()).not.toContain('name="accountId"');
|
|
1716
|
+
});
|
|
1717
|
+
|
|
1718
|
+
it("GET /admin/agents/new — an owner never sees an account or type choice", async () => {
|
|
1719
|
+
const { deps } = depsCapturingCreate("acct-a");
|
|
1720
|
+
const res = await createAdminUIApp(deps).request("/admin/agents/new", {
|
|
1721
|
+
headers: { Cookie: `admin_session=${accountCookie}` },
|
|
1722
|
+
});
|
|
1723
|
+
const html = await res.text();
|
|
1724
|
+
expect(html).not.toContain('name="accountId"');
|
|
1725
|
+
expect(html).not.toMatch(/<select[^>]*name="type"/);
|
|
1726
|
+
});
|
|
1727
|
+
|
|
1728
|
+
it("POST /admin/agents — the chosen account and type are used", async () => {
|
|
1729
|
+
const { deps, created } = adminDeps(["a1", "a2"]);
|
|
1730
|
+
const res = await createAdminUIApp(deps).request(
|
|
1731
|
+
"/admin/agents",
|
|
1732
|
+
form(adminCookie, { name: "made", type: TYPE, accountId: "a2" }),
|
|
1733
|
+
);
|
|
1734
|
+
expect(res.status).toBe(302);
|
|
1735
|
+
expect(created[0]).toMatchObject({ accountId: "a2", specialty: TYPE });
|
|
1736
|
+
});
|
|
1737
|
+
});
|
|
1738
|
+
|
|
1674
1739
|
it("POST /admin/agents — non-admin without an account gets 403", async () => {
|
|
1675
1740
|
const { deps, created } = depsCapturingCreate(null);
|
|
1676
1741
|
const res = await createAdminUIApp(deps).request(
|
|
@@ -149,8 +149,7 @@ export function renderAccountPage(opts: AccountPageOpts): string {
|
|
|
149
149
|
}
|
|
150
150
|
|
|
151
151
|
/** Shown on /admin/agents in place of the create button when maxAgents = 0. */
|
|
152
|
-
export function renderZeroQuotaNotice(
|
|
153
|
-
|
|
154
|
-
return `<div class="alert alert-warning" id="zero-quota-notice">Email ${email} to request a trial</div>
|
|
152
|
+
export function renderZeroQuotaNotice(): string {
|
|
153
|
+
return `<div class="alert alert-warning" id="zero-quota-notice">This account has reached its agent limit.</div>
|
|
155
154
|
<button type="button" class="btn btn-primary" disabled aria-disabled="true">+ New agent</button>`;
|
|
156
155
|
}
|
|
@@ -88,9 +88,11 @@ describe("renderAccountPage", () => {
|
|
|
88
88
|
});
|
|
89
89
|
|
|
90
90
|
describe("renderZeroQuotaNotice", () => {
|
|
91
|
-
test("shows
|
|
92
|
-
const html = renderZeroQuotaNotice(
|
|
93
|
-
expect(html).toContain("
|
|
91
|
+
test("shows a neutral limit message with no contact address", () => {
|
|
92
|
+
const html = renderZeroQuotaNotice();
|
|
93
|
+
expect(html).toContain("This account has reached its agent limit.");
|
|
94
|
+
expect(html).not.toContain("trial");
|
|
95
|
+
expect(html).not.toContain("mailto:");
|
|
94
96
|
});
|
|
95
97
|
});
|
|
96
98
|
|
package/src/admin-ui-pages.ts
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import { PROGRESS_LABELS } from "@app-vitals/agent-lib/progress-phases";
|
|
14
|
-
import {
|
|
14
|
+
import { getOwnerAgentSpecialty } from "./account-agent-create.ts";
|
|
15
15
|
import {
|
|
16
16
|
renderGithubAccessCard,
|
|
17
17
|
renderGithubInstallCard,
|
|
@@ -579,7 +579,9 @@ export function renderNewLocalAgentPage(
|
|
|
579
579
|
* remaining agent quota and the prerequisites, and pins the type to
|
|
580
580
|
* the self-serve specialty (the server forces it regardless).
|
|
581
581
|
*/
|
|
582
|
-
selfServe?: { remaining: number; max: number
|
|
582
|
+
selfServe?: { remaining: number; max: number };
|
|
583
|
+
/** Platform admins: accounts to pick from when more than one exists. */
|
|
584
|
+
accountChoices?: { id: string; name: string }[];
|
|
583
585
|
/**
|
|
584
586
|
* ATP-2.4: present when agent templates are available. Lists the
|
|
585
587
|
* template-provided defaults and adds the opt-out checkbox; `allowEnv`
|
|
@@ -648,8 +650,7 @@ export function renderNewLocalAgentPage(
|
|
|
648
650
|
${
|
|
649
651
|
selfServe.remaining <= 0
|
|
650
652
|
? `<p style="font-size:13px;color:var(--vos-danger-text);margin-bottom:8px">
|
|
651
|
-
This account has reached its agent limit. Delete an agent to free a slot
|
|
652
|
-
or contact <a href="mailto:${escapeHtml(selfServe.contactEmail)}">${escapeHtml(selfServe.contactEmail)}</a> for more.
|
|
653
|
+
This account has reached its agent limit. Delete an agent to free a slot.
|
|
653
654
|
</p>`
|
|
654
655
|
: ""
|
|
655
656
|
}
|
|
@@ -701,8 +702,17 @@ export function renderNewLocalAgentPage(
|
|
|
701
702
|
</div>
|
|
702
703
|
</fieldset>`
|
|
703
704
|
: "";
|
|
705
|
+
const accountFieldHtml = opts?.accountChoices
|
|
706
|
+
? `<div class="form-group">
|
|
707
|
+
<label class="form-label" for="accountId">Account <span style="color:#ef4444">*</span></label>
|
|
708
|
+
<select id="accountId" name="accountId" class="form-input" required>
|
|
709
|
+
<option value="">Choose an account</option>
|
|
710
|
+
${opts.accountChoices.map((a) => `<option value="${escapeHtml(a.id)}">${escapeHtml(a.name)}</option>`).join("\n")}
|
|
711
|
+
</select>
|
|
712
|
+
</div>`
|
|
713
|
+
: "";
|
|
704
714
|
const typeFieldHtml = selfServe
|
|
705
|
-
? `<input type="hidden" name="type" value="${escapeHtml(
|
|
715
|
+
? `<input type="hidden" name="type" value="${escapeHtml(getOwnerAgentSpecialty())}" />`
|
|
706
716
|
: `<div class="form-group">
|
|
707
717
|
<label class="form-label" for="type">Specialty <span style="color:#ef4444">*</span></label>
|
|
708
718
|
<select id="type" name="type" class="form-input" required>
|
|
@@ -742,6 +752,7 @@ export function renderNewLocalAgentPage(
|
|
|
742
752
|
/>
|
|
743
753
|
</div>
|
|
744
754
|
${typeFieldHtml}
|
|
755
|
+
${accountFieldHtml}
|
|
745
756
|
<fieldset style="border:1px solid var(--vos-border);border-radius:8px;padding:16px">
|
|
746
757
|
<legend style="font-size:13px;font-weight:600;padding:0 8px">Runtime</legend>
|
|
747
758
|
<div class="form-group" style="margin-bottom:0">
|
|
@@ -4333,7 +4333,7 @@ describe("renderAgentDetailPage — canManage gating (SSP-4.3)", () => {
|
|
|
4333
4333
|
|
|
4334
4334
|
describe("renderNewLocalAgentPage — self-serve account user (SSP-4.2)", () => {
|
|
4335
4335
|
const CODING_TYPE = { name: "coding", displayName: "Coding Agent" };
|
|
4336
|
-
const selfServe = { remaining: 2, max: 3
|
|
4336
|
+
const selfServe = { remaining: 2, max: 3 };
|
|
4337
4337
|
|
|
4338
4338
|
test("shows remaining quota and the credential prerequisites", () => {
|
|
4339
4339
|
const html = renderNewLocalAgentPage(USER_NAME, [CODING_TYPE], {
|
|
@@ -4355,31 +4355,22 @@ describe("renderNewLocalAgentPage — self-serve account user (SSP-4.2)", () =>
|
|
|
4355
4355
|
});
|
|
4356
4356
|
|
|
4357
4357
|
describe("hidden type input", () => {
|
|
4358
|
-
const saved =
|
|
4359
|
-
selfServe: process.env.SHIPWRIGHT_SELF_SERVE_AGENT_TYPE,
|
|
4360
|
-
defaultType: process.env.SHIPWRIGHT_DEFAULT_AGENT_TYPE,
|
|
4361
|
-
};
|
|
4362
|
-
const restore = (key: string, value: string | undefined) => {
|
|
4363
|
-
if (value === undefined) delete process.env[key];
|
|
4364
|
-
else process.env[key] = value;
|
|
4365
|
-
};
|
|
4358
|
+
const saved = process.env.SHIPWRIGHT_DEFAULT_AGENT_TYPE;
|
|
4366
4359
|
afterEach(() => {
|
|
4367
|
-
|
|
4368
|
-
|
|
4360
|
+
if (saved === undefined) delete process.env.SHIPWRIGHT_DEFAULT_AGENT_TYPE;
|
|
4361
|
+
else process.env.SHIPWRIGHT_DEFAULT_AGENT_TYPE = saved;
|
|
4369
4362
|
});
|
|
4370
4363
|
|
|
4371
|
-
test("carries the
|
|
4372
|
-
process.env.
|
|
4364
|
+
test("carries the deployment default type instead of a type select", () => {
|
|
4365
|
+
process.env.SHIPWRIGHT_DEFAULT_AGENT_TYPE = "base";
|
|
4373
4366
|
const html = renderNewLocalAgentPage(USER_NAME, [CODING_TYPE], {
|
|
4374
4367
|
selfServe,
|
|
4375
4368
|
});
|
|
4376
4369
|
expect(html).toContain('<input type="hidden" name="type" value="base"');
|
|
4377
|
-
expect(html).not.toContain('name="type" value="coding"');
|
|
4378
4370
|
expect(html).not.toMatch(/<select[^>]*name="type"/);
|
|
4379
4371
|
});
|
|
4380
4372
|
|
|
4381
|
-
test("falls back to
|
|
4382
|
-
delete process.env.SHIPWRIGHT_SELF_SERVE_AGENT_TYPE;
|
|
4373
|
+
test("falls back to specialist when the default is unset", () => {
|
|
4383
4374
|
delete process.env.SHIPWRIGHT_DEFAULT_AGENT_TYPE;
|
|
4384
4375
|
const html = renderNewLocalAgentPage(USER_NAME, [CODING_TYPE], {
|
|
4385
4376
|
selfServe,
|
|
@@ -4390,12 +4381,26 @@ describe("renderNewLocalAgentPage — self-serve account user (SSP-4.2)", () =>
|
|
|
4390
4381
|
});
|
|
4391
4382
|
});
|
|
4392
4383
|
|
|
4393
|
-
test("at zero remaining, explains the limit
|
|
4384
|
+
test("at zero remaining, explains the limit without a contact address", () => {
|
|
4394
4385
|
const html = renderNewLocalAgentPage(USER_NAME, [CODING_TYPE], {
|
|
4395
4386
|
selfServe: { ...selfServe, remaining: 0 },
|
|
4396
4387
|
});
|
|
4397
4388
|
expect(html).toContain("agent limit");
|
|
4398
|
-
expect(html).toContain("
|
|
4389
|
+
expect(html).not.toContain("mailto:");
|
|
4390
|
+
});
|
|
4391
|
+
|
|
4392
|
+
test("admin form offers an account select only when choices are given", () => {
|
|
4393
|
+
const withChoices = renderNewLocalAgentPage(USER_NAME, [CODING_TYPE], {
|
|
4394
|
+
accountChoices: [
|
|
4395
|
+
{ id: "a1", name: "Alpha" },
|
|
4396
|
+
{ id: "a2", name: "Beta" },
|
|
4397
|
+
],
|
|
4398
|
+
});
|
|
4399
|
+
expect(withChoices).toMatch(/<select[^>]*name="accountId"/);
|
|
4400
|
+
expect(withChoices).toContain('value="a2">Beta');
|
|
4401
|
+
expect(renderNewLocalAgentPage(USER_NAME, [CODING_TYPE])).not.toContain(
|
|
4402
|
+
'name="accountId"',
|
|
4403
|
+
);
|
|
4399
4404
|
});
|
|
4400
4405
|
|
|
4401
4406
|
test("admin form (no selfServe opt) is unchanged", () => {
|
|
@@ -4408,9 +4413,9 @@ describe("renderNewLocalAgentPage — self-serve account user (SSP-4.2)", () =>
|
|
|
4408
4413
|
describe("renderAgentsPage zero-quota notice (SSP-3.2)", () => {
|
|
4409
4414
|
test("replaces the create CTA with the notice and a disabled button", () => {
|
|
4410
4415
|
const html = renderAgentsPage([], "u@x.com", true, "UTC", {
|
|
4411
|
-
zeroQuotaNotice: renderZeroQuotaNotice(
|
|
4416
|
+
zeroQuotaNotice: renderZeroQuotaNotice(),
|
|
4412
4417
|
});
|
|
4413
|
-
expect(html).toContain("
|
|
4418
|
+
expect(html).toContain("This account has reached its agent limit.");
|
|
4414
4419
|
expect(html).toContain("disabled");
|
|
4415
4420
|
expect(html).not.toContain(
|
|
4416
4421
|
'<a href="/admin/agents/new" class="btn btn-primary">',
|
|
@@ -8325,11 +8325,7 @@ describe("admin UI — agents list account features, self-serve off and on", ()
|
|
|
8325
8325
|
const base = makeMockDeps();
|
|
8326
8326
|
return createAdminUIApp(
|
|
8327
8327
|
makeMockDeps({
|
|
8328
|
-
selfServe: {
|
|
8329
|
-
enabled,
|
|
8330
|
-
defaultMaxAgents: 0,
|
|
8331
|
-
contactEmail: "quota@example.com",
|
|
8332
|
-
},
|
|
8328
|
+
selfServe: { enabled, defaultMaxAgents: 0 },
|
|
8333
8329
|
callerScopeResolver: async () => ({
|
|
8334
8330
|
kind: "scoped" as const,
|
|
8335
8331
|
accountId: "acct-a",
|
|
@@ -8368,7 +8364,7 @@ describe("admin UI — agents list account features, self-serve off and on", ()
|
|
|
8368
8364
|
expect(body).toContain('href="/admin/accounts/acct-a"');
|
|
8369
8365
|
});
|
|
8370
8366
|
|
|
8371
|
-
it(`self-serve ${label}: an owner of a zero-limit account sees the
|
|
8367
|
+
it(`self-serve ${label}: an owner of a zero-limit account sees the limit notice`, async () => {
|
|
8372
8368
|
const cookie = await makeSessionCookie(
|
|
8373
8369
|
SESSION_SECRET,
|
|
8374
8370
|
"google-sub-owner",
|
|
@@ -8379,7 +8375,10 @@ describe("admin UI — agents list account features, self-serve off and on", ()
|
|
|
8379
8375
|
headers: { Cookie: `admin_session=${cookie}` },
|
|
8380
8376
|
});
|
|
8381
8377
|
expect(res.status).toBe(200);
|
|
8382
|
-
|
|
8378
|
+
const body = await res.text();
|
|
8379
|
+
expect(body).toContain("This account has reached its agent limit.");
|
|
8380
|
+
expect(body).not.toContain("request a trial");
|
|
8381
|
+
expect(body).not.toContain("quota@example.com");
|
|
8383
8382
|
});
|
|
8384
8383
|
}
|
|
8385
8384
|
});
|
package/src/admin-ui.ts
CHANGED
|
@@ -32,7 +32,7 @@ import { sign, verify } from "hono/jwt";
|
|
|
32
32
|
import {
|
|
33
33
|
accountIdFromScope,
|
|
34
34
|
createAccountIdFromScope,
|
|
35
|
-
|
|
35
|
+
getOwnerAgentSpecialty,
|
|
36
36
|
} from "./account-agent-create.ts";
|
|
37
37
|
import type { AccountCreatedNotifier } from "./account-created-notifier.ts";
|
|
38
38
|
import { fireAccountCreatedNotification } from "./account-created-notifier.ts";
|
|
@@ -129,7 +129,11 @@ import type { AgentTemplateService } from "./agent-templates.ts";
|
|
|
129
129
|
import type { AgentTokenService } from "./agent-tokens.ts";
|
|
130
130
|
import type { AgentToolService } from "./agent-tools.ts";
|
|
131
131
|
import type { AgentService } from "./agents.ts";
|
|
132
|
-
import {
|
|
132
|
+
import {
|
|
133
|
+
ACCOUNT_REQUIRED_MESSAGE,
|
|
134
|
+
createAgent,
|
|
135
|
+
describeRepoNameCollision,
|
|
136
|
+
} from "./agents.ts";
|
|
133
137
|
import { AnthropicCredentialsBlockedError } from "./anthropic-credential-guard.ts";
|
|
134
138
|
import {
|
|
135
139
|
audioContentTypeForFilename,
|
|
@@ -176,10 +180,7 @@ import {
|
|
|
176
180
|
sanitizeStartUrl,
|
|
177
181
|
} from "./pwa.ts";
|
|
178
182
|
import { secretsEqual } from "./secrets-equal.ts";
|
|
179
|
-
import {
|
|
180
|
-
DEFAULT_SELF_SERVE_CONTACT_EMAIL,
|
|
181
|
-
type SelfServeConfig,
|
|
182
|
-
} from "./self-serve-config.ts";
|
|
183
|
+
import type { SelfServeConfig } from "./self-serve-config.ts";
|
|
183
184
|
import {
|
|
184
185
|
SETUP_RESUME_COOKIE,
|
|
185
186
|
SETUP_RESUME_TTL_SECONDS,
|
|
@@ -1624,17 +1625,14 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
1624
1625
|
// malformed/tampered query param — render without the panel
|
|
1625
1626
|
}
|
|
1626
1627
|
}
|
|
1627
|
-
// SSP-3.2: a zero-quota account sees a
|
|
1628
|
-
//
|
|
1629
|
-
let
|
|
1630
|
-
if (accountServices) {
|
|
1628
|
+
// SSP-3.2: a zero-quota account sees a limit message and a disabled
|
|
1629
|
+
// create button instead of the create CTA. Platform admins are not limited.
|
|
1630
|
+
let zeroQuota = false;
|
|
1631
|
+
if (accountServices && !c.var.isAdmin) {
|
|
1631
1632
|
const account = await accountServices.accounts.getByMemberEmail(
|
|
1632
1633
|
c.var.userEmail,
|
|
1633
1634
|
);
|
|
1634
|
-
|
|
1635
|
-
zeroQuotaContactEmail =
|
|
1636
|
-
selfServe?.contactEmail ?? DEFAULT_SELF_SERVE_CONTACT_EMAIL;
|
|
1637
|
-
}
|
|
1635
|
+
zeroQuota = account?.maxAgents === 0;
|
|
1638
1636
|
}
|
|
1639
1637
|
// SSP-5.2: admins get an Account column.
|
|
1640
1638
|
let accountNames: Map<string, string> | undefined;
|
|
@@ -1652,9 +1650,7 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
1652
1650
|
queueActivityLinks: deps.queueActivityLinks,
|
|
1653
1651
|
successMsg,
|
|
1654
1652
|
manualSteps,
|
|
1655
|
-
zeroQuotaNotice:
|
|
1656
|
-
? renderZeroQuotaNotice(zeroQuotaContactEmail)
|
|
1657
|
-
: undefined,
|
|
1653
|
+
zeroQuotaNotice: zeroQuota ? renderZeroQuotaNotice() : undefined,
|
|
1658
1654
|
}),
|
|
1659
1655
|
);
|
|
1660
1656
|
});
|
|
@@ -1694,8 +1690,10 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
1694
1690
|
"In-cluster provisioning is not enabled on this admin service — create a self-hosted agent instead.",
|
|
1695
1691
|
provision_failed:
|
|
1696
1692
|
"Failed to provision the agent's cluster resources — the agent was not created.",
|
|
1697
|
-
quota_exceeded:
|
|
1693
|
+
quota_exceeded:
|
|
1694
|
+
"This account has reached its agent limit. Delete an agent to free a slot.",
|
|
1698
1695
|
account_inactive: "This account is not active.",
|
|
1696
|
+
account_required: ACCOUNT_REQUIRED_MESSAGE,
|
|
1699
1697
|
...deps.agentDetailErrorMessages,
|
|
1700
1698
|
};
|
|
1701
1699
|
|
|
@@ -1754,9 +1752,15 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
1754
1752
|
if (!c.var.isAdmin && accountId === null) {
|
|
1755
1753
|
return new Response("Forbidden", { status: 403 });
|
|
1756
1754
|
}
|
|
1757
|
-
let selfServeOpts:
|
|
1758
|
-
|
|
1759
|
-
|
|
1755
|
+
let selfServeOpts: { remaining: number; max: number } | undefined;
|
|
1756
|
+
// Platform admins pick the account when more than one exists.
|
|
1757
|
+
let accountChoices: { id: string; name: string }[] | undefined;
|
|
1758
|
+
if (c.var.isAdmin && accountServices) {
|
|
1759
|
+
const all = await accountServices.accounts.listWithCounts();
|
|
1760
|
+
if (all.length > 1) {
|
|
1761
|
+
accountChoices = all.map((a) => ({ id: a.id, name: a.name }));
|
|
1762
|
+
}
|
|
1763
|
+
}
|
|
1760
1764
|
if (accountId !== null && accountService) {
|
|
1761
1765
|
const [account, count] = await Promise.all([
|
|
1762
1766
|
accountService.getById(accountId),
|
|
@@ -1765,8 +1769,6 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
1765
1769
|
selfServeOpts = {
|
|
1766
1770
|
remaining: Math.max(0, (account?.maxAgents ?? 0) - count),
|
|
1767
1771
|
max: account?.maxAgents ?? 0,
|
|
1768
|
-
contactEmail:
|
|
1769
|
-
selfServe?.contactEmail ?? DEFAULT_SELF_SERVE_CONTACT_EMAIL,
|
|
1770
1772
|
};
|
|
1771
1773
|
}
|
|
1772
1774
|
const rawError = c.req.query("error") ?? undefined;
|
|
@@ -1782,6 +1784,7 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
1782
1784
|
accountId,
|
|
1783
1785
|
),
|
|
1784
1786
|
...(selfServeOpts ? { selfServe: selfServeOpts } : {}),
|
|
1787
|
+
...(accountChoices ? { accountChoices } : {}),
|
|
1785
1788
|
...(templateService
|
|
1786
1789
|
? {
|
|
1787
1790
|
template: {
|
|
@@ -1806,6 +1809,7 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
1806
1809
|
}
|
|
1807
1810
|
let name: string | undefined;
|
|
1808
1811
|
let specialty: string | undefined;
|
|
1812
|
+
let chosenAccountId: string | undefined;
|
|
1809
1813
|
let reposRaw: string | undefined;
|
|
1810
1814
|
let authorAllowlistRaw: string | undefined;
|
|
1811
1815
|
let patchAuthorAllowlistRaw: string | undefined;
|
|
@@ -1832,6 +1836,8 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
1832
1836
|
envRaw = formData.get("env")?.toString();
|
|
1833
1837
|
name = formData.get("name")?.toString()?.trim();
|
|
1834
1838
|
specialty = formData.get("type")?.toString()?.trim();
|
|
1839
|
+
chosenAccountId =
|
|
1840
|
+
formData.get("accountId")?.toString()?.trim() || undefined;
|
|
1835
1841
|
reposRaw = formData.get("repos")?.toString()?.trim();
|
|
1836
1842
|
authorAllowlistRaw = formData.get("authorAllowlist")?.toString()?.trim();
|
|
1837
1843
|
patchAuthorAllowlistRaw = formData
|
|
@@ -1878,9 +1884,13 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
1878
1884
|
);
|
|
1879
1885
|
}
|
|
1880
1886
|
const connectSlack = connectSlackRaw === "true";
|
|
1881
|
-
//
|
|
1882
|
-
// account — any submitted type/accountId is ignored.
|
|
1883
|
-
|
|
1887
|
+
// Account owners always create the default agent type in their own
|
|
1888
|
+
// account — any submitted type/accountId is ignored. Platform admins
|
|
1889
|
+
// choose the type, and the account when several exist.
|
|
1890
|
+
const targetAccountId = c.var.isAdmin
|
|
1891
|
+
? chosenAccountId
|
|
1892
|
+
: (accountId ?? undefined);
|
|
1893
|
+
if (accountId !== null) specialty = getOwnerAgentSpecialty();
|
|
1884
1894
|
// Absent/unrecognized runtime means self-hosted — the historical behavior
|
|
1885
1895
|
// of this form. createAgent() below re-derives this same value itself
|
|
1886
1896
|
// (it owns the runtime/provisioning validation); it's recomputed here
|
|
@@ -1943,7 +1953,9 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
1943
1953
|
restrictSlackToMembersRaw,
|
|
1944
1954
|
claudeCodeOauthToken,
|
|
1945
1955
|
anthropicApiKey,
|
|
1946
|
-
...(
|
|
1956
|
+
...(targetAccountId !== undefined
|
|
1957
|
+
? { accountId: targetAccountId }
|
|
1958
|
+
: {}),
|
|
1947
1959
|
...(templateDetachedRaw === "true" ? { templateDetached: true } : {}),
|
|
1948
1960
|
...(Object.keys(explicitEnv).length > 0 ? { env: explicitEnv } : {}),
|
|
1949
1961
|
// PAI-1.2: owner is the authenticated session user, never form data.
|