feat: persist execution state and tool results in SQLite

This commit is contained in:
Agent Workbench Dev
2026-10-29 13:11:30 +08:00
parent b047665a33
commit 93f4d90ccb
21 changed files with 1125 additions and 81 deletions
+30
View File
@@ -99,3 +99,33 @@ test('runtime diagnostics and model-response validation use actual records and p
assert.ok(!JSON.stringify(diagnostic).includes('fixture-saved-connection')); assert.ok(!JSON.stringify(diagnostic).includes('fixture-tentative-connection'));
await server.api('/config/models', {}); assert.equal(model.requests[1].headers.authorization, 'Bearer fixture-saved-connection');
});
test('persistent event replay is read-only and keeps run/artifact identity across reconnects', async t => {
const f = fixture(t), server = await launchWorkbench(t, f.data); f.onCleanup(server.close);
const cursor = server.bootstrap.eventCursor;
await server.api('/sessions/' + f.session.id + '/messages', { content: 'Use the controlled offline fixture' });
let waiting;
await until(async () => { waiting = await server.api('/sessions/' + f.session.id); return waiting.status === 'awaiting_approval'; }, 12000);
await server.api('/sessions/' + f.session.id + '/approvals/' + waiting.approvals[0].id, { allow: false });
let ended;
await until(async () => { ended = await server.api('/sessions/' + f.session.id); return ended.status === 'needs_review'; }, 12000);
const history = await server.api('/events/history?after=' + cursor + '&session=' + f.session.id + '&limit=3');
assert.equal(history.events.length, 3); assert.equal(history.hasMore, true);
assert.ok(history.events.every(value => value.taskId === ended.execution.task.id && value.runId === ended.execution.run.id));
const artifact = ended.execution.artifacts.find(value => value.kind === 'tool-result');
const result = await server.api('/artifacts/' + artifact.id + '?session=' + f.session.id);
assert.equal(result.sha256, artifact.sha256); assert.ok(result.content);
const other = await server.api('/sessions', { projectId: f.project.id });
await assert.rejects(server.api('/artifacts/' + artifact.id + '?session=' + other.id), { status: 404 });
const stop = new AbortController();
const stream = await fetch(server.url + '/api/events?token=' + encodeURIComponent(server.bootstrap.token) + '&after=' + cursor,
{ headers: { 'Last-Event-ID': String(history.nextCursor) }, signal: stop.signal });
const reader = stream.body.getReader(); const bytes = await reader.read(); const text = Buffer.from(bytes.value).toString('utf8');
stop.abort(); await reader.cancel().catch(() => {});
assert.match(text, /session_changed/); assert.match(text, /id: \d+/);
const replayedIds = [...text.matchAll(/^id: (\d+)$/gm)].map(match => Number(match[1]));
assert.ok(replayedIds.every(value => value > history.nextCursor));
const after = await server.api('/sessions/' + f.session.id);
assert.equal(after.runId, ended.runId); assert.equal(after.approvals.length, ended.approvals.length);
assert.deepEqual(after.changes, ended.changes); assert.equal(after.execution.run.toolCalls, ended.execution.run.toolCalls);
});