slicekit 0.7.1 → 0.7.3
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/package.json +1 -1
- package/src/build/commit.js +128 -42
- package/src/build/red.js +41 -36
- package/src/build/review.js +36 -6
- package/src/build/verdict.js +92 -12
- package/src/check/rules/frozen.js +70 -19
- package/src/cli/build.js +8 -4
- package/src/hooks/paths.js +25 -10
- package/src/hooks/pre-edit.js +148 -17
- package/src/state/index.js +28 -8
- package/src/state/transitions.js +24 -3
- package/src/testnames.js +293 -0
- package/templates/instructions/agents/reviewer.md +11 -11
- package/templates/instructions/commands/build.md +15 -10
- package/templates/instructions/commands/review.md +20 -2
package/src/state/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import { parseSliceAddr, stateFileName } from '../ids.js';
|
|
|
6
6
|
import { withFileLock } from '../lock.js';
|
|
7
7
|
import { kitPaths } from '../paths.js';
|
|
8
8
|
import { findSliceFiles, parseSliceFile } from '../slicefile.js';
|
|
9
|
+
import { entryLabel, evaluationRows, frozenEntries } from '../testnames.js';
|
|
9
10
|
import { TRANSITIONS, TransitionError, allowedMove, nextStates, validateEvidence } from './transitions.js';
|
|
10
11
|
|
|
11
12
|
export { TransitionError };
|
|
@@ -187,22 +188,41 @@ export function recordHead(root, cfg, id, pr) {
|
|
|
187
188
|
});
|
|
188
189
|
}
|
|
189
190
|
|
|
190
|
-
//
|
|
191
|
-
//
|
|
192
|
-
//
|
|
193
|
-
export function
|
|
191
|
+
// The tests a state file freezes, as [{ file, name }] (`name` null for a whole file), read with the
|
|
192
|
+
// slice file's evaluation set: a path string, the form written before P8/S-60, is every evaluation
|
|
193
|
+
// test of that file by name, or the whole file when the evaluation set names none in it (D-102).
|
|
194
|
+
export function frozenOf(state, slice) {
|
|
195
|
+
return frozenEntries(state.frozenTests, evaluationRows(slice));
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Whether `test` (a path, or { file, name }) is frozen in `current`: a path only when it is listed as a
|
|
199
|
+
// path, the form of a state file written before P8/S-60; the file of a test frozen by name is not, so a
|
|
200
|
+
// bare path never unfreezes tests frozen by name (REQ-1.5, D-102); { file, name } is one of the tests
|
|
201
|
+
// frozenOf reads. `slice` is the slice file at the red commit.
|
|
202
|
+
export function isFrozen(current, test, slice) {
|
|
203
|
+
if (typeof test === 'string') return current.frozenTests.some((t) => typeof t === 'string' && t === test);
|
|
204
|
+
return frozenOf(current, slice).some((e) => e.file === test.file && e.name === test.name);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Only a test frozen at tests-red can be unfrozen; any other path has nothing to release. `test` is a
|
|
208
|
+
// path (the whole file, as before P8/S-60) or { file, name } (D-102); `slice` is the parsed slice file,
|
|
209
|
+
// whose evaluation set reads an old path entry by name. `extra` joins the history entry's evidence
|
|
210
|
+
// (build amend gives the amendment commit and the reason). `to` moves the slice in the same write:
|
|
211
|
+
// build amend during review takes it back to building (D-43).
|
|
212
|
+
export function unfreeze(root, cfg, id, test, extra = {}, { to, slice } = {}) {
|
|
194
213
|
return withLock(root, cfg, id, () => {
|
|
195
214
|
const current = readSlice(root, cfg, id);
|
|
196
|
-
|
|
197
|
-
|
|
215
|
+
const label = entryLabel(test);
|
|
216
|
+
if (!isFrozen(current, test, slice)) {
|
|
217
|
+
throw new TransitionError(`${label} is not a frozen test of ${id}`);
|
|
198
218
|
}
|
|
199
219
|
const state = to ?? current.state;
|
|
200
220
|
const next = {
|
|
201
221
|
...current,
|
|
202
222
|
state,
|
|
203
223
|
...(state === current.state ? {} : { handoff: null }),
|
|
204
|
-
unfrozen: [...current.unfrozen, file],
|
|
205
|
-
history: [...current.history, entry(current.state, state, 'cli', { unfreeze:
|
|
224
|
+
unfrozen: [...current.unfrozen, typeof test === 'string' ? test : { file: test.file, name: test.name }],
|
|
225
|
+
history: [...current.history, entry(current.state, state, 'cli', { unfreeze: label, ...extra })],
|
|
206
226
|
};
|
|
207
227
|
writeSlice(root, cfg, next);
|
|
208
228
|
return next;
|
package/src/state/transitions.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { isDate, isSha, sameSha } from '../evidence.js';
|
|
4
|
+
import { TestNameError, entryFile, entryLabel, findTest, isEntry } from '../testnames.js';
|
|
4
5
|
import { isReviewWorktreeAt } from '../worktrees.js';
|
|
5
6
|
import { headCovers } from './covers.js';
|
|
6
7
|
|
|
@@ -29,6 +30,19 @@ const last = (list) => list[list.length - 1];
|
|
|
29
30
|
const isInt = (n) => Number.isInteger(n) && n >= 0;
|
|
30
31
|
const isStr = (s) => typeof s === 'string' && s !== '';
|
|
31
32
|
const present = (root, rel) => fs.existsSync(path.resolve(root, rel));
|
|
33
|
+
// A frozen entry's file is present, and a test frozen by name is found in it; a file the reader
|
|
34
|
+
// cannot parse is not judged present.
|
|
35
|
+
function presentTest(root, entry) {
|
|
36
|
+
const file = entryFile(entry);
|
|
37
|
+
if (!present(root, file)) return false;
|
|
38
|
+
if (typeof entry === 'string') return true;
|
|
39
|
+
try {
|
|
40
|
+
return findTest(fs.readFileSync(path.resolve(root, file), 'utf8'), entry.name) !== null;
|
|
41
|
+
} catch (e) {
|
|
42
|
+
if (e instanceof TestNameError) return false;
|
|
43
|
+
throw e;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
32
46
|
const escape = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
33
47
|
|
|
34
48
|
// The verdicts that hold on the pull request head as it stands now: those given on it, and, with a
|
|
@@ -73,6 +87,10 @@ export function validateEvidence(ev) {
|
|
|
73
87
|
if (ev.tests !== undefined && !(Array.isArray(ev.tests) && ev.tests.every(isStr))) {
|
|
74
88
|
return bad('tests', 'an array of non-empty strings');
|
|
75
89
|
}
|
|
90
|
+
// P8/S-60 (D-102): the evaluation tests frozen by name, { file, name } or a whole file's path.
|
|
91
|
+
if (ev.frozen !== undefined && !(Array.isArray(ev.frozen) && ev.frozen.every(isEntry))) {
|
|
92
|
+
return bad('frozen', 'an array of { file, name } entries or paths');
|
|
93
|
+
}
|
|
76
94
|
const pr = ev.pr;
|
|
77
95
|
if (pr !== undefined) {
|
|
78
96
|
if (pr === null || typeof pr !== 'object') return bad('pr', 'an object');
|
|
@@ -121,15 +139,18 @@ export const TRANSITIONS = {
|
|
|
121
139
|
}
|
|
122
140
|
return null;
|
|
123
141
|
},
|
|
124
|
-
|
|
142
|
+
// `frozen`, given by build red, holds each evaluation test by its file and name (D-102); without
|
|
143
|
+
// it (`state set` with --tests) the files are recorded whole, as before P8/S-60.
|
|
144
|
+
apply: (_current, ev) => ({ redCommit: ev.commit, frozenTests: ev.frozen ? ev.frozen.map((e) => (typeof e === 'string' ? e : { file: e.file, name: e.name })) : [...ev.tests] }),
|
|
125
145
|
},
|
|
126
146
|
building: {
|
|
127
147
|
from: ['tests-red'],
|
|
128
148
|
required: [],
|
|
149
|
+
// Each frozen file is present and each test frozen by name is found in its file (D-102).
|
|
129
150
|
check(current, _ev, ctx) {
|
|
130
151
|
if (!current.redCommit) return 'building needs a recorded red commit';
|
|
131
|
-
const missing = current.frozenTests.filter((t) => !
|
|
132
|
-
return missing.length > 0 ? `frozen tests are missing: ${missing.join(', ')}` : null;
|
|
152
|
+
const missing = current.frozenTests.filter((t) => !isEntry(t) || !presentTest(ctx.root, t));
|
|
153
|
+
return missing.length > 0 ? `frozen tests are missing: ${missing.map((t) => (isEntry(t) ? entryLabel(t) : String(t))).join(', ')}` : null;
|
|
133
154
|
},
|
|
134
155
|
apply: () => ({}),
|
|
135
156
|
},
|
package/src/testnames.js
ADDED
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
// A test of the evaluation set, found in its file by its name (REQ-3.3, REQ-3.15, D-102), and the
|
|
2
|
+
// frozen entries of a state file read as { file, name }.
|
|
3
|
+
//
|
|
4
|
+
// `findTest(text, name)` finds the one `test(...)` or `it(...)` call, at any depth, whose first argument
|
|
5
|
+
// is a string literal (single, double or backtick quotes, no substitution) equal to `name`. It returns
|
|
6
|
+
// { line, text }: the 1-based line the call starts on, and the text from `test`/`it` to the call's
|
|
7
|
+
// matching close parenthesis; null when no call has the name. Strings, template literals, comments
|
|
8
|
+
// and regular expression literals are skipped, so a parenthesis or a brace inside them does not count.
|
|
9
|
+
// A file the reader cannot parse (an unterminated string, comment or call), or a name given to two
|
|
10
|
+
// calls, throws a TestNameError: every caller treats it as "cannot judge".
|
|
11
|
+
//
|
|
12
|
+
// Only `node:` modules (D-04): none are needed.
|
|
13
|
+
|
|
14
|
+
export class TestNameError extends Error {
|
|
15
|
+
constructor(message) {
|
|
16
|
+
super(message);
|
|
17
|
+
this.name = 'TestNameError';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const IDENT_START = /[A-Za-z_$]/;
|
|
22
|
+
const IDENT = /[A-Za-z0-9_$]/;
|
|
23
|
+
// An escaped quote or backslash keeps a literal plain; any other escape does not.
|
|
24
|
+
const QUOTE_ESCAPE = /['"`\\]/;
|
|
25
|
+
// After one of these tokens a `/` starts a regular expression literal, not a division.
|
|
26
|
+
const REGEX_AFTER_PUNCT = new Set(['(', ',', '=', ':', '[', '!', '&', '|', '?', '{', '}', ';', '+', '-', '*', '%', '<', '>', '~', '^', '=>']);
|
|
27
|
+
const REGEX_AFTER_WORD = new Set(['return', 'typeof', 'instanceof', 'in', 'of', 'new', 'delete', 'void', 'throw', 'case', 'do', 'else', 'yield', 'await']);
|
|
28
|
+
|
|
29
|
+
// The tokens of `text` that matter here: identifiers, punctuation, and string literals (a template
|
|
30
|
+
// with no substitution counts as one). Each is { type, value, start, end, line }; a string's value is
|
|
31
|
+
// its raw content between the quotes, and `plain` is false when it holds an escape or a substitution.
|
|
32
|
+
function tokens(text) {
|
|
33
|
+
const out = [];
|
|
34
|
+
let i = 0;
|
|
35
|
+
let line = 1;
|
|
36
|
+
// Each open `{` in code, and each `${` of a template: a `}` closing a `${` resumes the template.
|
|
37
|
+
const braces = [];
|
|
38
|
+
const prevSignificant = () => out.at(-1);
|
|
39
|
+
const regexAllowed = () => {
|
|
40
|
+
const p = prevSignificant();
|
|
41
|
+
if (!p) return true;
|
|
42
|
+
if (p.type === 'punct') return REGEX_AFTER_PUNCT.has(p.value);
|
|
43
|
+
if (p.type === 'ident') return REGEX_AFTER_WORD.has(p.value);
|
|
44
|
+
return false;
|
|
45
|
+
};
|
|
46
|
+
const fail = (what, at) => {
|
|
47
|
+
throw new TestNameError(`cannot read the test file: ${what} at line ${at}`);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// Reads a template literal from just after a backtick or a `}` closing a substitution. -> whether it
|
|
51
|
+
// ended at a backtick (true) or at a `${` (false); adds a string token for the part read.
|
|
52
|
+
const template = (start, startLine, fromBacktick) => {
|
|
53
|
+
let plain = fromBacktick;
|
|
54
|
+
let j = i;
|
|
55
|
+
while (j < text.length) {
|
|
56
|
+
const c = text[j];
|
|
57
|
+
if (c === '\\') {
|
|
58
|
+
if (!QUOTE_ESCAPE.test(text[j + 1] ?? '')) plain = false;
|
|
59
|
+
if (text[j + 1] === '\n') line += 1;
|
|
60
|
+
j += 2;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (c === '\n') line += 1;
|
|
64
|
+
if (c === '`') {
|
|
65
|
+
out.push({ type: 'string', value: text.slice(i, j), plain, start, end: j + 1, line: startLine });
|
|
66
|
+
i = j + 1;
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
if (c === '$' && text[j + 1] === '{') {
|
|
70
|
+
out.push({ type: 'string', value: text.slice(i, j), plain: false, start, end: j + 2, line: startLine });
|
|
71
|
+
i = j + 2;
|
|
72
|
+
braces.push('template');
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
j += 1;
|
|
76
|
+
}
|
|
77
|
+
return fail('an unterminated template literal', startLine);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
while (i < text.length) {
|
|
81
|
+
const c = text[i];
|
|
82
|
+
if (c === '\n') {
|
|
83
|
+
line += 1;
|
|
84
|
+
i += 1;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (c === ' ' || c === '\t' || c === '\r' || c === '\f' || c === '\v' || c === '\uFEFF') {
|
|
88
|
+
i += 1;
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (c === '/' && text[i + 1] === '/') {
|
|
92
|
+
const nl = text.indexOf('\n', i);
|
|
93
|
+
i = nl === -1 ? text.length : nl;
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (c === '/' && text[i + 1] === '*') {
|
|
97
|
+
const close = text.indexOf('*/', i + 2);
|
|
98
|
+
if (close === -1) fail('an unterminated comment', line);
|
|
99
|
+
for (let k = i; k < close; k += 1) if (text[k] === '\n') line += 1;
|
|
100
|
+
i = close + 2;
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
if (c === '#' && i === 0 && text[1] === '!') {
|
|
104
|
+
const nl = text.indexOf('\n', i);
|
|
105
|
+
i = nl === -1 ? text.length : nl;
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
if (c === "'" || c === '"') {
|
|
109
|
+
const start = i;
|
|
110
|
+
const startLine = line;
|
|
111
|
+
let plain = true;
|
|
112
|
+
let j = i + 1;
|
|
113
|
+
while (j < text.length && text[j] !== c) {
|
|
114
|
+
if (text[j] === '\n') fail('an unterminated string', startLine);
|
|
115
|
+
if (text[j] === '\\') {
|
|
116
|
+
if (!QUOTE_ESCAPE.test(text[j + 1] ?? '')) plain = false;
|
|
117
|
+
if (text[j + 1] === '\n') line += 1;
|
|
118
|
+
j += 2;
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
j += 1;
|
|
122
|
+
}
|
|
123
|
+
if (j >= text.length) fail('an unterminated string', startLine);
|
|
124
|
+
out.push({ type: 'string', value: text.slice(i + 1, j), plain, start, end: j + 1, line: startLine });
|
|
125
|
+
i = j + 1;
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
if (c === '`') {
|
|
129
|
+
const start = i;
|
|
130
|
+
i += 1;
|
|
131
|
+
template(start, line, true);
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (c === '/' && regexAllowed()) {
|
|
135
|
+
const startLine = line;
|
|
136
|
+
let j = i + 1;
|
|
137
|
+
let inClass = false;
|
|
138
|
+
while (j < text.length) {
|
|
139
|
+
const d = text[j];
|
|
140
|
+
if (d === '\n') fail('an unterminated regular expression', startLine);
|
|
141
|
+
if (d === '\\') {
|
|
142
|
+
j += 2;
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
if (d === '[') inClass = true;
|
|
146
|
+
else if (d === ']') inClass = false;
|
|
147
|
+
else if (d === '/' && !inClass) break;
|
|
148
|
+
j += 1;
|
|
149
|
+
}
|
|
150
|
+
if (j >= text.length) fail('an unterminated regular expression', startLine);
|
|
151
|
+
j += 1;
|
|
152
|
+
while (j < text.length && IDENT.test(text[j])) j += 1;
|
|
153
|
+
out.push({ type: 'regex', value: text.slice(i, j), start: i, end: j, line: startLine });
|
|
154
|
+
i = j;
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
if (IDENT_START.test(c)) {
|
|
158
|
+
let j = i + 1;
|
|
159
|
+
while (j < text.length && IDENT.test(text[j])) j += 1;
|
|
160
|
+
out.push({ type: 'ident', value: text.slice(i, j), start: i, end: j, line });
|
|
161
|
+
i = j;
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
if (/[0-9]/.test(c)) {
|
|
165
|
+
let j = i + 1;
|
|
166
|
+
while (j < text.length && /[0-9A-Za-z_.]/.test(text[j])) j += 1;
|
|
167
|
+
out.push({ type: 'number', value: text.slice(i, j), start: i, end: j, line });
|
|
168
|
+
i = j;
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
if (c === '}' && braces.at(-1) === 'template') {
|
|
172
|
+
braces.pop();
|
|
173
|
+
const start = i;
|
|
174
|
+
i += 1;
|
|
175
|
+
template(start, line, false);
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
if (c === '{') braces.push('code');
|
|
179
|
+
if (c === '}') braces.pop();
|
|
180
|
+
if (c === '=' && text[i + 1] === '>') {
|
|
181
|
+
out.push({ type: 'punct', value: '=>', start: i, end: i + 2, line });
|
|
182
|
+
i += 2;
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
out.push({ type: 'punct', value: c, start: i, end: i + 1, line });
|
|
186
|
+
i += 1;
|
|
187
|
+
}
|
|
188
|
+
return out;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// A literal's raw content with its quote and backslash escapes read; any other escape keeps its
|
|
192
|
+
// backslash, so a name with one never matches.
|
|
193
|
+
const unescape = (raw) => raw.replace(/\\(['"`\\])/g, '$1');
|
|
194
|
+
|
|
195
|
+
const OPEN = { '(': ')', '[': ']', '{': '}' };
|
|
196
|
+
|
|
197
|
+
// The index of the token closing the call whose `(` is at index `open`, or a TestNameError.
|
|
198
|
+
function closeOf(toks, open) {
|
|
199
|
+
const stack = [];
|
|
200
|
+
for (let k = open; k < toks.length; k += 1) {
|
|
201
|
+
const t = toks[k];
|
|
202
|
+
if (t.type !== 'punct') continue;
|
|
203
|
+
if (OPEN[t.value]) stack.push(OPEN[t.value]);
|
|
204
|
+
else if (t.value === ')' || t.value === ']' || t.value === '}') {
|
|
205
|
+
if (stack.pop() !== t.value) throw new TestNameError(`cannot read the test file: an unbalanced ${t.value} at line ${t.line}`);
|
|
206
|
+
if (stack.length === 0) return k;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
throw new TestNameError(`cannot read the test file: the call at line ${toks[open].line} is not closed`);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// Every `test(...)` or `it(...)` call named `name`: [{ line, text }].
|
|
213
|
+
function calls(text, name) {
|
|
214
|
+
const toks = tokens(text);
|
|
215
|
+
const found = [];
|
|
216
|
+
for (let k = 0; k + 2 < toks.length; k += 1) {
|
|
217
|
+
const t = toks[k];
|
|
218
|
+
if (t.type !== 'ident' || (t.value !== 'test' && t.value !== 'it')) continue;
|
|
219
|
+
const before = toks[k - 1];
|
|
220
|
+
if (before && before.type === 'punct' && before.value === '.') continue;
|
|
221
|
+
const open = toks[k + 1];
|
|
222
|
+
const label = toks[k + 2];
|
|
223
|
+
if (open.type !== 'punct' || open.value !== '(' || label.type !== 'string' || !label.plain) continue;
|
|
224
|
+
if (unescape(label.value) !== name) continue;
|
|
225
|
+
const end = closeOf(toks, k + 1);
|
|
226
|
+
found.push({ line: t.line, text: text.slice(t.start, toks[end].end) });
|
|
227
|
+
}
|
|
228
|
+
return found;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export function findTest(text, name) {
|
|
232
|
+
const found = calls(String(text).replace(/\r\n/g, '\n'), name);
|
|
233
|
+
if (found.length > 1) {
|
|
234
|
+
throw new TestNameError(`the test name "${name}" is given twice, at lines ${found.map((f) => f.line).join(' and ')}`);
|
|
235
|
+
}
|
|
236
|
+
return found[0] ?? null;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// ---- the evaluation set's rows and the state file's frozen entries ----
|
|
240
|
+
|
|
241
|
+
export const SEP = ' » ';
|
|
242
|
+
|
|
243
|
+
// One evaluation-set cell, `<file> » <name>` or a bare `<file>`: { row, file, name } (name null).
|
|
244
|
+
export function parseRow(cell) {
|
|
245
|
+
const row = String(cell).replace(/^`|`$/g, '').trim();
|
|
246
|
+
const at = row.indexOf(SEP);
|
|
247
|
+
return {
|
|
248
|
+
row,
|
|
249
|
+
file: (at === -1 ? row : row.slice(0, at)).trim(),
|
|
250
|
+
name: at === -1 ? null : row.slice(at + SEP.length).trim(),
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// The rows of a parsed slice file's evaluation set.
|
|
255
|
+
export const evaluationRows = (slice) => (slice?.evaluation ?? []).map(({ test }) => parseRow(test));
|
|
256
|
+
|
|
257
|
+
// A listed test path ends with a row's file: the row `hooks/a.test.js` names `test/hooks/a.test.js`.
|
|
258
|
+
export const endsWithFile = (t, file) => t === file || t.endsWith(`/${file}`);
|
|
259
|
+
|
|
260
|
+
// An entry as a state file stores it: a path string (a whole file, written before P8/S-60, or a file
|
|
261
|
+
// `build amend --test <file>` unfroze whole), or { file, name }.
|
|
262
|
+
export const isEntry = (e) =>
|
|
263
|
+
(typeof e === 'string' && e !== '') ||
|
|
264
|
+
(e !== null && typeof e === 'object' && !Array.isArray(e) && typeof e.file === 'string' && e.file !== '' && typeof e.name === 'string' && e.name !== '');
|
|
265
|
+
|
|
266
|
+
export const entryFile = (e) => (typeof e === 'string' ? e : e.file);
|
|
267
|
+
export const entryLabel = (e) => (typeof e === 'string' || e.name === null ? entryFile(e) : `${e.file}${SEP}${e.name}`);
|
|
268
|
+
|
|
269
|
+
// The frozen entries as [{ file, name }], `name` null for a whole file. A path string, the form of a
|
|
270
|
+
// state file written before P8/S-60, is read as every evaluation test of that file by name when
|
|
271
|
+
// `rows` (the slice file's evaluation set) names tests in it; else as the whole file. `same` compares
|
|
272
|
+
// two paths (case-folded on win32 by callers that need it).
|
|
273
|
+
export function frozenEntries(list, rows = [], same = (a, b) => a === b) {
|
|
274
|
+
const out = [];
|
|
275
|
+
const add = (e) => {
|
|
276
|
+
if (!out.some((o) => same(o.file, e.file) && o.name === e.name)) out.push(e);
|
|
277
|
+
};
|
|
278
|
+
for (const e of list ?? []) {
|
|
279
|
+
if (typeof e !== 'string') {
|
|
280
|
+
add({ file: e.file, name: e.name });
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
const named = rows.filter((r) => r.name !== null && endsWithFile(e, r.file));
|
|
284
|
+
if (named.length === 0) add({ file: e, name: null });
|
|
285
|
+
else for (const r of named) add({ file: e, name: r.name });
|
|
286
|
+
}
|
|
287
|
+
return out;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// Whether `unfrozen` lifts the freeze on entry { file, name }: it lists the file whole, or the same test.
|
|
291
|
+
export function isUnfrozen(entry, unfrozen, same = (a, b) => a === b) {
|
|
292
|
+
return (unfrozen ?? []).some((u) => (typeof u === 'string' ? same(u, entry.file) : same(u.file, entry.file) && u.name === entry.name));
|
|
293
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# Brief: reviewer
|
|
2
2
|
|
|
3
|
-
You review one slice and write one verdict file. You try to break the change: run its tests
|
|
3
|
+
You review one slice and write one verdict file. You try to break the change: run its tests and read its diff against the slice file, its requirements and the writing rules.
|
|
4
4
|
|
|
5
5
|
## You write
|
|
6
6
|
|
|
7
|
-
One verdict file and nothing else. The command gives you the absolute path
|
|
7
|
+
One verdict file and nothing else. The command gives you the absolute path: it ends `.slicekit/reviews/P<n>-S-<nn>[i]-r<k>.md` and is in the session root, never under the worktree. `k` is the round; the letter `i` marks an independent review. The file has this shape:
|
|
8
8
|
|
|
9
9
|
```
|
|
10
10
|
Verdict: BLOCK
|
|
@@ -41,23 +41,23 @@ The rest of the file:
|
|
|
41
41
|
|
|
42
42
|
## Reviewing a slice
|
|
43
43
|
|
|
44
|
-
The command gives you the pull request
|
|
44
|
+
The command gives you the pull request, the worktree, the round `k` and the verdict path. Your round budget (REQ-2.6, REQ-2.8): two build rounds, one independent round and a second only after a blocker; a blocker left in the last round stops the slice.
|
|
45
45
|
|
|
46
46
|
1. Read the slice file in the worktree, the change with `git diff <base>...HEAD` run in the worktree (read only; `<base>` is `defaultBranch` in `.slicekit/config.json`), and the pull request body.
|
|
47
|
-
2. Run the test command and `{{cli}} check` in the worktree. Quote each
|
|
48
|
-
3. A blocker is
|
|
49
|
-
4.
|
|
50
|
-
5. A verdict
|
|
51
|
-
6. A should-have
|
|
52
|
-
7. A finding states the fault and stops
|
|
47
|
+
2. Run the test command and `{{cli}} check` in the worktree. Quote each summary line in the "How verified" column of the findings it supports.
|
|
48
|
+
3. A blocker is: a Done when check that fails; a REQ or D row the change breaks; a rule weakened or a baseline raised (REQ-3.7); a writing-rule breach in the pull request body. Every other finding is a should-have.
|
|
49
|
+
4. A finding that survives from an earlier round keeps its ID. A new finding takes the next number never used in this slice, B and H counted apart: after B-1 and B-2, a new blocker is B-3 even if B-2 was fixed. Any other ID is refused.
|
|
50
|
+
5. A verdict with a phrase from `style.banned` in `.slicekit/config.json`, an unknown slice, requirement or decision ID, a missing backticked path, or a `<!--` in a "What is wrong", is refused; reword it.
|
|
51
|
+
6. A should-have the pull request body lists under "Should-haves declined" is not raised again.
|
|
52
|
+
7. A finding states the fault and stops; it holds no code. You report no finding on wording, formatting or naming alone, and no finding when you have none: then write `Verdict: APPROVE` with an empty findings table.
|
|
53
53
|
|
|
54
54
|
## You never
|
|
55
55
|
|
|
56
56
|
- Write or change code, tests or any file other than the verdict.
|
|
57
|
-
- Ask a question
|
|
57
|
+
- Ask a question; a doubt is a finding or a `## Not checked` item.
|
|
58
58
|
- Praise the change.
|
|
59
59
|
- Run git, except the read-only `git diff`, `git log`, `git show` and `git status`. You never commit or push the verdict; the command does that.
|
|
60
60
|
|
|
61
61
|
## Your report
|
|
62
62
|
|
|
63
|
-
Your reply names the verdict file's path and
|
|
63
|
+
Your reply names the verdict file's path and verdict line. It ends with a `Skipped:` line and then a `Not checked:` line. Each of these lines starts at the beginning of its line, with no list marker, bold or backticks. When you stop, the newest verdict file of this slice is checked against the shape above.
|
|
@@ -74,9 +74,11 @@ After each developer report in which a test newly passes, run
|
|
|
74
74
|
`feat(<id>): <what now works>`. It prints `<sha7> exit <n>`, or `nothing to commit` with exit 0,
|
|
75
75
|
which is success. With nothing staged it commits every changed path; with paths staged it commits
|
|
76
76
|
those alone, as staged, and runs the tests on the staged content; a tracked path changed but not
|
|
77
|
-
staged stays in the worktree, out of the commit. A
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
staged stays in the worktree, out of the commit. A test is frozen by its name, as the evaluation
|
|
78
|
+
set's `<file> » <name>` cell names it, not by the file that holds it: another test or line of that
|
|
79
|
+
file may change. A refusal naming a frozen test, `frozen test <file> » <name> changed since <sha7>`,
|
|
80
|
+
means the developer changed one: send it back with the message. While tests still fail, spawn the
|
|
81
|
+
developer again with what is left.
|
|
80
82
|
|
|
81
83
|
When the developer reports a line `amend: <test path> — <why>`, ask the human whether that test may
|
|
82
84
|
change. On no, tell the developer the test stands. On yes:
|
|
@@ -86,20 +88,23 @@ change. On no, tell the developer the test stands. On yes:
|
|
|
86
88
|
2. Change the evaluation set's row when the test's name or kind changes. When the row stays the
|
|
87
89
|
same (only the test was wrong), still record the amendment in that file, as a line under the
|
|
88
90
|
evaluation set naming the test and the reason: `build amend` refuses a slice file with no change.
|
|
89
|
-
3. Run `{{cli}} build amend <id> --test <test path> --reason "<why>" --worktree <path>`,
|
|
90
|
-
the developer it may change that one test.
|
|
91
|
+
3. Run `{{cli}} build amend <id> --test "<test path> » <test name>" --reason "<why>" --worktree <path>`,
|
|
92
|
+
and tell the developer it may change that one test. It commits the slice file, records the
|
|
93
|
+
test, the amendment commit and the reason in the state file, and prints
|
|
94
|
+
`unfroze <test path> » <test name>`; every other frozen test stays frozen. Naming a test already
|
|
95
|
+
unfrozen records a second amendment of it and its reason, and prints
|
|
96
|
+
`<sha7> amended the slice file; <test path> » <test name> was already unfrozen`.
|
|
91
97
|
|
|
92
98
|
`build amend` also runs at `draft-pr`, `in-review` and `changes-requested`, for a finding that sits
|
|
93
99
|
inside a frozen test: the same three steps, then the slice is back at `building`. The fixer (or the
|
|
94
100
|
developer) changes that test, and step 7's `build commit` and `build pr` take the slice back to
|
|
95
101
|
`draft-pr` on the same pull request.
|
|
96
102
|
|
|
97
|
-
When the human changes the slice file and
|
|
98
|
-
to name: edit the slice file in the worktree as in step 1, then run
|
|
103
|
+
When the human changes the slice file and no test is to change (a Done when item, a pending marker,
|
|
104
|
+
a note), there is no test to name: edit the slice file in the worktree as in step 1, then run
|
|
99
105
|
`{{cli}} build amend <id> --reason "<why>" --worktree <path>`. It commits the slice file alone,
|
|
100
|
-
records the reason in the state file, leaves the state as it is, and
|
|
101
|
-
`<sha7> amended the slice file`.
|
|
102
|
-
`--test`.
|
|
106
|
+
records the amendment commit and the reason in the state file, leaves the state as it is, and
|
|
107
|
+
prints `<sha7> amended the slice file`. Every frozen test stays frozen.
|
|
103
108
|
|
|
104
109
|
## 5. Green, then the draft pull request
|
|
105
110
|
|
|
@@ -18,6 +18,10 @@ it is left to the person who started this session. When this session built the s
|
|
|
18
18
|
the building session's context, stop and tell the human to run `/slicekit review <PR>` in a new
|
|
19
19
|
session.
|
|
20
20
|
|
|
21
|
+
A reviewer subagent started by `{{cli}} review start <PR>` from the main checkout, given only the
|
|
22
|
+
pull request and the reviewer's brief and no build context, counts as independent, and
|
|
23
|
+
`/slicekit review` in a new session is the stronger form (D-104).
|
|
24
|
+
|
|
21
25
|
When the arguments are `(none)`, ask the human for the pull request's number and use it in place of
|
|
22
26
|
`{{args}}` below. Call that number `<n>`.
|
|
23
27
|
|
|
@@ -39,6 +43,13 @@ refusal and stop, since the human decides each of these. A refusal that names
|
|
|
39
43
|
`build pr <id> --worktree <dir>` means an earlier review session committed a fix it did not push:
|
|
40
44
|
run `{{cli}} build pr <id> --worktree <dir>` with the path it names, then this step again.
|
|
41
45
|
|
|
46
|
+
The independent review has one round, and a second only when the first left a blocker (D-101). A
|
|
47
|
+
refusal that `no independent round is left` names the latest round's open blockers and three
|
|
48
|
+
choices: fix them by hand, re-scope the slice, or record a decision row that allows one more round,
|
|
49
|
+
committed on the default branch and pushed to origin.
|
|
50
|
+
A refusal that the review `left no blocker` means the slice has its independent verdict. Print
|
|
51
|
+
either refusal and stop: the human decides.
|
|
52
|
+
|
|
42
53
|
## 3. The reviewer gives the independent verdict
|
|
43
54
|
|
|
44
55
|
Run `{{cli}} instructions reviewer <id> --worktree <wt>`. Spawn the reviewer with that output as its
|
|
@@ -51,7 +62,9 @@ section lets it write that one file outside the worktree.
|
|
|
51
62
|
When the reviewer stops, run `{{cli}} build verdict <id> <path> --independent --worktree <wt>` with
|
|
52
63
|
step 2's verdict path. It commits the verdict into the review worktree, pushes it to the slice
|
|
53
64
|
branch, and prints `next: <step>`, `blockers: <IDs or none>`, `should-haves: <IDs or none>` and
|
|
54
|
-
`rounds: <used> of 2`; the rounds stay as they were.
|
|
65
|
+
`rounds: <used> of 2`; the rounds stay as they were. On `next: fix` it also prints
|
|
66
|
+
`review: <command>`, the `review start` command of the next independent round that the budget
|
|
67
|
+
allows (D-101); keep it for step 5. By what it prints:
|
|
55
68
|
|
|
56
69
|
- A refusal that names the verdict's content (a finding with no "How verified", a reused finding
|
|
57
70
|
number, a banned phrase, a `<!--`): send the reviewer back with the printed message, then run this
|
|
@@ -60,6 +73,10 @@ branch, and prints `next: <step>`, `blockers: <IDs or none>`, `should-haves: <ID
|
|
|
60
73
|
session pushed since step 2. Run `{{cli}} build sync <id> --worktree <wt>`, then this command again.
|
|
61
74
|
- `a new verdict needs a fresh fetch`: origin could not be reached. Print it and stop; tell the
|
|
62
75
|
human to run this command again once origin answers.
|
|
76
|
+
- Exit 1 with `stopped:` and `next: stuck`: the round was the last one allowed and left a blocker
|
|
77
|
+
(D-101). The slice is `changes-requested`. Print the open blockers and the three choices it
|
|
78
|
+
prints and stop: the human fixes them by hand, re-scopes the slice, or records a decision row that
|
|
79
|
+
allows one more round, committed on the default branch and pushed to origin.
|
|
63
80
|
- Any other refusal goes to the human: print it and stop.
|
|
64
81
|
|
|
65
82
|
When the verdict lists should-haves, ask the human once, listing each with its ID and its "What is
|
|
@@ -91,7 +108,8 @@ When the fixer reports, run these two in this order:
|
|
|
91
108
|
`pass --notes <file>`, the body lost a section: print the refusal and stop, since the notes are the
|
|
92
109
|
building session's.
|
|
93
110
|
|
|
94
|
-
Then start again at step 2 with
|
|
111
|
+
Then start again at step 2 with the command step 4's `review:` line printed,
|
|
112
|
+
`{{cli}} review start <n>`: the new head needs its own independent
|
|
95
113
|
verdict, at the next round. Tell the human that the slice branch moved under the building session:
|
|
96
114
|
that session syncs its worktree with `build sync <id>` before its next push.
|
|
97
115
|
|