diff --git a/.agents/references/provider-profile-inventory.md b/.agents/references/provider-profile-inventory.md index e9395605a8e..b12544b3849 100644 --- a/.agents/references/provider-profile-inventory.md +++ b/.agents/references/provider-profile-inventory.md @@ -30,6 +30,21 @@ does not authorize adoption of an existing provider. Ambiguous mutations require another mutation. Restart and rebuild verify recorded authority; they do not authorize automatic migration of old shared-route sandboxes. +## Native local host address boundary + +New native-local selections admit RFC1918 IPv4 and IPv6 unique-local (`fc00::/7`) resolution +only for `host.openshell.internal` or `host.docker.internal`. Each profile still binds one host, +port, API prefix, binary set, and credential reference. Public IPv6, link-local IPv6, and literal +IPv6 endpoints remain excluded. Literal private IPv4 endpoints retain their single-address `/32` boundary. + +The dual-stack boundary has a distinct profile and provider identity. Existing IPv4-only receipts +remain valid for verification and cleanup; resume and rebuild retain their recorded permissions. +To use IPv6 after upgrading, reselect the local provider with `nemoclaw inference set --provider --model `. +If onboarding has not finished, resume with `nemoclaw onboard --resume`; if it retains the old +attachment, reselect local inference before retrying the proof. Do not overwrite or delete an +attached profile to change its permissions. Reselection uses the existing ownership and cleanup +transaction. Profile collisions and missing ownership still stop before provider mutation. + ## Owned inference profiles All fixed definitions below are in diff --git a/.github/workflows/platform-vitest-main.yaml b/.github/workflows/platform-vitest-main.yaml index 4917fed1f65..0ae66acd191 100644 --- a/.github/workflows/platform-vitest-main.yaml +++ b/.github/workflows/platform-vitest-main.yaml @@ -485,6 +485,7 @@ jobs: set -euo pipefail cd $workdir $exports + test "`$(git rev-parse HEAD)" = "$env:GITHUB_SHA" export NEMOCLAW_RUN_LIVE_E2E=1 npx vitest run --project e2e-live test/e2e/live/full-e2e.test.ts --silent=false --reporter=default "@ diff --git a/ci/e2e-assertion-budget.json b/ci/e2e-assertion-budget.json index 96449b627a8..b34c598224e 100644 --- a/ci/e2e-assertion-budget.json +++ b/ci/e2e-assertion-budget.json @@ -15,26 +15,26 @@ "testFileCount": 77, "liveFileCount": 186, "direct": { - "expectCalls": 1260, - "matcherAssertions": 1240, + "expectCalls": 1267, + "matcherAssertions": 1247, "nodeAssertions": 109, - "namedAssertionHelpers": 423, + "namedAssertionHelpers": 424, "failCalls": 0, "throwGuards": 50, "objectFieldAssertions": 184, - "assertionPoints": 2006, + "assertionPoints": 2014, "generatedProbeBlocks": 86, "generatedProbeConditions": 215 }, "unique": { - "expectCalls": 1685, - "matcherAssertions": 1660, + "expectCalls": 1692, + "matcherAssertions": 1667, "nodeAssertions": 132, - "namedAssertionHelpers": 665, + "namedAssertionHelpers": 666, "failCalls": 1, "throwGuards": 526, "objectFieldAssertions": 261, - "assertionPoints": 3245, + "assertionPoints": 3253, "generatedProbeBlocks": 209, "generatedProbeConditions": 721 }, @@ -95,7 +95,7 @@ "test/e2e/live/onboard-repair.test.ts": [22,26,22,26,0], "test/e2e/live/onboard-resume.test.ts": [59,63,59,63,0], "test/e2e/live/openclaw-discord-pairing.test.ts": [13,20,28,86,10], - "test/e2e/live/openclaw-inference-switch.test.ts": [28,40,55,85,3], + "test/e2e/live/openclaw-inference-switch.test.ts": [35,48,62,93,3], "test/e2e/live/openclaw-skill-cli.test.ts": [10,14,10,14,1], "test/e2e/live/openclaw-slack-pairing.test.ts": [11,18,26,84,10], "test/e2e/live/openshell-credential-generation-window.test.ts": [42,92,43,112,18], diff --git a/ci/e2e-assertion-growth-exceptions.json b/ci/e2e-assertion-growth-exceptions.json index 25a314bd4f2..c0859b1a165 100644 --- a/ci/e2e-assertion-growth-exceptions.json +++ b/ci/e2e-assertion-growth-exceptions.json @@ -1,5 +1,5 @@ { - "$comment": "SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\nSPDX-License-Identifier: Apache-2.0\n\nMaintainer-approved exception for the exact PR #10341 budget transition. Adds only deferred-onboarding.test.ts with [12,14,12,14,0]; existing per-file budgets remain unchanged. Approval: https://github.com/NVIDIA/NemoClaw/pull/10341#issuecomment-5799263232. Local hooks and candidate CI may use this branch policy. The independent PR check reads only trusted base policy, so its expected growth failure is explicitly waived for #10341. A changed base or candidate budget invalidates this exception. Remove after #10341 merges.\n\nPR #12305 adds 19 live assertion points for the approved stopped-container recovery proof while retaining healthy-rebuild coverage. Exact budget-transition approval: https://github.com/NVIDIA/NemoClaw/pull/12305#issuecomment-5803852010. No other budget transition is accepted by this entry.\n\nThe same 19-assertion helper is also exercised by rebuild-openclaw, independently of the inherited private-MCP failure. Unique assertion counts are unchanged; one helper file is extracted. Revised exact-transition approval: https://github.com/NVIDIA/NemoClaw/pull/12305#issuecomment-5807159038.\n\nProposed exact budget transition for PR #12591: replace a restart progress-message check with a native gateway-owner observation before and after inference switching. Adds one generated probe and five probe conditions; direct and unique expectation counts do not exceed main. The imported helper also appears in the full-e2e transitive inventory. This entry requires maintainer review before landing on main. Remove it after #12591 merges.\n\nPR #12718 is the prerequisite for the PR #12382 budget transition recorded below. The exception matches only PR #12382 and both budget digests. A changed base or candidate budget invalidates it. The independent check reads trusted base policy, so this prerequisite must land on main before #12382 uses the exception. Remove after #12382 merges.\n\nMaintainer Prekshi Vyas (@prekshivyas) approved this exact refreshed PR #12382 transition on 2026-10-08: base budget SHA-256 53c51c4229d387633165771730f8f1a8373f84e9f3303b2144280027a56e3441 to candidate budget SHA-256 8162408384d7a6b97ef0062042c73d4bc9486f54d2dfa6c0c5732e42d1060e2a. Acceptance record: https://github.com/NVIDIA/NemoClaw/pull/12840#issuecomment-6066319444. It includes one additional unique assertion point and one generated probe condition. This refresh preserves the #12608 concurrent-gateway-ports reduction and the previously reviewed runtime assertion changes. The independent check is not waived: the refreshed exception must land on main before enforcement can accept it. A different PR or budget digest remains rejected. Remove after #12382 merges.\n\nPR #12777 adds exactly two approved live assertions for native host-local inference success and sibling provider isolation. Deterministic behavior remains in unit/integration tests. Approval transcription: https://github.com/NVIDIA/NemoClaw/pull/12777#issuecomment-6048385152. The independent check reads trusted base policy; this entry does not disable it. Remove after #12777 merges.\n\nThe #12777 budget digests account for main #12608 removing seven assertions from concurrent-gateway-ports. The candidate preserves that reduction and adds only the same two approved inference-routing assertions. No other file budget increases.\n\nPR #12886 approved the provider-smoke transition extracted by #12955. Approval: https://github.com/NVIDIA/NemoClaw/pull/12886#issuecomment-6083839176. The unchanged change digest binds the same nine assertion points and companion inventory. This entry supports local preliminary validation and the Slice 2 consumer. Independent CI for the prerequisite requires its own maintainer approval record; this entry does not approve that PR.\n\nPR #12958 extracts the same approved provider-smoke budget transition for #12955. Its exact, unedited maintainer approval is https://github.com/NVIDIA/NemoClaw/pull/12958#issuecomment-6093851571. This candidate entry supports static hooks; the independent check continues to verify the PR-specific approval on GitHub. Remove after #12958 merges.\n\nPR #13203 adds the approved 19 assertion points for real authenticated and credentialless DCode native-local requests, credential isolation and sibling denial. Approval: https://github.com/NVIDIA/NemoClaw/pull/13203#issuecomment-6180239679. This exact change digest supports local hooks and candidate CI. Independent enforcement still verifies the PR-specific maintainer approval on GitHub. Remove after #13203 merges.\n\nPR #13201 adds one generated probe block and one counted probe condition in the existing full E2E owner to verify the selected sandbox agent endpoint, API, model and credential reference. Rebecca Sliter approved this exact delta: https://github.com/NVIDIA/NemoClaw/pull/13201#issuecomment-6180464605. This entry supports local validation; the independent check must verify the maintainer record. Remove after #13201 merges.\n\nPR #13293 consolidates OpenClaw native-local scenarios into the existing switching owner and removes duplicated deterministic metadata checks and the redundant mock curl probe. Suite totals fall by 16 expect calls and 10 assertion points without adding live files. Only the owning file transitive allocation grows because it now imports existing live helpers. Maintainer authorization: https://github.com/NVIDIA/NemoClaw/pull/13293#issuecomment-6211036786. This exact transition supports candidate CI; independent enforcement still verifies the maintainer record.\n\nPR #13007 retains the same ten Pi native-local live assertion points approved at https://github.com/NVIDIA/NemoClaw/pull/13007#issuecomment-6175787892. The exact change digest is unchanged against its replacement OpenClaw parent #13293. This entry supports local checks against that stacked base; independent enforcement still checks the authenticated PR approval.", + "$comment": "SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\nSPDX-License-Identifier: Apache-2.0\n\nMaintainer-approved exception for the exact PR #10341 budget transition. Adds only deferred-onboarding.test.ts with [12,14,12,14,0]; existing per-file budgets remain unchanged. Approval: https://github.com/NVIDIA/NemoClaw/pull/10341#issuecomment-5799263232. Local hooks and candidate CI may use this branch policy. The independent PR check reads only trusted base policy, so its expected growth failure is explicitly waived for #10341. A changed base or candidate budget invalidates this exception. Remove after #10341 merges.\n\nPR #12305 adds 19 live assertion points for the approved stopped-container recovery proof while retaining healthy-rebuild coverage. Exact budget-transition approval: https://github.com/NVIDIA/NemoClaw/pull/12305#issuecomment-5803852010. No other budget transition is accepted by this entry.\n\nThe same 19-assertion helper is also exercised by rebuild-openclaw, independently of the inherited private-MCP failure. Unique assertion counts are unchanged; one helper file is extracted. Revised exact-transition approval: https://github.com/NVIDIA/NemoClaw/pull/12305#issuecomment-5807159038.\n\nProposed exact budget transition for PR #12591: replace a restart progress-message check with a native gateway-owner observation before and after inference switching. Adds one generated probe and five probe conditions; direct and unique expectation counts do not exceed main. The imported helper also appears in the full-e2e transitive inventory. This entry requires maintainer review before landing on main. Remove it after #12591 merges.\n\nPR #12718 is the prerequisite for the PR #12382 budget transition recorded below. The exception matches only PR #12382 and both budget digests. A changed base or candidate budget invalidates it. The independent check reads trusted base policy, so this prerequisite must land on main before #12382 uses the exception. Remove after #12382 merges.\n\nMaintainer Prekshi Vyas (@prekshivyas) approved this exact refreshed PR #12382 transition on 2026-10-08: base budget SHA-256 53c51c4229d387633165771730f8f1a8373f84e9f3303b2144280027a56e3441 to candidate budget SHA-256 8162408384d7a6b97ef0062042c73d4bc9486f54d2dfa6c0c5732e42d1060e2a. Acceptance record: https://github.com/NVIDIA/NemoClaw/pull/12840#issuecomment-6066319444. It includes one additional unique assertion point and one generated probe condition. This refresh preserves the #12608 concurrent-gateway-ports reduction and the previously reviewed runtime assertion changes. The independent check is not waived: the refreshed exception must land on main before enforcement can accept it. A different PR or budget digest remains rejected. Remove after #12382 merges.\n\nPR #12777 adds exactly two approved live assertions for native host-local inference success and sibling provider isolation. Deterministic behavior remains in unit/integration tests. Approval transcription: https://github.com/NVIDIA/NemoClaw/pull/12777#issuecomment-6048385152. The independent check reads trusted base policy; this entry does not disable it. Remove after #12777 merges.\n\nThe #12777 budget digests account for main #12608 removing seven assertions from concurrent-gateway-ports. The candidate preserves that reduction and adds only the same two approved inference-routing assertions. No other file budget increases.\n\nPR #12886 approved the provider-smoke transition extracted by #12955. Approval: https://github.com/NVIDIA/NemoClaw/pull/12886#issuecomment-6083839176. The unchanged change digest binds the same nine assertion points and companion inventory. This entry supports local preliminary validation and the Slice 2 consumer. Independent CI for the prerequisite requires its own maintainer approval record; this entry does not approve that PR.\n\nPR #12958 extracts the same approved provider-smoke budget transition for #12955. Its exact, unedited maintainer approval is https://github.com/NVIDIA/NemoClaw/pull/12958#issuecomment-6093851571. This candidate entry supports static hooks; the independent check continues to verify the PR-specific approval on GitHub. Remove after #12958 merges.\n\nPR #13203 adds the approved 19 assertion points for real authenticated and credentialless DCode native-local requests, credential isolation and sibling denial. Approval: https://github.com/NVIDIA/NemoClaw/pull/13203#issuecomment-6180239679. This exact change digest supports local hooks and candidate CI. Independent enforcement still verifies the PR-specific maintainer approval on GitHub. Remove after #13203 merges.\n\nPR #13201 adds one generated probe block and one counted probe condition in the existing full E2E owner to verify the selected sandbox agent endpoint, API, model and credential reference. Rebecca Sliter approved this exact delta: https://github.com/NVIDIA/NemoClaw/pull/13201#issuecomment-6180464605. This entry supports local validation; the independent check must verify the maintainer record. Remove after #13201 merges.\n\nPR #13293 consolidates OpenClaw native-local scenarios into the existing switching owner and removes duplicated deterministic metadata checks and the redundant mock curl probe. Suite totals fall by 16 expect calls and 10 assertion points without adding live files. Only the owning file transitive allocation grows because it now imports existing live helpers. Maintainer authorization: https://github.com/NVIDIA/NemoClaw/pull/13293#issuecomment-6211036786. This exact transition supports candidate CI; independent enforcement still verifies the maintainer record.\n\nPR #13007 retains the same ten Pi native-local live assertion points approved at https://github.com/NVIDIA/NemoClaw/pull/13007#issuecomment-6175787892. The exact change digest is unchanged against its replacement OpenClaw parent #13293. This entry supports local checks against that stacked base; independent enforcement still checks the authenticated PR approval.\n\nPR #13582 adds eight live assertion points for the WSL2 IPv6 native-local policy boundary. Only openclaw-inference-switch.test.ts increases, by seven direct expectations and the existing onboard-success helper. Deterministic CIDR and receipt coverage remain in source tests. Maintainer approval: https://github.com/NVIDIA/NemoClaw/pull/13582#issuecomment-6308860348. Independent enforcement verifies that PR-specific record. Remove this preliminary local exception after merge.", "schemaVersion": 1, "exceptions": [ { @@ -66,6 +66,10 @@ { "pullRequest": 12244, "changeSha256": "17dc02d59670eb356eb608df119747918ad481da4ca11044c55e41f52ba54904" + }, + { + "pullRequest": 13582, + "changeSha256": "90b021fd5c15eac87cc230ec2310b4b81fcbf2e7ce50c08b31775232d1dbc38e" } ] } diff --git a/docs/reference/troubleshooting.mdx b/docs/reference/troubleshooting.mdx index a2d3e6f2512..86b15bd6f44 100644 --- a/docs/reference/troubleshooting.mdx +++ b/docs/reference/troubleshooting.mdx @@ -2721,12 +2721,18 @@ Configuring an inference provider with a base URL like `http://host.docker.inter getent hosts host.docker.internal ``` -Expected output: +A native Linux Docker bridge can return an address such as this example: ```text 172.17.0.1 host.docker.internal host.openshell.internal ``` +With Docker Desktop WSL integration, the aliases can instead resolve to an IPv6 unique-local address in `fc00::/7`, such as `fdc4:f303:9324::254`. +New native-local host-alias profiles admit private IPv4 and IPv6 unique-local addresses while retaining the selected hostname and port restrictions. +Public, link-local, and loopback IPv6 addresses remain excluded. +A valid DNS result does not prove that the host service is reachable. +In the IPv4 example, this request still fails if the host service is not forwarded to port `11434`: + ```bash no_proxy=host.docker.internal curl -v http://host.docker.internal:11434/api/tags ``` diff --git a/src/lib/actions/inference-set-openclaw-native-local.test.ts b/src/lib/actions/inference-set-openclaw-native-local.test.ts index 1dbcc9496f6..5fcea7f352e 100644 --- a/src/lib/actions/inference-set-openclaw-native-local.test.ts +++ b/src/lib/actions/inference-set-openclaw-native-local.test.ts @@ -9,6 +9,7 @@ import { } from "../../../test/helpers/inference-set-openclaw-native-local"; import { resolveOpenClawLocalSwitch } from "./inference-set/native-local"; import { runInferenceSet } from "./inference-set"; +import { nativeLocalIdentity } from "../inference/native-local/contract"; vi.mock("../adapters/openshell/provider-policy", () => ({ requireNativeProviderPolicy: vi.fn(async () => {}), @@ -85,6 +86,37 @@ describe("OpenClaw native local live selection", () => { expect(deps.calls.clearNativeLocalProviderAuthority).not.toHaveBeenCalled(); }); + it("reselects the same Ollama endpoint with the dual-stack profile (#13544)", async () => { + const previous = { ...attachment, ...nativeLocalIdentity(attachment, 1) }; + const { deps, next, isAttached } = switchingFixture(previous, "ollama-local"); + await expect( + runInferenceSet({ provider: "ollama-local", model: "old-model", sandboxName: "alpha" }, deps), + ).resolves.toMatchObject({ provider: "ollama-local" }); + expect(isAttached()).toBe(true); + expect(deps.calls.updateSandbox).toHaveBeenCalledWith( + "alpha", + expect.objectContaining({ nativeLocalProviderAttachment: next }), + ); + expect(deps.calls.clearNativeLocalProviderAuthority).toHaveBeenCalledWith(previous); + }); + + it("restores the IPv4 attachment when dual-stack selection cannot save the registry (#13544)", async () => { + const previous = { ...attachment, ...nativeLocalIdentity(attachment, 1) }; + const { deps, isAttached } = switchingFixture(previous, "ollama-local"); + deps.calls.updateSandbox.mockReturnValue(false); + await expect( + runInferenceSet({ provider: "ollama-local", model: "old-model", sandboxName: "alpha" }, deps), + ).rejects.toThrow(/Failed to update NemoClaw registry/); + expect(isAttached()).toBe(false); + expect( + await deps.providerAdapter.listProviderAttachments({ + target: { kind: "named", gatewayName: "nemoclaw" }, + sandboxName: "alpha", + }), + ).toMatchObject({ ok: true, value: { names: [previous.providerName] } }); + expect(deps.calls.clearNativeLocalProviderAuthority).not.toHaveBeenCalledWith(previous); + }); + it("switches from Ollama to another local provider without changing the shared route", async () => { const { deps } = switchingFixture(); await expect( diff --git a/src/lib/actions/inference-set/native-local.ts b/src/lib/actions/inference-set/native-local.ts index 73d54edd782..0dbf70f7a67 100644 --- a/src/lib/actions/inference-set/native-local.ts +++ b/src/lib/actions/inference-set/native-local.ts @@ -8,6 +8,7 @@ import { detachNativeLocalProvider, ensureNativeLocalProviderAttached, normalizeNativeLocalProviderAttachment, + nativeLocalIdentity, retireNativeLocalProvider, type NativeLocalProviderAttachment, verifyNativeLocalProviderAttachment, @@ -61,7 +62,12 @@ export async function resolveOpenClawLocalSwitch(input: { return { previous }; // A retained OpenClaw row may still own the historical shared route. if (!previous && entry.provider === provider) return {}; - if (!previous || entry.provider !== provider) return { previous, prepare: true }; + if ( + !previous || + entry.provider !== provider || + previous.profileId !== nativeLocalIdentity(previous).profileId + ) + return { previous, prepare: true }; return { selected: previous, previous }; } diff --git a/src/lib/actions/inference/native-local.ts b/src/lib/actions/inference/native-local.ts index 69df39d31f1..debcae15ce9 100644 --- a/src/lib/actions/inference/native-local.ts +++ b/src/lib/actions/inference/native-local.ts @@ -8,6 +8,7 @@ import type { OpenShellProviderAdapter } from "../../adapters/openshell/provider import { resolveHermesLocalSwitchRuntime } from "../inference-set/local-runtime"; import { normalizeNativeLocalProviderAttachment, + nativeLocalIdentity, usesNativeLocalInference, usesNativeLocalInferenceForAgent, type NativeLocalProvider, @@ -32,7 +33,11 @@ export async function prepareNativeLocalSwitch(input: { readAuthority?: Parameters[0]["readAuthority"]; writeAuthority?: Parameters[0]["writeAuthority"]; }) { - if (input.previous?.provider === input.provider && !input.binding) { + if ( + input.previous?.provider === input.provider && + !input.binding && + input.previous.profileId === nativeLocalIdentity(input.previous).profileId + ) { return { ...(await ensureNativeLocalProviderAttached({ adapter: input.adapter, diff --git a/src/lib/inference/native-local.test.ts b/src/lib/inference/native-local.test.ts index 18f45f88f8f..1b83552de18 100644 --- a/src/lib/inference/native-local.test.ts +++ b/src/lib/inference/native-local.test.ts @@ -2,6 +2,9 @@ // SPDX-License-Identifier: Apache-2.0 import fs from "node:fs"; +import { BlockList, isIP } from "node:net"; +import { prepareNativeLocalSwitch } from "../actions/inference/native-local"; +import * as localRuntime from "../actions/inference-set/local-runtime"; import { OLLAMA_PROXY_PORT } from "../core/ollama-proxy-port"; import { isProtectedLocalInferencePort } from "./gateway/local-endpoint-ports"; import { describe, expect, it, vi } from "vitest"; @@ -409,8 +412,8 @@ describe("native local inference", () => { ).toBe(true); }); - it("isolates Hermes interpreter permissions without changing canonical DCode identity", () => { - expect(identity).toEqual({ + it("isolates Hermes interpreter permissions and preserves recorded agent identities", () => { + expect(nativeLocalIdentity(binding, 1)).toEqual({ profileId: "nemoclaw-local-authenticated-v1-2aa03053df038ef92e6bfbd9", providerName: "nemoclaw-local-v1-a97b50ec4828f77f37ca0fd6", }); @@ -422,16 +425,16 @@ describe("native local inference", () => { "/usr/bin/curl", ]); const hermes = prepareNativeLocalProfile({ ...binding, agent: "hermes" }); - expect(nativeLocalIdentity({ ...binding, agent: "hermes" })).toEqual({ + expect(nativeLocalIdentity({ ...binding, agent: "hermes" }, 1)).toEqual({ profileId: "nemoclaw-local-authenticated-v1-e6c1e496ac27438aa3ced2a6", providerName: "nemoclaw-local-v1-37774dccc8c1a20aa63ad49d", }); expect(hermes.profileId).not.toBe(dcode.profileId); - expect(nativeLocalIdentity({ ...binding, agent: "openclaw" })).toEqual({ + expect(nativeLocalIdentity({ ...binding, agent: "openclaw" }, 1)).toEqual({ profileId: "nemoclaw-local-authenticated-v1-9f7d167472a7f83a0c81d053", providerName: "nemoclaw-local-v1-618dfcccd3ab805e1b26339b", }); - expect(nativeLocalIdentity({ ...binding, agent: "pi" })).toEqual({ + expect(nativeLocalIdentity({ ...binding, agent: "pi" }, 1)).toEqual({ profileId: "nemoclaw-local-authenticated-v1-f6199144c76791c151009dc5", providerName: "nemoclaw-local-v1-ef8d855a399f3009f10266b8", }); @@ -521,6 +524,33 @@ describe("native local inference", () => { expect(isLocalInferenceProvider("llama-cpp-local")).toBe(true); }); + it.each(["host.openshell.internal", "host.docker.internal"])( + "admits private IPv6 resolution for %s (#13544)", + (host) => { + const endpoint = prepareNativeLocalProfile({ + ...binding, + endpointUrl: `http://${host}:11435/v1`, + }).document.endpoints[0]; + const addresses = new BlockList(); + endpoint.allowed_ips.forEach((cidr) => { + const [address, prefix] = cidr.split("/"); + addresses.addSubnet(address, Number(prefix), isIP(address) === 6 ? "ipv6" : "ipv4"); + }); + expect(addresses.check("fdc4:f303:9324::254", "ipv6")).toBe(true); + expect(addresses.check("fc00::", "ipv6")).toBe(true); + expect(addresses.check("fdff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", "ipv6")).toBe(true); + expect(addresses.check("fbff:ffff::1", "ipv6")).toBe(false); + expect(addresses.check("fe00::", "ipv6")).toBe(false); + expect(addresses.check("10.0.0.1", "ipv4")).toBe(true); + expect(addresses.check("172.16.0.1", "ipv4")).toBe(true); + expect(addresses.check("192.168.0.1", "ipv4")).toBe(true); + expect(addresses.check("2001:4860:4860::8888", "ipv6")).toBe(false); + expect(addresses.check("fe80::1", "ipv6")).toBe(false); + expect(addresses.check("::1", "ipv6")).toBe(false); + expect(addresses.check("8.8.8.8", "ipv4")).toBe(false); + }, + ); + it("restricts the selected bridge to models and chat requests (#12558)", () => { const profile = prepareNativeLocalProfile(binding); expect(profile.document.binaries).toContain("/usr/bin/python3"); @@ -542,7 +572,7 @@ describe("native local inference", () => { port: 11435, protocol: "rest", enforcement: "enforce", - allowed_ips: ["10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"], + allowed_ips: ["10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", "fc00::/7"], rules: [ { allow: { method: "GET", path: "/v1/models" } }, { allow: { method: "POST", path: "/v1/chat/completions" } }, @@ -715,6 +745,92 @@ describe("native local inference", () => { expect(f.adapter.getProvider).not.toHaveBeenCalled(); expect(f.adapter.attachProvider).not.toHaveBeenCalled(); }); + it("stops Hermes reselection before detaching IPv4 access when the dual-stack profile conflicts (#13544)", async () => { + const f = fixture({ + ...binding, + agent: "hermes", + credentialEnv: "NEMOCLAW_LOCAL_INFERENCE_TOKEN", + }); + const selected = f.input.binding; + const previous = { + ...selected, + ...nativeLocalIdentity(selected, 1), + schemaVersion: 1 as const, + providerId: "old-instance", + }; + vi.spyOn(localRuntime, "resolveHermesLocalSwitchRuntime").mockReturnValue({ + endpointUrl: selected.endpointUrl, + credentialValue: "test-only-secret", + authMode: "authenticated", + ownedProxy: true, + }); + f.adapter.importProviderProfile.mockResolvedValue({ + ok: false, + error: { kind: "command", reason: "profile_incompatible", message: "collision" }, + }); + await expect( + prepareNativeLocalSwitch({ + adapter: f.adapter, + previous, + provider: selected.provider, + agentName: "hermes", + gatewayName: selected.gatewayName, + sandboxName: selected.sandboxName, + binding: null, + resolveCredentialValue: () => "", + readAuthority: f.input.readAuthority, + writeAuthority: f.input.writeAuthority, + }), + ).rejects.toThrow("conflicts"); + expect(f.adapter.importProviderProfile).toHaveBeenCalledOnce(); + expect(f.adapter.createProvider).not.toHaveBeenCalled(); + expect(f.adapter.detachProvider).not.toHaveBeenCalled(); + expect(f.adapter.attachProvider).not.toHaveBeenCalled(); + }); + + it("verifies a recorded IPv4 attachment without expanding its permissions (#13544)", async () => { + const f = fixture(); + const current = await ensureNativeLocalProvider(f.input); + const expected = { ...receipt, ...nativeLocalIdentity(binding, 1) }; + f.adapter.getProvider.mockResolvedValue({ + ok: true, + value: { + name: expected.providerName, + type: expected.profileId, + credentialKeys: [expected.credentialEnv], + configKeys: [], + revision: { id: expected.providerId, resourceVersion: 1 }, + }, + }); + f.adapter.listProviderAttachments.mockResolvedValue({ + ok: true, + value: { names: [expected.providerName] }, + }); + vi.clearAllMocks(); + await expect( + verifyRecordedNativeLocalProviderAttachment({ + adapter: f.adapter, + expected, + sandboxName: "alice", + gatewayName: "nemoclaw", + agent: "langchain-deepagents-code", + provider: binding.provider, + }), + ).resolves.toEqual(expected); + const checked = f.adapter.inspectProviderProfile.mock.calls[0][0].expectedProfile; + expect(checked?.boundary.endpoints).toEqual( + prepareNativeLocalProfile(expected).document.endpoints, + ); + expect(JSON.stringify(checked)).not.toContain("fc00::/7"); + expect(current.profileId).not.toBe(expected.profileId); + expect(f.adapter.importProviderProfile).not.toHaveBeenCalled(); + expect(f.adapter.updateProvider).not.toHaveBeenCalled(); + await expect(ensureNativeLocalProvider({ ...f.input, expected })).rejects.toThrow( + "identity does not match", + ); + expect(f.adapter.createProvider).not.toHaveBeenCalled(); + }); + it("refuses a changed profile before attachment verification (#12558)", async () => { const f = fixture(); await ensureNativeLocalProvider(f.input); diff --git a/src/lib/inference/native-local/contract.ts b/src/lib/inference/native-local/contract.ts index 7ec089607ed..c5f35532def 100644 --- a/src/lib/inference/native-local/contract.ts +++ b/src/lib/inference/native-local/contract.ts @@ -75,7 +75,8 @@ export function normalizeNativeLocalBinding(value: unknown): NativeLocalBinding }; } -export function nativeLocalIdentity(binding: NativeLocalBinding) { +/** Version 1 remains readable for recorded IPv4-only attachments. New selections use version 2. */ +export function nativeLocalIdentity(binding: NativeLocalBinding, policyVersion: 1 | 2 = 2) { const normalized = normalizeNativeLocalBinding(binding); if (!normalized) throw new Error("Invalid native host-local inference boundary."); const profileHash = createHash("sha256") @@ -86,6 +87,10 @@ export function nativeLocalIdentity(binding: NativeLocalBinding) { normalized.endpointUrl, normalized.credentialEnv, normalized.authMode, + // Literal private IPv4 endpoints retain their existing immutable boundary. + ...(policyVersion === 2 && new URL(normalized.endpointUrl).hostname.startsWith("host.") + ? ["private-dual-stack-v1"] + : []), ...(normalized.agent === "hermes" ? [normalized.agent] : []), ]), ) @@ -112,7 +117,9 @@ export function normalizeNativeLocalProviderAttachment( const binding = normalizeNativeLocalBinding(value); if (!binding) return undefined; const receipt = value as Record; - const identity = nativeLocalIdentity(binding); + const current = nativeLocalIdentity(binding); + const legacy = nativeLocalIdentity(binding, 1); + const identity = receipt.profileId === current.profileId ? current : legacy; if ( receipt.schemaVersion !== 1 || receipt.profileId !== identity.profileId || diff --git a/src/lib/inference/native-local/profile.test.ts b/src/lib/inference/native-local/profile.test.ts new file mode 100644 index 00000000000..838d2bb705b --- /dev/null +++ b/src/lib/inference/native-local/profile.test.ts @@ -0,0 +1,114 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import fs from "node:fs"; +import os from "node:os"; +import path from "node:path"; +import { describe, expect, it, vi } from "vitest"; +import { createCliOpenShellProviderAdapter } from "../../adapters/openshell/provider-adapter-cli"; +import { + nativeLocalIdentity, + normalizeNativeLocalProviderAttachment, + type NativeLocalBinding, +} from "./contract"; +import { prepareNativeLocalProfile } from "./profile"; + +const binding: NativeLocalBinding = { + provider: "ollama-local", + agent: "openclaw", + endpointUrl: "http://host.openshell.internal:11435/v1", + credentialEnv: "NEMOCLAW_LOCAL_INFERENCE_TOKEN", + authMode: "authenticated", + gatewayName: "nemoclaw", + sandboxName: "alice", +}; + +function legacyAttachment() { + return { ...binding, ...nativeLocalIdentity(binding, 1), schemaVersion: 1, providerId: "owned" }; +} + +describe("native local address policy compatibility", () => { + it("preserves the recorded IPv4 boundary and gives new selections a distinct identity (#13544)", () => { + const legacy = legacyAttachment(); + const normalized = normalizeNativeLocalProviderAttachment(legacy); + expect(normalized).toEqual(legacy); + const oldProfile = prepareNativeLocalProfile(normalized!); + const profile = prepareNativeLocalProfile(binding); + expect(profile.profileId).not.toBe(oldProfile.profileId); + expect(profile.providerName).not.toBe(oldProfile.providerName); + expect(oldProfile.document.endpoints[0].allowed_ips).toEqual([ + "10.0.0.0/8", + "172.16.0.0/12", + "192.168.0.0/16", + ]); + const { allowed_ips: oldAddresses, ...oldEndpoint } = oldProfile.document.endpoints[0]; + const { allowed_ips: addresses, ...endpoint } = profile.document.endpoints[0]; + expect(addresses).toEqual([...oldAddresses, "fc00::/7"]); + expect(endpoint).toEqual(oldEndpoint); + expect(profile.document.credentials).toEqual(oldProfile.document.credentials); + expect(profile.document.binaries).toEqual(oldProfile.document.binaries); + expect( + normalizeNativeLocalProviderAttachment({ + ...legacy, + endpointUrl: "http://host.docker.internal:11435/v1", + }), + ).toBeUndefined(); + }); + + it("keeps literal IPv4 endpoints and identities restricted to one address (#13544)", () => { + const literal = { ...binding, endpointUrl: "http://192.168.1.20:11435/v1" }; + expect(nativeLocalIdentity(literal)).toEqual(nativeLocalIdentity(literal, 1)); + expect(prepareNativeLocalProfile(literal).document.endpoints[0].allowed_ips).toEqual([ + "192.168.1.20/32", + ]); + }); + + it.each([ + "http://unrelated.example:11435/v1", + "http://host.openshell.internal.evil:11435/v1", + "http://[fdc4:f303:9324::254]:11435/v1", + "http://[2001:4860:4860::8888]:11435/v1", + "http://host.openshell.internal:80/v1", + "http://host.openshell.internal:11435/v1/*", + ])("rejects an unqualified endpoint %s (#13544)", (endpointUrl) => { + expect(() => prepareNativeLocalProfile({ ...binding, endpointUrl })).toThrow("boundary"); + }); + + it("registers and reuses the new profile beside an installed IPv4 profile, then refuses drift (#13544)", async () => { + const legacy = prepareNativeLocalProfile(legacyAttachment()); + const profile = prepareNativeLocalProfile(binding); + const directory = fs.mkdtempSync(path.join(os.tmpdir(), "native-local-policy-test-")); + try { + const profilePath = path.join(directory, "profile.json"); + fs.writeFileSync(profilePath, JSON.stringify(profile.document)); + const run = vi + .fn() + .mockReturnValueOnce({ + status: 1, + stdout: "", + stderr: `Provider profile '${profile.profileId}' not found`, + }) + .mockReturnValueOnce({ status: 0, stdout: "", stderr: "" }) + .mockReturnValue({ status: 0, stdout: JSON.stringify(profile.document), stderr: "" }); + const adapter = createCliOpenShellProviderAdapter({ run, environment: {} }); + const request = { target: { kind: "named" as const, gatewayName: "nemoclaw" }, profilePath }; + expect(await adapter.importProviderProfile(request)).toMatchObject({ ok: true }); + expect(await adapter.importProviderProfile(request)).toMatchObject({ ok: true }); + expect(run.mock.calls.filter(([args]) => args.includes("import"))).toHaveLength(1); + expect(run.mock.calls.every(([args]) => !args.includes(legacy.profileId))).toBe(true); + run.mockClear(); + run.mockReturnValue({ + status: 0, + stdout: JSON.stringify({ ...profile.document, endpoints: legacy.document.endpoints }), + stderr: "", + }); + expect(await adapter.importProviderProfile(request)).toMatchObject({ + ok: false, + error: { reason: "profile_incompatible" }, + }); + expect(run.mock.calls.every(([args]) => args.includes("export"))).toBe(true); + } finally { + fs.rmSync(directory, { recursive: true, force: true }); + } + }); +}); diff --git a/src/lib/inference/native-local/profile.ts b/src/lib/inference/native-local/profile.ts index b0eba0bcebc..f206d186d9a 100644 --- a/src/lib/inference/native-local/profile.ts +++ b/src/lib/inference/native-local/profile.ts @@ -24,16 +24,21 @@ import { type NativeLocalProviderAttachment, } from "./contract"; -export { normalizeNativeLocalProviderAttachment }; +export { normalizeNativeLocalProviderAttachment, nativeLocalIdentity }; export type { NativeLocalProviderAttachment }; export function prepareNativeLocalProfile(input: NativeLocalBinding) { const binding = normalizeNativeLocalBinding(input); if (!binding) throw new Error("Invalid native host-local inference boundary."); - const identity = nativeLocalIdentity(binding); + // A recorded attachment keeps its original immutable permissions. Reselection + // creates the dual-stack profile through the existing ownership transaction. + const recorded = normalizeNativeLocalProviderAttachment(input); + const identity = recorded ?? nativeLocalIdentity(binding); + const dualStack = identity.profileId === nativeLocalIdentity(binding).profileId; const endpoint = new URL(binding.endpointUrl); return { - ...identity, + profileId: identity.profileId, + providerName: identity.providerName, credentialEnv: binding.credentialEnv, document: { id: identity.profileId, @@ -62,7 +67,7 @@ export function prepareNativeLocalProfile(input: NativeLocalBinding) { // admit its private resolution, never another hostname or port. allowed_ips: isIP(endpoint.hostname) ? [`${endpoint.hostname}/32`] - : ["10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"], + : ["10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", ...(dualStack ? ["fc00::/7"] : [])], rules: [ { allow: { method: "GET", path: `${endpoint.pathname}/models` } }, { allow: { method: "POST", path: `${endpoint.pathname}/chat/completions` } }, diff --git a/test/automation/e2e/platform-vitest-main-workflow.test.ts b/test/automation/e2e/platform-vitest-main-workflow.test.ts index d29f3719daa..debd200f904 100644 --- a/test/automation/e2e/platform-vitest-main-workflow.test.ts +++ b/test/automation/e2e/platform-vitest-main-workflow.test.ts @@ -1,6 +1,11 @@ // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 +import { spawnSync } from "node:child_process"; +import { mkdtempSync, rmSync } from "node:fs"; +import os from "node:os"; +import path from "node:path"; + import { describe, expect, it } from "vitest"; import { @@ -103,8 +108,56 @@ describe("platform evidence workflow", () => { }); expect(detection.run).toContain("-User $env:WSL_TEST_USER"); expect(live.run).toContain("-User $env:WSL_TEST_USER"); + expect(live.run).toContain('test "`$(git rev-parse HEAD)" = "$env:GITHUB_SHA"'); }); + it.each([0, 17])( + "preserves full-suite status %s on the native Docker WSL runner", + (fullStatus) => { + const run = step("wsl-vitest", "Run WSL live E2E").run ?? ""; + const script = run.match(/\$script = @"\n([\s\S]*?)\n"@/u)?.[1]; + expect(script).toBeDefined(); + const workspace = mkdtempSync(path.join(os.tmpdir(), "wsl-native-docker-")); + try { + const shell = script! + .replaceAll("$workdir", '"$TEST_WORKSPACE"') + .replaceAll("$exports", "") + .replaceAll("$env:GITHUB_SHA", "test-revision") + .replaceAll("`", ""); + const result = spawnSync( + "bash", + [ + "-c", + ` + git() { echo test-revision; } + docker() { echo Ubuntu; } + python3() { return 42; } + npx() { + case "$*" in + *full-e2e.test.ts*) return "$TEST_FULL_STATUS" ;; + *) echo 'Native Docker has no IPv6-only host alias' >&2; return 42 ;; + esac + } + ${shell} + `, + ], + { + encoding: "utf8", + env: { + PATH: process.env.PATH, + TEST_WORKSPACE: workspace, + TEST_FULL_STATUS: String(fullStatus), + }, + }, + ); + expect(result.error).toBeUndefined(); + expect(result.status, result.stderr).toBe(fullStatus); + } finally { + rmSync(workspace, { recursive: true, force: true }); + } + }, + ); + it("keeps credentialed macOS E2E independent from non-live shard failures", () => { const nonLive = job("macos-vitest"); const liveJob = job("macos-live-e2e"); diff --git a/test/e2e/README.md b/test/e2e/README.md index ae0c5945d06..aafda01773b 100644 --- a/test/e2e/README.md +++ b/test/e2e/README.md @@ -110,6 +110,34 @@ tests. The real-child input cases include a relative symbolic-link chain to a re file with spaces while stdin contains competing data. This target is selectable for Docker and Podman through the existing runtime matrix. +## WSL2 IPv6 native-local policy proof + +`TC-INF-19` requires WSL2 Docker and IPv6-only ULA resolution for +`host.openshell.internal`. It binds the authenticated host fixture on `::`, +rejects DNS answers with an IPv4 fallback, and sends a sandbox chat through the +OpenShell-issued credential handle. Public, link-local, and loopback IPv6 requests +must receive `policy_denied` HTTP 403; a timeout does not satisfy denial. +Fixture cleanup removes the sandbox and host endpoint. + +The `inference-routing-openclaw-native` catalogue target runs on Ubuntu Docker and +Podman. It skips `TC-INF-19` and does not qualify the WSL2 regression. +The WSL lane in `CI / Platform Compatibility` installs native Ubuntu Docker. +It does not provision IPv6-only ULA resolution, so it runs its existing full +E2E suite without invoking `TC-INF-19`. + +WSL2 ARM Docker Desktop qualification remains unverified. No PR catalogue +selector currently provides that platform. Run `TC-INF-19` on a prepared +WSL2 Docker Desktop host with IPv6-only ULA resolution before claiming this +qualification. A passing Ubuntu catalogue run or WSL non-live shard cannot +replace this missing live evidence. +The source tests own CIDR membership and receipt compatibility. E2E support tests +own resolution classification and probe command construction. +On a prepared WSL2 Docker Desktop host, run: + +```bash +NEMOCLAW_RUN_LIVE_E2E=1 npx vitest run --project e2e-live test/e2e/live/openclaw-inference-switch.test.ts -t '^TC-INF-19' +``` + ## CI execution shape ### Protected DGX Spark qualification diff --git a/test/e2e/fixtures/inference-routing-openclaw-native.ts b/test/e2e/fixtures/inference-routing-openclaw-native.ts index 3ef028d8547..31820d74706 100644 --- a/test/e2e/fixtures/inference-routing-openclaw-native.ts +++ b/test/e2e/fixtures/inference-routing-openclaw-native.ts @@ -23,6 +23,7 @@ type NativeOpenClawContext = Pick< export async function onboardNativeOpenClaw( authenticated: boolean, { artifacts, cleanup, host, progress, runtimeProvider, sandbox }: NativeOpenClawContext, + listenHost: "0.0.0.0" | "::" = "0.0.0.0", ) { await requireLivePrerequisites(host, runtimeProvider); const owner = inferenceSandboxName(authenticated ? "e2e-oc-auth" : "e2e-oc-none"); @@ -34,7 +35,7 @@ export async function onboardNativeOpenClaw( model, additionalModels: authenticated ? [switchedModel] : [], chatContent: "PONG", - host: "0.0.0.0", + host: listenHost, port: authenticated ? 8081 : 8000, publicHost: "host.openshell.internal", requireAuth: true, diff --git a/test/e2e/fixtures/native-local-ipv6-evidence.ts b/test/e2e/fixtures/native-local-ipv6-evidence.ts new file mode 100644 index 00000000000..4d0dc10bcfd --- /dev/null +++ b/test/e2e/fixtures/native-local-ipv6-evidence.ts @@ -0,0 +1,57 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import { BlockList, isIP } from "node:net"; +import os from "node:os"; + +/** Require only ULA answers so a successful request cannot hide an IPv4 fallback. */ +export function nativeLocalUlaOnlyResolution(output: string): boolean { + const addresses: unknown = JSON.parse(output); + const ula = new BlockList(); + ula.addSubnet("fc00::", 7, "ipv6"); + return ( + Array.isArray(addresses) && + addresses.length > 0 && + addresses.every( + (address: unknown) => + typeof address === "string" && isIP(address) === 6 && ula.check(address, "ipv6"), + ) + ); +} + +/** Observe both address families to reject an unexercised IPv4 fallback. */ +export function nativeLocalIpv6ResolutionCommand(): string[] { + return [ + "python3", + "-c", + "import json,socket; print(json.dumps(sorted({r[4][0] for r in socket.getaddrinfo('host.openshell.internal',8081,type=socket.SOCK_STREAM)})))", + ]; +} + +/** Require a policy response rather than treating a network timeout as a denial. */ +export function nativeLocalIpv6DeniedCommand(address: string, body: string): string[] { + if (isIP(address) !== 6) throw new Error("The denial probe requires an IPv6 literal."); + return [ + "curl", + "-sS", + "--max-time", + "15", + "--noproxy", + "", + "--write-out", + "\n%{http_code}", + "--header", + "Content-Type: application/json", + "--data", + body, + `http://[${address}]:8081/v1/chat/completions`, + ]; +} + +/** This scenario requires the WSL Docker host bridge, not the Podman runtime. */ +export function isWslDockerIpv6TestHost( + release = os.release(), + runtime = process.env.NEMOCLAW_GATEWAY_RUNTIME, +): boolean { + return /microsoft/i.test(release) && runtime !== "podman"; +} diff --git a/test/e2e/live/openclaw-inference-switch.test.ts b/test/e2e/live/openclaw-inference-switch.test.ts index b3f21997bed..243a0bf19b5 100644 --- a/test/e2e/live/openclaw-inference-switch.test.ts +++ b/test/e2e/live/openclaw-inference-switch.test.ts @@ -78,6 +78,13 @@ import { onboardNativeOpenClaw, requestNativeOpenClaw, } from "../fixtures/inference-routing-openclaw-native.ts"; +import { + nativeLocalUlaOnlyResolution, + isWslDockerIpv6TestHost, + nativeLocalIpv6ResolutionCommand, + nativeLocalIpv6DeniedCommand, +} from "../fixtures/native-local-ipv6-evidence.ts"; +import { nativeLocalChatCommand } from "../fixtures/native-local-chat.ts"; import { assertAgentExecutionSucceeded } from "./gpu-e2e-helpers.ts"; import { hostedCredentialScanCommand } from "./inference-routing-credential-scan.ts"; import { @@ -1434,3 +1441,60 @@ test( expect(requests.every((request) => request.auth === "ok")).toBe(true); }, ); + +test.skipIf(!isWslDockerIpv6TestHost())( + "TC-INF-19 OpenClaw admits a WSL2 IPv6 host bridge and denies other IPv6 destinations (#13544)", + { + timeout: ONBOARD_SINGLE_FINAL_HANDOFF_TEST_TIMEOUT_MS, + meta: { + e2ePhases: [ + "confirm live inference prerequisites", + "onboard native OpenClaw owner", + "verify IPv6 policy boundary", + ], + }, + }, + async ({ artifacts, cleanup, host, progress, runtimeProvider, sandbox }) => { + progress.phase("onboard native OpenClaw owner"); + const context = { artifacts, cleanup, host, progress, runtimeProvider, sandbox }; + const selected = await onboardNativeOpenClaw(true, context, "::"); + const { owner, apiKey, fake, onboard, attachment } = selected; + const options = { env: sandboxAccessEnv(), timeoutMs: 150_000, redactionValues: [apiKey] }; + expectOnboardSuccess(onboard, `${owner} IPv6 onboard`); + progress.phase("verify IPv6 policy boundary"); + const resolution = await sandbox.exec(owner, nativeLocalIpv6ResolutionCommand(), { + artifactName: `${owner}-ipv6-resolution`, + env: sandboxAccessEnv(), + timeoutMs: 30_000, + }); + expect(resolution.exitCode, resultText(resolution)).toBe(0); + expect(nativeLocalUlaOnlyResolution(resolution.stdout), resolution.stdout).toBe(true); + const offset = fake.requests().length; + const body = JSON.stringify({ + model: "nemoclaw-openclaw-native-local", + messages: [{ role: "user", content: "PONG" }], + max_tokens: 8, + }); + const reply = await sandbox.execShell( + owner, + trustedSandboxShellScript(nativeLocalChatCommand(attachment!.endpointUrl, body, "-fsS")), + { ...options, artifactName: `${owner}-ipv6-chat` }, + ); + expect(reply.exitCode, resultText(reply)).toBe(0); + const requests = fake.requests().slice(offset); + expect(requests.some((r) => r.path === "/v1/chat/completions" && r.auth === "ok")).toBe(true); + const [publicIpv6, linkLocal, loopback] = await Promise.all( + ["2001:4860:4860::8888", "fe80::1", "::1"].map((address) => + sandbox.exec(owner, nativeLocalIpv6DeniedCommand(address, body), { + artifactName: `${owner}-ipv6-deny-${address.replaceAll(":", "-")}`, + env: sandboxAccessEnv(), + timeoutMs: 30_000, + }), + ), + ); + const policyDenied = /"error"\s*:\s*"policy_denied"[\s\S]*\n403$/; + expect(publicIpv6.stdout, resultText(publicIpv6)).toMatch(policyDenied); + expect(linkLocal.stdout, resultText(linkLocal)).toMatch(policyDenied); + expect(loopback.stdout, resultText(loopback)).toMatch(policyDenied); + }, +); diff --git a/test/e2e/mock-parity.json b/test/e2e/mock-parity.json index f0b2407051e..48d684ecd4a 100644 --- a/test/e2e/mock-parity.json +++ b/test/e2e/mock-parity.json @@ -881,7 +881,8 @@ "test/e2e/fixtures/admin-approval-connect.ts", "test/e2e/fixtures/admin-approval-connect.sh", "test/e2e/fixtures/issue-4462-admin-approval-evidence.ts", - "test/e2e/fixtures/managed-image-receipt.ts" + "test/e2e/fixtures/managed-image-receipt.ts", + "test/e2e/fixtures/native-local-ipv6-evidence.ts" ], "fast": [ "src/lib/inference/native-local.test.ts", @@ -902,7 +903,8 @@ "test/e2e/support/openclaw-inference-switch-helpers.test.ts", "test/e2e/support/public-nvidia-switch-provider.test.ts", "test/security/admin-approval-helper.test.ts", - "test/e2e/support/hosted-inference.test.ts" + "test/e2e/support/hosted-inference.test.ts", + "test/e2e/support/native-local-ipv6-evidence.test.ts" ] }, { diff --git a/test/e2e/support/inference-switch-workflow-boundary.test.ts b/test/e2e/support/inference-switch-workflow-boundary.test.ts index d47e58126c8..7763f6d8170 100644 --- a/test/e2e/support/inference-switch-workflow-boundary.test.ts +++ b/test/e2e/support/inference-switch-workflow-boundary.test.ts @@ -14,6 +14,20 @@ import { DEFAULT_CLOUD_MODEL } from "../../../src/lib/inference/config.ts"; import { PUBLIC_NVIDIA_SWITCH_MODEL } from "../live/public-nvidia-switch-provider.ts"; describe("inference-switch catalogue boundary", () => { + it("selects native-local enforcement coverage when IPv6 evidence changes (#13544)", () => { + expect( + catalogueTargetsForChangedFiles(["test/e2e/fixtures/native-local-ipv6-evidence.ts"]).map( + (target) => target.id, + ), + ).toContain("inference-routing-openclaw-native"); + expect( + catalogueTarget("inference-routing-openclaw-native").environmentOrInferenceEndpoint, + ).toContain("Ubuntu"); + expect( + catalogueTarget("inference-routing-openclaw-native").environmentOrInferenceEndpoint, + ).toContain("skips WSL-only TC-INF-19"); + }); + it.each([ "src/lib/inference/native-provider/contract.ts", "src/lib/inference/native-provider/custom-setup.ts", diff --git a/test/e2e/support/native-local-ipv6-evidence.test.ts b/test/e2e/support/native-local-ipv6-evidence.test.ts new file mode 100644 index 00000000000..b992c8ad2fa --- /dev/null +++ b/test/e2e/support/native-local-ipv6-evidence.test.ts @@ -0,0 +1,113 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import { describe, expect, it } from "vitest"; +import { startTestProgress } from "../fixtures/progress.ts"; +import { startFakeOpenAiCompatibleServer } from "../fixtures/fake-openai-compatible.ts"; +import { + nativeLocalUlaOnlyResolution, + isWslDockerIpv6TestHost, + nativeLocalIpv6ResolutionCommand, + nativeLocalIpv6DeniedCommand, +} from "../fixtures/native-local-ipv6-evidence.ts"; + +describe("native local IPv6 resolution evidence", () => { + it.each([ + ['["fdc4:f303:9324::254"]', true], + ['["fc00::1", "fdff::ffff"]', true], + ['["fdc4:f303:9324::254", "192.168.65.254"]', false], + ['["2001:4860:4860::8888"]', false], + ['["fe80::1"]', false], + ['["::1"]', false], + ['["192.168.65.254"]', false], + ["[]", false], + ["[null]", false], + ['{"address":"fdc4:f303:9324::254"}', false], + ])("classifies resolver evidence %s as IPv6-only ULA=%s", (output, expected) => { + expect(nativeLocalUlaOnlyResolution(output)).toBe(expected); + }); + it.each([ + ["6.6.87.2-microsoft-standard-WSL2", "docker", true], + ["6.6.87.2-microsoft-standard-WSL2", "podman", false], + ["6.8.0-generic", "docker", false], + ["Darwin Kernel Version 25", "docker", false], + ])("selects the WSL Docker scenario for %s with %s=%s", (release, runtime, expected) => { + expect(isWslDockerIpv6TestHost(release, runtime)).toBe(expected); + }); + it("queries both address families and keeps policy response evidence separate from transport errors", () => { + const resolution = nativeLocalIpv6ResolutionCommand(); + expect(resolution.slice(0, 2)).toEqual(["python3", "-c"]); + expect(resolution[2]).toContain( + "socket.getaddrinfo('host.openshell.internal',8081,type=socket.SOCK_STREAM)", + ); + const command = nativeLocalIpv6DeniedCommand("::1", '{"model":"fixture"}'); + expect(command).toEqual([ + "curl", + "-sS", + "--max-time", + "15", + "--noproxy", + "", + "--write-out", + "\n%{http_code}", + "--header", + "Content-Type: application/json", + "--data", + '{"model":"fixture"}', + "http://[::1]:8081/v1/chat/completions", + ]); + expect(() => nativeLocalIpv6DeniedCommand("host.openshell.internal", "{}")).toThrow( + "IPv6 literal", + ); + }); + it("serves authenticated chat on the IPv6 listener used by the live fixture", async () => { + const apiKey = "dummy"; + const progress = startTestProgress( + "IPv6 host fixture", + ["serve fixture", "verify authentication"], + { logLine: () => undefined }, + ); + progress.phase("serve fixture"); + const server = await startFakeOpenAiCompatibleServer({ + progress, + host: "::", + apiKey, + model: "ipv6-test", + requireAuth: true, + }); + try { + progress.phase("verify authentication"); + const endpoint = new URL(server.baseUrl); + endpoint.hostname = "[::1]"; + const body = JSON.stringify({ + model: "ipv6-test", + messages: [{ role: "user", content: "PONG" }], + }); + const unauthenticated = await fetch(`${endpoint}/chat/completions`, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body, + }); + await unauthenticated.text(); + expect(unauthenticated.status).toBe(401); + const response = await fetch(`${endpoint}/chat/completions`, { + method: "POST", + headers: { "Content-Type": "application/json", Authorization: `Bearer ${apiKey}` }, + body, + }); + await response.text(); + expect(response.status).toBe(200); + expect( + server + .requests() + .some((request) => request.path === "/v1/chat/completions" && request.auth === "ok"), + ).toBe(true); + } finally { + await server.close(); + progress.stop(); + } + }); + it("rejects malformed resolver output", () => { + expect(() => nativeLocalUlaOnlyResolution("not JSON")).toThrow(); + }); +}); diff --git a/test/e2e/support/openclaw-inference-switch-baseline.test.ts b/test/e2e/support/openclaw-inference-switch-baseline.test.ts index 7ad2cbc9ecb..2d5470e1e1f 100644 --- a/test/e2e/support/openclaw-inference-switch-baseline.test.ts +++ b/test/e2e/support/openclaw-inference-switch-baseline.test.ts @@ -2,13 +2,16 @@ // SPDX-License-Identifier: Apache-2.0 import fs from "node:fs"; +import os from "node:os"; import { afterEach, expect, it, vi } from "vitest"; const captured = vi.hoisted(() => ({ test: vi.fn() })); vi.mock("../fixtures/e2e-test.ts", async () => ({ expect: (await import("vitest")).expect, - test: captured.test, + test: Object.assign(captured.test, { + skipIf: (skip: boolean) => (skip ? vi.fn() : captured.test), + }), })); vi.mock("../fixtures/managed-image-receipt.ts", () => ({ selectedE2eManagedImageReference: () => "example.invalid/openclaw@sha256:" + "a".repeat(64), @@ -47,9 +50,18 @@ async function loadNativeSwitchRun(nativeCustom = false) { return { progress, run }; } -it.each([false, true])( - "selects the authenticated baseline with native custom=%s", - async (nativeCustom) => { +it.each( + [false, true].flatMap((nativeCustom) => + ["6.8.0-generic", "6.6.87.2-microsoft-standard-WSL2"].map((release) => ({ + nativeCustom, + release, + })), + ), +)( + "selects the authenticated baseline with native custom=$nativeCustom on $release", + async ({ nativeCustom, release }) => { + vi.spyOn(os, "release").mockReturnValue(release); + vi.stubEnv("NEMOCLAW_GATEWAY_RUNTIME", "docker"); const { progress, run } = await loadNativeSwitchRun(nativeCustom); const result = { exitCode: 0, stdout: "", stderr: "" }; const stop = new Error("onboarding captured"); diff --git a/test/helpers/inference-set-openclaw-native-local.ts b/test/helpers/inference-set-openclaw-native-local.ts index 40fc328f432..c14ee522b9a 100644 --- a/test/helpers/inference-set-openclaw-native-local.ts +++ b/test/helpers/inference-set-openclaw-native-local.ts @@ -24,7 +24,7 @@ export const attachment = { providerId: "owned-local-provider", }; -export function fixture() { +export function fixture(selectedAttachment = attachment) { const config: ConfigObject = { agents: { defaults: { model: { primary: "inference/old-model" } } }, models: { @@ -48,17 +48,21 @@ export function fixture() { model: "old-model", endpointUrl: binding.endpointUrl, preferredInferenceApi: "openai-completions", - nativeLocalProviderAttachment: attachment, + nativeLocalProviderAttachment: selectedAttachment, }, }); } -export function switchingFixture() { - const deps = fixture(); +export function switchingFixture( + previous = attachment, + provider: "ollama-local" | "vllm-local" = "vllm-local", +) { + const deps = fixture(previous); const nextBinding = { ...binding, - provider: "vllm-local" as const, - endpointUrl: "http://host.openshell.internal:8000/v1", + provider, + endpointUrl: + provider === "ollama-local" ? binding.endpointUrl : "http://host.openshell.internal:8000/v1", }; const next = { ...nextBinding, @@ -75,9 +79,9 @@ export function switchingFixture() { }; deps.resolveLocalSwitchRuntime = () => ({ endpointUrl: next.endpointUrl, - credentialValue: "dummy", + credentialValue: provider === "ollama-local" ? "ollama" : "dummy", authMode: "sentinel", - ownedProxy: false, + ownedProxy: provider === "ollama-local", }); const adapter = deps.providerAdapter; const original = { ...adapter }; diff --git a/tools/e2e/target-catalogue.mts b/tools/e2e/target-catalogue.mts index 55edae99262..af313249020 100644 --- a/tools/e2e/target-catalogue.mts +++ b/tools/e2e/target-catalogue.mts @@ -1052,7 +1052,7 @@ export const E2E_TARGET_CATALOGUE: readonly E2eCatalogueTarget[] = [ displayName: "Inference: OpenClaw native local requests and isolation", agentRuntime: "openclaw", environmentOrInferenceEndpoint: - "Ubuntu; authenticated llama.cpp and credentialless vLLM fixtures", + "Ubuntu; authenticated llama.cpp and credentialless vLLM fixtures; skips WSL-only TC-INF-19", profile: "standard", timeoutMinutes: OPENCLAW_NATIVE_LOCAL_TARGET_TIMEOUT_MINUTES, installMode: "none", @@ -1068,6 +1068,7 @@ export const E2E_TARGET_CATALOGUE: readonly E2eCatalogueTarget[] = [ "src/lib/actions/sandbox/inference-invocation-probe.ts", "src/lib/actions/sandbox/inference-route-health.ts", "test/e2e/fixtures/inference-routing-openclaw-native.ts", + "test/e2e/fixtures/native-local-ipv6-evidence.ts", "tools/e2e/onboard-timeout-contract.mts", ], }),