Skip to content

A full-featured download manager.

fix: repair CI, package-smoke, and NAT integration workflow failures (#1836)

Dr_rOot31bd9f9eff52
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 00000000..71fd2c71
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,5 @@
+# Reviewed license texts are hash-pinned byte-for-byte in
+# scripts/third-party-notices.config.json (verified by
+# scripts/generate-third-party-notices.mjs). Disable line-ending conversion so
+# Windows checkouts (autocrlf) stay byte-identical to the committed blobs.
+THIRD_PARTY_LICENSES/** -text
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index ebc55e79..f534fa8f 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -192,9 +192,13 @@ jobs:
name: Package smoke / ${{ matrix.target }}
runs-on: ${{ matrix.os }}
timeout-minutes: 45
+ # No CARGO_TARGET_*_MUSL_LINKER override: rustc's musl std is
+ # self-contained (bundled musl CRT + libc.a, linked via the host cc as
+ # `-static-pie`). Forcing Ubuntu's musl-gcc wrapper mixed its older musl
+ # CRT into the link and emitted a dynamic-loader INTERP, so every x86_64
+ # musl binary segfaulted at load (runs 31322798699 / 31324102504 /
+ # 31349513764).
env:
- CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER: musl-gcc
- CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER: musl-gcc
MACOSX_DEPLOYMENT_TARGET: ${{ matrix.platform == 'darwin' && '12.0' || '' }}
strategy:
fail-fast: false
@@ -248,12 +252,6 @@ jobs:
node-version: 24
cache: pnpm
- - name: Install musl toolchain
- if: matrix.platform == 'linux'
- run: |
- sudo apt-get update
- sudo apt-get install --yes musl-tools
-
- name: Setup Rust
uses: dtolnay/rust-toolchain@4cda84d5c5c54efe2404f9d843567869ab1699d4 # stable
with:
@@ -264,8 +262,6 @@ jobs:
# rust_target. Tests therefore execute the target binary directly; no
# Rosetta, QEMU, Wine, or compile-only result is presented as a test.
- name: Tests (native target)
- # A SIGSEGV on x86_64-musl (run 31322798699) did not reproduce in a
- # CI-equivalent container; keep full backtraces on until root-caused.
env:
RUST_BACKTRACE: full
run: >-
diff --git a/.github/workflows/flatpak.yml b/.github/workflows/flatpak.yml
index f80c58bd..601a1539 100644
--- a/.github/workflows/flatpak.yml
+++ b/.github/workflows/flatpak.yml
@@ -115,20 +115,17 @@ jobs:
- name: Install dependencies
run: pnpm install --frozen-lockfile --ignore-scripts
- - name: Install musl toolchain for the x86_64 host companion smoke
- run: |
- sudo apt-get update -qq
- sudo apt-get install -y --no-install-recommends musl-tools
-
- name: Setup Rust for the x86_64 host companion smoke
uses: dtolnay/rust-toolchain@4cda84d5c5c54efe2404f9d843567869ab1699d4 # stable
with:
toolchain: 1.94.1
targets: x86_64-unknown-linux-musl
+ # rustc's musl std is self-contained; overriding the linker with
+ # Ubuntu's musl-gcc mixes CRTs and produces load-time SIGSEGVs (see
+ # ci.yml package-targets).
- name: Build and package x86_64 Flatpak host companion
env:
- CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER: musl-gcc
SOURCE_DATE_EPOCH: '0'
run: |
node packages/native-host/build.mjs --platform linux --arch x64
@@ -265,10 +262,14 @@ jobs:
- name: Smoke-test installed payload
env:
MOTRIX_FLATPAK_ARCH: ${{ matrix.electron_arch }}
- MOTRIX_SMOKE_HOME: ${{ runner.temp }}/flatpak-smoke-home
- MOTRIX_SMOKE_DATA: ${{ runner.temp }}/flatpak-smoke-data
- MOTRIX_SMOKE_CONFIG: ${{ runner.temp }}/flatpak-smoke-config
+ # Container-local /tmp, not runner.temp: the workspace mount (/__w)
+ # is owned by neither the container user nor root, and the host
+ # companion refuses install trees under such ancestors by design.
+ MOTRIX_SMOKE_HOME: /tmp/flatpak-smoke-home
+ MOTRIX_SMOKE_DATA: /tmp/flatpak-smoke-data
+ MOTRIX_SMOKE_CONFIG: /tmp/flatpak-smoke-config
run: |
+ set -x
export HOME="$MOTRIX_SMOKE_HOME"
export XDG_DATA_HOME="$MOTRIX_SMOKE_DATA"
export XDG_CONFIG_HOME="$MOTRIX_SMOKE_CONFIG"
@@ -282,6 +283,7 @@ jobs:
--env=MOTRIX_EXPECTED_ARCH="$MOTRIX_FLATPAK_ARCH" \
app.motrix.native \
-eu -c '
+ set -x
aria2c="/app/motrix/resources/extra/linux/$MOTRIX_EXPECTED_ARCH/aria2c"
test -x "$aria2c"
test ! -e /app/motrix/resources/bin/motrix-native-host
@@ -302,7 +304,9 @@ jobs:
printf "%s\n" "$output" | grep -qF "BitTorrent"
printf "%s\n" "$output" | grep -qF "HTTPS"
printf "%s\n" "$output" | grep -qF "SFTP"
- printf "%s\n" "$output" | grep -qF "WebSocket"
+ # aria2c --version never lists WebSocket; assert the wslay RPC
+ # handshake path is compiled in by scanning the binary itself.
+ grep -qa "Sec-WebSocket-Accept" "$aria2c"
'
broker_hex="$(
printf 'MXBR\001\000\000\000\025\000\000\000%s' \
@@ -319,14 +323,21 @@ jobs:
- name: Smoke-test Browser Native Messaging through the host companion
if: matrix.flatpak_arch == 'x86_64'
env:
- MOTRIX_SMOKE_HOME: ${{ runner.temp }}/flatpak-smoke-home
- MOTRIX_SMOKE_DATA: ${{ runner.temp }}/flatpak-smoke-data
- MOTRIX_SMOKE_CONFIG: ${{ runner.temp }}/flatpak-smoke-config
+ # Container-local /tmp, not runner.temp: the workspace mount (/__w)
+ # is owned by neither the container user nor root, and the host
+ # companion refuses install trees under such ancestors by design.
+ MOTRIX_SMOKE_HOME: /tmp/flatpak-smoke-home
+ MOTRIX_SMOKE_DATA: /tmp/flatpak-smoke-data
+ MOTRIX_SMOKE_CONFIG: /tmp/flatpak-smoke-config
run: |
+ set -x
export HOME="$MOTRIX_SMOKE_HOME"
export XDG_DATA_HOME="$MOTRIX_SMOKE_DATA"
export XDG_CONFIG_HOME="$MOTRIX_SMOKE_CONFIG"
- companion_payload="$RUNNER_TEMP/flatpak-host-companion-payload"
+ # The flathub infra container does not ship flatpak at /usr/bin —
+ # resolve it from PATH like every other step in this job does.
+ flatpak_bin="$(command -v flatpak)"
+ companion_payload=/tmp/flatpak-host-companion-payload
mkdir -p "$companion_payload"
tar -xzf \
"$RUNNER_TEMP/flatpak-host-companion/Motrix-Native-Host-0.0.0-ci-linux-x64.tar.gz" \
@@ -334,7 +345,7 @@ jobs:
-C "$companion_payload"
archive_companion="$companion_payload/motrix-flatpak-native-host"
installed_companion="${XDG_DATA_HOME:-$HOME/.local/share}/motrix/native-messaging/motrix-flatpak-native-host"
- "$archive_companion" install --flatpak-bin /usr/bin/flatpak
+ "$archive_companion" install --flatpak-bin "$flatpak_bin"
"$installed_companion" status
ready_file="$RUNNER_TEMP/flatpak-nonce-server.ready"
@@ -345,7 +356,7 @@ jobs:
fi
"$installed_companion" uninstall || true
# shellcheck disable=SC2016
- /usr/bin/flatpak run --command=sh app.motrix.native -c '
+ "$flatpak_bin" run --command=sh app.motrix.native -c '
rm -f "${XDG_CONFIG_HOME:?}/motrix/bridge/endpoint.json"
' || true
rm -f "$ready_file"
@@ -355,7 +366,7 @@ jobs:
rm -f "$ready_file"
# The payload is expanded by sh inside the Flatpak.
# shellcheck disable=SC2016
- /usr/bin/flatpak run --command=sh app.motrix.native -eu -c '
+ "$flatpak_bin" run --command=sh app.motrix.native -eu -c '
bridge_dir="${XDG_CONFIG_HOME:?}/motrix/bridge"
mkdir -p "$bridge_dir"
printf "%s\n" "{\"port\":55809}" > "$bridge_dir/endpoint.json"
diff --git a/.github/workflows/nat-integration.yml b/.github/workflows/nat-integration.yml
index 28b00485..6abb60c4 100644
--- a/.github/workflows/nat-integration.yml
+++ b/.github/workflows/nat-integration.yml
@@ -11,17 +11,23 @@ on:
- 'src/core/nat/**'
- 'tests/docker/**'
- 'tests/integration/**'
+ - 'scripts/fuzz-nat-codecs.mjs'
- '.github/workflows/nat-integration.yml'
pull_request:
branches: [main]
paths:
- 'src/core/nat/**'
- 'tests/docker/**'
+ - 'tests/integration/**'
+ - 'scripts/fuzz-nat-codecs.mjs'
+ - '.github/workflows/nat-integration.yml'
jobs:
nat-docker-matrix:
runs-on: ubuntu-latest
- timeout-minutes: 20
+ # Observed ~2 min end-to-end (image build + compose up + 5 tests);
+ # 10 minutes flags a hang quickly instead of idling out a runner.
+ timeout-minutes: 10
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
@@ -63,9 +69,9 @@ jobs:
nat-fuzz-regression:
runs-on: ubuntu-latest
- # Must fit checkout + cold-cache pnpm install + the 5-minute fuzz run;
- # 10 minutes was cancelled at 10m16s on the first cache-less run.
- timeout-minutes: 20
+ # Worst case observed: ~1 min setup + the 5-minute main-branch fuzz
+ # budget. Anything past 10 minutes is a hang, not a slow run.
+ timeout-minutes: 10
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271 # v6.0.9
@@ -76,5 +82,10 @@ jobs:
node-version: 24
cache: pnpm
- run: pnpm install --frozen-lockfile
- - name: 5-minute codec fuzz
- run: pnpm run fuzz:nat:ci
+ # PRs get a 60s smoke (per-codec throughput is ~10^4..10^6 iters/sec,
+ # so every codec still sees millions of inputs); each main push keeps
+ # the full 5-minute budget.
+ - name: Codec fuzz
+ run: >-
+ pnpm exec node --import tsx scripts/fuzz-nat-codecs.mjs
+ --duration=${{ github.event_name == 'pull_request' && '60' || '300' }}
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 40ad4102..9d8a6b13 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -125,9 +125,10 @@ jobs:
electron_builder_args: --win --x64
resources_dir: release/win-unpacked/resources
+ # rustc's musl std is self-contained; overriding the linker with Ubuntu's
+ # musl-gcc mixes CRTs and produces binaries that SIGSEGV at load (see
+ # ci.yml package-targets).
env:
- CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER: musl-gcc
- CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER: musl-gcc
# Electron 43 requires macOS 12 even though the locked aria2 binaries
# themselves are built with an 11.0 deployment target.
MACOSX_DEPLOYMENT_TARGET: ${{ matrix.platform == 'darwin' && '12.0' || '' }}
@@ -152,7 +153,7 @@ jobs:
if: matrix.platform == 'linux'
run: |
sudo apt-get update
- sudo apt-get install --yes musl-tools rpm
+ sudo apt-get install --yes rpm
- name: Setup Rust
uses: dtolnay/rust-toolchain@4cda84d5c5c54efe2404f9d843567869ab1699d4 # stable
diff --git a/.github/workflows/snap.yml b/.github/workflows/snap.yml
index bf8e67da..d3b972e2 100644
--- a/.github/workflows/snap.yml
+++ b/.github/workflows/snap.yml
@@ -99,9 +99,9 @@ jobs:
needs: preflight
runs-on: ${{ matrix.os }}
timeout-minutes: 90
- env:
- CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER: musl-gcc
- CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER: musl-gcc
+ # rustc's musl std is self-contained; overriding the linker with Ubuntu's
+ # musl-gcc mixes CRTs and produces binaries that SIGSEGV at load (see
+ # ci.yml package-targets).
strategy:
fail-fast: false
matrix:
@@ -136,7 +136,7 @@ jobs:
- name: Install native build tools
run: |
sudo apt-get update
- sudo apt-get install --yes musl-tools squashfs-tools
+ sudo apt-get install --yes squashfs-tools
- name: Setup Rust
uses: dtolnay/rust-toolchain@4cda84d5c5c54efe2404f9d843567869ab1699d4 # stable
@@ -156,6 +156,12 @@ jobs:
env:
MOTRIX_SKIP_ENGINE_FETCH: '1'
+ # Same side-effects-cache guard as the ci job: pnpm can reuse an
+ # electron store entry recorded while its build script was blocked,
+ # leaving dist/ absent. The notice contract needs dist/LICENSE.
+ - name: Ensure Electron runtime payload
+ run: node node_modules/electron/install.js
+
- name: Fetch target aria2
run: >-
pnpm run fetch:engine
diff --git a/flatpak/app.motrix.native.yml b/flatpak/app.motrix.native.yml
index 5e5d058a..133536da 100644
--- a/flatpak/app.motrix.native.yml
+++ b/flatpak/app.motrix.native.yml
@@ -97,6 +97,9 @@ modules:
no-make-install: true
post-install:
- |
+ # set -e is load-bearing: without it the for-loop's exit status is
+ # only the LAST grep, and any earlier missing feature is swallowed.
+ set -e
output="$(src/aria2c --version)"
printf '%s\n' "$output"
printf '%s\n' "$output" | grep -qF 'aria2 version 1.37.0-motrix.3'
@@ -110,11 +113,13 @@ modules:
'Metalink' \
'SFTP' \
'SQLite3-Persistence' \
- 'WebSocket' \
'XML-RPC'
do
printf '%s\n' "$output" | grep -qF "$feature"
done
+ # aria2c --version never lists WebSocket support; assert the wslay
+ # RPC handshake path is compiled in by scanning the binary itself.
+ grep -qa 'Sec-WebSocket-Accept' src/aria2c
- install -Dm755 src/aria2c $FLATPAK_DEST/libexec/motrix-build/aria2c
sources:
- type: git
@@ -154,7 +159,10 @@ modules:
XDG_CACHE_HOME: /run/build/motrix/flatpak-node/cache
npm_config_cache: /run/build/motrix/flatpak-node/npm-cache
npm_config_loglevel: warn
- npm_config_nodedir: /run/build/motrix/flatpak-node/cache/node-gyp/43.2.0
+ # Must track the electron version in package.json — generated-sources
+ # unpacks that release's headers here, and electron-rebuild's gyp run
+ # fails on a dangling path.
+ npm_config_nodedir: /run/build/motrix/flatpak-node/cache/node-gyp/43.3.0
npm_config_offline: 'true'
CARGO_HOME: /run/build/motrix/cargo
CARGO_NET_OFFLINE: 'true'
@@ -180,6 +188,18 @@ modules:
--prefix=/run/build/motrix/flatpak-node/pnpm-cli
./flatpak-node/pnpm/pnpm-11.18.0.tgz
--offline
+ # pnpm's supply-chain cooldown check fetches per-package publish times
+ # from the registry even under --offline, and the sandbox has no
+ # network. pnpm treats the setting as workspace-file-only (a
+ # --config.minimum-release-age=0 CLI override is silently ignored), so
+ # disable it by appending to the sandbox's own copy of
+ # pnpm-workspace.yaml — the committed file keeps the policy on, the
+ # same lockfile already passed it online in the "Verify locked offline
+ # sources" job, and every sandbox input is sha256-pinned in
+ # generated-sources.json.
+ # (Quoted: the colon inside would otherwise turn this YAML scalar into
+ # a mapping and the command would silently never run.)
+ - "echo 'minimumReleaseAge: 0' >> pnpm-workspace.yaml"
- pnpm install --offline --frozen-lockfile --ignore-scripts
# The root postinstall is intentionally suppressed. Extract only the
@@ -218,10 +238,15 @@ modules:
- pnpm --config.verify-deps-before-run=false run build:builtin
- pnpm --config.verify-deps-before-run=false run build:electron
+ # electronDist reuses the runtime install.js already extracted from
+ # generated-sources; without it electron-builder re-downloads the dist
+ # zip and its SHASUMS256.txt from GitHub, which the offline sandbox
+ # cannot reach (the SHASUMS file has no URL-keyed cache entry).
- pnpm --config.verify-deps-before-run=false exec electron-builder
--linux dir
--$npm_config_arch
-c.linux.target=dir
+ -c.electronDist=node_modules/electron/dist
--publish=never
- |
diff --git a/packages/native-host/tests/flatpak_broker_integration.rs b/packages/native-host/tests/flatpak_broker_integration.rs
index 7f864c0c..26189bb5 100644
--- a/packages/native-host/tests/flatpak_broker_integration.rs
+++ b/packages/native-host/tests/flatpak_broker_integration.rs
@@ -52,12 +52,18 @@ fn run_broker(config_home: &std::path::Path, flatpak_id: &str, wire: &[u8]) -> O
.stderr(Stdio::piped())
.spawn()
.expect("spawn Flatpak broker");
- child
- .stdin
- .take()
- .expect("broker stdin")
- .write_all(wire)
- .expect("write broker input");
+ // The broker validates FLATPAK_ID and XDG_CONFIG_HOME before reading any
+ // stdin, so on a rejected environment it may exit without ever consuming
+ // input; losing that race surfaces here as EPIPE. That early exit is part
+ // of the contract under test — every case still asserts on exit status and
+ // stdout — so only a BrokenPipe write failure is tolerated.
+ if let Err(error) = child.stdin.take().expect("broker stdin").write_all(wire) {
+ assert_eq!(
+ error.kind(),
+ std::io::ErrorKind::BrokenPipe,
+ "write broker input: {error}"
+ );
+ }
child.wait_with_output().expect("wait for broker")
}
diff --git a/scripts/fuzz-nat-codecs.mjs b/scripts/fuzz-nat-codecs.mjs
index c6bc43e9..c3952ea5 100644
--- a/scripts/fuzz-nat-codecs.mjs
+++ b/scripts/fuzz-nat-codecs.mjs
@@ -87,11 +87,17 @@ async function main() {
},
].filter((t) => !CODEC_FILTER || t.name.includes(CODEC_FILTER))
+ // --duration is the TOTAL wall-clock budget. Callers size job timeouts to
+ // it (nat-integration.yml budgets a "5-minute fuzz run"), so divide it
+ // across the selected targets — granting each target the full window
+ // silently turned 300s into a 35-minute run that outlived every timeout.
+ const perTargetMs = (DURATION_SEC * 1000) / targets.length
+
for (const t of targets) {
const start = performance.now()
let iters = 0
let crashed = false
- const endTime = start + DURATION_SEC * 1000
+ const endTime = start + perTargetMs
while (performance.now() < endTime) {
try {
t.run()
diff --git a/scripts/postinstall.mjs b/scripts/postinstall.mjs
index f4a04e75..84b02f7b 100644
--- a/scripts/postinstall.mjs
+++ b/scripts/postinstall.mjs
@@ -40,8 +40,12 @@ export function classifyRebuildResult(result) {
}
function runElectronRebuild() {
+ // On Windows the .bin entry is a `electron-builder.cmd` shim, which Node
+ // refuses to spawn directly (ENOENT/EINVAL since CVE-2024-27980); route it
+ // through cmd.exe. The argv is a fixed literal, so shell quoting is moot.
const result = spawnSync('electron-builder', ['install-app-deps'], {
stdio: 'inherit',
+ shell: process.platform === 'win32',
})
const { code, reason } = classifyRebuildResult(result)
if (reason) console.error(`[postinstall] electron-builder ${reason}`)
diff --git a/scripts/verify-flatpak-packaging.mjs b/scripts/verify-flatpak-packaging.mjs
index b1a8743f..61f66b7e 100644
--- a/scripts/verify-flatpak-packaging.mjs
+++ b/scripts/verify-flatpak-packaging.mjs
@@ -520,7 +520,7 @@ export async function verifyFlatpakPackaging(root = REPO_ROOT) {
workflow.includes('--strip-components=1') &&
workflow.includes(FLATPAK_COMPANION_COMMAND) &&
workflow.includes(
- '"$archive_companion" install --flatpak-bin /usr/bin/flatpak'
+ '"$archive_companion" install --flatpak-bin "$flatpak_bin"'
) &&
workflow.includes('"$installed_companion" status') &&
workflow.includes('"$installed_companion" uninstall') &&
diff --git a/src/core/nat/codecs/ssdp-codec.test.ts b/src/core/nat/codecs/ssdp-codec.test.ts
index 1cf363cc..8a5bb376 100644
--- a/src/core/nat/codecs/ssdp-codec.test.ts
+++ b/src/core/nat/codecs/ssdp-codec.test.ts
@@ -75,6 +75,19 @@ describe('parseMSearchResponse happy path', () => {
const r = parseMSearchResponse(raw)
expect(r.ok).toBe(true)
})
+
+ it('accepts the dotted UPnP 1.1 headers every compliant IGD sends', () => {
+ // UDA 1.1 §1.2.2 mandates BOOTID.UPNP.ORG / CONFIGID.UPNP.ORG; miniupnpd
+ // also emits OPT/01-NLS. Rejecting the dot rejected every real router.
+ const raw = buildSsdpResponse({
+ OPT: '"http://schemas.upnp.org/upnp/1/0/"; ns=01',
+ '01-NLS': '1786330815',
+ 'BOOTID.UPNP.ORG': '1786330815',
+ 'CONFIGID.UPNP.ORG': '1337',
+ })
+ const r = parseMSearchResponse(raw)
+ expect(r.ok).toBe(true)
+ })
})
describe('parseMSearchResponse security', () => {
diff --git a/src/core/nat/codecs/ssdp-codec.ts b/src/core/nat/codecs/ssdp-codec.ts
index 9d90f031..fc49d080 100644
--- a/src/core/nat/codecs/ssdp-codec.ts
+++ b/src/core/nat/codecs/ssdp-codec.ts
@@ -96,7 +96,10 @@ export function parseMSearchResponse(raw: Buffer): ParseResult<SsdpResponse> {
if (value.length > SSDP_HEADER_VALUE_MAX) {
return parseErr(ErrorCode.NatSecurityViolation, 'header value too long')
}
- if (!/^[A-Za-z0-9-]+$/.test(name)) {
+ // Dot is required: UPnP 1.1 (UDA §1.2.2) mandates BOOTID.UPNP.ORG /
+ // CONFIGID.UPNP.ORG on every advertisement, and '.' is a legal RFC 9110
+ // token character — without it every spec-compliant IGD is rejected.
+ if (!/^[A-Za-z0-9.-]+$/.test(name)) {
return parseErr(ErrorCode.NatParseError, 'invalid header name')
}
headers[name] = value
diff --git a/tests/docker/README.md b/tests/docker/README.md
index c8c1503e..60473b9a 100644
--- a/tests/docker/README.md
+++ b/tests/docker/README.md
@@ -6,18 +6,26 @@ for the design context.
## Images
-| Name | Binds | Purpose |
-|-----------|-------------------|------------------------------------------------|
-| upnp-v1 | tcp/49152 | miniupnpd 2.0 — IGD v1 behavior |
-| upnp-v2 | tcp/49153 | miniupnpd latest — IGD v2 behavior |
-| natpmp | udp/5351 | natpmpd reference NAT-PMP |
-| pcp-fake | udp/5352 | Self-developed Python PCP server (MAP opcode) |
-| hostile | tcp/49154 | Returns XXE / billion-laughs on HTTP GET |
-| broken | tcp/49155 udp/5353| Returns malformed / truncated payloads |
-
-SSDP multicast (udp/1900) uses `network_mode: host` on Linux. On macOS and
-Windows, the UPnP images publish their device description on the bound TCP
-port and the integration harness sends synthetic M-SEARCH packets directly.
+| Name | Binds | Purpose |
+|-----------|----------------------------|------------------------------------------------|
+| upnp-v1 | tcp/49152 (host mode) | miniupnpd 2.0 — IGD v1 behavior |
+| upnp-v2 | tcp/49153 (host mode) | miniupnpd latest — IGD v2 behavior |
+| natpmp | udp/5351 (host mode) | natpmpd reference NAT-PMP |
+| pcp-fake | udp/5351 (bridge) | Self-developed Python PCP server (MAP opcode) |
+| hostile | tcp/49154 (bridge) | Returns XXE / billion-laughs on HTTP GET |
+| broken | tcp/49155 udp/5353 (bridge)| Returns malformed / truncated payloads |
+
+SSDP multicast (udp/1900) uses `network_mode: host` on Linux. The miniupnpd
+confs set `listening_ip=eth0` (GitHub runners' primary NIC) because miniupnpd
+ignores any sender outside its LAN subnet. On macOS and Windows, the UPnP
+images publish their device description on the bound TCP port and the
+integration harness sends synthetic M-SEARCH packets directly.
+
+Bridge-network services are addressed by their container IP (see
+`containerIp()` in `tests/integration/helpers/docker-harness.ts`), never via
+`127.0.0.1:published-port`: the NAT clients' SSRF guards reject loopback, and
+pcp-fake can only own the client's hardcoded PCP port 5351 inside its own
+network namespace.
## Quick start
diff --git a/tests/docker/docker-compose.yml b/tests/docker/docker-compose.yml
index 7653ccfe..eec31f2c 100644
--- a/tests/docker/docker-compose.yml
+++ b/tests/docker/docker-compose.yml
@@ -23,9 +23,12 @@ services:
network_mode: host
restart: unless-stopped
+ # Bridge network on purpose: in its own namespace the fake server owns the
+ # standard PCP port 5351 (no clash with natpmp's host-mode miniupnpd), and
+ # tests reach it via its RFC1918 bridge address — the loopback route is
+ # rejected by the NAT clients' SSRF guards.
pcp-fake:
image: motrix-test/pcp-fake:latest
- network_mode: host
restart: unless-stopped
hostile:
diff --git a/tests/docker/natpmp/natpmpd.conf b/tests/docker/natpmp/natpmpd.conf
index 696f75e3..3688dc78 100644
--- a/tests/docker/natpmp/natpmpd.conf
+++ b/tests/docker/natpmp/natpmpd.conf
@@ -1,5 +1,7 @@
-listening_ip=0.0.0.0
-ext_ifname=eth0
+# LAN side (see upnp-v1/miniupnpd.conf for why an interface name is
+# required); ext must differ, and is fake anyway.
+listening_ip=eth0
+ext_ifname=lo
enable_natpmp=yes
enable_upnp=no
# Minimal HTTP port — required by miniupnpd but not used
diff --git a/tests/docker/pcp-fake/Dockerfile b/tests/docker/pcp-fake/Dockerfile
index db592ec5..4ac4f826 100644
--- a/tests/docker/pcp-fake/Dockerfile
+++ b/tests/docker/pcp-fake/Dockerfile
@@ -1,4 +1,6 @@
FROM python:3.11-alpine
COPY pcp_server.py /app/pcp_server.py
-EXPOSE 5351/udp 5352/udp
-CMD ["python3", "/app/pcp_server.py", "--bind=0.0.0.0", "--port=5352"]
+EXPOSE 5351/udp
+# Standard PCP port: the container runs on the compose bridge network in its
+# own namespace, so it cannot clash with natpmp's host-mode miniupnpd.
+CMD ["python3", "/app/pcp_server.py", "--bind=0.0.0.0", "--port=5351"]
diff --git a/tests/docker/upnp-v1/miniupnpd.conf b/tests/docker/upnp-v1/miniupnpd.conf
index 12924d28..25de5b98 100644
--- a/tests/docker/upnp-v1/miniupnpd.conf
+++ b/tests/docker/upnp-v1/miniupnpd.conf
@@ -1,10 +1,15 @@
# Simulated gateway for motrix NAT integration tests — IGD v1.
-# Internal listening interface (host mode uses default route)
-listening_ip=0.0.0.0
+# LAN side. miniupnpd only answers SSDP/PCP from senders inside a configured
+# lan_addr subnet; listening_ip=0.0.0.0 yields a subnet nothing matches, so
+# every probe was dropped with "not from a LAN, ignoring". Naming the
+# interface derives the real subnet. GitHub's Linux runners (and the CI
+# host-network namespace) expose the primary NIC as eth0.
+listening_ip=eth0
-# External interface — set to a fake value; integration tests don't care about actual routing
-ext_ifname=eth0
+# External interface — fake; integration tests don't care about actual
+# routing. Must differ from listening_ip's interface, so point it at lo.
+ext_ifname=lo
# HTTP port for SOAP control
http_port=49152
@@ -18,3 +23,7 @@ allow 1024-65535 0.0.0.0/0 1024-65535
# Lease duration in seconds — short so tests don't spend time on TTL
bitrate_up=0
bitrate_down=0
+
+# Surface miniupnpd in <manufacturer> so discovery tests can assert the
+# simulated router identity (the default reports the OS name instead).
+manufacturer_name=MiniUPnPd project
diff --git a/tests/docker/upnp-v2/miniupnpd.conf b/tests/docker/upnp-v2/miniupnpd.conf
index b506ff79..21e37f4d 100644
--- a/tests/docker/upnp-v2/miniupnpd.conf
+++ b/tests/docker/upnp-v2/miniupnpd.conf
@@ -1,10 +1,15 @@
# Simulated gateway for motrix NAT integration tests — IGD v2.
-# Internal listening interface (host mode uses default route)
-listening_ip=0.0.0.0
+# LAN side. miniupnpd only answers SSDP/PCP from senders inside a configured
+# lan_addr subnet; listening_ip=0.0.0.0 yields a subnet nothing matches, so
+# every probe was dropped with "not from a LAN, ignoring". Naming the
+# interface derives the real subnet. GitHub's Linux runners (and the CI
+# host-network namespace) expose the primary NIC as eth0.
+listening_ip=eth0
-# External interface — set to a fake value; integration tests don't care about actual routing
-ext_ifname=eth0
+# External interface — fake; integration tests don't care about actual
+# routing. Must differ from listening_ip's interface, so point it at lo.
+ext_ifname=lo
# HTTP port for SOAP control
http_port=49153
@@ -18,3 +23,7 @@ allow 1024-65535 0.0.0.0/0 1024-65535
# Lease duration in seconds — short so tests don't spend time on TTL
bitrate_up=0
bitrate_down=0
+
+# Surface miniupnpd in <manufacturer> so discovery tests can assert the
+# simulated router identity (the default reports the OS name instead).
+manufacturer_name=MiniUPnPd project
diff --git a/tests/integration/helpers/docker-harness.ts b/tests/integration/helpers/docker-harness.ts
index 70a9201d..ee9f6e3f 100644
--- a/tests/integration/helpers/docker-harness.ts
+++ b/tests/integration/helpers/docker-harness.ts
@@ -92,6 +92,27 @@ async function dumpMatrixEvidence(): Promise<void> {
}
}
+// Resolve a bridge-network service's container IP. Tests target this address
+// directly: the NAT clients' SSRF guards reject loopback by design, so a
+// 127.0.0.1:published-port route can never be exercised — the RFC1918 bridge
+// address is the reachable-and-allowed path on the Linux CI runner.
+export async function containerIp(service: string): Promise<string> {
+ const id = (
+ await runOutput('docker', ['compose', 'ps', '-q', service])
+ ).trim()
+ if (!id) throw new Error(`no container for compose service: ${service}`)
+ const ip = (
+ await runOutput('docker', [
+ 'inspect',
+ '--format',
+ '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}',
+ id,
+ ])
+ ).trim()
+ if (!ip) throw new Error(`no bridge IP for compose service: ${service}`)
+ return ip
+}
+
export async function isMatrixUp(): Promise<boolean> {
try {
const out = await runOutput('docker', ['compose', 'ps', '--format', 'json'])
diff --git a/tests/integration/nat-docker.test.ts b/tests/integration/nat-docker.test.ts
index 8075c8c3..d6916f96 100644
--- a/tests/integration/nat-docker.test.ts
+++ b/tests/integration/nat-docker.test.ts
@@ -4,6 +4,7 @@ import { afterAll, beforeAll, describe, expect, it } from 'vitest'
import {
composeDown,
composeUp,
+ containerIp,
dockerMatrixAvailable,
} from './helpers/docker-harness'
@@ -23,7 +24,9 @@ describe.skipIf(SKIP)('NAT docker matrix', () => {
}, 30_000)
describe('UPnP IGD v1', () => {
- it('discovers miniupnpd', async () => {
+ // Test timeout must exceed the client's own discovery timeout so a silent
+ // router surfaces as `r.ok === false`, not as an opaque vitest timeout.
+ it('discovers miniupnpd', { timeout: 10_000 }, async () => {
const { UpnpClient } = await import('@core/nat/clients')
const client = new UpnpClient({
udpFactory: nodeUdpSocketFactory,
@@ -40,6 +43,10 @@ describe.skipIf(SKIP)('NAT docker matrix', () => {
describe('PCP fake server', () => {
it('accepts MAP and echoes nonce', async () => {
const { PmpPcpClient } = await import('@core/nat/clients')
+ // The client hardcodes the standard port 5351 and its transport rejects
+ // loopback gateways, so target the fake server's own bridge address
+ // where it owns 5351 in its private namespace.
+ const gatewayIp = await containerIp('pcp-fake')
const clientIp = Buffer.concat([
Buffer.alloc(10),
Buffer.from([0xff, 0xff]),
@@ -47,7 +54,7 @@ describe.skipIf(SKIP)('NAT docker matrix', () => {
])
const client = new PmpPcpClient({
udpFactory: nodeUdpSocketFactory,
- gatewayIp: '127.0.0.1',
+ gatewayIp,
clientIp,
})
const r = await client.pcpMap({
@@ -63,10 +70,13 @@ describe.skipIf(SKIP)('NAT docker matrix', () => {
})
describe('Hostile router', () => {
+ // nodeHttpClient's SSRF guard admits only private/link-local hosts, so
+ // 127.0.0.1:published-port is unreachable by design — always target the
+ // container's RFC1918 bridge address.
it('rejects XXE response', async () => {
const res = await nodeHttpClient.request({
method: 'GET',
- host: '127.0.0.1',
+ host: await containerIp('hostile'),
port: 49154,
path: '/xxe',
timeoutMs: 3000,
@@ -84,12 +94,17 @@ describe.skipIf(SKIP)('NAT docker matrix', () => {
it('rejects 302 redirect', async () => {
const res = await nodeHttpClient.request({
method: 'GET',
- host: '127.0.0.1',
+ host: await containerIp('hostile'),
port: 49154,
path: '/redirect',
timeoutMs: 3000,
})
expect(res.ok).toBe(false)
+ if (!res.ok) {
+ // Reaching the router and refusing its redirect is the behavior under
+ // test; an unreachable router would also report ok=false.
+ expect(res.detail).toMatch(/redirect/i)
+ }
})
})
@@ -97,7 +112,7 @@ describe.skipIf(SKIP)('NAT docker matrix', () => {
it('parser handles malformed HTTP without crashing', async () => {
const res = await nodeHttpClient.request({
method: 'GET',
- host: '127.0.0.1',
+ host: await containerIp('broken'),
port: 49155,
path: '/',
timeoutMs: 3000,
diff --git a/tests/scripts/flatpak-native-host.test.ts b/tests/scripts/flatpak-native-host.test.ts
index 252b0838..2d6e18cd 100644
--- a/tests/scripts/flatpak-native-host.test.ts
+++ b/tests/scripts/flatpak-native-host.test.ts
@@ -104,7 +104,7 @@ describe('Flatpak native-host boundary', () => {
)
expect(workflow).toContain('--strip-components=1')
expect(workflow).toContain(
- '"$archive_companion" install --flatpak-bin /usr/bin/flatpak'
+ '"$archive_companion" install --flatpak-bin "$flatpak_bin"'
)
expect(workflow).toContain('"$installed_companion" status')
expect(workflow).toContain('"$installed_companion" uninstall')
diff --git a/tests/scripts/flatpak-project.test.ts b/tests/scripts/flatpak-project.test.ts
index 046d9575..94a23c4a 100644
--- a/tests/scripts/flatpak-project.test.ts
+++ b/tests/scripts/flatpak-project.test.ts
@@ -16,7 +16,11 @@ const manifest = parseYaml(
'utf8'
)
) as {
- modules: Array<{ name: string; sources: unknown[] }>
+ modules: Array<{
+ name: string
+ sources: unknown[]
+ 'build-options'?: { env?: Record<string, string> }
+ }>
}
describe('prepare-flatpak-project', () => {
@@ -64,6 +68,24 @@ describe('prepare-flatpak-project', () => {
).toThrow('exactly one git source')
})
+ it('pins the sandbox node-gyp headers to the packaged electron version', () => {
+ // generated-sources unpacks the electron release headers under
+ // flatpak-node/cache/node-gyp/<electron version>; a stale nodedir makes
+ // electron-rebuild's gyp fail on a dangling include path (run
+ // 31363983647 shipped 43.3.0 sources against a 43.2.0 nodedir).
+ const electronVersion = (
+ JSON.parse(
+ readFileSync(path.join(process.cwd(), 'package.json'), 'utf8')
+ ) as { devDependencies: Record<string, string> }
+ ).devDependencies.electron.replace(/^[~^]/, '')
+ const motrix = manifest.modules.find(
+ (candidate) => candidate.name === 'motrix'
+ )
+ expect(motrix?.['build-options']?.env?.npm_config_nodedir).toBe(
+ `/run/build/motrix/flatpak-node/cache/node-gyp/${electronVersion}`
+ )
+ })
+
it('parses explicit workflow paths and rejects unknown flags', () => {
expect(
parseArgs([