diff --git a/plugins/ai-psychosis/tests/privacy.test.mjs b/plugins/ai-psychosis/tests/privacy.test.mjs index d7a6340..240dae5 100644 --- a/plugins/ai-psychosis/tests/privacy.test.mjs +++ b/plugins/ai-psychosis/tests/privacy.test.mjs @@ -41,4 +41,26 @@ describe('privacy', () => { const allContent = readAllFiles(dir); assert.ok(!allContent.includes(canary), `Canary "${canary}" found in data files — privacy violation`); }); + + it('never leaks matched-pattern phrases through full lifecycle', () => { + dir = setupTestDir(); + const matchedPhrase = 'are you sure'; + const canary = 'CANARY_PRIVACY_xyz123'; + const prompt = `${matchedPhrase}? ${canary}`; + + runHook('session-start.mjs', { session_id: 'priv2', cwd: '/tmp' }, dir); + runHook('prompt-analyzer.mjs', { session_id: 'priv2', prompt }, dir); + runHook('tool-tracker.mjs', { session_id: 'priv2', tool_name: 'Edit' }, dir); + runHook('session-end.mjs', { session_id: 'priv2', cwd: '/tmp' }, dir); + + const allContent = readAllFiles(dir); + assert.ok( + !allContent.includes(canary), + `Canary "${canary}" leaked — pattern-match did not protect prompt text` + ); + assert.ok( + !allContent.toLowerCase().includes(matchedPhrase), + `Matched phrase "${matchedPhrase}" leaked — pattern name or trigger phrase written to disk` + ); + }); });