test: dedupe codex registration mock calls

This commit is contained in:
Peter Steinberger
2026-05-12 13:36:21 +01:00
parent e6551e63ba
commit 14b871efd9

View File

@@ -4,6 +4,14 @@ import { describe, expect, it, vi } from "vitest";
import { createCodexAppServerAgentHarness } from "./harness.js";
import plugin from "./index.js";
function mockCall(mock: { mock: { calls: unknown[][] } }, index = 0) {
return mock.mock.calls.at(index);
}
function mockCallArg(mock: { mock: { calls: unknown[][] } }, index = 0, argIndex = 0) {
return mockCall(mock, index)?.at(argIndex);
}
describe("codex plugin", () => {
it("is opt-in by default", () => {
const manifest = JSON.parse(
@@ -40,16 +48,13 @@ describe("codex plugin", () => {
}),
);
const providerRegistration = registerProvider.mock.calls[0]?.[0] as Record<string, unknown>;
const agentHarnessRegistration = registerAgentHarness.mock.calls[0]?.[0] as Record<
string,
unknown
>;
const mediaProviderRegistration = registerMediaUnderstandingProvider.mock.calls[0]?.[0] as
const providerRegistration = mockCallArg(registerProvider) as Record<string, unknown>;
const agentHarnessRegistration = mockCallArg(registerAgentHarness) as Record<string, unknown>;
const mediaProviderRegistration = mockCallArg(registerMediaUnderstandingProvider) as
| Record<string, unknown>
| undefined;
const inboundClaimRegistration = on.mock.calls[0] as [unknown, unknown] | undefined;
const bindingResolvedRegistration = onConversationBindingResolved.mock.calls[0] as
const inboundClaimRegistration = mockCall(on) as [unknown, unknown] | undefined;
const bindingResolvedRegistration = mockCall(onConversationBindingResolved) as
| [unknown]
| undefined;
@@ -66,12 +71,14 @@ describe("codex plugin", () => {
expect(mediaProviderRegistration?.defaultModels).toEqual({ image: "gpt-5.5" });
expect(typeof mediaProviderRegistration?.describeImage).toBe("function");
expect(typeof mediaProviderRegistration?.describeImages).toBe("function");
const commandRegistration = registerCommand.mock.calls[0]?.[0];
const commandRegistration = mockCallArg(registerCommand) as Record<string, unknown> | undefined;
expect(commandRegistration?.name).toBe("codex");
expect(commandRegistration?.description).toBe(
"Inspect and control the Codex app-server harness",
);
const migrationRegistration = registerMigrationProvider.mock.calls[0]?.[0];
const migrationRegistration = mockCallArg(registerMigrationProvider) as
| Record<string, unknown>
| undefined;
expect(migrationRegistration?.id).toBe("codex");
expect(migrationRegistration?.label).toBe("Codex");
expect(inboundClaimRegistration?.[0]).toBe("inbound_claim");
@@ -98,7 +105,7 @@ describe("codex plugin", () => {
plugin.register(api);
expect(registerProvider).toHaveBeenCalledTimes(1);
expect(registerProvider.mock.calls[0]?.[0].id).toBe("codex");
expect((mockCallArg(registerProvider) as { id?: string } | undefined)?.id).toBe("codex");
});
it("only claims the codex provider by default", () => {