--- a/research/qc/questions.js +++ b/research/qc/questions.js @@ -33,9 +33,16 @@ // untracked note is new. `residue-only` remains a supported declaration. // -// Several notes may share an id. Their statuses are reported as one status only -// when they agree; otherwise the index prints MIXED with each note's status. -// The verdict shown is the last note's in path order; the full chain is listed. +// Several notes may share an id. They are reported under one status only when they +// agree on the status AND on the verdict; otherwise the index prints MIXED, naming +// which axis disagrees and each note's own status, so a reader opens the records +// instead of trusting a rank. The verdict shown is the NEWEST note's by last commit +// date (the parity gate's source for dates), with the last-in-path-order rule kept +// as the tiebreak and as the fallback where git is absent; the full chain is always +// listed. (2026-09-13, job #609: the two Q-rho-maximal-law notes agree on PARTIAL +// and disagree on the verdict, and path order displayed the OLDER one -- 2026-08-19 +// "model-dependent and undecided" -- over the 2026-08-28 note that had moved past +// it to "measured against rather than undecided".) // // research/QUESTIONS.md is GENERATED from these blocks (node research/qc.js // --index, or node research/gen-questions-index.js) and is the one place to @@ -57,6 +64,8 @@ const C = require('./corpus'); const STATUSES = new Set(['OPEN', 'PARTIAL', 'ANSWERED', 'CLOSED', 'SUPERSEDED']); +// One separator for every path comparison in this file (see indexedFiles). +const slash = f => C.rel(f).split(path.sep).join('/'); const BLOCK_RE = //; const TODO_PATH = path.join(C.ROOT, 'TODO.md'); const OUT_PATH = path.join(C.RESEARCH, 'QUESTIONS.md'); @@ -66,8 +75,17 @@ // a `Q-registry-` block (their question is what they index); generated // files (SCRIPTS.md, QUESTIONS.md) carry none and are excluded by corpus.js. History other than staging is never // audited (qc/README.md), and that boundary holds here too. - const staging = C.historyMarkdown.filter(f => /history\/staging\//.test(f)); - const body = C.bodyMarkdown.filter(f => /^research\/[^/]+\.md$/.test(C.rel(f))); + // + // PATHS ARE COMPARED IN ONE SEPARATOR (2026-09-13). These filters used to + // match a literal '/', which is right on POSIX and wrong on Windows, where + // path.relative yields '\'. On Windows the two filters then matched NOTHING: + // indexedFiles() returned [], collect() saw 0 notes, and --index wrote a + // QUESTIONS.md carrying 0 questions from 0 indexed notes, exit code 0. The + // ledger gate reported "0 of 0 notes carry a ledger block" and stayed clean + // for the same reason. Ported the paths once here rather than in every + // regex: `slash()` is the only place a separator is spelled. + const staging = C.historyMarkdown.filter(f => slash(f).includes('history/staging/')); + const body = C.bodyMarkdown.filter(f => /^research\/[^/]+\.md$/.test(slash(f))); return [...staging, ...body].sort(); } @@ -206,6 +224,44 @@ return addDates; } +// The display choice, as a pure function so it can be checked without git: +// `group` is the notes sharing one id, `dates` a Map(relpath -> 'YYYY-MM-DD'). +// A file git does not know counts as NEW (the parity gate's convention, above), +// and with no dates at all the last note in path order wins, which is exactly +// the rule this replaced. +function pickNewest(group, dates, rel) { + const known = group.filter(x => dates.has(rel(x.file))); + const newest = known.length === group.length + ? known.filter(x => dates.get(rel(x.file)) === known.map(y => dates.get(rel(y.file))).sort().pop()) + : group.filter(x => !dates.has(rel(x.file))); + return newest[newest.length - 1]; +} + +let lastDates = null; +function fileLastDates() { + // Last-commit date of every file under research/, one git call, cached: the + // display rule's date source (see summarise). `git log --name-only` walks + // newest first, so the FIRST time a file appears is its most recent change. + // The parity gate above reads the same log for first-commit dates. A corpus + // without git yields an empty map, and then summarise falls back to path + // order, exactly what it did before this rule existed. + if (lastDates) return lastDates; + lastDates = new Map(); + try { + const out = require('child_process').execFileSync('git', + ['-C', C.ROOT, 'log', '--format=%as', '--name-only', '--', 'research'], + { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }); + let date = null; + for (const ln of out.split('\n')) { + if (/^\d{4}-\d\d-\d\d$/.test(ln)) { date = ln; continue; } + const f = ln.trim(); + if (!f || !date || lastDates.has(f)) continue; // newest first: the first hit wins + lastDates.set(f, date); + } + } catch (e) { /* no git: the display rule keeps path order */ } + return lastDates; +} + function parity() { const { rows } = collect(); const dates = fileAddDates(); @@ -258,9 +314,9 @@ // THE GENERATOR — research/QUESTIONS.md // --------------------------------------------------------------------------- const cell = s => String(s || '').replace(/\|/g, '\\|').replace(/\n/g, ' ').trim(); -const link = f => { const r = C.rel(f); const p = r.replace(/^research\//, ''); return `[${path.basename(r)}](${p})`; }; - -function generate() { +const link = f => { const r = slash(f); const p = r.replace(/^research\//, ''); return `[${path.basename(r)}](${p})`; }; + +function renderQuestions() { const { rows, todo } = collect(); const withBlock = rows.filter(r => r.block && r.block.id); const byId = new Map(); @@ -268,19 +324,30 @@ const ids = [...byId.keys()].sort(); const summarise = id => { const g = byId.get(id); - // Deterministic display choice: the last note in path order supplies the - // verdict. This is NOT chronology or review precedence. List every record - // and explain the choice in the generated preamble. - const last = g[g.length - 1].block; - // A shared id carries one status ONLY when its notes agree. When they do not, - // the index says MIXED and lists each note's own status, so a reader opens - // them instead of trusting a rank. (2026-08-28 red team: taking the highest - // rank showed Q-c2prime-drift as CLOSED while its earlier note reads PARTIAL - // and the later one closed on a weaker window.) + // Deterministic display choice: the NEWEST note supplies the verdict, where + // newest is the last commit date of its file -- one cached git call. This is + // chronology of the FILES, not review precedence, and it is not authority: + // an accepted review of an older note still outranks a newer one, so read + // the chain. A file git does not know counts as NEW (the parity gate's + // convention), and a corpus without git keeps the old path-order rule. + // Within the newest-dated set the last in path order wins, so the choice + // stays deterministic. (2026-09-13, job #609 -- see the header.) + const chosen = pickNewest(g, fileLastDates(), C.rel); + // A shared id carries one status ONLY when its notes agree on the status AND + // on the verdict. When either disagrees the index says MIXED, names the axis + // and lists each note's own status, so a reader opens them instead of + // trusting a rank. (2026-08-28 red team: taking the highest rank showed + // Q-c2prime-drift as CLOSED while its earlier note reads PARTIAL and the + // later one closed on a weaker window.) const statuses = [...new Set(g.map(x => x.block.status))]; - const status = statuses.length === 1 ? statuses[0] - : 'MIXED (' + g.map(x => path.basename(x.file) + ': ' + x.block.status).join('; ') + ')'; - return { id, question: last.question, status, verdict: last.verdict, files: g.map(x => x.file), todo: [...new Set(g.flatMap(x => x.block.todo.map(t => t.id + (t.retired ? ' (retired)' : ''))))] }; + const verdicts = new Set(g.map(x => x.block.verdict)); + const status = statuses.length === 1 && verdicts.size === 1 ? statuses[0] + : statuses.length > 1 + ? 'MIXED (statuses differ: ' + g.map(x => path.basename(x.file) + ': ' + x.block.status).join('; ') + ')' + : 'MIXED (verdicts differ across ' + g.length + ' records)'; + return { id, question: chosen.block.question, status, verdict: chosen.block.verdict, + files: g.map(x => x.file), + todo: [...new Set(g.flatMap(x => x.block.todo.map(t => t.id + (t.retired ? ' (retired)' : ''))))] }; }; const S = ids.map(summarise); @@ -307,10 +374,14 @@ out.push('does not refute every related conjecture. SUPERSEDED: another record replaces'); out.push('this one. Consult the owning note and linked reviews for HELD or other grades.'); out.push(''); - out.push('**Multiple records:** conflicting statuses are shown as MIXED. The displayed'); - out.push('verdict comes from the last record in path order, not necessarily the newest'); - out.push('or most authoritative review. Read the linked records before resolving a'); - out.push('disagreement; the generator does not adjudicate it.'); + out.push('**Multiple records:** a shared id is shown under one status only when its'); + out.push('records agree on the status and on the verdict; otherwise the row reads MIXED,'); + out.push("naming which of the two disagrees and each record's own status. The displayed"); + out.push('verdict comes from the record with the newest last-commit date (a file git does'); + out.push('not track counts as newest; without git, the last record in path order), which'); + out.push('is chronology of the files, not necessarily the most authoritative review.'); + out.push('Read the linked records before resolving a disagreement; the generator does not'); + out.push('adjudicate it.'); out.push(''); out.push('## 1. By TODO item: what has already run under each'); out.push(''); @@ -340,11 +411,76 @@ out.push(''); for (const r of missing) out.push(`- ${link(r.file)}: ${cell(r.title)}`); out.push(''); - fs.writeFileSync(OUT_PATH, out.join('\n')); - return { questions: S.length, notes: withBlock.length, unindexed: missing.length }; -} - -module.exports = { parity, ledger, ledgerBacklog, generate, collect }; + return { text: out.join('\n'), questions: S.length, notes: withBlock.length, unindexed: missing.length }; +} + +function generate() { + const r = renderQuestions(); + fs.writeFileSync(OUT_PATH, r.text); + return { questions: r.questions, notes: r.notes, unindexed: r.unindexed }; +} + +// --------------------------------------------------------------------------- +// THE CHECK: registry drift. +// +// research/QUESTIONS.md is GENERATED from the notes' ledger blocks, so each row +// is a COPY and has exactly one mechanical failure mode: the ledger block (or +// the revision its patch carried) lands and the index is never regenerated. +// Nothing else in this file tests that, and it is the defect the served +// snapshot actually shows on 2026-09-13: six of the fifty-three open/partial +// rows are not what their own sources say -- Q-xchan-at29-prereg, +// Q-shadow-prereg, Q-centered-discrepancy-estimate, +// Q-fixed-endpoint-discrepancy, Q-global-factor-signs and Q-derive-0904-L7-transfer +// (job #587, return #230; the row-37 note is byte-for-byte the file accepted +// audit #152 names as its revised document and the index still prints the +// pre-#152 verdict). +// +// THE FIX IS ALWAYS THE SAME, which is why this is one finding kind and not a +// family: regenerate. A row that disagrees with its own block cannot be +// hand-edited (the next regeneration overwrites it), and if the BLOCK is the +// stale thing then the correction belongs in the note -- this check cannot tell +// which, so it names the row and says both. +// --------------------------------------------------------------------------- +function registryDrift() { + const now = renderQuestions(); + const findings = []; + const rowsOf = (text, into) => { + for (const ln of text.split('\n')) { + const m = /^\|\s*`([^`]+)`\s*\|/.exec(ln); + if (m && !into.has(m[1])) into.set(m[1], ln); + } + return into; + }; + if (!fs.existsSync(OUT_PATH)) { + findings.push({ file: 'research/QUESTIONS.md', line: 1, kind: 'registry-missing', + detail: 'the generated index does not exist', + note: 'run `node research/qc.js --index` and commit research/QUESTIONS.md' }); + return { name: 'registry-drift', description: 'the generated index exists and matches its ledger blocks (0 rows)', findings }; + } + const onDisk = fs.readFileSync(OUT_PATH, 'utf8').split('\r\n').join('\n'); + const was = rowsOf(onDisk, new Map()); + const is = rowsOf(now.text, new Map()); + for (const [id, line] of is) { + const old = was.get(id); + if (old === undefined) { + findings.push({ file: 'research/QUESTIONS.md', line: 1, kind: 'registry-row-missing', + detail: `${id} carries a ledger block but has no row in the index`, + note: 'run `node research/qc.js --index` and commit research/QUESTIONS.md' }); + } else if (old !== line) { + findings.push({ file: 'research/QUESTIONS.md', line: 1, kind: 'registry-row-stale', + detail: `${id}: the row is not what its own ledger block(s) say`, + note: 'THE REGISTRY DRIFT: this file is generated, so a row that disagrees with its source means the index was not regenerated after the block or its integrated revision landed. Regenerate (`node research/qc.js --index`) and commit. If the BLOCK is the stale thing, fix the note instead -- this check cannot tell, and a hand-edit to this file is overwritten at the next regeneration.' }); + } + } + for (const id of was.keys()) if (!is.has(id)) + findings.push({ file: 'research/QUESTIONS.md', line: 1, kind: 'registry-row-orphan', + detail: `${id} has a row in the index but no ledger block carries the id now`, + note: 'regenerate; a row whose block was removed or renamed should not survive in the index' }); + return { name: 'registry-drift', + description: `the generated index is exactly what its ledger blocks generate (${is.size} rows)`, findings }; +} + +module.exports = { parity, ledger, ledgerBacklog, generate, renderQuestions, registryDrift, collect, pickNewest, fileLastDates }; if (require.main === module) { const r = generate();