confluence_web/agent/tests/peer.test.ts
Artur Mukhamadiev 38a8ca67f7 agent: pi runtime track handoff (contract revision 1)
Pinned pi SDK 0.85.1 bridge, Python supervisor, artifact exporter,
scripted backend peer, image checks and boundary checks under agent/**.
Review findings F1-F3 are recorded in docs/implementation/PI_AGENT_REVIEW.md.
2026-09-14 21:57:54 +03:00

31 lines
1.6 KiB
TypeScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { runPeer } from '../dev/fake-backend.js';
for (const mode of ['happy', 'no-artifacts', 'empty-file', 'skip', 'delayed', 'background', 'spaces', 'confluence-error']) {
test(`real SDK and native tools over public wire: ${mode}`, async () => { assert((await runPeer({ mode })).complete); });
}
for (const mode of ['upstream-failure', 'bad-reply', 'duplicate', 'eof-model', 'context-limit', 'output-limit', 'zero-text']) {
test(`scripted peer failure: ${mode}`, async () => {
const result = await runPeer({ mode }); assert(!result.complete);
if (mode !== 'eof-model') assert(result.failure, result.stderr);
assert(!JSON.stringify(result.failure).includes('DUMMY_PRIVATE'));
});
}
test('host supervisor leaves sibling processes alive', async t => {
const { spawn } = await import('node:child_process');
const sibling = spawn('sleep', ['10']);
t.after(() => sibling.kill('SIGTERM'));
assert((await runPeer()).complete);
assert.equal(sibling.exitCode, null);
assert.equal(sibling.signalCode, null);
});
test('failure entrypoint flushes an active large line and error through a slow peer', async () => {
const result = await runPeer({ mode: 'failure-during-collection' });
assert(!result.complete); assert.equal(result.failure.code, 'invalid_input');
const outgoing = result.transcript.filter(f => f.id.startsWith('a_'));
assert.deepEqual(outgoing.slice(-2).map(f => f.type), ['collection_start', 'error']);
assert(outgoing.at(-2).payload.markdown.length > 1024 * 1024);
});