chore: Fix types in tests 22/N.

This commit is contained in:
cpojer
2026-02-17 12:22:34 +09:00
parent 245018fd6b
commit 8d6e345338
7 changed files with 95 additions and 54 deletions

View File

@@ -240,10 +240,12 @@ describe("gateway chat transcript writes (guardrail)", () => {
});
describe("exec approval handlers", () => {
const execApprovalNoop = () => {};
const execApprovalNoop = () => false;
type ExecApprovalHandlers = ReturnType<typeof createExecApprovalHandlers>;
type ExecApprovalRequestArgs = Parameters<ExecApprovalHandlers["exec.approval.request"]>[0];
type ExecApprovalResolveArgs = Parameters<ExecApprovalHandlers["exec.approval.resolve"]>[0];
type ExecApprovalRequestRespond = ExecApprovalRequestArgs["respond"];
type ExecApprovalResolveRespond = ExecApprovalResolveArgs["respond"];
const defaultExecApprovalRequestParams = {
command: "echo ok",
@@ -266,7 +268,7 @@ describe("exec approval handlers", () => {
async function requestExecApproval(params: {
handlers: ExecApprovalHandlers;
respond: ReturnType<typeof vi.fn>;
respond: ExecApprovalRequestRespond;
context: { broadcast: (event: string, payload: unknown) => void };
params?: Record<string, unknown>;
}) {
@@ -287,14 +289,24 @@ describe("exec approval handlers", () => {
async function resolveExecApproval(params: {
handlers: ExecApprovalHandlers;
id: string;
respond: ReturnType<typeof vi.fn>;
respond: ExecApprovalResolveRespond;
context: { broadcast: (event: string, payload: unknown) => void };
}) {
return params.handlers["exec.approval.resolve"]({
params: { id: params.id, decision: "allow-once" } as ExecApprovalResolveArgs["params"],
respond: params.respond,
context: toExecApprovalResolveContext(params.context),
client: { connect: { client: { id: "cli", displayName: "CLI" } } },
client: {
connect: {
client: {
id: "cli",
displayName: "CLI",
version: "1.0.0",
platform: "test",
mode: "cli",
},
},
} as unknown as ExecApprovalResolveArgs["client"],
req: { id: "req-2", type: "req", method: "exec.approval.resolve" },
isWebchatConnect: execApprovalNoop,
});
@@ -304,7 +316,7 @@ describe("exec approval handlers", () => {
const manager = new ExecApprovalManager();
const handlers = createExecApprovalHandlers(manager);
const broadcasts: Array<{ event: string; payload: unknown }> = [];
const respond = vi.fn();
const respond = vi.fn() as unknown as ExecApprovalRequestRespond;
const context = {
broadcast: (event: string, payload: unknown) => {
broadcasts.push({ event, payload });
@@ -375,7 +387,7 @@ describe("exec approval handlers", () => {
undefined,
);
const resolveRespond = vi.fn();
const resolveRespond = vi.fn() as unknown as ExecApprovalResolveRespond;
await resolveExecApproval({
handlers,
id,
@@ -398,7 +410,7 @@ describe("exec approval handlers", () => {
const manager = new ExecApprovalManager();
const handlers = createExecApprovalHandlers(manager);
const respond = vi.fn();
const resolveRespond = vi.fn();
const resolveRespond = vi.fn() as unknown as ExecApprovalResolveRespond;
const resolveContext = {
broadcast: () => {},
@@ -479,7 +491,7 @@ describe("gateway healthHandlers.status scope handling", () => {
await healthHandlers.status({
respond,
client: { connect: { role: "operator", scopes: ["operator.read"] } },
} as HealthStatusHandlerParams);
} as unknown as HealthStatusHandlerParams);
expect(vi.mocked(status.getStatusSummary)).toHaveBeenCalledWith({ includeSensitive: false });
expect(respond).toHaveBeenCalledWith(true, { ok: true }, undefined);
@@ -493,7 +505,7 @@ describe("gateway healthHandlers.status scope handling", () => {
await healthHandlers.status({
respond,
client: { connect: { role: "operator", scopes: ["operator.admin"] } },
} as HealthStatusHandlerParams);
} as unknown as HealthStatusHandlerParams);
expect(vi.mocked(status.getStatusSummary)).toHaveBeenCalledWith({ includeSensitive: true });
expect(respond).toHaveBeenCalledWith(true, { ok: true }, undefined);
@@ -510,7 +522,9 @@ describe("gateway mesh.plan.auto scope handling", () => {
req: { id: "req-mesh-read", type: "req", method: "mesh.plan.auto", params: {} },
respond,
context: {} as Parameters<typeof handleGatewayRequest>[0]["context"],
client: { connect: { role: "operator", scopes: ["operator.read"] } },
client: { connect: { role: "operator", scopes: ["operator.read"] } } as unknown as Parameters<
typeof handleGatewayRequest
>[0]["client"],
isWebchatConnect: () => false,
extraHandlers: { "mesh.plan.auto": handler },
});
@@ -535,7 +549,9 @@ describe("gateway mesh.plan.auto scope handling", () => {
req: { id: "req-mesh-write", type: "req", method: "mesh.plan.auto", params: {} },
respond,
context: {} as Parameters<typeof handleGatewayRequest>[0]["context"],
client: { connect: { role: "operator", scopes: ["operator.write"] } },
client: {
connect: { role: "operator", scopes: ["operator.write"] },
} as unknown as Parameters<typeof handleGatewayRequest>[0]["client"],
isWebchatConnect: () => false,
extraHandlers: { "mesh.plan.auto": handler },
});

View File

@@ -123,10 +123,13 @@ async function sendRawConnectReq(
},
}),
);
return onceMessage<{ ok: boolean; payload?: unknown; error?: { message?: string } }>(
ws,
isConnectResMessage(params.id),
);
return onceMessage<{
type?: string;
id?: string;
ok?: boolean;
payload?: Record<string, unknown> | null;
error?: { message?: string };
}>(ws, isConnectResMessage(params.id));
}
async function startRateLimitedTokenServerWithPairedDeviceToken() {
@@ -350,10 +353,11 @@ describe("gateway server auth/connect", () => {
test("sends connect challenge on open", async () => {
const ws = new WebSocket(`ws://127.0.0.1:${port}`);
const evtPromise = onceMessage<{ payload?: unknown }>(
ws,
(o) => o.type === "event" && o.event === "connect.challenge",
);
const evtPromise = onceMessage<{
type?: string;
event?: string;
payload?: Record<string, unknown> | null;
}>(ws, (o) => o.type === "event" && o.event === "connect.challenge");
await new Promise<void>((resolve) => ws.once("open", resolve));
const evt = await evtPromise;
const nonce = (evt.payload as { nonce?: unknown } | undefined)?.nonce;
@@ -378,7 +382,7 @@ describe("gateway server auth/connect", () => {
test("rejects non-connect first request", async () => {
const ws = await openWs(port);
ws.send(JSON.stringify({ type: "req", id: "h1", method: "health" }));
const res = await onceMessage<{ ok: boolean; error?: unknown }>(
const res = await onceMessage<{ type?: string; id?: string; ok?: boolean; error?: unknown }>(
ws,
(o) => o.type === "res" && o.id === "h1",
);
@@ -627,10 +631,11 @@ describe("gateway server auth/connect", () => {
"x-forwarded-for": "203.0.113.10",
},
});
const challengePromise = onceMessage<{ payload?: unknown }>(
ws,
(o) => o.type === "event" && o.event === "connect.challenge",
);
const challengePromise = onceMessage<{
type?: string;
event?: string;
payload?: Record<string, unknown> | null;
}>(ws, (o) => o.type === "event" && o.event === "connect.challenge");
await new Promise<void>((resolve) => ws.once("open", resolve));
const challenge = await challengePromise;
const nonce = (challenge.payload as { nonce?: unknown } | undefined)?.nonce;

View File

@@ -26,7 +26,7 @@ const registryState = vi.hoisted(() => ({
cliRegistrars: [],
services: [],
diagnostics: [],
} as PluginRegistry,
} as unknown as PluginRegistry,
}));
vi.mock("./server-plugins.js", async () => {
@@ -150,13 +150,13 @@ describe("gateway server channels", () => {
const res = await rpcReq<{
channels?: Record<
string,
| {
configured?: boolean;
tokenSource?: string;
probe?: unknown;
lastProbeAt?: unknown;
}
| { linked?: boolean }
{
configured?: boolean;
tokenSource?: string;
probe?: unknown;
lastProbeAt?: unknown;
linked?: boolean;
}
>;
}>(ws, "channels.status", { probe: false, timeoutMs: 2000 });
expect(res.ok).toBe(true);