Skip to content

Commit fd08bfd

Browse files
committed
fix(windows): preserve Unicode LAN route aliases
1 parent 01c1ebf commit fd08bfd

7 files changed

Lines changed: 97 additions & 9 deletions

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1966,7 +1966,7 @@
19661966
"test:unit:fast:audit": "node --import tsx scripts/test-unit-fast-audit.mts",
19671967
"test:voicecall:closedloop": "node --import tsx scripts/test-voicecall-closedloop.mts",
19681968
"test:watch": "node --import tsx scripts/test-projects.mts --watch",
1969-
"test:windows:ci": "node --import tsx scripts/test-projects.mts src/shared/runtime-import.test.ts src/config/sessions/session-accessor.sqlite-archive.worker.test.ts src/commands/doctor-gateway-auth-token.windows.test.ts src/agents/tools/media-tool-file-url.windows.test.ts src/media/local-media-path.windows.test.ts src/infra/sqlite-snapshot.test.ts src/infra/ssh-client.windows.test.ts src/infra/ports.test.ts src/infra/update-managed-service-handoff-command.test.ts src/infra/update-managed-service-handoff-lifecycle.test.ts src/infra/exec-allowlist-pattern.test.ts src/infra/executable-path.test.ts src/infra/process-env.test.ts src/infra/fs-safe-remove.test.ts src/snapshot/local-repository.windows.test.ts src/state/openclaw-database-paths.windows.test.ts src/commands/backup-verify.test.ts src/infra/state-migrations.legacy-session-store.test.ts src/test-utils/openclaw-test-state.test.ts src/agents/provider-local-service.env-case.test.ts src/agents/sessions/windows-git-bash-path.test.ts src/agents/bash-tools.exec.script-preflight.test.ts src/process/exec.windows.test.ts src/process/exec.windows.integration.test.ts src/process/windows-command.test.ts src/infra/windows-install-roots.test.ts src/node-host/invoke-system-run-allowlist.test.ts src/auto-reply/usage-bar/template.windows.test.ts src/auto-reply/reply.triggers.trigger-handling.stages-inbound-media-into-sandbox-workspace.test.ts src/media-understanding/attachments.file-url.windows.test.ts src/utils.test.ts src/commands/agents.commands.list.test.ts src/cli/daemon-cli/status.print.test.ts src/cli/mcp-cli.path-case.windows.test.ts extensions/memory-core/src/memory-extra-file-path.windows.test.ts packages/terminal-core/src/display-string.test.ts src/agents/sandbox/fs-paths.test.ts src/agents/sessions/tools/render-utils.test.ts src/agents/agent-tools.read.windows.test.ts src/agents/agent-tools.read.host-operations.test.ts src/agents/sessions/tools/path-utils.test.ts src/daemon/schtasks.startup-fallback.test.ts src/media/web-media.file-url.windows.test.ts extensions/lobster/src/lobster-runner.test.ts extensions/msteams/src/media-helpers.test.ts extensions/msteams/src/messenger.test.ts extensions/mxc/test/mxc-backend.test.ts extensions/mxc/test/sandbox-policy-loader.test.ts test/e2e/qa-lab/runtime/package-openclaw-for-docker.e2e.test.ts test/scripts/direct-run-entrypoints.test.ts test/scripts/format-generated-module.test.ts test/scripts/npm-runner.test.ts test/scripts/openclaw-cross-os-installer.windows.test.ts test/scripts/openclaw-cross-os-release-workflow.test.ts test/scripts/pnpm-runner.test.ts test/scripts/run-with-env.test.ts test/scripts/ts-topology.test.ts test/scripts/ui.test.ts test/scripts/vitest-process-group.test.ts",
1969+
"test:windows:ci": "node --import tsx scripts/test-projects.mts src/shared/runtime-import.test.ts src/config/sessions/session-accessor.sqlite-archive.worker.test.ts src/commands/doctor-gateway-auth-token.windows.test.ts src/agents/tools/media-tool-file-url.windows.test.ts src/media/local-media-path.windows.test.ts src/infra/sqlite-snapshot.test.ts src/infra/ssh-client.windows.test.ts src/infra/ports.test.ts src/infra/advertised-lan-host.windows.test.ts src/infra/update-managed-service-handoff-command.test.ts src/infra/update-managed-service-handoff-lifecycle.test.ts src/infra/exec-allowlist-pattern.test.ts src/infra/executable-path.test.ts src/infra/process-env.test.ts src/infra/fs-safe-remove.test.ts src/snapshot/local-repository.windows.test.ts src/state/openclaw-database-paths.windows.test.ts src/commands/backup-verify.test.ts src/infra/state-migrations.legacy-session-store.test.ts src/test-utils/openclaw-test-state.test.ts src/agents/provider-local-service.env-case.test.ts src/agents/sessions/windows-git-bash-path.test.ts src/agents/bash-tools.exec.script-preflight.test.ts src/process/exec.windows.test.ts src/process/exec.windows.integration.test.ts src/process/windows-command.test.ts src/infra/windows-install-roots.test.ts src/node-host/invoke-system-run-allowlist.test.ts src/auto-reply/usage-bar/template.windows.test.ts src/auto-reply/reply.triggers.trigger-handling.stages-inbound-media-into-sandbox-workspace.test.ts src/media-understanding/attachments.file-url.windows.test.ts src/utils.test.ts src/commands/agents.commands.list.test.ts src/cli/daemon-cli/status.print.test.ts src/cli/mcp-cli.path-case.windows.test.ts extensions/memory-core/src/memory-extra-file-path.windows.test.ts packages/terminal-core/src/display-string.test.ts src/agents/sandbox/fs-paths.test.ts src/agents/sessions/tools/render-utils.test.ts src/agents/agent-tools.read.windows.test.ts src/agents/agent-tools.read.host-operations.test.ts src/agents/sessions/tools/path-utils.test.ts src/daemon/schtasks.startup-fallback.test.ts src/media/web-media.file-url.windows.test.ts extensions/lobster/src/lobster-runner.test.ts extensions/msteams/src/media-helpers.test.ts extensions/msteams/src/messenger.test.ts extensions/mxc/test/mxc-backend.test.ts extensions/mxc/test/sandbox-policy-loader.test.ts test/e2e/qa-lab/runtime/package-openclaw-for-docker.e2e.test.ts test/scripts/direct-run-entrypoints.test.ts test/scripts/format-generated-module.test.ts test/scripts/npm-runner.test.ts test/scripts/openclaw-cross-os-installer.windows.test.ts test/scripts/openclaw-cross-os-release-workflow.test.ts test/scripts/pnpm-runner.test.ts test/scripts/run-with-env.test.ts test/scripts/ts-topology.test.ts test/scripts/ui.test.ts test/scripts/vitest-process-group.test.ts",
19701970
"test:windows:schtasks:integration": "node --import tsx scripts/run-with-env.mts CI_WINDOWS_SCHTASKS_INTEGRATION=1 OPENCLAW_E2E_VERBOSE=1 OPENCLAW_VITEST_MAX_WORKERS=1 -- node scripts/run-vitest.mjs src/daemon/schtasks.integration.e2e.test.ts",
19711971
"tool-display:check": "node --import tsx scripts/tool-display.ts --check",
19721972
"tool-display:write": "node --import tsx scripts/tool-display.ts --write",

