feat: export continuity plugin MVP packaging
This commit is contained in:
1
plugins/continuity/test/.gitkeep
Normal file
1
plugins/continuity/test/.gitkeep
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
133
plugins/continuity/test/continuity.config.test.mjs
Normal file
133
plugins/continuity/test/continuity.config.test.mjs
Normal file
@@ -0,0 +1,133 @@
|
||||
import assert from 'node:assert/strict';
|
||||
|
||||
import defaultConfig from '../src/config/defaults.mjs';
|
||||
import {
|
||||
normalizeContinuityConfig,
|
||||
validateContinuityConfig,
|
||||
} from '../src/config/schema.mjs';
|
||||
|
||||
function test(name, fn) {
|
||||
try {
|
||||
fn();
|
||||
console.log(`ok - ${name}`);
|
||||
} catch (error) {
|
||||
console.error(`not ok - ${name}`);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
test('accepts default config', () => {
|
||||
const result = validateContinuityConfig(defaultConfig);
|
||||
assert.equal(result.ok, true);
|
||||
assert.deepEqual(result.errors, []);
|
||||
assert.deepEqual(result.normalizedConfig, defaultConfig);
|
||||
});
|
||||
|
||||
test('accepts custom receipt directory', () => {
|
||||
const result = validateContinuityConfig({
|
||||
receiptDir: 'tmp/continuity-receipts',
|
||||
});
|
||||
|
||||
assert.equal(result.ok, true);
|
||||
assert.equal(result.normalizedConfig.receiptDir, 'tmp/continuity-receipts');
|
||||
assert.deepEqual(result.errors, []);
|
||||
});
|
||||
|
||||
test('accepts custom legal terminal states list', () => {
|
||||
const result = validateContinuityConfig({
|
||||
legalTerminalStates: ['waiting_user', 'blocked', 'done_elsewhere'],
|
||||
});
|
||||
|
||||
assert.equal(result.ok, true);
|
||||
assert.deepEqual(result.normalizedConfig.legalTerminalStates, ['waiting_user', 'blocked', 'done_elsewhere']);
|
||||
});
|
||||
|
||||
test('normalizes missing fields from defaults', () => {
|
||||
const normalized = normalizeContinuityConfig({
|
||||
debug: true,
|
||||
});
|
||||
|
||||
assert.equal(normalized.debug, true);
|
||||
assert.equal(normalized.enabled, defaultConfig.enabled);
|
||||
assert.equal(normalized.receiptDir, defaultConfig.receiptDir);
|
||||
assert.deepEqual(normalized.legalTerminalStates, defaultConfig.legalTerminalStates);
|
||||
assert.notEqual(normalized.legalTerminalStates, defaultConfig.legalTerminalStates);
|
||||
});
|
||||
|
||||
test('rejects non-array legalTerminalStates', () => {
|
||||
const result = validateContinuityConfig({
|
||||
legalTerminalStates: 'waiting_user',
|
||||
});
|
||||
|
||||
assert.equal(result.ok, false);
|
||||
assert.match(result.errors.join('\n'), /legalTerminalStates/);
|
||||
assert.match(result.errors.join('\n'), /array/i);
|
||||
});
|
||||
|
||||
test('rejects invalid legalTerminalStates entry types', () => {
|
||||
const result = validateContinuityConfig({
|
||||
legalTerminalStates: ['waiting_user', 123],
|
||||
});
|
||||
|
||||
assert.equal(result.ok, false);
|
||||
assert.match(result.errors.join('\n'), /legalTerminalStates\[1\]/);
|
||||
assert.match(result.errors.join('\n'), /string/i);
|
||||
});
|
||||
|
||||
test('rejects empty receiptDir', () => {
|
||||
const result = validateContinuityConfig({
|
||||
receiptDir: ' ',
|
||||
});
|
||||
|
||||
assert.equal(result.ok, false);
|
||||
assert.match(result.errors.join('\n'), /receiptDir/);
|
||||
});
|
||||
|
||||
test('rejects malformed adapter.forceRecall shape', () => {
|
||||
const result = validateContinuityConfig({
|
||||
adapter: {
|
||||
forceRecall: false,
|
||||
},
|
||||
});
|
||||
|
||||
assert.equal(result.ok, false);
|
||||
assert.match(result.errors.join('\n'), /adapter\.forceRecall/);
|
||||
});
|
||||
|
||||
test('rejects malformed adapter.forceRecall.enabled type', () => {
|
||||
const result = validateContinuityConfig({
|
||||
adapter: {
|
||||
forceRecall: {
|
||||
enabled: 'yes',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
assert.equal(result.ok, false);
|
||||
assert.match(result.errors.join('\n'), /adapter\.forceRecall\.enabled/);
|
||||
});
|
||||
|
||||
test('rejects malformed adapter.forceRecall.injectBlockLabel type', () => {
|
||||
const result = validateContinuityConfig({
|
||||
adapter: {
|
||||
forceRecall: {
|
||||
injectBlockLabel: 42,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
assert.equal(result.ok, false);
|
||||
assert.match(result.errors.join('\n'), /injectBlockLabel/);
|
||||
});
|
||||
|
||||
test('rejects unknown top-level key', () => {
|
||||
const result = validateContinuityConfig({
|
||||
unexpected: true,
|
||||
});
|
||||
|
||||
assert.equal(result.ok, false);
|
||||
assert.match(result.errors.join('\n'), /unknown/i);
|
||||
assert.match(result.errors.join('\n'), /unexpected/);
|
||||
});
|
||||
|
||||
console.log('continuity.config.test.mjs PASS');
|
||||
97
plugins/continuity/test/continuity.evaluator.test.mjs
Normal file
97
plugins/continuity/test/continuity.evaluator.test.mjs
Normal file
@@ -0,0 +1,97 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import {
|
||||
buildContinuityGateBlock,
|
||||
evaluateContinuity,
|
||||
hasValidDispatchReceipt,
|
||||
receiptMatchesPayload,
|
||||
} from '../src/continuity/evaluator.mjs';
|
||||
|
||||
function test(name, fn) {
|
||||
try {
|
||||
fn();
|
||||
console.log(`ok - ${name}`);
|
||||
} catch (error) {
|
||||
console.error(`not ok - ${name}`);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
const validReceipt = {
|
||||
planId: 'plan-1',
|
||||
currentTask: 'task-7',
|
||||
nextDerivedAction: { type: 'message_subagent', task: 'continue' },
|
||||
dispatchedAt: '2026-04-24T09:00:00.000Z',
|
||||
};
|
||||
|
||||
test('recognizes minimum valid dispatch receipt', () => {
|
||||
assert.equal(hasValidDispatchReceipt(validReceipt), true);
|
||||
});
|
||||
|
||||
test('matches payload against valid receipt', () => {
|
||||
const payload = {
|
||||
planId: 'plan-1',
|
||||
currentTask: 'task-7',
|
||||
nextDerivedAction: { type: 'message_subagent', task: 'continue' },
|
||||
};
|
||||
|
||||
assert.equal(receiptMatchesPayload(payload, validReceipt), true);
|
||||
});
|
||||
|
||||
test('fails when completion has next action and no receipt', () => {
|
||||
const result = evaluateContinuity({
|
||||
planId: 'plan-1',
|
||||
currentTask: 'task-7',
|
||||
taskState: 'complete',
|
||||
nextDerivedAction: { type: 'message_subagent' },
|
||||
replyClosureState: 'completed',
|
||||
dispatchReceipt: null,
|
||||
});
|
||||
|
||||
assert.equal(result.ok, false);
|
||||
assert.equal(result.reason, 'missing_dispatch_receipt');
|
||||
});
|
||||
|
||||
test('fails auto-next boundary without dispatch', () => {
|
||||
const result = evaluateContinuity({
|
||||
planId: 'plan-1',
|
||||
currentTask: 'task-8',
|
||||
taskState: 'complete',
|
||||
nextTaskKnown: true,
|
||||
sameApprovedPlan: true,
|
||||
taskBoundaryStop: true,
|
||||
nextTaskId: 'task-9',
|
||||
nextDerivedAction: { type: 'message_subagent', task: 'continue' },
|
||||
replyClosureState: 'completed',
|
||||
dispatchReceipt: null,
|
||||
});
|
||||
|
||||
assert.equal(result.ok, false);
|
||||
assert.equal(result.reason, 'missing_auto_next_dispatch');
|
||||
});
|
||||
|
||||
test('passes allowed terminal state', () => {
|
||||
const result = evaluateContinuity({
|
||||
planId: 'plan-1',
|
||||
currentTask: 'task-7',
|
||||
taskState: 'complete',
|
||||
nextDerivedAction: { type: 'message_subagent' },
|
||||
replyClosureState: 'waiting_user',
|
||||
dispatchReceipt: null,
|
||||
});
|
||||
|
||||
assert.equal(result.ok, true);
|
||||
});
|
||||
|
||||
test('renders hard-gate block', () => {
|
||||
const text = buildContinuityGateBlock({
|
||||
ok: false,
|
||||
status: 'continuity_failure',
|
||||
verdict: 'continuity_failure',
|
||||
reason: 'missing_dispatch_receipt',
|
||||
});
|
||||
|
||||
assert.match(text, /APPROVED_PLAN_CONTINUITY_GATE/);
|
||||
assert.match(text, /HARD_GATE/);
|
||||
});
|
||||
|
||||
console.log('continuity.evaluator.test.mjs PASS');
|
||||
63
plugins/continuity/test/continuity.plugin.test.mjs
Normal file
63
plugins/continuity/test/continuity.plugin.test.mjs
Normal file
@@ -0,0 +1,63 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import plugin, {
|
||||
createForceRecallContinuityAdapter,
|
||||
defaultConfig,
|
||||
evaluateContinuity,
|
||||
} from '../src/index.mjs';
|
||||
|
||||
function test(name, fn) {
|
||||
try {
|
||||
fn();
|
||||
console.log(`ok - ${name}`);
|
||||
} catch (error) {
|
||||
console.error(`not ok - ${name}`);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
test('index exports plugin surface', () => {
|
||||
assert.equal(plugin.name, '@openclaw/plugin-continuity');
|
||||
assert.equal(typeof evaluateContinuity, 'function');
|
||||
assert.equal(defaultConfig.adapter.forceRecall.enabled, true);
|
||||
});
|
||||
|
||||
test('adapter preserves current hook parity for plain wrapper next-action mapping', () => {
|
||||
const adapter = createForceRecallContinuityAdapter(defaultConfig);
|
||||
const out = adapter.evaluate({
|
||||
wrapperResult: {
|
||||
classification: 'long_task',
|
||||
planId: 'plan-1',
|
||||
currentTask: 'task-7',
|
||||
taskState: 'complete',
|
||||
nextDerivedAction: { type: 'message_subagent', task: 'continue' },
|
||||
replyClosureState: 'completed',
|
||||
dispatchReceipt: null,
|
||||
},
|
||||
});
|
||||
|
||||
assert.equal(out.result.ok, true);
|
||||
assert.match(out.block, /status=pass/);
|
||||
});
|
||||
|
||||
test('adapter fails when planner-derived auto-next boundary exists without dispatch receipt', () => {
|
||||
const adapter = createForceRecallContinuityAdapter(defaultConfig);
|
||||
const out = adapter.evaluate({
|
||||
wrapperResult: {
|
||||
classification: 'long_task',
|
||||
planId: 'plan-2',
|
||||
currentTask: 'task-8',
|
||||
replyClosureState: 'completed',
|
||||
dispatchReceipt: null,
|
||||
},
|
||||
autoChainPlanResult: {
|
||||
derivedAction: 'continue_task_9',
|
||||
dispatchMode: 'message_subagent',
|
||||
},
|
||||
});
|
||||
|
||||
assert.equal(out.result.ok, false);
|
||||
assert.equal(out.result.reason, 'missing_auto_next_dispatch');
|
||||
assert.match(out.block, /continuity_failure/);
|
||||
});
|
||||
|
||||
console.log('continuity.plugin.test.mjs PASS');
|
||||
38
plugins/continuity/test/continuity.receipt-store.test.mjs
Normal file
38
plugins/continuity/test/continuity.receipt-store.test.mjs
Normal 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');
|
||||
@@ -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');
|
||||
28
plugins/continuity/test/continuity.smoke.test.mjs
Normal file
28
plugins/continuity/test/continuity.smoke.test.mjs
Normal file
@@ -0,0 +1,28 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import plugin, {
|
||||
runForceRecallContinuityAdapter,
|
||||
validateContinuityConfig,
|
||||
} from '../src/index.mjs';
|
||||
|
||||
const configResult = validateContinuityConfig(plugin.defaultConfig);
|
||||
assert.equal(configResult.ok, true);
|
||||
|
||||
const smoke = runForceRecallContinuityAdapter({
|
||||
config: plugin.defaultConfig,
|
||||
wrapperResult: {
|
||||
classification: 'long_task',
|
||||
planId: 'plan-smoke',
|
||||
currentTask: 'task-8',
|
||||
replyClosureState: 'completed',
|
||||
dispatchReceipt: null,
|
||||
},
|
||||
autoChainPlanResult: {
|
||||
derivedAction: 'continue_task_9',
|
||||
dispatchMode: 'message_subagent',
|
||||
},
|
||||
});
|
||||
|
||||
assert.equal(smoke.result.ok, false);
|
||||
assert.equal(smoke.result.reason, 'missing_auto_next_dispatch');
|
||||
assert.match(smoke.block, /APPROVED_PLAN_CONTINUITY_GATE/);
|
||||
console.log('continuity.smoke.test.mjs PASS');
|
||||
Reference in New Issue
Block a user