@app-vitals/agent-admin 1.65.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.
- package/openapi.platform.json +5 -0
- package/package.json +2 -2
- package/prisma/client/internal/class.ts +4 -4
- package/prisma/client/internal/prismaNamespace.ts +1 -0
- package/prisma/client/internal/prismaNamespaceBrowser.ts +1 -0
- package/prisma/client/models/AgentTemplateItem.ts +36 -1
- package/prisma/migrations/20261117000000_add_agent_template_item_managed_by/migration.sql +5 -0
- package/prisma/schema/schema.prisma +3 -0
- package/src/admin-boot.boot-order.unit.test.ts +13 -1
- package/src/admin-boot.ts +14 -1
- package/src/admin-ui-templates-pages.ts +15 -1
- package/src/admin-ui-templates-pages.unit.test.ts +9 -0
- package/src/admin-ui-templates.smoke.test.ts +38 -0
- package/src/agent-templates-api.ts +1 -0
- package/src/agent-templates.ts +184 -9
- package/src/openapi-schemas.ts +5 -0
- package/src/template-seed.integration.test.ts +408 -0
- package/src/template-seed.ts +222 -0
- package/src/template-seed.unit.test.ts +272 -0
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* admin/src/template-seed.ts
|
|
3
|
+
* TMK-3.2: seed the deployment-wide, all-specialties agent template from
|
|
4
|
+
* SHIPWRIGHT_TEMPLATE_SEED, the JSON the agent-platform chart renders from
|
|
5
|
+
* `admin.templateSeed` Helm values:
|
|
6
|
+
*
|
|
7
|
+
* {"marketplaces":[{"name":"example-plugins","source":"example-org/plugins","ref":"v1.2.0"}],
|
|
8
|
+
* "plugins":["some-plugin@example-plugins"]}
|
|
9
|
+
*
|
|
10
|
+
* Only marketplaces and plugins can be seeded. Run once per admin boot, after
|
|
11
|
+
* migrations (admin-boot.ts):
|
|
12
|
+
*
|
|
13
|
+
* - Unset or blank: nothing happens; previously seeded items stay.
|
|
14
|
+
* - A listed kind (`marketplaces` / `plugins` present, even as `[]`) is
|
|
15
|
+
* replaced: its seeded items become exactly the list. A kind whose key is
|
|
16
|
+
* absent keeps its seeded items, so removal only ever happens by listing a
|
|
17
|
+
* smaller seed.
|
|
18
|
+
* - Invalid JSON or an entry failing the template validators (the same
|
|
19
|
+
* normalizeTemplateItem() as the /templates API): one error naming the
|
|
20
|
+
* entry is logged and nothing is written.
|
|
21
|
+
*
|
|
22
|
+
* The apply goes through AgentTemplateService.applyManagedItems(): items get
|
|
23
|
+
* managedBy="helm", hand-added items (managedBy null) are never touched, the
|
|
24
|
+
* write holds a transaction-scoped advisory lock so concurrent replicas are
|
|
25
|
+
* safe, and the ATP-2.2 fan-out then reconciles every attached agent.
|
|
26
|
+
*
|
|
27
|
+
* Seeded items are not read-only: UI/API edits are allowed and overwritten on
|
|
28
|
+
* the next boot. Never throws (like startup-policy-reconcile.ts).
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
import type { AgentTemplateItemKind } from "./agent-template-items.ts";
|
|
32
|
+
import {
|
|
33
|
+
type AgentTemplateService,
|
|
34
|
+
type ManagedItemsResult,
|
|
35
|
+
normalizeTemplateItem,
|
|
36
|
+
type TemplateItemInput,
|
|
37
|
+
} from "./agent-templates.ts";
|
|
38
|
+
|
|
39
|
+
export const TEMPLATE_SEED_ENV = "SHIPWRIGHT_TEMPLATE_SEED";
|
|
40
|
+
|
|
41
|
+
/** AgentTemplateItem.managedBy for seeded items. */
|
|
42
|
+
export const TEMPLATE_SEED_MANAGER = "helm";
|
|
43
|
+
|
|
44
|
+
type SeedKind = Extract<AgentTemplateItemKind, "marketplace" | "plugin">;
|
|
45
|
+
|
|
46
|
+
export interface TemplateSeed {
|
|
47
|
+
/** The kinds the seed lists; their seeded items are replaced. */
|
|
48
|
+
kinds: SeedKind[];
|
|
49
|
+
items: TemplateItemInput[];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type TemplateSeedParse =
|
|
53
|
+
| { status: "unset" }
|
|
54
|
+
| { status: "ok"; seed: TemplateSeed }
|
|
55
|
+
| { status: "invalid"; error: string };
|
|
56
|
+
|
|
57
|
+
const MARKETPLACE_FIELDS = new Set(["name", "source", "ref"]);
|
|
58
|
+
|
|
59
|
+
const isObject = (v: unknown): v is Record<string, unknown> =>
|
|
60
|
+
v !== null && typeof v === "object" && !Array.isArray(v);
|
|
61
|
+
|
|
62
|
+
class SeedError extends Error {}
|
|
63
|
+
|
|
64
|
+
/** `marketplaces[1] (broken)` — how errors name an entry. */
|
|
65
|
+
function entryLabel(list: string, index: number, name: unknown): string {
|
|
66
|
+
return typeof name === "string" && name.trim() !== ""
|
|
67
|
+
? `${list}[${index}] (${name})`
|
|
68
|
+
: `${list}[${index}]`;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Runs the template validators on one item, naming the entry on failure. */
|
|
72
|
+
function validated(label: string, item: TemplateItemInput): TemplateItemInput {
|
|
73
|
+
try {
|
|
74
|
+
const { kind, key, payload } = normalizeTemplateItem(item);
|
|
75
|
+
return { kind, key, payload };
|
|
76
|
+
} catch (err) {
|
|
77
|
+
throw new SeedError(
|
|
78
|
+
`${label}: ${err instanceof Error ? err.message : String(err)}`,
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function parseMarketplaces(value: unknown): TemplateItemInput[] {
|
|
84
|
+
if (!Array.isArray(value)) {
|
|
85
|
+
throw new SeedError("marketplaces must be a list");
|
|
86
|
+
}
|
|
87
|
+
const names = new Set<string>();
|
|
88
|
+
return value.map((entry, i) => {
|
|
89
|
+
const name = isObject(entry) ? entry.name : undefined;
|
|
90
|
+
const label = entryLabel("marketplaces", i, name);
|
|
91
|
+
if (!isObject(entry)) {
|
|
92
|
+
throw new SeedError(`${label}: must be an object {name, source, ref?}`);
|
|
93
|
+
}
|
|
94
|
+
const unknown = Object.keys(entry).filter(
|
|
95
|
+
(k) => !MARKETPLACE_FIELDS.has(k),
|
|
96
|
+
);
|
|
97
|
+
if (unknown.length > 0) {
|
|
98
|
+
throw new SeedError(`${label}: unknown field ${unknown.join(", ")}`);
|
|
99
|
+
}
|
|
100
|
+
if (typeof name !== "string" || name.trim() === "") {
|
|
101
|
+
throw new SeedError(`${label}: name must be a non-empty string`);
|
|
102
|
+
}
|
|
103
|
+
if (typeof entry.source !== "string" || entry.source.trim() === "") {
|
|
104
|
+
throw new SeedError(`${label}: source must be a non-empty string`);
|
|
105
|
+
}
|
|
106
|
+
const payload: Record<string, unknown> = { source: entry.source };
|
|
107
|
+
if (entry.ref !== undefined) payload.ref = entry.ref;
|
|
108
|
+
const item = validated(label, { kind: "marketplace", key: name, payload });
|
|
109
|
+
if (names.has(item.key)) {
|
|
110
|
+
throw new SeedError(`${label}: duplicate marketplace ${item.key}`);
|
|
111
|
+
}
|
|
112
|
+
names.add(item.key);
|
|
113
|
+
return item;
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function parsePlugins(value: unknown): TemplateItemInput[] {
|
|
118
|
+
if (!Array.isArray(value)) throw new SeedError("plugins must be a list");
|
|
119
|
+
const specs = new Set<string>();
|
|
120
|
+
return value.map((entry, i) => {
|
|
121
|
+
const label = entryLabel("plugins", i, entry);
|
|
122
|
+
if (typeof entry !== "string") {
|
|
123
|
+
throw new SeedError(`${label}: must be a plugin spec string`);
|
|
124
|
+
}
|
|
125
|
+
const item = validated(label, { kind: "plugin", key: entry, payload: {} });
|
|
126
|
+
if (specs.has(item.key)) {
|
|
127
|
+
throw new SeedError(`${label}: duplicate plugin ${item.key}`);
|
|
128
|
+
}
|
|
129
|
+
specs.add(item.key);
|
|
130
|
+
return item;
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Parses and validates SHIPWRIGHT_TEMPLATE_SEED. Pure; never throws. */
|
|
135
|
+
export function parseTemplateSeed(raw: string | undefined): TemplateSeedParse {
|
|
136
|
+
if (raw === undefined || raw.trim() === "") return { status: "unset" };
|
|
137
|
+
let doc: unknown;
|
|
138
|
+
try {
|
|
139
|
+
doc = JSON.parse(raw);
|
|
140
|
+
} catch (err) {
|
|
141
|
+
return {
|
|
142
|
+
status: "invalid",
|
|
143
|
+
error: `not valid JSON (${err instanceof Error ? err.message : String(err)})`,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
try {
|
|
147
|
+
if (!isObject(doc)) {
|
|
148
|
+
throw new SeedError(
|
|
149
|
+
"must be a JSON object with marketplaces and/or plugins",
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
const unknown = Object.keys(doc).filter(
|
|
153
|
+
(k) => k !== "marketplaces" && k !== "plugins",
|
|
154
|
+
);
|
|
155
|
+
if (unknown.length > 0) {
|
|
156
|
+
throw new SeedError(
|
|
157
|
+
`unknown key ${unknown.join(", ")}; only marketplaces and plugins can be seeded`,
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
const kinds: SeedKind[] = [];
|
|
161
|
+
const items: TemplateItemInput[] = [];
|
|
162
|
+
if (doc.marketplaces !== undefined) {
|
|
163
|
+
kinds.push("marketplace");
|
|
164
|
+
items.push(...parseMarketplaces(doc.marketplaces));
|
|
165
|
+
}
|
|
166
|
+
if (doc.plugins !== undefined) {
|
|
167
|
+
kinds.push("plugin");
|
|
168
|
+
items.push(...parsePlugins(doc.plugins));
|
|
169
|
+
}
|
|
170
|
+
return { status: "ok", seed: { kinds, items } };
|
|
171
|
+
} catch (err) {
|
|
172
|
+
if (err instanceof SeedError) {
|
|
173
|
+
return { status: "invalid", error: err.message };
|
|
174
|
+
}
|
|
175
|
+
throw err;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export interface TemplateSeedDeps {
|
|
180
|
+
/** The raw env value (process.env.SHIPWRIGHT_TEMPLATE_SEED). */
|
|
181
|
+
raw: string | undefined;
|
|
182
|
+
templateService: Pick<AgentTemplateService, "applyManagedItems">;
|
|
183
|
+
logger: Pick<Console, "log" | "error">;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export type TemplateSeedOutcome =
|
|
187
|
+
| { status: "unset" }
|
|
188
|
+
| { status: "invalid"; error: string }
|
|
189
|
+
| { status: "applied"; result: ManagedItemsResult }
|
|
190
|
+
| { status: "failed"; error: string };
|
|
191
|
+
|
|
192
|
+
/** Applies the seed on boot. Never throws; every failure is logged once. */
|
|
193
|
+
export async function runTemplateSeed({
|
|
194
|
+
raw,
|
|
195
|
+
templateService,
|
|
196
|
+
logger,
|
|
197
|
+
}: TemplateSeedDeps): Promise<TemplateSeedOutcome> {
|
|
198
|
+
const parsed = parseTemplateSeed(raw);
|
|
199
|
+
if (parsed.status === "unset") return parsed;
|
|
200
|
+
if (parsed.status === "invalid") {
|
|
201
|
+
logger.error(
|
|
202
|
+
`[template-seed] invalid ${TEMPLATE_SEED_ENV}, nothing applied (previously seeded items kept): ${parsed.error}`,
|
|
203
|
+
);
|
|
204
|
+
return parsed;
|
|
205
|
+
}
|
|
206
|
+
try {
|
|
207
|
+
const result = await templateService.applyManagedItems(
|
|
208
|
+
TEMPLATE_SEED_MANAGER,
|
|
209
|
+
parsed.seed.kinds,
|
|
210
|
+
parsed.seed.items,
|
|
211
|
+
);
|
|
212
|
+
const skipped = result.skipped.map((s) => `${s.kind}:${s.key}`).join(",");
|
|
213
|
+
logger.log(
|
|
214
|
+
`[template-seed] kinds=${parsed.seed.kinds.join(",") || "none"} created=${result.created} updated=${result.updated} unchanged=${result.unchanged} deleted=${result.deleted}${skipped ? ` skipped(hand-added)=${skipped}` : ""}`,
|
|
215
|
+
);
|
|
216
|
+
return { status: "applied", result };
|
|
217
|
+
} catch (err) {
|
|
218
|
+
const error = err instanceof Error ? err.message : String(err);
|
|
219
|
+
logger.error(`[template-seed] apply failed, nothing applied: ${error}`);
|
|
220
|
+
return { status: "failed", error };
|
|
221
|
+
}
|
|
222
|
+
}
|
|
@@ -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
|
+
});
|