397777089e
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
25 lines
1.2 KiB
JavaScript
25 lines
1.2 KiB
JavaScript
import { describe, it, expect } from 'vitest';
|
|
import { snapshotNeeded, resolveGitState } from './snapshot-decide.mjs';
|
|
describe('snapshot-decide snapshotNeeded', () => {
|
|
it('Bash floor (reset --hard) → нужен', () => {
|
|
expect(snapshotNeeded('Bash', { command: 'git reset --hard' })).toBe(true);
|
|
});
|
|
it('обычный Bash → не нужен', () => {
|
|
expect(snapshotNeeded('Bash', { command: 'git status' })).toBe(false);
|
|
});
|
|
it('Write → не нужен', () => {
|
|
expect(snapshotNeeded('Write', { file_path: '/a/b' })).toBe(false);
|
|
});
|
|
});
|
|
describe('snapshot-decide resolveGitState (чистое-дерево vs ошибка)', () => {
|
|
it('stash create дал sha → ref=sha, ok', () => {
|
|
expect(resolveGitState({ stashOut: 'abc123\n', headOut: 'head1\n', error: false })).toEqual({ ok: true, ref: 'abc123' });
|
|
});
|
|
it('чистое дерево (stash пуст) → ref=HEAD, ok (успех, не ошибка)', () => {
|
|
expect(resolveGitState({ stashOut: ' \n', headOut: 'head1\n', error: false })).toEqual({ ok: true, ref: 'head1' });
|
|
});
|
|
it('ошибка git → ok:false (fail-close)', () => {
|
|
expect(resolveGitState({ stashOut: '', headOut: '', error: true })).toEqual({ ok: false, ref: null });
|
|
});
|
|
});
|