11// OpenClaw tests cover main rescue and audit command behavior.
2- import { describe , expect , it , vi } from "vitest" ;
2+ import { beforeAll , describe , expect , it , vi } from "vitest" ;
33import type { OpenClawConfig } from "../config/types.openclaw.js" ;
44import { SystemAgentInferenceUnavailableError } from "./inference-error.js" ;
55import type { SystemAgentCommandDeps } from "./operations.js" ;
@@ -9,13 +9,35 @@ import {
99 createSystemAgentTestRuntime ,
1010 createSystemAgentVerifiedInferenceTestFixture ,
1111} from "./system-agent.test-helpers.js" ;
12+ import type { SystemAgentVerifiedInferenceBinding } from "./verified-inference.js" ;
13+
14+ const inferenceMocks = vi . hoisted ( ( ) => ( {
15+ sharedVerifiedInference : undefined as SystemAgentVerifiedInferenceBinding | undefined ,
16+ } ) ) ;
1217
1318vi . mock ( "../plugins/providers.js" , async ( importOriginal ) => ( {
1419 ...( await importOriginal < typeof import ( "../plugins/providers.js" ) > ( ) ) ,
1520 resolveOwningPluginIdsForModelRefs : vi . fn ( ( ) => [ ] ) ,
1621 resolveOwningPluginIdsForProviderRef : vi . fn ( ( ) => [ ] ) ,
1722} ) ) ;
1823
24+ vi . mock ( "./verified-inference.js" , async ( importOriginal ) => {
25+ const actual = await importOriginal < typeof import ( "./verified-inference.js" ) > ( ) ;
26+ return {
27+ ...actual ,
28+ resolveSystemAgentVerifiedInferenceRoute : (
29+ ...args : Parameters < typeof actual . resolveSystemAgentVerifiedInferenceRoute >
30+ ) => {
31+ // Ordinary runner cases share one immutable verified fixture. Distinct
32+ // bindings still use the real resolver for route and apply-boundary drift.
33+ if ( args [ 0 ] === inferenceMocks . sharedVerifiedInference ) {
34+ return Promise . resolve ( args [ 0 ] . execution ) ;
35+ }
36+ return actual . resolveSystemAgentVerifiedInferenceRoute ( ...args ) ;
37+ } ,
38+ } ;
39+ } ) ;
40+
1941const overview : SystemAgentOverview = {
2042 defaultAgentId : "main" ,
2143 defaultModel : "openai/gpt-5.5" ,
@@ -71,10 +93,22 @@ function configSnapshot(config: OpenClawConfig) {
7193 } ;
7294}
7395
74- async function createVerifiedRunOptions ( deps : SystemAgentCommandDeps = { } ) {
75- const fixture = await createSystemAgentVerifiedInferenceTestFixture ( verifiedConfig ) ;
96+ let sharedVerifiedFixture : Awaited <
97+ ReturnType < typeof createSystemAgentVerifiedInferenceTestFixture >
98+ > ;
99+
100+ beforeAll ( async ( ) => {
101+ sharedVerifiedFixture = await createSystemAgentVerifiedInferenceTestFixture ( verifiedConfig ) ;
102+ inferenceMocks . sharedVerifiedInference = sharedVerifiedFixture . binding ;
103+ } ) ;
104+
105+ function createVerifiedRunOptions (
106+ deps : SystemAgentCommandDeps = { } ,
107+ options : { revalidate ?: boolean } = { } ,
108+ ) {
109+ const fixture = sharedVerifiedFixture ;
76110 return {
77- verifiedInference : fixture . binding ,
111+ verifiedInference : options . revalidate ? { ... fixture . binding } : fixture . binding ,
78112 deps : {
79113 ...fixture . deps ,
80114 readConfigFileSnapshot : vi . fn ( async ( ) => configSnapshot ( verifiedConfig ) ) as never ,
@@ -123,7 +157,7 @@ describe("runSystemAgent", () => {
123157 const { runtime, lines } = createSystemAgentTestRuntime ( ) ;
124158 let runGatewayRestartCalls = 0 ;
125159 let onReadyCalls = 0 ;
126- const verified = await createVerifiedRunOptions ( {
160+ const verified = createVerifiedRunOptions ( {
127161 runGatewayRestart : async ( ) => {
128162 runGatewayRestartCalls += 1 ;
129163 } ,
@@ -166,10 +200,13 @@ describe("runSystemAgent", () => {
166200 . mockResolvedValueOnce ( configSnapshot ( verifiedConfig ) )
167201 . mockResolvedValue ( configSnapshot ( changedConfig ) ) ;
168202 const runGatewayRestart = vi . fn ( async ( ) => { } ) ;
169- const verified = await createVerifiedRunOptions ( {
170- readConfigFileSnapshot : readConfigFileSnapshot as never ,
171- runGatewayRestart,
172- } ) ;
203+ const verified = createVerifiedRunOptions (
204+ {
205+ readConfigFileSnapshot : readConfigFileSnapshot as never ,
206+ runGatewayRestart,
207+ } ,
208+ { revalidate : true } ,
209+ ) ;
173210
174211 await expect (
175212 runSystemAgent (
@@ -195,12 +232,16 @@ describe("runSystemAgent", () => {
195232 . fn ( )
196233 . mockResolvedValueOnce ( configSnapshot ( verifiedConfig ) )
197234 . mockResolvedValueOnce ( configSnapshot ( verifiedConfig ) )
235+ . mockResolvedValueOnce ( configSnapshot ( verifiedConfig ) )
198236 . mockResolvedValue ( configSnapshot ( changedConfig ) ) ;
199237 const runGatewayRestart = vi . fn ( async ( ) => { } ) ;
200- const verified = await createVerifiedRunOptions ( {
201- readConfigFileSnapshot : readConfigFileSnapshot as never ,
202- runGatewayRestart,
203- } ) ;
238+ const verified = createVerifiedRunOptions (
239+ {
240+ readConfigFileSnapshot : readConfigFileSnapshot as never ,
241+ runGatewayRestart,
242+ } ,
243+ { revalidate : true } ,
244+ ) ;
204245
205246 await expect (
206247 runSystemAgent (
@@ -215,15 +256,15 @@ describe("runSystemAgent", () => {
215256 ) ,
216257 ) . rejects . toBeInstanceOf ( SystemAgentInferenceUnavailableError ) ;
217258
218- expect ( readConfigFileSnapshot ) . toHaveBeenCalledTimes ( 3 ) ;
259+ expect ( readConfigFileSnapshot ) . toHaveBeenCalledTimes ( 4 ) ;
219260 expect ( runGatewayRestart ) . not . toHaveBeenCalled ( ) ;
220261 } ) ;
221262
222263 it ( "keeps exact one-shot parsing ahead of the assistant planner" , async ( ) => {
223264 const { runtime, lines } = createSystemAgentTestRuntime ( ) ;
224265 let plannerCalls = 0 ;
225266 let onReadyCalls = 0 ;
226- const verified = await createVerifiedRunOptions ( ) ;
267+ const verified = createVerifiedRunOptions ( ) ;
227268
228269 await runSystemAgent (
229270 {
@@ -248,7 +289,7 @@ describe("runSystemAgent", () => {
248289
249290 it ( "prints an explicit one-shot overview exactly once" , async ( ) => {
250291 const { runtime, lines } = createSystemAgentTestRuntime ( ) ;
251- const verified = await createVerifiedRunOptions ( ) ;
292+ const verified = createVerifiedRunOptions ( ) ;
252293
253294 await runSystemAgent (
254295 {
@@ -268,7 +309,7 @@ describe("runSystemAgent", () => {
268309 { name : "invalid command" , plan : { command : "invent a new operation" } } ,
269310 ] ) ( "fails a fuzzy one-shot when inference returns $name" , async ( { plan } ) => {
270311 const { runtime } = createSystemAgentTestRuntime ( ) ;
271- const verified = await createVerifiedRunOptions ( ) ;
312+ const verified = createVerifiedRunOptions ( ) ;
272313
273314 await expect (
274315 runSystemAgent (
@@ -285,7 +326,7 @@ describe("runSystemAgent", () => {
285326
286327 it ( "prints a valid reply-only one-shot plan" , async ( ) => {
287328 const { runtime, lines } = createSystemAgentTestRuntime ( ) ;
288- const verified = await createVerifiedRunOptions ( ) ;
329+ const verified = createVerifiedRunOptions ( ) ;
289330
290331 await runSystemAgent (
291332 {
@@ -306,9 +347,12 @@ describe("runSystemAgent", () => {
306347 agents : { defaults : { model : "anthropic/claude-opus-4-8" } } ,
307348 } satisfies OpenClawConfig ;
308349 let currentConfig : OpenClawConfig = verifiedConfig ;
309- const verified = await createVerifiedRunOptions ( {
310- readConfigFileSnapshot : vi . fn ( async ( ) => configSnapshot ( currentConfig ) ) as never ,
311- } ) ;
350+ const verified = createVerifiedRunOptions (
351+ {
352+ readConfigFileSnapshot : vi . fn ( async ( ) => configSnapshot ( currentConfig ) ) as never ,
353+ } ,
354+ { revalidate : true } ,
355+ ) ;
312356
313357 await expect (
314358 runSystemAgent (
@@ -331,7 +375,7 @@ describe("runSystemAgent", () => {
331375 const { runtime, lines } = createSystemAgentTestRuntime ( ) ;
332376 let runInteractiveTuiCalls = 0 ;
333377 let onReadyCalls = 0 ;
334- const verified = await createVerifiedRunOptions ( ) ;
378+ const verified = createVerifiedRunOptions ( ) ;
335379
336380 await runSystemAgent (
337381 {
@@ -357,7 +401,7 @@ describe("runSystemAgent", () => {
357401 const { runtime, lines } = createSystemAgentTestRuntime ( ) ;
358402 let loadOverviewCalls = 0 ;
359403 let runInteractiveTuiCalls = 0 ;
360- const verified = await createVerifiedRunOptions ( ) ;
404+ const verified = createVerifiedRunOptions ( ) ;
361405
362406 await runSystemAgent (
363407 {
@@ -396,7 +440,7 @@ describe("runSystemAgent", () => {
396440 ] ) ( "exits non-zero when $name" , async ( { input, output, interactive } ) => {
397441 const { runtime, lines } = createSystemAgentTestRuntime ( ) ;
398442 let runInteractiveTuiCalls = 0 ;
399- const verified = await createVerifiedRunOptions ( ) ;
443+ const verified = createVerifiedRunOptions ( ) ;
400444
401445 await expect (
402446 runSystemAgent (
0 commit comments