diff --git a/plugins/ai-psychosis/tests/prompt-analyzer.test.mjs b/plugins/ai-psychosis/tests/prompt-analyzer.test.mjs index ef79caa..0122f35 100644 --- a/plugins/ai-psychosis/tests/prompt-analyzer.test.mjs +++ b/plugins/ai-psychosis/tests/prompt-analyzer.test.mjs @@ -428,3 +428,60 @@ describe('pushback integration (state accumulation + same-invocation valence)', assert.equal(s.domain_context, null); }); }); + +// --- Pushback count contract (v1.1.0 deferred-alert state) --- +// +// Locks the v1.1.0 contract: pushback is COUNTED but NEVER alerted. +// lib.mjs:131 confirms "tier-reduction logic is v1.2 scope". This test +// is the regression baseline that Step 12 will rewrite when the alert is +// added with domain-aware re-contextualization. If this contract changes +// without Step 12 being in flight, something has silently enabled +// pushback alerting. + +function runPromptCapture(prompt, stateOverrides = {}) { + dir = setupTestDir(); + createStateFile(dir, 'p1', { ...freshState(), ...stateOverrides }); + const out = runHook('prompt-analyzer.mjs', { session_id: 'p1', prompt }, dir); + const state = readState(dir, 'p1'); + return { state, out }; +} + +describe('pushback count contract (v1.1.0 deferred-alert state)', () => { + it('accumulates pushback_count to 5 over 5 sequential pushback prompts', () => { + dir = setupTestDir(); + createStateFile(dir, 'p1', { ...freshState(), domain_context: 'relationship' }); + const prompts = [ + 'are you sure?', + "I'm not convinced", + "that doesn't seem right", + "actually, I think you're wrong", + "are you absolutely sure?", + ]; + let lastOut; + for (const p of prompts) { + lastOut = runHook('prompt-analyzer.mjs', { session_id: 'p1', prompt: p }, dir); + } + const s = readState(dir, 'p1'); + assert.equal(s.pushback_count, 5, 'pushback_count should accumulate across calls'); + // Final hook call output: continue: true, no hookSpecificOutput. + assert.equal(lastOut.continue, true); + assert.equal(lastOut.hookSpecificOutput, undefined, + 'v1.1.0 must not emit pushback alert via hookSpecificOutput'); + }); + + it('does not emit pushback alert in relationship domain even at high count', () => { + const { state, out } = runPromptCapture('are you absolutely sure?', { + domain_context: 'relationship', + pushback_count: 4, // already 4, this prompt makes 5 + }); + assert.equal(state.pushback_count, 5); + assert.equal(out.hookSpecificOutput, undefined, + 'v1.1.0 contract: count but never alert'); + }); + + it('does not emit pushback alert when domain_context is null', () => { + const { state, out } = runPromptCapture("I'm not convinced", { pushback_count: 1 }); + assert.equal(state.pushback_count, 2); + assert.equal(out.hookSpecificOutput, undefined); + }); +});