@app-vitals/agent-admin 1.64.0 → 1.66.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 (32) hide show
  1. package/openapi.json +1 -1
  2. package/openapi.platform.json +6 -1
  3. package/package.json +2 -2
  4. package/prisma/client/internal/class.ts +4 -4
  5. package/prisma/client/internal/prismaNamespace.ts +1 -0
  6. package/prisma/client/internal/prismaNamespaceBrowser.ts +1 -0
  7. package/prisma/client/models/AgentTemplateItem.ts +36 -1
  8. package/prisma/migrations/20261117000000_add_agent_template_item_managed_by/migration.sql +5 -0
  9. package/prisma/schema/schema.prisma +3 -0
  10. package/src/admin-boot.boot-order.unit.test.ts +13 -1
  11. package/src/admin-boot.ts +25 -1
  12. package/src/admin-ui-pages.ts +30 -6
  13. package/src/admin-ui-pages.unit.test.ts +36 -1
  14. package/src/admin-ui-slack-config-token-flows.smoke.test.ts +346 -0
  15. package/src/admin-ui-templates-pages.ts +15 -1
  16. package/src/admin-ui-templates-pages.unit.test.ts +9 -0
  17. package/src/admin-ui-templates.smoke.test.ts +38 -0
  18. package/src/admin-ui.ts +46 -2
  19. package/src/agent-deletion.ts +39 -5
  20. package/src/agent-deletion.unit.test.ts +141 -0
  21. package/src/agent-templates-api.ts +1 -0
  22. package/src/agent-templates.ts +184 -9
  23. package/src/agents-api.smoke.test.ts +107 -1
  24. package/src/agents-api.ts +12 -4
  25. package/src/openapi-schemas.ts +9 -2
  26. package/src/slack-config-token-resolve.unit.test.ts +108 -0
  27. package/src/slack-config-token.ts +51 -0
  28. package/src/slack-provisioning-service.integration.test.ts +189 -1
  29. package/src/slack-provisioning-service.ts +43 -9
  30. package/src/template-seed.integration.test.ts +408 -0
  31. package/src/template-seed.ts +222 -0
  32. package/src/template-seed.unit.test.ts +272 -0
