397777089e
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
29 lines
1.1 KiB
JavaScript
29 lines
1.1 KiB
JavaScript
import { describe, it, expect } from 'vitest';
|
|
import { retrofillLine } from './observer-retrofill-chain-ref.mjs';
|
|
import { loadChainMap } from './observer-chain-detector.mjs';
|
|
|
|
const map = loadChainMap();
|
|
|
|
describe('retrofillLine', () => {
|
|
it('adds chain_ref to a v2 episode with a known node', () => {
|
|
const ep = { schema_version: 2, primary_rationale: { node_chosen: 'billing-audit' } };
|
|
const out = retrofillLine(ep, map);
|
|
expect(out.primary_rationale.chain_ref).toEqual(['L13']);
|
|
});
|
|
|
|
it('sets chain_ref null for a direct v2 episode', () => {
|
|
const ep = { schema_version: 2, primary_rationale: { node_chosen: 'direct' } };
|
|
expect(retrofillLine(ep, map).primary_rationale.chain_ref).toBeNull();
|
|
});
|
|
|
|
it('is idempotent — does not overwrite existing chain_ref', () => {
|
|
const ep = { schema_version: 2, primary_rationale: { node_chosen: 'direct', chain_ref: ['L1'] } };
|
|
expect(retrofillLine(ep, map).primary_rationale.chain_ref).toEqual(['L1']);
|
|
});
|
|
|
|
it('skips v1 episodes (no schema_version 2)', () => {
|
|
const ep = { foo: 'bar' };
|
|
expect(retrofillLine(ep, map)).toEqual({ foo: 'bar' });
|
|
});
|
|
});
|