feat: package continuity plugin MVP docs and receipt store

This commit is contained in:
Eve
2026-04-24 17:32:47 +08:00
parent acf83824b7
commit b9ccc3d096
6 changed files with 580 additions and 43 deletions

View File

@@ -0,0 +1,38 @@
import assert from 'node:assert/strict';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { buildReceiptFilename, slugifyReceiptSegment, writeReceipt } from '../src/continuity/receipt-store.mjs';
function test(name, fn) {
Promise.resolve()
.then(fn)
.then(() => console.log(`ok - ${name}`))
.catch((error) => {
console.error(`not ok - ${name}`);
throw error;
});
}
assert.equal(slugifyReceiptSegment(' Plan ID / 01 '), 'plan-id-01');
const built = buildReceiptFilename({ planId: 'Plan ID', dispatchRunId: 'Run 01' });
assert.equal(built.filename, 'receipt-plan-id-run-01.json');
test('writes receipt using canonical filename', async () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'continuity-receipt-store-'));
const receipt = {
planId: 'Plan ID',
currentTask: 'task-7',
nextDerivedAction: { type: 'message_subagent' },
dispatchedAt: '2026-04-24T09:00:00.000Z',
dispatchRunId: 'Run 01',
childSessionKey: 'child-1',
replyClosureState: 'completed',
};
const receiptPath = await writeReceipt({ receiptDir: dir, receipt });
assert.match(receiptPath, /receipt-plan-id-run-01\.json$/);
assert.equal(fs.existsSync(receiptPath), true);
});
console.log('continuity.receipt-store.test.mjs PASS');

View File

@@ -0,0 +1,44 @@
import assert from 'node:assert/strict';
import { isValidReceipt, validateReceipt } from '../src/continuity/receipt-validator.mjs';
function test(name, fn) {
try {
fn();
console.log(`ok - ${name}`);
} catch (error) {
console.error(`not ok - ${name}`);
throw error;
}
}
test('accepts full receipt contract', () => {
const receipt = {
planId: 'plan-1',
currentTask: 'task-7',
nextDerivedAction: { type: 'message_subagent' },
dispatchedAt: '2026-04-24T09:00:00.000Z',
dispatchRunId: 'run-1',
childSessionKey: 'child-1',
replyClosureState: 'completed',
};
const result = validateReceipt(receipt);
assert.equal(result.ok, true);
assert.equal(isValidReceipt(receipt), true);
});
test('rejects non-object receipt', () => {
const result = validateReceipt(null);
assert.equal(result.ok, false);
assert.match(result.errors.join('\n'), /expected object/);
});
test('rejects missing required fields', () => {
const result = validateReceipt({ planId: 'plan-1' });
assert.equal(result.ok, false);
assert.match(result.errors.join('\n'), /currentTask/);
assert.match(result.errors.join('\n'), /nextDerivedAction/);
assert.match(result.errors.join('\n'), /replyClosureState/);
});
console.log('continuity.receipt-validator.test.mjs PASS');