test: guard multiline helper assertions

This commit is contained in:
Peter Steinberger
2026-05-11 20:49:19 +01:00
parent 6e1e057e88
commit 93dd5e61ba
7 changed files with 36 additions and 49 deletions

View File

@@ -107,12 +107,8 @@ describe("Codex app-server approval bridge", () => {
expect(requestPayload.turnSourceChannel).toBe("telegram");
expect(requestPayload.turnSourceTo).toBe("chat-1");
expect(gatewayCallOptions()).toEqual({ expectFinal: false });
expect(
findApprovalEvent(params, { status: "pending", approvalId: "plugin:approval-1" }),
).toBeDefined();
expect(
findApprovalEvent(params, { status: "approved", approvalId: "plugin:approval-1" }),
).toBeDefined();
findApprovalEvent(params, { status: "pending", approvalId: "plugin:approval-1" });
findApprovalEvent(params, { status: "approved", approvalId: "plugin:approval-1" });
});
it("describes command approvals from parsed command actions when available", async () => {
@@ -240,12 +236,10 @@ describe("Codex app-server approval bridge", () => {
expect(gatewayRequestPayload().description).toBe(
"Command: pnpm test --watch extensions/codex/src/app-server\nSession: agent:main:session-1",
);
expect(
findApprovalEvent(params, {
status: "pending",
command: "pnpm test --watch extensions/codex/src/app-server",
}),
).toBeDefined();
findApprovalEvent(params, {
status: "pending",
command: "pnpm test --watch extensions/codex/src/app-server",
});
});
it("escapes command approval previews before forwarding approval text and events", async () => {
@@ -275,12 +269,9 @@ describe("Codex app-server approval bridge", () => {
expect(description).not.toContain("<@U123>");
expect(description).not.toContain("[trusted](https://evil)");
expect(description).not.toContain("@here");
expect(
findApprovalEvent(params, {
command:
"printf '&lt;\uff20U123&gt; \uff3btrusted\uff3d\uff08https://evil\uff09 \uff20here'",
}),
).toBeDefined();
findApprovalEvent(params, {
command: "printf '&lt;\uff20U123&gt; \uff3btrusted\uff3d\uff08https://evil\uff09 \uff20here'",
});
});
it("preserves visible OSC-8 link labels in command previews", async () => {
@@ -416,12 +407,10 @@ describe("Codex app-server approval bridge", () => {
"plugin.approval.request",
"plugin.approval.waitDecision",
]);
expect(
findApprovalEvent(params, {
status: "denied",
approvalId: "plugin:approval-untrusted",
}),
).toBeDefined();
findApprovalEvent(params, {
status: "denied",
approvalId: "plugin:approval-untrusted",
});
});
it("only treats own null data-property request decisions as no-route", async () => {
@@ -538,9 +527,7 @@ describe("Codex app-server approval bridge", () => {
expect(result).toEqual({ decision: "decline" });
expect(mockCallGatewayTool).toHaveBeenCalledTimes(1);
expect(
findApprovalEvent(params, { status: "unavailable", reason: "needs write access" }),
).toBeDefined();
findApprovalEvent(params, { status: "unavailable", reason: "needs write access" });
});
it("sanitizes reason previews before forwarding approval text and events", async () => {
@@ -566,12 +553,10 @@ describe("Codex app-server approval bridge", () => {
expect(gatewayRequestPayload().description).toBe(
"Reason: needs write access for /tmp please\nSession: agent:main:session-1",
);
expect(
findApprovalEvent(params, {
status: "unavailable",
reason: "needs write access for /tmp please",
}),
).toBeDefined();
findApprovalEvent(params, {
status: "unavailable",
reason: "needs write access for /tmp please",
});
});
it("fails closed for unsupported native approval methods without requesting plugin approval", async () => {

View File

@@ -236,7 +236,8 @@ describe("diffs tool", () => {
mode: "file",
});
const filePath = (result?.details as Record<string, unknown>).filePath as string;
await expect(fs.stat(filePath)).resolves.toBeDefined();
const stat = await fs.stat(filePath);
expect(stat.isFile()).toBe(true);
vi.setSystemTime(new Date(now.getTime() + 61_000));
await store.cleanupExpired();

View File

@@ -2783,9 +2783,13 @@ describe("DiscordVoiceManager", () => {
expect(lastTtsStreamArgs().disableFallback).toBe(true);
expect(lastTtsStreamArgs().text).toBe("hello back");
expect(textToSpeechMock).not.toHaveBeenCalled();
expect(
lastMockCall(createAudioResourceMock as unknown as MockCallSource, "audio resource")[0],
).toBeDefined();
const audioResourceInput = lastMockCall(
createAudioResourceMock as unknown as MockCallSource,
"audio resource",
)[0];
if (audioResourceInput === undefined) {
throw new Error("expected Discord audio resource input");
}
await vi.waitFor(() => expect(release).toHaveBeenCalledTimes(1));
});

View File

@@ -413,11 +413,6 @@ describe("telegram live qa runtime", () => {
.find((scenario) => scenario.id === "telegram-mentioned-message-reply")
?.buildRun("sut_bot").steps[0].replyToLatestSutMessage,
).toBe(true);
expect(
scenarios
.find((scenario) => scenario.id === "telegram-reply-chain-exact-marker")
?.buildRun("sut_bot").steps[0],
).toBeDefined();
const replyChainStep = requireScenario(scenarios, "telegram-reply-chain-exact-marker").buildRun(
"sut_bot",
).steps[0];

View File

@@ -458,9 +458,7 @@ describe("deliverWebReply", () => {
expect(mediaPayload.mimetype).toBe("image/jpeg");
expect(mockCallArg(msg.sendMedia, 0, 1, "sendMedia")).toBeUndefined();
expect(msg.reply).toHaveBeenCalledWith("aaa", undefined);
expect(
findLoggerContext(replyLogger.info, "auto-reply sent (media)", "replyLogger.info"),
).toBeDefined();
findLoggerContext(replyLogger.info, "auto-reply sent (media)", "replyLogger.info");
expect(logVerbose).toHaveBeenCalled();
});

View File

@@ -331,7 +331,11 @@ describe("acp translator stop reason mapping", () => {
await Promise.resolve();
agent.handleGatewayDisconnect("1006: first disconnect");
agent.handleGatewayReconnect();
await vi.waitFor(() => expect(resolveAgentWait).toBeDefined());
await vi.waitFor(() => {
if (resolveAgentWait === undefined) {
throw new Error("expected agent.wait resolver");
}
});
const resolveWait = requireValue(resolveAgentWait, "agent.wait resolver");
agent.handleGatewayDisconnect("1006: second disconnect");

View File

@@ -5433,11 +5433,11 @@ module.exports = {
},
});
expect(
registry.channels.find((entry) => entry.plugin.id === "healthy-chat")?.plugin.meta,
).toBeDefined();
const healthyMeta = registry.channels.find((entry) => entry.plugin.id === "healthy-chat")
?.plugin.meta;
if (!healthyMeta) {
throw new Error("expected healthy chat plugin metadata");
}
expect(healthyMeta?.label).toBe("Healthy Chat");
expect(healthyMeta?.docsPath).toBe("/channels/healthy-chat");
expect(registry.plugins.find((entry) => entry.id === "healthy-channel")?.status).toBe("loaded");