Files
stack/packages/cli/tests/model-stall.test.mjs
jason.woltje 362893d043 feat: integrate reviewed proxy page and managed model keys
Source-candidate: poe d9a564e6d20f5f0fd75ce45b12cbbf8bb4c9d568\nSource-candidate: magica38ba5762b06716db1dee00d0afec162656488f5c\nValidated321whole-file phase plus whole bus1349/model-proxy100/webui490; final gate tooling checks pending, not landed.
2026-10-26 12:04:21 -05:00

31 lines
2.1 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { watchModelOutput } from '../src/model-stall.mjs';
function fixture(t) { const root = fs.mkdtempSync(join(tmpdir(), 'p2-stall-')); t.after(() => fs.rmSync(root, { recursive: true, force: true })); return root; }
test('proxy-stall: silent run stops and logs only ids, never output or key values', async t => {
const root = fixture(t), receipts = []; let stops = 0;
const watch = watchModelOutput({ runDir: root, seconds: 0.02, keyId: '0123456789ab', stop: async () => { stops++; }, receipt: r => receipts.push(r) });
t.after(watch.cancel); await watch.done;
assert.equal(stops, 1); assert.deepEqual(receipts, [{ action: 'proxy-stall', keyIds: ['0123456789ab'] }]);
});
test('first stdout marker cancels stall without reading or logging marker text', async t => {
const root = fixture(t), receipts = []; let stops = 0;
fs.writeFileSync(join(root, 'proxy-first-output'), 'fx331-private-output');
const watch = watchModelOutput({ runDir: root, seconds: 0.02, keyId: '0123456789ab', stop: async () => { stops++; }, receipt: r => receipts.push(r) });
t.after(watch.cancel); await watch.done; assert.equal(stops, 0); assert.deepEqual(receipts, []);
});
test('proxy-stop-failed: failed stall stop is logged by code and never leaks error text', async t => {
const root = fixture(t), receipts = [];
const watch = watchModelOutput({ runDir: root, seconds: 0.02, keyId: '0123456789ab', stop: async () => { throw Error('fx331-private-output'); }, receipt: r => receipts.push(r) });
t.after(watch.cancel); await watch.done;
assert.deepEqual(receipts, [{ action: 'proxy-stall', code: 'proxy-stop-failed', keyIds: ['0123456789ab'] }]);
});
test('run exit cancellation settles watcher without stopping the run', async t => {
const root = fixture(t); let stops = 0;
const watch = watchModelOutput({ runDir: root, seconds: 0.02, keyId: '0123456789ab', stop: async () => { stops++; }, receipt: () => {} });
watch.cancel(); await watch.done; assert.equal(stops, 0);
});