Skip to content

Commit b69e845

Browse files
committed
feat: update permissions.test.ts and session.test.ts
1 parent 79bc1ed commit b69e845

2 files changed

Lines changed: 54 additions & 50 deletions

File tree

‎packages/core/src/tests/permissions.test.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ test("computeToolCallPermissions temporarily upgrades allowed forced scopes to a
302302

303303
test("computeToolCallPermissions allows read tool calls under skill scan paths", () => {
304304
const projectRoot = createTempDir("deepcode-permissions-skill-read-workspace-");
305-
const home = createTempDir("deepcode-permissions-skill-read-home-");
305+
const home = createTempDir("deepcode-permissions-skill-read-home-", process.cwd());
306306
const skillRoot = path.join(home, ".agents", "skills");
307307
const skillResourcePath = path.join(skillRoot, "pdf", "scripts", "extract.py");
308308
const outsidePath = path.join(home, "notes.txt");
@@ -342,7 +342,7 @@ test("computeToolCallPermissions allows read tool calls under skill scan paths",
342342

343343
test("UnderstandImage requires network and exempts only configured image directories from read scope", () => {
344344
const projectRoot = createTempDir("deepcode-permissions-image-workspace-");
345-
const home = createTempDir("deepcode-permissions-image-home-");
345+
const home = createTempDir("deepcode-permissions-image-home-", process.cwd());
346346
const sessionImages = path.join(home, ".deepcode", "projects", "project", "images", "session-1");
347347
const currentImage = path.join(sessionImages, "current.png");
348348
const projectImage = path.join(projectRoot, "project.png");
@@ -388,7 +388,7 @@ test("UnderstandImage requires network and exempts only configured image directo
388388

389389
test("ReadImage uses filesystem read permissions without network access", () => {
390390
const projectRoot = createTempDir("deepcode-permissions-read-image-workspace-");
391-
const home = createTempDir("deepcode-permissions-read-image-home-");
391+
const home = createTempDir("deepcode-permissions-read-image-home-", process.cwd());
392392
const projectImage = path.join(projectRoot, "project.png");
393393
const outsideImage = path.join(home, "outside.png");
394394
const plan = computeToolCallPermissions({
@@ -666,8 +666,8 @@ test("hasUserPermissionReplies detects permission reply payloads", () => {
666666
assert.equal(hasUserPermissionReplies({ alwaysAllows: ["network"] }), true);
667667
});
668668

669-
function createTempDir(prefix: string): string {
670-
const dir = fs.mkdtempSync(path.join(os.tmpdir(), prefix));
669+
function createTempDir(prefix: string, parentDir = os.tmpdir()): string {
670+
const dir = fs.mkdtempSync(path.join(parentDir, prefix));
671671
tempDirs.push(dir);
672672
return dir;
673673
}

‎packages/core/src/tests/session.test.ts‎

Lines changed: 49 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2628,56 +2628,60 @@ test("activateSession temporarily asks before allowed writes in Plan Mode", asyn
26282628
assert.deepEqual(assistant?.meta?.permissions, [{ toolCallId: "call-write", permission: "ask" }]);
26292629
});
26302630

2631-
test("activateSession does not force allowed temporary writes to ask in Plan Mode", async () => {
2632-
const workspace = createTempDir("deepcode-plan-tmp-permission-workspace-");
2633-
const home = createTempDir("deepcode-plan-tmp-permission-home-");
2634-
const targetPath = path.join("/tmp", `deepcode-plan-${crypto.randomUUID()}.txt`);
2635-
tempDirs.push(targetPath);
2636-
setHomeDir(home);
2631+
test(
2632+
"activateSession does not force allowed temporary writes to ask in Plan Mode",
2633+
{ skip: process.platform === "win32" },
2634+
async () => {
2635+
const workspace = createTempDir("deepcode-plan-tmp-permission-workspace-");
2636+
const home = createTempDir("deepcode-plan-tmp-permission-home-");
2637+
const targetPath = path.join("/tmp", `deepcode-plan-${crypto.randomUUID()}.txt`);
2638+
tempDirs.push(targetPath);
2639+
setHomeDir(home);
26372640

2638-
const manager = createPermissionSessionManager(
2639-
workspace,
2640-
[
2641-
{
2642-
choices: [
2643-
{
2644-
message: {
2645-
content: "",
2646-
tool_calls: [
2647-
{
2648-
id: "call-write-tmp",
2649-
type: "function",
2650-
function: {
2651-
name: "write",
2652-
arguments: JSON.stringify({ file_path: targetPath, content: "planned" }),
2641+
const manager = createPermissionSessionManager(
2642+
workspace,
2643+
[
2644+
{
2645+
choices: [
2646+
{
2647+
message: {
2648+
content: "",
2649+
tool_calls: [
2650+
{
2651+
id: "call-write-tmp",
2652+
type: "function",
2653+
function: {
2654+
name: "write",
2655+
arguments: JSON.stringify({ file_path: targetPath, content: "planned" }),
2656+
},
26532657
},
2654-
},
2655-
],
2658+
],
2659+
},
26562660
},
2657-
},
2658-
],
2659-
usage: { prompt_tokens: 1, completion_tokens: 1, total_tokens: 2 },
2660-
},
2661-
createChatResponse("done", { prompt_tokens: 1, completion_tokens: 1, total_tokens: 2 }),
2662-
],
2663-
{
2664-
allow: ["write-in-tmp"],
2665-
deny: [],
2666-
ask: [],
2667-
defaultMode: "allowAll",
2668-
}
2669-
);
2661+
],
2662+
usage: { prompt_tokens: 1, completion_tokens: 1, total_tokens: 2 },
2663+
},
2664+
createChatResponse("done", { prompt_tokens: 1, completion_tokens: 1, total_tokens: 2 }),
2665+
],
2666+
{
2667+
allow: ["write-in-tmp"],
2668+
deny: [],
2669+
ask: [],
2670+
defaultMode: "allowAll",
2671+
}
2672+
);
26702673

2671-
const sessionId = await manager.createSession({ text: "Plan this change", planMode: true });
2672-
const session = manager.getSession(sessionId);
2673-
const assistant = manager
2674-
.listSessionMessages(sessionId)
2675-
.find((message) => message.role === "assistant" && (message.messageParams as any)?.tool_calls);
2674+
const sessionId = await manager.createSession({ text: "Plan this change", planMode: true });
2675+
const session = manager.getSession(sessionId);
2676+
const assistant = manager
2677+
.listSessionMessages(sessionId)
2678+
.find((message) => message.role === "assistant" && (message.messageParams as any)?.tool_calls);
26762679

2677-
assert.equal(session?.status, "completed");
2678-
assert.deepEqual(assistant?.meta?.permissions, [{ toolCallId: "call-write-tmp", permission: "allow" }]);
2679-
assert.equal(fs.readFileSync(targetPath, "utf8"), "planned");
2680-
});
2680+
assert.equal(session?.status, "completed");
2681+
assert.deepEqual(assistant?.meta?.permissions, [{ toolCallId: "call-write-tmp", permission: "allow" }]);
2682+
assert.equal(fs.readFileSync(targetPath, "utf8"), "planned");
2683+
}
2684+
);
26812685

26822686
test("SessionManager preserves permission_denied status when sessions are reloaded", async () => {
26832687
const workspace = createTempDir("deepcode-permission-denied-workspace-");

0 commit comments

Comments
 (0)