Skip to content

Commit 5a22aff

Browse files
committed
test: isolate Codex auth and session completion fixtures
1 parent 3c43fcf commit 5a22aff

2 files changed

Lines changed: 42 additions & 5 deletions

File tree

‎extensions/codex/src/command-rpc.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ import {
77
type AuthProfileStore,
88
} from "openclaw/plugin-sdk/agent-runtime";
99
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
10+
import {
11+
createEmptyPluginRegistry,
12+
getActivePluginRegistry,
13+
resetPluginRuntimeStateForTest,
14+
setActivePluginRegistry,
15+
} from "openclaw/plugin-sdk/plugin-test-runtime";
1016
import {
1117
clearSessionStoreCacheForTest,
1218
upsertSessionEntry,
@@ -29,9 +35,19 @@ describe("Codex command RPC helpers", () => {
2935
let agentDir: string;
3036
let config: OpenClawConfig;
3137
let harness: ReturnType<typeof createClientHarness>;
38+
let previousPluginRegistry: ReturnType<typeof getActivePluginRegistry>;
3239
const sessionKey = "agent:main:control";
3340

3441
beforeEach(async () => {
42+
previousPluginRegistry = getActivePluginRegistry();
43+
const registry = createEmptyPluginRegistry();
44+
// Provide the provider hook contract; source discovery is outside this control-auth fixture.
45+
registry.providers.push({
46+
pluginId: "openai",
47+
provider: { id: "openai", label: "OpenAI", auth: [] },
48+
source: "test",
49+
});
50+
setActivePluginRegistry(registry);
3551
tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-codex-control-auth-"));
3652
agentDir = path.join(tempDir, "agents", "main", "agent");
3753
vi.stubEnv("OPENCLAW_STATE_DIR", tempDir);
@@ -52,6 +68,11 @@ describe("Codex command RPC helpers", () => {
5268
});
5369

5470
afterEach(async () => {
71+
if (previousPluginRegistry) {
72+
setActivePluginRegistry(previousPluginRegistry);
73+
} else {
74+
resetPluginRuntimeStateForTest();
75+
}
5576
harness.client.close();
5677
clearRuntimeAuthProfileStoreSnapshots();
5778
clearSessionStoreCacheForTest();

‎src/gateway/server.agent.subagent-delivery-context.test.ts‎

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Subagent delivery-context tests protect route metadata inheritance for child
22
// agent sessions and outbound delivery through channel plugins.
3+
import { randomUUID } from "node:crypto";
34
import { describe, expect, test } from "vitest";
45
import type { ChannelPlugin } from "../channels/plugins/types.public.js";
56
import { loadSessionEntry } from "../config/sessions/session-accessor.js";
@@ -12,7 +13,13 @@ import { projectSessionDeliveryFields } from "../utils/delivery-context.shared.j
1213
import { setRegistry } from "./server.agent.gateway-server-agent.mocks.js";
1314
import { createRegistry } from "./server.e2e-registry-helpers.js";
1415
import { installConnectedSessionStoreGatewaySuite } from "./test-helpers.connected-session-store.js";
15-
import { installGatewayTestHooks, rpcReq, testState, writeSessionStore } from "./test-helpers.js";
16+
import {
17+
installGatewayTestHooks,
18+
onceMessage,
19+
prepareGatewayReplyRuntimeForTest,
20+
testState,
21+
writeSessionStore,
22+
} from "./test-helpers.js";
1623

1724
installGatewayTestHooks({ scope: "suite" });
1825

@@ -74,11 +81,20 @@ async function readStoredSessionEntry(key: string): Promise<StoredEntry> {
7481
}
7582

7683
async function sendAgentRequest(params: Record<string, unknown>): Promise<void> {
77-
const res = await rpcReq(gatewaySuite.ws, "agent", {
78-
deliver: false,
79-
...params,
80-
});
84+
await prepareGatewayReplyRuntimeForTest();
85+
const id = randomUUID();
86+
// Acceptance precedes execution; the next fixture must not delete a session with an active run.
87+
const finalResponse = onceMessage(
88+
gatewaySuite.ws,
89+
(message) =>
90+
message.type === "res" && message.id === id && message.payload?.status !== "accepted",
91+
);
92+
gatewaySuite.ws.send(
93+
JSON.stringify({ type: "req", id, method: "agent", params: { deliver: false, ...params } }),
94+
);
95+
const res = await finalResponse;
8196
expect(res.ok).toBe(true);
97+
expect(res.payload?.status).toBe("ok");
8298
}
8399

84100
function expectDeliveryContextFields(entry: StoredEntry, expected: Record<string, unknown>): void {

0 commit comments

Comments
 (0)