@mjasnikovs/pi-task 0.18.40 → 0.18.41
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.
|
@@ -39,6 +39,7 @@ import { isYoloMode, yoloPickAnswer, yoloFinalGateChoice, YOLO_STAMP } from './y
|
|
|
39
39
|
import { configureResearchRun, resumeResearchRun } from '../workers/research-cache.js';
|
|
40
40
|
import { CONTRACT_EXTRACT_PROMPT, parseContractLines, keepGroundedContracts, appendContracts } from './contracts.js';
|
|
41
41
|
import { reconcileTitleSources } from './decompose-fidelity.js';
|
|
42
|
+
import { mandatesTestsInSameChange, rewriteBatchTestPlan } from './batch-test-task.js';
|
|
42
43
|
import { REQUIREMENT_EXTRACT_PROMPT, COVERAGE_MAP_PROMPT, parseRequirementLines, keepGroundedRequirements, capRequirements, enumerateObligationPassages, uncoveredPassages, extractionRetryHint, parseCoverageMap, accountCoverage, isCrossCuttingRequirement, appendCarriedRequirements, buildRequirementsLedger } from './requirements.js';
|
|
43
44
|
import { decideAdoption, groundedCoverage } from './coverage-loop.js';
|
|
44
45
|
import { findSpecDanglingArtifacts, titlesCoverArtifact, danglingMissingText, danglingCarryText } from './artifact-closure.js';
|
|
@@ -590,8 +591,18 @@ export async function planAuto(ctx, cwd, feature, deps) {
|
|
|
590
591
|
catch {
|
|
591
592
|
// best-effort channel
|
|
592
593
|
}
|
|
594
|
+
// Tests-in-the-same-change cadence (mx5 run 14, PROMPT item 6): when the
|
|
595
|
+
// decisions mandate it, a whole-project batch test task contradicts them —
|
|
596
|
+
// run 14 shipped one anyway (TASK_0037, 4.7h, yolo-accepted FAIL) because
|
|
597
|
+
// decompose mirrors the spec's milestone shape. The decisions channel
|
|
598
|
+
// OVERRIDES the spec doc, so this resolves toward the decision without asking.
|
|
599
|
+
const noBatchTests = mandatesTestsInSameChange(clarifications, featureForModel);
|
|
600
|
+
if (noBatchTests) {
|
|
601
|
+
logPlanDebug(cwd, 'decisions mandate tests-in-the-same-change — batch test tasks are banned '
|
|
602
|
+
+ 'from this plan (prompt rule + host rewrite)');
|
|
603
|
+
}
|
|
593
604
|
// decompose
|
|
594
|
-
const decomposePrompt = AUTO_DECOMPOSE_PROMPT(featureForModel, clarifications, buildRequirementsLedger(reqEntries));
|
|
605
|
+
const decomposePrompt = AUTO_DECOMPOSE_PROMPT(featureForModel, clarifications, buildRequirementsLedger(reqEntries), noBatchTests);
|
|
595
606
|
// Parse + FIDELITY RECONCILIATION (mx5 run 11, goal B): ground each title's
|
|
596
607
|
// [source: "…"] citation against the doc, strip the clause, and re-attach any
|
|
597
608
|
// `+`-joined constraint fragment the paraphrased title dropped (the silently
|
|
@@ -606,7 +617,18 @@ export async function planAuto(ctx, cwd, feature, deps) {
|
|
|
606
617
|
.map(r => ` [task ${r.index + 1}: ${r.fragments.join(', ')}]`)
|
|
607
618
|
.join(''));
|
|
608
619
|
}
|
|
609
|
-
|
|
620
|
+
// Batch-test ban (item 6): drop or scope a whole-project "write all the
|
|
621
|
+
// tests" task. Identity unless the cadence decision is present, and the
|
|
622
|
+
// sweep replacement re-grounds every requirement the drop would cost — so
|
|
623
|
+
// planned coverage cannot fall (run 12's lesson).
|
|
624
|
+
const debatched = rewriteBatchTestPlan(plan.titles, clarifications, featureForModel, reqEntries.map(e => e.quote), isCrossCuttingRequirement);
|
|
625
|
+
for (const a of debatched.actions) {
|
|
626
|
+
logPlanDebug(cwd, `batch test task ${a.kind} (tests-in-same-change decision): "${a.title}"`
|
|
627
|
+
+ (a.kind === 'scoped' ?
|
|
628
|
+
` → scoped sweep over ${a.orphaned.length} orphaned requirement(s)`
|
|
629
|
+
: ' — every requirement it touched is owned by another task'));
|
|
630
|
+
}
|
|
631
|
+
return debatched.titles;
|
|
610
632
|
};
|
|
611
633
|
const listRaw = await deps.runChild('auto-decompose', 'read', decomposePrompt);
|
|
612
634
|
let planTitles = parsePlan(listRaw);
|
|
@@ -12,8 +12,12 @@ export declare const AUTO_CLARIFY_PROMPT: (feature: string, priorQA: string) =>
|
|
|
12
12
|
* belt): the spec's obligations ride into decompose explicitly, so mirroring the
|
|
13
13
|
* spec's own milestone/section structure cannot silently discharge them. '' ⇒
|
|
14
14
|
* the prompt is unchanged.
|
|
15
|
+
*
|
|
16
|
+
* `noBatchTests` adds the anti-batch-test rule (batch-test-task.ts) — emitted ONLY
|
|
17
|
+
* when the decisions mandate tests-in-the-same-change, so every other run sees the
|
|
18
|
+
* prompt it always saw. It is the belt; the host-side rewrite is the lever.
|
|
15
19
|
*/
|
|
16
|
-
export declare const AUTO_DECOMPOSE_PROMPT: (feature: string, clarifications: string, requirementsLedger?: string) => string;
|
|
20
|
+
export declare const AUTO_DECOMPOSE_PROMPT: (feature: string, clarifications: string, requirementsLedger?: string, noBatchTests?: boolean) => string;
|
|
17
21
|
/**
|
|
18
22
|
* Coverage triage: judge whether a decomposed task list covers the whole
|
|
19
23
|
* feature. Guards the plan — the highest-leverage artifact in /task-auto —
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* LIST only; all research/spec depth is /task's job, run per-title later.
|
|
4
4
|
*/
|
|
5
5
|
import { DECOMPOSE_SOURCE_RULE } from './decompose-fidelity.js';
|
|
6
|
+
import { DECOMPOSE_NO_BATCH_TESTS_RULE } from './batch-test-task.js';
|
|
6
7
|
/**
|
|
7
8
|
* Clarify: asks ONE question at a time. Output MUST match parseClarifyList — a
|
|
8
9
|
* single numbered question followed by a "SUGGESTED: <default>" line, an optional
|
|
@@ -71,8 +72,12 @@ NONE`;
|
|
|
71
72
|
* belt): the spec's obligations ride into decompose explicitly, so mirroring the
|
|
72
73
|
* spec's own milestone/section structure cannot silently discharge them. '' ⇒
|
|
73
74
|
* the prompt is unchanged.
|
|
75
|
+
*
|
|
76
|
+
* `noBatchTests` adds the anti-batch-test rule (batch-test-task.ts) — emitted ONLY
|
|
77
|
+
* when the decisions mandate tests-in-the-same-change, so every other run sees the
|
|
78
|
+
* prompt it always saw. It is the belt; the host-side rewrite is the lever.
|
|
74
79
|
*/
|
|
75
|
-
export const AUTO_DECOMPOSE_PROMPT = (feature, clarifications, requirementsLedger = '') => `Split this feature into an ordered list of implementation tasks. Each task
|
|
80
|
+
export const AUTO_DECOMPOSE_PROMPT = (feature, clarifications, requirementsLedger = '', noBatchTests = false) => `Split this feature into an ordered list of implementation tasks. Each task
|
|
76
81
|
will be handed, by its title, to a separate pipeline that does its own research
|
|
77
82
|
and writes its own spec — so here you produce TITLES ONLY, not specs.
|
|
78
83
|
|
|
@@ -94,7 +99,7 @@ RULES:
|
|
|
94
99
|
none. These are explicit user choices that may contradict the referenced spec
|
|
95
100
|
doc; phrase them as imperative directives (e.g. "use Bun's built-in bundler, do
|
|
96
101
|
not add vite"). Do NOT invent decisions — only restate ones from CLARIFICATIONS.
|
|
97
|
-
${DECOMPOSE_SOURCE_RULE}
|
|
102
|
+
${DECOMPOSE_SOURCE_RULE}${noBatchTests ? `\n${DECOMPOSE_NO_BATCH_TESTS_RULE}` : ''}
|
|
98
103
|
- Output the checkbox list and NOTHING else (no preamble, no numbering).`;
|
|
99
104
|
/**
|
|
100
105
|
* Coverage triage: judge whether a decomposed task list covers the whole
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Does the decisions/spec text mandate tests-in-the-same-change?
|
|
3
|
+
*
|
|
4
|
+
* Scans sentence by sentence and requires BOTH signals in the SAME sentence, so
|
|
5
|
+
* a testing section that happens to sit near an unrelated "don't defer" line
|
|
6
|
+
* cannot trigger the ban. `decisions` is checked first and alone is sufficient;
|
|
7
|
+
* the spec is scanned too because run 14's cadence rule is stated in §10 of the
|
|
8
|
+
* doc and only echoed into the decisions channel.
|
|
9
|
+
*/
|
|
10
|
+
export declare function mandatesTestsInSameChange(decisions: string, spec?: string): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Indices of titles that are whole-project BATCH test tasks.
|
|
13
|
+
*
|
|
14
|
+
* Three conditions must all hold — the title's deliverable is tests, its scope is
|
|
15
|
+
* the whole project, and it is not test INFRASTRUCTURE. A per-feature task that
|
|
16
|
+
* carries "+ tests" never matches (its head names the feature), which is the
|
|
17
|
+
* point: those are the cadence the decision asks for.
|
|
18
|
+
*/
|
|
19
|
+
export declare function findBatchTestTitles(titles: string[]): number[];
|
|
20
|
+
/**
|
|
21
|
+
* The spec's own coverage source — the command whose report scopes the sweep.
|
|
22
|
+
*
|
|
23
|
+
* Only backticked spans are considered, so the result is a command the spec
|
|
24
|
+
* actually writes down rather than a phrase inferred from prose; a span carrying
|
|
25
|
+
* a coverage flag wins over a plain test run. Falls back to a generic phrase when
|
|
26
|
+
* the spec names no command, which keeps the sweep title well-formed either way.
|
|
27
|
+
*/
|
|
28
|
+
export declare function coverageSourceFromSpec(spec: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* The scoped replacement: a gap-filling sweep, bounded by what the coverage
|
|
31
|
+
* source reports and by the requirements that lost their only owner. It states
|
|
32
|
+
* the ban explicitly, because the child that receives this title sees nothing
|
|
33
|
+
* else.
|
|
34
|
+
*/
|
|
35
|
+
export declare function buildSweepTitle(orphaned: string[], coverageSource: string): string;
|
|
36
|
+
export interface BatchTestAction {
|
|
37
|
+
/** Index of the offending title in the INPUT list. */
|
|
38
|
+
index: number;
|
|
39
|
+
/** The offending title, verbatim. */
|
|
40
|
+
title: string;
|
|
41
|
+
kind: 'dropped' | 'scoped';
|
|
42
|
+
/** The sweep title that replaced it (`kind: 'scoped'` only). */
|
|
43
|
+
replacement?: string;
|
|
44
|
+
/** Requirement quotes that no OTHER title grounds — what the sweep must cover. */
|
|
45
|
+
orphaned: string[];
|
|
46
|
+
}
|
|
47
|
+
export interface BatchTestRewrite {
|
|
48
|
+
titles: string[];
|
|
49
|
+
actions: BatchTestAction[];
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Rewrite a decomposed plan so it carries no whole-project batch test task when
|
|
53
|
+
* the decisions mandate tests-in-the-same-change.
|
|
54
|
+
*
|
|
55
|
+
* No mandate, or no batch title ⇒ the plan is returned untouched (identity), so
|
|
56
|
+
* every non-cadence run behaves exactly as before.
|
|
57
|
+
*
|
|
58
|
+
* With a mandate, ALL batch titles are removed at once before coverage is
|
|
59
|
+
* re-measured — otherwise two batch tasks would each mask the other's orphans and
|
|
60
|
+
* both would look droppable. The orphaned set is then whatever grounded coverage
|
|
61
|
+
* the removal costs; it is non-empty only when no other task's title claims that
|
|
62
|
+
* requirement, and it becomes the sweep's scope. At most ONE sweep is emitted (in
|
|
63
|
+
* the first batch title's position, so plan order is preserved).
|
|
64
|
+
*/
|
|
65
|
+
export declare function rewriteBatchTestPlan(titles: string[], decisions: string, spec: string, requirementQuotes: string[], isCrossCutting: (quote: string) => boolean): BatchTestRewrite;
|
|
66
|
+
/**
|
|
67
|
+
* The decompose-prompt rule (the belt; the host rewrite above is the lever).
|
|
68
|
+
* Emitted ONLY when the decisions mandate the cadence, so ordinary runs see the
|
|
69
|
+
* prompt they always saw. Kept next to the detector so the two cannot drift.
|
|
70
|
+
*/
|
|
71
|
+
export declare const DECOMPOSE_NO_BATCH_TESTS_RULE: string;
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* batch-test-task — ban the whole-project "write all the tests" task when the
|
|
3
|
+
* DECISIONS channel mandates tests-in-the-same-change (mx5 run 14, PROMPT item 6).
|
|
4
|
+
*
|
|
5
|
+
* The failure this closes: run 14's plan contained
|
|
6
|
+
*
|
|
7
|
+
* TASK_0037 "Write component and page tests — Playwright CT tests with
|
|
8
|
+
* screenshot baselines for all components and pages"
|
|
9
|
+
*
|
|
10
|
+
* — ~4.7h, the worst active-time task of the run, ended in a yolo-accepted verify
|
|
11
|
+
* FAIL with a frozen-config violation — while the very decision carried ON THAT
|
|
12
|
+
* TITLE said the opposite:
|
|
13
|
+
*
|
|
14
|
+
* "a test lands *as fast as possible* — in the same change — as each new route
|
|
15
|
+
* or React component/page. No route or component is considered done until its
|
|
16
|
+
* test exists and passes. Don't batch testing to the end of a milestone."
|
|
17
|
+
*
|
|
18
|
+
* Decompose did not invent the shape: the spec's own §10/§12 structure induced it,
|
|
19
|
+
* and decompose mirrors the spec. So the conflict is SPEC-INTERNAL (the spec's
|
|
20
|
+
* milestone shape vs the spec's own cadence rule), and the decisions channel
|
|
21
|
+
* OVERRIDES the spec doc by definition — the same precedence the task titles
|
|
22
|
+
* already state. Resolve toward the decision; never ask the user.
|
|
23
|
+
*
|
|
24
|
+
* The mechanism is a deterministic post-decompose rewrite (applied on EVERY
|
|
25
|
+
* decompose output, like fidelity reconciliation), plus a conditional prompt rule
|
|
26
|
+
* as the belt. Only the batch-EVERYTHING shape is banned — coverage is never
|
|
27
|
+
* nuked (run 12's lesson). Which of the two outcomes fires is decided by
|
|
28
|
+
* `groundedCoverage`, not by wording:
|
|
29
|
+
*
|
|
30
|
+
* • the batch title grounds NO requirement that survives its removal ⇒ every
|
|
31
|
+
* requirement it touched is owned by some other task, the per-change cadence
|
|
32
|
+
* already covers the work, and the task is DROPPED;
|
|
33
|
+
* • it is the ONLY title grounding some requirement(s) ⇒ dropping it would
|
|
34
|
+
* reduce planned coverage, so it is REPLACED by a scoped sweep that names
|
|
35
|
+
* exactly those orphaned requirements and points at the spec's own coverage
|
|
36
|
+
* source ("fill the gaps <that command> reports"), never "test everything".
|
|
37
|
+
*
|
|
38
|
+
* Because the replacement's owned-set is computed from the same groundedCoverage
|
|
39
|
+
* the monotonic adoption guard uses, total planned coverage cannot fall.
|
|
40
|
+
*/
|
|
41
|
+
import { groundedCoverage } from './coverage-loop.js';
|
|
42
|
+
/**
|
|
43
|
+
* Sentences that MANDATE tests landing with the change they cover. Deliberately
|
|
44
|
+
* narrow: a spec that merely REQUIRES tests ("every route has tests") does not
|
|
45
|
+
* ban a batch task — only an explicit cadence/anti-batch directive does.
|
|
46
|
+
*/
|
|
47
|
+
const SAME_CHANGE_RE = /\bin the same (?:change|commit|pr|patch|diff|task|step)\b|\b(?:do ?n['’]?t|do not|never|no)\s+(?:batch|defer|postpone|save|leave)\b|\bnot\b[^.]{0,60}\bdone until\b[^.]{0,60}\btest/i;
|
|
48
|
+
/** Any mention of testing — the mandate must be ABOUT tests, not about docs. */
|
|
49
|
+
const TEST_WORD_RE = /\btests?\b|\btesting\b|\btest-first\b/i;
|
|
50
|
+
/**
|
|
51
|
+
* Does the decisions/spec text mandate tests-in-the-same-change?
|
|
52
|
+
*
|
|
53
|
+
* Scans sentence by sentence and requires BOTH signals in the SAME sentence, so
|
|
54
|
+
* a testing section that happens to sit near an unrelated "don't defer" line
|
|
55
|
+
* cannot trigger the ban. `decisions` is checked first and alone is sufficient;
|
|
56
|
+
* the spec is scanned too because run 14's cadence rule is stated in §10 of the
|
|
57
|
+
* doc and only echoed into the decisions channel.
|
|
58
|
+
*/
|
|
59
|
+
export function mandatesTestsInSameChange(decisions, spec = '') {
|
|
60
|
+
for (const text of [decisions, spec]) {
|
|
61
|
+
for (const sentence of text.split(/(?<=[.!?])\s+|\n{2,}/)) {
|
|
62
|
+
if (TEST_WORD_RE.test(sentence) && SAME_CHANGE_RE.test(sentence))
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
/** Trailing `[decisions: …]` clauses decompose appends — carried onto the
|
|
69
|
+
* replacement title verbatim so the rewrite never loses a directive. */
|
|
70
|
+
const DECISIONS_CLAUSE_RE = /\s*\[decisions:/i;
|
|
71
|
+
/**
|
|
72
|
+
* Where decompose's trailing metadata starts. `[source: …]` is included because
|
|
73
|
+
* reconcileTitleSources only strips a WELL-FORMED trailing citation: measured
|
|
74
|
+
* live, the model also emits `[source: "…" [10. Testing]]`, which fails that
|
|
75
|
+
* regex and leaks the QUOTED SPEC LINE into the title. Judging scope on such a
|
|
76
|
+
* title reads the citation's words as the task's own — the cadence quote "…as
|
|
77
|
+
* each new route or React component/page" made a properly scoped
|
|
78
|
+
* "Write route/API tests for auth" look like a batch task (live false positive,
|
|
79
|
+
* rep 1). A citation is provenance, never scope.
|
|
80
|
+
*/
|
|
81
|
+
const CLAUSE_START_RE = /\s*\[(?:source|decisions)\s*:/i;
|
|
82
|
+
/** Split a title into the part decompose authored, and the `[decisions: …]` tail
|
|
83
|
+
* that must survive onto a replacement title. A leaked `[source: …]` remnant is
|
|
84
|
+
* dropped from both — the sweep does not derive from that line. */
|
|
85
|
+
function splitDecisions(title) {
|
|
86
|
+
const clause = CLAUSE_START_RE.exec(title);
|
|
87
|
+
const body = (clause ? title.slice(0, clause.index) : title).trim();
|
|
88
|
+
const decisions = DECISIONS_CLAUSE_RE.exec(title);
|
|
89
|
+
return { body, tail: decisions ? title.slice(decisions.index) : '' };
|
|
90
|
+
}
|
|
91
|
+
/** The head of a title: everything before the " — <detail>" separator. */
|
|
92
|
+
function head(body) {
|
|
93
|
+
return body.split(/\s+[—–-]\s+|\s*\|\s*/)[0];
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Remove double-quoted spans — they are QUOTED SPEC TEXT, never the task's own
|
|
97
|
+
* scope. Measured live: the model frequently appends its citation as a bare
|
|
98
|
+
* quote with no `[source: …]` wrapper ("Write auth route tests — … — "…a test
|
|
99
|
+
* lands as fast as possible — in the same change — as each new route or React
|
|
100
|
+
* component/page.""), and that borrowed "each" made five correctly scoped
|
|
101
|
+
* per-area test tasks read as batch tasks (rep 5). Trading a possible miss (a
|
|
102
|
+
* batch title whose only quantifier sits inside a quote) for never deleting a
|
|
103
|
+
* properly scoped test task: the false positive is far the more expensive error.
|
|
104
|
+
*/
|
|
105
|
+
function stripQuotedSpans(s) {
|
|
106
|
+
return s.replace(/"[^"]*"/g, ' ').replace(/[“][^”]*[”]/g, ' ');
|
|
107
|
+
}
|
|
108
|
+
/** A title whose DELIVERABLE is tests: an authoring verb whose object is tests,
|
|
109
|
+
* with nothing else claimed in between ("Write component and page tests" ✓,
|
|
110
|
+
* "Add listings CRUD + tests" ✗ — the `+` marks tests as an additive constraint
|
|
111
|
+
* on a feature task, which is exactly the cadence the decision asks for). */
|
|
112
|
+
const TEST_AUTHORING_RE = /^\s*(?:(?:write|add|create|implement|author|build|develop|produce|backfill)\b[\w\s,/-]*\b(?:tests?|test suite|test coverage|testing)\b|(?:tests?|testing)\b)/i;
|
|
113
|
+
/** Enabling/infrastructure work — a runner, a config, fixtures, CI. Those are
|
|
114
|
+
* NOT batched test authoring; banning them would remove the very thing the
|
|
115
|
+
* per-change tests need to exist first. */
|
|
116
|
+
const TEST_INFRA_RE = /\b(?:harness|infrastructure|infra|runner|config|configuration|scaffold|scaffolding|set ?up|fixtures?|helpers?|utilities|utility|ci|pipeline|database|seed)\b/i;
|
|
117
|
+
/**
|
|
118
|
+
* WHOLE-PROJECT scope: a universal quantifier that governs a PROJECT-LEVEL target
|
|
119
|
+
* ("all components and pages", "every route"), not merely any noun.
|
|
120
|
+
*
|
|
121
|
+
* Both halves are load-bearing, each learned from a live false positive:
|
|
122
|
+
* - "full"/"complete" are excluded — they routinely scope a single area
|
|
123
|
+
* ("full login flow");
|
|
124
|
+
* - the quantifier must reach a project-level plural within ~20 chars, because
|
|
125
|
+
* "Test PartCard component — ALL badge combinations…" is a one-component task
|
|
126
|
+
* that a bare-quantifier rule flagged and DROPPED (live rep 3).
|
|
127
|
+
*/
|
|
128
|
+
const WHOLE_SCOPE_RE = /\b(?:all|every|each|entire|whole|comprehensive)\b[\w\s,/-]{0,20}?\b(?:components?|pages?|routes?|endpoints?|screens?|views?|modules?|layers?|files?|features?|app|application|project|codebase|repo|repository|system|surface)\b|\bacross the (?:app|application|project|codebase|repo|repository)\b|\bend[- ]to[- ]end coverage\b/i;
|
|
129
|
+
/**
|
|
130
|
+
* Indices of titles that are whole-project BATCH test tasks.
|
|
131
|
+
*
|
|
132
|
+
* Three conditions must all hold — the title's deliverable is tests, its scope is
|
|
133
|
+
* the whole project, and it is not test INFRASTRUCTURE. A per-feature task that
|
|
134
|
+
* carries "+ tests" never matches (its head names the feature), which is the
|
|
135
|
+
* point: those are the cadence the decision asks for.
|
|
136
|
+
*/
|
|
137
|
+
export function findBatchTestTitles(titles) {
|
|
138
|
+
const out = [];
|
|
139
|
+
for (let i = 0; i < titles.length; i++) {
|
|
140
|
+
const { body } = splitDecisions(titles[i]);
|
|
141
|
+
const scope = stripQuotedSpans(body);
|
|
142
|
+
const h = head(scope);
|
|
143
|
+
if (!TEST_AUTHORING_RE.test(h))
|
|
144
|
+
continue;
|
|
145
|
+
if (TEST_INFRA_RE.test(h))
|
|
146
|
+
continue;
|
|
147
|
+
if (!WHOLE_SCOPE_RE.test(scope))
|
|
148
|
+
continue;
|
|
149
|
+
out.push(i);
|
|
150
|
+
}
|
|
151
|
+
return out;
|
|
152
|
+
}
|
|
153
|
+
/** Test-runner commands a spec may name as the thing that REPORTS coverage. */
|
|
154
|
+
const TEST_COMMAND_RE = /\b(?:bun test|npm (?:run )?test|yarn test|pnpm (?:run )?test|npx (?:vitest|jest|playwright test)|playwright test|vitest|jest|pytest|go test|cargo test|mix test|rspec)\b[^`\n]*/i;
|
|
155
|
+
/**
|
|
156
|
+
* The spec's own coverage source — the command whose report scopes the sweep.
|
|
157
|
+
*
|
|
158
|
+
* Only backticked spans are considered, so the result is a command the spec
|
|
159
|
+
* actually writes down rather than a phrase inferred from prose; a span carrying
|
|
160
|
+
* a coverage flag wins over a plain test run. Falls back to a generic phrase when
|
|
161
|
+
* the spec names no command, which keeps the sweep title well-formed either way.
|
|
162
|
+
*/
|
|
163
|
+
export function coverageSourceFromSpec(spec) {
|
|
164
|
+
const spans = [...spec.matchAll(/`([^`\n]+)`/g)].map(m => m[1].trim());
|
|
165
|
+
const commands = spans.filter(s => TEST_COMMAND_RE.test(s));
|
|
166
|
+
const withCoverage = commands.find(s => /--coverage|\bcoverage\b/i.test(s));
|
|
167
|
+
return withCoverage ?? commands[0] ?? "the project's own test suite";
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Vocabulary that every testing task and every testing requirement shares, so it
|
|
171
|
+
* carries NO ownership signal here. Without this scrub the bare token "test"
|
|
172
|
+
* connects a screenshot-baseline requirement to "Write auth route tests", and the
|
|
173
|
+
* orphan check goes blind. (Scrubbed locally rather than added to
|
|
174
|
+
* COVERAGE_STOPWORDS: those govern the A/B-validated monotonic adoption guard,
|
|
175
|
+
* where "test" IS a discriminating noun for a plan that has no testing task at
|
|
176
|
+
* all.) Token-level, not regex — `mx5_test` must scrub to `mx5`.
|
|
177
|
+
*/
|
|
178
|
+
const GENERIC_TEST_TOKENS = new Set([
|
|
179
|
+
'test',
|
|
180
|
+
'tests',
|
|
181
|
+
'testing',
|
|
182
|
+
'tested',
|
|
183
|
+
'spec',
|
|
184
|
+
'specs',
|
|
185
|
+
'suite',
|
|
186
|
+
'suites',
|
|
187
|
+
'coverage',
|
|
188
|
+
'assertion',
|
|
189
|
+
'assertions',
|
|
190
|
+
'case',
|
|
191
|
+
'cases',
|
|
192
|
+
'unit',
|
|
193
|
+
'e2e'
|
|
194
|
+
]);
|
|
195
|
+
/** Drop the generic testing vocabulary, keeping the tokenization coverage-loop
|
|
196
|
+
* itself uses so the scrubbed text grounds exactly the same way. */
|
|
197
|
+
function scrubTestVocabulary(s) {
|
|
198
|
+
return s
|
|
199
|
+
.toLowerCase()
|
|
200
|
+
.split(/[^a-z0-9]+/)
|
|
201
|
+
.filter(w => w.length > 0 && !GENERIC_TEST_TOKENS.has(w))
|
|
202
|
+
.join(' ');
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Requirement indices that lose their owner when the batch titles are removed.
|
|
206
|
+
*
|
|
207
|
+
* Two independent measures, unioned:
|
|
208
|
+
*
|
|
209
|
+
* 1. STRICT (the one that actually fires): generic testing vocabulary scrubbed
|
|
210
|
+
* from both sides, and a requirement that is ABOUT testing may only be owned
|
|
211
|
+
* by a title that is about testing — "Implement login page" does not
|
|
212
|
+
* discharge "every component/page test captures a screenshot".
|
|
213
|
+
* 2. PLAIN groundedCoverage, exactly as the monotonic adoption guard measures
|
|
214
|
+
* it. This is the belt: whatever that guard would call a drop is an orphan
|
|
215
|
+
* here too, so the rewrite can never trip the guard it feeds.
|
|
216
|
+
*/
|
|
217
|
+
function orphanedRequirements(quotes, titles, kept, isCrossCutting) {
|
|
218
|
+
const scrubbed = quotes.map(scrubTestVocabulary);
|
|
219
|
+
// Index-aligned cross-cutting lookup: the scrubbed text is not the quote the
|
|
220
|
+
// classifier expects, so map back to the original.
|
|
221
|
+
const crossByScrub = new Map();
|
|
222
|
+
quotes.forEach((q, i) => crossByScrub.set(scrubbed[i], isCrossCutting(q)));
|
|
223
|
+
const isCrossScrubbed = (s) => crossByScrub.get(s) ?? false;
|
|
224
|
+
const testish = (t) => TEST_WORD_RE.test(t);
|
|
225
|
+
const scrub = (list) => list.map(scrubTestVocabulary);
|
|
226
|
+
const strictBefore = groundedCoverage(scrubbed, scrub(titles), isCrossScrubbed);
|
|
227
|
+
const strictAfterAll = groundedCoverage(scrubbed, scrub(kept), isCrossScrubbed);
|
|
228
|
+
const strictAfterTest = groundedCoverage(scrubbed, scrub(kept.filter(testish)), isCrossScrubbed);
|
|
229
|
+
const plainBefore = groundedCoverage(quotes, titles, isCrossCutting);
|
|
230
|
+
const plainAfter = groundedCoverage(quotes, kept, isCrossCutting);
|
|
231
|
+
const out = [];
|
|
232
|
+
for (let i = 0; i < quotes.length; i++) {
|
|
233
|
+
const owner = testish(quotes[i]) ? strictAfterTest : strictAfterAll;
|
|
234
|
+
const strictLost = strictBefore.has(i) && !owner.has(i);
|
|
235
|
+
const plainLost = plainBefore.has(i) && !plainAfter.has(i);
|
|
236
|
+
if (strictLost || plainLost)
|
|
237
|
+
out.push(i);
|
|
238
|
+
}
|
|
239
|
+
return out;
|
|
240
|
+
}
|
|
241
|
+
/** How many orphaned requirement quotes the sweep title names, and how long each
|
|
242
|
+
* may be — a title is a one-line handoff, not a ledger. */
|
|
243
|
+
const MAX_SWEEP_QUOTES = 6;
|
|
244
|
+
const MAX_QUOTE_CHARS = 120;
|
|
245
|
+
function shorten(q) {
|
|
246
|
+
const s = q.replace(/\s+/g, ' ').trim();
|
|
247
|
+
return s.length <= MAX_QUOTE_CHARS ? s : s.slice(0, MAX_QUOTE_CHARS - 1).trimEnd() + '…';
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* The scoped replacement: a gap-filling sweep, bounded by what the coverage
|
|
251
|
+
* source reports and by the requirements that lost their only owner. It states
|
|
252
|
+
* the ban explicitly, because the child that receives this title sees nothing
|
|
253
|
+
* else.
|
|
254
|
+
*/
|
|
255
|
+
export function buildSweepTitle(orphaned, coverageSource) {
|
|
256
|
+
const named = orphaned.slice(0, MAX_SWEEP_QUOTES).map(q => `"${shorten(q)}"`);
|
|
257
|
+
const more = orphaned.length > named.length ? ` (+${orphaned.length - named.length} more)` : '';
|
|
258
|
+
return (`Fill the test-coverage gaps left by the per-change tests — run \`${coverageSource}\`,`
|
|
259
|
+
+ ' and add tests ONLY for what it reports uncovered, specifically:'
|
|
260
|
+
+ ` ${named.join('; ')}${more}.`
|
|
261
|
+
+ ' Do NOT re-test what earlier tasks already covered, and do NOT modify'
|
|
262
|
+
+ ' existing test config or existing tests.');
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Rewrite a decomposed plan so it carries no whole-project batch test task when
|
|
266
|
+
* the decisions mandate tests-in-the-same-change.
|
|
267
|
+
*
|
|
268
|
+
* No mandate, or no batch title ⇒ the plan is returned untouched (identity), so
|
|
269
|
+
* every non-cadence run behaves exactly as before.
|
|
270
|
+
*
|
|
271
|
+
* With a mandate, ALL batch titles are removed at once before coverage is
|
|
272
|
+
* re-measured — otherwise two batch tasks would each mask the other's orphans and
|
|
273
|
+
* both would look droppable. The orphaned set is then whatever grounded coverage
|
|
274
|
+
* the removal costs; it is non-empty only when no other task's title claims that
|
|
275
|
+
* requirement, and it becomes the sweep's scope. At most ONE sweep is emitted (in
|
|
276
|
+
* the first batch title's position, so plan order is preserved).
|
|
277
|
+
*/
|
|
278
|
+
export function rewriteBatchTestPlan(titles, decisions, spec, requirementQuotes, isCrossCutting) {
|
|
279
|
+
if (!mandatesTestsInSameChange(decisions, spec))
|
|
280
|
+
return { titles, actions: [] };
|
|
281
|
+
const batch = findBatchTestTitles(titles);
|
|
282
|
+
if (batch.length === 0)
|
|
283
|
+
return { titles, actions: [] };
|
|
284
|
+
const batchSet = new Set(batch);
|
|
285
|
+
const kept = titles.filter((_, i) => !batchSet.has(i));
|
|
286
|
+
const orphaned = orphanedRequirements(requirementQuotes, titles, kept, isCrossCutting).map(i => requirementQuotes[i]);
|
|
287
|
+
const actions = [];
|
|
288
|
+
const out = [];
|
|
289
|
+
let sweepEmitted = false;
|
|
290
|
+
for (let i = 0; i < titles.length; i++) {
|
|
291
|
+
if (!batchSet.has(i)) {
|
|
292
|
+
out.push(titles[i]);
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
if (orphaned.length === 0 || sweepEmitted) {
|
|
296
|
+
actions.push({ index: i, title: titles[i], kind: 'dropped', orphaned: [] });
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
299
|
+
// Carry the offending title's own [decisions: …] clauses onto the sweep —
|
|
300
|
+
// they are user directives and survive the reshaping of the task.
|
|
301
|
+
const { tail } = splitDecisions(titles[i]);
|
|
302
|
+
const replacement = buildSweepTitle(orphaned, coverageSourceFromSpec(spec)) + tail;
|
|
303
|
+
actions.push({ index: i, title: titles[i], kind: 'scoped', replacement, orphaned });
|
|
304
|
+
out.push(replacement);
|
|
305
|
+
sweepEmitted = true;
|
|
306
|
+
}
|
|
307
|
+
return { titles: out, actions };
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* The decompose-prompt rule (the belt; the host rewrite above is the lever).
|
|
311
|
+
* Emitted ONLY when the decisions mandate the cadence, so ordinary runs see the
|
|
312
|
+
* prompt they always saw. Kept next to the detector so the two cannot drift.
|
|
313
|
+
*/
|
|
314
|
+
export const DECOMPOSE_NO_BATCH_TESTS_RULE = '- The CLARIFICATIONS mandate that tests land in the SAME change as the code they'
|
|
315
|
+
+ ' cover. So do NOT emit a task whose job is writing tests for all components /'
|
|
316
|
+
+ ' all routes / the whole project — that shape is rejected host-side. Fold each'
|
|
317
|
+
+ " test into the task that builds the thing it tests (name it in that task's"
|
|
318
|
+
+ ' title), and emit a separate testing task ONLY as a narrowly scoped sweep of'
|
|
319
|
+
+ ' gaps a coverage run reports. Test INFRASTRUCTURE (runner, config, fixtures)'
|
|
320
|
+
+ ' may still be its own early task.';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mjasnikovs/pi-task",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.41",
|
|
4
4
|
"description": "Deterministic task planning and spec-orchestration for local models — crash-safe /task pipelines with verify/enforce gates, a real-time remote web view, and web/docs/fetch/worker subagent tools.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|