import assert from 'node:assert/strict' import test from 'node:test' import { canonical, goalDigest, stageDigest } from '../src/digest.js' test('canonical 与键顺序无关', () => { assert.equal(canonical({ b: 1, a: 2 }), canonical({ a: 2, b: 1 })) assert.equal(canonical({ a: [1, { d: 4, c: 3 }] }), '{"a":[1,{"c":3,"d":4}]}') }) const goal = () => ({ id: 'goal-1', objective: 'o', acceptance: 'a', constraints: ['c'], stages: [ { id: 's1', title: '一', acceptance: 'x', status: 'active', tasks: [{ id: 't1', botId: 'b', task: 'do', status: 'pending', note: '' }], }, ], }) test('stageDigest 随任务状态/备注变化', () => { const a = goal() const first = stageDigest(a, 1) a.stages[0].tasks[0].status = 'done' const second = stageDigest(a, 1) assert.notEqual(first, second) a.stages[0].tasks[0].task = 'do more' assert.notEqual(second, stageDigest(a, 1)) }) test('stageDigest 对不存在的阶段返回 undefined', () => { assert.equal(stageDigest(goal(), 2), undefined) }) test('goalDigest 含整体目标与阶段状态', () => { const a = goal() const first = goalDigest(a) a.stages[0].status = 'passed' assert.notEqual(first, goalDigest(a)) a.acceptance = 'a2' assert.notEqual(first, goalDigest(a)) })