Skip to content

Commit 20eb662

Browse files
steipetechelsealongayeshafayyaz-pixel
committed
test(acp): isolate configured binding regression coverage
Keep the real manager/lifecycle regression in a focused test file and narrow the adapter case union explicitly. Runtime behavior is unchanged. Co-authored-by: chelsealong <[email protected]> Co-authored-by: ayeshafayyaz-pixel <[email protected]>
1 parent 5c8f87f commit 20eb662

3 files changed

Lines changed: 100 additions & 84 deletions

File tree

‎extensions/acpx/src/runtime.test.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,7 +1751,8 @@ describe("AcpxRuntime fresh reset wrapper", () => {
17511751
expected: undefined,
17521752
errorCode: "ACP_BACKEND_UNSUPPORTED_CONTROL",
17531753
})),
1754-
])("$name", async ({ key, value, expected, errorCode }) => {
1754+
])("$name", async (testCase) => {
1755+
const { key, value, expected } = testCase;
17551756
const baseStore: TestSessionStore = {
17561757
load: vi.fn(async () => ({
17571758
acpxRecordId: "agent:codex:acp:test",
@@ -1775,7 +1776,7 @@ describe("AcpxRuntime fresh reset wrapper", () => {
17751776
});
17761777
if (!expected) {
17771778
await expect(update).rejects.toMatchObject({
1778-
code: errorCode ?? "ACP_INVALID_RUNTIME_OPTION",
1779+
code: "errorCode" in testCase ? testCase.errorCode : "ACP_INVALID_RUNTIME_OPTION",
17791780
});
17801781
expect(setConfigOption).not.toHaveBeenCalled();
17811782
return;
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/** Tests configured binding controls against the real ACP manager lifecycle. */
2+
import { describe, expect, it, vi } from "vitest";
3+
import { buildConfiguredAcpSessionKey } from "../persistent-bindings.types.js";
4+
import {
5+
AcpRuntimeError,
6+
AcpSessionManager,
7+
baseCfg,
8+
createRuntime,
9+
hoisted,
10+
installAcpSessionManagerTestLifecycle,
11+
type SessionAcpMeta,
12+
} from "./manager.test-helpers.js";
13+
14+
describe("AcpSessionManager configured bindings", () => {
15+
installAcpSessionManagerTestLifecycle();
16+
17+
it("keeps startup omission but rejects live binding changes before overwriting accepted thinking", async () => {
18+
const managerModule = await import("./manager.js");
19+
const { ensureConfiguredAcpBindingSession } =
20+
await import("../persistent-bindings.lifecycle.js");
21+
const runtimeState = createRuntime();
22+
runtimeState.setConfigOption.mockImplementation(async ({ value }) => {
23+
if (value === "off") {
24+
throw new AcpRuntimeError("ACP_BACKEND_UNSUPPORTED_CONTROL", "Live off is unsupported");
25+
}
26+
});
27+
hoisted.requireAcpRuntimeBackendMock.mockReturnValue({
28+
id: "acpx",
29+
runtime: runtimeState.runtime,
30+
});
31+
const spec = {
32+
channel: "discord" as const,
33+
accountId: "default",
34+
conversationId: "configured-thinking",
35+
agentId: "codex",
36+
mode: "persistent" as const,
37+
thinking: "off",
38+
};
39+
const sessionKey = buildConfiguredAcpSessionKey(spec);
40+
let currentMeta: SessionAcpMeta | undefined;
41+
hoisted.readAcpSessionEntryMock.mockImplementation(() =>
42+
currentMeta ? { sessionKey, storeSessionKey: sessionKey, acp: currentMeta } : null,
43+
);
44+
hoisted.upsertAcpSessionMetaMock.mockImplementation(
45+
({
46+
mutate,
47+
}: {
48+
mutate: (
49+
current: SessionAcpMeta | undefined,
50+
entry: { acp?: SessionAcpMeta },
51+
) => SessionAcpMeta | null | undefined;
52+
}) => {
53+
currentMeta = mutate(currentMeta, { acp: currentMeta }) ?? currentMeta;
54+
return { sessionId: "configured-session", updatedAt: Date.now(), acp: currentMeta };
55+
},
56+
);
57+
const manager = new AcpSessionManager();
58+
const getManager = vi.spyOn(managerModule, "getAcpSessionManager").mockReturnValue(manager);
59+
const ensure = (thinking?: string) =>
60+
ensureConfiguredAcpBindingSession({ cfg: baseCfg, spec: { ...spec, thinking } });
61+
const runTurn = (requestId: string) =>
62+
manager.runTurn({
63+
provenance: "system",
64+
cfg: baseCfg,
65+
sessionKey,
66+
text: requestId,
67+
mode: "prompt",
68+
requestId,
69+
});
70+
try {
71+
expect(await ensure("off")).toEqual({ ok: true, sessionKey });
72+
await runTurn("first");
73+
await runTurn("second");
74+
expect(currentMeta?.runtimeOptions?.thinking).toBe("off");
75+
76+
expect(await ensure("high")).toEqual({ ok: true, sessionKey });
77+
await runTurn("third");
78+
const acceptedMeta = currentMeta;
79+
for (let attempt = 0; attempt < 2; attempt++) {
80+
expect(await ensure("off")).toEqual({
81+
ok: false,
82+
sessionKey,
83+
error: "Live off is unsupported",
84+
});
85+
expect(currentMeta).toEqual(acceptedMeta);
86+
}
87+
expect(await ensure()).toEqual({ ok: true, sessionKey });
88+
await runTurn("fourth");
89+
expect(currentMeta?.runtimeOptions?.thinking).toBe("high");
90+
expect(runtimeState.ensureSession).toHaveBeenCalledOnce();
91+
expect(runtimeState.close).not.toHaveBeenCalled();
92+
expect(runtimeState.runTurn).toHaveBeenCalledTimes(4);
93+
} finally {
94+
getManager.mockRestore();
95+
}
96+
});
97+
});

‎src/acp/control-plane/manager.runtime-config.test.ts‎

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/** Tests ACP runtime mode/config option persistence and backend control calls. */
22
import { describe, expect, it, vi } from "vitest";
3-
import { buildConfiguredAcpSessionKey } from "../persistent-bindings.types.js";
43
import {
54
type AcpRuntime,
65
AcpRuntimeError,
@@ -22,87 +21,6 @@ import {
2221
describe("AcpSessionManager runtime config", () => {
2322
installAcpSessionManagerTestLifecycle();
2423

25-
it("keeps startup omission but rejects live binding changes before overwriting accepted thinking", async () => {
26-
const managerModule = await import("./manager.js");
27-
const { ensureConfiguredAcpBindingSession } =
28-
await import("../persistent-bindings.lifecycle.js");
29-
const runtimeState = createRuntime();
30-
runtimeState.setConfigOption.mockImplementation(async ({ value }) => {
31-
if (value === "off") {
32-
throw new AcpRuntimeError("ACP_BACKEND_UNSUPPORTED_CONTROL", "Live off is unsupported");
33-
}
34-
});
35-
hoisted.requireAcpRuntimeBackendMock.mockReturnValue({
36-
id: "acpx",
37-
runtime: runtimeState.runtime,
38-
});
39-
const spec = {
40-
channel: "discord" as const,
41-
accountId: "default",
42-
conversationId: "configured-thinking",
43-
agentId: "codex",
44-
mode: "persistent" as const,
45-
thinking: "off",
46-
};
47-
const sessionKey = buildConfiguredAcpSessionKey(spec);
48-
let currentMeta: SessionAcpMeta | undefined;
49-
hoisted.readAcpSessionEntryMock.mockImplementation(() =>
50-
currentMeta ? { sessionKey, storeSessionKey: sessionKey, acp: currentMeta } : null,
51-
);
52-
hoisted.upsertAcpSessionMetaMock.mockImplementation(
53-
({
54-
mutate,
55-
}: {
56-
mutate: (
57-
current: SessionAcpMeta | undefined,
58-
entry: { acp?: SessionAcpMeta },
59-
) => SessionAcpMeta | null | undefined;
60-
}) => {
61-
currentMeta = mutate(currentMeta, { acp: currentMeta }) ?? currentMeta;
62-
return { sessionId: "configured-session", updatedAt: Date.now(), acp: currentMeta };
63-
},
64-
);
65-
const manager = new AcpSessionManager();
66-
const getManager = vi.spyOn(managerModule, "getAcpSessionManager").mockReturnValue(manager);
67-
const ensure = (thinking?: string) =>
68-
ensureConfiguredAcpBindingSession({ cfg: baseCfg, spec: { ...spec, thinking } });
69-
const runTurn = (requestId: string) =>
70-
manager.runTurn({
71-
provenance: "system",
72-
cfg: baseCfg,
73-
sessionKey,
74-
text: requestId,
75-
mode: "prompt",
76-
requestId,
77-
});
78-
try {
79-
expect(await ensure("off")).toEqual({ ok: true, sessionKey });
80-
await runTurn("first");
81-
await runTurn("second");
82-
expect(currentMeta?.runtimeOptions?.thinking).toBe("off");
83-
84-
expect(await ensure("high")).toEqual({ ok: true, sessionKey });
85-
await runTurn("third");
86-
const acceptedMeta = currentMeta;
87-
for (let attempt = 0; attempt < 2; attempt++) {
88-
expect(await ensure("off")).toEqual({
89-
ok: false,
90-
sessionKey,
91-
error: "Live off is unsupported",
92-
});
93-
expect(currentMeta).toEqual(acceptedMeta);
94-
}
95-
expect(await ensure()).toEqual({ ok: true, sessionKey });
96-
await runTurn("fourth");
97-
expect(currentMeta?.runtimeOptions?.thinking).toBe("high");
98-
expect(runtimeState.ensureSession).toHaveBeenCalledOnce();
99-
expect(runtimeState.close).not.toHaveBeenCalled();
100-
expect(runtimeState.runTurn).toHaveBeenCalledTimes(4);
101-
} finally {
102-
getManager.mockRestore();
103-
}
104-
});
105-
10624
it("persists runtime mode changes through setSessionRuntimeMode", async () => {
10725
const runtimeState = createRuntime();
10826
hoisted.requireAcpRuntimeBackendMock.mockReturnValue({

0 commit comments

Comments
 (0)