‎scripts/ci-changed-scope.mjs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ const WINDOWS_SQLITE_SCOPE_RE = /^src\/(?:state\/|.*sqlite.*\.ts$)/;
5858
const WINDOWS_FILE_URL_SCOPE_RE =
5959
/^(?:src\/agents\/tools\/(?:media-tool-file-url\.windows\.test|media-tool-shared(?:\.test)?|pdf-tool(?:\.test)?)|src\/auto-reply\/(?:reply\/stage-sandbox-media|reply\.triggers\.trigger-handling\.stages-inbound-media-into-sandbox-workspace\.test)|src\/media\/(?:local-media-path(?:\.windows\.test)?|local-roots(?:\.test)?|web-media(?:\.file-url\.windows\.test)?)|src\/channels\/inbound-event\/media(?:\.test)?|src\/gateway\/managed-image-attachments(?:\.test)?|extensions\/msteams\/src\/(?:media-helpers|messenger)(?:\.test)?)\.ts$/;
6060
const WINDOWS_SCOPE_RE =
61-
/^(extensions\/mxc\/|src\/agents\/(?:bash-tools\.exec-script-(?:preflight|target)|bash-tools\.exec\.script-preflight\.test)\.ts$|src\/config\/sessions\/(?:session-accessor\.sqlite-archive(?:\.worker(?:\.test)?)?|store\.session-lifecycle-mutation\.test)\.ts$|src\/process\/|src\/infra\/(?:(?:exec-allowlist-pattern|fs-safe-remove)(?:\.test)?|ports(?:-inspect|\.test)|ssh-client(?:\.windows\.test)?|update-managed-service-handoff(?:-(?:command|lifecycle)\.test)?|windows-install-roots)\.ts$|src\/shared\/(?:import-specifier|runtime-import)(?:\.test)?\.ts$|src\/test-utils\/openclaw-test-state(?:\.test)?\.ts$|scripts\/(?:android-(?:app-i18n|pin-version)\.ts|ci-run-timings\.mjs|e2e\/lib\/package-compat\.mjs|generate-bundled-channel-config-metadata\.ts|install\.ps1|openclaw-cross-os-release-checks\.ts|plan-release-workflow-matrix\.mjs|run-additional-boundary-checks\.mts|verify-docker-attestations\.mjs|github\/run-openclaw-cross-os-release-checks\.sh|(?:npm-runner|pnpm-runner|ui|vitest-process-group)\.(?:mjs|mts|js)|lib\/(?:direct-run\.(?:mjs|mts)|format-generated-module\.mts|tsx-cli-shim\.mjs|cross-os-release-checks\/[^/]+\.ts))$|test\/scripts\/(?:direct-run-entrypoints|format-generated-module|install-ps1|npm-runner|openclaw-cross-os-release-workflow|pnpm-runner|ui|vitest-process-group)\.test\.ts$|package\.json$|pnpm-lock\.yaml$|pnpm-workspace\.yaml$|\.github\/workflows\/(?:ci|openclaw-cross-os-release-checks-reusable)\.yml$|\.github\/actions\/setup-node-env\/action\.yml$|\.github\/actions\/setup-pnpm-store-cache\/action\.yml$)/;
61+
/^(extensions\/mxc\/|src\/agents\/(?:bash-tools\.exec-script-(?:preflight|target)|bash-tools\.exec\.script-preflight\.test)\.ts$|src\/config\/sessions\/(?:session-accessor\.sqlite-archive(?:\.worker(?:\.test)?)?|store\.session-lifecycle-mutation\.test)\.ts$|src\/process\/|src\/infra\/(?:(?:advertised-lan-host|exec-allowlist-pattern|fs-safe-remove)(?:\.windows)?(?:\.test)?|ports(?:-inspect|\.test)|ssh-client(?:\.windows\.test)?|update-managed-service-handoff(?:-(?:command|lifecycle)\.test)?|windows-install-roots)\.ts$|src\/shared\/(?:import-specifier|runtime-import)(?:\.test)?\.ts$|src\/test-utils\/openclaw-test-state(?:\.test)?\.ts$|scripts\/(?:android-(?:app-i18n|pin-version)\.ts|ci-run-timings\.mjs|e2e\/lib\/package-compat\.mjs|generate-bundled-channel-config-metadata\.ts|install\.ps1|openclaw-cross-os-release-checks\.ts|plan-release-workflow-matrix\.mjs|run-additional-boundary-checks\.mts|verify-docker-attestations\.mjs|github\/run-openclaw-cross-os-release-checks\.sh|(?:npm-runner|pnpm-runner|ui|vitest-process-group)\.(?:mjs|mts|js)|lib\/(?:direct-run\.(?:mjs|mts)|format-generated-module\.mts|tsx-cli-shim\.mjs|cross-os-release-checks\/[^/]+\.ts))$|test\/scripts\/(?:direct-run-entrypoints|format-generated-module|install-ps1|npm-runner|openclaw-cross-os-release-workflow|pnpm-runner|ui|vitest-process-group)\.test\.ts$|package\.json$|pnpm-lock\.yaml$|pnpm-workspace\.yaml$|\.github\/workflows\/(?:ci|openclaw-cross-os-release-checks-reusable)\.yml$|\.github\/actions\/setup-node-env\/action\.yml$|\.github\/actions\/setup-pnpm-store-cache\/action\.yml$)/;
6262
const WINDOWS_TEST_SCOPE_RE =
63-
/^(extensions\/mxc\/test\/(?:mxc-backend|sandbox-policy-loader)\.test\.ts$|src\/agents\/bash-tools\.exec\.script-preflight\.test\.ts$|src\/config\/sessions\/(?:session-accessor\.sqlite-archive\.worker|store\.session-lifecycle-mutation)\.test\.ts$|src\/process\/(?:exec\.windows|windows-command)\.test\.ts$|src\/infra\/(?:exec-allowlist-pattern|fs-safe-remove|ports|ssh-client\.windows|update-managed-service-handoff-(?:command|lifecycle)|windows-install-roots)\.test\.ts$|src\/shared\/runtime-import\.test\.ts$|src\/state\/openclaw-database-paths\.windows\.test\.ts$|src\/test-utils\/openclaw-test-state\.test\.ts$|test\/scripts\/(?:direct-run-entrypoints|format-generated-module|npm-runner|openclaw-cross-os-release-workflow|pnpm-runner|ui|vitest-process-group)\.test\.ts$)/;
63+
/^(extensions\/mxc\/test\/(?:mxc-backend|sandbox-policy-loader)\.test\.ts$|src\/agents\/bash-tools\.exec\.script-preflight\.test\.ts$|src\/config\/sessions\/(?:session-accessor\.sqlite-archive\.worker|store\.session-lifecycle-mutation)\.test\.ts$|src\/process\/(?:exec\.windows|windows-command)\.test\.ts$|src\/infra\/(?:advertised-lan-host(?:\.windows)?|exec-allowlist-pattern|fs-safe-remove|ports|ssh-client\.windows|update-managed-service-handoff-(?:command|lifecycle)|windows-install-roots)\.test\.ts$|src\/shared\/runtime-import\.test\.ts$|src\/state\/openclaw-database-paths\.windows\.test\.ts$|src\/test-utils\/openclaw-test-state\.test\.ts$|test\/scripts\/(?:direct-run-entrypoints|format-generated-module|npm-runner|openclaw-cross-os-release-workflow|pnpm-runner|ui|vitest-process-group)\.test\.ts$)/;
6464
const WINDOWS_SECRETREF_SCOPE_RE =
6565
/^(?:src\/commands\/doctor-gateway-auth-token(?:\.windows\.test)?\.ts|src\/flows\/(?:doctor-core-checks|doctor-health-contributions)\.ts|src\/gateway\/(?:auth-token-resolution|resolve-configured-secret-input-string)\.ts|src\/infra\/(?:fs-safe|fs-safe-defaults|permissions)\.ts|src\/secrets\/(?:resolve|resolve-errors)\.ts|src\/security\/audit-fs\.ts)$/;
6666
const WINDOWS_SECRETREF_TEST_SCOPE_RE =

