import { describe, it, expect } from 'vitest'; import { buildMentorGo, persistMentorGo, loadMentorGo, clearMentorGo } from './mentor-go-store.mjs'; function memFs() { const s = new Map(); return { s, writeFileSync: (p, d) => s.set(String(p), d), renameSync: (a, b) => { s.set(String(b), s.get(String(a))); s.delete(String(a)); }, readFileSync: (p) => { if (!s.has(String(p))) { const e = new Error('no'); e.code = 'ENOENT'; throw e; } return s.get(String(p)); }, unlinkSync: (p) => { if (!s.has(String(p))) { const e = new Error('no'); e.code = 'ENOENT'; throw e; } s.delete(String(p)); }, }; } const KEY = 'mgk'; const DIR = '/rt'; const SESS = 's1'; describe('clearMentorGo — реальный NO-GO стирает прежнее «да» наставника (стейл-fix)', () => { it('после persist + clear загрузка возвращает null', () => { const fs = memFs(); persistMentorGo({ record: buildMentorGo({ planHash: 'H', key: KEY }), sessionId: SESS, runtimeDir: DIR, fsImpl: fs }); expect(loadMentorGo({ sessionId: SESS, runtimeDir: DIR, fsImpl: fs })).not.toBe(null); clearMentorGo({ sessionId: SESS, runtimeDir: DIR, fsImpl: fs }); expect(loadMentorGo({ sessionId: SESS, runtimeDir: DIR, fsImpl: fs })).toBe(null); }); it('clear на отсутствующем файле не бросает (no-op)', () => { const fs = memFs(); expect(() => clearMentorGo({ sessionId: SESS, runtimeDir: DIR, fsImpl: fs })).not.toThrow(); }); });