Files
msd-core/tests
Tom Boucher 9cbb48afa1 fix(#2753): scan every key occurrence when asserting a documented default (#2756)
* fix(#2753): scan every key occurrence when asserting a documented default

The settings-default assertion located each key with indexOf and checked only a
400-char window after the FIRST match. Its stated contract is "the workflow
documents the default for this key"; what it actually asserted was "the first
mention of this key is followed by the default" - an ordering assumption that was
never part of the contract and that breaks the moment a workflow names a key in
prose before its settings-table entry.

PR #2558 does exactly that: a shared language directive puts response_language at
index 6 while the table documents null at 7185, so the gate failed a document that
was correct, and the failure message showed the prose window rather than the cause.

Extracted findDocumentedDefault, which scans every occurrence and reports how many
it examined. Widening the window to the whole file was rejected - it would pass on
any unrelated occurrence of the token - as was parsing the settings table, which
would couple the check to table markup. The negative case still fails: a key that
no occurrence documents is a failure, now with the occurrence count so a genuine
miss stays distinguishable from this false negative.

* fix(#2753): guard the empty needle and de-vacuum the newline test

Isolated review found a real hang: String#indexOf('', pos) clamps to str.length
rather than returning -1, so an empty key made the scan loop stabilize at the end
of the document and spin forever. Unreachable from SPEC_FIELDS today, but the
docstring claimed termination while reasoning only about self-overlap. Guarded,
with the clamping behavior named so the guard is not tidied away later.

The newline test asserted only that CRLF and LF agree, which a constant stub
satisfies. It now pins the absolute verdict on both, plus a document neither style
can rescue.

Added the property test the review noted was missing: windowSize is a budget limit,
so the verdict is asserted to be exactly "key + gap + default fits the window" over
disjoint alphabets. It would have caught the empty-key hang on its own.

* fix(#2753): assert examined-occurrence count, not the document's total

The no-regression test asserted occurrences === 2 because the fixture mentions the
key twice. The scan short-circuits on the first documenting window, so exactly one
occurrence is examined - the assertion was describing the fixture rather than the
function.

Documented the semantic properly instead of just correcting the number:
occurrences is how many were EXAMINED before deciding, so on success it is the
1-based position of the match and on failure the document's full count. The
asymmetry is deliberate - the failure path is where the number must be trustworthy,
since "examined N, none documented it" is what separates a genuine miss from the
first-occurrence false negative this function removes.
2026-07-28 08:58:27 -04:00
..