‎src/infra/advertised-lan-host.test.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe("advertised LAN host", () => {
4949
const runner = createRouteRunner(
5050
JSON.stringify([
5151
{ InterfaceAlias: "Ethernet", RouteMetric: 1, InterfaceMetric: 1000 },
52-
{ InterfaceAlias: "Ethernet 2", RouteMetric: 100, InterfaceMetric: 1 },
52+
{ InterfaceAlias: "réseau-网卡", RouteMetric: 100, InterfaceMetric: 1 },
5353
]),
5454
);
5555

@@ -60,7 +60,7 @@ describe("advertised LAN host", () => {
6060
networkInterfaces: () =>
6161
({
6262
Ethernet: [ipv4("10.37.129.4")],
63-
"Ethernet 2": [ipv4("10.211.55.3")],
63+
"réseau-网卡": [ipv4("10.211.55.3")],
6464
}) as NetworkInterfacesSnapshot,
6565
}),
6666
).resolves.toBe("10.211.55.3");
@@ -71,7 +71,9 @@ describe("advertised LAN host", () => {
7171
"-ExecutionPolicy",
7272
"Bypass",
7373
"-Command",
74-
expect.stringContaining("Get-NetRoute"),
74+
expect.stringMatching(
75+
/^\[Console\]::OutputEncoding=\[Text\.UTF8Encoding\]::new\(\$false\); Get-NetRoute/,
76+
),
7577
],
7678
{ timeoutMs: 3_000, maxOutputBytes: 16 * 1024 },
7779
);

‎src/infra/advertised-lan-host.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ import {
1111
const DEFAULT_ROUTE_HINT_TIMEOUT_MS = 3_000;
1212
const DEFAULT_ROUTE_HINT_OUTPUT_BYTES = 16 * 1024;
1313
const WINDOWS_DEFAULT_ROUTE_COMMAND =
14-
"Get-NetRoute -AddressFamily IPv4 -DestinationPrefix '0.0.0.0/0' | " +
15-
"Select-Object -Property InterfaceAlias,InterfaceIndex,NextHop,RouteMetric,InterfaceMetric,DestinationPrefix | " +
16-
"ConvertTo-Json -Compress";
14+
"[Console]::OutputEncoding=[Text.UTF8Encoding]::new($false); Get-NetRoute -AddressFamily IPv4 -DestinationPrefix '0.0.0.0/0' | " +
15+
"Select-Object -Property InterfaceAlias,RouteMetric,InterfaceMetric | ConvertTo-Json -Compress";
1716

1817
type AdvertisedLanHostCandidate = {
1918
interfaceName: string;
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Windows-native proof that PowerShell preserves localized adapter aliases.
2+
import { describe, expect, it, vi } from "vitest";
3+
import { runCommandWithTimeout } from "../process/exec.js";
4+
import { resolveAdvertisedLanHostCore } from "./advertised-lan-host.js";
5+
import type { NetworkInterfacesSnapshot } from "./network-interfaces.js";
6+
7+
type ResolveOptions = NonNullable<Parameters<typeof resolveAdvertisedLanHostCore>[0]>;
8+
type RouteRunner = NonNullable<ResolveOptions["runCommandWithTimeout"]>;
9+
10+
function ipv4(address: string) {
11+
return {
12+
address,
13+
family: "IPv4" as const,
14+
internal: false,
15+
netmask: "255.255.255.0",
16+
mac: "00:00:00:00:00:00",
17+
cidr: `${address}/24`,
18+
};
19+
}
20+
21+
describe.runIf(process.platform === "win32")("advertised LAN host PowerShell contract", () => {
22+
it("round-trips a localized route alias through the production command prefix", async () => {
23+
let capturedArgv: string[] | undefined;
24+
const captureRunner: RouteRunner = vi.fn(async (argv) => {
25+
capturedArgv = argv;
26+
return { code: 0, stdout: "", stderr: "" };
27+
});
28+
const interfaces = {
29+
"vEthernet (Default Switch)": [ipv4("10.37.129.4")],
30+
"réseau-网卡": [ipv4("192.168.1.20")],
31+
} as NetworkInterfacesSnapshot;
32+
33+
await resolveAdvertisedLanHostCore({
34+
platform: "win32",
35+
networkInterfaces: () => interfaces,
36+
runCommandWithTimeout: captureRunner,
37+
});
38+
39+
const command = capturedArgv?.at(-1);
40+
const routeCommandIndex = command?.indexOf("Get-NetRoute") ?? -1;
41+
const outputPrefix = routeCommandIndex > 0 ? (command?.slice(0, routeCommandIndex) ?? "") : "";
42+
const result = await runCommandWithTimeout(
43+
[
44+
"powershell.exe",
45+
"-NoProfile",
46+
"-ExecutionPolicy",
47+
"Bypass",
48+
"-Command",
49+
`[Console]::OutputEncoding=[Text.Encoding]::GetEncoding(437); ${outputPrefix}[pscustomobject]@{InterfaceAlias='réseau-网卡';RouteMetric=1;InterfaceMetric=1} | ConvertTo-Json -Compress`,
50+
],
51+
{ timeoutMs: 3_000, maxOutputBytes: 16 * 1024 },
52+
);
53+
expect(result).toMatchObject({ code: 0 });
54+
expect(JSON.parse(result.stdout)).toMatchObject({ InterfaceAlias: "réseau-网卡" });
55+
expect(command).toMatch(
56+
/^\[Console\]::OutputEncoding=\[Text\.UTF8Encoding\]::new\(\$false\); Get-NetRoute/,
57+
);
58+
expect(routeCommandIndex).toBeGreaterThan(0);
59+
60+
await expect(
61+
resolveAdvertisedLanHostCore({
62+
platform: "win32",
63+
networkInterfaces: () => interfaces,
64+
runCommandWithTimeout: vi.fn(async () => result),
65+
}),
66+
).resolves.toBe("192.168.1.20");
67+
});
68+
});

‎src/scripts/ci-changed-scope.windows.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,19 @@ describe("detectChangedScope Windows routing", () => {
7474
}
7575
});
7676

77+
it("routes LAN advertisement and its native PowerShell proof to Windows", () => {
78+
for (const lanPath of [
79+
"src/infra/advertised-lan-host.ts",
80+
"src/infra/advertised-lan-host.test.ts",
81+
"src/infra/advertised-lan-host.windows.test.ts",
82+
]) {
83+
expect(detectChangedScope([lanPath]), lanPath).toMatchObject({
84+
runNode: true,
85+
runWindows: true,
86+
});
87+
}
88+
});
89+
7790
it("routes MXC runtime changes and Windows-only suites to Windows", () => {
7891
for (const mxcPath of [
7992
"extensions/mxc/src/mxc-backend.ts",

‎test/package-scripts.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,12 @@ describe("package scripts", () => {
237237
expect(readPackageJson().scripts["test:windows:ci"]).toContain("src/infra/ports.test.ts");
238238
});
239239

240+
it("runs native LAN advertisement coverage in Windows CI", () => {
241+
expect(readPackageJson().scripts["test:windows:ci"]).toContain(
242+
"src/infra/advertised-lan-host.windows.test.ts",
243+
);
244+
});
245+
240246
it("keeps the native Scheduled Task lifecycle proof opt-in", () => {
241247
const scripts = readPackageJson().scripts;
242248

0 commit comments

Comments
 (0)