Files
brain/tools/round-memory-store.test.mjs
T
2026-06-16 15:31:31 +03:00

59 lines
2.4 KiB
JavaScript

import { describe, it, expect } from 'vitest';
import { mkdtempSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import {
recordVersion, getVersions, diffVersions,
recordObjection, getObjections,
recordArg, getArgs, clearRoundMemory,
} from './round-memory-store.mjs';
const dir = () => mkdtempSync(join(tmpdir(), 'rmem-'));
describe('round-memory-store', () => {
it('версии: record → get round-trip', () => {
const d = dir();
recordVersion('t1', 'spec', 'v1', d);
recordVersion('t1', 'spec', 'v2', d);
expect(getVersions('t1', 'spec', d)).toEqual(['v1', 'v2']);
});
it('diffVersions двух последних', () => {
const d = dir();
recordVersion('t1', 'plan', 'a\nb', d);
recordVersion('t1', 'plan', 'a\nb\nc', d);
expect(diffVersions('t1', 'plan', d)).toContain('+ c');
});
it('замечания по стороне дословно', () => {
const d = dir();
recordObjection('t1', 'spec', 'mentor', 'правь X', d);
recordObjection('t1', 'spec', 'judge', 'правь Y', d);
expect(getObjections('t1', 'spec', 'mentor', d)).toEqual(['правь X']);
expect(getObjections('t1', 'spec', 'judge', d)).toEqual(['правь Y']);
});
it('доводы по дорожке (M/J)', () => {
const d = dir();
recordArg('t1', 'spec', 'M', 'довод наставнику', d);
recordArg('t1', 'spec', 'J', 'довод судье', d);
expect(getArgs('t1', 'spec', 'M', d)).toEqual(['довод наставнику']);
expect(getArgs('t1', 'spec', 'J', d)).toEqual(['довод судье']);
});
it('изоляция по (taskId, stage)', () => {
const d = dir();
recordVersion('t1', 'spec', 'x', d);
expect(getVersions('t1', 'plan', d)).toEqual([]);
expect(getVersions('t2', 'spec', d)).toEqual([]);
});
it('clearRoundMemory стирает задачу', () => {
const d = dir();
recordVersion('t1', 'spec', 'x', d);
recordObjection('t1', 'spec', 'mentor', 'z', d);
clearRoundMemory('t1', d);
expect(getVersions('t1', 'spec', d)).toEqual([]);
expect(getObjections('t1', 'spec', 'mentor', d)).toEqual([]);
});
it('fail-quiet: битый baseDir не кидает', () => {
expect(() => getVersions('t1', 'spec', '\0bad')).not.toThrow();
expect(getVersions('t1', 'spec', '\0bad')).toEqual([]);
});
});