55import { writeFile , mkdir } from "fs/promises" ;
66import { join } from "path" ;
77import { describe , expect , it } from "vitest" ;
8+ import { approveAll } from "../../src/index.js" ;
89import { createSdkTestContext } from "./harness/sdkTestContext" ;
910
1011describe ( "Built-in Tools" , async ( ) => {
1112 const { copilotClient : client , workDir } = await createSdkTestContext ( ) ;
1213
1314 describe ( "bash" , ( ) => {
1415 it ( "should capture exit code in output" , async ( ) => {
15- const session = await client . createSession ( ) ;
16+ const session = await client . createSession ( { onPermissionRequest : approveAll } ) ;
1617 const msg = await session . sendAndWait ( {
1718 prompt : "Run 'echo hello && echo world'. Tell me the exact output." ,
1819 } ) ;
@@ -21,7 +22,7 @@ describe("Built-in Tools", async () => {
2122 } ) ;
2223
2324 it ( "should capture stderr output" , async ( ) => {
24- const session = await client . createSession ( ) ;
25+ const session = await client . createSession ( { onPermissionRequest : approveAll } ) ;
2526 const msg = await session . sendAndWait ( {
2627 prompt : "Run 'echo error_msg >&2; echo ok' and tell me what stderr said. Reply with just the stderr content." ,
2728 } ) ;
@@ -32,7 +33,7 @@ describe("Built-in Tools", async () => {
3233 describe ( "view" , ( ) => {
3334 it ( "should read file with line range" , async ( ) => {
3435 await writeFile ( join ( workDir , "lines.txt" ) , "line1\nline2\nline3\nline4\nline5\n" ) ;
35- const session = await client . createSession ( ) ;
36+ const session = await client . createSession ( { onPermissionRequest : approveAll } ) ;
3637 const msg = await session . sendAndWait ( {
3738 prompt : "Read lines 2 through 4 of the file 'lines.txt' in this directory. Tell me what those lines contain." ,
3839 } ) ;
@@ -41,7 +42,7 @@ describe("Built-in Tools", async () => {
4142 } ) ;
4243
4344 it ( "should handle nonexistent file gracefully" , async ( ) => {
44- const session = await client . createSession ( ) ;
45+ const session = await client . createSession ( { onPermissionRequest : approveAll } ) ;
4546 const msg = await session . sendAndWait ( {
4647 prompt : "Try to read the file 'does_not_exist.txt'. If it doesn't exist, say 'FILE_NOT_FOUND'." ,
4748 } ) ;
@@ -54,7 +55,7 @@ describe("Built-in Tools", async () => {
5455 describe ( "edit" , ( ) => {
5556 it ( "should edit a file successfully" , async ( ) => {
5657 await writeFile ( join ( workDir , "edit_me.txt" ) , "Hello World\nGoodbye World\n" ) ;
57- const session = await client . createSession ( ) ;
58+ const session = await client . createSession ( { onPermissionRequest : approveAll } ) ;
5859 const msg = await session . sendAndWait ( {
5960 prompt : "Edit the file 'edit_me.txt': replace 'Hello World' with 'Hi Universe'. Then read it back and tell me its contents." ,
6061 } ) ;
@@ -64,7 +65,7 @@ describe("Built-in Tools", async () => {
6465
6566 describe ( "create_file" , ( ) => {
6667 it ( "should create a new file" , async ( ) => {
67- const session = await client . createSession ( ) ;
68+ const session = await client . createSession ( { onPermissionRequest : approveAll } ) ;
6869 const msg = await session . sendAndWait ( {
6970 prompt : "Create a file called 'new_file.txt' with the content 'Created by test'. Then read it back to confirm." ,
7071 } ) ;
@@ -75,7 +76,7 @@ describe("Built-in Tools", async () => {
7576 describe ( "grep" , ( ) => {
7677 it ( "should search for patterns in files" , async ( ) => {
7778 await writeFile ( join ( workDir , "data.txt" ) , "apple\nbanana\napricot\ncherry\n" ) ;
78- const session = await client . createSession ( ) ;
79+ const session = await client . createSession ( { onPermissionRequest : approveAll } ) ;
7980 const msg = await session . sendAndWait ( {
8081 prompt : "Search for lines starting with 'ap' in the file 'data.txt'. Tell me which lines matched." ,
8182 } ) ;
@@ -90,7 +91,7 @@ describe("Built-in Tools", async () => {
9091 await writeFile ( join ( workDir , "src" , "app.ts" ) , "export const app = 1;" ) ;
9192 await writeFile ( join ( workDir , "src" , "index.ts" ) , "export const index = 1;" ) ;
9293 await writeFile ( join ( workDir , "README.md" ) , "# Readme" ) ;
93- const session = await client . createSession ( ) ;
94+ const session = await client . createSession ( { onPermissionRequest : approveAll } ) ;
9495 const msg = await session . sendAndWait ( {
9596 prompt : "Find all .ts files in this directory (recursively). List the filenames you found." ,
9697 } ) ;
0 commit comments