* fix(#2770): coerce non-string truths to preserve cross-cutting constraints `cmdRoadmapAnnotateDependencies` skipped non-string truth entries via `if (typeof t !== 'string') continue`. That avoided the TypeError reported in #2770 but silently dropped legitimate constraints — numeric YAML scalars (`- 3`) and kv-shaped truths from parseMustHavesBlock's continuation-kv path (#2757) — from the cross-cutting analysis, leaving ROADMAP.md under-annotated. Replace the skip-guard with a `coerceTruthToString` helper that: * passes strings through * `String()`-coerces numbers, booleans, bigints * extracts a string field (title, text, name, rule, path, provides) from object-shaped items Composes cleanly with #2757 (objects from kv continuation lines now contribute their title rather than being dropped) and the existing `splitInlineArray` quote-aware parser. Tests: tests/bug-2770-annotate-deps-int-coerce.test.cjs - numeric scalar truth shared across plans surfaces as constraint - kv-shaped truth surfaces via title field - bare-int depends_on regression guards on extractFrontmatter Full suite: 5678 pass, 0 fail. Closes #2770 * test(#2770): use array join() for multi-line fixtures per CONTRIBUTING * refactor(#2770): cache trim() and avoid no-op truthCounts.set in aggregation
This commit is contained in:
@@ -6,6 +6,35 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { escapeRegex, normalizePhaseName, planningPaths, withPlanningLock, output, error, findPhaseInternal, stripShippedMilestones, extractCurrentMilestone, replaceInCurrentMilestone, phaseTokenMatches, atomicWriteFileSync } = require('./core.cjs');
|
||||
|
||||
/**
|
||||
* Coerce an arbitrary YAML scalar/object into a string for cross-cutting
|
||||
* truth aggregation. Handles:
|
||||
* - strings (passthrough)
|
||||
* - numbers / booleans (String() coercion — issue #2770: bare YAML ints
|
||||
* like `- 3` must be surfaced, not silently skipped)
|
||||
* - kv-shaped objects from parseMustHavesBlock continuation kv (issue
|
||||
* #2757) — extract the first meaningful string field
|
||||
*
|
||||
* Returns the empty string when no usable text can be derived; callers should
|
||||
* skip empty results.
|
||||
*/
|
||||
function coerceTruthToString(t) {
|
||||
if (t === null || t === undefined) return '';
|
||||
if (typeof t === 'string') return t;
|
||||
if (typeof t === 'number' || typeof t === 'boolean' || typeof t === 'bigint') {
|
||||
return String(t);
|
||||
}
|
||||
if (typeof t === 'object') {
|
||||
// Prefer common title-bearing keys produced by parseMustHavesBlock
|
||||
for (const k of ['title', 'text', 'name', 'rule', 'path', 'provides']) {
|
||||
const v = t[k];
|
||||
if (typeof v === 'string' && v.trim()) return v;
|
||||
if (typeof v === 'number' || typeof v === 'boolean') return String(v);
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for a phase header (and its section) within the given content string.
|
||||
* Returns a result object if found (either a full match or a malformed_roadmap
|
||||
@@ -412,16 +441,26 @@ function cmdRoadmapAnnotateDependencies(cwd, phaseNum, raw) {
|
||||
}
|
||||
const waves = [...waveGroups.keys()].sort((a, b) => a - b);
|
||||
|
||||
// Find cross-cutting truths: appear in 2+ plans (de-duplicated, case-insensitive)
|
||||
// Find cross-cutting truths: appear in 2+ plans (de-duplicated, case-insensitive).
|
||||
//
|
||||
// Issue #2770: must **coerce, not skip**. A previous guard
|
||||
// `if (typeof t !== 'string') continue` silently dropped numeric scalars
|
||||
// (YAML ints like `- 3`) and kv-shaped truths (`- title: X`), so the
|
||||
// cross-cutting analysis lost real constraints rather than crashing on
|
||||
// `t.trim()`. We coerce primitives via `String(t)` and extract a sensible
|
||||
// string field from object-shaped items produced by parseMustHavesBlock's
|
||||
// continuation-kv path (issue #2757 produces those shapes for nested keys).
|
||||
const truthCounts = new Map();
|
||||
for (const { truths } of planData) {
|
||||
const seen = new Set();
|
||||
for (const t of truths) {
|
||||
if (typeof t !== 'string') continue;
|
||||
const key = t.trim().toLowerCase();
|
||||
const text = coerceTruthToString(t);
|
||||
if (!text) continue;
|
||||
const trimmed = text.trim();
|
||||
const key = trimmed.toLowerCase();
|
||||
if (!key || seen.has(key)) continue;
|
||||
seen.add(key);
|
||||
truthCounts.set(key, (truthCounts.get(key) || { count: 0, text: t.trim() }));
|
||||
if (!truthCounts.has(key)) truthCounts.set(key, { count: 0, text: trimmed });
|
||||
truthCounts.get(key).count++;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user