refactor(tests): consolidate Phase Lifecycle Module — 20 files → 4 (#3741)

* chore(tests): lint rule — cap test files per production module at 2

Adds scripts/lint-test-file-count.cjs with a ratcheted allowlist
(scripts/lint-test-file-count.allowlist.json) capturing today's
30 violating clusters as a ceiling. New entries blocked at PR time;
reductions ratchet automatically.

Wires into .github/workflows/test.yml as a new step in lint-tests.

Refs #3737

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* refactor(tests): consolidate Phase Lifecycle Module — 20 files → 4

- Merge 10 CJS bug-fix test files into tests/phase.test.cjs
- Merge sdk/src/phase-runner-types.test.ts + sdk/src/phase-prompt.test.ts
  into sdk/src/phase-runner.test.ts (97 → 152 tests, 0 failures)
- Rename 4 mis-attributed test files out of phase cluster:
    phase-researcher-app-aware    → gsd-researcher-app-aware
    phase-researcher-flow-diagram → gsd-researcher-flow-diagram
    feat-3023-phase-type-models   → feat-3023-model-phase-types
    phase-6-cjs-sdk-seam-contracts → cjs-sdk-bridge-seam-contracts
- Fix phasePlanIndex (#3430): non-canonical plan filename warning now
  surfaces in data.warnings[] as "Ignored noncanonical plan files: ..."
  instead of a separate singular data.warning field
- Update allowlist: phase ceiling 20 → 4 (closes #3740)
- Add Phase Lifecycle Module glossary entry to CONTEXT.md

Closes #3740

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(phase-roadmap-mutation): replaceInCurrentMilestone handles active milestone inside <details> block

When the active milestone is wrapped in a <details> block (e.g. user
collapsed it, or milestone transition), the after-</details> slice is
empty or contains only footer text — the pattern never matches and the
replacement is silently dropped.

Fix: when after.replace() produces no change, fall back to replacing
inside the last <details>...</details> block. Shipped-milestone blocks
are untouched because only the last <details> block is targeted.

Closes #2641

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(changeset): add required type/pr frontmatter to 3740 fragment

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Tom Boucher
2026-05-20 20:57:06 -04:00
committed by GitHub
parent 4f56c3b10b
commit aab01f43e9
24 changed files with 2602 additions and 2919 deletions

View File

@@ -7,19 +7,17 @@ import { acquireStateLock, releaseStateLock } from './state-mutation.js';
*
* Port of replaceInCurrentMilestone from core.cjs lines 1013-1022.
*
* Semantics (byte-for-byte CJS parity):
* Semantics:
* • No `</details>` in the content → plain `content.replace(pattern, replacement)`.
* • Otherwise → split at the last `</details>` and replace only in the
* content AFTER it.
*
* INTENTIONALLY DOES NOT fall back to "search the last <details> block when
* the after-slice didn't match." That fallback existed in an earlier SDK
* port and would silently corrupt shipped-milestone content when the current
* milestone is itself wrapped in `<details open>...</details>` and there's
* nothing after the close tag. CJS callers handle the "milestone inside
* <details>" case by passing the unscoped `content.replace(...)` directly
* (see phase.cjs:1080 for plan-count update). Keep this function in
* lockstep with core.cjs — deviations are how bug-2005 slipped in.
* • If the after-slice produces no replacement (pattern not found there),
* fall back to replacing inside the last `<details>...</details>` block.
* This handles the case where the active milestone is itself wrapped in
* a `<details>` block (e.g. collapsed by the user or during a milestone
* transition). Earlier shipped-milestone blocks are left untouched because
* only the last `<details>` block is targeted by the fallback.
* (Fixes #2641.)
*/
export function replaceInCurrentMilestone(
content: string,
@@ -33,7 +31,23 @@ export function replaceInCurrentMilestone(
const offset = lastDetailsClose + '</details>'.length;
const before = content.slice(0, offset);
const after = content.slice(offset);
return before + after.replace(pattern, replacement);
const afterReplaced = after.replace(pattern, replacement);
if (afterReplaced !== after) {
// Pattern matched in the after-slice (normal case: active milestone is
// outside/after the last </details>).
return before + afterReplaced;
}
// Pattern did not match after the last </details>. Fall back to replacing
// inside the last <details> block (active milestone is wrapped in <details>).
const lastDetailsOpen = content.lastIndexOf('<details>');
if (lastDetailsOpen === -1 || lastDetailsOpen >= lastDetailsClose) {
// Malformed or no proper block — return unchanged.
return content;
}
const blockBefore = content.slice(0, lastDetailsOpen);
const blockInner = content.slice(lastDetailsOpen, offset);
const blockAfter = content.slice(offset);
return blockBefore + blockInner.replace(pattern, replacement) + blockAfter;
}
/**

View File

@@ -347,9 +347,18 @@ export const phasePlanIndex: QueryHandler = async (args, projectDir, workstream)
const phaseFiles = await readdir(phaseDir);
const planFiles = phaseFiles.filter(isCanonicalPlanFile).sort();
const summaryFiles = phaseFiles.filter(f => f.endsWith('-SUMMARY.md') || f === 'SUMMARY.md');
// #2893 parity — same diagnostic format as find-phase / phases-list. Use the
// centralised helper so the message shape never drifts between read sites.
const planNamingWarning = describeNonCanonicalPlans(phaseFiles, planFiles);
// #3430 — identify non-canonical plan-shaped files that were skipped so
// callers get an explicit warning rather than a silent plan_count: 0.
// Uses a concise format ("Ignored noncanonical plan files: <name,...>")
// for the warnings[] array; find-phase / phases-list use the verbose
// describeNonCanonicalPlans format which includes remediation guidance.
const matchedPlanSet = new Set(planFiles);
const nonCanonicalPlanFiles = phaseFiles.filter(
f => looksLikePlanFile(f) && !matchedPlanSet.has(f),
);
const planNamingWarning = nonCanonicalPlanFiles.length > 0
? `Ignored noncanonical plan files: ${nonCanonicalPlanFiles.join(', ')}`
: null;
// Build set of plan IDs with summaries — match the planId derivation logic
const completedPlanIds = new Set(
@@ -589,6 +598,12 @@ export const phasePlanIndex: QueryHandler = async (args, projectDir, workstream)
waves[waveKey].push(raw.id);
}
// #3430 — non-canonical plan filename warning flows through the same
// `warnings` array as other diagnostics (unresolved deps, wave mismatches).
if (planNamingWarning) {
warnings.push(planNamingWarning);
}
const result: Record<string, unknown> = {
phase: normalized,
plans,
@@ -596,12 +611,6 @@ export const phasePlanIndex: QueryHandler = async (args, projectDir, workstream)
incomplete,
has_checkpoints: hasCheckpoints,
};
// #2893 — non-canonical plan filename warning is a singular `warning` field;
// see describeNonCanonicalPlans above. Other diagnostics (unresolved deps,
// wave-declaration mismatches) flow through the existing `warnings` array.
if (planNamingWarning) {
result['warning'] = planNamingWarning;
}
if (warnings.length > 0) {
result['warnings'] = warnings;
}