/** * prompting-model-scope tests — the model-scoped ANNOTATION layer on top of the * subtraction lens's single `compensatory-instruction` detector (BP-SUB-001). * * This module does NOT generate new subtraction candidates. It answers a * narrower question over text that already passed the general detector: does * this block specifically claim a model no longer needs — self-verification, or * delegated-to-a-subagent verification? Precision comes from requiring a * reflexive/delegate TARGET alongside the verify verb, not from narrowing the * verb list — a bare "check"/"verify" also matches EXTERNAL verification * ("check the CI status"), which must stay a true negative here even though it * is (correctly) still a BP-SUB-001 candidate upstream. */ import { describe, it } from 'node:test'; import assert from 'node:assert/strict'; import { isModelContradictedVerification, matchModelScope, normalizeModel, } from '../../scanners/lib/prompting-model-scope.mjs'; describe('isModelContradictedVerification — true positives', () => { const positives = [ 'Always double-check your own work before responding.', 'Re-verify before responding to the user.', 'Verify complex changes with a subagent.', 'Use a subagent to verify the diff before finishing.', 'Dobbeltsjekk ditt eget arbeid før du svarer.', 'Verifiser med en subagent før du er ferdig.', ]; for (const text of positives) { it(`matches: "${text}"`, () => { assert.equal(isModelContradictedVerification(text), true); }); } }); describe('isModelContradictedVerification — true negatives (external verification)', () => { const negatives = [ 'Check the CI status before merging.', 'Verify the deployment succeeded.', 'Sjekk build-status i CI før du merger.', 'Review the pull request for style issues.', 'Confirm the ticket is assigned to you.', 'Read the file before editing it.', ]; for (const text of negatives) { it(`does not match: "${text}"`, () => { assert.equal(isModelContradictedVerification(text), false); }); } }); describe('normalizeModel', () => { it('lowercases and strips non-alphanumerics', () => { for (const s of ['opus-5', 'Opus 5', 'OPUS5', 'opus_5']) { assert.equal(normalizeModel(s), 'opus5'); } }); it('handles null/undefined/empty', () => { assert.equal(normalizeModel(null), ''); assert.equal(normalizeModel(undefined), ''); assert.equal(normalizeModel(''), ''); }); }); describe('matchModelScope', () => { const entries = [ { id: 'BP-PROMPT-001', claim: 'test claim', modelScope: ['opus-5'] }, ]; const positiveText = 'Always double-check your own work.'; it('returns null when targetModel is absent', () => { assert.equal(matchModelScope(positiveText, null, entries), null); assert.equal(matchModelScope(positiveText, undefined, entries), null); assert.equal(matchModelScope(positiveText, '', entries), null); }); it('returns null when the text is not a model-contradicted verification claim', () => { assert.equal(matchModelScope('Check the CI status.', 'opus-5', entries), null); }); it('returns null when no entry matches the requested model', () => { assert.equal(matchModelScope(positiveText, 'sonnet-5', entries), null); }); it('returns null when entries is empty', () => { assert.equal(matchModelScope(positiveText, 'opus-5', []), null); }); it('matches on an exact normalized model name', () => { const m = matchModelScope(positiveText, 'opus-5', entries); assert.ok(m); assert.equal(m.registerId, 'BP-PROMPT-001'); assert.equal(m.claim, 'test claim'); assert.equal(m.requestedModel, 'opus-5'); }); it('matches across normalization variants of the same model name', () => { for (const variant of ['Opus 5', 'OPUS-5', 'opus5']) { const m = matchModelScope(positiveText, variant, entries); assert.ok(m, `expected a match for "${variant}"`); assert.equal(m.registerId, 'BP-PROMPT-001'); } }); it('picks the entry whose modelScope contains the requested model, ignoring others', () => { const multi = [ { id: 'BP-PROMPT-OTHER', claim: 'unrelated', modelScope: ['haiku-5'] }, { id: 'BP-PROMPT-001', claim: 'test claim', modelScope: ['opus-5'] }, ]; const m = matchModelScope(positiveText, 'opus-5', multi); assert.equal(m.registerId, 'BP-PROMPT-001'); }); });