Skip to content

Commit 507ea8a

Browse files
committed
Refactor e2e test fixture creation
1 parent 134f753 commit 507ea8a

4 files changed

Lines changed: 8 additions & 12 deletions

File tree

src/__tests__/CodexACPAgent/e2e/acp-e2e-file-approval.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import fs from "node:fs";
22
import path from "node:path";
33
import {afterEach, beforeEach, expect, it} from "vitest";
4+
import {AgentMode} from "../../../AgentMode";
45
import {ApprovalOptionId} from "../../../ApprovalOptionId";
56
import {
7+
createAuthenticatedFixture,
68
createPermissionResponder,
7-
createReadOnlyFixture,
89
describeE2E,
910
type SpawnedAgentFixture,
1011
} from "./acp-e2e-test-utils";
@@ -17,7 +18,7 @@ describeE2E("E2E file approval tests", () => {
1718
let sessionId: string;
1819

1920
beforeEach(async () => {
20-
fixture = await createReadOnlyFixture();
21+
fixture = await createAuthenticatedFixture(AgentMode.ReadOnly);
2122
sessionId = (await fixture.createSession()).sessionId;
2223
});
2324

src/__tests__/CodexACPAgent/e2e/acp-e2e-shell-approval.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import fs from "node:fs";
22
import path from "node:path";
33
import {afterEach, beforeEach, expect, it, vi} from "vitest";
4+
import {AgentMode} from "../../../AgentMode";
45
import {ApprovalOptionId} from "../../../ApprovalOptionId";
56
import {
67
createAuthenticatedFixture,
78
createPermissionResponse,
89
createPermissionResponder,
9-
createReadOnlyFixture,
1010
describeE2E,
1111
expectEndTurn,
1212
type SpawnedAgentFixture,
@@ -21,7 +21,7 @@ describeE2E("E2E shell approval tests", () => {
2121
let sessionId: string;
2222

2323
beforeEach(async () => {
24-
fixture = await createReadOnlyFixture();
24+
fixture = await createAuthenticatedFixture(AgentMode.ReadOnly);
2525
sessionId = (await fixture.createSession()).sessionId;
2626
});
2727

src/__tests__/CodexACPAgent/e2e/acp-e2e-test-utils.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ export function expectEndTurn(response: acp.PromptResponse): void {
2626
expect(response.stopReason).toBe("end_turn");
2727
}
2828

29-
export async function createAuthenticatedFixture(extraEnv?: NodeJS.ProcessEnv): Promise<SpawnedAgentFixture> {
29+
export async function createAuthenticatedFixture(initialMode?: AgentMode): Promise<SpawnedAgentFixture> {
3030
const apiKey = requireLiveApiKey();
31+
const extraEnv = initialMode ? {INITIAL_AGENT_MODE: initialMode.id} : undefined;
3132
return await createSpawnedFixture(async (connection, authMethods) => {
3233
if (!authMethods.some((method) => method.id === "api-key")) {
3334
throw new Error("API key authentication is not available.");
@@ -49,10 +50,6 @@ export async function createAuthenticatedFixture(extraEnv?: NodeJS.ProcessEnv):
4950
}, extraEnv);
5051
}
5152

52-
export async function createReadOnlyFixture(): Promise<SpawnedAgentFixture> {
53-
return await createAuthenticatedFixture({INITIAL_AGENT_MODE: AgentMode.ReadOnly.id});
54-
}
55-
5653
export async function createGatewayFixture(
5754
baseUrl: string,
5855
headers: Record<string, string>,

src/__tests__/CodexACPAgent/e2e/acp-e2e.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ describeE2E("E2E tests", () => {
7979

8080
it("respects INITIAL_AGENT_MODE when seeding the initial session mode", async () => {
8181
const initialMode = AgentMode.ReadOnly;
82-
fixture = await createAuthenticatedFixture({
83-
INITIAL_AGENT_MODE: initialMode.id,
84-
});
82+
fixture = await createAuthenticatedFixture(initialMode);
8583
const session = await fixture.createSession();
8684

8785
expect(session.modes?.currentModeId).toBe(initialMode.id);

0 commit comments

Comments
 (0)