@antelopejs/dms 0.18.0 → 0.18.1
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/CHANGELOG.md +31 -0
- package/README.md +3 -3
- package/bin/control/backend-records.test.mjs +276 -0
- package/bin/control/backend.mjs +212 -0
- package/bin/control/backend.test.mjs +325 -0
- package/bin/control/base.mjs +3 -7
- package/bin/control/browser-client.mjs +6 -4
- package/bin/control/browser.mjs +173 -36
- package/bin/control/build-cache.mjs +394 -0
- package/bin/control/build-cache.test.mjs +270 -0
- package/bin/control/build-inputs.mjs +172 -0
- package/bin/control/build-key-refusals.test.mjs +138 -0
- package/bin/control/build-key.mjs +479 -0
- package/bin/control/build-key.test.mjs +392 -0
- package/bin/control/build-layout.test.mjs +314 -0
- package/bin/control/commands-stack.mjs +46 -6
- package/bin/control/commands-verify.mjs +9 -2
- package/bin/control/doctor.mjs +87 -16
- package/bin/control/forwarder.mjs +86 -0
- package/bin/control/forwarder.test.mjs +141 -0
- package/bin/control/frontend-check.mjs +54 -0
- package/bin/control/frontend-workspace.mjs +150 -0
- package/bin/control/frontend-workspace.test.mjs +133 -0
- package/bin/control/helpers/env.mjs +21 -0
- package/bin/control/helpers/evidence.mjs +13 -0
- package/bin/control/helpers/fake-run.mjs +290 -0
- package/bin/control/helpers/key-fixture.mjs +82 -0
- package/bin/control/helpers/pids.mjs +27 -0
- package/bin/control/helpers/repo.mjs +13 -0
- package/bin/control/helpers/tree.mjs +40 -0
- package/bin/control/identity.mjs +238 -0
- package/bin/control/identity.test.mjs +166 -0
- package/bin/control/journey.mjs +64 -16
- package/bin/control/journey.test.mjs +60 -2
- package/bin/control/namespaces.test.mjs +211 -0
- package/bin/control/options.mjs +2 -0
- package/bin/control/pid-guard.test.mjs +202 -0
- package/bin/control/prepared-workspace.mjs +20 -0
- package/bin/control/processes.mjs +122 -33
- package/bin/control/processes.test.mjs +255 -0
- package/bin/control/renderer.test.mjs +2 -1
- package/bin/control/run-copy.mjs +77 -0
- package/bin/control/run-state.mjs +142 -16
- package/bin/control/stack.mjs +259 -210
- package/bin/control/tab.mjs +13 -6
- package/bin/control/tab.test.mjs +444 -0
- package/bin/control/timing.mjs +244 -0
- package/bin/control/timing.test.mjs +197 -0
- package/bin/control/verify/decode.mjs +34 -21
- package/bin/control/verify/decode.test.mjs +39 -0
- package/bin/control/verify/doors.test.mjs +2 -0
- package/bin/control/verify/map.mjs +57 -7
- package/bin/control/verify/map.test.mjs +264 -0
- package/bin/control/verify/skill.mjs +12 -3
- package/bin/control/verify/types.mjs +2 -2
- package/bin/control/verify/verdict.mjs +37 -7
- package/bin/dms-control.mjs +14 -6
- package/frontend-vue/layers/dms-layout/app/components/layout/DashboardSearch.vue +24 -1
- package/package.json +1 -1
- package/skills/dms-project/SKILL.md +6 -3
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { appendFileSync, existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { isBoolean, isNumber, isString, objectOf } from "./json.mjs";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {{ feature?: string, journey?: string, step?: string, command?: string, action?: string, check?: string }} TimingDetail What a phase names besides its own name
|
|
7
|
+
* @typedef {{ phase: string, ms: number, startedAt: string, ok: boolean } & TimingDetail} TimingEntry One measured phase, as `timings.jsonl` holds it
|
|
8
|
+
* @typedef {{ name: string, count: number, totalMs: number, medianMs: number, maxMs: number }} TimingRow
|
|
9
|
+
* @typedef {{ rows: TimingRow[], totalMs: number }} TimingSummary
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/** The file of a run's evidence that every process appends its phases to, one JSON object per line. */
|
|
13
|
+
export const TIMINGS_FILE = "timings.jsonl";
|
|
14
|
+
|
|
15
|
+
const MS_PER_SECOND = 1000;
|
|
16
|
+
const TOP_LEVEL = new Set(["prepare", "up", "journey", "formal"]);
|
|
17
|
+
|
|
18
|
+
const isTimingEntry = objectOf(
|
|
19
|
+
{ phase: isString, ms: isNumber, startedAt: isString, ok: isBoolean },
|
|
20
|
+
{
|
|
21
|
+
feature: isString,
|
|
22
|
+
journey: isString,
|
|
23
|
+
step: isString,
|
|
24
|
+
command: isString,
|
|
25
|
+
action: isString,
|
|
26
|
+
check: isString,
|
|
27
|
+
},
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Starts a clock.
|
|
32
|
+
*
|
|
33
|
+
* @returns {() => { ms: number, startedAt: string }} A function that reads the whole milliseconds elapsed and when the clock started
|
|
34
|
+
*/
|
|
35
|
+
export function stopwatch() {
|
|
36
|
+
const startedAt = new Date().toISOString();
|
|
37
|
+
const began = performance.now();
|
|
38
|
+
return () => ({ ms: Math.round(performance.now() - began), startedAt });
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Appends one entry to the run's `timings.jsonl`. Separate processes append
|
|
43
|
+
* to it, so no write reads the file first.
|
|
44
|
+
*
|
|
45
|
+
* @param {{ evidence: string }} state The run
|
|
46
|
+
* @param {TimingEntry} entry The entry
|
|
47
|
+
*/
|
|
48
|
+
export function appendTiming(state, entry) {
|
|
49
|
+
appendFileSync(
|
|
50
|
+
join(state.evidence, TIMINGS_FILE),
|
|
51
|
+
`${JSON.stringify(entry)}\n`,
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Appends the entry of a phase that was measured with {@link stopwatch}.
|
|
57
|
+
*
|
|
58
|
+
* @param {{ evidence: string }} state The run
|
|
59
|
+
* @param {string} phase The phase name
|
|
60
|
+
* @param {{ ms: number, startedAt: string }} lap What the stopwatch read
|
|
61
|
+
* @param {boolean} ok Whether the phase succeeded
|
|
62
|
+
* @param {TimingDetail} [detail] What the phase names
|
|
63
|
+
*/
|
|
64
|
+
export function recordTiming(state, phase, lap, ok, detail = {}) {
|
|
65
|
+
appendTiming(state, {
|
|
66
|
+
phase,
|
|
67
|
+
ms: lap.ms,
|
|
68
|
+
startedAt: lap.startedAt,
|
|
69
|
+
ok,
|
|
70
|
+
...detail,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Runs `action` and records how long it took, also when it throws (then with
|
|
76
|
+
* `ok: false`, and the error is rethrown).
|
|
77
|
+
*
|
|
78
|
+
* @template T
|
|
79
|
+
* @param {{ evidence: string }} state The run
|
|
80
|
+
* @param {string} phase The phase name
|
|
81
|
+
* @param {() => T | Promise<T>} action What to measure
|
|
82
|
+
* @param {TimingDetail} [detail] What the phase names
|
|
83
|
+
* @returns {Promise<T>} What `action` returned
|
|
84
|
+
*/
|
|
85
|
+
export async function timed(state, phase, action, detail) {
|
|
86
|
+
const stop = stopwatch();
|
|
87
|
+
let ok = false;
|
|
88
|
+
try {
|
|
89
|
+
const result = await action();
|
|
90
|
+
ok = true;
|
|
91
|
+
return result;
|
|
92
|
+
} finally {
|
|
93
|
+
recordTiming(state, phase, stop(), ok, detail);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* @param {string} line A line of `timings.jsonl`
|
|
99
|
+
* @returns {TimingEntry[]} The entry, none for a line that holds no entry
|
|
100
|
+
*/
|
|
101
|
+
function entryOf(line) {
|
|
102
|
+
try {
|
|
103
|
+
/** @type {unknown} */
|
|
104
|
+
const parsed = JSON.parse(line);
|
|
105
|
+
return isTimingEntry(parsed) ? [parsed] : [];
|
|
106
|
+
} catch {
|
|
107
|
+
return [];
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* The entries a run recorded, in the order they were written. A run with no
|
|
113
|
+
* `timings.jsonl`, and any line that is no entry, give none.
|
|
114
|
+
*
|
|
115
|
+
* @param {string} evidence The run's evidence folder
|
|
116
|
+
* @returns {TimingEntry[]} The entries
|
|
117
|
+
*/
|
|
118
|
+
export function readTimings(evidence) {
|
|
119
|
+
const file = join(evidence, TIMINGS_FILE);
|
|
120
|
+
if (!existsSync(file)) return [];
|
|
121
|
+
return readFileSync(file, "utf8").split("\n").flatMap(entryOf);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* @param {TimingEntry} entry An entry
|
|
126
|
+
* @returns {string} Its row name: the phase, or for a journey `journey <feature>/<id>`
|
|
127
|
+
*/
|
|
128
|
+
function rowName(entry) {
|
|
129
|
+
return entry.phase === "journey" && entry.feature && entry.journey
|
|
130
|
+
? `journey ${entry.feature}/${entry.journey}`
|
|
131
|
+
: entry.phase;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* @param {number[]} sorted Durations, ascending and not empty
|
|
136
|
+
* @returns {number} Their median, the mean of the two middle ones when the count is even
|
|
137
|
+
*/
|
|
138
|
+
function median(sorted) {
|
|
139
|
+
const middle = Math.floor(sorted.length / 2);
|
|
140
|
+
return sorted.length % 2 === 1
|
|
141
|
+
? sorted[middle]
|
|
142
|
+
: Math.round((sorted[middle - 1] + sorted[middle]) / 2);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* One row per phase name, a journey counting under its own name, ordered by
|
|
147
|
+
* when the phase first started, and the total: the sum of the top-level
|
|
148
|
+
* phases (`prepare`, `up`, each `journey`, `formal`), which contain the others.
|
|
149
|
+
*
|
|
150
|
+
* @param {TimingEntry[]} entries The entries of a run
|
|
151
|
+
* @returns {TimingSummary} The rows and the total
|
|
152
|
+
*/
|
|
153
|
+
export function summarize(entries) {
|
|
154
|
+
/** @type {Map<string, TimingEntry[]>} */
|
|
155
|
+
const groups = new Map();
|
|
156
|
+
for (const entry of entries) {
|
|
157
|
+
const name = rowName(entry);
|
|
158
|
+
groups.set(name, [...(groups.get(name) ?? []), entry]);
|
|
159
|
+
}
|
|
160
|
+
/** @type {(group: TimingEntry[]) => string} */
|
|
161
|
+
const firstStart = (group) => group.map((entry) => entry.startedAt).sort()[0];
|
|
162
|
+
const rows = [...groups]
|
|
163
|
+
.sort(([, a], [, b]) => firstStart(a).localeCompare(firstStart(b)))
|
|
164
|
+
.map(([name, group]) => {
|
|
165
|
+
const durations = group.map((entry) => entry.ms).sort((a, b) => a - b);
|
|
166
|
+
return {
|
|
167
|
+
name,
|
|
168
|
+
count: group.length,
|
|
169
|
+
totalMs: durations.reduce((sum, ms) => sum + ms, 0),
|
|
170
|
+
medianMs: median(durations),
|
|
171
|
+
maxMs: durations[durations.length - 1],
|
|
172
|
+
};
|
|
173
|
+
});
|
|
174
|
+
const totalMs = entries
|
|
175
|
+
.filter((entry) => TOP_LEVEL.has(entry.phase))
|
|
176
|
+
.reduce((sum, entry) => sum + entry.ms, 0);
|
|
177
|
+
return { rows, totalMs };
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* @param {number} ms A duration
|
|
182
|
+
* @returns {string} It in seconds with one decimal
|
|
183
|
+
*/
|
|
184
|
+
export function formatSeconds(ms) {
|
|
185
|
+
return (ms / MS_PER_SECOND).toFixed(1);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* @param {TimingSummary} summary The summary
|
|
190
|
+
* @returns {string[][]} The header, a row per phase and the total, as cells
|
|
191
|
+
*/
|
|
192
|
+
function cellsOf(summary) {
|
|
193
|
+
return [
|
|
194
|
+
["phase", "count", "total s", "median ms", "max ms"],
|
|
195
|
+
...summary.rows.map((row) => [
|
|
196
|
+
row.name,
|
|
197
|
+
String(row.count),
|
|
198
|
+
formatSeconds(row.totalMs),
|
|
199
|
+
String(row.medianMs),
|
|
200
|
+
String(row.maxMs),
|
|
201
|
+
]),
|
|
202
|
+
["total", "", formatSeconds(summary.totalMs), "", ""],
|
|
203
|
+
];
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* The summary as the plain table `dms-control timings` prints.
|
|
208
|
+
*
|
|
209
|
+
* @param {TimingSummary} summary The summary
|
|
210
|
+
* @returns {string} The table
|
|
211
|
+
*/
|
|
212
|
+
export function formatTimings(summary) {
|
|
213
|
+
const cells = cellsOf(summary);
|
|
214
|
+
const widths = cells[0].map((_, column) =>
|
|
215
|
+
Math.max(...cells.map((row) => row[column].length)),
|
|
216
|
+
);
|
|
217
|
+
return cells
|
|
218
|
+
.map((row) =>
|
|
219
|
+
row
|
|
220
|
+
.map((cell, column) =>
|
|
221
|
+
column === 0
|
|
222
|
+
? cell.padEnd(widths[column])
|
|
223
|
+
: cell.padStart(widths[column]),
|
|
224
|
+
)
|
|
225
|
+
.join(" ")
|
|
226
|
+
.trimEnd(),
|
|
227
|
+
)
|
|
228
|
+
.join("\n");
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* The summary as the Markdown table of the verdict's Timing section.
|
|
233
|
+
*
|
|
234
|
+
* @param {TimingSummary} summary The summary
|
|
235
|
+
* @returns {string[]} The lines of the table
|
|
236
|
+
*/
|
|
237
|
+
export function markdownTimings(summary) {
|
|
238
|
+
const [header, ...body] = cellsOf(summary);
|
|
239
|
+
return [
|
|
240
|
+
`| ${header.join(" | ")} |`,
|
|
241
|
+
`|${header.map(() => "---").join("|")}|`,
|
|
242
|
+
...body.map((row) => `| ${row.join(" | ")} |`),
|
|
243
|
+
];
|
|
244
|
+
}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import test from "node:test";
|
|
6
|
+
import {
|
|
7
|
+
formatTimings,
|
|
8
|
+
markdownTimings,
|
|
9
|
+
readTimings,
|
|
10
|
+
summarize,
|
|
11
|
+
timed,
|
|
12
|
+
TIMINGS_FILE,
|
|
13
|
+
} from "./timing.mjs";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @param {import("node:test").TestContext} t The test
|
|
17
|
+
* @returns {{ evidence: string }} A run whose evidence folder is removed when the test ends
|
|
18
|
+
*/
|
|
19
|
+
function scratchRun(t) {
|
|
20
|
+
const evidence = mkdtempSync(join(tmpdir(), "dms-control-timing-test-"));
|
|
21
|
+
t.after(() => rmSync(evidence, { recursive: true, force: true }));
|
|
22
|
+
return { evidence };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @param {string} phase The phase
|
|
27
|
+
* @param {number} ms Its duration
|
|
28
|
+
* @param {string} second The second of the minute it started in
|
|
29
|
+
* @param {import("./timing.mjs").TimingDetail} [detail] What it names
|
|
30
|
+
* @returns {import("./timing.mjs").TimingEntry} The entry
|
|
31
|
+
*/
|
|
32
|
+
function entry(phase, ms, second, detail = {}) {
|
|
33
|
+
return {
|
|
34
|
+
phase,
|
|
35
|
+
ms,
|
|
36
|
+
startedAt: `2026-11-07T10:00:${second}.000Z`,
|
|
37
|
+
ok: true,
|
|
38
|
+
...detail,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
await test("each journey is its own row, so two journeys of a feature are not merged", () => {
|
|
43
|
+
const { rows } = summarize([
|
|
44
|
+
entry("journey", 4000, "10", { feature: "auth", journey: "login" }),
|
|
45
|
+
entry("journey", 9000, "20", { feature: "auth", journey: "invite" }),
|
|
46
|
+
]);
|
|
47
|
+
assert.deepEqual(
|
|
48
|
+
rows.map((row) => [row.name, row.count, row.totalMs]),
|
|
49
|
+
[
|
|
50
|
+
["journey auth/login", 1, 4000],
|
|
51
|
+
["journey auth/invite", 1, 9000],
|
|
52
|
+
],
|
|
53
|
+
);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
await test("the total sums the top-level phases and not the phases they contain", () => {
|
|
57
|
+
const { totalMs } = summarize([
|
|
58
|
+
entry("prepare", 1000, "00"),
|
|
59
|
+
entry("up", 5000, "01"),
|
|
60
|
+
entry("mongod", 2000, "02"),
|
|
61
|
+
entry("journey", 3000, "10", { feature: "auth", journey: "login" }),
|
|
62
|
+
entry("journey-run", 2500, "11", { feature: "auth", journey: "login" }),
|
|
63
|
+
entry("backend-stop", 700, "12"),
|
|
64
|
+
entry("formal", 400, "30", { check: "formal-add" }),
|
|
65
|
+
entry("browser-command", 900, "40", { action: "snapshot" }),
|
|
66
|
+
]);
|
|
67
|
+
assert.equal(totalMs, 1000 + 5000 + 3000 + 400);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
await test("a phase run several times has its count, total, median and maximum", () => {
|
|
71
|
+
const { rows } = summarize([
|
|
72
|
+
entry("aria", 30, "01"),
|
|
73
|
+
entry("aria", 10, "02"),
|
|
74
|
+
entry("aria", 200, "03"),
|
|
75
|
+
]);
|
|
76
|
+
assert.deepEqual(rows, [
|
|
77
|
+
{ name: "aria", count: 3, totalMs: 240, medianMs: 30, maxMs: 200 },
|
|
78
|
+
]);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
await test("the median of an even count is the mean of the two middle durations", () => {
|
|
82
|
+
const { rows } = summarize([
|
|
83
|
+
entry("screenshot", 400, "01"),
|
|
84
|
+
entry("screenshot", 100, "02"),
|
|
85
|
+
entry("screenshot", 300, "03"),
|
|
86
|
+
entry("screenshot", 200, "04"),
|
|
87
|
+
]);
|
|
88
|
+
assert.equal(rows[0].medianMs, 250);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
await test("rows follow when each phase first started, not the order its entries were written", () => {
|
|
92
|
+
const { rows } = summarize([
|
|
93
|
+
entry("mongod", 100, "02"),
|
|
94
|
+
entry("up", 900, "01"),
|
|
95
|
+
entry("prepare", 5000, "00"),
|
|
96
|
+
]);
|
|
97
|
+
assert.deepEqual(
|
|
98
|
+
rows.map((row) => row.name),
|
|
99
|
+
["prepare", "up", "mongod"],
|
|
100
|
+
);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
await test("an empty run has no rows and a zero total", () => {
|
|
104
|
+
assert.deepEqual(summarize([]), { rows: [], totalMs: 0 });
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
await test("the plain table aligns its columns and ends with the total line", () => {
|
|
108
|
+
const summary = summarize([
|
|
109
|
+
entry("up", 123_400, "00"),
|
|
110
|
+
entry("aria", 20, "10"),
|
|
111
|
+
entry("aria", 80, "11"),
|
|
112
|
+
]);
|
|
113
|
+
assert.equal(
|
|
114
|
+
formatTimings(summary),
|
|
115
|
+
[
|
|
116
|
+
"phase count total s median ms max ms",
|
|
117
|
+
"up 1 123.4 123400 123400",
|
|
118
|
+
"aria 2 0.1 50 80",
|
|
119
|
+
"total 123.4",
|
|
120
|
+
].join("\n"),
|
|
121
|
+
);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
await test("the Markdown table has the same cells as the plain one", () => {
|
|
125
|
+
const summary = summarize([entry("up", 2000, "00")]);
|
|
126
|
+
assert.deepEqual(markdownTimings(summary), [
|
|
127
|
+
"| phase | count | total s | median ms | max ms |",
|
|
128
|
+
"|---|---|---|---|---|",
|
|
129
|
+
"| up | 1 | 2.0 | 2000 | 2000 |",
|
|
130
|
+
"| total | | 2.0 | | |",
|
|
131
|
+
]);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
await test("timed records the phase and returns what the action returned", async (t) => {
|
|
135
|
+
const run = scratchRun(t);
|
|
136
|
+
const value = await timed(run, "mail", () => 7, { step: "01-open" });
|
|
137
|
+
const [recorded] = readTimings(run.evidence);
|
|
138
|
+
assert.equal(value, 7);
|
|
139
|
+
assert.equal(recorded.phase, "mail");
|
|
140
|
+
assert.equal(recorded.ok, true);
|
|
141
|
+
assert.equal(recorded.step, "01-open");
|
|
142
|
+
assert.equal(Number.isInteger(recorded.ms), true);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
await test("timed records a failing action with ok false and rethrows its error", async (t) => {
|
|
146
|
+
const run = scratchRun(t);
|
|
147
|
+
await assert.rejects(
|
|
148
|
+
timed(run, "project-build", () => Promise.reject(new Error("boom"))),
|
|
149
|
+
/boom/,
|
|
150
|
+
);
|
|
151
|
+
const [recorded] = readTimings(run.evidence);
|
|
152
|
+
assert.equal(recorded.phase, "project-build");
|
|
153
|
+
assert.equal(recorded.ok, false);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
await test("timed records a synchronous throw too", async (t) => {
|
|
157
|
+
const run = scratchRun(t);
|
|
158
|
+
await assert.rejects(
|
|
159
|
+
timed(run, "layout", () => {
|
|
160
|
+
throw new Error("no space");
|
|
161
|
+
}),
|
|
162
|
+
/no space/,
|
|
163
|
+
);
|
|
164
|
+
assert.equal(readTimings(run.evidence)[0].ok, false);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
await test("entries appended one after another are all read back, none replaced", async (t) => {
|
|
168
|
+
const run = scratchRun(t);
|
|
169
|
+
await timed(run, "up", () => undefined);
|
|
170
|
+
await timed(run, "journey", () => undefined, { feature: "a", journey: "b" });
|
|
171
|
+
assert.deepEqual(
|
|
172
|
+
readTimings(run.evidence).map((recorded) => recorded.phase),
|
|
173
|
+
["up", "journey"],
|
|
174
|
+
);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
await test("a run without timings reads as none", (t) => {
|
|
178
|
+
assert.deepEqual(readTimings(scratchRun(t).evidence), []);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
await test("lines that are no entry are skipped and the others are kept", (t) => {
|
|
182
|
+
const run = scratchRun(t);
|
|
183
|
+
writeFileSync(
|
|
184
|
+
join(run.evidence, TIMINGS_FILE),
|
|
185
|
+
[
|
|
186
|
+
JSON.stringify(entry("up", 10, "00")),
|
|
187
|
+
'{"phase":"half',
|
|
188
|
+
"",
|
|
189
|
+
JSON.stringify({ phase: "up", ms: "slow" }),
|
|
190
|
+
JSON.stringify(entry("mail", 5, "01")),
|
|
191
|
+
].join("\n"),
|
|
192
|
+
);
|
|
193
|
+
assert.deepEqual(
|
|
194
|
+
readTimings(run.evidence).map((recorded) => recorded.phase),
|
|
195
|
+
["up", "mail"],
|
|
196
|
+
);
|
|
197
|
+
});
|
|
@@ -56,24 +56,27 @@ export const isFormalResult = objectOf(
|
|
|
56
56
|
|
|
57
57
|
/** @type {import("../json.mjs").Guard<import("./types.mjs").FeatureResult[]>} The journey results a run records in `<feature>/feature.json` */
|
|
58
58
|
const isFeatureResults = arrayOf(
|
|
59
|
-
objectOf(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
59
|
+
objectOf(
|
|
60
|
+
{
|
|
61
|
+
feature: isString,
|
|
62
|
+
journey: isString,
|
|
63
|
+
title: isString,
|
|
64
|
+
entryPoint: isString,
|
|
65
|
+
status: oneOf(["PASS", "FAIL"]),
|
|
66
|
+
database: isString,
|
|
67
|
+
steps: arrayOf(
|
|
68
|
+
objectOf({
|
|
69
|
+
name: isString,
|
|
70
|
+
checks: arrayOf(
|
|
71
|
+
objectOf({ name: isString, pass: isBoolean, detail: isString }),
|
|
72
|
+
),
|
|
73
|
+
}),
|
|
74
|
+
),
|
|
75
|
+
error: nullable(isString),
|
|
76
|
+
folder: isString,
|
|
77
|
+
},
|
|
78
|
+
{ ms: isNumber },
|
|
79
|
+
),
|
|
77
80
|
);
|
|
78
81
|
|
|
79
82
|
/** @type {import("../json.mjs").Guard<import("./types.mjs").RawJudgement>} The verifier's `judgement.json` */
|
|
@@ -143,7 +146,7 @@ const isDoorRule = objectOf({
|
|
|
143
146
|
why: isString,
|
|
144
147
|
});
|
|
145
148
|
|
|
146
|
-
/** The default export of a skill's `verify.config.ts`. `notUserFacing` may be absent. */
|
|
149
|
+
/** The default export of a skill's `verify.config.ts`. `notUserFacing`, `shared` and `notShared` may be absent. */
|
|
147
150
|
export const isSkillConfig = objectOf(
|
|
148
151
|
{
|
|
149
152
|
playground: isString,
|
|
@@ -154,7 +157,12 @@ export const isSkillConfig = objectOf(
|
|
|
154
157
|
doors: recordOf(nullable(isDoorRule)),
|
|
155
158
|
formal: arrayOf(isFormalCheck),
|
|
156
159
|
},
|
|
157
|
-
{
|
|
160
|
+
{
|
|
161
|
+
notUserFacing: strings,
|
|
162
|
+
shared: strings,
|
|
163
|
+
notShared: strings,
|
|
164
|
+
renderer: isString,
|
|
165
|
+
},
|
|
158
166
|
);
|
|
159
167
|
|
|
160
168
|
/**
|
|
@@ -170,7 +178,12 @@ export function decodeSkillConfig(exported, source) {
|
|
|
170
178
|
source,
|
|
171
179
|
"a verification skill config",
|
|
172
180
|
);
|
|
173
|
-
return {
|
|
181
|
+
return {
|
|
182
|
+
...config,
|
|
183
|
+
notUserFacing: config.notUserFacing ?? [],
|
|
184
|
+
shared: config.shared ?? [],
|
|
185
|
+
notShared: config.notShared ?? [],
|
|
186
|
+
};
|
|
174
187
|
}
|
|
175
188
|
|
|
176
189
|
/**
|
|
@@ -84,6 +84,17 @@ await test("journey results are read as recorded and none when absent", (t) => {
|
|
|
84
84
|
assert.deepEqual(readFeatureResults(join(dir, "feature.json")), [RESULT]);
|
|
85
85
|
});
|
|
86
86
|
|
|
87
|
+
await test("a journey result keeps its duration, and one whose duration is no number is refused", (t) => {
|
|
88
|
+
const dir = scratch(t);
|
|
89
|
+
writeJson(join(dir, "feature.json"), [{ ...RESULT, ms: 4200 }]);
|
|
90
|
+
assert.equal(readFeatureResults(join(dir, "feature.json"))[0].ms, 4200);
|
|
91
|
+
writeJson(join(dir, "feature.json"), [{ ...RESULT, ms: "4.2s" }]);
|
|
92
|
+
assert.throws(
|
|
93
|
+
() => readFeatureResults(join(dir, "feature.json")),
|
|
94
|
+
/malformed: expected a list of journey results/,
|
|
95
|
+
);
|
|
96
|
+
});
|
|
97
|
+
|
|
87
98
|
await test("a journey result with a status that is neither PASS nor FAIL is refused", (t) => {
|
|
88
99
|
const dir = scratch(t);
|
|
89
100
|
writeJson(join(dir, "feature.json"), [{ ...RESULT, status: "PASSED" }]);
|
|
@@ -166,6 +177,34 @@ await test("a config without the optional list of non-user-facing paths loads wi
|
|
|
166
177
|
assert.equal(skill.config.doors.format, null);
|
|
167
178
|
});
|
|
168
179
|
|
|
180
|
+
await test("a config loads its shared globs, and none when it lists none; a loader that drops the fields escalates nothing", async (t) => {
|
|
181
|
+
const bare = await loadSkill(skillFolder(t, CONFIG), tmpdir());
|
|
182
|
+
assert.deepEqual([bare.config.shared, bare.config.notShared], [[], []]);
|
|
183
|
+
const listed = await loadSkill(
|
|
184
|
+
skillFolder(
|
|
185
|
+
t,
|
|
186
|
+
CONFIG.replace(
|
|
187
|
+
" smoke:",
|
|
188
|
+
' shared: ["**/package.json"],\n notShared: ["hosts/**"],\n smoke:',
|
|
189
|
+
),
|
|
190
|
+
),
|
|
191
|
+
tmpdir(),
|
|
192
|
+
);
|
|
193
|
+
assert.deepEqual(listed.config.shared, ["**/package.json"]);
|
|
194
|
+
assert.deepEqual(listed.config.notShared, ["hosts/**"]);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
await test("a config whose shared globs are not strings is refused", async (t) => {
|
|
198
|
+
const dir = skillFolder(
|
|
199
|
+
t,
|
|
200
|
+
CONFIG.replace(" smoke:", ' shared: "**/package.json",\n smoke:'),
|
|
201
|
+
);
|
|
202
|
+
await assert.rejects(
|
|
203
|
+
loadSkill(dir, tmpdir()),
|
|
204
|
+
/verify\.config\.ts is malformed: expected a verification skill config/,
|
|
205
|
+
);
|
|
206
|
+
});
|
|
207
|
+
|
|
169
208
|
await test("a config missing a field is refused where the skill loads", async (t) => {
|
|
170
209
|
const dir = skillFolder(t, CONFIG.replace('smoke: "smoke",\n', ""));
|
|
171
210
|
await assert.rejects(
|
|
@@ -28,6 +28,21 @@ export function isUserFacing(skill, file) {
|
|
|
28
28
|
);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Whether a repository path is shared: matched by the config's `shared`
|
|
33
|
+
* globs and by none of its `notShared` globs. A change to it can alter any
|
|
34
|
+
* feature, so the plan runs them all.
|
|
35
|
+
*
|
|
36
|
+
* @param {import("./skill.mjs").Skill} skill The skill
|
|
37
|
+
* @param {string} file A repository path
|
|
38
|
+
* @returns {boolean} True when the file forces the full set
|
|
39
|
+
*/
|
|
40
|
+
export function isShared(skill, file) {
|
|
41
|
+
return (
|
|
42
|
+
matches(file, skill.config.shared) && !matches(file, skill.config.notShared)
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
31
46
|
/**
|
|
32
47
|
* The features whose `covers:` globs match a file.
|
|
33
48
|
*
|
|
@@ -84,6 +99,25 @@ async function featureProblems(skill, feature, tracked) {
|
|
|
84
99
|
return problems;
|
|
85
100
|
}
|
|
86
101
|
|
|
102
|
+
/**
|
|
103
|
+
* @param {import("./skill.mjs").Skill} skill The skill
|
|
104
|
+
* @param {string[]} tracked The tracked paths
|
|
105
|
+
* @returns {string[]} One line per problem
|
|
106
|
+
*/
|
|
107
|
+
function sharedProblems(skill, tracked) {
|
|
108
|
+
return skill.config.shared
|
|
109
|
+
.filter(
|
|
110
|
+
(glob) =>
|
|
111
|
+
!tracked.some(
|
|
112
|
+
(path) =>
|
|
113
|
+
matchesGlob(path, glob) && !matches(path, skill.config.notShared),
|
|
114
|
+
),
|
|
115
|
+
)
|
|
116
|
+
.map(
|
|
117
|
+
(glob) => `verify.config.ts: shared glob ${glob} matches no tracked file`,
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
87
121
|
/**
|
|
88
122
|
* @param {import("./skill.mjs").Skill} skill The skill
|
|
89
123
|
* @param {string[]} tracked The tracked paths
|
|
@@ -107,8 +141,8 @@ function doorProblems(skill, tracked) {
|
|
|
107
141
|
/**
|
|
108
142
|
* Checks the map against the repository: every user-facing file is
|
|
109
143
|
* covered, every feature has journeys, each described in its file,
|
|
110
|
-
* existing docs pages, and every feature and door glob matches a
|
|
111
|
-
* file.
|
|
144
|
+
* existing docs pages, and every feature, shared and door glob matches a
|
|
145
|
+
* tracked file.
|
|
112
146
|
*
|
|
113
147
|
* @param {import("./skill.mjs").Skill} skill The skill
|
|
114
148
|
* @returns {Promise<string[]>} One line per problem
|
|
@@ -134,22 +168,32 @@ export async function checkMap(skill) {
|
|
|
134
168
|
}
|
|
135
169
|
}
|
|
136
170
|
}
|
|
137
|
-
return [
|
|
171
|
+
return [
|
|
172
|
+
...problems,
|
|
173
|
+
...sharedProblems(skill, tracked),
|
|
174
|
+
...doorProblems(skill, tracked),
|
|
175
|
+
];
|
|
138
176
|
}
|
|
139
177
|
|
|
140
178
|
/**
|
|
141
179
|
* Maps the diff from the merge base of `baseRef` to HEAD onto features:
|
|
142
180
|
* every touched feature plus the smoke feature runs, a user-facing file
|
|
143
|
-
* outside every glob is an unmapped surface.
|
|
181
|
+
* outside every glob is an unmapped surface. A changed shared file, or
|
|
182
|
+
* `all`, runs the smoke feature and then every feature; `shared` lists the
|
|
183
|
+
* changed files that forced it.
|
|
144
184
|
*
|
|
145
185
|
* @param {import("./skill.mjs").Skill} skill The skill
|
|
146
186
|
* @param {string} baseRef The base, such as `origin/main`
|
|
187
|
+
* @param {boolean} [all] Run every feature whatever the diff, for a release
|
|
147
188
|
* @returns {import("./types.mjs").Plan} The plan
|
|
148
189
|
*/
|
|
149
|
-
export function planFor(skill, baseRef) {
|
|
190
|
+
export function planFor(skill, baseRef, all = false) {
|
|
150
191
|
const features = readFeatures(skill);
|
|
151
192
|
const baseSha = git(["merge-base", baseRef, "HEAD"], skill.repo);
|
|
152
|
-
const changed = git(
|
|
193
|
+
const changed = git(
|
|
194
|
+
["diff", "--name-only", "--no-renames", `${baseSha}...HEAD`],
|
|
195
|
+
skill.repo,
|
|
196
|
+
)
|
|
153
197
|
.split("\n")
|
|
154
198
|
.filter(Boolean);
|
|
155
199
|
const touched = features
|
|
@@ -170,15 +214,21 @@ export function planFor(skill, baseRef) {
|
|
|
170
214
|
.flatMap((feature) => feature.docs),
|
|
171
215
|
),
|
|
172
216
|
];
|
|
217
|
+
const shared = changed.filter((file) => isShared(skill, file));
|
|
173
218
|
const smoke = skill.config.smoke;
|
|
219
|
+
const names =
|
|
220
|
+
all || shared.length > 0
|
|
221
|
+
? features.map((feature) => feature.name)
|
|
222
|
+
: [...touchedNames];
|
|
174
223
|
return {
|
|
175
224
|
baseRef,
|
|
176
225
|
baseSha,
|
|
177
226
|
headSha: git(["rev-parse", "HEAD"], skill.repo),
|
|
178
227
|
changed,
|
|
179
228
|
touched,
|
|
229
|
+
shared,
|
|
180
230
|
unmapped,
|
|
181
231
|
docs,
|
|
182
|
-
run: [smoke, ...
|
|
232
|
+
run: [smoke, ...names.filter((name) => name !== smoke)],
|
|
183
233
|
};
|
|
184
234
|
}
|