1+ import { execFileSync } from "node:child_process" ;
12// Doctor UI tests cover control UI asset checks, repair hints, and filesystem diagnostics.
23import fs from "node:fs/promises" ;
34import os from "node:os" ;
@@ -88,12 +89,132 @@ describe("UI protocol freshness health mapping", () => {
8889 expect ( uiProtocolFreshnessIssueToRepairEffects ( issue ( { canBuild : false } ) ) ) . toEqual ( [ ] ) ;
8990 } ) ;
9091
92+ it ( "reports missing packaged UI assets without requiring unpublished protocol sources" , async ( ) => {
93+ const root = await createOpenClawRoot ( ) ;
94+ await fs . rm ( path . join ( root , "packages" ) , { recursive : true } ) ;
95+
96+ await expect ( detectUiProtocolFreshnessIssues ( { root } ) ) . resolves . toEqual ( [
97+ {
98+ kind : "missing-assets" ,
99+ root,
100+ uiIndexPath : path . join ( root , "dist/control-ui/index.html" ) ,
101+ canBuild : false ,
102+ } ,
103+ ] ) ;
104+ } ) ;
105+
106+ it ( "gives packaged installs an actionable recovery hint instead of a missing build command" , ( ) => {
107+ const finding = uiProtocolFreshnessIssueToHealthFinding ( issue ( { canBuild : false } ) ) ;
108+
109+ expect ( finding . message ) . not . toContain ( "pnpm ui:build" ) ;
110+ expect ( finding . fixHint ) . toContain ( "Reinstall OpenClaw" ) ;
111+ } ) ;
112+
113+ it ( "keeps healthy packaged UI assets quiet without probing unpublished protocol history" , async ( ) => {
114+ const root = await createOpenClawRoot ( ) ;
115+ await fs . rm ( path . join ( root , "packages" ) , { recursive : true } ) ;
116+ await touch ( path . join ( root , "dist/control-ui/index.html" ) , new Date ( "2026-01-02" ) ) ;
117+ let checkedHistory = false ;
118+
119+ await expect (
120+ detectUiProtocolFreshnessIssues ( {
121+ root,
122+ async collectChangesSinceBuild ( ) {
123+ checkedHistory = true ;
124+ return [ "abc123 unavailable packaged source" ] ;
125+ } ,
126+ } ) ,
127+ ) . resolves . toEqual ( [ ] ) ;
128+ expect ( checkedHistory ) . toBe ( false ) ;
129+ } ) ;
130+
131+ it . each ( [
132+ [ "a nested schema module" , "schema/sessions.ts" ] ,
133+ [ "the protocol package entrypoint" , "index.ts" ] ,
134+ ] ) ( "reports stale assets after changes to %s" , async ( _description , changedProtocolFile ) => {
135+ const root = await createOpenClawRoot ( ) ;
136+ const uiIndexPath = path . join ( root , "dist/control-ui/index.html" ) ;
137+ const schemaBarrelPath = path . join ( root , "packages/gateway-protocol/src/schema.ts" ) ;
138+ await touch ( schemaBarrelPath , new Date ( "2026-01-01T00:00:00.000Z" ) ) ;
139+ await touch ( uiIndexPath , new Date ( "2026-01-02T00:00:00.000Z" ) ) ;
140+ await touch ( path . join ( root , "ui/package.json" ) , new Date ( "2026-01-02T00:00:00.000Z" ) ) ;
141+ await touch (
142+ path . join ( root , "packages/gateway-protocol/src" , changedProtocolFile ) ,
143+ new Date ( "2026-01-03T00:00:00.000Z" ) ,
144+ ) ;
145+
146+ await expect (
147+ detectUiProtocolFreshnessIssues ( {
148+ root,
149+ async collectChangesSinceBuild ( ) {
150+ return [ `abc123 changed ${ changedProtocolFile } ` ] ;
151+ } ,
152+ } ) ,
153+ ) . resolves . toEqual ( [
154+ {
155+ kind : "stale-assets" ,
156+ root,
157+ uiIndexPath,
158+ canBuild : true ,
159+ changesSinceBuild : [ `abc123 changed ${ changedProtocolFile } ` ] ,
160+ } ,
161+ ] ) ;
162+ } ) ;
163+
164+ it ( "reads committed nested protocol changes from the real complete-package git pathspec" , async ( ) => {
165+ const root = await createOpenClawRoot ( ) ;
166+ const uiIndexPath = path . join ( root , "dist/control-ui/index.html" ) ;
167+ await touch ( path . join ( root , "packages/gateway-protocol/src/schema.ts" ) , new Date ( "2026-01-01" ) ) ;
168+ await touch ( uiIndexPath , new Date ( "2026-01-02" ) ) ;
169+ await touch ( path . join ( root , "ui/package.json" ) , new Date ( "2026-01-02" ) ) ;
170+ await touch (
171+ path . join ( root , "packages/gateway-protocol/src/schema/sessions.ts" ) ,
172+ new Date ( "2026-01-03" ) ,
173+ ) ;
174+ execFileSync ( "git" , [ "init" , "--quiet" , root ] ) ;
175+ execFileSync ( "git" , [ "-C" , root , "add" , "packages/gateway-protocol/src/schema/sessions.ts" ] ) ;
176+ execFileSync (
177+ "git" ,
178+ [
179+ "-C" ,
180+ root ,
181+ "-c" ,
182+ "core.hooksPath=/dev/null" ,
183+ "-c" ,
184+ "commit.gpgSign=false" ,
185+ "-c" ,
186+ "user.name=Doctor UI Test" ,
187+ "-c" ,
188+ 189+ "commit" ,
190+ "--quiet" ,
191+ "-m" ,
192+ "update nested protocol schema" ,
193+ ] ,
194+ {
195+ env : {
196+ ...process . env ,
197+ GIT_AUTHOR_DATE : "2026-01-03T00:00:00Z" ,
198+ GIT_COMMITTER_DATE : "2026-01-03T00:00:00Z" ,
199+ } ,
200+ } ,
201+ ) ;
202+
203+ await expect ( detectUiProtocolFreshnessIssues ( { root } ) ) . resolves . toEqual ( [
204+ expect . objectContaining ( {
205+ kind : "stale-assets" ,
206+ changesSinceBuild : [ expect . stringMatching ( / u p d a t e n e s t e d p r o t o c o l s c h e m a $ / ) ] ,
207+ } ) ,
208+ ] ) ;
209+ } ) ;
210+
91211 it ( "does not report stale assets when git finds no schema changes" , async ( ) => {
92212 const root = await createOpenClawRoot ( ) ;
93213 const schemaPath = path . join ( root , "packages/gateway-protocol/src/schema.ts" ) ;
94214 const uiIndexPath = path . join ( root , "dist/control-ui/index.html" ) ;
95215 await touch ( uiIndexPath , new Date ( "2026-01-01T00:00:00.000Z" ) ) ;
96216 await touch ( schemaPath , new Date ( "2026-01-02T00:00:00.000Z" ) ) ;
217+ await touch ( path . join ( root , "ui/package.json" ) , new Date ( "2026-01-01T00:00:00.000Z" ) ) ;
97218
98219 await expect (
99220 detectUiProtocolFreshnessIssues ( {
@@ -111,6 +232,7 @@ describe("UI protocol freshness health mapping", () => {
111232 const uiIndexPath = path . join ( root , "dist/control-ui/index.html" ) ;
112233 await touch ( uiIndexPath , new Date ( "2026-01-01T00:00:00.000Z" ) ) ;
113234 await touch ( schemaPath , new Date ( "2026-01-02T00:00:00.000Z" ) ) ;
235+ await touch ( path . join ( root , "ui/package.json" ) , new Date ( "2026-01-01T00:00:00.000Z" ) ) ;
114236
115237 await expect (
116238 detectUiProtocolFreshnessIssues ( {
0 commit comments