#!/usr/bin/env node // Synthetic teaching checker. No language understanding, inference or entitlement lookup. import { readFileSync } from 'node:fs'; import { resolve } from 'node:path'; import { pathToFileURL } from 'node:url'; export const expectedFixtures = Object.freeze([ { fixtureId: 'F1', disposition: 'supported', meanings: ['C44_East_critical', 'one_hour_acknowledgement', 'not_resolution_guarantee'] }, { fixtureId: 'F2', disposition: 'blocked', meanings: ['wrong_account_region', 'no_entitlement_transfer'] }, { fixtureId: 'F3', disposition: 'blocked', meanings: ['acknowledgement_not_resolution'] }, { fixtureId: 'F4', disposition: 'qualified', meanings: ['activation_not_established'] }, { fixtureId: 'F5', disposition: 'unresolved', meanings: ['equal_authority_conflict', 'owner_review_required'] }, { fixtureId: 'F6', disposition: 'reference', meanings: ['evaluator_unavailable', 'authorized_reference_only'] }, { fixtureId: 'F7', disposition: 'supported', meanings: ['C44_East_critical', 'one_hour_acknowledgement', 'not_resolution_guarantee'] }, ].map(fixture => Object.freeze({ ...fixture, meanings: Object.freeze(fixture.meanings) }))); export function teachingRecords() { return expectedFixtures.map(fixture => ({ ...fixture, meanings: [...fixture.meanings], candidateId: fixture.fixtureId + '-candidate-1', reviewedCandidateId: fixture.fixtureId + '-candidate-1' })); } export function reconcile(records) { const problems = []; if (!Array.isArray(records)) return { pass: false, intended: expectedFixtures.length, observed: 0, problems: ['Observed records must be an array.'] }; const ids = new Set(expectedFixtures.map(fixture => fixture.fixtureId)); for (const record of records) { if (!record || typeof record !== 'object' || !ids.has(record.fixtureId)) problems.push('Unknown or malformed observed fixture.'); } for (const fixture of expectedFixtures) { const matches = records.filter(record => record?.fixtureId === fixture.fixtureId); if (matches.length !== 1) { problems.push(fixture.fixtureId + ': expected exactly one observed record, found ' + matches.length); continue; } const record = matches[0]; if (record.disposition !== fixture.disposition) problems.push(fixture.fixtureId + ': release disposition differs from independent expectation'); if (typeof record.candidateId !== 'string' || !record.candidateId.trim() || record.candidateId !== record.reviewedCandidateId) problems.push(fixture.fixtureId + ': final candidate does not match its review'); if (!Array.isArray(record.meanings) || record.meanings.some(meaning => typeof meaning !== 'string')) { problems.push(fixture.fixtureId + ': meanings must be an adjudicated string array'); continue; } const observed = new Set(record.meanings); if (observed.size !== record.meanings.length) problems.push(fixture.fixtureId + ': duplicated meaning identifier'); for (const meaning of fixture.meanings) if (!observed.has(meaning)) problems.push(fixture.fixtureId + ': missing required meaning ' + meaning); for (const meaning of observed) if (!fixture.meanings.includes(meaning)) problems.push(fixture.fixtureId + ': unaccepted additional meaning ' + meaning); } return { pass: problems.length === 0, intended: expectedFixtures.length, observed: records.length, problems }; } export function observerControls() { const mutations = [ ['unsafe outcome', records => { records[0].meanings.push('guaranteed_one_hour_resolution'); }], ['missing qualification', records => { records[0].meanings.pop(); }], ['changed candidate', records => { records[6].candidateId = 'F7-rewritten-candidate-2'; }], ['duplicate attempt', records => { records.push(structuredClone(records[0])); }], ['missing fixture', records => { records.pop(); }], ['implicit acceptance', records => { records[5].disposition = 'supported'; }], ['invented activation outcome', records => { records[3].meanings = ['amendment_rejected']; }], ['unknown fixture', records => { records.push({ fixtureId: 'F99' }); }], ['malformed meanings', records => { records[0].meanings = 'claiming success'; }], ]; return mutations.map(([control, mutate]) => { const records = teachingRecords(); mutate(records); const result = reconcile(records); return { control, detected: !result.pass, problems: result.problems }; }); } if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) { const args = process.argv.slice(2); try { if (args.length !== 1) throw new Error('Usage: node answer-support-drill.mjs --demo | --self-test | observed-records.json'); if (args[0] === '--self-test') { const controls = observerControls(); const baseline = reconcile(teachingRecords()); const pass = baseline.pass && controls.every(control => control.detected); console.log(JSON.stringify({ scope: 'Synthetic observer controls only. Not model accuracy.', pass, baseline, controls }, null, 2)); process.exitCode = pass ? 0 : 1; } else { const records = args[0] === '--demo' ? teachingRecords() : JSON.parse(readFileSync(resolve(args[0]), 'utf8')); const result = reconcile(records); console.log(JSON.stringify({ scope: 'Explicit adjudicated identifiers only. Independently inspect actual output.', ...result }, null, 2)); process.exitCode = result.pass ? 0 : 1; } } catch (error) { console.error(JSON.stringify({ pass: false, error: error.message })); process.exitCode = 1; } }