@@ -0,0 +1,272 @@
1
+ /**
2
+ * admin/src/template-seed.unit.test.ts
3
+ * TMK-3.2: SHIPWRIGHT_TEMPLATE_SEED parsing and validation, and the
4
+ * never-throwing boot runner over a stubbed template service. Pure; no DB.
5
+ */
6
+
7
+ import { describe, expect, it } from "bun:test";
8
+ import type { TemplateItemInput } from "./agent-templates.ts";
9
+ import {
10
+ parseTemplateSeed,
11
+ runTemplateSeed,
12
+ TEMPLATE_SEED_MANAGER,
13
+ } from "./template-seed.ts";
14
+
15
+ const VALID = JSON.stringify({
16
+ marketplaces: [
17
+ { name: "example-plugins", source: "example-org/plugins", ref: "v1.2.0" },
18
+ { name: "other", source: "https://example.com/other.git" },
19
+ ],
20
+ plugins: ["some-plugin@example-plugins", "tool@other"],
21
+ });
22
+
23
+ function invalid(raw: string): string {
24
+ const parsed = parseTemplateSeed(raw);
25
+ if (parsed.status !== "invalid") {
26
+ throw new Error(`expected invalid, got ${parsed.status}`);
27
+ }
28
+ return parsed.error;
29
+ }
30
+
31
+ describe("parseTemplateSeed", () => {
32
+ it("treats an unset, empty or blank value as unset", () => {
33
+ expect(parseTemplateSeed(undefined)).toEqual({ status: "unset" });
34
+ expect(parseTemplateSeed("")).toEqual({ status: "unset" });
35
+ expect(parseTemplateSeed(" \n")).toEqual({ status: "unset" });
36
+ });
37
+
38
+ it("parses marketplaces and plugins into template items", () => {
39
+ const parsed = parseTemplateSeed(VALID);
40
+ expect(parsed).toEqual({
41
+ status: "ok",
42
+ seed: {
43
+ kinds: ["marketplace", "plugin"],
44
+ items: [
45
+ {
46
+ kind: "marketplace",
47
+ key: "example-plugins",
48
+ payload: { source: "example-org/plugins", ref: "v1.2.0" },
49
+ },
50
+ {
51
+ kind: "marketplace",
52
+ key: "other",
53
+ payload: { source: "https://example.com/other.git" },
54
+ },
55
+ { kind: "plugin", key: "some-plugin@example-plugins", payload: {} },
56
+ { kind: "plugin", key: "tool@other", payload: {} },
57
+ ],
58
+ },
59
+ });
60
+ });
61
+
62
+ it("lists only the kinds whose key is present, so an absent key leaves that kind alone", () => {
63
+ const parsed = parseTemplateSeed(JSON.stringify({ plugins: ["a@b"] }));
64
+ expect(parsed.status === "ok" && parsed.seed.kinds).toEqual(["plugin"]);
65
+ });
66
+
67
+ it("keeps an empty list as a managed kind with no items (clears it)", () => {
68
+ const parsed = parseTemplateSeed(
69
+ JSON.stringify({ marketplaces: [], plugins: [] }),
70
+ );
71
+ expect(parsed).toEqual({
72
+ status: "ok",
73
+ seed: { kinds: ["marketplace", "plugin"], items: [] },
74
+ });
75
+ });
76
+
77
+ it("accepts a null ref as no ref", () => {
78
+ const parsed = parseTemplateSeed(
79
+ JSON.stringify({
80
+ marketplaces: [{ name: "mk", source: "org/repo", ref: null }],
81
+ }),
82
+ );
83
+ expect(parsed.status === "ok" && parsed.seed.items[0]?.payload).toEqual({
84
+ source: "org/repo",
85
+ ref: null,
86
+ });
87
+ });
88
+
89
+ it("rejects malformed JSON", () => {
90
+ expect(invalid("{not json")).toContain("not valid JSON");
91
+ });
92
+
93
+ it("rejects a non-object document", () => {
94
+ expect(invalid("[]")).toContain("must be a JSON object");
95
+ expect(invalid("null")).toContain("must be a JSON object");
96
+ });
97
+
98
+ it("rejects kinds that cannot be seeded", () => {
99
+ const error = invalid(JSON.stringify({ env: { A: "1" } }));
100
+ expect(error).toContain("env");
101
+ expect(error).toContain("marketplaces and plugins");
102
+ });
103
+
104
+ it("rejects a marketplaces value that is not a list", () => {
105
+ expect(invalid(JSON.stringify({ marketplaces: {} }))).toContain(
106
+ "marketplaces must be a list",
107
+ );
108
+ });
109
+
110
+ it("names a marketplace entry missing its source", () => {
111
+ const error = invalid(
112
+ JSON.stringify({
113
+ marketplaces: [
114
+ { name: "fine", source: "org/fine" },
115
+ { name: "broken" },
116
+ ],
117
+ }),
118
+ );
119
+ expect(error).toContain("marketplaces[1]");
120
+ expect(error).toContain("broken");
121
+ expect(error).toContain("source");
122
+ });
123
+
124
+ it("names a marketplace entry whose source fails the template validators", () => {
125
+ const error = invalid(
126
+ JSON.stringify({
127
+ marketplaces: [{ name: "bad-src", source: "--upload-pack=evil" }],
128
+ }),
129
+ );
130
+ expect(error).toContain("marketplaces[0]");
131
+ expect(error).toContain("bad-src");
132
+ });
133
+
134
+ it("names a marketplace entry with an invalid name", () => {
135
+ const error = invalid(
136
+ JSON.stringify({
137
+ marketplaces: [{ name: "../escape", source: "org/repo" }],
138
+ }),
139
+ );
140
+ expect(error).toContain("marketplaces[0]");
141
+ });
142
+
143
+ it("rejects unknown fields on a marketplace entry", () => {
144
+ const error = invalid(
145
+ JSON.stringify({
146
+ marketplaces: [{ name: "mk", source: "org/repo", branch: "main" }],
147
+ }),
148
+ );
149
+ expect(error).toContain("marketplaces[0]");
150
+ expect(error).toContain("branch");
151
+ });
152
+
153
+ it("names a plugin entry that is not a string", () => {
154
+ const error = invalid(JSON.stringify({ plugins: ["ok@mk", { name: 1 }] }));
155
+ expect(error).toContain("plugins[1]");
156
+ expect(error).toContain("string");
157
+ });
158
+
159
+ it("names an empty plugin entry", () => {
160
+ expect(invalid(JSON.stringify({ plugins: [" "] }))).toContain(
161
+ "plugins[0]",
162
+ );
163
+ });
164
+
165
+ it("rejects duplicate entries", () => {
166
+ expect(
167
+ invalid(
168
+ JSON.stringify({
169
+ marketplaces: [
170
+ { name: "mk", source: "org/a" },
171
+ { name: "mk", source: "org/b" },
172
+ ],
173
+ }),
174
+ ),
175
+ ).toContain("marketplaces[1]");
176
+ expect(invalid(JSON.stringify({ plugins: ["a@b", "a@b"] }))).toContain(
177
+ "plugins[1]",
178
+ );
179
+ });
180
+ });
181
+
182
+ describe("runTemplateSeed", () => {
183
+ function harness(apply?: () => Promise<unknown>) {
184
+ const calls: {
185
+ managedBy: string;
186
+ kinds: readonly string[];
187
+ items: TemplateItemInput[];
188
+ }[] = [];
189
+ const logs: string[] = [];
190
+ const errors: string[] = [];
191
+ const templateService = {
192
+ async applyManagedItems(
193
+ managedBy: string,
194
+ kinds: readonly ("marketplace" | "plugin")[],
195
+ items: TemplateItemInput[],
196
+ ) {
197
+ calls.push({ managedBy, kinds, items });
198
+ if (apply) await apply();
199
+ return {
200
+ templateId: "t1",
201
+ created: items.length,
202
+ updated: 0,
203
+ unchanged: 0,
204
+ deleted: 0,
205
+ skipped: [],
206
+ fanOut: true,
207
+ };
208
+ },
209
+ };
210
+ const logger = {
211
+ log: (...a: unknown[]) => logs.push(a.map(String).join(" ")),
212
+ error: (...a: unknown[]) => errors.push(a.map(String).join(" ")),
213
+ };
214
+ return { calls, logs, errors, templateService, logger };
215
+ }
216
+
217
+ it("does nothing when the env var is unset", async () => {
218
+ const h = harness();
219
+ const result = await runTemplateSeed({
220
+ raw: undefined,
221
+ templateService: h.templateService as never,
222
+ logger: h.logger,
223
+ });
224
+ expect(result.status).toBe("unset");
225
+ expect(h.calls).toHaveLength(0);
226
+ expect(h.errors).toHaveLength(0);
227
+ });
228
+
229
+ it("applies a valid seed as helm-managed items", async () => {
230
+ const h = harness();
231
+ const result = await runTemplateSeed({
232
+ raw: VALID,
233
+ templateService: h.templateService as never,
234
+ logger: h.logger,
235
+ });
236
+ expect(result.status).toBe("applied");
237
+ expect(h.calls).toHaveLength(1);
238
+ expect(h.calls[0]?.managedBy).toBe(TEMPLATE_SEED_MANAGER);
239
+ expect(TEMPLATE_SEED_MANAGER).toBe("helm");
240
+ expect(h.calls[0]?.kinds).toEqual(["marketplace", "plugin"]);
241
+ expect(h.calls[0]?.items).toHaveLength(4);
242
+ expect(h.logs.join("\n")).toContain("[template-seed]");
243
+ });
244
+
245
+ it("logs exactly one error naming the bad entry and applies nothing for an invalid seed", async () => {
246
+ const h = harness();
247
+ const result = await runTemplateSeed({
248
+ raw: JSON.stringify({ marketplaces: [{ name: "nosource" }] }),
249
+ templateService: h.templateService as never,
250
+ logger: h.logger,
251
+ });
252
+ expect(result.status).toBe("invalid");
253
+ expect(h.calls).toHaveLength(0);
254
+ expect(h.errors).toHaveLength(1);
255
+ expect(h.errors[0]).toContain("SHIPWRIGHT_TEMPLATE_SEED");
256
+ expect(h.errors[0]).toContain("nosource");
257
+ });
258
+
259
+ it("never throws when the apply fails", async () => {
260
+ const h = harness(async () => {
261
+ throw new Error("db down");
262
+ });
263
+ const result = await runTemplateSeed({
264
+ raw: VALID,
265
+ templateService: h.templateService as never,
266
+ logger: h.logger,
267
+ });
268
+ expect(result.status).toBe("failed");
269
+ expect(h.errors).toHaveLength(1);
270
+ expect(h.errors[0]).toContain("db down");
271
+ });
272
+ });