From 0ae561b8d27e48fc44a0c8debd690424062d27ca Mon Sep 17 00:00:00 2001 From: ikim Date: Wed, 26 Aug 2026 22:55:12 +0800 Subject: [PATCH] fix(ci): run WSL2 contract tests via prebuilt binaries (#6472) * ci: run WSL2 contract tests via prebuilt binaries link.exe/mt.exe fails to create manifests when TEMP points to a WSL UNC path (LNK1327). Run precompiled test binaries directly instead of re-invoking cargo, and explicitly set native TEMP during compilation. * ci: harden prebuilt WSL2 contract runner Keep the scheduled full-suite workflow unchanged until it can be validated independently. Drain Cargo's JSON stream before using the test binary and propagate its exit status. --------- Co-authored-by: saladday <1203511142@qq.com> --- .github/workflows/ci.yml | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9eeafbb4f..36c332352 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -205,15 +205,40 @@ jobs: - name: Compile backend tests with native temp # link.exe/mt.exe cannot create manifests when TEMP points at a WSL UNC path. - run: cargo test --lib --manifest-path src-tauri/Cargo.toml --no-run + # Record the built test binary path so the run step below can execute + # it directly instead of re-invoking cargo with TEMP on \\wsl.localhost. + env: + TEMP: ${{ runner.temp }} + TMP: ${{ runner.temp }} + shell: pwsh + run: | + $testBinary = cargo test --lib --manifest-path src-tauri/Cargo.toml --no-run --message-format=json | + ForEach-Object { + if ($_ -match '"reason":"compiler-artifact"') { + $artifact = $_ | ConvertFrom-Json + if ($artifact.executable -and $artifact.profile.test -and $artifact.target.name -eq 'cc_switch_lib') { + $artifact.executable + } + } + } | Select-Object -First 1 -Wait + if ($LASTEXITCODE -ne 0) { + exit $LASTEXITCODE + } + if (-not $testBinary) { + throw "cc_switch_lib test binary not found in cargo compiler artifacts" + } + "CC_SWITCH_TEST_EXE=$testBinary" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - name: Run Windows-to-WSL2 filesystem contract + # Run the test binary built in the previous step directly. Invoking cargo + # here with TEMP pointing at a WSL UNC path can re-link the crate, and + # link.exe/mt.exe cannot create manifest temp files on \\wsl.localhost. shell: pwsh run: | $env:TEMP = $env:CC_SWITCH_WSL_TEST_TEMP $env:TMP = $env:CC_SWITCH_WSL_TEST_TEMP $testName = "config::tests::atomic_write_replaces_existing_wsl_unc_file" - $testList = cargo test --lib --manifest-path src-tauri/Cargo.toml -- --ignored --list + $testList = & $env:CC_SWITCH_TEST_EXE --list --ignored if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } @@ -221,7 +246,7 @@ jobs: if ($testList -notcontains $expected) { throw "Expected ignored test was not discovered: $testName" } - cargo test --lib --manifest-path src-tauri/Cargo.toml $testName -- --ignored --exact --nocapture + & $env:CC_SWITCH_TEST_EXE $testName --ignored --exact --nocapture if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }