Test strict app payload unexpected-field rejection in renderer

Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
Cursor AgentandTheo Browne committed 2026-02-10 12:52:36 +00:00
1 parent a124fd9cb9
commit 2f1eb3d30d
1 file changed
+66
+66
View File
@@ -486,6 +486,35 @@ describe("wsNativeApi", () => {
);
});
it("rejects app.health responses with unexpected payload fields", async () => {
setWindowSearch("?ws=ws%3A%2F%2F127.0.0.1%3A4535");
const { getOrCreateWsNativeApi } = await import("./wsNativeApi");
const api = getOrCreateWsNativeApi();
const request = api.app.health();
const socket = MockWebSocket.instances[0];
await waitForCondition(() => (socket?.sentMessages.length ?? 0) > 0);
const requestEnvelope = JSON.parse(socket?.sentMessages[0] ?? "{}") as { id: string };
socket?.emitMessage(
JSON.stringify({
type: "response",
id: requestEnvelope.id,
ok: true,
result: {
status: "ok",
launchCwd: "/workspace",
sessionCount: 0,
activeClientConnected: true,
unexpected: true,
},
}),
);
await expect(request).rejects.toThrow(
"Runtime method 'app.health' returned invalid response payload.",
);
});
it("sends app.bootstrap requests and returns payload", async () => {
setWindowSearch("?ws=ws%3A%2F%2F127.0.0.1%3A4412");
const { getOrCreateWsNativeApi } = await import("./wsNativeApi");
@@ -577,6 +606,43 @@ describe("wsNativeApi", () => {
});
});
it("rejects app.bootstrap responses with unexpected payload fields", async () => {
setWindowSearch("?ws=ws%3A%2F%2F127.0.0.1%3A4536");
const { getOrCreateWsNativeApi } = await import("./wsNativeApi");
const api = getOrCreateWsNativeApi();
const request = api.app.bootstrap();
const socket = MockWebSocket.instances[0];
await waitForCondition(() => (socket?.sentMessages.length ?? 0) > 0);
const requestEnvelope = JSON.parse(socket?.sentMessages[0] ?? "{}") as { id: string };
socket?.emitMessage(
JSON.stringify({
type: "response",
id: requestEnvelope.id,
ok: true,
result: {
launchCwd: "/workspace",
projectName: "workspace",
provider: "codex",
model: "gpt-5-codex",
session: {
sessionId: "sess-1",
provider: "codex",
status: "ready",
createdAt: "2026-02-01T00:00:00.000Z",
updatedAt: "2026-02-01T00:00:00.000Z",
},
unexpected: true,
},
}),
);
await expect(request).rejects.toThrow(
"Runtime method 'app.bootstrap' returned invalid response payload.",
);
});
it("falls back to default local runtime URL when ws query is missing", async () => {
setWindowSearch("");
const { getOrCreateWsNativeApi } = await import("./wsNativeApi");