bmad-method-test-architecture-enterprise 3.3.0 → 3.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/cli/lib/evaluate/test-design-replay.js +3 -2
- package/package.json +2 -2
- package/skills/bmad-tea-automate/SKILL.md +1 -0
- package/skills/bmad-tea-automate/red/atdd-checklist-template.md +7 -2
- package/skills/bmad-tea-automate/red/checklist.md +1 -1
- package/skills/bmad-tea-automate/red/resources/atdd-checklist-2-4-guest-checkout.example.md +5 -2
- package/skills/bmad-tea-automate/red/steps-c/step-01-preflight-and-context.md +12 -14
- package/skills/bmad-tea-automate/red/steps-c/step-01b-resume.md +4 -2
- package/skills/bmad-tea-automate/red/steps-c/step-04c-aggregate.md +7 -5
- package/skills/bmad-tea-automate/red/steps-c/step-05-validate-and-complete.md +5 -3
- package/skills/bmad-tea-automate/steps-c/step-01-preflight-and-context.md +4 -2
- package/skills/bmad-tea-automate/steps-c/step-01b-resume.md +2 -0
- package/skills/bmad-tea-automate/steps-c/step-02-identify-targets.md +1 -1
- package/skills/bmad-tea-evaluate/references/ci.md +2 -2
- package/skills/bmad-tea-framework/resources/framework-setup-progress.example.md +1 -1
- package/skills/bmad-tea-framework/resources/hooks/tea-enforce.cjs +295 -39
- package/skills/bmad-tea-framework/steps-c/step-04-docs-and-scripts.md +2 -2
- package/skills/bmad-tea-nfr/SKILL.md +1 -0
- package/skills/bmad-tea-nfr/steps-c/step-01-load-context.md +4 -2
- package/skills/bmad-tea-nfr/steps-c/step-01b-resume.md +2 -0
- package/skills/bmad-tea-test-design/checklist.md +39 -8
- package/skills/bmad-tea-test-design/steps-c/step-01-detect-mode.md +4 -1
- package/skills/bmad-tea-test-design/steps-c/step-03-risk-and-testability.md +1 -1
- package/skills/bmad-tea-test-design/steps-c/step-04-coverage-plan.md +10 -3
- package/skills/bmad-tea-test-design/steps-c/step-05-generate-output.md +69 -21
- package/skills/bmad-tea-test-design/steps-e/step-02-apply-edit.md +3 -0
- package/skills/bmad-tea-test-design/steps-v/step-01-validate.md +1 -0
- package/skills/bmad-tea-test-design/test-design-qa-template.md +1 -1
- package/skills/bmad-tea-test-review/SKILL.md +2 -1
- package/skills/bmad-tea-test-review/steps-c/step-01-load-context.md +7 -4
- package/skills/bmad-tea-test-review/steps-c/step-01b-resume.md +2 -0
- package/skills/bmad-tea-trace/SKILL.md +1 -0
- package/skills/bmad-tea-trace/steps-c/step-01-load-context.md +6 -4
- package/skills/bmad-tea-trace/steps-c/step-01b-resume.md +2 -0
- package/skills/bmod-tea/bmod.toml +1 -1
- package/skills/bmod-tea/contracts/story-identity.md +77 -0
- package/skills/bmod-tea/help/help.md +38 -6
- package/skills/bmod-tea/migration-2.toml +100 -0
|
@@ -32,19 +32,24 @@
|
|
|
32
32
|
* 3. A whole-file rule (H5's 1000-line ceiling, C4's "this flow asserts nothing
|
|
33
33
|
* anywhere") cannot be decided from a fragment at all.
|
|
34
34
|
*
|
|
35
|
-
* So: `--pre` is the fast block on the
|
|
35
|
+
* So: `--pre` is the fast block on the write about to land. For an Edit or
|
|
36
|
+
* MultiEdit it applies the edit to the file on disk and scans the result whole,
|
|
37
|
+
* reporting only what the edit introduced, so a fragment inside an existing
|
|
38
|
+
* comment is read as a comment and a violation spanning the fragment's edge is
|
|
39
|
+
* seen; it scans the bare fragment only when the file cannot be read. `--post`
|
|
36
40
|
* re-reads the affected file(s) from disk in full and applies the same rules,
|
|
37
|
-
* which is what catches Bash writes
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* for `Write`, where the whole content is genuinely present.
|
|
41
|
+
* which is what catches Bash writes; `--stop` sweeps recently modified test files
|
|
42
|
+
* at the end of a turn, which is what catches a codegen script that wrote files it
|
|
43
|
+
* never named. File-scope rules (H5, C4) skip only that bare-fragment fallback.
|
|
41
44
|
*
|
|
42
45
|
* FALSE POSITIVES
|
|
43
46
|
*
|
|
44
47
|
* Comments and string literals are stripped, per language, before any pattern runs.
|
|
45
48
|
* A doc example that writes `await page.waitForTimeout(500)` inside a fenced block
|
|
46
49
|
* in a `.md` is not a violation and this hook does not claim it is. Line numbers
|
|
47
|
-
* survive stripping because stripped characters are replaced by spaces.
|
|
50
|
+
* survive stripping because stripped characters are replaced by spaces. Rules
|
|
51
|
+
* whose construct a formatter splits across lines (C2, C3) match the whole
|
|
52
|
+
* stripped source and map each match back to the line it starts on.
|
|
48
53
|
*
|
|
49
54
|
* GATES
|
|
50
55
|
*
|
|
@@ -282,7 +287,31 @@ function blank(length) {
|
|
|
282
287
|
return ' '.repeat(length);
|
|
283
288
|
}
|
|
284
289
|
|
|
285
|
-
|
|
290
|
+
/**
|
|
291
|
+
* A string or regex literal, rendered for the requested view: blanked (the
|
|
292
|
+
* default, for matching), kept (for reading operands), or masked with `x` (for
|
|
293
|
+
* knowing which characters of a kept operand are inside a literal; see
|
|
294
|
+
* `codeInMask` for everything else in that view). Every view
|
|
295
|
+
* is the same length, so offsets line up across all three. The blanked view keeps
|
|
296
|
+
* newlines so line numbers survive; the mask marks them too, because a newline
|
|
297
|
+
* inside a literal is part of its value.
|
|
298
|
+
*/
|
|
299
|
+
function literal(source, start, end, mode) {
|
|
300
|
+
const text = source.slice(start, end);
|
|
301
|
+
if (mode === 'keep') return text;
|
|
302
|
+
if (mode === 'mask') return 'x'.repeat(text.length);
|
|
303
|
+
return text.replaceAll(/[^\n]/g, ' ');
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Code outside a literal, in the masked view: blank, newlines kept. The mask must
|
|
308
|
+
* hold nothing but `x` for literal positions, or an identifier ending in `x`
|
|
309
|
+
* would merge with the literal after it (a template tagged `x` would read as a
|
|
310
|
+
* literal opening with `x`, not with a backtick).
|
|
311
|
+
*/
|
|
312
|
+
const codeInMask = (character) => (character === '\n' ? '\n' : ' ');
|
|
313
|
+
|
|
314
|
+
function stripCLike(source, literals) {
|
|
286
315
|
let out = '';
|
|
287
316
|
let index = 0;
|
|
288
317
|
// Whether a `/` at this position could open a regex literal rather than divide.
|
|
@@ -329,7 +358,7 @@ function stripCLike(source) {
|
|
|
329
358
|
scan += 1;
|
|
330
359
|
}
|
|
331
360
|
if (closed) {
|
|
332
|
-
out +=
|
|
361
|
+
out += literal(source, index, scan, literals);
|
|
333
362
|
index = scan;
|
|
334
363
|
regexAllowed = false;
|
|
335
364
|
continue;
|
|
@@ -351,20 +380,20 @@ function stripCLike(source) {
|
|
|
351
380
|
if (quote !== '`' && source[scan] === '\n') break;
|
|
352
381
|
scan += 1;
|
|
353
382
|
}
|
|
354
|
-
|
|
383
|
+
out += literal(source, index, scan, literals);
|
|
355
384
|
index = scan;
|
|
356
385
|
regexAllowed = true;
|
|
357
386
|
continue;
|
|
358
387
|
}
|
|
359
388
|
|
|
360
|
-
out += character;
|
|
389
|
+
out += literals === 'mask' ? codeInMask(character) : character;
|
|
361
390
|
if (!/\s/.test(character)) regexAllowed = /[(,=:[!&|?{};+\-*%<>~^]/.test(character);
|
|
362
391
|
index += 1;
|
|
363
392
|
}
|
|
364
393
|
return out;
|
|
365
394
|
}
|
|
366
395
|
|
|
367
|
-
function stripPython(source) {
|
|
396
|
+
function stripPython(source, literals) {
|
|
368
397
|
let out = '';
|
|
369
398
|
let index = 0;
|
|
370
399
|
while (index < source.length) {
|
|
@@ -382,7 +411,7 @@ function stripPython(source) {
|
|
|
382
411
|
if (triple === '"""' || triple === "'''") {
|
|
383
412
|
const end = source.indexOf(triple, index + 3);
|
|
384
413
|
const stop = end === -1 ? source.length : end + 3;
|
|
385
|
-
|
|
414
|
+
out += literal(source, index, stop, literals);
|
|
386
415
|
index = stop;
|
|
387
416
|
continue;
|
|
388
417
|
}
|
|
@@ -401,12 +430,12 @@ function stripPython(source) {
|
|
|
401
430
|
}
|
|
402
431
|
scan += 1;
|
|
403
432
|
}
|
|
404
|
-
out +=
|
|
433
|
+
out += literal(source, index, scan, literals);
|
|
405
434
|
index = scan;
|
|
406
435
|
continue;
|
|
407
436
|
}
|
|
408
437
|
|
|
409
|
-
out += character;
|
|
438
|
+
out += literals === 'mask' ? codeInMask(character) : character;
|
|
410
439
|
index += 1;
|
|
411
440
|
}
|
|
412
441
|
return out;
|
|
@@ -461,20 +490,98 @@ function stripNoise(source, kind) {
|
|
|
461
490
|
}
|
|
462
491
|
}
|
|
463
492
|
|
|
493
|
+
/**
|
|
494
|
+
* Comments blanked, string and regex literals kept (`mode: 'keep'`) or masked
|
|
495
|
+
* (`mode: 'mask'`), same length as the input.
|
|
496
|
+
*
|
|
497
|
+
* `stripNoise` is right for deciding WHERE a pattern matches, and wrong for
|
|
498
|
+
* deciding what an operand IS: once literal contents are blanked,
|
|
499
|
+
* `result['actual']` and `result['expected']` are both `result[ ]`.
|
|
500
|
+
* C3 finds its match on the stripped text and reads the operands from the kept
|
|
501
|
+
* view, at the same offsets; the masked view says which of those characters sit
|
|
502
|
+
* inside a literal, where whitespace is part of the value.
|
|
503
|
+
*/
|
|
504
|
+
function stripComments(source, kind, mode) {
|
|
505
|
+
switch (kind) {
|
|
506
|
+
case 'js':
|
|
507
|
+
case 'java':
|
|
508
|
+
case 'go':
|
|
509
|
+
case 'pactconfig': {
|
|
510
|
+
return stripCLike(source, mode);
|
|
511
|
+
}
|
|
512
|
+
case 'py': {
|
|
513
|
+
return stripPython(source, mode);
|
|
514
|
+
}
|
|
515
|
+
default: {
|
|
516
|
+
// Maestro YAML has no C3 and no kept view; callers use the stripped text.
|
|
517
|
+
return null;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
|
|
464
522
|
// ---------------------------------------------------------------------------
|
|
465
523
|
// Helpers shared by the rule predicates
|
|
466
524
|
// ---------------------------------------------------------------------------
|
|
467
525
|
|
|
468
|
-
|
|
526
|
+
/**
|
|
527
|
+
* An operand with the whitespace outside its literals removed.
|
|
528
|
+
*
|
|
529
|
+
* Whitespace inside a string or regex literal is part of the value: `'a b'` and
|
|
530
|
+
* `'ab'` differ, as do `/a b/` and `/ab/`, and collapsing them would turn a
|
|
531
|
+
* comparison that can fail into a reported tautology. `mask` is the same slice of
|
|
532
|
+
* the masked view, `x` wherever the character is inside a literal.
|
|
533
|
+
*/
|
|
534
|
+
function normalizeOperand(value, mask) {
|
|
535
|
+
return value.replaceAll(/\s/g, (character, offset) => (mask[offset] === 'x' ? character : '')).replace(/;$/, '');
|
|
536
|
+
}
|
|
469
537
|
|
|
470
|
-
/**
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
538
|
+
/**
|
|
539
|
+
* Whether a JavaScript operand contains a template literal that interpolates.
|
|
540
|
+
* Stripping blanks the whole template, `${...}` included, so the operand pattern
|
|
541
|
+
* cannot see a call or an `i++` inside it, and two textually equal templates can
|
|
542
|
+
* still evaluate to different values. Such operands are never reported.
|
|
543
|
+
*
|
|
544
|
+
* Only a literal that OPENS with a backtick is a template. A backtick inside a
|
|
545
|
+
* quoted string is data, and Go's backtick raw strings never interpolate, so
|
|
546
|
+
* `${` in either is a constant.
|
|
547
|
+
*/
|
|
548
|
+
function interpolates(text, mask, kind) {
|
|
549
|
+
if (kind !== 'js') return false;
|
|
550
|
+
for (const run of mask.matchAll(/x+/g)) {
|
|
551
|
+
const body = text.slice(run.index, run.index + run[0].length);
|
|
552
|
+
if (body.startsWith('`') && body.includes('${')) return true;
|
|
553
|
+
}
|
|
554
|
+
return false;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
/**
|
|
558
|
+
* `[start, end]` of every match whose two operands are the same expression: the
|
|
559
|
+
* mechanical core of C3.
|
|
560
|
+
*
|
|
561
|
+
* The pattern runs on the stripped source, so a quote or comment cannot fake a
|
|
562
|
+
* match. The operands are read from the kept view (comments blanked, literals
|
|
563
|
+
* intact) at the match's group offsets, so two operands that differ only inside
|
|
564
|
+
* a literal still compare different. Each operand group must span everything
|
|
565
|
+
* between its delimiters, surrounding whitespace included: a group that stops at
|
|
566
|
+
* the last non-blank stripped character would cut `x + 'a'` down to `x +`.
|
|
567
|
+
*/
|
|
568
|
+
function selfComparisons(stripped, views, pattern) {
|
|
569
|
+
const spans = [];
|
|
570
|
+
for (const match of stripped.matchAll(pattern)) {
|
|
571
|
+
const operands = [1, 2].map((group) => {
|
|
572
|
+
const [start, end] = match.indices[group] ?? [0, 0];
|
|
573
|
+
return { text: views.code.slice(start, end), mask: views.mask.slice(start, end) };
|
|
574
|
+
});
|
|
575
|
+
if (operands.some(({ text, mask }) => interpolates(text, mask, views.kind))) continue;
|
|
576
|
+
const [left, right] = operands.map(({ text, mask }) => normalizeOperand(text, mask));
|
|
577
|
+
if (left.length > 0 && left === right) spans.push([match.index, match.index + match[0].length]);
|
|
578
|
+
}
|
|
579
|
+
return spans;
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
/** `[start, end]` of every match of `pattern` (which must carry the `g` flag). */
|
|
583
|
+
function matchSpans(source, pattern) {
|
|
584
|
+
return [...source.matchAll(pattern)].map((match) => [match.index, match.index + match[0].length]);
|
|
478
585
|
}
|
|
479
586
|
|
|
480
587
|
const SKIP_TOKEN = /\.skip|xit|xdescribe|test\.todo|@Ignore|@Disabled|pytest\.mark\.skip/;
|
|
@@ -578,11 +685,13 @@ const RULES = [
|
|
|
578
685
|
severity: 'CRITICAL',
|
|
579
686
|
gate: 'Absolute',
|
|
580
687
|
action: 'block',
|
|
581
|
-
scope:
|
|
688
|
+
// Source scope because formatters split chains: `test.only\n("x", ...)` is as
|
|
689
|
+
// focused as the one-line form, and a per-line scan never sees it.
|
|
690
|
+
scope: 'source',
|
|
582
691
|
kinds: ['js'],
|
|
583
692
|
fix: 'Remove `.only` / `fdescribe` / `fit`. A committed focus silently disables every sibling test in the file.',
|
|
584
|
-
|
|
585
|
-
return /(
|
|
693
|
+
matchSource(stripped) {
|
|
694
|
+
return [...matchSpans(stripped, /(?<![\w.])(?:fdescribe|fit|ftest)\s*\(/g), ...matchSpans(stripped, /\.only\s*[(.]/g)];
|
|
586
695
|
},
|
|
587
696
|
},
|
|
588
697
|
{
|
|
@@ -591,33 +700,39 @@ const RULES = [
|
|
|
591
700
|
severity: 'CRITICAL',
|
|
592
701
|
gate: 'Absolute',
|
|
593
702
|
action: 'block',
|
|
594
|
-
scope:
|
|
703
|
+
// Source scope because formatters split chains: `expect(actual)\n .toBe(actual)`
|
|
704
|
+
// is the same tautology as the one-line form.
|
|
705
|
+
scope: 'source',
|
|
595
706
|
kinds: ['js', 'py', 'java', 'go'],
|
|
596
707
|
fix: 'Assert the value the system under test produced against an expectation that could differ from it.',
|
|
597
|
-
|
|
708
|
+
matchSource(stripped, context) {
|
|
598
709
|
if (context.kind === 'js') {
|
|
599
710
|
// `.not.` is excluded on purpose: `expect(x).not.toBe(x)` is a defect too,
|
|
600
711
|
// but it always FAILS, so it is not the "test cannot fail" failure this row
|
|
601
712
|
// is about, and blocking it would be this hook overreaching its row.
|
|
602
|
-
return
|
|
603
|
-
|
|
604
|
-
|
|
713
|
+
return selfComparisons(
|
|
714
|
+
stripped,
|
|
715
|
+
context,
|
|
716
|
+
/expect\s*\(([^(),]+?)\)\s*\.\s*(?:to\s*\.\s*)?(?:toBe|toEqual|toStrictEqual|toBeCloseTo|equal|equals|eql|deep\s*\.\s*equal)\s*\(([^(),]+?)\)/dg,
|
|
605
717
|
);
|
|
606
718
|
}
|
|
607
719
|
if (context.kind === 'py') {
|
|
608
|
-
|
|
720
|
+
// Horizontal whitespace only: a Python statement does not continue onto the
|
|
721
|
+
// next line without a bracket or a backslash, so `\s` here would pair an
|
|
722
|
+
// `assert` with a `==` on a later, unrelated line.
|
|
723
|
+
return selfComparisons(stripped, context, /assert[ \t]+([^=<>!\s]+)[ \t]*==[ \t]*([^=<>!\s#]+)/dg);
|
|
609
724
|
}
|
|
610
725
|
if (context.kind === 'java') {
|
|
611
|
-
return
|
|
612
|
-
/assertTrue\s*\(\s*true\s*\)
|
|
613
|
-
/assertFalse\s*\(\s*false\s*\)
|
|
614
|
-
|
|
615
|
-
|
|
726
|
+
return [
|
|
727
|
+
...matchSpans(stripped, /assertTrue\s*\(\s*true\s*\)/g),
|
|
728
|
+
...matchSpans(stripped, /assertFalse\s*\(\s*false\s*\)/g),
|
|
729
|
+
...selfComparisons(stripped, context, /assertEquals\s*\(([^,()]+?),([^,()]+?)\)/dg),
|
|
730
|
+
];
|
|
616
731
|
}
|
|
617
732
|
if (context.kind === 'go') {
|
|
618
|
-
return
|
|
733
|
+
return selfComparisons(stripped, context, /assert\.(?:Equal|EqualValues)\s*\(\s*t\s*,([^,()]+?),([^,()]+?)\)/dg);
|
|
619
734
|
}
|
|
620
|
-
return
|
|
735
|
+
return [];
|
|
621
736
|
},
|
|
622
737
|
},
|
|
623
738
|
{
|
|
@@ -746,6 +861,24 @@ function activeRules(config) {
|
|
|
746
861
|
return RULES.filter((rule) => !disabled.has(rule.id));
|
|
747
862
|
}
|
|
748
863
|
|
|
864
|
+
function lineStartOffsets(source) {
|
|
865
|
+
const starts = [0];
|
|
866
|
+
for (let index = source.indexOf('\n'); index !== -1; index = source.indexOf('\n', index + 1)) starts.push(index + 1);
|
|
867
|
+
return starts;
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
/** Zero-based line holding `offset`, by binary search over line starts. */
|
|
871
|
+
function lineAt(lineStarts, offset) {
|
|
872
|
+
let low = 0;
|
|
873
|
+
let high = lineStarts.length - 1;
|
|
874
|
+
while (low < high) {
|
|
875
|
+
const middle = Math.ceil((low + high) / 2);
|
|
876
|
+
if (lineStarts[middle] <= offset) low = middle;
|
|
877
|
+
else high = middle - 1;
|
|
878
|
+
}
|
|
879
|
+
return low;
|
|
880
|
+
}
|
|
881
|
+
|
|
749
882
|
/**
|
|
750
883
|
* Apply every open-gated rule to one file's content.
|
|
751
884
|
*
|
|
@@ -769,6 +902,8 @@ function scanContent(relativePath, source, config, options) {
|
|
|
769
902
|
const strippedLines = stripped.split('\n');
|
|
770
903
|
const rawLines = source.split('\n');
|
|
771
904
|
const lineCount = source.replace(/\n$/, '').split('\n').length;
|
|
905
|
+
const lineStarts = lineStartOffsets(stripped);
|
|
906
|
+
let views = null;
|
|
772
907
|
const findings = [];
|
|
773
908
|
|
|
774
909
|
for (const rule of activeRules(settings)) {
|
|
@@ -783,6 +918,34 @@ function scanContent(relativePath, source, config, options) {
|
|
|
783
918
|
line: 1,
|
|
784
919
|
detail: rule.describe ? rule.describe(context) : '',
|
|
785
920
|
text: '',
|
|
921
|
+
occurrences: [''],
|
|
922
|
+
});
|
|
923
|
+
}
|
|
924
|
+
continue;
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
views ??= { code: stripComments(source, kind, 'keep') ?? stripped, mask: stripComments(source, kind, 'mask') ?? '' };
|
|
928
|
+
// What a violation IS, independent of where it sits and of the comments and
|
|
929
|
+
// layout around it: the code it spans, literals intact, whitespace outside
|
|
930
|
+
// literals dropped. `introducedFindings` compares these.
|
|
931
|
+
const identity = (start, end) => normalizeOperand(views.code.slice(start, end), views.mask.slice(start, end));
|
|
932
|
+
|
|
933
|
+
if (rule.scope === 'source') {
|
|
934
|
+
// Every match maps back to the line it starts on. Stripping preserves
|
|
935
|
+
// newlines, so offsets into the stripped text are offsets into the source.
|
|
936
|
+
// One finding per line, as the line rules report, carrying every match on it.
|
|
937
|
+
const byLine = new Map();
|
|
938
|
+
for (const [start, end] of rule.matchSource(stripped, { kind, config: settings, ...views, relativePath })) {
|
|
939
|
+
const index = lineAt(lineStarts, start);
|
|
940
|
+
byLine.set(index, [...(byLine.get(index) || []), identity(start, end)]);
|
|
941
|
+
}
|
|
942
|
+
for (const index of [...byLine.keys()].sort((a, b) => a - b)) {
|
|
943
|
+
findings.push({
|
|
944
|
+
rule,
|
|
945
|
+
line: index + 1,
|
|
946
|
+
detail: '',
|
|
947
|
+
text: (rawLines[index] || '').trim().slice(0, 120),
|
|
948
|
+
occurrences: byLine.get(index),
|
|
786
949
|
});
|
|
787
950
|
}
|
|
788
951
|
continue;
|
|
@@ -796,6 +959,7 @@ function scanContent(relativePath, source, config, options) {
|
|
|
796
959
|
line: index + 1,
|
|
797
960
|
detail: '',
|
|
798
961
|
text: (rawLines[index] || '').trim().slice(0, 120),
|
|
962
|
+
occurrences: [identity(lineStarts[index], lineStarts[index] + line.length)],
|
|
799
963
|
});
|
|
800
964
|
}
|
|
801
965
|
}
|
|
@@ -899,6 +1063,86 @@ function fragmentsFromPayload(payload) {
|
|
|
899
1063
|
return [];
|
|
900
1064
|
}
|
|
901
1065
|
|
|
1066
|
+
/**
|
|
1067
|
+
* One Edit step applied to `content` the way the Edit tool applies it, or null
|
|
1068
|
+
* when it cannot be (the tool would reject it too).
|
|
1069
|
+
*
|
|
1070
|
+
* Index splicing on purpose: `String.prototype.replace` reads `$&` and `$1` in the
|
|
1071
|
+
* replacement as patterns, and test code is full of template literals.
|
|
1072
|
+
*/
|
|
1073
|
+
function applyEdit(content, edit) {
|
|
1074
|
+
if (!edit || typeof edit.old_string !== 'string' || typeof edit.new_string !== 'string') return null;
|
|
1075
|
+
if (edit.old_string === '') return content === '' ? edit.new_string : null;
|
|
1076
|
+
if (edit.replace_all === true) {
|
|
1077
|
+
return content.includes(edit.old_string) ? content.split(edit.old_string).join(edit.new_string) : null;
|
|
1078
|
+
}
|
|
1079
|
+
const at = content.indexOf(edit.old_string);
|
|
1080
|
+
if (at === -1) return null;
|
|
1081
|
+
return content.slice(0, at) + edit.new_string + content.slice(at + edit.old_string.length);
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
/**
|
|
1085
|
+
* The file as it is now and as it will be once this Edit or MultiEdit lands, or
|
|
1086
|
+
* null when that cannot be built.
|
|
1087
|
+
*
|
|
1088
|
+
* An Edit's `new_string` scanned on its own is scanned out of context: a fragment
|
|
1089
|
+
* that sits inside an existing block comment or template literal looks like code,
|
|
1090
|
+
* and a rule that spans the fragment's boundary is invisible. Building the
|
|
1091
|
+
* proposed file gives `--pre` the same view `--post` will have, and lets the
|
|
1092
|
+
* file-scope rules run on edits too. A missing file is an empty one, which is how
|
|
1093
|
+
* the Edit tool creates a file from an empty `old_string`.
|
|
1094
|
+
*/
|
|
1095
|
+
function proposedEdit(payload, absolutePath) {
|
|
1096
|
+
const input = payload.tool_input || {};
|
|
1097
|
+
let edits = null;
|
|
1098
|
+
if (payload.tool_name === 'Edit') edits = [input];
|
|
1099
|
+
if (payload.tool_name === 'MultiEdit' && Array.isArray(input.edits)) edits = input.edits;
|
|
1100
|
+
if (!edits) return null;
|
|
1101
|
+
|
|
1102
|
+
let before = '';
|
|
1103
|
+
try {
|
|
1104
|
+
before = fs.readFileSync(absolutePath, 'utf8');
|
|
1105
|
+
} catch (error) {
|
|
1106
|
+
if (!error || error.code !== 'ENOENT') return null;
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
let after = before;
|
|
1110
|
+
for (const edit of edits) {
|
|
1111
|
+
after = applyEdit(after, edit);
|
|
1112
|
+
if (after === null) return null;
|
|
1113
|
+
}
|
|
1114
|
+
return { before, after };
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
/**
|
|
1118
|
+
* Findings in `after` that `before` does not already have.
|
|
1119
|
+
*
|
|
1120
|
+
* `--pre` judges the write in front of it. A violation already sitting in the
|
|
1121
|
+
* untouched part of the file is `--post`'s to report, and blocking an unrelated
|
|
1122
|
+
* edit on it would stop the agent fixing a file one edit at a time. Line numbers
|
|
1123
|
+
* move under an edit, so each occurrence is matched by rule and identity (the
|
|
1124
|
+
* code it spans, comments out, literals in), as a multiset: rewording a comment
|
|
1125
|
+
* beside a violation adds nothing, and a second copy of an existing violation on
|
|
1126
|
+
* the same line still adds one. The one trade this makes is an edit that removes
|
|
1127
|
+
* a violation and writes an identical one elsewhere, which `--post` reports.
|
|
1128
|
+
*/
|
|
1129
|
+
function introducedFindings(before, after) {
|
|
1130
|
+
const key = (finding, occurrence) => `${finding.rule.id}\u0000${occurrence}`;
|
|
1131
|
+
const existing = new Map();
|
|
1132
|
+
for (const finding of before) {
|
|
1133
|
+
for (const occurrence of finding.occurrences) existing.set(key(finding, occurrence), (existing.get(key(finding, occurrence)) || 0) + 1);
|
|
1134
|
+
}
|
|
1135
|
+
return after.filter((finding) => {
|
|
1136
|
+
let introduced = false;
|
|
1137
|
+
for (const occurrence of finding.occurrences) {
|
|
1138
|
+
const remaining = existing.get(key(finding, occurrence)) || 0;
|
|
1139
|
+
if (remaining === 0) introduced = true;
|
|
1140
|
+
else existing.set(key(finding, occurrence), remaining - 1);
|
|
1141
|
+
}
|
|
1142
|
+
return introduced;
|
|
1143
|
+
});
|
|
1144
|
+
}
|
|
1145
|
+
|
|
902
1146
|
function scanRoots(globs) {
|
|
903
1147
|
const roots = new Set();
|
|
904
1148
|
for (const glob of globs || []) {
|
|
@@ -1060,6 +1304,15 @@ function main(argv) {
|
|
|
1060
1304
|
const relative = path.relative(projectRoot, absolute);
|
|
1061
1305
|
if (relative.startsWith('..')) return 0;
|
|
1062
1306
|
|
|
1307
|
+
const proposed = proposedEdit(payload, absolute);
|
|
1308
|
+
if (proposed) {
|
|
1309
|
+
const scan = (source) => scanContent(relative, source, config, { fragmentOnly: false });
|
|
1310
|
+
const findings = introducedFindings(scan(proposed.before), scan(proposed.after)).map((finding) => ({ ...finding, file: relative }));
|
|
1311
|
+
return report(findings, 'TEA enforcement blocked this write:');
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
// The proposed file could not be built (unreadable file, or an old_string the
|
|
1315
|
+
// Edit tool will reject anyway), so fall back to the fragments on their own.
|
|
1063
1316
|
const findings = fragmentsFromPayload(payload).flatMap((fragment) =>
|
|
1064
1317
|
scanContent(relative, fragment.text, config, { fragmentOnly: fragment.fragmentOnly }).map((finding) => ({
|
|
1065
1318
|
...finding,
|
|
@@ -1091,11 +1344,14 @@ module.exports = {
|
|
|
1091
1344
|
matchesAnyGlob,
|
|
1092
1345
|
kindForPath,
|
|
1093
1346
|
stripNoise,
|
|
1347
|
+
stripComments,
|
|
1094
1348
|
commentIndex,
|
|
1095
1349
|
integrityWarning,
|
|
1096
1350
|
scanContent,
|
|
1097
1351
|
scanFile,
|
|
1098
1352
|
targetsFromPayload,
|
|
1099
1353
|
fragmentsFromPayload,
|
|
1354
|
+
proposedEdit,
|
|
1355
|
+
introducedFindings,
|
|
1100
1356
|
main,
|
|
1101
1357
|
};
|
|
@@ -162,8 +162,8 @@ Merge into `{project-root}/.claude/settings.json`. If the file already exists, *
|
|
|
162
162
|
|
|
163
163
|
All three are required, and each one covers a hole the others cannot:
|
|
164
164
|
|
|
165
|
-
- `--pre` blocks the write before it lands.
|
|
166
|
-
- `--post` re-reads the affected file from disk in full. This is what catches a write made through Bash (`cat > x.spec.ts`, `sed -i`, `tee`)
|
|
165
|
+
- `--pre` blocks the write before it lands. For an Edit or MultiEdit it applies the edit to the file on disk and scans the result, so text inside an existing comment reads as a comment and a violation the edit completes is seen; it blocks only on violations the edit introduces. It sees only Write, Edit and MultiEdit, which is why it is not sufficient on its own.
|
|
166
|
+
- `--post` re-reads the affected file from disk in full. This is what catches a write made through Bash (`cat > x.spec.ts`, `sed -i`, `tee`) and a violation sitting in the part of the file the edit never touched.
|
|
167
167
|
- `--stop` sweeps test files modified during the turn. This is what catches a codegen script that wrote files it never named on its command line.
|
|
168
168
|
|
|
169
169
|
The hook fails open: a malformed payload, an unreadable config, or an internal error exits 0 and allows the write. A broken enforcement hook must never become an agent that cannot write files.
|
|
@@ -17,6 +17,7 @@ You will continue to operate with your given name, identity, and communication_s
|
|
|
17
17
|
- `{skill-root}` resolves to this skill's installed directory (where `customize.toml` lives).
|
|
18
18
|
- `{project-root}` is the nearest folder containing `_bmad/`, starting at the project working directory and moving up through its parents.
|
|
19
19
|
- `{tea-knowledge}` is the `knowledge/` folder of the `bmod-tea` skill, installed beside this one: `{skill-root}/../bmod-tea/knowledge`. `tea-index.csv` there lists every fragment by a path relative to that folder.
|
|
20
|
+
- `{tea-contracts}` is the `contracts/` folder of the `bmod-tea` skill, installed beside this one: `{skill-root}/../bmod-tea/contracts`. `story-identity.md` there says how a story is resolved, read and named.
|
|
20
21
|
- `{skill-name}` resolves to the skill directory's basename.
|
|
21
22
|
- Resolve sibling workflow files such as `instructions.md`, `checklist.md`, `steps-c/...`, `steps-e/...`, `steps-v/...`, and templates from `{skill-root}`.
|
|
22
23
|
|
|
@@ -103,14 +103,14 @@ Every run writes its audit to a file whose name carries the run's scope, so an a
|
|
|
103
103
|
|
|
104
104
|
- `system`: the whole project or system, or no narrower scope could be resolved.
|
|
105
105
|
- `epic-{epic_num}`: one epic.
|
|
106
|
-
- `story-{story_key}`: one story.
|
|
106
|
+
- `story-{story_key}`: one story. Resolve, read and name the story by `{tea-contracts}/story-identity.md`: `story_key` is `shop--e1-s2` for a v7 epic entry and the v6 story file basename (`1-2-user-authentication`) for a v6 story.
|
|
107
107
|
|
|
108
108
|
Slug rule (used for an epic title with no number): lowercase; replace every run of characters outside `a-z` and `0-9` with a single `-`; trim leading and trailing `-`; truncate to 64 characters.
|
|
109
109
|
|
|
110
110
|
Resolve the scope in this order:
|
|
111
111
|
|
|
112
112
|
1. Use the scope the user named in this invocation (a story, an epic, or the whole system).
|
|
113
|
-
2. Otherwise take the scope carried by the artifacts loaded above: the story file
|
|
113
|
+
2. Otherwise take the scope carried by the artifacts loaded above: the story (a v7 ticket or a v6 story file) for a story, or the epic number from the epic document's metadata, H1 heading, or filename for an epic. An epic with no number uses the slug of its title in place of `epic_num`.
|
|
114
114
|
3. If several candidate scopes remain in an interactive run, list them and ask the user which one this audit covers. **Halt** until they answer. A headless or autonomous run that cannot resolve a single scope uses `system` and states that choice in the audit's output.
|
|
115
115
|
|
|
116
116
|
Set `run_scope` to `story`, `epic`, or `system` to match the resolved form, and set `run_key` accordingly.
|
|
@@ -155,6 +155,8 @@ lastSaved: '{date}'
|
|
|
155
155
|
|
|
156
156
|
Then write this step's output below the frontmatter.
|
|
157
157
|
|
|
158
|
+
For a story run (`run_scope` is `story`), also write `storyId`, `storyKey`, `ticketRef` and `storyFile` into this frontmatter, as `{tea-contracts}/story-identity.md` section 4 defines them. Other scopes leave them out.
|
|
159
|
+
|
|
158
160
|
`runScope` and `runKey` are this run's identity. Later steps carry both forward unchanged, and Resume mode refuses to continue a file whose `runKey` does not match the run being resumed.
|
|
159
161
|
|
|
160
162
|
**Update `inputDocuments`**: Set `inputDocuments` in the output template frontmatter to the list of artifact paths loaded in this step (e.g., knowledge fragments, test design documents, configuration files).
|
|
@@ -78,6 +78,8 @@ If `workflowStatus` is missing (legacy output document), infer it from `lastStep
|
|
|
78
78
|
|
|
79
79
|
---
|
|
80
80
|
|
|
81
|
+
For a story run, read `{tea-contracts}/story-identity.md` before continuing: a named story is resolved by its sections 1 and 4 for the identity check, `ticketRef` locates the story when `storyFile` is empty or gone, and section 5 governs every citation the checkpoint carries (read through `resolvedSources`; report, never follow, an `unresolved` one). This holds on every resume path, named or not.
|
|
82
|
+
|
|
81
83
|
### 3. Display Progress Dashboard
|
|
82
84
|
|
|
83
85
|
Display progress with checkmark/empty indicators:
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
- [ ] Test levels selected (E2E/API/Component/Unit)
|
|
57
57
|
- [ ] No duplicate coverage across levels
|
|
58
58
|
- [ ] Priority levels assigned (P0/P1/P2/P3)
|
|
59
|
-
- [ ] P0 scenarios meet strict criteria (
|
|
59
|
+
- [ ] P0 scenarios meet strict criteria (critical business, security, data-integrity, or compliance consequence + no safe workaround)
|
|
60
60
|
- [ ] NFR-derived risks mapped to planned validation scenarios
|
|
61
61
|
- [ ] Planned NFR evidence artifacts documented without final PASS/CONCERNS/FAIL decisions
|
|
62
62
|
- [ ] Data prerequisites identified
|
|
@@ -233,6 +233,39 @@
|
|
|
233
233
|
- [ ] Regression scope defined per impacted service
|
|
234
234
|
- [ ] Cross-team coordination noted where needed
|
|
235
235
|
|
|
236
|
+
## Document Quality (All Outputs)
|
|
237
|
+
|
|
238
|
+
**Applies to every output: the epic document in epic-level mode, and both documents plus the handoff in system-level mode.** These items check the Editorial Contract in `steps-c/step-05-generate-output.md`.
|
|
239
|
+
|
|
240
|
+
### Clear Instructions
|
|
241
|
+
|
|
242
|
+
- [ ] Each instruction names the actor, action, condition, and expected result wherever the sources provide them
|
|
243
|
+
- [ ] Prerequisites, conditions, and warnings appear before the action they govern
|
|
244
|
+
- [ ] Instructions that combine several actions or conditions are split into separate steps, and no condition was lost in the split
|
|
245
|
+
- [ ] One name per concept; repository names and domain terms match the sources exactly
|
|
246
|
+
- [ ] No filler sentences, promotional claims, or vague attribution; citations are kept
|
|
247
|
+
- [ ] Emojis appear only where the template uses them as markers, such as the Quick Guide tiers
|
|
248
|
+
- [ ] No banned-word list was applied: exact technical terms such as test harness and test vector remain
|
|
249
|
+
|
|
250
|
+
### Evidence and Uncertainty
|
|
251
|
+
|
|
252
|
+
- [ ] Missing details remain visible as `UNKNOWN`, open assumptions, or clarification items; none was invented to complete a sentence
|
|
253
|
+
- [ ] Observed facts, planned checks, assumptions, and unknowns read as what they are
|
|
254
|
+
- [ ] Planned tests read as planned; no planned test is described as run, verified, or passing
|
|
255
|
+
- [ ] Confidence statements and unverified behavior from the sources are still stated
|
|
256
|
+
|
|
257
|
+
### Protected Content
|
|
258
|
+
|
|
259
|
+
- [ ] Requirement, risk, and test IDs, requirement-to-test mappings, source links, evidence references, and exclusions match the decisions of steps 3 and 4
|
|
260
|
+
- [ ] Risk categories, probabilities, impacts, scores, owners, mitigations, and timelines match the decisions of steps 3 and 4
|
|
261
|
+
- [ ] Test levels, priorities, preconditions, test data, sequences, assertions, negative cases, cleanup, and dependencies are intact
|
|
262
|
+
- [ ] Thresholds, units, comparison operators, timeouts, retry counts, quantifiers, and negations are exact
|
|
263
|
+
- [ ] Literal commands, paths, code, regular expressions, payloads, Unicode test data, and expected strings are exact
|
|
264
|
+
- [ ] Priority headings open with `P0`, `P1`, `P2`, or `P3`, and every risk-band heading states its score range
|
|
265
|
+
- [ ] No scored risk table or coverage table sits under a heading that opens or ends with Example or Illustration, a heading that ends with Reference, or a paragraph opening `Example:`, `Worked example:`, or `Illustration:`
|
|
266
|
+
- [ ] No scored risk table or coverage table sits inside a blockquote or callout
|
|
267
|
+
- [ ] Validation ran on the saved files after the last edit, and every check affected by a later fix was rerun
|
|
268
|
+
|
|
236
269
|
## System-Level Mode: Two-Document Validation
|
|
237
270
|
|
|
238
271
|
**When in system-level mode (PRD + ADR input), validate BOTH documents:**
|
|
@@ -349,9 +382,9 @@
|
|
|
349
382
|
- [ ] Dates and authors match across documents
|
|
350
383
|
- [ ] ADR and PRD references consistent
|
|
351
384
|
|
|
352
|
-
###
|
|
385
|
+
### System-Level Anti-Bloat Check
|
|
353
386
|
|
|
354
|
-
**CRITICAL: Check for bloat and repetition across BOTH documents.**
|
|
387
|
+
**CRITICAL: Check for bloat and repetition across BOTH documents.** Document Quality (All Outputs) covers wording and tone.
|
|
355
388
|
|
|
356
389
|
- [ ] **No repeated notes 10+ times** (e.g., "Timing is pessimistic until R-005 fixed" on every section)
|
|
357
390
|
- [ ] **Repeated information consolidated** (write once at top, reference briefly if needed)
|
|
@@ -360,10 +393,6 @@
|
|
|
360
393
|
- [ ] **Architecture doc**: Concerns-focused, NOT implementation-focused
|
|
361
394
|
- [ ] **QA doc**: Implementation-focused, NOT theory-focused
|
|
362
395
|
- [ ] **Clear separation**: Architecture = WHAT and WHY, QA = HOW
|
|
363
|
-
- [ ] **Professional tone**: No AI slop markers
|
|
364
|
-
- [ ] Avoid excessive ✅/❌ emojis (use sparingly, only when adding clarity)
|
|
365
|
-
- [ ] Avoid "absolutely", "excellent", "fantastic", overly enthusiastic language
|
|
366
|
-
- [ ] Write professionally and directly
|
|
367
396
|
- [ ] **Architecture doc length**: Target ~150-200 lines max (focus on actionable concerns only)
|
|
368
397
|
- [ ] **QA doc length**: Keep concise, remove bloat sections
|
|
369
398
|
|
|
@@ -406,6 +435,8 @@
|
|
|
406
435
|
- [ ] **System-level mode:** Both documents validated (if applicable)
|
|
407
436
|
- [ ] **System-level mode:** Handoff document validated (if applicable)
|
|
408
437
|
- [ ] **Epic-level mode:** Single document validated (if applicable)
|
|
438
|
+
- [ ] Document Quality (All Outputs) passed for every output
|
|
439
|
+
- [ ] Final validation ran after the last edit to every output
|
|
409
440
|
- [ ] Team review scheduled (if required)
|
|
410
441
|
|
|
411
442
|
## Post-Workflow Actions
|
|
@@ -441,7 +472,7 @@ If workflow fails:
|
|
|
441
472
|
|
|
442
473
|
**Issue**: Too many P0 tests
|
|
443
474
|
|
|
444
|
-
- **Solution**: Apply strict P0 criteria - must
|
|
475
|
+
- **Solution**: Apply strict P0 criteria - must have a critical business, security, data-integrity, or compliance consequence AND no safe workaround
|
|
445
476
|
|
|
446
477
|
**Issue**: Risk scores all high
|
|
447
478
|
|