Files
brain/tools/post-seal.test.mjs
T

54 lines
2.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, it, expect } from 'vitest';
import { postSealPlan } from './post-seal.mjs';
import { buildJudgeGo } from './judge-go-store.mjs';
const key = 'k-123';
const planEvent = { tool_input: { file_path: 'docs/superpowers/plans/x.md', content: '```steps-json\n[{"op":"Edit","object":"tools/x.mjs","ref":"r"}]\n```' } };
describe('postSealPlan — печать плана в Post по свежему вердикту + GO судьи', () => {
it('валидный GO для этого плана → делегирует sealOnWiredGo, печать встаёт', () => {
let sealedArgs = null;
const r = postSealPlan({
event: planEvent, mentorVerdict: { plan_hash: 'PH' }, planHash: 'PH', sessionId: 's', runtimeDir: '/rt', key,
deps: {
loadJudgeGo: () => buildJudgeGo({ planHash: 'PH', judgedHash: 'JH', judgeMode: 'live-block', key }),
sealOnWiredGo: (args) => { sealedArgs = args; return { sealed: true, kind: 'plan' }; },
},
});
expect(r.sealed).toBe(true);
expect(sealedArgs.verdict).toEqual({ wired: true, decision: 'GO', judged_hash: 'JH' });
expect(sealedArgs.judgeMode).toBe('live-block');
});
it('нет GO судьи (null) → sealed:false с причиной', () => {
const r = postSealPlan({
event: planEvent, mentorVerdict: {}, planHash: 'PH', sessionId: 's', runtimeDir: '/rt', key,
deps: { loadJudgeGo: () => null, sealOnWiredGo: () => ({ sealed: true }) },
});
expect(r.sealed).toBe(false);
expect(r.reason).toMatch(/GO судьи/);
});
it('GO судьи для ДРУГОГО плана (stale) → sealed:false (не пломбируем чужое)', () => {
let called = false;
const r = postSealPlan({
event: planEvent, mentorVerdict: {}, planHash: 'PH', sessionId: 's', runtimeDir: '/rt', key,
deps: {
loadJudgeGo: () => buildJudgeGo({ planHash: 'OTHER', judgedHash: 'JH', key }),
sealOnWiredGo: () => { called = true; return { sealed: true }; },
},
});
expect(r.sealed).toBe(false);
expect(called).toBe(false);
});
it('подделанный GO (битая подпись) → sealed:false', () => {
const good = buildJudgeGo({ planHash: 'PH', judgedHash: 'JH', key });
const r = postSealPlan({
event: planEvent, mentorVerdict: {}, planHash: 'PH', sessionId: 's', runtimeDir: '/rt', key,
deps: { loadJudgeGo: () => ({ ...good, judged_hash: 'FAKE' }), sealOnWiredGo: () => ({ sealed: true }) },
});
expect(r.sealed).toBe(false);
});
});