@@ -5,7 +5,7 @@ import os from "node:os";
55import path from "node:path" ;
66import { DatabaseSync } from "node:sqlite" ;
77import { afterAll , describe , expect , it } from "vitest" ;
8- import { testing as openclawTestInstanceTesting } from "../../test/helpers/openclaw-test-instance.js" ;
8+ import { createOpenClawTestInstance } from "../../test/helpers/openclaw-test-instance.js" ;
99import { useAutoCleanupTempDirTracker } from "../../test/helpers/temp-dir.js" ;
1010import { resolveGatewayLockDir } from "../config/paths.js" ;
1111import type { OpenClawConfig } from "../config/types.openclaw.js" ;
@@ -16,7 +16,6 @@ import {
1616 ensureOpenClawAgentDatabaseSchema ,
1717 OPENCLAW_AGENT_SCHEMA_VERSION ,
1818} from "../state/openclaw-agent-db.js" ;
19- import { getFreePort } from "../test-utils/ports.js" ;
2019import {
2120 createSourceRuntime ,
2221 runIsolatedModuleScript ,
@@ -384,104 +383,85 @@ describe("doctor invalid config process exit", () => {
384383// Synchronous CLI probes must not consume neighboring cases' timeout budgets.
385384describe ( "gateway startup-migration refusal" , ( ) => {
386385 it ( "quarantines every invalid legacy automation before Gateway readiness" , async ( ) => {
387- const root = await fs . promises . realpath ( tempDirs . make ( "openclaw-cron-upgrade-ready-" ) ) ;
388- const stateDir = path . join ( root , "state" ) ;
389- const configPath = path . join ( root , "openclaw.json" ) ;
386+ const instance = await createOpenClawTestInstance ( {
387+ name : "cron-upgrade-ready" ,
388+ startTimeoutMs : 30_000 ,
389+ stopTimeoutMs : 1_500 ,
390+ env : {
391+ NODE_ENV : undefined ,
392+ NO_COLOR : "1" ,
393+ OPENCLAW_DISABLE_BUNDLED_PLUGINS : "1" ,
394+ OPENCLAW_HOME : undefined ,
395+ OPENCLAW_NO_RESPAWN : "1" ,
396+ OPENCLAW_SKIP_CHANNELS : "1" ,
397+ OPENCLAW_TEST_FAST : "1" ,
398+ VITEST : undefined ,
399+ // Preserve full startup; the shared fixture otherwise skips sidecar readiness.
400+ OPENCLAW_GATEWAY_TOKEN : process . env . OPENCLAW_GATEWAY_TOKEN ,
401+ OPENCLAW_GATEWAY_PASSWORD : process . env . OPENCLAW_GATEWAY_PASSWORD ,
402+ OPENCLAW_SKIP_PROVIDERS : process . env . OPENCLAW_SKIP_PROVIDERS ,
403+ OPENCLAW_SKIP_GMAIL_WATCHER : process . env . OPENCLAW_SKIP_GMAIL_WATCHER ,
404+ OPENCLAW_SKIP_CRON : process . env . OPENCLAW_SKIP_CRON ,
405+ OPENCLAW_SKIP_BROWSER_CONTROL_SERVER : process . env . OPENCLAW_SKIP_BROWSER_CONTROL_SERVER ,
406+ OPENCLAW_SKIP_CANVAS_HOST : process . env . OPENCLAW_SKIP_CANVAS_HOST ,
407+ OPENCLAW_TEST_MINIMAL_GATEWAY : process . env . OPENCLAW_TEST_MINIMAL_GATEWAY ,
408+ } ,
409+ } ) ;
410+ const { env, port, stateDir } = instance ;
390411 const storePath = path . join ( stateDir , "cron" , "jobs.json" ) ;
391- const port = await getFreePort ( ) ;
392- const runtimeRoot = createSourceRuntime ( root ) ;
393- const env : NodeJS . ProcessEnv = {
394- ...process . env ,
395- HOME : root ,
396- USERPROFILE : root ,
397- OPENCLAW_CONFIG_PATH : configPath ,
398- OPENCLAW_DISABLE_BUNDLED_PLUGINS : "1" ,
399- OPENCLAW_NO_RESPAWN : "1" ,
400- OPENCLAW_SKIP_CHANNELS : "1" ,
401- OPENCLAW_STATE_DIR : stateDir ,
402- OPENCLAW_TEST_FAST : "1" ,
403- NO_COLOR : "1" ,
404- } ;
405- delete env . NODE_ENV ;
406- delete env . OPENCLAW_HOME ;
407- delete env . VITEST ;
408-
409- fs . mkdirSync ( path . dirname ( storePath ) , { recursive : true } ) ;
410- fs . writeFileSync (
411- configPath ,
412- JSON . stringify ( { gateway : { mode : "local" , auth : { mode : "none" } } } ) ,
413- ) ;
414- const job = {
415- name : "Legacy automation" ,
416- enabled : true ,
417- createdAtMs : 1 ,
418- updatedAtMs : 1 ,
419- schedule : { kind : "cron" , expr : "0 9 * * *" } ,
420- sessionTarget : "main" ,
421- wakeMode : "now" ,
422- payload : { kind : "systemEvent" , text : "tick" } ,
423- state : { } ,
424- } ;
425- fs . writeFileSync (
426- storePath ,
427- JSON . stringify ( {
428- version : 1 ,
429- jobs : [
430- { ...job , id : "valid-job" } ,
431- { ...job , id : "invalid-state-job" , state : { nextRunAtMs : - 1 } } ,
432- { ...job , id : "invalid-trigger-job" , trigger : { script : [ ] } } ,
433- ] ,
434- } ) ,
435- ) ;
436- const stdout = openclawTestInstanceTesting . createBoundedStringLog ( ) ;
437- const stderr = openclawTestInstanceTesting . createBoundedStringLog ( ) ;
438- const gateway = spawn (
439- process . execPath ,
440- [
441- "--preserve-symlinks" ,
442- "--preserve-symlinks-main" ,
443- "--import" ,
444- "tsx" ,
445- path . join ( runtimeRoot , "src" , "entry.ts" ) ,
446- "gateway" ,
447- "run" ,
448- "--allow-unconfigured" ,
449- "--port" ,
450- String ( port ) ,
451- ] ,
452- { cwd : runtimeRoot , env, stdio : [ "ignore" , "pipe" , "pipe" ] } ,
453- ) ;
454- gateway . stdout . setEncoding ( "utf8" ) ;
455- gateway . stderr . setEncoding ( "utf8" ) ;
456- gateway . stdout . on ( "data" , ( chunk ) => openclawTestInstanceTesting . appendLogChunk ( stdout , chunk ) ) ;
457- gateway . stderr . on ( "data" , ( chunk ) => openclawTestInstanceTesting . appendLogChunk ( stderr , chunk ) ) ;
458412
459413 try {
460- await openclawTestInstanceTesting . waitForGatewayReady ( gateway , stdout , stderr , port , 30_000 ) ;
461- const response = await fetch ( `http://127.0.0.1:${ port } /readyz` ) ;
462- await expect ( response . json ( ) ) . resolves . toMatchObject ( { ready : true , failing : [ ] } ) ;
463- } finally {
464- expect (
465- await openclawTestInstanceTesting . stopGatewayProcess ( gateway , Date . now ( ) + 5_000 , 1_500 , {
466- forceWindowsTree : true ,
414+ // Readiness must use the migration fixture without extra hooks or Control UI settings.
415+ await instance . state . writeConfig ( { gateway : { mode : "local" , auth : { mode : "none" } } } ) ;
416+ fs . mkdirSync ( path . dirname ( storePath ) , { recursive : true } ) ;
417+ const job = {
418+ name : "Legacy automation" ,
419+ enabled : true ,
420+ createdAtMs : 1 ,
421+ updatedAtMs : 1 ,
422+ schedule : { kind : "cron" , expr : "0 9 * * *" } ,
423+ sessionTarget : "main" ,
424+ wakeMode : "now" ,
425+ payload : { kind : "systemEvent" , text : "tick" } ,
426+ state : { } ,
427+ } ;
428+ fs . writeFileSync (
429+ storePath ,
430+ JSON . stringify ( {
431+ version : 1 ,
432+ jobs : [
433+ { ...job , id : "valid-job" } ,
434+ { ...job , id : "invalid-state-job" , state : { nextRunAtMs : - 1 } } ,
435+ { ...job , id : "invalid-trigger-job" , trigger : { script : [ ] } } ,
436+ ] ,
467437 } ) ,
468- ) . toBe ( true ) ;
469- }
438+ ) ;
470439
471- const loaded = await loadCronJobsStoreWithConfigJobsReadOnly ( storePath , env ) ;
472- expect ( loaded . store . jobs . map ( ( entry ) => entry . id ) ) . toContain ( "valid-job" ) ;
473- expect (
474- loadCronQuarantinedJobs ( storePath , env ) . map ( ( entry ) => ( {
475- sourceIndex : entry . sourceIndex ,
476- reason : entry . reason ,
477- id : entry . job ?. id ,
478- } ) ) ,
479- ) . toEqual ( [
480- { sourceIndex : 1 , reason : "invalid-state" , id : "invalid-state-job" } ,
481- { sourceIndex : 2 , reason : "invalid-trigger" , id : "invalid-trigger-job" } ,
482- ] ) ;
483- expect ( fs . existsSync ( storePath ) ) . toBe ( false ) ;
484- expect ( fs . existsSync ( `${ storePath } .migrated` ) ) . toBe ( true ) ;
440+ try {
441+ await instance . startGateway ( ) ;
442+ const response = await fetch ( `http://127.0.0.1:${ port } /readyz` ) ;
443+ await expect ( response . json ( ) ) . resolves . toMatchObject ( { ready : true , failing : [ ] } ) ;
444+ } finally {
445+ await instance . stopGateway ( ) ;
446+ }
447+
448+ const loaded = await loadCronJobsStoreWithConfigJobsReadOnly ( storePath , env ) ;
449+ expect ( loaded . store . jobs . map ( ( entry ) => entry . id ) ) . toContain ( "valid-job" ) ;
450+ expect (
451+ loadCronQuarantinedJobs ( storePath , env ) . map ( ( entry ) => ( {
452+ sourceIndex : entry . sourceIndex ,
453+ reason : entry . reason ,
454+ id : entry . job ?. id ,
455+ } ) ) ,
456+ ) . toEqual ( [
457+ { sourceIndex : 1 , reason : "invalid-state" , id : "invalid-state-job" } ,
458+ { sourceIndex : 2 , reason : "invalid-trigger" , id : "invalid-trigger-job" } ,
459+ ] ) ;
460+ expect ( fs . existsSync ( storePath ) ) . toBe ( false ) ;
461+ expect ( fs . existsSync ( `${ storePath } .migrated` ) ) . toBe ( true ) ;
462+ } finally {
463+ await instance . cleanup ( ) ;
464+ }
485465 } , 45_000 ) ;
486466
487467 it ( "repairs the stable upgrade config and additive state schema before readiness" , async ( ) => {
0 commit comments