@@ -4,7 +4,7 @@ import type { OpenClawConfig } from "../config/types.openclaw.js";
44import { runDoctorHealthRepairs } from "./doctor-repair-flow.js" ;
55import { normalizeHealthCheck } from "./health-check-adapter.js" ;
66import type { RunnableHealthCheck , SplitHealthCheckInput } from "./health-check-runner-types.js" ;
7- import type { HealthCheck , HealthRepairContext } from "./health-checks.js" ;
7+ import type { HealthCheck , HealthFinding , HealthRepairContext } from "./health-checks.js" ;
88
99function ctx ( cfg : OpenClawConfig ) : HealthRepairContext {
1010 return {
@@ -18,6 +18,34 @@ function ctx(cfg: OpenClawConfig): HealthRepairContext {
1818 } ;
1919}
2020
21+ function warningFinding ( checkId : string ) : HealthFinding {
22+ return {
23+ checkId,
24+ severity : "warning" ,
25+ message : `Unresolved finding from ${ checkId } .` ,
26+ path : checkId ,
27+ } ;
28+ }
29+
30+ function successfullyRepairedCheck ( ) : HealthCheck {
31+ return normalizeHealthCheck ( {
32+ id : "test/repaired-first" ,
33+ kind : "core" ,
34+ description : "repairs before the unresolved check" ,
35+ async detect ( checkContext ) {
36+ return checkContext . cfg . gateway ?. mode === "local"
37+ ? [ ]
38+ : [ warningFinding ( "test/repaired-first" ) ] ;
39+ } ,
40+ async repair ( checkContext ) {
41+ return {
42+ config : { ...checkContext . cfg , gateway : { ...checkContext . cfg . gateway , mode : "local" } } ,
43+ changes : [ "Set gateway.mode to local." ] ,
44+ } ;
45+ } ,
46+ } ) ;
47+ }
48+
2149describe ( "runDoctorHealthRepairs" , ( ) => {
2250 it ( "repairs single-run checks and validates through lint mode" , async ( ) => {
2351 const runModes : string [ ] = [ ] ;
@@ -114,7 +142,7 @@ describe("runDoctorHealthRepairs", () => {
114142 } ) ) . not . toMatchTypeOf < SplitRepair > ( ) ;
115143 } ) ;
116144
117- it ( "leaves non-repairable checks for legacy doctor behavior " , async ( ) => {
145+ it ( "retains non-repairable findings for the legacy doctor owner " , async ( ) => {
118146 const checks : HealthCheck [ ] = [
119147 normalizeHealthCheck ( {
120148 id : "test/legacy-only" ,
@@ -136,7 +164,7 @@ describe("runDoctorHealthRepairs", () => {
136164
137165 expect ( result . config ) . toEqual ( { } ) ;
138166 expect ( result . findings ) . toHaveLength ( 1 ) ;
139- expect ( result . remainingFindings ) . toEqual ( [ ] ) ;
167+ expect ( result . remainingFindings ) . toEqual ( result . findings ) ;
140168 expect ( result . changes ) . toEqual ( [ ] ) ;
141169 expect ( result . checksRepaired ) . toBe ( 0 ) ;
142170 expect ( result . checksValidated ) . toBe ( 0 ) ;
@@ -173,6 +201,7 @@ describe("runDoctorHealthRepairs", () => {
173201 } ,
174202 ] ) ;
175203 expect ( result . warnings ) . toEqual ( [ "test/repair-throws repair failed: repair exploded" ] ) ;
204+ expect ( result . remainingFindings ) . toEqual ( result . findings ) ;
176205 expect ( result . checksRepaired ) . toBe ( 0 ) ;
177206 expect ( result . checksValidated ) . toBe ( 0 ) ;
178207 } ) ;
@@ -285,11 +314,90 @@ describe("runDoctorHealthRepairs", () => {
285314 expect ( validationCalls ) . toBe ( 1 ) ;
286315 expect ( result . checksRepaired ) . toBe ( 0 ) ;
287316 expect ( result . checksValidated ) . toBe ( 0 ) ;
288- expect ( result . remainingFindings ) . toEqual ( [ ] ) ;
317+ expect ( result . remainingFindings ) . toEqual ( result . findings ) ;
289318 expect ( result . changes ) . toEqual ( [ "Review required before changing gateway.mode." ] ) ;
290319 expect ( result . warnings ) . toEqual ( [ "test/skipped repair skipped: manual confirmation required" ] ) ;
291320 } ) ;
292321
322+ it . each ( [ "skipped" , "failed" , "throws" , "unavailable" , "validation-failed" ] as const ) (
323+ "preserves unresolved split findings after a successful sibling repair (%s)" ,
324+ async ( outcome ) => {
325+ const unresolvedId = `test/split-${ outcome } ` ;
326+ const unresolvedCheck = normalizeHealthCheck ( {
327+ id : unresolvedId ,
328+ kind : "core" ,
329+ description : "unresolved split check" ,
330+ async detect ( _checkContext , scope ) {
331+ if ( outcome === "validation-failed" && scope !== undefined ) {
332+ throw new Error ( "validation unavailable" ) ;
333+ }
334+ return [ warningFinding ( unresolvedId ) ] ;
335+ } ,
336+ ...( outcome === "unavailable"
337+ ? { }
338+ : {
339+ async repair ( ) {
340+ if ( outcome === "throws" ) {
341+ throw new Error ( "repair unavailable" ) ;
342+ }
343+ if ( outcome === "skipped" || outcome === "failed" ) {
344+ return { status : outcome , reason : "manual repair required" , changes : [ ] } ;
345+ }
346+ return { changes : [ "Attempted unresolved repair." ] } ;
347+ } ,
348+ } ) ,
349+ } ) ;
350+
351+ const result = await runDoctorHealthRepairs ( ctx ( { } ) , {
352+ checks : [ successfullyRepairedCheck ( ) , unresolvedCheck ] ,
353+ } ) ;
354+
355+ expect ( result . config . gateway ?. mode ) . toBe ( "local" ) ;
356+ expect ( result . findings . map ( ( finding ) => finding . checkId ) ) . toEqual ( [
357+ "test/repaired-first" ,
358+ unresolvedId ,
359+ ] ) ;
360+ expect ( result . remainingFindings ) . toEqual ( [ warningFinding ( unresolvedId ) ] ) ;
361+ expect ( result . checksRun ) . toBe ( 2 ) ;
362+ expect ( result . checksRepaired ) . toBe ( outcome === "validation-failed" ? 2 : 1 ) ;
363+ expect ( result . checksValidated ) . toBe ( 1 ) ;
364+ } ,
365+ ) ;
366+
367+ it . each ( [ "skipped" , "failed" , "unavailable" , "validation-failed" ] as const ) (
368+ "preserves unresolved runnable findings after a successful split sibling repair (%s)" ,
369+ async ( outcome ) => {
370+ const unresolvedId = `test/runnable-${ outcome } ` ;
371+ const runnable : RunnableHealthCheck = {
372+ id : unresolvedId ,
373+ kind : "core" ,
374+ description : "unresolved runnable check" ,
375+ async run ( checkContext ) {
376+ if ( checkContext . mode === "lint" ) {
377+ throw new Error ( "validation unavailable" ) ;
378+ }
379+ const findings = [ warningFinding ( unresolvedId ) ] ;
380+ if ( outcome === "skipped" || outcome === "failed" ) {
381+ return { status : outcome , reason : "manual repair required" , findings } ;
382+ }
383+ return outcome === "validation-failed"
384+ ? { findings, changes : [ "Attempted unresolved repair." ] }
385+ : { findings } ;
386+ } ,
387+ } ;
388+
389+ const result = await runDoctorHealthRepairs ( ctx ( { } ) , {
390+ checks : [ successfullyRepairedCheck ( ) , normalizeHealthCheck ( runnable ) ] ,
391+ } ) ;
392+
393+ expect ( result . config . gateway ?. mode ) . toBe ( "local" ) ;
394+ expect ( result . remainingFindings ) . toEqual ( [ warningFinding ( unresolvedId ) ] ) ;
395+ expect ( result . checksRun ) . toBe ( 2 ) ;
396+ expect ( result . checksRepaired ) . toBe ( outcome === "validation-failed" ? 2 : 1 ) ;
397+ expect ( result . checksValidated ) . toBe ( 1 ) ;
398+ } ,
399+ ) ;
400+
293401 it ( "supports dry-run repairs without applying returned config or validating" , async ( ) => {
294402 const repairContexts : HealthRepairContext [ ] = [ ] ;
295403 let detectCalls = 0 ;
0 commit comments