@@ -223,7 +223,7 @@ describe("Anthropic Agent SDK runtime ownership", () => {
223223 expect ( sideQuestion ) . not . toHaveProperty ( "execute" ) ;
224224 } ) ;
225225
226- it ( "delivers a selected credential only through descriptor 3 and zeroes its delivered buffer " , async ( ) => {
226+ it ( "owns the selected- credential process tree while keeping its descriptor private and zeroed " , async ( ) => {
227227 const backend = buildAnthropicCliBackend ( ) ;
228228 const token = "selected-private-descriptor-fixture" ;
229229 const prepared = ( await backend . prepareExecution ?.( {
@@ -256,9 +256,12 @@ describe("Anthropic Agent SDK runtime ownership", () => {
256256 "-e" ,
257257 [
258258 'const data = require("node:fs").readFileSync(3);' ,
259+ 'require("node:fs").writeSync(2, Buffer.alloc(1024 * 1024));' ,
259260 'const digest = require("node:crypto").createHash("sha256").update(data).digest("hex");' ,
260- "process.stdout.write(JSON.stringify({fd: Number(process.env.CLAUDE_CODE_OAUTH_TOKEN_FILE_DESCRIPTOR), digest}));" ,
261+ 'const descendant = require("node:child_process").spawn(process.execPath, ["-e", "setInterval(() => {}, 1000)"], {stdio: "ignore"});' ,
262+ "process.stdout.write(JSON.stringify({fd: Number(process.env.CLAUDE_CODE_OAUTH_TOKEN_FILE_DESCRIPTOR), digest, descendantPid: descendant.pid}));" ,
261263 "data.fill(0);" ,
264+ "setInterval(() => {}, 1000);" ,
262265 ] . join ( "" ) ,
263266 ] ;
264267 const env = { PATH : process . env . PATH , ...prepared . env } ;
@@ -275,17 +278,30 @@ describe("Anthropic Agent SDK runtime ownership", () => {
275278 let stdout = "" ;
276279 child . stdout . on ( "data" , ( chunk : Buffer | string ) => {
277280 stdout += chunk . toString ( ) ;
281+ child . kill ( "SIGTERM" ) ;
278282 } ) ;
279283 child . once ( "error" , reject ) ;
280- child . once ( "exit" , ( code ) => {
281- if ( code === 0 ) {
284+ child . once ( "exit" , ( code , signal ) => {
285+ if ( signal === "SIGTERM" || ( process . platform === "win32" && code !== null ) ) {
282286 resolve ( stdout ) ;
283287 } else {
284288 reject ( new Error ( `Credential descriptor proof exited ${ String ( code ) } .` ) ) ;
285289 }
286290 } ) ;
287291 } ) ;
288- descriptorOutput = JSON . parse ( output ) as { fd : number ; digest : string } ;
292+ const { descendantPid, ...descriptor } = JSON . parse ( output ) as {
293+ fd : number ;
294+ digest : string ;
295+ descendantPid : number ;
296+ } ;
297+ descriptorOutput = descriptor ;
298+ try {
299+ await vi . waitFor ( ( ) => expect ( ( ) => process . kill ( descendantPid , 0 ) ) . toThrow ( ) ) ;
300+ } finally {
301+ try {
302+ process . kill ( descendantPid , "SIGKILL" ) ;
303+ } catch { }
304+ }
289305 } ) ;
290306
291307 const events : Record < string , unknown > [ ] = [ ] ;
@@ -310,10 +326,7 @@ describe("Anthropic Agent SDK runtime ownership", () => {
310326 [
311327 {
312328 name : "denies" ,
313- decision : {
314- behavior : "deny" as const ,
315- message : "OpenClaw denied restricted native Bash execution." ,
316- } ,
329+ decision : { behavior : "deny" as const , message : "OpenClaw denied restricted Bash." } ,
317330 } ,
318331 {
319332 name : "allows" ,
@@ -331,10 +344,7 @@ describe("Anthropic Agent SDK runtime ownership", () => {
331344 "$name restricted native Bash through the prepared SDK approval owner" ,
332345 async ( { credential, decision } ) => {
333346 const backend = buildAnthropicCliBackend ( ) ;
334- const toolAvailability = {
335- native : [ "Bash" ] ,
336- openClaw : [ "message" ] ,
337- } ;
347+ const toolAvailability = { native : [ "Bash" ] , openClaw : [ "message" ] } ;
338348 const prepareContext = {
339349 workspaceDir : "/tmp/openclaw-workspace" ,
340350 provider : "claude-cli" ,
@@ -371,7 +381,7 @@ describe("Anthropic Agent SDK runtime ownership", () => {
371381 tool_input : input ,
372382 tool_use_id : "restricted-native-bash" ,
373383 } ,
374- "restricted-native-bash" ,
384+ undefined ,
375385 { signal } ,
376386 ) ;
377387 callbackDecision = await sdkNativeTool ( options ) ( "Bash" , input , {
@@ -754,7 +764,9 @@ describe("Anthropic Agent SDK runtime ownership", () => {
754764 "--allowedTools" ,
755765 "mcp__openclaw__message" ,
756766 "--disallowedTools" ,
757- "Bash,Edit,Write" ,
767+ "Bash" ,
768+ "Edit" ,
769+ "Write" ,
758770 ] ,
759771 toolAvailability : {
760772 native : [ ] ,
@@ -783,13 +795,20 @@ describe("Anthropic Agent SDK runtime ownership", () => {
783795 ) . not . toContain ( context . env . OPENCLAW_MCP_TOKEN ) ;
784796 } ) ;
785797
786- it ( "preserves managed skill plugins without letting isolated plugins discover MCP servers " , async ( ) => {
798+ it ( "preserves variadic directories, tools, and managed plugin MCP isolation " , async ( ) => {
787799 useSdkMessages ( ) ;
788800
789801 await collect (
790802 createContext ( {
791803 args : [
792804 "-p" ,
805+ "--add-dir" ,
806+ "/tmp/a" ,
807+ "/tmp/b" ,
808+ "--add-dir=/tmp/c" ,
809+ "--tools" ,
810+ "Read" ,
811+ "Grep" ,
793812 "--plugin-dir" ,
794813 "/tmp/openclaw-native-skills" ,
795814 "--plugin-dir-no-mcp" ,
@@ -802,6 +821,8 @@ describe("Anthropic Agent SDK runtime ownership", () => {
802821 { type : "local" , path : "/tmp/openclaw-native-skills" } ,
803822 { type : "local" , path : "/tmp/openclaw-isolated-skills" , skipMcpDiscovery : true } ,
804823 ] ) ;
824+ expect ( sdkOptions ( ) . additionalDirectories ) . toEqual ( [ "/tmp/a" , "/tmp/b" , "/tmp/c" ] ) ;
825+ expect ( sdkOptions ( ) . tools ) . toEqual ( [ "Read" , "Grep" ] ) ;
805826 } ) ;
806827
807828 it . each ( [
@@ -825,7 +846,7 @@ describe("Anthropic Agent SDK runtime ownership", () => {
825846
826847 await collect (
827848 createContext ( {
828- args : [ "-p" , "--allowedTools" , "Bash, mcp__openclaw__*, Edit" ] ,
849+ args : [ "-p" , "--allowedTools" , "Bash" , " mcp__openclaw__*" , " Edit"] ,
829850 toolAvailability : {
830851 native : [ ] ,
831852 openClaw : [ "message" , "memory_search" ] ,
@@ -914,37 +935,6 @@ describe("Anthropic Agent SDK runtime ownership", () => {
914935 } ) ;
915936 } ) ;
916937
917- it ( "projects an approved native pre-tool action with the exact host-authorized input" , async ( ) => {
918- const updatedInput = { command : "printf SDK_TOOL_OK" } ;
919- const requestToolPermission = vi . fn ( async ( ) => ( { behavior : "allow" as const , updatedInput } ) ) ;
920- let decision : unknown ;
921- useSdkMessages ( [ SUCCESS_RESULT ] , async ( options ) => {
922- decision = await sdkPreToolUse ( options ) (
923- {
924- hook_event_name : "PreToolUse" ,
925- tool_name : "Bash" ,
926- tool_input : { command : "printf original" } ,
927- tool_use_id : "approved-native-tool" ,
928- } ,
929- undefined ,
930- { signal : new AbortController ( ) . signal } ,
931- ) ;
932- } ) ;
933-
934- await collect ( createContext ( { requestToolPermission } ) ) ;
935-
936- expect ( decision ) . toEqual ( {
937- hookSpecificOutput : {
938- hookEventName : "PreToolUse" ,
939- permissionDecision : "allow" ,
940- updatedInput,
941- } ,
942- } ) ;
943- expect ( requestToolPermission ) . toHaveBeenCalledWith (
944- expect . objectContaining ( { toolCallId : "approved-native-tool" } ) ,
945- ) ;
946- } ) ;
947-
948938 it ( "keeps bypass-shaped backend arguments behind the host permission callback" , async ( ) => {
949939 const requestToolPermission = vi . fn ( async ( ) => ( {
950940 behavior : "deny" as const ,
0 commit comments