okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
425bca719
main
1// A turn always ends: when the model goes silent the watchdog stops it with a plain message. 2import test from 'node:test' ; 3import assert from 'node:assert/strict' ; 4import { mkdtempSync , mkdirSync , rmSync } from 'node:fs' ; 5import { tmpdir } from 'node:os' ; 6import { join } from 'node:path' ; 7import { startScriptedWorker } from './helpers/scripted-worker.mjs' ; 8import { createAgentBridge } from '../server/agent/agent-bridge.mjs' ; 9import { resolveHarness } from '../server/agent/harness-runtime.mjs' ; 10const HARNESS = process . env . STRATA_HARNESS_DIR ; 11const skip = ! HARNESS || ! resolveHarness ({ env :process . env }). ok ?'STRATA_HARNESS_DIR is not set to a built Harness' :false ; 12 13test ( 'a silent model ends the turn with a plain message, and the chat works again afterwards' , { skip}, async ( t ) => { 14const worker = await startScriptedWorker ({}); 15const dir = mkdtempSync ( join ( tmpdir (), 'strata-wd-' )); const ws = join ( dir , 'ws' ); mkdirSync ( ws , { recursive :true }); 16const bridge = createAgentBridge ({ dataDir :dir , localInstances :() => [{ id :'i' , label :'S' , baseUrl :worker . url , modelId :'scripted-model' , context :32768 , slots :2 }], connections :() => [], env :process . env , startTimeoutMs :90_000 , stallMs :2500 , stallToolMs :6000 }); 17t . after ( async () => { await bridge . close (); await worker . close (); try { rmSync ( dir , { recursive :true , force :true , maxRetries :3 }); } catch { /* best effort */ } }); 18const out = []; 19const t0 = Date . now (); 20await bridge . runTurn ({ chatId :'w1' , message :'SCRIPT:hang' , workspacePath :ws , mode :'bypass' , onFrame :f => out . push ( f ) }); 21assert . ok ( Date . now () - t0 < 30_000 , 'it ended by itself' ); 22const err = out . find ( f => f . type === 'error' ); 23assert . match ( err . message , / stopped answering / ); assert . match ( err . message , / Send your message again / ); 24assert . equal ( out . at ( - 1 ). type , 'error' ); 25const again = []; 26await bridge . runTurn ({ chatId :'w1' , message :'SCRIPT:echo fine' , workspacePath :ws , mode :'bypass' , onFrame :f => again . push ( f ) }); 27assert . match ( again . filter ( f => f . type === 'delta' ). map ( f => f . text ). join ( '' ), / fine / ); 28}); 29 30test ( 'engine progress keeps a long prompt read alive past the stall limit, then the normal limit applies (#3623)' , { skip}, async ( t ) => { 31const worker = await startScriptedWorker ({}); 32const dir = mkdtempSync ( join ( tmpdir (), 'strata-wd-' )); const ws = join ( dir , 'ws' ); mkdirSync ( ws , { recursive :true }); 33const started = Date . now (); 34const bridge = createAgentBridge ({ dataDir :dir , localInstances :() => [{ id :'i' , label :'S' , baseUrl :worker . url , modelId :'scripted-model' , context :32768 , slots :2 }], connections :() => [], env :process . env , startTimeoutMs :90_000 , stallMs :2500 , stallToolMs :6000 , engineGraceMs :60_000 , 35// The engine moves for 7 s (a prompt being read), then goes quiet. 36engineProgress :() => ( Date . now () - started < 7_000 ?`reading: ${ Date . now ()} ` :null ) }); 37t . after ( async () => { await bridge . close (); await worker . close (); try { rmSync ( dir , { recursive :true , force :true , maxRetries :3 }); } catch { /* best effort */ } }); 38const out = []; 39const t0 = Date . now (); 40await bridge . runTurn ({ chatId :'w2' , message :'SCRIPT:hang' , workspacePath :ws , mode :'bypass' , onFrame :f => out . push ( f ) }); 41assert . ok ( Date . now () - started > 7_000 , 'the 2.5 s stall limit did not fire while the engine was reading' ); 42assert . ok ( Date . now () - t0 < 40_000 , 'and it still ended by itself once the engine went quiet' ); 43assert . match ( out . find ( f => f . type === 'error' ). message , / stopped answering / ); 44});