feat: persist execution state and tool results in SQLite
This commit is contained in:
@@ -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);
|
||||
});
|
||||
|
||||
@@ -174,6 +174,7 @@ test('old session data receives a truthful historical connection diagnosis witho
|
||||
const f = fixture(t);
|
||||
f.store.message(f.session, 'system', 'fetch failed'); f.store.event(f.session, { kind: 'error', phase: 'failed', output: 'fetch failed' });
|
||||
const originalMessages = structuredClone(f.session.messages), reloaded = new Store(f.data);
|
||||
f.onCleanup(() => reloaded.close());
|
||||
const session = reloaded.session(f.session.id), visible = reloaded.publicSession(session);
|
||||
assert.equal(visible.lastFailure.source, 'model_connection'); assert.equal(visible.lastFailure.historical, true);
|
||||
assert.deepEqual(session.messages, originalMessages); assert.equal(Object.hasOwn(visible, 'providerMessages'), false);
|
||||
|
||||
@@ -0,0 +1,180 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { spawn } from 'node:child_process';
|
||||
import { Store, repairToolPairs } from '../src/server/store.mjs';
|
||||
import { StateDatabase } from '../src/core/storage/state-database.mjs';
|
||||
import { Runtime } from '../src/server/runtime.mjs';
|
||||
import { Provider } from '../src/server/provider.mjs';
|
||||
import { fixture, workspace, call, until, assertToolPairs } from './helpers.mjs';
|
||||
|
||||
function legacyCase(f, name) {
|
||||
f.store.message(f.session, 'user', 'Original fixture requirement');
|
||||
fs.writeFileSync(path.join(f.projectRoot, 'worker-effect.mjs'), "import fs from 'node:fs'; const file='executions.txt'; const count=fs.existsSync(file)?Number(fs.readFileSync(file,'utf8')):0; fs.writeFileSync(file,String(count+1)); console.log('fixture-result');\n");
|
||||
const directory = path.join(f.root, name); f.store.exportLegacyData(directory);
|
||||
return directory;
|
||||
}
|
||||
async function crash(t, directory, phase) {
|
||||
const env = { ...process.env }; delete env.AGENT_WORKBENCH_API_KEY;
|
||||
const child = spawn(process.execPath, [path.join(workspace, 'tests/fixtures/core-crash-worker.mjs'), directory, phase], { env, windowsHide: true, stdio: ['ignore', 'pipe', 'pipe'] });
|
||||
let output = ''; child.stdout.on('data', bytes => output += bytes.toString('utf8')); child.stderr.on('data', bytes => output += bytes.toString('utf8'));
|
||||
t.after(() => { if (child.exitCode === null && child.signalCode === null) child.kill(); });
|
||||
await until(() => child.exitCode !== null || child.signalCode !== null, 15000);
|
||||
assert.equal(child.exitCode, 66, output);
|
||||
}
|
||||
function reopen(f, directory) { const store = new Store(directory); f.onCleanup(() => store.close()); return store; }
|
||||
|
||||
test('JSON migration survives process exit before commit and retains exact legacy backups', { timeout: 30000 }, async t => {
|
||||
const f = fixture(t), directory = legacyCase(f, 'migration');
|
||||
const sessionFile = path.join(directory, 'sessions', f.session.id + '.json');
|
||||
const before = fs.readFileSync(sessionFile);
|
||||
await crash(t, directory, 'migration');
|
||||
const raw = new StateDatabase(directory);
|
||||
assert.equal(raw.initialized, false); assert.equal(raw.cursor, 0); assert.equal(raw.load().sessions.length, 0); raw.close();
|
||||
assert.deepEqual(fs.readFileSync(sessionFile), before);
|
||||
const recovered = reopen(f, directory), session = recovered.session(f.session.id);
|
||||
assert.equal(session.messages[0].content, 'Original fixture requirement');
|
||||
assert.equal(recovered.core.task.size, 1);
|
||||
const migration = recovered.storage.meta('migration');
|
||||
assert.deepEqual(fs.readFileSync(path.join(directory, migration.backupRelative, 'sessions', f.session.id + '.json')), before);
|
||||
const expected = structuredClone(session); recovered.close();
|
||||
fs.writeFileSync(sessionFile, '{}');
|
||||
const again = reopen(f, directory);
|
||||
assert.deepEqual(again.session(f.session.id), expected, 'A stale JSON mirror cannot overwrite migrated SQLite state');
|
||||
const exported = path.join(f.root, 'rollback-export'); again.exportLegacyData(exported);
|
||||
assert.deepEqual(JSON.parse(fs.readFileSync(path.join(exported, 'sessions', session.id + '.json'), 'utf8')), expected);
|
||||
});
|
||||
|
||||
for (const point of ['after_state', 'after_event']) test('process exit ' + point + ' rolls back state, event and outbox together', { timeout: 30000 }, async t => {
|
||||
const f = fixture(t), directory = legacyCase(f, point), initial = reopen(f, directory);
|
||||
const before = structuredClone(initial.session(f.session.id)), cursor = initial.eventCursor;
|
||||
initial.close(); await crash(t, directory, point);
|
||||
const recovered = reopen(f, directory);
|
||||
assert.deepEqual(recovered.session(f.session.id), before); assert.equal(recovered.eventCursor, cursor);
|
||||
assert.equal(recovered.eventsAfter(cursor).events.length, 0);
|
||||
});
|
||||
|
||||
for (const phase of ['accepted', 'queued', 'approval_wait', 'approved', 'effect_unrecorded', 'result_committed', 'before_next_model']) {
|
||||
test('crash recovery at ' + phase + ' retains execution identity and never replays side effects', { timeout: 30000 }, async t => {
|
||||
const f = fixture(t), directory = legacyCase(f, phase);
|
||||
await crash(t, directory, phase);
|
||||
const recovered = reopen(f, directory), session = recovered.session(f.session.id), execution = recovered.executionSnapshot(session);
|
||||
assert.equal(session.status, 'paused'); assert.equal(execution.task.goal, 'Crash fixture task');
|
||||
assert.equal(execution.run.status, 'paused'); assert.equal(execution.run.stopReason, 'restart');
|
||||
const marker = path.join(f.projectRoot, 'executions.txt');
|
||||
const effectOccurred = ['effect_unrecorded', 'result_committed', 'before_next_model'].includes(phase);
|
||||
assert.equal(fs.existsSync(marker), effectOccurred);
|
||||
if (effectOccurred) assert.equal(fs.readFileSync(marker, 'utf8'), '1');
|
||||
assertToolPairs(session.providerMessages);
|
||||
const invocation = [...recovered.core.tool.values()].find(value => value.callId === 'crash-' + phase);
|
||||
if (phase !== 'accepted') {
|
||||
assert.ok(invocation); assert.equal(invocation.runId, execution.run.id); assert.equal(invocation.taskId, execution.task.id);
|
||||
if (['result_committed', 'before_next_model'].includes(phase)) {
|
||||
assert.equal(invocation.state, 'completed'); assert.equal(invocation.requiresVerification, false);
|
||||
const result = JSON.parse(session.providerMessages.find(value => value.tool_call_id === invocation.callId).content);
|
||||
assert.equal(result.status, 'completed'); assert.match(result.stdout, /fixture-result/);
|
||||
} else if (['approved', 'effect_unrecorded'].includes(phase)) {
|
||||
assert.equal(invocation.state, 'unknown'); assert.equal(invocation.requiresVerification, true);
|
||||
assert.ok(execution.run.checkpoint.requiresVerification.includes(invocation.id));
|
||||
} else { assert.equal(invocation.state, 'interrupted'); assert.equal(invocation.requiresVerification, false); }
|
||||
}
|
||||
const oldApproval = session.approvals[0]?.id;
|
||||
const provider = new Provider(); let requests = 0;
|
||||
provider.complete = async () => { requests++; return { message: { role: 'assistant', content: 'Recovered records inspected.' }, usage: null }; };
|
||||
const runtime = new Runtime(recovered, provider); f.onCleanup(() => runtime.stopAll());
|
||||
if (oldApproval) assert.throws(() => runtime.decide(session.id, oldApproval, true), { status: 409 });
|
||||
if (phase !== 'accepted') {
|
||||
const previousRunId = session.runId, taskId = session.taskId;
|
||||
runtime.resume(session.id); await runtime.active.get(session.id).promise;
|
||||
assert.equal(requests, 1); assert.equal(session.taskId, taskId); assert.notEqual(session.runId, previousRunId);
|
||||
assert.equal(recovered.core.run.get(session.runId).resumeOf, previousRunId);
|
||||
if (oldApproval) assert.throws(() => runtime.decide(session.id, oldApproval, true), { status: 409 });
|
||||
assert.equal(fs.existsSync(marker), effectOccurred);
|
||||
if (effectOccurred) assert.equal(fs.readFileSync(marker, 'utf8'), '1');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
test('state and event failures publish no success and preserve the last committed memory snapshot', t => {
|
||||
const f = fixture(t), before = structuredClone(f.session), cursor = f.store.eventCursor;
|
||||
let notifications = 0; f.store.on('update', () => notifications++);
|
||||
f.store.storage.faultInjector = point => { if (point === 'after_event') throw new Error('Controlled transaction failure'); };
|
||||
assert.throws(() => f.store.message(f.session, 'user', 'must not publish'), /Controlled transaction failure/);
|
||||
assert.deepEqual(f.session, before); assert.equal(f.store.eventCursor, cursor); assert.equal(notifications, 0);
|
||||
f.store.storage.faultInjector = null;
|
||||
f.store.message(f.session, 'user', 'committed'); assert.equal(notifications, 1);
|
||||
});
|
||||
|
||||
test('tool result artifacts and event cursors retain project ownership across restart', async t => {
|
||||
const f = fixture(t), provider = new Provider(); let round = 0;
|
||||
provider.complete = async () => ({ message: round++ === 0 ? { role: 'assistant', content: '', tool_calls: [call('owned-read', 'read_file', { path: 'README.md' })] }
|
||||
: { role: 'assistant', content: 'Read complete.' }, usage: { prompt_tokens: 11, completion_tokens: 3 } });
|
||||
const runtime = new Runtime(f.store, provider); f.onCleanup(() => runtime.stopAll());
|
||||
const initial = f.store.eventCursor;
|
||||
runtime.start(f.session.id, 'Read the fixture'); await runtime.active.get(f.session.id).promise;
|
||||
const snapshot = f.store.executionSnapshot(f.session);
|
||||
assert.equal(snapshot.run.usage.requests, 2); assert.equal(snapshot.run.usage.totalTokens, 28);
|
||||
const artifact = snapshot.artifacts[0]; assert.equal(artifact.projectId, f.project.id);
|
||||
assert.match(JSON.parse(f.store.artifactStore.read(artifact)).content, /Fixture project/);
|
||||
const other = f.store.createSession(f.project.id);
|
||||
assert.throws(() => f.store.owned('artifact', artifact.id, other.id), { status: 404 });
|
||||
const page = f.store.eventsAfter(initial, { sessionId: f.session.id, limit: 3 });
|
||||
assert.equal(page.events.length, 3); assert.equal(page.hasMore, true);
|
||||
assert.ok(page.events.every(event => event.projectId === f.project.id && event.sessionId === f.session.id));
|
||||
const next = f.store.eventsAfter(page.nextCursor, { sessionId: f.session.id });
|
||||
assert.ok(next.events.every(event => event.seq > page.nextCursor));
|
||||
const all = [...page.events, ...next.events]; assert.equal(new Set(all.map(event => event.seq)).size, all.length);
|
||||
const expectedCursor = f.store.eventCursor;
|
||||
f.store.close(); const recovered = reopen(f, f.data);
|
||||
assert.equal(recovered.eventCursor, expectedCursor);
|
||||
assert.deepEqual(recovered.owned('artifact', artifact.id, f.session.id), artifact);
|
||||
});
|
||||
|
||||
test('token budgets pause before tools execute and continuation keeps original task and accumulated usage', async t => {
|
||||
const f = fixture(t), provider = new Provider(); let round = 0;
|
||||
f.store.saveConfig({ maxRunTokens: 25 });
|
||||
provider.complete = async () => ({ message: { role: 'assistant', content: '', tool_calls: [call('budget-' + round++, 'run_command', { command: 'node --version', reason: 'must not execute over budget' })] },
|
||||
usage: { prompt_tokens: 20, completion_tokens: 10 } });
|
||||
const runtime = new Runtime(f.store, provider); f.onCleanup(() => runtime.stopAll());
|
||||
runtime.start(f.session.id, 'Original goal'); await runtime.active.get(f.session.id).promise;
|
||||
assert.equal(f.session.status, 'paused'); assert.equal(f.session.approvals.length, 0);
|
||||
const originalTaskId = f.session.taskId;
|
||||
assert.equal(f.store.core.run.get(f.session.runId).stopReason, 'token_limit');
|
||||
assert.equal(f.store.core.task.get(originalTaskId).usage.totalTokens, 30); assertToolPairs(f.session.providerMessages);
|
||||
f.store.saveConfig({ maxRunTokens: 1000 });
|
||||
provider.complete = async () => ({ message: { role: 'assistant', content: 'Finished.' }, usage: { prompt_tokens: 5, completion_tokens: 5 } });
|
||||
runtime.start(f.session.id, 'Also preserve the public API.'); await runtime.active.get(f.session.id).promise;
|
||||
assert.equal(f.session.taskId, originalTaskId); assert.equal(f.store.core.task.get(originalTaskId).goal, 'Original goal');
|
||||
assert.equal(f.store.core.task.get(originalTaskId).instructions[0].content, 'Also preserve the public API.');
|
||||
assert.equal(f.store.core.task.get(originalTaskId).usage.totalTokens, 40);
|
||||
assert.equal(f.store.core.run.get(f.session.runId).budget.maxTokens, 1000);
|
||||
});
|
||||
|
||||
test('a time budget interrupts an unresponsive model and persists a resumable run', async t => {
|
||||
const f = fixture(t), provider = new Provider(); f.store.saveConfig({ maxRunDurationMs: 80 });
|
||||
provider.complete = async (_config, _messages, _project, signal) => new Promise((resolve, reject) => {
|
||||
signal.addEventListener('abort', () => reject(signal.reason), { once: true });
|
||||
if (signal.aborted) reject(signal.reason);
|
||||
});
|
||||
const runtime = new Runtime(f.store, provider); f.onCleanup(() => runtime.stopAll());
|
||||
runtime.start(f.session.id, 'Keep this goal after timeout'); await runtime.active.get(f.session.id).promise;
|
||||
assert.equal(f.session.status, 'paused'); assert.equal(f.store.core.run.get(f.session.runId).stopReason, 'time_limit');
|
||||
assert.match(f.session.messages.at(-1).content, /时间预算/); assert.equal(runtime.isActive(f.session.id), false);
|
||||
});
|
||||
|
||||
test('a corrupted large result artifact cannot become a recovered success', t => {
|
||||
const f = fixture(t), run = f.store.beginRun(f.session, 'Read a large fixture', false, f.store.config);
|
||||
const tool = call('large-result', 'read_file', { path: 'README.md' });
|
||||
f.session.providerMessages.push({ role: 'assistant', content: '', tool_calls: [tool] });
|
||||
const event = { id: crypto.randomUUID(), kind: 'tool', tool: 'read_file', phase: 'queued', toolCallId: tool.id, runId: run.id, createdAt: new Date().toISOString() };
|
||||
f.session.events.push(event); f.store.registerInvocation(f.session, tool, run, event);
|
||||
f.store.beginInvocation(f.session, tool, run, event); f.store.invocationState(f.session, event, 'running');
|
||||
event.phase = 'completed';
|
||||
const artifact = f.store.finishInvocation(f.session, event, { status: 'completed', content: 'x'.repeat(20000) });
|
||||
fs.writeFileSync(path.join(f.data, 'artifacts', artifact.relative), 'corrupted fixture result');
|
||||
f.store.close(); const recovered = reopen(f, f.data), session = recovered.session(f.session.id);
|
||||
const result = JSON.parse(session.providerMessages.find(value => value.tool_call_id === tool.id).content);
|
||||
assert.equal(result.status, 'unknown'); assert.equal(result.requires_verification, true);
|
||||
assert.equal(recovered.executionSnapshot(session).progress.requiresVerification.length, 1);
|
||||
});
|
||||
Vendored
+54
@@ -0,0 +1,54 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { randomUUID } from 'node:crypto';
|
||||
import { Store } from '../../src/server/store.mjs';
|
||||
import { Runtime } from '../../src/server/runtime.mjs';
|
||||
import { Provider } from '../../src/server/provider.mjs';
|
||||
|
||||
const [directory, phase] = process.argv.slice(2);
|
||||
const store = new Store(directory, { faultInjector: point => { if (phase === 'migration' && point === 'migration_records') process.exit(66); } });
|
||||
const session = [...store.sessions.values()][0];
|
||||
const project = store.project(session.projectId);
|
||||
const call = { id: 'crash-' + phase, type: 'function', function: { name: 'run_command', arguments: JSON.stringify({ command: 'node worker-effect.mjs', reason: 'Controlled crash fixture' }) } };
|
||||
|
||||
if (phase === 'after_state' || phase === 'after_event') {
|
||||
store.storage.faultInjector = point => { if (point === phase) process.exit(66); };
|
||||
store.message(session, 'user', 'This transaction must roll back.');
|
||||
throw new Error('Transaction crash point was not reached.');
|
||||
}
|
||||
if (phase === 'accepted' || phase === 'queued') {
|
||||
const run = store.beginRun(session, 'Crash fixture task', false, store.config);
|
||||
if (phase === 'queued') {
|
||||
session.providerMessages.push({ role: 'assistant', content: '', tool_calls: [call] });
|
||||
const event = { id: randomUUID(), kind: 'tool', phase: 'queued', tool: 'run_command', toolCallId: call.id, runId: run.id, taskId: run.taskId, label: 'Controlled fixture', createdAt: new Date().toISOString() };
|
||||
session.events.push(event); store.registerInvocation(session, call, run, event); store.save(session);
|
||||
}
|
||||
process.exit(66);
|
||||
}
|
||||
|
||||
const provider = new Provider();
|
||||
let requests = 0;
|
||||
provider.complete = async () => {
|
||||
requests++;
|
||||
if (requests > 1 && phase === 'before_next_model') process.exit(66);
|
||||
return { message: requests === 1 ? { role: 'assistant', content: '', tool_calls: [call] } : { role: 'assistant', content: 'Done.' }, usage: { prompt_tokens: 20, completion_tokens: 10 } };
|
||||
};
|
||||
const runtime = new Runtime(store, provider);
|
||||
if (phase === 'approved') runtime.executeCommand = () => process.exit(66);
|
||||
const finish = store.finishInvocation.bind(store);
|
||||
store.finishInvocation = (...args) => {
|
||||
if (phase === 'effect_unrecorded') process.exit(66);
|
||||
const result = finish(...args);
|
||||
if (phase === 'result_committed') process.exit(66);
|
||||
return result;
|
||||
};
|
||||
runtime.start(session.id, 'Crash fixture task');
|
||||
const poll = setInterval(() => {
|
||||
const approval = session.approvals.find(value => value.status === 'pending');
|
||||
if (!approval) return;
|
||||
if (phase === 'approval_wait') process.exit(66);
|
||||
runtime.decide(session.id, approval.id, true);
|
||||
}, 10);
|
||||
await runtime.active.get(session.id).promise;
|
||||
clearInterval(poll); store.close();
|
||||
throw new Error('Runtime crash point was not reached: ' + phase + ' at ' + path.basename(project.root));
|
||||
+4
-2
@@ -8,6 +8,7 @@ import { Store } from '../src/server/store.mjs';
|
||||
|
||||
export const workspace = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
||||
const fixtureRoot = path.join(workspace, '.qa');
|
||||
const disposalLists = new WeakMap();
|
||||
|
||||
export function fixture(t) {
|
||||
fs.mkdirSync(fixtureRoot, { recursive: true });
|
||||
@@ -19,7 +20,8 @@ export function fixture(t) {
|
||||
const store = new Store(data);
|
||||
const project = store.addProject(projectRoot);
|
||||
const session = store.createSession(project.id);
|
||||
const disposers = [];
|
||||
const disposers = [() => store.close()];
|
||||
disposalLists.set(t, disposers);
|
||||
t.after(async () => {
|
||||
for (const dispose of disposers.reverse()) await dispose();
|
||||
const resolved = path.resolve(root);
|
||||
@@ -102,6 +104,6 @@ export async function launchWorkbench(t, data, extraEnv = {}) {
|
||||
try { await api('/shutdown', {}); await until(() => child.exitCode !== null || child.signalCode !== null, 5000); }
|
||||
finally { if (child.exitCode === null && child.signalCode === null) child.kill(); }
|
||||
};
|
||||
t.after(close);
|
||||
if (disposalLists.has(t)) disposalLists.get(t).push(close); else t.after(close);
|
||||
return { child, url, bootstrap, api, close };
|
||||
}
|
||||
|
||||
@@ -63,7 +63,8 @@ test('the compatible HTTP loop preserves call IDs, validates errors and waits be
|
||||
assert.match(f.session.events.find(event => event.toolCallId === 'command').output, /fixture-command/);
|
||||
assert.equal(runtime.isActive(f.session.id), false);
|
||||
assert.ok(model.requests.every(request => request.headers.authorization === 'Bearer fixture-only-secret'));
|
||||
for (const name of fs.readdirSync(path.join(f.data, 'sessions'))) assert.ok(!fs.readFileSync(path.join(f.data, 'sessions', name), 'utf8').includes('fixture-only-secret'));
|
||||
assert.ok(!JSON.stringify(f.store.storage.load()).includes('fixture-only-secret'));
|
||||
for (const artifact of f.store.core.artifact.values()) assert.ok(!f.store.artifactStore.read(artifact).includes('fixture-only-secret'));
|
||||
assert.ok(!fs.readFileSync(path.join(f.data, 'config.json'), 'utf8').includes('fixture-only-secret'));
|
||||
});
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ test('tool-pair recovery fills missing results and drops orphan or duplicate res
|
||||
});
|
||||
|
||||
test('restart pauses unfinished work, retains proposals and never replays a command', t => {
|
||||
const { store, session, data, projectRoot } = fixture(t);
|
||||
const f = fixture(t), { store, session, data, projectRoot } = f;
|
||||
const proposal = proposeFile(store, session, { path: 'new.md', content: '# Pending\n' });
|
||||
session.status = 'awaiting_approval';
|
||||
session.providerMessages = [{ role: 'user', content: 'test' }, { role: 'assistant', content: '', tool_calls: [call('unfinished', 'run_command', { command: 'node --version', reason: 'test' })] }];
|
||||
@@ -37,6 +37,7 @@ test('restart pauses unfinished work, retains proposals and never replays a comm
|
||||
session.approvals.push({ id: 'approval', status: 'pending', command: 'node --version' });
|
||||
store.save(session); const previousRevision = session.revision;
|
||||
const recoveredStore = new Store(data), recovered = recoveredStore.session(session.id);
|
||||
f.onCleanup(() => recoveredStore.close());
|
||||
assert.equal(recovered.status, 'paused');
|
||||
assert.equal(recovered.events[0].phase, 'interrupted');
|
||||
assert.match(recovered.events[0].output, /进入执行阶段/);
|
||||
|
||||
@@ -8,8 +8,9 @@ import { upgradeRunning } from '../scripts/upgrade-running.mjs';
|
||||
|
||||
test('the running 0.1.0 process upgrades in place and retains its project, session, files and volatile model connection', { timeout: 30000 }, async t => {
|
||||
const f = fixture(t);
|
||||
const legacyData = path.join(f.root, 'legacy-data'); f.store.exportLegacyData(legacyData);
|
||||
const oldRoot = path.join(workspace, 'tests', 'fixtures', 'legacy-workbench-0.1');
|
||||
const env = { ...process.env, AGENT_WORKBENCH_APP_DIR: oldRoot, AGENT_WORKBENCH_DATA_DIR: f.data, AGENT_WORKBENCH_PORT: '0' };
|
||||
const env = { ...process.env, AGENT_WORKBENCH_APP_DIR: oldRoot, AGENT_WORKBENCH_DATA_DIR: legacyData, AGENT_WORKBENCH_PORT: '0' };
|
||||
delete env.AGENT_WORKBENCH_API_KEY;
|
||||
const child = spawn(process.execPath, [path.join(oldRoot, 'dist-server', 'server.mjs')], { cwd: oldRoot, env, windowsHide: true, stdio: ['ignore', 'pipe', 'pipe'] });
|
||||
let url = '', output = '', stderr = '';
|
||||
@@ -37,7 +38,9 @@ test('the running 0.1.0 process upgrades in place and retains its project, sessi
|
||||
assert.equal((await api('/diagnostics?session=' + f.session.id)).version, '1.0.0');
|
||||
assert.deepEqual((await api('/config/models', {})).models, ['upgrade-fixture']);
|
||||
assert.equal(model.requests[0].headers.authorization, 'Bearer fixture-upgrade-memory-key');
|
||||
assert.ok(!fs.readFileSync(path.join(f.data, 'config.json'), 'utf8').includes('fixture-upgrade-memory-key'));
|
||||
assert.ok(!fs.readFileSync(path.join(legacyData, 'config.json'), 'utf8').includes('fixture-upgrade-memory-key'));
|
||||
assert.equal(bootstrap.storage.engine, 'sqlite');
|
||||
assert.equal((await api('/sessions/' + f.session.id)).execution.task.origin, 'legacy-import');
|
||||
const health = await (await fetch(url + '/api/health')).json(); assert.equal(health.pid, child.pid);
|
||||
await assert.rejects(fetch('http://127.0.0.1:9229/json/list', { signal: AbortSignal.timeout(500) }));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user