@patronage/factory-ci 1.0.0-alpha.4 → 1.0.0-alpha.40
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/README.md +712 -10
- package/dist/.build-fingerprint.json +3 -0
- package/dist/alchemy/index.d.ts +1174 -0
- package/dist/alchemy/index.js +2142 -0
- package/dist/bundle-alchemy-entry-CT5hCphA.js +112 -0
- package/dist/execute-alchemy-entry-B397GSk5.d.ts +134 -0
- package/dist/execute-alchemy-entry-CZ7Knz4q.js +160 -0
- package/dist/index.d.ts +1205 -87
- package/dist/index.js +2752 -317
- package/package.json +28 -10
- package/src/actions.ts +13 -0
- package/src/alchemy/child-diagnostics.ts +148 -0
- package/src/alchemy/credential-preflight.ts +428 -0
- package/src/alchemy/destroy-postcondition.ts +103 -0
- package/src/alchemy/evaluate-stack.ts +153 -0
- package/src/alchemy/first-deploy-authorization.ts +194 -0
- package/src/alchemy/index.ts +144 -0
- package/src/alchemy/lifecycle-failure.ts +174 -0
- package/src/alchemy/lifecycle.ts +1330 -0
- package/src/alchemy/local-emulation.ts +89 -0
- package/src/alchemy/plan-effects.ts +510 -0
- package/src/alchemy/retained-identity.ts +248 -0
- package/src/alchemy/secret-name-policy.ts +96 -0
- package/src/alchemy/stage-policy.ts +269 -0
- package/src/alchemy/state-tree.ts +168 -0
- package/src/alchemy/url-implies-auth.ts +264 -0
- package/src/alchemy-baseline.ts +75 -0
- package/src/bundle-alchemy-entry.ts +5 -0
- package/src/candidate-impact-workflow.ts +110 -0
- package/src/candidate-lifecycle.ts +29 -0
- package/src/cursor-oidc.ts +33 -0
- package/src/execute-alchemy-entry.ts +128 -8
- package/src/factory-workflow.ts +83 -40
- package/src/github-app-token.ts +92 -18
- package/src/github-transport.ts +186 -0
- package/src/impact-demand-condition.ts +67 -0
- package/src/index.ts +174 -0
- package/src/lifecycle-contract-lane.ts +113 -0
- package/src/merge-freeze-job.ts +253 -0
- package/src/pinned-action.ts +30 -0
- package/src/pr-status-hud-workflow.ts +96 -0
- package/src/preview-cleanup-topology.ts +115 -0
- package/src/preview-proof-inventory.ts +1092 -0
- package/src/preview-proof-lifecycle.ts +328 -0
- package/src/preview-receipt-workflow.ts +83 -0
- package/src/production-impact-workflow.ts +181 -0
- package/src/proof-reuse-gate.ts +223 -48
- package/src/proof-reuse-presentation.ts +131 -0
- package/src/push-identity-workflow.ts +463 -0
- package/src/runnable-cli.ts +27 -0
- package/src/verify-runner-policy.ts +290 -0
- package/src/vitest-profile-reader.test.ts +208 -0
- package/src/vitest-profile-reader.ts +225 -0
- package/src/vitest-profile.ts +631 -0
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
const DEPOT_LABEL = "depot-ubuntu-24.04";
|
|
2
|
+
const HOSTED_LABEL = "ubuntu-latest";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Why a job runs where it does. The two Depot kinds share a label. They stay
|
|
6
|
+
* distinct so billed-rounding jobs and long compute jobs cannot be confused
|
|
7
|
+
* in the declaration table.
|
|
8
|
+
*
|
|
9
|
+
* `deploy-credentials` is legal to construct (HQ deploy).
|
|
10
|
+
* `assertVerifyRunnerPolicy` refuses it, because a Verify workflow has no
|
|
11
|
+
* Cloudflare production secret.
|
|
12
|
+
*/
|
|
13
|
+
export type FactoryRunnerKind =
|
|
14
|
+
| "sustained-compute"
|
|
15
|
+
| "rounding-tax"
|
|
16
|
+
| "app-token"
|
|
17
|
+
| "deploy-credentials";
|
|
18
|
+
|
|
19
|
+
export type FactoryRunnerHome = "depot" | "hosted";
|
|
20
|
+
|
|
21
|
+
export interface FactoryRunnerOverride {
|
|
22
|
+
readonly kind: "override";
|
|
23
|
+
readonly home: FactoryRunnerHome;
|
|
24
|
+
readonly why: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type FactoryRunnerDecision = FactoryRunnerKind | FactoryRunnerOverride;
|
|
28
|
+
|
|
29
|
+
export interface FactoryVerifyRunner {
|
|
30
|
+
readonly decision: FactoryRunnerDecision;
|
|
31
|
+
readonly home: FactoryRunnerHome;
|
|
32
|
+
readonly label: typeof DEPOT_LABEL | typeof HOSTED_LABEL;
|
|
33
|
+
readonly why?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type FactoryVerifyRunnerTable = Readonly<
|
|
37
|
+
Record<string, FactoryVerifyRunner>
|
|
38
|
+
>;
|
|
39
|
+
|
|
40
|
+
export interface FactoryVerifyRunnerPolicyInput {
|
|
41
|
+
readonly source: string;
|
|
42
|
+
readonly jobs: FactoryVerifyRunnerTable;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface FactoryVerifyRunnerMismatch {
|
|
46
|
+
readonly jobId: string;
|
|
47
|
+
readonly expected: string;
|
|
48
|
+
readonly actual: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface FactoryVerifyRunnerPolicyReport {
|
|
52
|
+
readonly ok: boolean;
|
|
53
|
+
readonly undeclared: readonly string[];
|
|
54
|
+
readonly missing: readonly string[];
|
|
55
|
+
readonly mismatches: readonly FactoryVerifyRunnerMismatch[];
|
|
56
|
+
readonly forbiddenKinds: readonly string[];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const isOverride = (
|
|
60
|
+
decision: FactoryRunnerDecision
|
|
61
|
+
): decision is FactoryRunnerOverride => typeof decision === "object";
|
|
62
|
+
|
|
63
|
+
const homeForKind = (kind: FactoryRunnerKind): FactoryRunnerHome => {
|
|
64
|
+
switch (kind) {
|
|
65
|
+
case "sustained-compute":
|
|
66
|
+
case "rounding-tax": {
|
|
67
|
+
return "depot";
|
|
68
|
+
}
|
|
69
|
+
case "app-token":
|
|
70
|
+
case "deploy-credentials": {
|
|
71
|
+
return "hosted";
|
|
72
|
+
}
|
|
73
|
+
default: {
|
|
74
|
+
const exhaustive: never = kind;
|
|
75
|
+
return exhaustive;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const labelForHome = (
|
|
81
|
+
home: FactoryRunnerHome
|
|
82
|
+
): typeof DEPOT_LABEL | typeof HOSTED_LABEL =>
|
|
83
|
+
home === "depot" ? DEPOT_LABEL : HOSTED_LABEL;
|
|
84
|
+
|
|
85
|
+
const assertOverrideWhy = (why: string): void => {
|
|
86
|
+
if (why.includes("\n") || why.includes("\r") || why.trim().length === 0) {
|
|
87
|
+
throw new Error(
|
|
88
|
+
"factoryVerifyRunner override requires a non-empty single-line why"
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export const factoryVerifyRunner = (
|
|
94
|
+
decision: FactoryRunnerDecision
|
|
95
|
+
): FactoryVerifyRunner => {
|
|
96
|
+
if (isOverride(decision)) {
|
|
97
|
+
assertOverrideWhy(decision.why);
|
|
98
|
+
return Object.freeze({
|
|
99
|
+
decision,
|
|
100
|
+
home: decision.home,
|
|
101
|
+
label: labelForHome(decision.home),
|
|
102
|
+
why: decision.why,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const home = homeForKind(decision);
|
|
107
|
+
return Object.freeze({
|
|
108
|
+
decision,
|
|
109
|
+
home,
|
|
110
|
+
label: labelForHome(home),
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const indentOf = (line: string): number =>
|
|
115
|
+
line.length - line.trimStart().length;
|
|
116
|
+
|
|
117
|
+
const unquote = (raw: string): string => {
|
|
118
|
+
const value = raw.trim();
|
|
119
|
+
if (value.startsWith("'") && value.endsWith("'") && value.length > 1) {
|
|
120
|
+
return value.slice(1, -1).replaceAll("''", "'");
|
|
121
|
+
}
|
|
122
|
+
if (value.startsWith('"') && value.endsWith('"') && value.length > 1) {
|
|
123
|
+
return value.slice(1, -1);
|
|
124
|
+
}
|
|
125
|
+
return value;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const JOB_ID = /^[\w-]+$/u;
|
|
129
|
+
const MATRIX_EXPRESSION = /\$\{\{\s*matrix\b/u;
|
|
130
|
+
|
|
131
|
+
const throwNonScalarRunsOn = (jobId: string): never => {
|
|
132
|
+
throw new Error(
|
|
133
|
+
`job ${jobId} uses a list, group, or matrix runs-on; Verify policy accepts a scalar label only`
|
|
134
|
+
);
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const verifyWorkflowJobRunners = (
|
|
138
|
+
yaml: string
|
|
139
|
+
): Readonly<Record<string, string>> => {
|
|
140
|
+
const lines = yaml.split("\n");
|
|
141
|
+
const jobsLine = lines.findIndex((line) => line.trim() === "jobs:");
|
|
142
|
+
if (jobsLine === -1) {
|
|
143
|
+
return {};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const jobsIndent = indentOf(lines[jobsLine]);
|
|
147
|
+
const jobIdIndent = jobsIndent + 2;
|
|
148
|
+
const jobKeyIndent = jobIdIndent + 2;
|
|
149
|
+
const runners: Record<string, string> = {};
|
|
150
|
+
|
|
151
|
+
for (let index = jobsLine + 1; index < lines.length; index += 1) {
|
|
152
|
+
const line = lines[index];
|
|
153
|
+
if (line.trim().length === 0) {
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
const indent = indentOf(line);
|
|
157
|
+
if (indent <= jobsIndent) {
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
if (indent !== jobIdIndent) {
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const trimmed = line.trim();
|
|
165
|
+
if (!trimmed.endsWith(":") || trimmed.includes(" ")) {
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
const jobId = trimmed.slice(0, -1);
|
|
169
|
+
if (!JOB_ID.test(jobId)) {
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
let runsOn: string | undefined;
|
|
174
|
+
for (let cursor = index + 1; cursor < lines.length; cursor += 1) {
|
|
175
|
+
const candidate = lines[cursor];
|
|
176
|
+
if (candidate.trim().length === 0) {
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
const candidateIndent = indentOf(candidate);
|
|
180
|
+
if (candidateIndent <= jobIdIndent) {
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
if (candidateIndent !== jobKeyIndent) {
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
const rest = candidate.trimStart();
|
|
187
|
+
if (!rest.startsWith("runs-on:")) {
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
const inline = rest.slice("runs-on:".length).trim();
|
|
191
|
+
if (inline.length === 0) {
|
|
192
|
+
throwNonScalarRunsOn(jobId);
|
|
193
|
+
}
|
|
194
|
+
if (inline.startsWith("[") || inline.startsWith("{")) {
|
|
195
|
+
throwNonScalarRunsOn(jobId);
|
|
196
|
+
}
|
|
197
|
+
const label = unquote(inline);
|
|
198
|
+
if (MATRIX_EXPRESSION.test(label)) {
|
|
199
|
+
throwNonScalarRunsOn(jobId);
|
|
200
|
+
}
|
|
201
|
+
runsOn = label;
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
if (runsOn === undefined) {
|
|
205
|
+
throw new Error(`job ${jobId} has no runs-on`);
|
|
206
|
+
}
|
|
207
|
+
runners[jobId] = runsOn;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return runners;
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
const isDeployCredentials = (runner: FactoryVerifyRunner): boolean =>
|
|
214
|
+
runner.decision === "deploy-credentials";
|
|
215
|
+
|
|
216
|
+
export const verifyRunnerPolicy = (
|
|
217
|
+
yaml: string,
|
|
218
|
+
input: FactoryVerifyRunnerPolicyInput
|
|
219
|
+
): FactoryVerifyRunnerPolicyReport => {
|
|
220
|
+
const actual = verifyWorkflowJobRunners(yaml);
|
|
221
|
+
const declared = Object.keys(input.jobs);
|
|
222
|
+
const emitted = Object.keys(actual);
|
|
223
|
+
|
|
224
|
+
const undeclared = emitted
|
|
225
|
+
.filter((jobId) => input.jobs[jobId] === undefined)
|
|
226
|
+
.toSorted();
|
|
227
|
+
const missing = declared
|
|
228
|
+
.filter((jobId) => actual[jobId] === undefined)
|
|
229
|
+
.toSorted();
|
|
230
|
+
const mismatches = declared
|
|
231
|
+
.filter(
|
|
232
|
+
(jobId) =>
|
|
233
|
+
actual[jobId] !== undefined && actual[jobId] !== input.jobs[jobId].label
|
|
234
|
+
)
|
|
235
|
+
.toSorted()
|
|
236
|
+
.map((jobId) => ({
|
|
237
|
+
actual: actual[jobId],
|
|
238
|
+
expected: input.jobs[jobId].label,
|
|
239
|
+
jobId,
|
|
240
|
+
}));
|
|
241
|
+
const forbiddenKinds = declared
|
|
242
|
+
.filter((jobId) => isDeployCredentials(input.jobs[jobId]))
|
|
243
|
+
.toSorted();
|
|
244
|
+
|
|
245
|
+
return Object.freeze({
|
|
246
|
+
forbiddenKinds,
|
|
247
|
+
mismatches,
|
|
248
|
+
missing,
|
|
249
|
+
ok:
|
|
250
|
+
undeclared.length === 0 &&
|
|
251
|
+
missing.length === 0 &&
|
|
252
|
+
mismatches.length === 0 &&
|
|
253
|
+
forbiddenKinds.length === 0,
|
|
254
|
+
undeclared,
|
|
255
|
+
});
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
export const assertVerifyRunnerPolicy = (
|
|
259
|
+
yaml: string,
|
|
260
|
+
input: FactoryVerifyRunnerPolicyInput
|
|
261
|
+
): FactoryVerifyRunnerPolicyReport => {
|
|
262
|
+
const report = verifyRunnerPolicy(yaml, input);
|
|
263
|
+
if (report.ok) {
|
|
264
|
+
return report;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const details: string[] = [];
|
|
268
|
+
if (report.undeclared.length > 0) {
|
|
269
|
+
details.push(`undeclared jobs: ${report.undeclared.join(", ")}`);
|
|
270
|
+
}
|
|
271
|
+
if (report.missing.length > 0) {
|
|
272
|
+
details.push(`missing from YAML: ${report.missing.join(", ")}`);
|
|
273
|
+
}
|
|
274
|
+
for (const mismatch of report.mismatches) {
|
|
275
|
+
details.push(
|
|
276
|
+
`${mismatch.jobId} runs-on ${mismatch.actual}, expected ${mismatch.expected}`
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
if (report.forbiddenKinds.length > 0) {
|
|
280
|
+
details.push(
|
|
281
|
+
`deploy-credentials is illegal inside Verify: ${report.forbiddenKinds.join(", ")}`
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
throw new Error(
|
|
286
|
+
`${input.source} Verify runner policy failed:\n${details
|
|
287
|
+
.map((detail) => ` - ${detail}`)
|
|
288
|
+
.join("\n")}`
|
|
289
|
+
);
|
|
290
|
+
};
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { readVitestProfileDocument } from "./vitest-profile-reader.ts";
|
|
4
|
+
import type { VitestProfile } from "./vitest-profile.ts";
|
|
5
|
+
|
|
6
|
+
const durations = {
|
|
7
|
+
maximum: 16_200,
|
|
8
|
+
mean: 15_800,
|
|
9
|
+
median: 15_700,
|
|
10
|
+
minimum: 15_300,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/** A document shaped exactly as `runVitestProfile` writes it. */
|
|
14
|
+
const validProfile = (): VitestProfile => ({
|
|
15
|
+
command: ["vitest", "run", "--reporter=json", "--maxWorkers=2"],
|
|
16
|
+
endedAt: "2026-08-06T12:01:00.000Z",
|
|
17
|
+
environment: {
|
|
18
|
+
arch: "x64",
|
|
19
|
+
availableParallelism: 4,
|
|
20
|
+
cpuCount: 4,
|
|
21
|
+
cpuModel: "AMD EPYC 9R45",
|
|
22
|
+
gitDirty: false,
|
|
23
|
+
gitHead: "0123456789abcdef0123456789abcdef01234567",
|
|
24
|
+
node: "v24.0.0",
|
|
25
|
+
osRelease: "6.8.0",
|
|
26
|
+
platform: "linux",
|
|
27
|
+
totalMemoryBytes: 16_000_000_000,
|
|
28
|
+
vitest: "3.0.0",
|
|
29
|
+
},
|
|
30
|
+
options: { maxWorkers: 2, samples: 3, slowLimit: 20 },
|
|
31
|
+
rawReportDirectory: "/tmp/profile.raw/abc",
|
|
32
|
+
runs: [
|
|
33
|
+
{
|
|
34
|
+
counts: {
|
|
35
|
+
failed: 0,
|
|
36
|
+
passed: 900,
|
|
37
|
+
pending: 0,
|
|
38
|
+
suites: 80,
|
|
39
|
+
tests: 900,
|
|
40
|
+
todo: 0,
|
|
41
|
+
},
|
|
42
|
+
durationMs: 15_300,
|
|
43
|
+
endedAt: "2026-08-06T12:00:20.000Z",
|
|
44
|
+
exitCode: 0,
|
|
45
|
+
failure: null,
|
|
46
|
+
files: [{ durationMs: 900, path: "src/slow.test.ts", status: "passed" }],
|
|
47
|
+
reportAvailable: true,
|
|
48
|
+
sample: 1,
|
|
49
|
+
startedAt: "2026-08-06T12:00:00.000Z",
|
|
50
|
+
tests: [
|
|
51
|
+
{
|
|
52
|
+
durationMs: 450,
|
|
53
|
+
file: "src/slow.test.ts",
|
|
54
|
+
name: "slow case",
|
|
55
|
+
status: "passed",
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
schemaVersion: 1,
|
|
61
|
+
startedAt: "2026-08-06T12:00:00.000Z",
|
|
62
|
+
summary: {
|
|
63
|
+
durationMs: { ...durations },
|
|
64
|
+
slowFiles: [
|
|
65
|
+
{ durationMs: { ...durations }, path: "src/slow.test.ts", samples: 3 },
|
|
66
|
+
],
|
|
67
|
+
slowTests: [
|
|
68
|
+
{
|
|
69
|
+
durationMs: { ...durations },
|
|
70
|
+
file: "src/slow.test.ts",
|
|
71
|
+
name: "slow case",
|
|
72
|
+
samples: 3,
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
},
|
|
76
|
+
tool: "factory-ci-vitest-profile",
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe("readVitestProfileDocument", () => {
|
|
80
|
+
it("accepts a document the writer emitted", () => {
|
|
81
|
+
const result = readVitestProfileDocument(validProfile());
|
|
82
|
+
|
|
83
|
+
expect(result.kind).toBe("profile");
|
|
84
|
+
if (result.kind === "profile") {
|
|
85
|
+
expect(result.profile.environment.cpuModel).toBe("AMD EPYC 9R45");
|
|
86
|
+
expect(result.profile.summary.durationMs.median).toBe(15_700);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("names the tool mismatch instead of guessing", () => {
|
|
91
|
+
const result = readVitestProfileDocument({
|
|
92
|
+
...validProfile(),
|
|
93
|
+
tool: "someone-elses-artifact",
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
expect(result).toEqual({
|
|
97
|
+
kind: "unrecognized",
|
|
98
|
+
reason:
|
|
99
|
+
'tool is "someone-elses-artifact" rather than "factory-ci-vitest-profile"',
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("refuses a future schema version rather than misreading it", () => {
|
|
104
|
+
const result = readVitestProfileDocument({
|
|
105
|
+
...validProfile(),
|
|
106
|
+
schemaVersion: 2,
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
expect(result).toEqual({
|
|
110
|
+
kind: "unrecognized",
|
|
111
|
+
reason: "schemaVersion is 2 rather than 1",
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it("refuses a document whose environment lost the cpuModel field", () => {
|
|
116
|
+
const document = validProfile() as unknown as {
|
|
117
|
+
environment: Record<string, unknown>;
|
|
118
|
+
};
|
|
119
|
+
delete document.environment.cpuModel;
|
|
120
|
+
|
|
121
|
+
expect(readVitestProfileDocument(document)).toEqual({
|
|
122
|
+
kind: "unrecognized",
|
|
123
|
+
reason: "environment.cpuModel is neither a string nor null",
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("refuses a run without a finite duration", () => {
|
|
128
|
+
const document = validProfile();
|
|
129
|
+
(document.runs[0] as unknown as Record<string, unknown>).durationMs =
|
|
130
|
+
"fast";
|
|
131
|
+
|
|
132
|
+
expect(readVitestProfileDocument(document)).toEqual({
|
|
133
|
+
kind: "unrecognized",
|
|
134
|
+
reason: "runs[0].durationMs is not a finite number",
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("refuses a summary without duration statistics", () => {
|
|
139
|
+
const document = validProfile() as unknown as {
|
|
140
|
+
summary: { durationMs: Record<string, unknown> };
|
|
141
|
+
};
|
|
142
|
+
delete document.summary.durationMs.median;
|
|
143
|
+
|
|
144
|
+
expect(readVitestProfileDocument(document)).toEqual({
|
|
145
|
+
kind: "unrecognized",
|
|
146
|
+
reason: "summary.durationMs.median is not a finite number",
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it("refuses empty counts rather than serving undefined fields", () => {
|
|
151
|
+
const document = validProfile();
|
|
152
|
+
(document.runs[0] as unknown as Record<string, unknown>).counts = {};
|
|
153
|
+
|
|
154
|
+
expect(readVitestProfileDocument(document)).toEqual({
|
|
155
|
+
kind: "unrecognized",
|
|
156
|
+
reason: "runs[0].counts.failed is not a finite number",
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it("refuses a null slowFiles entry rather than crashing projection", () => {
|
|
161
|
+
const document = validProfile() as unknown as {
|
|
162
|
+
summary: { slowFiles: unknown[] };
|
|
163
|
+
};
|
|
164
|
+
document.summary.slowFiles = [null];
|
|
165
|
+
|
|
166
|
+
expect(readVitestProfileDocument(document)).toEqual({
|
|
167
|
+
kind: "unrecognized",
|
|
168
|
+
reason: "summary.slowFiles[0] is not an object",
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("refuses a slow test whose duration summary is incomplete", () => {
|
|
173
|
+
const document = validProfile() as unknown as {
|
|
174
|
+
summary: { slowTests: { durationMs: Record<string, unknown> }[] };
|
|
175
|
+
};
|
|
176
|
+
const [slowTest] = document.summary.slowTests;
|
|
177
|
+
if (slowTest) {
|
|
178
|
+
delete slowTest.durationMs.median;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
expect(readVitestProfileDocument(document)).toEqual({
|
|
182
|
+
kind: "unrecognized",
|
|
183
|
+
reason: "summary.slowTests[0].durationMs.median is not a finite number",
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it("refuses a slow file without a path string", () => {
|
|
188
|
+
const document = validProfile() as unknown as {
|
|
189
|
+
summary: { slowFiles: Record<string, unknown>[] };
|
|
190
|
+
};
|
|
191
|
+
const [slowFile] = document.summary.slowFiles;
|
|
192
|
+
if (slowFile) {
|
|
193
|
+
delete slowFile.path;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
expect(readVitestProfileDocument(document)).toEqual({
|
|
197
|
+
kind: "unrecognized",
|
|
198
|
+
reason: "summary.slowFiles[0].path is not a string",
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it("refuses non-object input", () => {
|
|
203
|
+
expect(readVitestProfileDocument(null)).toEqual({
|
|
204
|
+
kind: "unrecognized",
|
|
205
|
+
reason: "the document is not an object",
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
});
|