99 createDoctorRuntime ,
1010 mockDoctorConfigSnapshot ,
1111 readConfigFileSnapshot ,
12+ resolveOpenClawPackageRoot ,
13+ runCommandWithTimeout ,
1214 runGatewayUpdate ,
1315} from "./doctor.e2e-harness.js" ;
1416
@@ -21,7 +23,33 @@ describe("doctor database schema preflight", () => {
2123 vi . clearAllMocks ( ) ;
2224 } ) ;
2325
24- it ( "refuses a newer state schema before update and config repair flows" , async ( ) => {
26+ it ( "lets a successful interactive update replace the stale doctor" , async ( ) => {
27+ writeStateSchemaVersion ( OPENCLAW_STATE_SCHEMA_VERSION + 1 ) ;
28+ mockDoctorConfigSnapshot ( ) ;
29+ mockInteractiveGitUpdate ( "ok" ) ;
30+
31+ await expect ( doctorCommand ( createDoctorRuntime ( ) ) ) . resolves . toBeUndefined ( ) ;
32+
33+ expect ( runGatewayUpdate ) . toHaveBeenCalledOnce ( ) ;
34+ expect ( autoMigrateLegacyStateDir ) . not . toHaveBeenCalled ( ) ;
35+ expect ( readConfigFileSnapshot ) . not . toHaveBeenCalled ( ) ;
36+ } ) ;
37+
38+ it ( "refuses after an interactive update does not handle doctor" , async ( ) => {
39+ writeStateSchemaVersion ( OPENCLAW_STATE_SCHEMA_VERSION + 1 ) ;
40+ mockDoctorConfigSnapshot ( ) ;
41+ mockInteractiveGitUpdate ( "skipped" ) ;
42+
43+ await expect ( doctorCommand ( createDoctorRuntime ( ) ) ) . rejects . toThrow (
44+ / D o c t o r r e f u s e d t o c o n t i n u e .* d a t a b a s e s c h e m a .* n e w e r t h a n t h i s b u i l d / iu,
45+ ) ;
46+
47+ expect ( runGatewayUpdate ) . toHaveBeenCalledOnce ( ) ;
48+ expect ( autoMigrateLegacyStateDir ) . not . toHaveBeenCalled ( ) ;
49+ expect ( readConfigFileSnapshot ) . not . toHaveBeenCalled ( ) ;
50+ } ) ;
51+
52+ it ( "refuses before config repair flows when updates are disabled" , async ( ) => {
2553 writeStateSchemaVersion ( OPENCLAW_STATE_SCHEMA_VERSION + 1 ) ;
2654 mockDoctorConfigSnapshot ( ) ;
2755
@@ -35,6 +63,25 @@ describe("doctor database schema preflight", () => {
3563 } ) ;
3664} ) ;
3765
66+ function mockInteractiveGitUpdate ( status : "ok" | "skipped" ) : void {
67+ delete process . env . OPENCLAW_UPDATE_IN_PROGRESS ;
68+ resolveOpenClawPackageRoot . mockResolvedValue ( "/repo" ) ;
69+ runCommandWithTimeout . mockResolvedValue ( {
70+ stdout : "/repo\n" ,
71+ stderr : "" ,
72+ code : 0 ,
73+ signal : null ,
74+ killed : false ,
75+ } ) ;
76+ runGatewayUpdate . mockResolvedValue ( {
77+ status,
78+ mode : "git" ,
79+ root : "/repo" ,
80+ steps : [ ] ,
81+ durationMs : 0 ,
82+ } ) ;
83+ }
84+
3885function writeStateSchemaVersion ( version : number ) : void {
3986 const statePath = resolveOpenClawStateSqlitePath ( process . env ) ;
4087 fs . mkdirSync ( path . dirname ( statePath ) , { recursive : true } ) ;
0 commit comments