Files
brain/tools/judge-escalation.test.mjs
T

35 lines
1.8 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 { mkdtempSync, rmSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { bumpJudgeNoGo } from './enforce-judge-gate.mjs';
describe('M7 эскалация судьи: счётчик подряд идущих NO-GO (round-control C-12)', () => {
it('blocked подряд → счёт растёт; allow → сброс в 0', () => {
const dir = mkdtempSync(join(tmpdir(), 'judge-nogo-'));
try {
expect(bumpJudgeNoGo({ sessionId: 's1', blocked: true, dir })).toBe(1);
expect(bumpJudgeNoGo({ sessionId: 's1', blocked: true, dir })).toBe(2);
expect(bumpJudgeNoGo({ sessionId: 's1', blocked: true, dir })).toBe(3); // ← порог эскалации
expect(bumpJudgeNoGo({ sessionId: 's1', blocked: false, dir })).toBe(0); // allow → сброс
expect(bumpJudgeNoGo({ sessionId: 's1', blocked: true, dir })).toBe(1); // снова с 1
} finally { rmSync(dir, { recursive: true, force: true }); }
});
it('разные сессии — независимые счётчики', () => {
const dir = mkdtempSync(join(tmpdir(), 'judge-nogo-'));
try {
expect(bumpJudgeNoGo({ sessionId: 'a', blocked: true, dir })).toBe(1);
expect(bumpJudgeNoGo({ sessionId: 'b', blocked: true, dir })).toBe(1);
expect(bumpJudgeNoGo({ sessionId: 'a', blocked: true, dir })).toBe(2);
} finally { rmSync(dir, { recursive: true, force: true }); }
});
it('битый/опасный sessionId не ломает (санитизация пути) и стартует с 1', () => {
const dir = mkdtempSync(join(tmpdir(), 'judge-nogo-'));
try {
expect(bumpJudgeNoGo({ sessionId: '../../evil', blocked: true, dir })).toBe(1);
} finally { rmSync(dir, { recursive: true, force: true }); }
});
});