slicekit 0.7.2 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "slicekit",
3
- "version": "0.7.2",
3
+ "version": "0.7.3",
4
4
  "description": "Spec-driven agentic workflow kit",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -10,7 +10,9 @@ import { configSubject, namesConfigAt } from './config.js';
10
10
  import { freshAt, renderPathsOnly, renderSubject } from './render.js';
11
11
  import { stateFileName, verdictFilePattern } from '../ids.js';
12
12
  import { kitPaths } from '../paths.js';
13
- import { TransitionError, readSlice, unfreeze } from '../state/index.js';
13
+ import { SliceFileError, parseSliceFile } from '../slicefile.js';
14
+ import { TransitionError, frozenOf, isFrozen, readSlice, unfreeze } from '../state/index.js';
15
+ import { SEP, TestNameError, entryLabel, findTest, isUnfrozen } from '../testnames.js';
14
16
  import { isKitFile, posixRel, runCommand, sliceIn, toWorktreePath, unusableRun } from './red.js';
15
17
  import { commitState, recordAmendment } from './record.js';
16
18
  import { BuildError, findWorktree } from './worktree.js';
@@ -65,23 +67,76 @@ function stateFileProblem(wt, stateRel, held) {
65
67
  return null;
66
68
  }
67
69
 
70
+ // The file's text at `rev` (`''` for the index), or null when it has no such file.
71
+ const textAt = (wt, rev, file) => {
72
+ try {
73
+ return git(wt, ['show', `${rev}:${file}`]);
74
+ } catch (e) {
75
+ if (e instanceof GitError) return null;
76
+ throw e;
77
+ }
78
+ };
79
+
80
+ // The slice file as it was at the red commit, read from git: a path entry of a state file written
81
+ // before P8/S-60 is read with this evaluation set, never the working tree's, which an agent can edit
82
+ // (D-102). Null when the red commit has no such file or it does not parse: every path entry is then
83
+ // the whole file, frozen for any change.
84
+ function sliceAtRed(wt, current, slice) {
85
+ if (typeof current.redCommit !== 'string' || current.redCommit === '') return null;
86
+ const rel = posixRel(wt, slice.path);
87
+ const text = textAt(wt, current.redCommit, rel);
88
+ if (text === null) return null;
89
+ try {
90
+ return parseSliceFile(text, rel);
91
+ } catch (e) {
92
+ if (e instanceof SliceFileError) return null;
93
+ throw e;
94
+ }
95
+ }
96
+
97
+ // The text of the test named `name` in `text`: null when the file or the test is missing; undefined
98
+ // when the file cannot be read by name (unparseable, or the name given twice), which never matches.
99
+ function bodyOf(text, name) {
100
+ if (text === null) return null;
101
+ try {
102
+ return findTest(text, name)?.text ?? null;
103
+ } catch (e) {
104
+ if (e instanceof TestNameError) return undefined;
105
+ throw e;
106
+ }
107
+ }
108
+
68
109
  // The first frozen test (not unfrozen) that differs from the red commit, and how: hidden from git by
