test(pi): hold packaged rpc confirmation past timeout
This commit is contained in:
@@ -40,6 +40,7 @@ describe('Pi packaged release proof wiring', () => {
|
||||
expect(scriptSource).toContain('setMainWindowVisible(electronApplication, false)');
|
||||
expect(scriptSource).toContain("evaluateProof(electronApplication, 'resilience.dispose-target')");
|
||||
expect(proofSource).toContain('const PROOF_MUTATION_CONFIRMATION_DELAY_MS = 12_000;');
|
||||
expect(proofSource).toContain('delayNextTopLevelConfirmationForProof');
|
||||
expect(mainSource).toContain("'resilience.arm-compact-delay'");
|
||||
expect(mainSource).toContain("'resilience.arm-prompt-delay'");
|
||||
expect(scriptSource).toContain("evaluateProof(electronApplication, 'resilience.arm-compact-delay')");
|
||||
|
||||
@@ -102,6 +102,38 @@ describe('strict Pi LF JSONL framing', () => {
|
||||
});
|
||||
|
||||
describe('Pi RPC client', () => {
|
||||
it('can deterministically hold one proof response past the mutation timeout', async () => {
|
||||
vi.useFakeTimers();
|
||||
let written = '';
|
||||
const writable = new Writable({
|
||||
write(chunk, _encoding, callback) {
|
||||
written += chunk.toString();
|
||||
callback();
|
||||
},
|
||||
});
|
||||
const lateResults: Array<{ success: boolean }> = [];
|
||||
const client = new PiRpcClient(writable, { generation: 1, defaultTimeoutMs: 10_000 });
|
||||
client.delayNextResponseForProof('prompt', 12_000);
|
||||
const requested = client.request(
|
||||
{ type: 'prompt', message: 'proof response hold' },
|
||||
{
|
||||
retainAfterTimeout: true,
|
||||
onLateResult: (result) => lateResults.push({ success: result.response?.success === true }),
|
||||
},
|
||||
);
|
||||
void requested.catch(() => undefined);
|
||||
await Promise.resolve();
|
||||
const command = JSON.parse(written) as { id: string };
|
||||
client.accept({ type: 'response', id: command.id, success: true });
|
||||
|
||||
await vi.advanceTimersByTimeAsync(10_000);
|
||||
await expect(requested).rejects.toMatchObject({ code: 'PI_RPC_TIMEOUT' });
|
||||
expect(client.pendingCount).toBe(1);
|
||||
await vi.advanceTimersByTimeAsync(2_000);
|
||||
expect(client.pendingCount).toBe(0);
|
||||
expect(lateResults).toEqual([{ success: true }]);
|
||||
});
|
||||
|
||||
it('keeps a mutation correlated after the 10 second confirmation timeout', async () => {
|
||||
vi.useFakeTimers();
|
||||
let written = '';
|
||||
|
||||
Reference in New Issue
Block a user