test(infra): use bonjour beacon type in discovery test

Replace the loose bonjour discovery test record shape with the exported GatewayBonjourBeacon contract so invalid-port regression coverage keeps passing the core test typecheck gate.

Verification:
- node scripts/run-vitest.mjs run src/infra/bonjour-discovery.test.ts --reporter=verbose
- node scripts/run-oxlint.mjs src/infra/bonjour-discovery.test.ts
- ./node_modules/oxfmt/bin/oxfmt --check --threads=1 src/infra/bonjour-discovery.test.ts
- git diff --check
- .agents/skills/autoreview/scripts/autoreview --mode local
- AWS Crabbox corepack pnpm check:changed: run_1af313cdd0bb, cbx_f0ef52388e7c, provider aws, exit 0

PR: https://github.com/openclaw/openclaw/pull/87765
This commit is contained in:
Vincent Koc
2026-05-28 20:53:02 +01:00
committed by GitHub
parent 46f023d097
commit 9cb4e48018

View File

@@ -1,22 +1,13 @@
import { describe, expect, it, vi } from "vitest";
import type { runCommandWithTimeout } from "../process/exec.js";
import { discoverGatewayBeacons, resolveGatewayDiscoveryEndpoint } from "./bonjour-discovery.js";
import {
discoverGatewayBeacons,
type GatewayBonjourBeacon,
resolveGatewayDiscoveryEndpoint,
} from "./bonjour-discovery.js";
const WIDE_AREA_DOMAIN = "openclaw.internal.";
type BeaconRecord = {
domain?: string;
instanceName?: string;
displayName?: string;
host?: string;
port?: number;
tailnetDns?: string;
gatewayPort?: number;
sshPort?: number;
cliPath?: string;
txt?: Record<string, unknown>;
};
function collectMatching<T, U>(
items: readonly T[],
predicate: (item: T) => boolean,
@@ -31,7 +22,10 @@ function collectMatching<T, U>(
return matches;
}
function findBeaconByInstance(beacons: readonly BeaconRecord[], instanceName: string) {
function findBeaconByInstance(
beacons: readonly GatewayBonjourBeacon[],
instanceName: string,
): GatewayBonjourBeacon {
const beacon = beacons.find((item) => item.instanceName === instanceName);
if (!beacon) {
throw new Error(`Expected beacon ${instanceName}`);
@@ -39,6 +33,15 @@ function findBeaconByInstance(beacons: readonly BeaconRecord[], instanceName: st
return beacon;
}
function getOnlyBeacon(beacons: readonly GatewayBonjourBeacon[]): GatewayBonjourBeacon {
expect(beacons).toHaveLength(1);
const beacon = beacons[0];
if (!beacon) {
throw new Error("Expected one beacon");
}
return beacon;
}
describe("bonjour-discovery", () => {
it("discovers beacons on darwin across local + wide-area domains", async () => {
const calls: Array<{ argv: string[]; timeoutMs: number }> = [];
@@ -179,8 +182,7 @@ describe("bonjour-discovery", () => {
run: run as unknown as typeof runCommandWithTimeout,
});
expect(beacons).toHaveLength(1);
const beacon = beacons[0] as BeaconRecord;
const beacon = getOnlyBeacon(beacons);
expect(beacon.domain).toBe("local.");
expect(beacon.instanceName).toBe("Studio Gateway");
expect(beacon.displayName).toBe("Peters Mac Studio");
@@ -224,8 +226,7 @@ describe("bonjour-discovery", () => {
run: run as unknown as typeof runCommandWithTimeout,
});
expect(beacons).toHaveLength(1);
const beacon = beacons[0] as BeaconRecord;
const beacon = getOnlyBeacon(beacons);
expect(beacon.host).toBe("broken.local");
expect(beacon.port).toBeUndefined();
expect(beacon.gatewayPort).toBeUndefined();
@@ -324,8 +325,7 @@ describe("bonjour-discovery", () => {
run: run as unknown as typeof runCommandWithTimeout,
});
expect(beacons).toHaveLength(1);
const beacon = beacons[0] as BeaconRecord;
const beacon = getOnlyBeacon(beacons);
expect(beacon.domain).toBe(WIDE_AREA_DOMAIN);
expect(beacon.instanceName).toBe("studio-gateway");
expect(beacon.displayName).toBe("Studio");