11import fs from "node:fs/promises" ;
22import os from "node:os" ;
33import path from "node:path" ;
4- import { beforeEach , describe , expect , it , vi } from "vitest" ;
5- import { note } from "../terminal/note.js" ;
4+ import { describe , expect , it } from "vitest" ;
65import { withEnvAsync } from "../test-utils/env.js" ;
7- import { runDoctorConfigWithInput } from "./doctor-config-flow.test-utils.js" ;
8-
9- vi . mock ( "../terminal/note.js" , ( ) => ( {
10- note : vi . fn ( ) ,
11- } ) ) ;
12-
13- import { loadAndMaybeMigrateDoctorConfig } from "./doctor-config-flow .js" ;
6+ import {
7+ collectExecSafeBinCoverageWarnings ,
8+ collectExecSafeBinTrustedDirHintWarnings ,
9+ maybeRepairExecSafeBinProfiles ,
10+ scanExecSafeBinCoverage ,
11+ scanExecSafeBinTrustedDirHints ,
12+ } from "./doctor/shared/exec-safe-bins .js" ;
1413
1514describe ( "doctor config flow safe bins" , ( ) => {
16- const noteSpy = vi . mocked ( note ) ;
17-
18- beforeEach ( ( ) => {
19- noteSpy . mockClear ( ) ;
20- } ) ;
21-
22- it ( "scaffolds missing custom safe-bin profiles on repair but skips interpreter bins" , async ( ) => {
23- const result = await runDoctorConfigWithInput ( {
24- repair : true ,
25- config : {
26- tools : {
27- exec : {
28- safeBins : [ "myfilter" , "python3" ] ,
29- } ,
15+ it ( "scaffolds missing custom safe-bin profiles on repair but skips interpreter bins" , ( ) => {
16+ const result = maybeRepairExecSafeBinProfiles ( {
17+ tools : {
18+ exec : {
19+ safeBins : [ "myfilter" , "python3" ] ,
3020 } ,
31- agents : {
32- list : [
33- {
34- id : "ops" ,
35- tools : {
36- exec : {
37- safeBins : [ "mytool" , "node" ] ,
38- } ,
21+ } ,
22+ agents : {
23+ list : [
24+ {
25+ id : "ops" ,
26+ tools : {
27+ exec : {
28+ safeBins : [ "mytool" , "node" ] ,
3929 } ,
4030 } ,
41- ] ,
42- } ,
31+ } ,
32+ ] ,
4333 } ,
44- run : loadAndMaybeMigrateDoctorConfig ,
4534 } ) ;
4635
47- const cfg = result . cfg as {
36+ const cfg = result . config as {
4837 tools ?: {
4938 exec ?: {
5039 safeBinProfiles ?: Record < string , object > ;
@@ -68,26 +57,22 @@ describe("doctor config flow safe bins", () => {
6857 expect ( ops ?. tools ?. exec ?. safeBinProfiles ?. node ) . toBeUndefined ( ) ;
6958 } ) ;
7059
71- it ( "warns when interpreter/custom safeBins entries are missing profiles in non-repair mode" , async ( ) => {
72- await runDoctorConfigWithInput ( {
73- config : {
60+ it ( "warns when interpreter/custom safeBins entries are missing profiles in non-repair mode" , ( ) => {
61+ const warnings = collectExecSafeBinCoverageWarnings ( {
62+ hits : scanExecSafeBinCoverage ( {
7463 tools : {
7564 exec : {
7665 safeBins : [ "python3" , "myfilter" ] ,
7766 } ,
7867 } ,
79- } ,
80- run : loadAndMaybeMigrateDoctorConfig ,
68+ } ) ,
69+ doctorFixCommand : "openclaw doctor --fix" ,
8170 } ) ;
8271
83- expect ( noteSpy ) . toHaveBeenCalledWith (
84- expect . stringContaining ( "tools.exec.safeBins includes interpreter/runtime 'python3'" ) ,
85- "Doctor warnings" ,
86- ) ;
87- expect ( noteSpy ) . toHaveBeenCalledWith (
88- expect . stringContaining ( "openclaw doctor --fix" ) ,
89- "Doctor warnings" ,
72+ expect ( warnings . join ( "\n" ) ) . toContain (
73+ "tools.exec.safeBins includes interpreter/runtime 'python3'" ,
9074 ) ;
75+ expect ( warnings . join ( "\n" ) ) . toContain ( "openclaw doctor --fix" ) ;
9176 } ) ;
9277
9378 it ( "hints safeBinTrustedDirs when safeBins resolve outside default trusted dirs" , async ( ) => {
@@ -104,8 +89,8 @@ describe("doctor config flow safe bins", () => {
10489 PATH : `${ dir } ${ path . delimiter } ${ process . env . PATH ?? "" } ` ,
10590 } ,
10691 async ( ) => {
107- await runDoctorConfigWithInput ( {
108- config : {
92+ const warnings = collectExecSafeBinTrustedDirHintWarnings (
93+ scanExecSafeBinTrustedDirHints ( {
10994 tools : {
11095 exec : {
11196 safeBins : [ "mydoctorbin" ] ,
@@ -114,19 +99,12 @@ describe("doctor config flow safe bins", () => {
11499 } ,
115100 } ,
116101 } ,
117- } ,
118- run : loadAndMaybeMigrateDoctorConfig ,
119- } ) ;
102+ } ) ,
103+ ) ;
104+ expect ( warnings . join ( "\n" ) ) . toContain ( "outside trusted safe-bin dirs" ) ;
105+ expect ( warnings . join ( "\n" ) ) . toContain ( "tools.exec.safeBinTrustedDirs" ) ;
120106 } ,
121107 ) ;
122- expect ( noteSpy ) . toHaveBeenCalledWith (
123- expect . stringContaining ( "outside trusted safe-bin dirs" ) ,
124- "Doctor warnings" ,
125- ) ;
126- expect ( noteSpy ) . toHaveBeenCalledWith (
127- expect . stringContaining ( "tools.exec.safeBinTrustedDirs" ) ,
128- "Doctor warnings" ,
129- ) ;
130108 } finally {
131109 await fs . rm ( dir , { recursive : true , force : true } ) . catch ( ( ) => undefined ) ;
132110 }
0 commit comments