69
- // skip-worktree or assume-unchanged, different bytes or missing on disk (an edit through Bash never
70
- // meets the pre-edit hook), or different in the index or a commit since (a mode change, a removal).
71
- function frozenProblem(wt, current) {
72
- for (const t of current.frozenTests) {
73
- if (current.unfrozen.includes(t)) continue;
110
+ // skip-worktree or assume-unchanged, different or missing on disk (an edit through Bash never meets
111
+ // the pre-edit hook), or different in the index or a commit since (a mode change, a removal). A test
112
+ // frozen by name (D-102) is compared by its text on disk, in the index and at HEAD; a file frozen
113
+ // whole (a state file written before P8/S-60 whose evaluation set names no test in it), by its bytes.
114
+ function frozenProblem(wt, current, slice) {
115
+ const entries = frozenOf(current, sliceAtRed(wt, current, slice)).filter((e) => !isUnfrozen(e, current.unfrozen));
116
+ const changed = (t, what = t) => `frozen test ${what} changed since ${short(current.redCommit)}; amend the slice file to change the evaluation set`;
117
+ for (const t of [...new Set(entries.map((e) => e.file))]) {
74
118
  const flag = git(wt, ['--literal-pathspecs', 'ls-files', '-v', '--', t]).slice(0, 1);
75
119
  if (flag === 'S' || (flag !== '' && flag !== flag.toUpperCase())) {
76
120
  return `frozen test ${t} is marked skip-worktree or assume-unchanged, so git cannot see its changes; clear the mark`;
77
121
  }
78
- const red = blobAt(wt, current.redCommit, t);
79
- const onDisk = fs.existsSync(path.join(wt, ...t.split('/'))) ? git(wt, ['hash-object', '--', t]) : null;
80
- const elsewhere = ['--cached', 'HEAD'].some(
81
- (where) => git(wt, ['--literal-pathspecs', 'diff', '--name-only', ...(where === 'HEAD' ? [current.redCommit, 'HEAD'] : [where, current.redCommit]), '--', t]) !== '',
82
- );
83
- if (onDisk !== red || elsewhere) {
84
- return `frozen test ${t} changed since ${short(current.redCommit)}; amend the slice file to change the evaluation set`;
122
+ const exists = fs.existsSync(path.join(wt, ...t.split('/')));
123
+ const names = entries.filter((e) => e.file === t).map((e) => e.name);
124
+ if (names.includes(null)) {
125
+ const red = blobAt(wt, current.redCommit, t);
126
+ const onDisk = exists ? git(wt, ['hash-object', '--', t]) : null;
127
+ const elsewhere = ['--cached', 'HEAD'].some(
128
+ (where) => git(wt, ['--literal-pathspecs', 'diff', '--name-only', ...(where === 'HEAD' ? [current.redCommit, 'HEAD'] : [where, current.redCommit]), '--', t]) !== '',
129
+ );
130
+ if (onDisk !== red || elsewhere) return changed(t);
131
+ continue;
132
+ }
133
+ // The file that holds the tests is gone: the file is named, as for a file frozen whole.
134
+ if (!exists || textAt(wt, '', t) === null || textAt(wt, 'HEAD', t) === null) return changed(t);
135
+ const versions = [fs.readFileSync(path.join(wt, ...t.split('/')), 'utf8'), textAt(wt, '', t), textAt(wt, 'HEAD', t)];
136
+ const atRed = textAt(wt, current.redCommit, t);
137
+ for (const name of names) {
138
+ const red = bodyOf(atRed, name);
139
+ if (versions.some((v) => { const b = bodyOf(v, name); return b === undefined || red === undefined || b !== red; })) return changed(t, entryLabel({ file: t, name }));
85
140
  }
86
141
  }
87
142
  return null;
@@ -327,7 +382,7 @@ export function commitWork(root, cfg, id, { message, requireGreen = false, workt
327
382
  const paths = staged.length > 0 ? staged : changedPaths(wt);
328
383
  const hidden = stateFileProblem(wt, stateRel, paths.includes(stateRel));
329
384
  if (hidden) throw new BuildError(hidden);
330
- const frozen = frozenProblem(wt, current);
385
+ const frozen = frozenProblem(wt, current, slice);
331
386
  if (frozen) throw new BuildError(frozen);
332
387
  const kit = paths.find((p) => isKitFile(wt, cfg, slice, p));
333
388
  if (kit) {
@@ -389,7 +444,8 @@ function isAmendment(wt, id, sliceRel, sha) {
389
444
  // The state file on disk differs from HEAD's copy only by this unfreeze (and its move to building),
390
445
  // its amendment commit is on HEAD's history, and HEAD's state is one amend runs from: its bookkeeping
391
446
  // commit did not land.
392
- function pendingUnfreeze(wt, id, stateRel, sliceRel, file) {
447
+ // `test` is the entry as unfreeze stores it: a path, or { file, name }.
448
+ function pendingUnfreeze(wt, id, stateRel, sliceRel, test) {
393
449
  const committed = committedState(wt, stateRel);
394
450
  if (!committed || !AMEND_FROM.includes(committed.state)) return false;
395
451
  const now = JSON.parse(fs.readFileSync(path.join(wt, ...stateRel.split('/')), 'utf8'));
@@ -398,10 +454,10 @@ function pendingUnfreeze(wt, id, stateRel, sliceRel, file) {
398
454
  return (
399
455
  strip(now) === strip(committed) &&
400
456
  (now.state === committed.state || now.state === 'building') &&
401
- JSON.stringify(now.unfrozen) === JSON.stringify([...committed.unfrozen, file]) &&
457
+ JSON.stringify(now.unfrozen) === JSON.stringify([...committed.unfrozen, test]) &&
402
458
  now.history.length === committed.history.length + 1 &&
403
459
  JSON.stringify(now.history.slice(0, -1)) === JSON.stringify(committed.history) &&
404
- added?.evidence?.unfreeze === file &&
460
+ added?.evidence?.unfreeze === entryLabel(test) &&
405
461
  isAmendment(wt, id, sliceRel, added?.evidence?.amendCommit)
406
462
  );
407
463
  }
@@ -427,22 +483,19 @@ function pendingAmendment(wt, id, stateRel, sliceRel) {
427
483
  return pending ? sha : null;
428
484
  }
429
485
 
430
- // `build amend` with no test named (issue #72): the slice file alone is amended and committed, and
431
- // the reason recorded in the state file. Refused while any test the slice file names is still
432
- // frozen: a frozen test changes only when amend names it. A run that stopped after the slice file's
433
- // commit, or after the record was written but before it was committed, is finished.
434
- function amendSliceOnly(wt, cfg, id, current, reason, stateRel) {
435
- const frozen = current.frozenTests.filter((t) => !current.unfrozen.includes(t));
436
- if (frozen.length > 0) {
437
- throw new BuildError(`${frozen.join(', ')} ${frozen.length === 1 ? 'is' : 'are'} frozen; name the test amend changes with --test`);
438
- }
439
- const sliceRel = posixRel(wt, sliceIn(wt, cfg, id).path);
486
+ // An amendment of the slice file that unfreezes nothing (issue #72, issue #187, D-102): the slice file
487
+ // alone is committed and the reason recorded in the state file; every frozen test stays frozen, and
488
+ // the state stays where it is. `again`, the label of a test already unfrozen that the call named, joins
489
+ // the record as `test`: a second amendment of that test. A run that stopped after the slice file's
490
+ // commit, or after the record was written but before it was committed, is finished. `none` is the
491
+ // refusal when the slice file has no change.
492
+ function amendSliceFile(wt, cfg, id, current, reason, stateRel, sliceRel, { again, none = 'amend the slice file first; it has no change' } = {}) {
440
493
  const sliceChanged = git(wt, ['--literal-pathspecs', 'status', '--porcelain', '--', sliceRel]) !== '';
441
494
  const recorded = sliceChanged ? null : pendingAmendment(wt, id, stateRel, sliceRel);
442
495
  if (recorded) {
443
496
  // The record is written; only its bookkeeping commit is left.
444
497
  commitState(wt, cfg, id, 'amend');
445
- return { sha: recorded, test: null };
498
+ return { sha: recorded, test: again ?? null, again: again !== undefined };
446
499
  }
447
500
  let sha;
448
501
  if (sliceChanged) {
@@ -451,12 +504,26 @@ function amendSliceOnly(wt, cfg, id, current, reason, stateRel) {
451
504
  // A run that committed the slice file and stopped before its record is finished.
452
505
  sha = git(wt, ['rev-parse', 'HEAD']);
453
506
  } else {
454
- throw new BuildError('amend the slice file first; it has no change');
507
+ throw new BuildError(none);
455
508
  }
456
- recordAmendment(wt, cfg, id, { amendCommit: sha, reason });
457
- return { sha, test: null };
509
+ recordAmendment(wt, cfg, id, { amendCommit: sha, reason, ...(again === undefined ? {} : { test: again }) });
510
+ return { sha, test: again ?? null, again: again !== undefined };
511
+ }
512
+
513
+ // The test `--test` names: `<file> » <name>` as { file, name } (D-102), or a bare path, the whole file.
514
+ function namedTest(wt, given) {
515
+ const text = String(given).trim();
516
+ const at = text.indexOf(SEP.trim());
517
+ if (at === -1) return toWorktreePath(wt, text);
518
+ const name = text.slice(at + SEP.trim().length).trim();
519
+ if (name === '') throw new BuildError(`--test ${text} names no test after »`, 2);
520
+ return { file: toWorktreePath(wt, text.slice(0, at).trim()), name };
458
521
  }
459
522
 
523
+ // Whether `current.unfrozen` already lifts the freeze on `test`.
524
+ const alreadyUnfrozen = (current, test) =>
525
+ typeof test === 'string' ? current.unfrozen.includes(test) : isUnfrozen(test, current.unfrozen);
526
+
460
527
  // -> { sha, test }: the slice file's amendment commit, and the test as stored. A run that stopped part
461
528
  // way (the slice file committed, or the state written but not committed) is finished, not refused.
462
529
  export function amend(root, cfg, id, { test, reason, worktree } = {}) {
@@ -467,16 +534,35 @@ export function amend(root, cfg, id, { test, reason, worktree } = {}) {
467
534
  // Where amend runs from is read from HEAD's state file, never the copy on disk.
468
535
  const committed = committedState(wt, stateRel) ?? current;
469
536
  if (!AMEND_FROM.includes(committed.state)) throw new BuildError(`${id} is ${committed.state}; amend runs from ${AMEND_FROM.join(', ')}`);
470
- if (test === undefined || (typeof test === 'string' && test.trim() === '')) return amendSliceOnly(wt, cfg, id, current, reason.trim(), stateRel);
471
- const file = toWorktreePath(wt, test);
537
+ const slice = sliceIn(wt, cfg, id);
538
+ const sliceRel = posixRel(wt, slice.path);
539
+ // No test named: the slice file alone, whatever is frozen; every frozen test stays frozen (D-102).
540
+ if (test === undefined || (typeof test === 'string' && test.trim() === '')) return amendSliceFile(wt, cfg, id, current, reason.trim(), stateRel, sliceRel);
541
+ const target = namedTest(wt, test);
542
+ const label = entryLabel(target);
543
+ // A path entry is read with the evaluation set at the red commit, not the slice file being amended.
544
+ const atRed = sliceAtRed(wt, current, slice);
545
+ // A bare file whose tests are frozen by name unfreezes nothing: each test is named (REQ-1.5, D-102).
546
+ // Only a path entry, the form of a state file written before P8/S-60, unfreezes the whole file.
547
+ if (typeof target === 'string') {
548
+ const byName = current.frozenTests.filter((e) => typeof e !== 'string' && e.file === target);
549
+ if (byName.length > 0) {
550
+ throw new BuildError(`${target} holds tests frozen by name: ${byName.map(entryLabel).join(', ')}; name the one to unfreeze as --test "<file>${SEP}<name>"`);
551
+ }
552
+ }
472
553
  // Checked before the slice file is committed; the words are unfreeze's own TransitionError reason.
473
- if (!current.frozenTests.includes(file)) throw new BuildError(`${file} is not a frozen test of ${id}`);
474
- const sliceRel = posixRel(wt, sliceIn(wt, cfg, id).path);
554
+ if (!isFrozen(current, target, atRed)) throw new BuildError(`${label} is not a frozen test of ${id}`);
475
555
  const lastAmendment = () => git(wt, ['log', '-1', '--format=%H', `--grep=^docs(${id}): amend evaluation set$`, '--', sliceRel]);
476
- if (current.unfrozen.includes(file)) {
477
- if (!pendingUnfreeze(wt, id, stateRel, sliceRel, file)) throw new BuildError(`${file} is already unfrozen`);
478
- commitState(wt, cfg, id, `unfreeze ${file}`);
479
- return { sha: lastAmendment(), test: file };
556
+ if (alreadyUnfrozen(current, target)) {
557
+ if (pendingUnfreeze(wt, id, stateRel, sliceRel, target)) {
558
+ commitState(wt, cfg, id, `unfreeze ${label}`);
559
+ return { sha: lastAmendment(), test: label };
560
+ }
561
+ // A second amendment of a test already unfrozen: the slice file and the reason are recorded.
562
+ return amendSliceFile(wt, cfg, id, current, reason.trim(), stateRel, sliceRel, {
563
+ again: label,
564
+ none: `${label} is already unfrozen; a second amendment needs a change to the slice file`,
565
+ });
480
566
  }
481
567
  let sha;
482
568
  if (git(wt, ['--literal-pathspecs', 'status', '--porcelain', '--', sliceRel]) !== '') {
@@ -487,11 +573,11 @@ export function amend(root, cfg, id, { test, reason, worktree } = {}) {
487
573
  throw new BuildError('amend the slice file first; it has no change');
488
574
  }
489
575
  try {
490
- unfreeze(wt, cfg, id, file, { amendCommit: sha, reason: reason.trim() }, { to: 'building' });
576
+ unfreeze(wt, cfg, id, target, { amendCommit: sha, reason: reason.trim() }, { to: 'building', slice: atRed });
491
577
  } catch (e) {
492
578
  if (e instanceof TransitionError) throw new BuildError(e.reason);
493
579
  throw e;
494
580
  }
495
- commitState(wt, cfg, id, `unfreeze ${file}`);
496
- return { sha, test: file };
581
+ commitState(wt, cfg, id, `unfreeze ${label}`);
582
+ return { sha, test: label };
497
583
  }
package/src/build/red.js CHANGED
@@ -7,11 +7,11 @@ import path from 'node:path';
7
7
  import { buildTestCommand } from '../config.js';
8
8
  import { readText } from '../fs.js';
9
9
  import { commitPaths, git, headSha } from '../git.js';
10
- import { stateFileName } from '../ids.js';
11
10
  import { kitPaths } from '../paths.js';
12
11
  import { findSliceFiles, parseSliceFile } from '../slicefile.js';
13
12
  import { readSlice } from '../state/index.js';
14
- import { commitBookkeeping, recordState } from './record.js';
13
+ import { TestNameError, endsWithFile, entryFile, evaluationRows, findTest } from '../testnames.js';
14
+ import { commitState, recordState } from './record.js';
15
15
  import { BuildError, findWorktree } from './worktree.js';
16
16
 
17
17
  const nonEmpty = (text) => text.split(/\r?\n/).map((l) => l.trim()).filter((l) => l !== '');
@@ -89,7 +89,6 @@ export function sliceIn(wt, cfg, id) {
89
89
  }
90
90
 
91
91
  export const posixRel = (wt, abs) => path.relative(wt, abs).split(path.sep).join('/');
92
- const escape = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
93
92
 
94
93
  // A path (POSIX, relative to the worktree) the kit owns: anything under `.slicekit/` or `.githooks/`,
95
94
  // BUILD.md, the config, the slice file and `.claude/settings.json`. The kit's commands change these;
@@ -114,35 +113,43 @@ export function unusableRun(command, run) {
114
113
  return null;
115
114
  }
116
115
 
117
- // The rows as { row, file, name }: `<file> » <name>`, or a bare `<file>` with no name.
118
- function rows(slice) {
119
- return slice.evaluation.map(({ test }) => {
120
- const row = test.replace(/^`|`$/g, '').trim();
121
- const at = row.indexOf(' » ');
122
- return {
123
- row,
124
- file: (at === -1 ? row : row.slice(0, at)).trim(),
125
- name: at === -1 ? null : row.slice(at + ' » '.length).trim(),
126
- };
127
- });
128
- }
129
-
130
- const endsWithFile = (t, file) => t === file || t.endsWith(`/${file}`);
131
- // The name inside one string literal on one line: between matching quotes or backticks.
132
- const holdsName = (text, name) =>
133
- ["'", '"', '`'].some((q) => new RegExp(`${q}[^${q}\\n]*${escape(name)}[^${q}\\n]*${q}`).test(text));
134
-
135
- // Every row names a listed file ending in <file> that holds <name> as a string; every listed file
136
- // holds at least one row.
116
+ // Every row names a listed file ending in <file> that holds a `test(...)` or `it(...)` call named
117
+ // <name> (D-102); every listed file holds at least one row. -> the frozen entries, in row order:
118
+ // { file, name } for a named row, the file's path for a bare `<file>` row. A file the reader cannot
119
+ // parse, or one giving the name to two calls, is refused: its tests cannot be frozen by name.
137
120
  function checkEvaluation(wt, slice, tests) {
138
- const all = rows(slice);
121
+ const all = evaluationRows(slice);
122
+ const texts = new Map();
123
+ const textOf = (t) => {
124
+ if (!texts.has(t)) texts.set(t, readText(path.join(wt, t)));
125
+ return texts.get(t);
126
+ };
127
+ const frozen = [];
128
+ const add = (e) => {
129
+ if (!frozen.some((f) => JSON.stringify(f) === JSON.stringify(e))) frozen.push(e);
130
+ };
139
131
  for (const { row, file, name } of all) {
140
- const found = tests.some((t) => endsWithFile(t, file) && (name === null || holdsName(readText(path.join(wt, t)), name)));
141
- if (!found) throw new BuildError(`evaluation test "${row}" is not in the test files`);
132
+ const holders = tests.filter((t) => endsWithFile(t, file));
133
+ if (name === null) {
134
+ if (holders.length === 0) throw new BuildError(`evaluation test "${row}" is not in the test files`);
135
+ for (const t of holders) add(t);
136
+ continue;
137
+ }
138
+ const found = holders.find((t) => {
139
+ try {
140
+ return findTest(textOf(t), name) !== null;
141
+ } catch (e) {
142
+ if (e instanceof TestNameError) throw new BuildError(`${t}: ${e.message}; evaluation test "${row}" cannot be found by its name`);
143
+ throw e;
144
+ }
145
+ });
146
+ if (!found) throw new BuildError(`evaluation test "${row}" is not in the test files: no test(...) or it(...) call in ${holders.length > 0 ? holders.join(', ') : 'them'} is named "${name}"`);
147
+ add({ file: found, name });
142
148
  }
143
149
  for (const t of tests) {
144
150
  if (!all.some(({ file }) => endsWithFile(t, file))) throw new BuildError(`${t} holds no evaluation test`);
145
151
  }
152
+ return frozen;
146
153
  }
147
154
 
148
155
  // HEAD is this slice's red commit when it touches exactly the listed tests under the evaluation-set
@@ -165,19 +172,17 @@ function unchanged(wt, tests) {
165
172
  const noChange = (files) => new BuildError(`${files.join(', ')} have no change to commit; red needs the evaluation set as new or changed files`);
166
173
 
167
174
  // A run from tests-red: setState wrote tests-red but its bookkeeping commit, or the move to building,
168
- // did not land. The tests must be the frozen ones; nothing is run again.
175
+ // did not land. The tests must be the files of the frozen ones; nothing is run again. The bookkeeping
176
+ // commit holds the state file alone: a slice branch commits no BUILD.md (D-100, issue #210).
169
177
  function finishRed(wt, cfg, id, current, tests) {
170
178
  const files = resolveTests(wt, tests).sort();
171
- const frozen = [...current.frozenTests].sort();
179
+ const frozen = [...new Set(current.frozenTests.map(entryFile))].sort();
172
180
  if (files.length !== frozen.length || files.some((f, i) => f !== frozen[i])) {
173
- throw new BuildError(`${id} is tests-red with frozen tests ${current.frozenTests.join(', ')}; pass the same --tests`);
181
+ throw new BuildError(`${id} is tests-red with frozen tests ${frozen.join(', ')}; pass the same --tests`);
174
182
  }
175
- const paths = kitPaths(wt, cfg);
176
- const bookkeeping = [posixRel(wt, path.join(paths.state, stateFileName(id)))];
177
- if (fs.existsSync(paths.build)) bookkeeping.push(posixRel(wt, paths.build));
178
- commitBookkeeping(wt, id, 'tests-red', bookkeeping);
183
+ commitState(wt, cfg, id, 'tests-red');
179
184
  recordState(wt, cfg, id, 'building', {});
180
- return { commit: current.redCommit, tests: current.frozenTests };
185
+ return { commit: current.redCommit, tests: frozen };
181
186
  }
182
187
 
183
188
  export function red(root, cfg, id, { tests, worktree, env = process.env } = {}) {
@@ -190,7 +195,7 @@ export function red(root, cfg, id, { tests, worktree, env = process.env } = {})
190
195
  const files = resolveTests(wt, tests);
191
196
  const slice = sliceIn(wt, cfg, id);
192
197
  refuseKitFiles(wt, cfg, slice, files);
193
- checkEvaluation(wt, slice, files);
198
+ const frozen = checkEvaluation(wt, slice, files);
194
199
  const same = unchanged(wt, files);
195
200
  if (same.length > 0 && !headIsRedCommit(wt, id, files)) throw noChange(same);
196
201
 
@@ -202,7 +207,7 @@ export function red(root, cfg, id, { tests, worktree, env = process.env } = {})
202
207
  const made = commitPaths(wt, files, `test(${id}): evaluation set\n\nran: ${command} → exit ${run.exit}\n\nSlice: ${id}`);
203
208
  if (made === null && !headIsRedCommit(wt, id, files)) throw noChange(files);
204
209
  const commit = made ?? headSha(wt);
205
- recordState(wt, cfg, id, 'tests-red', { commit, testExit: run.exit, tests: files });
210
+ recordState(wt, cfg, id, 'tests-red', { commit, testExit: run.exit, tests: files, frozen });
206
211
  recordState(wt, cfg, id, 'building', {});
207
212
  return { commit, tests: files, local: local ? command : null };
208
213
  }
@@ -1,8 +1,12 @@
1
- // frozen (03 REQ-3.15, D-10): on a slice branch, a test of the slice's evaluation set stays as it was at
2
- // the red commit recorded in the slice's state file, unless the slice file was changed in a commit
3
- // after the red commit (as `build amend` does). The state file, the red commit, the slice file and
4
- // the tests are all read from git objects of the tip judged, never the working tree: a file hidden
5
- // with `assume-unchanged` or `skip-worktree` is judged by its committed content (issue #71).
1
+ // frozen (03 REQ-3.15, D-10, D-102): on a slice branch, a test of the slice's evaluation set, found by
2
+ // its name in its file, stays as it was at the red commit recorded in the slice's state file, unless
3
+ // `build amend` unfroze that test after the red commit: the tip's state file lists it in `unfrozen`
4
+ // and the slice file was changed in a commit after red. Other tests of the same file are not
5
+ // compared. A path entry of a state file written before P8/S-60 is every evaluation test of that file
6
+ // by name in the slice file at the red commit, or the whole file when that evaluation set names none
7
+ // in it. The state file, the red commit, the slice file and the tests are all read from git objects
8
+ // (of the tip judged, or of the red commit), never the working tree: a file hidden with
9
+ // `assume-unchanged` or `skip-worktree` is judged by its committed content (issue #71).
6
10
  //
7
11
  // The tip is HEAD, or under --ci on a pull request the pull request's head (branchTip). No branch, a
8
12
  // branch that is not a slice branch, no red commit recorded in any version of the state file (a slice
@@ -22,7 +26,8 @@ import { GitError, git, resolveCommit } from '../../git.js';
22
26
  import { branchTip } from '../ci-event.js';
23
27
  import { parseSliceAddr, sliceFromBranch, stateFileName } from '../../ids.js';
24
28
  import { kitPaths } from '../../paths.js';
25
- import { phaseOfDir } from '../../slicefile.js';
29
+ import { SliceFileError, parseSliceFile, phaseOfDir } from '../../slicefile.js';
30
+ import { TestNameError, entryFile, entryLabel, evaluationRows, findTest, frozenEntries, isEntry, isUnfrozen } from '../../testnames.js';
26
31
 
27
32
  export const id = 'frozen';
28
33
  export const blocking = true;
@@ -115,22 +120,68 @@ export function run(ctx) {
115
120
  return [...removed, { file: stateRel, line: 0, message: `red commit ${red} of ${slice} is not in this repository` }];
116
121
  }
117
122
 
118
- const tests = [...new Set(listed)];
119
- const bad = tests.filter((t) => !validTest(t));
120
- if (bad.length > 0) return [...removed, { file: stateRel, line: 0, message: `frozen tests of ${slice} name a path that is not a repository path: ${bad.map(String).join(', ')}` }];
121
- if (tests.length === 0) return removed;
123
+ const bad = listed.filter((t) => !isEntry(t) || !validTest(entryFile(t)));
124
+ if (bad.length > 0) return [...removed, { file: stateRel, line: 0, message: `frozen tests of ${slice} name a path that is not a repository path: ${bad.map((t) => (isEntry(t) ? entryLabel(t) : JSON.stringify(t))).join(', ')}` }];
125
+ if (listed.length === 0) return removed;
122
126
 
123
- // An amendment of the slice file after the red commit lifts the freeze (REQ-3.3). Only the slice
124
- // branch's own commits count: --first-parent --no-merges leaves out a change to the slice file made on
125
- // the default branch and merged into the slice branch.
126
- const sliceFiles = sliceFilesAt(root, tip, posixRel(root, paths.phases), addr);
127
- if (sliceFiles.length > 0) {
128
- const amended = git(root, ['--literal-pathspecs', 'log', '--first-parent', '--no-merges', '--format=%H', `${red}..${tip}`, '--', ...sliceFiles]);
129
- if (amended !== '') return removed;
127
+ // The slice file at the red commit: its evaluation set reads a path entry, the form of a state file
128
+ // written before P8/S-60, as every evaluation test of that file by name (D-102). A later change to
129
+ // the slice file does not change what is frozen; with no slice file at red that parses, a path
130
+ // entry is the whole file.
131
+ const phasesRel = posixRel(root, paths.phases);
132
+ const sliceFiles = sliceFilesAt(root, tip, phasesRel, addr);
133
+ const redSliceFiles = sliceFilesAt(root, red, phasesRel, addr);
134
+ let rows = [];
135
+ if (redSliceFiles.length === 1) {
136
+ try {
137
+ rows = evaluationRows(parseSliceFile(showAt(root, red, redSliceFiles[0]) ?? '', redSliceFiles[0]));
138
+ } catch (e) {
139
+ if (!(e instanceof SliceFileError)) throw e;
140
+ }
130
141
  }
142
+ const entries = frozenEntries(listed, rows);
143
+
144
+ // A test `build amend` unfroze after the red commit is not judged (REQ-3.15): the tip's state file
145
+ // lists it in `unfrozen`, and the slice file was amended after red. An amendment of the slice file
146
+ // alone unfreezes nothing (D-102). Only the slice branch's own commits count: --first-parent
147
+ // --no-merges leaves out a change to the slice file made on the default branch and merged in.
148
+ const amended = sliceFiles.length > 0
149
+ && git(root, ['--literal-pathspecs', 'log', '--first-parent', '--no-merges', '--format=%H', `${red}..${tip}`, '--', ...sliceFiles]) !== '';
150
+ const tipState = text === null ? null : parse(text);
151
+ const unfrozen = amended && Array.isArray(tipState?.unfrozen) ? tipState.unfrozen.filter(isEntry) : [];
152
+ const judged = entries.filter((e) => !isUnfrozen(e, unfrozen));
153
+ if (judged.length === 0) return removed;
131
154
 
132
- const changed = new Set(lines(git(root, ['--literal-pathspecs', 'diff', '--name-only', '--no-renames', red, tip, '--', ...tests])));
133
- return [...removed, ...tests.filter((t) => changed.has(t)).map((t) => ({ file: t, line: 0, message: `frozen test changed after red: ${t}` }))];
155
+ const files = [...new Set(judged.map((e) => e.file))];
156
+ const changed = new Set(lines(git(root, ['--literal-pathspecs', 'diff', '--name-only', '--no-renames', red, tip, '--', ...files])));
157
+ const findings = [];
158
+ for (const e of judged) {
159
+ if (!changed.has(e.file)) continue;
160
+ if (e.name === null) {
161
+ findings.push({ file: e.file, line: 0, message: `frozen test changed after red: ${e.file}` });
162
+ continue;
163
+ }
164
+ // A test frozen by name: its text at the tip against its text at red; another test of the file,
165
+ // or any other line of it, is not compared. A file that cannot be read by name is a change.
166
+ const before = bodyOf(showAt(root, red, e.file), e.name);
167
+ const after = bodyOf(showAt(root, tip, e.file), e.name);
168
+ if (after === null || after === undefined || before === undefined || after !== before) {
169
+ findings.push({ file: e.file, line: 0, message: `frozen test changed after red: ${entryLabel(e)}` });
170
+ }
171
+ }
172
+ return [...removed, ...findings];
173
+ }
174
+
175
+ // The text of the test named `name` in `text`: null when the file or the test is missing; undefined
176
+ // when the file cannot be read by name (unparseable, or the name given twice).
177
+ function bodyOf(text, name) {
178
+ if (text === null) return null;
179
+ try {
180
+ return findTest(text, name)?.text ?? null;
181
+ } catch (e) {
182
+ if (e instanceof TestNameError) return undefined;
183
+ throw e;
184
+ }
134
185
  }
135
186
 
136
187
  export default { id, blocking, ratchet, run };
package/src/cli/build.js CHANGED
@@ -28,7 +28,7 @@ import { INDEPENDENT_MISSING } from '../state/transitions.js';
28
28
 
29
29
  const SUBCOMMANDS = ['next', 'start', 'red', 'commit', 'render', 'config', 'amend', 'pr', 'verdict', 'decline', 'finish', 'sync', 'parallel'];
30
30
  const USAGE =
31
- 'build next | build start <id> [--descr <d>] | build parallel P<n> | build red <id> --tests <a,b> [--worktree <p>] | build commit <id> --message <m> [--require-green] [--worktree <p>] (commits the staged paths; with nothing staged, every changed path) | build render <id> [--worktree <p>] | build config <id> [--worktree <p>] | build amend <id> [--test <path>] --reason <r> [--worktree <p>] (no --test: the slice file alone, once every test it names is unfrozen) | build pr <id> [--notes <file>] [--worktree <p>] | build verdict <id> <file> [--independent] [--worktree <p>] | build decline <id> <H-n> [--worktree <p>] | build finish <id> [--wait <s>, default 90] [--worktree <p>] | build sync <id> [--worktree <p>]';
31
+ 'build next | build start <id> [--descr <d>] | build parallel P<n> | build red <id> --tests <a,b> [--worktree <p>] | build commit <id> --message <m> [--require-green] [--worktree <p>] (commits the staged paths; with nothing staged, every changed path) | build render <id> [--worktree <p>] | build config <id> [--worktree <p>] | build amend <id> [--test "<file> » <name>" | --test <file>] --reason <r> [--worktree <p>] (no --test: the slice file alone, every frozen test stays frozen) | build pr <id> [--notes <file>] [--worktree <p>] | build verdict <id> <file> [--independent] [--worktree <p>] | build decline <id> <H-n> [--worktree <p>] | build finish <id> [--wait <s>, default 90] [--worktree <p>] | build sync <id> [--worktree <p>]';
32
32
 
33
33
  const OPTIONS = {
34
34
  descr: { type: 'string' },
@@ -140,8 +140,10 @@ function configStep(root, io, positionals, values) {
140
140
  function amendStep(root, io, positionals, values) {
141
141
  if (positionals.length !== 1 || values.reason === undefined) return usage(io);
142
142
  const cfg = loadConfig(root);
143
- const { sha, test } = amend(root, cfg, positionals[0], { test: values.test, reason: values.reason, worktree: values.worktree });
144
- io.stdout(test === null ? `${sha.slice(0, 7)} amended the slice file\n` : `unfroze ${test}\n`);
143
+ const { sha, test, again } = amend(root, cfg, positionals[0], { test: values.test, reason: values.reason, worktree: values.worktree });
144
+ // A second amendment of a test already unfrozen unfreezes nothing (D-102).
145
+ if (again) io.stdout(`${sha.slice(0, 7)} amended the slice file; ${test} was already unfrozen\n`);
146
+ else io.stdout(test === null ? `${sha.slice(0, 7)} amended the slice file\n` : `unfroze ${test}\n`);
145
147
  return 0;
146
148
  }
147
149
 
@@ -5,6 +5,7 @@ import path from 'node:path';
5
5
  import { GitError, currentBranch } from '../git.js';
6
6
  import { sliceFromBranch } from '../ids.js';
7
7
  import { readSlice } from '../state/index.js';
8
+ import { entryFile, isEntry } from '../testnames.js';
8
9
 
9
10
  export const toPosix = (p) => p.split(path.sep).join('/');
10
11
 
@@ -115,26 +116,40 @@ export function activeSlice(root, cfg) {
115
116
  // The slice states in which its frozen tests are guarded (REQ-3.3).
116
117
  export const GUARDED_STATES = new Set(['tests-red', 'building']);
117
118
 
118
- const stringList = (v) => Array.isArray(v) && v.every((s) => typeof s === 'string');
119
+ // A state file's `frozenTests` and `unfrozen`: each entry a path (a whole file, the form written before
120
+ // P8/S-60) or { file, name } (a test frozen by its name, D-102). Throws on any other shape, so a guard
121
+ // reading them fails closed.
122
+ export function checkFrozenLists(active) {
123
+ for (const field of ['frozenTests', 'unfrozen']) {
124
+ const v = active.state[field];
125
+ if (!Array.isArray(v) || !v.every(isEntry)) throw new Error(`${active.id} state: ${field} must be an array of strings (paths) or { file, name } entries`);
126
+ }
127
+ }
119
128
 
120
- // The tests frozen for root's active slice: {id, files: [POSIX path relative to root's real path]},
121
- // with `unfrozen` ones left out; null when tests are not frozen, no slice is active, or the slice is
122
- // not in a guarded state. Throws when the state file cannot be read or its lists are malformed, so a
123
- // guard calling it fails closed.
129
+ // The files that hold a test frozen for root's active slice: {id, files: [POSIX path relative to root's
130
+ // real path]}. A file is left out once `unfrozen` lists it whole, or lists every test frozen in it by
131
+ // name; a path entry is the whole file. Null when tests are not frozen, no slice is active, or the slice
132
+ // is not in a guarded state. Throws when the state file cannot be read or its lists are malformed, so
133
+ // a guard calling it fails closed.
124
134
  export function frozenTests(root, cfg) {
125
135
  if (!cfg.freezeTests) return null;
126
136
  const active = activeSlice(root, cfg);
127
137
  if (!active) return null;
128
138
  if (active.error) throw new Error(active.error);
129
- for (const field of ['frozenTests', 'unfrozen']) {
130
- if (!stringList(active.state[field])) throw new Error(`${active.id} state: ${field} must be an array of strings`);
131
- }
139
+ checkFrozenLists(active);
132
140
  if (!GUARDED_STATES.has(active.state.state)) return null;
133
141
  const canon = real(path.resolve(root));
134
142
  const rel = (f) => toPosix(path.relative(canon, real(path.resolve(canon, fromGitBash(f.replace(/\\/g, '/'))))));
135
143
  const key = (p) => (process.platform === 'win32' ? p.toLowerCase() : p);
136
- const unfrozen = new Set(active.state.unfrozen.map((f) => key(rel(f))));
137
- const files = active.state.frozenTests.map(rel).filter((f) => !unfrozen.has(key(f)));
144
+ const norm = (e) => (typeof e === 'string' ? { file: key(rel(e)), name: null } : { file: key(rel(e.file)), name: e.name });
145
+ const unfrozen = active.state.unfrozen.map(norm);
146
+ const lifted = (e) => unfrozen.some((u) => u.file === e.file && (u.name === null || (e.name !== null && u.name === e.name)));
147
+ const files = [];
148
+ for (const e of active.state.frozenTests) {
149
+ if (lifted(norm(e))) continue;
150
+ const f = rel(entryFile(e));
151
+ if (!files.some((g) => key(g) === key(f))) files.push(f);
152
+ }
138
153
  return { id: active.id, files };
139
154
  }
140
155
 
@@ -10,9 +10,13 @@
10
10
  // — always; (4) a path that matches a pattern of the root's `agents.denyPaths` (REQ-3.13) — always;
11
11
  // then, only while
12
12
  // the file's own root has an active slice (a `slice/*` branch with a state file) in `tests-red` or
13
- // `building`: (1) a frozen test of that slice, unless `unfrozen` lists it; (2) a file under the docs root
14
- // that does not exist yet (only a create can name a missing file), except the runbook and anything in
15
- // the slice's own phase directory.
13
+ // `building`: (1) a change to a frozen test of that slice, unless `unfrozen` lists it: a test frozen by
14
+ // name (D-102) is denied when the call changes its text against the red commit, removes it or renames
15
+ // it, and another test or line of the same file may change; a file frozen whole (a path entry of a
16
+ // state file written before P8/S-60 whose evaluation set names no test in it) is denied for any
17
+ // change; (2) a file under the docs root that does not exist yet (only a create can name a missing
18
+ // file), except the runbook, anything in the slice's own phase directory, and a path the slice file's
19
+ // Expected changes names (D-102).
16
20
  //
17
21
  // The file's own root is the nearest directory above it holding `.slicekit/config.json`, else its git
18
22
  // top level, else the session's root: a session in the main checkout editing a nested worktree is
@@ -29,9 +33,10 @@ import { CONFIG_PATH, loadConfig } from '../config.js';
29
33
  import { GitError, git } from '../git.js';
30
34
  import { parseSliceAddr } from '../ids.js';
31
35
  import { kitPaths } from '../paths.js';
32
- import { phaseOfDir } from '../slicefile.js';
36
+ import { findSliceFiles, parseSliceFile, phaseOfDir } from '../slicefile.js';
37
+ import { TestNameError, entryFile, evaluationRows, findTest, frozenEntries, isUnfrozen } from '../testnames.js';
33
38
  import { allow, deny } from './io.js';
34
- import { activeSlice, denyPaths, existingAncestor, fromGitBash, leaves, matchesDeny, namesUnder, real, toPosix } from './paths.js';
39
+ import { activeSlice, checkFrozenLists, denyPaths, existingAncestor, fromGitBash, leaves, matchesDeny, namesUnder, real, toPosix } from './paths.js';
35
40
 
36
41
  const WIN = process.platform === 'win32';
37
42
  const GUARDED_STATES = new Set(['tests-red', 'building']);
@@ -115,7 +120,6 @@ function ownRoot(abs) {
115
120
  return top ? { root: top, config: false } : null;
116
121
  }
117
122
 
118
- const stringList = (v) => Array.isArray(v) && v.every((s) => typeof s === 'string');
119
123
 
120
124
  // Whether rel lies inside the slice's own phase directory, `<docs>/phases/P<n>[-name]/`.
121
125
  function inOwnPhase(rel, phasesRel, sliceId) {
@@ -161,20 +165,14 @@ function judge(filePath, input, hookRoot, hookCfg) {
161
165
 
162
166
  const active = activeSlice(root, cfg);
163
167
  if (active?.error) throw new Error(active.error);
164
- if (active) {
165
- for (const field of ['frozenTests', 'unfrozen']) {
166
- if (!stringList(active.state[field])) throw new Error(`${active.id} state: ${field} must be an array of strings`);
167
- }
168
- }
168
+ if (active) checkFrozenLists(active);
169
169
  if (!active || !GUARDED_STATES.has(active.state.state)) return allow();
170
170
  const { id, state } = active;
171
+ const slice = sliceOf(root, cfg, id);
171
172
 
172
173
  // (1)
173
- if (cfg.freezeTests) {
174
- const listed = (list) => list.some((f) => same(rel, normalise(f, root) ?? ''));
175
- if (listed(state.frozenTests) && !listed(state.unfrozen)) {
176
- return deny(`frozen for ${id}; amend the slice file to change the evaluation set`);
177
- }
174
+ if (cfg.freezeTests && changesFrozen(root, rel, abs, state, slice, input)) {
175
+ return deny(`frozen for ${id}; amend the slice file to change the evaluation set`);
178
176
  }
179
177
 
180
178
  // (2)
@@ -182,12 +180,145 @@ function judge(filePath, input, hookRoot, hookCfg) {
182
180
  const docs = toPosix(path.relative(root, k.docs));
183
181
  if (under(rel, docs) && !same(rel, docs) && !fs.existsSync(abs)
184
182
  && !same(rel, toPosix(path.relative(root, k.runbook)))
185
- && !inOwnPhase(rel, toPosix(path.relative(root, k.phases)), id)) {
183
+ && !inOwnPhase(rel, toPosix(path.relative(root, k.phases)), id)
184
+ && !namedInExpected(rel, sliceAtHead(root, slice))) {
186
185
  return deny("no slice starts a document; a document changes only when this slice's code made it wrong");
187
186
  }
188
187
  return allow();
189
188
  }
190
189
 
190
+ // The active slice's parsed slice file under root, or null when none parses with that id.
191
+ function sliceOf(root, cfg, id) {
192
+ for (const f of findSliceFiles(root, cfg)) {
193
+ try {
194
+ const s = parseSliceFile(fs.readFileSync(f.path, 'utf8'), f.path);
195
+ if (s.id === id) return s;
196
+ } catch {
197
+ // A slice file that does not parse names nothing.
198
+ }
199
+ }
200
+ return null;
201
+ }
202
+
203
+ // The slice file as committed at HEAD (D-102). The guard allows an Edit of the slice file, so the
204
+ // new-document exception reads Expected changes from git: only `build amend` commits the slice file.
205
+ // Null when the file is not at HEAD or does not parse (names nothing). A repository with no commit
206
+ // yet has no HEAD to read; its slice file is the working tree's.
207
+ function sliceAtHead(root, slice) {
208
+ if (!slice?.path) return null;
209
+ const rel = relInside(root, real(slice.path));
210
+ if (rel === null) return null;
211
+ let text;
212
+ try {
213
+ text = git(root, ['show', `HEAD:./${rel}`]);
214
+ } catch (e) {
215
+ if (!(e instanceof GitError)) throw e;
216
+ try {
217
+ git(root, ['rev-parse', '--verify', '--quiet', 'HEAD']);
218
+ return null;
219
+ } catch (e2) {
220
+ if (e2 instanceof GitError) return slice;
221
+ throw e2;
222
+ }
223
+ }
224
+ try {
225
+ return parseSliceFile(text, slice.path);
226
+ } catch {
227
+ return null;
228
+ }
229
+ }
230
+
231
+ // The slice file's Expected changes name `rel` (D-102): a new document the slice was planned to write.
232
+ const namedInExpected = (rel, slice) =>
233
+ (slice?.expectedChanges ?? []).some((p) => same(rel, toPosix(path.posix.normalize(p.replace(/\\/g, '/'))).replace(/^\.\//, '')));
234
+
235
+ // The file's text after the tool call: Write's content, or Edit's and MultiEdit's replacements applied
236
+ // to the text on disk. Null when the call cannot be applied, so it cannot be judged (fails closed).
237
+ function textAfter(abs, input) {
238
+ const tool = input?.tool_name;
239
+ const ti = input?.tool_input ?? {};
240
+ if (tool === 'Write') return typeof ti.content === 'string' ? ti.content : null;
241
+ const edits = tool === 'Edit' ? [ti] : tool === 'MultiEdit' && Array.isArray(ti.edits) ? ti.edits : null;
242
+ if (!edits || !fs.existsSync(abs)) return null;
243
+ let text = fs.readFileSync(abs, 'utf8');
244
+ for (const e of edits) {
245
+ if (typeof e?.old_string !== 'string' || typeof e?.new_string !== 'string' || e.old_string === '') return null;
246
+ let from = e.old_string;
247
+ if (!text.includes(from)) {
248
+ // The tool matches across line endings; so does the guard.
249
+ text = text.replace(/\r\n/g, '\n');
250
+ from = from.replace(/\r\n/g, '\n');
251
+ if (!text.includes(from)) return null;
252
+ }
253
+ const to = e.new_string.replace(/\r\n/g, text.includes('\r\n') ? '\r\n' : '\n');
254
+ text = e.replace_all === true ? text.split(from).join(to) : text.replace(from, () => to);
255
+ }
256
+ return text;
257
+ }
258
+
259
+ // The text of the test named `name`: null when missing; undefined when the file cannot be read by name.
260
+ function bodyOf(text, name) {
261
+ if (text === null) return null;
262
+ try {
263
+ return findTest(text, name)?.text ?? null;
264
+ } catch (e) {
265
+ if (e instanceof TestNameError) return undefined;
266
+ throw e;
267
+ }
268
+ }
269
+
270
+ // The slice file as it was at the red commit, read from git (D-102): a path entry of a state file
271
+ // written before P8/S-60 is read with that evaluation set, never the working tree's, which this guard
272
+ // does not protect. Null when there is no red commit, no such file at it, or it does not parse: each
273
+ // path entry is then the whole file, frozen for any change (fails closed).
274
+ function sliceAtRed(root, state, slice) {
275
+ if (!slice?.path || typeof state.redCommit !== 'string' || state.redCommit === '') return null;
276
+ const rel = relInside(root, real(slice.path));
277
+ if (rel === null) return null;
278
+ let text;
279
+ try {
280
+ text = git(root, ['show', `${state.redCommit}:./${rel}`]);
281
+ } catch (e) {
282
+ if (e instanceof GitError) return null;
283
+ throw e;
284
+ }
285
+ try {
286
+ return parseSliceFile(text, slice.path);
287
+ } catch {
288
+ return null;
289
+ }
290
+ }
291
+
292
+ // Whether the call changes, removes or renames a test frozen in `rel` (REQ-3.3, D-102). A file frozen
293
+ // whole (a path entry the evaluation set names no test in) is denied for any change; a test frozen by
294
+ // name, only when its text after the call differs from its text at the red commit. Another test of
295
+ // the file, or any other line, may change.
296
+ function changesFrozen(root, rel, abs, state, slice, input) {
297
+ const at = (f) => normalise(f, root) ?? '';
298
+ const mine = state.frozenTests.filter((e) => same(rel, at(entryFile(e))));
299
+ if (mine.length === 0) return false;
300
+ const local = (e) => (typeof e === 'string' ? rel : { file: rel, name: e.name });
301
+ const unfrozen = state.unfrozen.filter((e) => same(rel, at(entryFile(e)))).map(local);
302
+ const rows = mine.some((e) => typeof e === 'string') ? evaluationRows(sliceAtRed(root, state, slice)) : [];
303
+ const entries = frozenEntries(mine.map(local), rows, same).filter((e) => !isUnfrozen(e, unfrozen, same));
304
+ if (entries.length === 0) return false;
305
+ if (entries.some((e) => e.name === null)) return true;
306
+ const after = textAfter(abs, input);
307
+ if (after === null) return true;
308
+ let atRed = null;
309
+ try {
310
+ atRed = git(root, ['show', `${state.redCommit}:./${rel}`]);
311
+ } catch (e) {
312
+ if (!(e instanceof GitError)) throw e;
313
+ }
314
+ if (typeof state.redCommit !== 'string' || atRed === null) return true;
315
+ return entries.some((e) => {
316
+ const before = bodyOf(atRed, e.name);
317
+ const now = bodyOf(after, e.name);
318
+ return before === undefined || before === null || now === undefined || now === null || before !== now;
319
+ });
320
+ }
321
+
191
322
  export function handle(input, { root, cfg }) {
192
323
  const given = PATH_KEYS.filter((k) => input?.tool_input?.[k] !== undefined);
193
324
  if (!given.length) throw new Error('tool_input.file_path is missing');
@@ -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
- // Only a test frozen at tests-red can be unfrozen; any other path has nothing to release. `extra`
191
- // joins the history entry's evidence (build amend gives the amendment commit and the reason). `to`
192
- // moves the slice in the same write: build amend during review takes it back to building (D-43).
193
- export function unfreeze(root, cfg, id, file, extra = {}, { to } = {}) {
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
- if (!current.frozenTests.includes(file)) {
197
- throw new TransitionError(`${file} is not a frozen test of ${id}`);
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: file, ...extra })],
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;
@@ -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
- apply: (_current, ev) => ({ redCommit: ev.commit, frozenTests: [...ev.tests] }),
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) => !present(ctx.root, 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
  },
@@ -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
+ }
@@ -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 refusal naming
78
- a frozen test means the developer changed one: send it back with the message. While tests still
79
- fail, spawn the developer again with what is left.
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>`, and tell
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 every test it names is already unfrozen, there is no test
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 prints
101
- `<sha7> amended the slice file`. While a test is still frozen it refuses: name that test with
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