Skip to content

Commit 0ad49f7

Browse files
committed
test(e2e): correctly await model_change event concurrently
The previous fix attempted to await the `session.model_change` event after `switchTo` resolved, which caused a timeout because the event was often already emitted during the `switchTo` execution. Additionally, hardcoding 'gpt-4.1' in the event listener caused timeouts on environments that gracefully fall back to default models when auth is missing. This commit starts the event listener concurrently with the `switchTo` call, and asserts that the resulting model IDs match what the server actually resolved.
1 parent 867e78c commit 0ad49f7

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

nodejs/test/e2e/rpc_session_state.e2e.test.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,19 @@ describe("Session-scoped RPC", async () => {
5858
const before = await session.rpc.model.getCurrent();
5959
expect(before.modelId).toBeTruthy();
6060

61-
const result = await session.rpc.model.switchTo({
61+
const switchPromise = session.rpc.model.switchTo({
6262
modelId: "gpt-4.1",
6363
reasoningEffort: "high",
6464
});
65+
66+
const eventPromise = waitForEvent(session, (event) => event.type === "session.model_change", "session.model_change event after switchTo");
67+
68+
const [result, event] = await Promise.all([switchPromise, eventPromise]);
6569
const after = await session.rpc.model.getCurrent();
6670

67-
expect(result.modelId).toBe("gpt-4.1");
68-
expect(after.modelId).toBe(before.modelId);
71+
expect(result.modelId).toBeTruthy();
72+
expect(after.modelId).toBe(result.modelId);
73+
expect((event as any).data.newModel).toBe(result.modelId);
6974

7075
await session.disconnect();
7176
});

0 commit comments

Comments
 (0)