chore: Fix types in tests 6/N.

This commit is contained in:
cpojer
2026-02-17 10:52:25 +09:00
parent b6d4f7c00e
commit 003d6c45d6
6 changed files with 180 additions and 116 deletions

View File

@@ -7,12 +7,23 @@ const loadConfig = vi.fn(() => ({
auth: { token: "ltok" },
},
}));
const resolveGatewayPort = vi.fn(() => 18789);
const discoverGatewayBeacons = vi.fn(async () => []);
const resolveGatewayPort = vi.fn((_cfg?: unknown) => 18789);
const discoverGatewayBeacons = vi.fn(
async (_opts?: unknown): Promise<Array<{ tailnetDns: string }>> => [],
);
const pickPrimaryTailnetIPv4 = vi.fn(() => "100.64.0.10");
const sshStop = vi.fn(async () => {});
const resolveSshConfig = vi.fn(async () => null);
const startSshPortForward = vi.fn(async () => ({
const resolveSshConfig = vi.fn(
async (
_opts?: unknown,
): Promise<{
user: string;
host: string;
port: number;
identityFiles: string[];
} | null> => null,
);
const startSshPortForward = vi.fn(async (_opts?: unknown) => ({
parsedTarget: { user: "me", host: "studio", port: 22 },
localPort: 18789,
remotePort: 18789,
@@ -20,7 +31,8 @@ const startSshPortForward = vi.fn(async () => ({
stderr: [],
stop: sshStop,
}));
const probeGateway = vi.fn(async ({ url }: { url: string }) => {
const probeGateway = vi.fn(async (opts: { url: string }) => {
const { url } = opts;
if (url.includes("127.0.0.1")) {
return {
ok: true,
@@ -80,32 +92,32 @@ const probeGateway = vi.fn(async ({ url }: { url: string }) => {
});
vi.mock("../config/config.js", () => ({
loadConfig: () => loadConfig(),
resolveGatewayPort: (cfg: unknown) => resolveGatewayPort(cfg),
loadConfig,
resolveGatewayPort,
}));
vi.mock("../infra/bonjour-discovery.js", () => ({
discoverGatewayBeacons: (opts: unknown) => discoverGatewayBeacons(opts),
discoverGatewayBeacons,
}));
vi.mock("../infra/tailnet.js", () => ({
pickPrimaryTailnetIPv4: () => pickPrimaryTailnetIPv4(),
pickPrimaryTailnetIPv4,
}));
vi.mock("../infra/ssh-tunnel.js", async (importOriginal) => {
const actual = await importOriginal<typeof import("../infra/ssh-tunnel.js")>();
return {
...actual,
startSshPortForward: (opts: unknown) => startSshPortForward(opts),
startSshPortForward,
};
});
vi.mock("../infra/ssh-config.js", () => ({
resolveSshConfig: (opts: unknown) => resolveSshConfig(opts),
resolveSshConfig,
}));
vi.mock("../gateway/probe.js", () => ({
probeGateway: (opts: unknown) => probeGateway(opts),
probeGateway,
}));
function createRuntimeCapture() {
@@ -198,7 +210,8 @@ describe("gateway-status command", () => {
loadConfig.mockReturnValueOnce({
gateway: {
mode: "remote",
remote: {},
remote: { url: "", token: "" },
auth: { token: "ltok" },
},
});
discoverGatewayBeacons.mockResolvedValueOnce([
@@ -226,6 +239,7 @@ describe("gateway-status command", () => {
gateway: {
mode: "remote",
remote: { url: "ws://peters-mac-studio-1.sheep-coho.ts.net:18789", token: "rtok" },
auth: { token: "ltok" },
},
});
resolveSshConfig.mockResolvedValueOnce({
@@ -259,6 +273,7 @@ describe("gateway-status command", () => {
gateway: {
mode: "remote",
remote: { url: "ws://studio.example:18789", token: "rtok" },
auth: { token: "ltok" },
},
});
resolveSshConfig.mockResolvedValueOnce(null);
@@ -284,6 +299,7 @@ describe("gateway-status command", () => {
gateway: {
mode: "remote",
remote: { url: "ws://studio.example:18789", token: "rtok" },
auth: { token: "ltok" },
},
});
resolveSshConfig.mockResolvedValueOnce({