-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathacp-e2e-file-approval.test.ts
More file actions
57 lines (50 loc) · 2.14 KB
/
Copy pathacp-e2e-file-approval.test.ts
File metadata and controls
57 lines (50 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import fs from "node:fs";
import path from "node:path";
import {afterEach, beforeEach, expect, it} from "vitest";
import {AgentMode} from "../../../AgentMode";
import {ApprovalOptionId} from "../../../ApprovalOptionId";
import {
createAuthenticatedFixture,
createPermissionResponder,
describeE2E,
type SpawnedAgentFixture,
} from "./acp-e2e-test-utils";
const FILE_NAME = "approval-file.txt";
const FILE_CONTENT = "file approval e2e";
describeE2E("E2E file approval tests", () => {
let fixture: SpawnedAgentFixture;
let sessionId: string;
beforeEach(async () => {
fixture = await createAuthenticatedFixture(AgentMode.ReadOnly);
sessionId = (await fixture.createSession()).sessionId;
});
afterEach(async () => {
await fixture.dispose();
});
async function expectFileApproval(
optionId: ApprovalOptionId,
expectedStopReason: "end_turn" | "cancelled",
): Promise<void> {
fixture.setPermissionResponder(createPermissionResponder("edit", optionId));
const response = await fixture.connection.prompt({
sessionId,
prompt: [{
type: "text",
text: `Create ${FILE_NAME} by editing files directly. Content must be exactly: ${FILE_CONTENT}. Do not use shell commands, and stop if the edit is rejected.`,
}],
});
expect(response.stopReason).toBe(expectedStopReason);
expect(fixture.readPermissionRequests(sessionId, "edit").length).toBe(1);
expect(fixture.readPermissionRequests(sessionId, "execute").length).toBe(0);
}
it("applies approved file edits", async () => {
await expectFileApproval(ApprovalOptionId.AllowOnce, "end_turn");
const filePath = path.join(fixture.workspaceDir, FILE_NAME);
expect(fs.existsSync(filePath)).toBe(true);
expect(fs.readFileSync(filePath, "utf8").trim()).toBe(FILE_CONTENT);
});
it("does not apply rejected file edits", async () => {
await expectFileApproval(ApprovalOptionId.RejectOnce, "cancelled");
expect(fs.existsSync(path.join(fixture.workspaceDir, FILE_NAME))).toBe(false);
});
});