From 899b69a92554e4237b2d047ab44c68713bd458ae Mon Sep 17 00:00:00 2001 From: Tryanks Date: Fri, 23 Oct 2026 13:11:45 +0800 Subject: [PATCH 01/15] ci: avoid release cache churn and unnecessary runner work --- .github/workflows/ci.yml | 4 ---- .github/workflows/release.yml | 31 ++------------------------ crates/runtime/src/app/test_support.rs | 13 ++++++----- 3 files changed, 9 insertions(+), 39 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c73793edb..46c708af7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -83,10 +83,6 @@ jobs: libasound2-dev libfontconfig-dev libwayland-dev libxkbcommon-dev \ libxkbcommon-x11-dev libx11-xcb-dev libxcb1-dev libgbm-dev \ libvulkan-dev xvfb - if cargo tree -e normal -i glib-sys >/dev/null 2>&1; then - "${apt_get[@]}" install -y --no-install-recommends \ - libgtk-3-dev libwebkit2gtk-4.1-dev - fi - name: Check formatting run: cargo fmt --all --check diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6ea5d546b..b8803cc5c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,6 +17,8 @@ concurrency: group: release-${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref_name }} cancel-in-progress: false +# Tag-scoped Cargo caches cannot warm the next release and evict the main CI +# caches from the shared Actions quota. jobs: setup: runs-on: ubuntu-24.04 @@ -98,11 +100,6 @@ jobs: with: targets: ${{ matrix.target }} - - name: Cache Cargo build data - uses: Swatinem/rust-cache@v2 - with: - shared-key: release-${{ matrix.target }} - - name: Install Linux system dependencies if: matrix.platform == 'linux' run: | @@ -112,10 +109,6 @@ jobs: build-essential clang cmake pkg-config libssl-dev libzstd-dev \ libasound2-dev libfontconfig-dev libwayland-dev libxkbcommon-dev \ libxkbcommon-x11-dev libx11-xcb-dev libxcb1-dev libgbm-dev libvulkan-dev - if cargo tree -e normal -i glib-sys >/dev/null 2>&1; then - "${apt_get[@]}" install -y --no-install-recommends \ - libgtk-3-dev libwebkit2gtk-4.1-dev - fi - name: Build release binary shell: bash @@ -416,11 +409,6 @@ jobs: with: targets: wasm32-unknown-unknown - - name: Cache Cargo build data - uses: Swatinem/rust-cache@v2 - with: - shared-key: release-web-bundle - - name: Install wasm tools run: | cargo install wasm-bindgen-cli --version 0.2.127 --locked @@ -504,11 +492,6 @@ jobs: with: targets: ${{ matrix.target }} - - name: Cache Cargo build data - uses: Swatinem/rust-cache@v2 - with: - shared-key: release-headless-${{ matrix.target }} - - name: Install Linux system dependencies if: matrix.platform == 'linux' run: | @@ -614,11 +597,6 @@ jobs: with: targets: ${{ matrix.target }} - - name: Cache Cargo build data - uses: Swatinem/rust-cache@v2 - with: - shared-key: release-traverse-${{ matrix.target }} - - name: Install Linux system dependencies if: matrix.platform == 'linux' run: | @@ -683,11 +661,6 @@ jobs: with: targets: aarch64-linux-android - - name: Cache Cargo build data - uses: Swatinem/rust-cache@v2 - with: - shared-key: release-android-arm64 - - name: Set up JDK 21 uses: actions/setup-java@v6 with: diff --git a/crates/runtime/src/app/test_support.rs b/crates/runtime/src/app/test_support.rs index e8b18cb6f..225094bb1 100644 --- a/crates/runtime/src/app/test_support.rs +++ b/crates/runtime/src/app/test_support.rs @@ -86,7 +86,7 @@ impl TestAppContext { .and_then(Weak::upgrade) .expect("test state must outlive its context"); let deadline = Instant::now() + Duration::from_secs(5); - let mut idle_passes = 0_u32; + let mut idle_since = Instant::now(); let mut saw_work = false; let mut store_flushed = false; @@ -104,23 +104,24 @@ impl TestAppContext { had_work = true; } if had_work { - idle_passes = 0; + idle_since = Instant::now(); saw_work = true; store_flushed = false; } else { - idle_passes += 1; // Loaded CI runners (notably Windows) can take well past 50ms // to schedule a background completion; calls that processed // work get a wider idle window before declaring parked. - let threshold = if saw_work && !store_flushed { 250 } else { 50 }; - if idle_passes >= threshold { + // Count elapsed time: a 1ms sleep can take much longer on a VM. + let idle_window = + Duration::from_millis(if saw_work && !store_flushed { 250 } else { 50 }); + if idle_since.elapsed() >= idle_window { if !store_flushed { // Barrier the store-writer task so persisted state is // visible before callers assert on it. Its failure // path can enqueue more work, so keep draining. store_flushed = true; if self.flush_store_writer(&state, deadline) { - idle_passes = 0; + idle_since = Instant::now(); continue; } } From 724835bac366917e62a8b4a699aa367bc2ee3358 Mon Sep 17 00:00:00 2001 From: Tryanks Date: Fri, 23 Oct 2026 13:29:45 +0800 Subject: [PATCH 02/15] ci: overlap the slow syntax test and avoid the slow apt mirror --- .config/nextest.toml | 4 ++++ .github/workflows/ci.yml | 6 ++++++ 2 files changed, 10 insertions(+) create mode 100644 .config/nextest.toml diff --git a/.config/nextest.toml b/.config/nextest.toml new file mode 100644 index 000000000..147763480 --- /dev/null +++ b/.config/nextest.toml @@ -0,0 +1,4 @@ +[[profile.default.overrides]] +# This otherwise starts near the end and leaves the other test workers idle. +filter = 'test(=highlight::tests::shipped_syntax_set_compiles_under_active_regex_backend)' +priority = 100 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 46c708af7..6480ac278 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -76,6 +76,12 @@ jobs: - name: Install Linux system dependencies if: runner.os == 'Linux' run: | + # The Azure mirror has delivered packages at ~65 kB/s on these runners. + for source in /etc/apt/sources.list.d/ubuntu.sources /etc/apt/apt-mirrors.txt; do + if [[ -f "$source" ]]; then + sudo sed -i 's|http://azure\.archive\.ubuntu\.com/ubuntu|https://archive.ubuntu.com/ubuntu|g' "$source" + fi + done apt_get=(sudo apt-get -o Acquire::ForceIPv4=true -o Acquire::Retries=3) "${apt_get[@]}" update "${apt_get[@]}" install -y --no-install-recommends \ From c250b94be2e444779b7171f24b62aded2f10c2c2 Mon Sep 17 00:00:00 2001 From: Tryanks Date: Fri, 23 Oct 2026 13:54:39 +0800 Subject: [PATCH 03/15] ci: parallelize desktop checks and deduplicate regex compilation --- .github/workflows/ci.yml | 50 ++++++++++++++++++++++++++++---------- crates/ui/src/highlight.rs | 7 +++++- 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6480ac278..b8f532203 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,19 +21,24 @@ env: RUST_BACKTRACE: 1 jobs: - desktop: - name: ${{ matrix.name }} + desktop-work: + name: ${{ matrix.name }} / ${{ matrix.task }} runs-on: ${{ matrix.os }} timeout-minutes: 60 strategy: fail-fast: false matrix: + task: [clippy, tests] + platform: [linux, macos, windows] include: - - name: Linux x64 + - platform: linux + name: Linux x64 os: ubuntu-24.04 - - name: macOS arm64 + - platform: macos + name: macOS arm64 os: macos-26 - - name: Windows x64 + - platform: windows + name: Windows x64 os: windows-2022 steps: - uses: actions/checkout@v7 @@ -49,23 +54,23 @@ jobs: with: components: rustfmt, clippy - # Only main writes the cache so pull requests share one warm copy per - # platform instead of evicting each other from the repository quota. + # Check-mode artifacts differ from test builds. Keep each main job's + # cache separate so parallel saves cannot discard the other mode. - name: Cache Cargo build data uses: Swatinem/rust-cache@v2 with: - shared-key: ci-${{ runner.os }}-${{ runner.arch }} + shared-key: ci-${{ runner.os }}-${{ runner.arch }}${{ matrix.task == 'clippy' && '-clippy' || '' }} save-if: ${{ github.ref == 'refs/heads/main' }} - name: Install cargo-nextest - if: runner.os != 'Windows' + if: matrix.task == 'tests' && runner.os != 'Windows' uses: taiki-e/install-action@v2 with: tool: nextest # Work around install-action's Windows bash startup failure (actions/partner-runner-images#169). - name: Install cargo-nextest on Windows - if: runner.os == 'Windows' + if: matrix.task == 'tests' && runner.os == 'Windows' shell: pwsh run: | $archive = Join-Path $env:RUNNER_TEMP 'nextest.zip' @@ -91,23 +96,42 @@ jobs: libvulkan-dev xvfb - name: Check formatting + if: matrix.task == 'clippy' run: cargo fmt --all --check - name: Run Clippy + if: matrix.task == 'clippy' run: cargo clippy --workspace --all-targets --locked -- -D warnings - name: Run tests - if: runner.os != 'Linux' + if: matrix.task == 'tests' && runner.os != 'Linux' run: cargo nextest run --workspace --locked - name: Test iOS text input on the host - if: runner.os == 'macOS' + if: matrix.task == 'tests' && runner.os == 'macOS' run: cargo test -p gpui-ios --lib --locked - name: Run tests under Xvfb - if: runner.os == 'Linux' + if: matrix.task == 'tests' && runner.os == 'Linux' run: xvfb-run -a cargo nextest run --workspace --locked + # Preserve the existing required check names. A skipped or cancelled worker + # must not let any desktop gate pass. + desktop: + name: ${{ matrix.name }} + needs: desktop-work + if: always() + runs-on: ubuntu-24.04 + timeout-minutes: 5 + strategy: + matrix: + name: [Linux x64, macOS arm64, Windows x64] + steps: + - name: Require all desktop checks + env: + RESULT: ${{ needs.desktop-work.result }} + run: test "$RESULT" = success + dependencies: name: Dependency hygiene runs-on: ubuntu-24.04 diff --git a/crates/ui/src/highlight.rs b/crates/ui/src/highlight.rs index 99b8f4b82..ff561e3b3 100644 --- a/crates/ui/src/highlight.rs +++ b/crates/ui/src/highlight.rs @@ -581,8 +581,11 @@ mod tests { syntect::dumps::from_uncompressed_data(include_bytes!("../assets/syntaxes.bin")) .expect("load shipped dump"); let mut failures = Vec::new(); + // Compilation depends only on the pattern, which many syntaxes share. + let mut checked = HashSet::new(); for syntax in set.into_builder().syntaxes() { if let Some(first_line) = &syntax.first_line_match + && checked.insert(first_line.clone()) && let Some(err) = Regex::try_compile(first_line) { failures.push(format!("{}: first_line_match: {err}", syntax.name)); @@ -597,7 +600,9 @@ mod tests { } else { pattern.regex.regex_str().to_string() }; - if let Some(err) = Regex::try_compile(&probe) { + if checked.insert(probe.clone()) + && let Some(err) = Regex::try_compile(&probe) + { failures.push(format!("{}: {err}", syntax.name)); } } From 11ea03076303c0080b2e82d249f71db8935f61b1 Mon Sep 17 00:00:00 2001 From: Tryanks Date: Fri, 23 Oct 2026 18:19:36 +0800 Subject: [PATCH 04/15] ci: double nextest concurrency on desktop runners --- .github/workflows/ci.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b8f532203..ec87f0c11 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -95,6 +95,16 @@ jobs: libxkbcommon-x11-dev libx11-xcb-dev libxcb1-dev libgbm-dev \ libvulkan-dev xvfb + - name: Set nextest test concurrency + if: matrix.task == 'tests' + shell: python + run: | + import os + test_threads = 2 * os.cpu_count() + print(f"nextest test threads: {test_threads}") + with open(os.environ["GITHUB_ENV"], "a") as env_file: + env_file.write(f"NEXTEST_TEST_THREADS={test_threads}\n") + - name: Check formatting if: matrix.task == 'clippy' run: cargo fmt --all --check From a5d77a2ab102acb27940fc1ba2b6df0851a92be7 Mon Sep 17 00:00:00 2001 From: Tryanks Date: Fri, 23 Oct 2026 18:53:37 +0800 Subject: [PATCH 05/15] ci: diagnose Windows leaks with same-binary concurrency comparison --- .github/scripts/diagnose-nextest-windows.ps1 | 78 ++++++++++++++++++++ .github/workflows/ci.yml | 15 +++- 2 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 .github/scripts/diagnose-nextest-windows.ps1 diff --git a/.github/scripts/diagnose-nextest-windows.ps1 b/.github/scripts/diagnose-nextest-windows.ps1 new file mode 100644 index 000000000..02b385923 --- /dev/null +++ b/.github/scripts/diagnose-nextest-windows.ps1 @@ -0,0 +1,78 @@ +# Temporary same-runner comparison; remove after the Windows LEAK investigation. +$ErrorActionPreference = 'Stop' +$PSNativeCommandUseErrorActionPreference = $false +$env:CARGO_TERM_COLOR = 'never' +$env:NO_COLOR = '1' +$out = Join-Path $env:RUNNER_TEMP 'nextest-concurrency' +New-Item -ItemType Directory -Force $out | Out-Null +$metadata = Join-Path $out 'cargo-metadata.json' +$binaries = Join-Path $out 'binaries.json' + +& cargo metadata --format-version 1 --no-deps --locked > $metadata +if ($LASTEXITCODE -ne 0) { throw 'cargo metadata failed' } +& cargo nextest list --workspace --locked --list-type binaries-only --message-format json > $binaries +if ($LASTEXITCODE -ne 0) { throw 'test prebuild failed' } + +$binaryPaths = (Get-Content $binaries -Raw | ConvertFrom-Json).'rust-binaries'.PSObject.Properties | + ForEach-Object { $_.Value.'binary-path' } +$before = @($binaryPaths | Sort-Object | Get-FileHash -Algorithm SHA256) +$before | ConvertTo-Json | Set-Content (Join-Path $out 'binaries-before.json') +$runs = @() +$failed = $false +$index = 0 + +# No retries: every result contributes to the final exit status, including LEAK. +foreach ($threads in @(4, 8, 8, 4)) { + $index++ + $label = "run$index-j$threads" + $log = Join-Path $out "$label.log" + $startId = "$label-start" + $stopId = "$label-stop" + Get-CimInstance Win32_Process | + Select-Object ProcessId, ParentProcessId, Name, CreationDate | + ConvertTo-Json | Set-Content (Join-Path $out "$label-processes-before.json") + Register-CimIndicationEvent -Query 'SELECT * FROM Win32_ProcessStartTrace' -SourceIdentifier $startId | Out-Null + Register-CimIndicationEvent -Query 'SELECT * FROM Win32_ProcessStopTrace' -SourceIdentifier $stopId | Out-Null + try { + Write-Host "::group::$label" + $started = [DateTime]::UtcNow + & cargo nextest run --cargo-metadata $metadata --binaries-metadata $binaries --test-threads $threads --no-fail-fast 2>&1 | + Tee-Object -FilePath $log + $code = $LASTEXITCODE + $finished = [DateTime]::UtcNow + $leaks = @(Select-String -Path $log -Pattern '^\s*LEAK(?:-FAIL)?\s+\[').Count + $summary = @(Select-String -Path $log -Pattern '^\s*Summary\s+\[' | ForEach-Object { $_.Line }) + $runs += [pscustomobject]@{ + run = $index; threads = $threads; exit_code = $code; leaks = $leaks + started = $started.ToString('o'); finished = $finished.ToString('o') + elapsed_seconds = ($finished - $started).TotalSeconds; summary = $summary + } + if ($code -ne 0 -or $leaks -gt 0 -or $summary.Count -eq 0) { $failed = $true } + Get-CimInstance Win32_Process | + Select-Object ProcessId, ParentProcessId, Name, CreationDate | + ConvertTo-Json | Set-Content (Join-Path $out "$label-processes-after.json") + # Let process-event notifications drain after measurement has stopped. + Start-Sleep -Seconds 2 + } finally { + Unregister-Event -SourceIdentifier $startId -ErrorAction SilentlyContinue + Unregister-Event -SourceIdentifier $stopId -ErrorAction SilentlyContinue + $events = @(Get-Event -ErrorAction SilentlyContinue | Where-Object { $_.SourceIdentifier -in @($startId, $stopId) }) + @($events | ForEach-Object { + $process = $_.SourceEventArgs.NewEvent + [pscustomobject]@{ + kind = $_.SourceIdentifier; time = [string]$process.TIME_CREATED + pid = $process.ProcessID; parent_pid = $process.ParentProcessID + name = $process.ProcessName; exit_status = $process.ExitStatus + } + }) | ConvertTo-Json | Set-Content (Join-Path $out "$label-process-events.json") + foreach ($event in $events) { Remove-Event -EventIdentifier $event.EventIdentifier } + $runs | ConvertTo-Json -Depth 4 | Set-Content (Join-Path $out 'results.json') + Write-Host '::endgroup::' + } +} + +$after = @($binaryPaths | Sort-Object | Get-FileHash -Algorithm SHA256) +$after | ConvertTo-Json | Set-Content (Join-Path $out 'binaries-after.json') +if (Compare-Object $before $after -Property Path, Hash) { throw 'Test binaries changed during comparison' } +$runs | Format-Table run, threads, elapsed_seconds, leaks, exit_code +if ($failed) { exit 1 } diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ec87f0c11..4dc75c87b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -114,9 +114,22 @@ jobs: run: cargo clippy --workspace --all-targets --locked -- -D warnings - name: Run tests - if: matrix.task == 'tests' && runner.os != 'Linux' + if: matrix.task == 'tests' && runner.os == 'macOS' run: cargo nextest run --workspace --locked + - name: Diagnose Windows test concurrency + if: matrix.task == 'tests' && runner.os == 'Windows' + shell: pwsh + run: ./.github/scripts/diagnose-nextest-windows.ps1 + + - name: Upload Windows concurrency evidence + if: always() && matrix.task == 'tests' && runner.os == 'Windows' + uses: actions/upload-artifact@v7 + with: + name: windows-nextest-concurrency + path: ${{ runner.temp }}/nextest-concurrency + retention-days: 7 + - name: Test iOS text input on the host if: matrix.task == 'tests' && runner.os == 'macOS' run: cargo test -p gpui-ios --lib --locked From 67cfde85951276ff17eb5a7117148ea0e5fa8c79 Mon Sep 17 00:00:00 2001 From: Tryanks Date: Fri, 23 Oct 2026 19:10:09 +0800 Subject: [PATCH 06/15] ci: preserve diagnostic results across event cleanup --- .github/scripts/diagnose-nextest-windows.ps1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/scripts/diagnose-nextest-windows.ps1 b/.github/scripts/diagnose-nextest-windows.ps1 index 02b385923..d85eb0ab6 100644 --- a/.github/scripts/diagnose-nextest-windows.ps1 +++ b/.github/scripts/diagnose-nextest-windows.ps1 @@ -65,8 +65,10 @@ foreach ($threads in @(4, 8, 8, 4)) { name = $process.ProcessName; exit_status = $process.ExitStatus } }) | ConvertTo-Json | Set-Content (Join-Path $out "$label-process-events.json") - foreach ($event in $events) { Remove-Event -EventIdentifier $event.EventIdentifier } $runs | ConvertTo-Json -Depth 4 | Set-Content (Join-Path $out 'results.json') + # Queue entries may already be gone; cleanup must not discard recorded results. + Remove-Event -SourceIdentifier $startId -ErrorAction SilentlyContinue + Remove-Event -SourceIdentifier $stopId -ErrorAction SilentlyContinue Write-Host '::endgroup::' } } From cd21e440855fa7bd65e81bdf38cb14a9fa522688 Mon Sep 17 00:00:00 2001 From: Tryanks Date: Sat, 24 Oct 2026 02:29:21 +0800 Subject: [PATCH 07/15] ci: retain safe Windows concurrency and fail on leaked handles --- .config/nextest.toml | 4 + .github/scripts/diagnose-nextest-windows.ps1 | 80 -------------------- .github/workflows/ci.yml | 23 ++---- 3 files changed, 10 insertions(+), 97 deletions(-) delete mode 100644 .github/scripts/diagnose-nextest-windows.ps1 diff --git a/.config/nextest.toml b/.config/nextest.toml index 147763480..837431323 100644 --- a/.config/nextest.toml +++ b/.config/nextest.toml @@ -2,3 +2,7 @@ # This otherwise starts near the end and leaves the other test workers idle. filter = 'test(=highlight::tests::shipped_syntax_set_compiles_under_active_regex_backend)' priority = 100 + +[profile.ci] +# Keep nextest's 200 ms threshold, but do not accept leaked output handles as a pass. +leak-timeout = { period = "200ms", result = "fail" } diff --git a/.github/scripts/diagnose-nextest-windows.ps1 b/.github/scripts/diagnose-nextest-windows.ps1 deleted file mode 100644 index d85eb0ab6..000000000 --- a/.github/scripts/diagnose-nextest-windows.ps1 +++ /dev/null @@ -1,80 +0,0 @@ -# Temporary same-runner comparison; remove after the Windows LEAK investigation. -$ErrorActionPreference = 'Stop' -$PSNativeCommandUseErrorActionPreference = $false -$env:CARGO_TERM_COLOR = 'never' -$env:NO_COLOR = '1' -$out = Join-Path $env:RUNNER_TEMP 'nextest-concurrency' -New-Item -ItemType Directory -Force $out | Out-Null -$metadata = Join-Path $out 'cargo-metadata.json' -$binaries = Join-Path $out 'binaries.json' - -& cargo metadata --format-version 1 --no-deps --locked > $metadata -if ($LASTEXITCODE -ne 0) { throw 'cargo metadata failed' } -& cargo nextest list --workspace --locked --list-type binaries-only --message-format json > $binaries -if ($LASTEXITCODE -ne 0) { throw 'test prebuild failed' } - -$binaryPaths = (Get-Content $binaries -Raw | ConvertFrom-Json).'rust-binaries'.PSObject.Properties | - ForEach-Object { $_.Value.'binary-path' } -$before = @($binaryPaths | Sort-Object | Get-FileHash -Algorithm SHA256) -$before | ConvertTo-Json | Set-Content (Join-Path $out 'binaries-before.json') -$runs = @() -$failed = $false -$index = 0 - -# No retries: every result contributes to the final exit status, including LEAK. -foreach ($threads in @(4, 8, 8, 4)) { - $index++ - $label = "run$index-j$threads" - $log = Join-Path $out "$label.log" - $startId = "$label-start" - $stopId = "$label-stop" - Get-CimInstance Win32_Process | - Select-Object ProcessId, ParentProcessId, Name, CreationDate | - ConvertTo-Json | Set-Content (Join-Path $out "$label-processes-before.json") - Register-CimIndicationEvent -Query 'SELECT * FROM Win32_ProcessStartTrace' -SourceIdentifier $startId | Out-Null - Register-CimIndicationEvent -Query 'SELECT * FROM Win32_ProcessStopTrace' -SourceIdentifier $stopId | Out-Null - try { - Write-Host "::group::$label" - $started = [DateTime]::UtcNow - & cargo nextest run --cargo-metadata $metadata --binaries-metadata $binaries --test-threads $threads --no-fail-fast 2>&1 | - Tee-Object -FilePath $log - $code = $LASTEXITCODE - $finished = [DateTime]::UtcNow - $leaks = @(Select-String -Path $log -Pattern '^\s*LEAK(?:-FAIL)?\s+\[').Count - $summary = @(Select-String -Path $log -Pattern '^\s*Summary\s+\[' | ForEach-Object { $_.Line }) - $runs += [pscustomobject]@{ - run = $index; threads = $threads; exit_code = $code; leaks = $leaks - started = $started.ToString('o'); finished = $finished.ToString('o') - elapsed_seconds = ($finished - $started).TotalSeconds; summary = $summary - } - if ($code -ne 0 -or $leaks -gt 0 -or $summary.Count -eq 0) { $failed = $true } - Get-CimInstance Win32_Process | - Select-Object ProcessId, ParentProcessId, Name, CreationDate | - ConvertTo-Json | Set-Content (Join-Path $out "$label-processes-after.json") - # Let process-event notifications drain after measurement has stopped. - Start-Sleep -Seconds 2 - } finally { - Unregister-Event -SourceIdentifier $startId -ErrorAction SilentlyContinue - Unregister-Event -SourceIdentifier $stopId -ErrorAction SilentlyContinue - $events = @(Get-Event -ErrorAction SilentlyContinue | Where-Object { $_.SourceIdentifier -in @($startId, $stopId) }) - @($events | ForEach-Object { - $process = $_.SourceEventArgs.NewEvent - [pscustomobject]@{ - kind = $_.SourceIdentifier; time = [string]$process.TIME_CREATED - pid = $process.ProcessID; parent_pid = $process.ParentProcessID - name = $process.ProcessName; exit_status = $process.ExitStatus - } - }) | ConvertTo-Json | Set-Content (Join-Path $out "$label-process-events.json") - $runs | ConvertTo-Json -Depth 4 | Set-Content (Join-Path $out 'results.json') - # Queue entries may already be gone; cleanup must not discard recorded results. - Remove-Event -SourceIdentifier $startId -ErrorAction SilentlyContinue - Remove-Event -SourceIdentifier $stopId -ErrorAction SilentlyContinue - Write-Host '::endgroup::' - } -} - -$after = @($binaryPaths | Sort-Object | Get-FileHash -Algorithm SHA256) -$after | ConvertTo-Json | Set-Content (Join-Path $out 'binaries-after.json') -if (Compare-Object $before $after -Property Path, Hash) { throw 'Test binaries changed during comparison' } -$runs | Format-Table run, threads, elapsed_seconds, leaks, exit_code -if ($failed) { exit 1 } diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4dc75c87b..66a244f77 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -100,7 +100,9 @@ jobs: shell: python run: | import os - test_threads = 2 * os.cpu_count() + test_threads = os.cpu_count() + if os.environ["RUNNER_OS"] != "Windows": + test_threads *= 2 print(f"nextest test threads: {test_threads}") with open(os.environ["GITHUB_ENV"], "a") as env_file: env_file.write(f"NEXTEST_TEST_THREADS={test_threads}\n") @@ -114,21 +116,8 @@ jobs: run: cargo clippy --workspace --all-targets --locked -- -D warnings - name: Run tests - if: matrix.task == 'tests' && runner.os == 'macOS' - run: cargo nextest run --workspace --locked - - - name: Diagnose Windows test concurrency - if: matrix.task == 'tests' && runner.os == 'Windows' - shell: pwsh - run: ./.github/scripts/diagnose-nextest-windows.ps1 - - - name: Upload Windows concurrency evidence - if: always() && matrix.task == 'tests' && runner.os == 'Windows' - uses: actions/upload-artifact@v7 - with: - name: windows-nextest-concurrency - path: ${{ runner.temp }}/nextest-concurrency - retention-days: 7 + if: matrix.task == 'tests' && runner.os != 'Linux' + run: cargo nextest run --workspace --locked --profile ci - name: Test iOS text input on the host if: matrix.task == 'tests' && runner.os == 'macOS' @@ -136,7 +125,7 @@ jobs: - name: Run tests under Xvfb if: matrix.task == 'tests' && runner.os == 'Linux' - run: xvfb-run -a cargo nextest run --workspace --locked + run: xvfb-run -a cargo nextest run --workspace --locked --profile ci # Preserve the existing required check names. A skipped or cancelled worker # must not let any desktop gate pass. From 9734ea078200225f39fcc5fcd7031ba7e59fdb8c Mon Sep 17 00:00:00 2001 From: Tryanks Date: Sat, 24 Oct 2026 02:50:52 +0800 Subject: [PATCH 08/15] ci: trace Git processes behind Windows test leaks --- .config/nextest.toml | 3 +++ .github/workflows/ci.yml | 26 +++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/.config/nextest.toml b/.config/nextest.toml index 837431323..577cdbce8 100644 --- a/.config/nextest.toml +++ b/.config/nextest.toml @@ -6,3 +6,6 @@ priority = 100 [profile.ci] # Keep nextest's 200 ms threshold, but do not accept leaked output handles as a pass. leak-timeout = { period = "200ms", result = "fail" } + +[profile.ci.junit] +path = "junit.xml" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 66a244f77..8d2ae376a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -116,9 +116,33 @@ jobs: run: cargo clippy --workspace --all-targets --locked -- -D warnings - name: Run tests - if: matrix.task == 'tests' && runner.os != 'Linux' + if: matrix.task == 'tests' && runner.os == 'macOS' run: cargo nextest run --workspace --locked --profile ci + - name: Trace Windows test Git processes + if: matrix.task == 'tests' && runner.os == 'Windows' + shell: pwsh + run: | + $trace = Join-Path $env:RUNNER_TEMP 'nextest-git-trace' + New-Item -ItemType Directory -Force $trace | Out-Null + (Get-Command git).Source | Set-Content (Join-Path $trace 'git-install.txt') + git version --build-options | Add-Content (Join-Path $trace 'git-install.txt') + git --exec-path | Add-Content (Join-Path $trace 'git-install.txt') + $env:GIT_TRACE2_EVENT = $trace + $env:GIT_TRACE2_ENV_VARS = 'NEXTEST_TEST_NAME,NEXTEST_BINARY_ID,NEXTEST_ATTEMPT_ID' + $env:GIT_TRACE2_CONFIG_PARAMS = 'core.fsmonitor,maintenance.auto' + cargo nextest run --workspace --locked --profile ci --no-fail-fast + + - name: Upload Windows process trace + if: always() && matrix.task == 'tests' && runner.os == 'Windows' + uses: actions/upload-artifact@v7 + with: + name: windows-git-trace + path: | + ${{ runner.temp }}/nextest-git-trace + target/nextest/ci/junit.xml + retention-days: 7 + - name: Test iOS text input on the host if: matrix.task == 'tests' && runner.os == 'macOS' run: cargo test -p gpui-ios --lib --locked From 2f3d44de76d29f8244651dcc820646443b6f7aa4 Mon Sep 17 00:00:00 2001 From: Tryanks Date: Sat, 24 Oct 2026 03:22:03 +0800 Subject: [PATCH 09/15] perf: share Git remote reads across forge detection --- crates/runtime/src/app/pull_requests_tests.rs | 2 +- crates/services/src/azure/mod.rs | 6 +- crates/services/src/azure/repository.rs | 4 +- crates/services/src/bitbucket/mod.rs | 6 +- crates/services/src/bitbucket/repository.rs | 4 +- crates/services/src/forge.rs | 62 ++++++++++++++++++- crates/services/src/forge/checkout.rs | 61 +++++++++++++----- crates/services/src/forgejo/mod.rs | 7 ++- crates/services/src/forgejo/repository.rs | 7 ++- crates/services/src/git.rs | 5 +- crates/services/src/github/forge.rs | 14 +++-- crates/services/src/github/repository.rs | 34 ++++------ crates/services/src/gitlab/mod.rs | 6 +- crates/services/src/gitlab/repository.rs | 7 ++- crates/services/tests/github.rs | 11 +++- 15 files changed, 165 insertions(+), 71 deletions(-) diff --git a/crates/runtime/src/app/pull_requests_tests.rs b/crates/runtime/src/app/pull_requests_tests.rs index be7f3dfb7..70337a378 100644 --- a/crates/runtime/src/app/pull_requests_tests.rs +++ b/crates/runtime/src/app/pull_requests_tests.rs @@ -2316,7 +2316,7 @@ fn a_partly_posted_review_keeps_only_unposted_drafts_for_the_next_submission() { fn pull_request_url(&self, _: &str) -> Option<(PullRequestKey, String)> { unreachable!() } - fn checkout_repository(&self, _: &Path) -> Option { + fn resolve_checkout(&self, _: &tcode_services::forge::Checkout<'_>) -> Option { unreachable!() } fn repository(&self, _: &str, _: &str) -> Option { diff --git a/crates/services/src/azure/mod.rs b/crates/services/src/azure/mod.rs index b14c71b9b..54bfd0e48 100644 --- a/crates/services/src/azure/mod.rs +++ b/crates/services/src/azure/mod.rs @@ -753,8 +753,8 @@ impl Forge for Azure { repository::pull_request_url(url) } - fn checkout_repository(&self, cwd: &Path) -> Option { - repository::resolve(cwd) + fn resolve_checkout(&self, checkout: &crate::forge::Checkout<'_>) -> Option { + repository::resolve(checkout) } fn repository(&self, name: &str, host: &str) -> Option { @@ -774,7 +774,7 @@ impl Forge for Azure { refresh: bool, ) -> Result, ForgeError> { let cwd = if cwd.exists() { cwd } else { root }; - let Some(target) = repository::resolve(root) else { + let Some(target) = repository::resolve(&crate::forge::Checkout::new(root)) else { return Ok(None); }; let Some(branch) = repository::branch(cwd) else { diff --git a/crates/services/src/azure/repository.rs b/crates/services/src/azure/repository.rs index 6181c00df..4ca0c626a 100644 --- a/crates/services/src/azure/repository.rs +++ b/crates/services/src/azure/repository.rs @@ -141,8 +141,8 @@ pub(super) fn selector(value: &str, host: &str) -> Option { ) } -pub(super) fn resolve(cwd: &Path) -> Option { - crate::forge::checkout::resolve(cwd, remote) +pub(super) fn resolve(checkout: &crate::forge::Checkout<'_>) -> Option { + crate::forge::checkout::resolve(checkout, remote) } pub(super) fn branch(cwd: &Path) -> Option { diff --git a/crates/services/src/bitbucket/mod.rs b/crates/services/src/bitbucket/mod.rs index ad2fda5e3..ea1b0413d 100644 --- a/crates/services/src/bitbucket/mod.rs +++ b/crates/services/src/bitbucket/mod.rs @@ -609,8 +609,8 @@ impl Forge for Bitbucket { repository::pull_request_url(url) } - fn checkout_repository(&self, cwd: &Path) -> Option { - repository::resolve(cwd) + fn resolve_checkout(&self, checkout: &crate::forge::Checkout<'_>) -> Option { + repository::resolve(checkout) } fn repository(&self, name: &str, _: &str) -> Option { @@ -630,7 +630,7 @@ impl Forge for Bitbucket { refresh: bool, ) -> Result, ForgeError> { let cwd = if cwd.exists() { cwd } else { root }; - let Some(target) = repository::resolve(root) else { + let Some(target) = repository::resolve(&crate::forge::Checkout::new(root)) else { return Ok(None); }; let Some(branch) = repository::branch(cwd) else { diff --git a/crates/services/src/bitbucket/repository.rs b/crates/services/src/bitbucket/repository.rs index acf787c05..550b919b9 100644 --- a/crates/services/src/bitbucket/repository.rs +++ b/crates/services/src/bitbucket/repository.rs @@ -91,8 +91,8 @@ pub(super) fn remote(value: &str) -> Option { repository(&segments) } -pub(super) fn resolve(cwd: &Path) -> Option { - crate::forge::checkout::resolve(cwd, remote) +pub(super) fn resolve(checkout: &crate::forge::Checkout<'_>) -> Option { + crate::forge::checkout::resolve(checkout, remote) } pub(super) fn branch(cwd: &Path) -> Option { diff --git a/crates/services/src/forge.rs b/crates/services/src/forge.rs index 40e06ab4e..d0449a405 100644 --- a/crates/services/src/forge.rs +++ b/crates/services/src/forge.rs @@ -5,6 +5,7 @@ pub(crate) mod anchors; pub(crate) mod checkout; +pub use checkout::Checkout; mod http; mod rate_limit; #[cfg(test)] @@ -74,7 +75,11 @@ pub trait Forge: Send + Sync { /// The key and canonical URL of a pull request's web URL, or `None` for any other URL. fn pull_request_url(&self, url: &str) -> Option<(PullRequestKey, String)>; /// The repository a checkout's remote names on the host. - fn checkout_repository(&self, cwd: &Path) -> Option; + fn checkout_repository(&self, cwd: &Path) -> Option { + self.resolve_checkout(&Checkout::new(cwd)) + } + /// Resolve against the same remotes when routing a lookup through multiple hosts. + fn resolve_checkout(&self, checkout: &Checkout<'_>) -> Option; /// A repository named as the host writes it, on `host`. fn repository(&self, name: &str, host: &str) -> Option; /// The web URL of a pull request. @@ -511,10 +516,10 @@ impl Forge for Hosts { }) } - fn checkout_repository(&self, cwd: &Path) -> Option { + fn resolve_checkout(&self, checkout: &Checkout<'_>) -> Option { self.all().into_iter().find_map(|forge| { forge - .checkout_repository(cwd) + .resolve_checkout(checkout) .filter(|repository| self.serves(forge, &repository.host)) }) } @@ -679,6 +684,57 @@ impl Forge for Hosts { mod tests { use super::*; + #[test] + fn checkout_routing_follows_git_init_and_remote_changes() { + let root = std::env::temp_dir().join(format!("tcode-checkout-{}", uuid::Uuid::new_v4())); + let cwd = root.join("checkout"); + std::fs::create_dir_all(&cwd).unwrap(); + let forge = connect(SettingsStore::new(root.clone()), []); + let git = |args: &[&str]| { + let output = crate::process::command("git") + .current_dir(&cwd) + .args(args) + .output() + .unwrap(); + assert!(output.status.success(), "git {args:?}: {output:?}"); + }; + assert!(forge.checkout_repository(&cwd).is_none()); + git(&["init", "-b", "main"]); + assert!(forge.checkout_repository(&cwd).is_none()); + git(&["remote", "add", "origin", "https://github.com/team/app.git"]); + for (url, host, repository) in [ + ("https://github.com/team/app.git", "github.com", "team/app"), + ( + "https://codeberg.org/team/app.git", + "codeberg.org", + "team/app", + ), + ("https://gitlab.com/team/app.git", "gitlab.com", "team/app"), + ( + "https://bitbucket.org/team/app.git", + "bitbucket.org", + "team/app", + ), + ( + "https://dev.azure.com/team/project/_git/app", + "dev.azure.com/team", + "project/app", + ), + ] { + git(&["remote", "set-url", "origin", url]); + assert_eq!( + forge + .checkout_repository(&cwd) + .map(|repository| repository.key(1)), + Some(PullRequestKey::new(host, repository, 1)), + "{url}" + ); + } + git(&["remote", "remove", "origin"]); + assert!(forge.checkout_repository(&cwd).is_none()); + std::fs::remove_dir_all(root).unwrap(); + } + /// A host that only rebases refuses a merge-style branch update before any request; a /// rebase passes the gate and reaches the host, here one turned off in settings. #[test] diff --git a/crates/services/src/forge/checkout.rs b/crates/services/src/forge/checkout.rs index f25e024ba..46c6110d7 100644 --- a/crates/services/src/forge/checkout.rs +++ b/crates/services/src/forge/checkout.rs @@ -2,33 +2,66 @@ //! URLs each kind reads in its own way. use super::Repository; +use std::cell::OnceCell; use std::path::Path; +/// One repository lookup, sharing the fetch remotes across host implementations. +/// A new lookup reads again so remote edits and a later `git init` are visible. +pub struct Checkout<'a> { + cwd: &'a Path, + remotes: OnceCell>, +} + +impl<'a> Checkout<'a> { + pub fn new(cwd: &'a Path) -> Self { + Self { + cwd, + remotes: OnceCell::new(), + } + } + + pub(crate) fn cwd(&self) -> &Path { + self.cwd + } + + pub(crate) fn remotes(&self) -> &[(String, String)] { + self.remotes.get_or_init(|| { + git(self.cwd, &["remote", "-v"]) + .unwrap_or_default() + .lines() + .filter_map(|line| { + let mut parts = line.split_whitespace(); + let name = parts.next()?; + let url = parts.next()?; + (parts.next()? == "(fetch)").then(|| (name.to_owned(), url.to_owned())) + }) + .collect() + }) + } +} + fn git(cwd: &Path, args: &[&str]) -> Option { crate::github::repository::git_read(cwd, args) } /// The fetch remotes of the checkout that `remote` reads as a repository, by remote name. -fn remotes(cwd: &Path, remote: impl Fn(&str) -> Option) -> Vec<(String, Repository)> { - git(cwd, &["remote", "-v"]) - .unwrap_or_default() - .lines() - .filter_map(|line| { - let mut parts = line.split_whitespace(); - let name = parts.next()?; - let url = parts.next()?; - (parts.next()? == "(fetch)").then_some(())?; - Some((name.to_owned(), remote(url)?)) - }) +fn remotes( + checkout: &Checkout<'_>, + remote: impl Fn(&str) -> Option, +) -> Vec<(String, Repository)> { + checkout + .remotes() + .iter() + .filter_map(|(name, url)| Some((name.clone(), remote(url)?))) .collect() } /// The checkout's repository: `upstream`, then `origin`, then the first remote `remote` reads. pub(crate) fn resolve( - cwd: &Path, + checkout: &Checkout<'_>, remote: impl Fn(&str) -> Option, ) -> Option { - let remotes = remotes(cwd, remote); + let remotes = remotes(checkout, remote); ["upstream", "origin"] .iter() .find_map(|name| remotes.iter().find(|(remote, _)| remote == name)) @@ -48,7 +81,7 @@ pub(crate) fn branch(cwd: &Path, remote: impl Fn(&str) -> Option) -> let branch = git(cwd, &["symbolic-ref", "--short", "HEAD"])?; let pushed_to = git(cwd, &["config", &format!("branch.{branch}.remote")])?; let merge = git(cwd, &["config", &format!("branch.{branch}.merge")])?; - let source = remotes(cwd, remote) + let source = remotes(&Checkout::new(cwd), remote) .into_iter() .find(|(name, _)| *name == pushed_to)? .1; diff --git a/crates/services/src/forgejo/mod.rs b/crates/services/src/forgejo/mod.rs index e13c9604b..7e718159a 100644 --- a/crates/services/src/forgejo/mod.rs +++ b/crates/services/src/forgejo/mod.rs @@ -775,8 +775,8 @@ impl Forge for Forgejo { repository::pull_request_url(&self.known(), url) } - fn checkout_repository(&self, cwd: &Path) -> Option { - repository::resolve(&self.known(), cwd) + fn resolve_checkout(&self, checkout: &crate::forge::Checkout<'_>) -> Option { + repository::resolve(&self.known(), checkout) } fn repository(&self, name: &str, host: &str) -> Option { @@ -797,7 +797,8 @@ impl Forge for Forgejo { ) -> Result, ForgeError> { let known = self.known(); let cwd = if cwd.exists() { cwd } else { root }; - let Some(repository) = repository::resolve(&known, root) else { + let Some(repository) = repository::resolve(&known, &crate::forge::Checkout::new(root)) + else { return Ok(None); }; let Some(branch) = repository::branch(&known, cwd) else { diff --git a/crates/services/src/forgejo/repository.rs b/crates/services/src/forgejo/repository.rs index 005a672bf..3ca860487 100644 --- a/crates/services/src/forgejo/repository.rs +++ b/crates/services/src/forgejo/repository.rs @@ -152,8 +152,11 @@ pub(super) fn remote(known: &[String], value: &str) -> Option { } /// The checkout's repository: `upstream`, then `origin`, then the first remote here. -pub(super) fn resolve(known: &[String], cwd: &Path) -> Option { - crate::forge::checkout::resolve(cwd, |url| remote(known, url)) +pub(super) fn resolve( + known: &[String], + checkout: &crate::forge::Checkout<'_>, +) -> Option { + crate::forge::checkout::resolve(checkout, |url| remote(known, url)) } /// The checked-out branch and where it is pushed: the head owner and branch a pull request diff --git a/crates/services/src/git.rs b/crates/services/src/git.rs index be5330328..deda88547 100644 --- a/crates/services/src/git.rs +++ b/crates/services/src/git.rs @@ -491,8 +491,9 @@ pub fn read_status(cwd: &Path) -> GitStatus { default_branch.as_deref(), has_origin_remote, ); - status.github_repository = crate::github::repository::resolve(cwd) - .map(|repository| format!("{}/{}", repository.owner, repository.name)); + status.github_repository = + crate::github::repository::resolve(&crate::forge::Checkout::new(cwd)) + .map(|repository| format!("{}/{}", repository.owner, repository.name)); status } diff --git a/crates/services/src/github/forge.rs b/crates/services/src/github/forge.rs index bf6aff4c6..bac10ffce 100644 --- a/crates/services/src/github/forge.rs +++ b/crates/services/src/github/forge.rs @@ -99,8 +99,8 @@ impl Forge for GitHub { repository::pull_request_url(url) } - fn checkout_repository(&self, cwd: &Path) -> Option { - repository::resolve(cwd).map(neutral) + fn resolve_checkout(&self, checkout: &crate::forge::Checkout<'_>) -> Option { + repository::resolve(checkout).map(neutral) } fn repository(&self, name: &str, host: &str) -> Option { @@ -118,9 +118,10 @@ impl Forge for GitHub { refresh: bool, ) -> Result, ForgeError> { let cwd = if cwd.exists() { cwd } else { root }; - let (Some(head), Some(project_repository)) = - (repository::branch_head(cwd), repository::resolve(root)) - else { + let (Some(head), Some(project_repository)) = ( + repository::branch_head(cwd), + repository::resolve(&crate::forge::Checkout::new(root)), + ) else { return Ok(None); }; if head.repository != project_repository { @@ -134,7 +135,8 @@ impl Forge for GitHub { if result.key.host != project_repository.host || result.key.repository != project_repository.key(result.key.number).repository || repository::branch_head(cwd).as_ref() != Some(&head) - || repository::resolve(root).as_ref() != Some(&project_repository) + || repository::resolve(&crate::forge::Checkout::new(root)).as_ref() + != Some(&project_repository) { return Err(ForgeError { kind: ForgeErrorKind::Uncertain, diff --git a/crates/services/src/github/repository.rs b/crates/services/src/github/repository.rs index 3d8ce9bd3..8f90dd49c 100644 --- a/crates/services/src/github/repository.rs +++ b/crates/services/src/github/repository.rs @@ -115,43 +115,31 @@ pub fn git_read(cwd: &Path, args: &[&str]) -> Option { .then(|| String::from_utf8_lossy(&output.stdout).trim().to_string()) } -fn fetch_remotes(cwd: &Path) -> Vec<(String, String)> { - git_read(cwd, &["remote", "-v"]) - .unwrap_or_default() - .lines() - .filter_map(|line| { - let mut parts = line.split_whitespace(); - let name = parts.next()?; - let url = parts.next()?; - if parts.next()? != "(fetch)" { - return None; - } - Some((name.to_owned(), url.to_owned())) - }) - .collect() -} - fn remotes(cwd: &Path) -> Vec<(String, Repository)> { - fetch_remotes(cwd) - .into_iter() - .filter_map(|(name, url)| Some((name, remote(&url)?.0))) + crate::forge::Checkout::new(cwd) + .remotes() + .iter() + .filter_map(|(name, url)| Some((name.clone(), remote(url)?.0))) .collect() } -pub fn resolve(cwd: &Path) -> Option { +pub fn resolve(checkout: &crate::forge::Checkout<'_>) -> Option { let default_host = std::env::var("GH_HOST").unwrap_or_else(|_| "github.com".into()); if let Ok(value) = std::env::var("GH_REPO") && let Some(repository) = selector(&value, &default_host) { return Some(repository); } - let fetch = fetch_remotes(cwd); + let fetch = checkout.remotes(); let remotes: Vec<_> = fetch .iter() .filter_map(|(name, url)| Some((name.clone(), remote(url)?.0))) .collect(); + if remotes.is_empty() { + return None; + } let marks = git_read( - cwd, + checkout.cwd(), &["config", "--get-regexp", "^remote\\..*\\.gh-resolved$"], ) .unwrap_or_default(); @@ -208,7 +196,7 @@ pub struct BranchHead { pub fn branch_head(cwd: &Path) -> Option { let cwd = cwd.canonicalize().ok()?; let branch = git_read(&cwd, &["symbolic-ref", "--short", "HEAD"])?; - let repository = resolve(&cwd)?; + let repository = resolve(&crate::forge::Checkout::new(&cwd))?; let refs = git_read( &cwd, &[ diff --git a/crates/services/src/gitlab/mod.rs b/crates/services/src/gitlab/mod.rs index 25ad058de..fcaa0dd98 100644 --- a/crates/services/src/gitlab/mod.rs +++ b/crates/services/src/gitlab/mod.rs @@ -594,8 +594,8 @@ impl Forge for GitLab { repository::pull_request_url(&self.known(), url) } - fn checkout_repository(&self, cwd: &Path) -> Option { - repository::resolve(&self.known(), cwd) + fn resolve_checkout(&self, checkout: &crate::forge::Checkout<'_>) -> Option { + repository::resolve(&self.known(), checkout) } fn repository(&self, name: &str, host: &str) -> Option { @@ -616,7 +616,7 @@ impl Forge for GitLab { ) -> Result, ForgeError> { let known = self.known(); let cwd = if cwd.exists() { cwd } else { root }; - let Some(target) = repository::resolve(&known, root) else { + let Some(target) = repository::resolve(&known, &crate::forge::Checkout::new(root)) else { return Ok(None); }; let Some(branch) = repository::branch(&known, cwd) else { diff --git a/crates/services/src/gitlab/repository.rs b/crates/services/src/gitlab/repository.rs index 6d37cc422..e044bd7e5 100644 --- a/crates/services/src/gitlab/repository.rs +++ b/crates/services/src/gitlab/repository.rs @@ -137,8 +137,11 @@ pub(super) fn remote(known: &[String], value: &str) -> Option { } /// The checkout's project: `upstream`, then `origin`, then the first remote here. -pub(super) fn resolve(known: &[String], cwd: &Path) -> Option { - crate::forge::checkout::resolve(cwd, |url| remote(known, url)) +pub(super) fn resolve( + known: &[String], + checkout: &crate::forge::Checkout<'_>, +) -> Option { + crate::forge::checkout::resolve(checkout, |url| remote(known, url)) } /// The checked-out branch and the project and branch a merge request from it names as its diff --git a/crates/services/tests/github.rs b/crates/services/tests/github.rs index 3a1616671..f06d48f8d 100644 --- a/crates/services/tests/github.rs +++ b/crates/services/tests/github.rs @@ -1230,11 +1230,18 @@ fn real_git_fork_heads_follow_gh_default_without_mistaking_the_base_for_a_publis git(&["config", "branch.topic.merge", "refs/heads/main"]); let subdirectory = cwd.join("nested"); std::fs::create_dir(&subdirectory).unwrap(); - assert_eq!(repository::resolve(&subdirectory).unwrap().owner, "sample"); + assert_eq!( + repository::resolve(&tcode_services::forge::Checkout::new(&subdirectory)) + .unwrap() + .owner, + "sample" + ); git(&["config", "--unset", "remote.upstream.gh-resolved"]); git(&["config", "remote.origin.gh-resolved", "base"]); assert_eq!( - repository::resolve(&subdirectory).unwrap().owner, + repository::resolve(&tcode_services::forge::Checkout::new(&subdirectory)) + .unwrap() + .owner, "sample", "mixed hosts and SSH aliases reject the strict gh mark and use the host-ranked remote" ); From f06d3ab5c80de3009afe3247c8bf2b8da2b75e8b Mon Sep 17 00:00:00 2001 From: Tryanks Date: Sat, 24 Oct 2026 03:40:25 +0800 Subject: [PATCH 10/15] ci: remove temporary Windows process tracing --- .config/nextest.toml | 3 --- .github/workflows/ci.yml | 26 +------------------------- 2 files changed, 1 insertion(+), 28 deletions(-) diff --git a/.config/nextest.toml b/.config/nextest.toml index 577cdbce8..837431323 100644 --- a/.config/nextest.toml +++ b/.config/nextest.toml @@ -6,6 +6,3 @@ priority = 100 [profile.ci] # Keep nextest's 200 ms threshold, but do not accept leaked output handles as a pass. leak-timeout = { period = "200ms", result = "fail" } - -[profile.ci.junit] -path = "junit.xml" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8d2ae376a..66a244f77 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -116,33 +116,9 @@ jobs: run: cargo clippy --workspace --all-targets --locked -- -D warnings - name: Run tests - if: matrix.task == 'tests' && runner.os == 'macOS' + if: matrix.task == 'tests' && runner.os != 'Linux' run: cargo nextest run --workspace --locked --profile ci - - name: Trace Windows test Git processes - if: matrix.task == 'tests' && runner.os == 'Windows' - shell: pwsh - run: | - $trace = Join-Path $env:RUNNER_TEMP 'nextest-git-trace' - New-Item -ItemType Directory -Force $trace | Out-Null - (Get-Command git).Source | Set-Content (Join-Path $trace 'git-install.txt') - git version --build-options | Add-Content (Join-Path $trace 'git-install.txt') - git --exec-path | Add-Content (Join-Path $trace 'git-install.txt') - $env:GIT_TRACE2_EVENT = $trace - $env:GIT_TRACE2_ENV_VARS = 'NEXTEST_TEST_NAME,NEXTEST_BINARY_ID,NEXTEST_ATTEMPT_ID' - $env:GIT_TRACE2_CONFIG_PARAMS = 'core.fsmonitor,maintenance.auto' - cargo nextest run --workspace --locked --profile ci --no-fail-fast - - - name: Upload Windows process trace - if: always() && matrix.task == 'tests' && runner.os == 'Windows' - uses: actions/upload-artifact@v7 - with: - name: windows-git-trace - path: | - ${{ runner.temp }}/nextest-git-trace - target/nextest/ci/junit.xml - retention-days: 7 - - name: Test iOS text input on the host if: matrix.task == 'tests' && runner.os == 'macOS' run: cargo test -p gpui-ios --lib --locked From 192bbdae9b2576ba22961ca4874f65f32542ec89 Mon Sep 17 00:00:00 2001 From: Tryanks Date: Sat, 24 Oct 2026 07:20:21 +0800 Subject: [PATCH 11/15] Keep tcode's own stdio out of the children it spawns A Windows child inherits every inheritable handle of its parent, so a git that outlived a test process held nextest's output pipes open and the test was reported as leaky. The process helpers now take tcode's standard handles out of that set once; Stdio::inherit still hands them over through std's own inheritable duplicates. --- Cargo.lock | 1 + crates/agent/Cargo.toml | 4 ++++ crates/agent/src/lib.rs | 2 ++ crates/agent/src/process.rs | 36 +++++++++++++++++++++++++++++++++- crates/services/src/process.rs | 8 ++++++-- 5 files changed, 48 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 27f4612fe..dd23e892d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -170,6 +170,7 @@ dependencies = [ "toml 1.1.6+spec-1.1.0", "ureq", "uuid", + "windows 0.62.2", ] [[package]] diff --git a/crates/agent/Cargo.toml b/crates/agent/Cargo.toml index 595d5ba19..d3eac58df 100644 --- a/crates/agent/Cargo.toml +++ b/crates/agent/Cargo.toml @@ -13,6 +13,7 @@ process = [ "dep:smol", "dep:ureq", "dep:uuid", + "dep:windows", ] [dependencies] @@ -31,6 +32,9 @@ smol = { version = "2", optional = true } ureq = { version = "2", default-features = false, features = ["tls", "gzip"], optional = true } uuid = { version = "1", features = ["v4"], optional = true } +[target.'cfg(windows)'.dependencies] +windows = { version = "=0.62.2", features = ["Win32_Foundation"], optional = true } + [dev-dependencies] env_logger = "0.11" toml = "1.1" diff --git a/crates/agent/src/lib.rs b/crates/agent/src/lib.rs index fb6b4d17d..4a0b25e44 100644 --- a/crates/agent/src/lib.rs +++ b/crates/agent/src/lib.rs @@ -38,6 +38,8 @@ pub mod pi; #[cfg(feature = "process")] mod process; #[cfg(feature = "process")] +pub use process::keep_own_stdio_from_children; +#[cfg(feature = "process")] mod subagent_tail; use std::path::PathBuf; diff --git a/crates/agent/src/process.rs b/crates/agent/src/process.rs index 789273bba..5b517c576 100644 --- a/crates/agent/src/process.rs +++ b/crates/agent/src/process.rs @@ -1,4 +1,5 @@ -//! Child-process constructors that never flash a console window on Windows. +//! Child-process constructors that never flash a console window on Windows, +//! and never hand a child this process's own standard handles. //! //! Provider CLIs are spawned from a GUI app; a plain `Command` on Windows //! allocates a console for the child, which pops a black box on screen. @@ -17,8 +18,41 @@ const STDERR_TAIL_LINES: usize = 20; #[cfg(windows)] const CREATE_NO_WINDOW: u32 = 0x0800_0000; +/// Keep this process's own standard handles out of every child it starts. +/// +/// Windows gives a child each inheritable handle of its parent, not only the +/// stdio its `Command` names, so a child that outlives the parent keeps open +/// the pipes whoever runs the parent reads from. A child spawned with +/// `Stdio::inherit` still gets them: std hands it an inheritable duplicate. +/// No-op elsewhere. +pub fn keep_own_stdio_from_children() { + #[cfg(windows)] + { + use std::os::windows::io::AsRawHandle as _; + use windows::Win32::Foundation::{ + HANDLE, HANDLE_FLAG_INHERIT, HANDLE_FLAGS, SetHandleInformation, + }; + static ONCE: std::sync::Once = std::sync::Once::new(); + ONCE.call_once(|| { + for handle in [ + std::io::stdin().as_raw_handle(), + std::io::stdout().as_raw_handle(), + std::io::stderr().as_raw_handle(), + ] { + // SAFETY: these are this process's standard handles, open for + // its lifetime; a missing one only makes the call fail, which + // leaves nothing to keep from a child. + let _ = unsafe { + SetHandleInformation(HANDLE(handle), HANDLE_FLAG_INHERIT.0, HANDLE_FLAGS(0)) + }; + } + }); + } +} + /// A blocking `std::process::Command` with the console suppressed. pub(crate) fn command>(program: S) -> std::process::Command { + keep_own_stdio_from_children(); #[cfg_attr(not(windows), allow(unused_mut))] // Approved constructor: this is the helper every other site must use. #[allow(clippy::disallowed_methods)] diff --git a/crates/services/src/process.rs b/crates/services/src/process.rs index 582d3e794..c591d9e23 100644 --- a/crates/services/src/process.rs +++ b/crates/services/src/process.rs @@ -1,7 +1,7 @@ //! Child-process helpers. //! //! Every process tcode spawns (git, the provider CLIs, npm, editors, …) must go -//! through these constructors, for two Windows reasons: +//! through these constructors, for three Windows reasons: //! //! 1. A plain `Command` pops a console window for the child, which is jarring in //! a GUI app. `CREATE_NO_WINDOW` suppresses it. @@ -9,8 +9,11 @@ //! `npm` / `pnpm` / `bun` (and `claude`) **`.cmd` shims** are invisible to it. //! [`resolve_program`] does a `PATHEXT`-aware PATH search first (shared with //! the agent crate's provider-binary resolution). +//! 3. A child inherits every inheritable handle of tcode's, tcode's own stdout +//! and stderr included, so a child that outlives tcode keeps whoever reads +//! tcode's output waiting. [`agent::keep_own_stdio_from_children`] stops it. //! -//! On other platforms both are no-ops / passthroughs — `exec` resolves PATH. +//! On other platforms all three are no-ops / passthroughs — `exec` resolves PATH. /// `CREATE_NO_WINDOW`: run the child without allocating a console. #[cfg(windows)] @@ -44,6 +47,7 @@ pub fn resolve_program>(program: S) -> std::ffi::OsStr /// A `std::process::Command` that never flashes a console window, with its /// program resolved through [`resolve_program`]. pub fn command>(program: S) -> std::process::Command { + agent::keep_own_stdio_from_children(); // Approved constructor: this is the helper every other site must use. #[allow(clippy::disallowed_methods)] let mut cmd = std::process::Command::new(resolve_program(program)); From 225d478c213ad86883087da64afb1dce98712e1f Mon Sep 17 00:00:00 2001 From: Tryanks Date: Sat, 24 Oct 2026 07:20:39 +0800 Subject: [PATCH 12/15] Park the runtime test host on queued work, not on idle windows run_until_parked waited out a 50/250 ms quiet window: a guess at how long background work takes, which loaded runners overrun. It now runs what is queued, barriers the store writer and returns. The tests that relied on the window wait for the state they assert instead: - sweep lets a running sync finish, since a sweep that finds one is skipped - an orchestration Cancel waits for its reply - a cold read and a subscription wait for the whole log after the bounded read answers first - provider events wait for the host to take or act on them - the native mirror waits for its last reply as well as its turn end --- .../src/app/pull_request_watch_tests.rs | 10 ++- crates/runtime/src/app/pull_requests_tests.rs | 14 ++++- crates/runtime/src/app/test_support.rs | 62 ++++++++----------- crates/runtime/src/app/tests.rs | 44 +++++++------ 4 files changed, 72 insertions(+), 58 deletions(-) diff --git a/crates/runtime/src/app/pull_request_watch_tests.rs b/crates/runtime/src/app/pull_request_watch_tests.rs index 80d4162bf..98d123639 100644 --- a/crates/runtime/src/app/pull_request_watch_tests.rs +++ b/crates/runtime/src/app/pull_request_watch_tests.rs @@ -323,6 +323,10 @@ impl Harness { ] { self.events.try_send(event).unwrap(); } + // The host's event pump queues each event for the host as it takes it, + // whether or not the host still acts on it. + let events = self.events.clone(); + self.cx.run_until(|_| events.is_empty()); self.cx.run_until_parked(); } @@ -837,7 +841,11 @@ fn a_wake_steers_into_a_running_turn_and_is_not_repeated() { .events .try_send(AgentEvent::TurnAccepted { delivery_id }) .unwrap(); - harness.cx.run_until_parked(); + harness.cx.run_until(|state| { + state + .resident("thread") + .is_some_and(|session| session.delivery_in_flight.is_none() && session.turn_in_flight) + }); harness.pass(); let commands = harness.commands.clone(); diff --git a/crates/runtime/src/app/pull_requests_tests.rs b/crates/runtime/src/app/pull_requests_tests.rs index 70337a378..2282e9c27 100644 --- a/crates/runtime/src/app/pull_requests_tests.rs +++ b/crates/runtime/src/app/pull_requests_tests.rs @@ -100,6 +100,8 @@ fn linked_meta(id: &str, settled: bool) -> SessionMeta { meta } fn sweep(state: &TestEntity, cx: &mut TestAppContext) { + // A sweep that finds a sync still running is skipped; let that one finish. + cx.run_until(|state| !state.pull_requests.syncing); state.update(cx, |state, cx| { state.sweep_pull_requests(false, cx).detach() }); @@ -1045,7 +1047,11 @@ fn instructions_reach_the_provider_at_launch_and_no_turn_carries_them() { .events .try_send(AgentEvent::TurnAccepted { delivery_id }) .unwrap(); - cx.run_until_parked(); + cx.run_until(|state| { + state + .resident("thread") + .is_some_and(|session| session.delivery_in_flight.is_none()) + }); let stored = store .read_events("thread") .unwrap() @@ -1091,9 +1097,11 @@ fn instructions_reach_the_provider_at_launch_and_no_turn_carries_them() { .events .try_send(AgentEvent::McpServersNotAttached) .unwrap(); - cx.run_until_parked(); + cx.run_until(|state| { + let tools = state.session_status_snapshot("thread").unwrap(); + !tools.pull_request_tools.unwrap().attached + }); let tools = disclosed(&state); - assert!(!tools.attached); assert!(tools.instructions.is_empty()); assert!(!tools.tools.is_empty()); } diff --git a/crates/runtime/src/app/test_support.rs b/crates/runtime/src/app/test_support.rs index 225094bb1..8be7e6d86 100644 --- a/crates/runtime/src/app/test_support.rs +++ b/crates/runtime/src/app/test_support.rs @@ -79,6 +79,10 @@ impl TestAppContext { HostCx::new(self.mailbox_tx.clone(), self.outgoing_tx.clone()) } + /// Run what is already queued for the host, and what that queues in turn, + /// until the mailbox is empty. Work running off the host (thread-pool + /// hops, timers) reports only when it finishes; a test that needs its + /// result waits for that state with [`Self::run_until`]. pub(super) fn run_until_parked(&mut self) { let state = self .state @@ -86,11 +90,13 @@ impl TestAppContext { .and_then(Weak::upgrade) .expect("test state must outlive its context"); let deadline = Instant::now() + Duration::from_secs(5); - let mut idle_since = Instant::now(); - let mut saw_work = false; let mut store_flushed = false; - while Instant::now() < deadline { + loop { + assert!( + Instant::now() < deadline, + "test host failed to park within five seconds" + ); let mut had_work = false; while let Ok(message) = self.mailbox_rx.try_recv() { had_work = true; @@ -104,45 +110,30 @@ impl TestAppContext { had_work = true; } if had_work { - idle_since = Instant::now(); - saw_work = true; store_flushed = false; - } else { - // Loaded CI runners (notably Windows) can take well past 50ms - // to schedule a background completion; calls that processed - // work get a wider idle window before declaring parked. - // Count elapsed time: a 1ms sleep can take much longer on a VM. - let idle_window = - Duration::from_millis(if saw_work && !store_flushed { 250 } else { 50 }); - if idle_since.elapsed() >= idle_window { - if !store_flushed { - // Barrier the store-writer task so persisted state is - // visible before callers assert on it. Its failure - // path can enqueue more work, so keep draining. - store_flushed = true; - if self.flush_store_writer(&state, deadline) { - idle_since = Instant::now(); - continue; - } - } - let mut host_cx = self.host_cx(); - state.borrow().sync_terminal_handles(); - self.domain_diff - .as_mut() - .expect("test domain diff must be initialized") - .emit_changes(&mut state.borrow_mut(), &mut host_cx); - return; + continue; + } + if !store_flushed { + // Barrier the store-writer task so persisted state is + // visible before callers assert on it. Its failure path can + // enqueue more work, so keep draining. + store_flushed = true; + if self.flush_store_writer(&state, deadline) { + continue; } } - std::thread::sleep(Duration::from_millis(1)); + break; } - panic!("test host failed to park within five seconds"); + let mut host_cx = self.host_cx(); + state.borrow().sync_terminal_handles(); + self.domain_diff + .as_mut() + .expect("test domain diff must be initialized") + .emit_changes(&mut state.borrow_mut(), &mut host_cx); } /// Park repeatedly until `done` observes the state a background chain - /// must reach. `run_until_parked` only watches the mailbox, so a chain - /// that hops through `unblock` (thread-pool filesystem work) between the - /// last event and its completion can look idle longer than the window. + /// must reach. pub(super) fn run_until(&mut self, mut done: impl FnMut(&TestClientState) -> bool) { let deadline = Instant::now() + Duration::from_secs(5); loop { @@ -159,6 +150,7 @@ impl TestAppContext { Instant::now() < deadline, "test host condition not reached within five seconds" ); + std::thread::sleep(Duration::from_millis(1)); } } diff --git a/crates/runtime/src/app/tests.rs b/crates/runtime/src/app/tests.rs index 76aa21a5e..eaa786c81 100644 --- a/crates/runtime/src/app/tests.rs +++ b/crates/runtime/src/app/tests.rs @@ -340,13 +340,28 @@ fn assert_native_mirror_turn_lifecycle(evict: bool, late: bool, end: MirrorEnd, state.load_background_session(meta, cx); } }); + // The turn's end can show before its last reply is folded in. + let replies = |mirror: &ActiveSession| { + mirror + .timeline + .entries + .iter() + .filter(|entry| { + matches!( + entry.content, + EntryContent::Item(ItemContent::AssistantMessage { .. }) + ) + }) + .count() + }; cx.run_until(|state| { state.resident(&mirror_id).is_some_and(|mirror| { - mirror - .timeline - .turns - .first() - .is_some_and(|turn| turn.end_ts.is_some()) + replies(mirror) == expected_items + && mirror + .timeline + .turns + .first() + .is_some_and(|turn| turn.end_ts.is_some()) }) }); state.update(cx, |state, _| { @@ -365,18 +380,6 @@ fn assert_native_mirror_turn_lifecycle(evict: bool, late: bool, end: MirrorEnd, .activity .working ); - assert_eq!( - mirror - .timeline - .entries - .iter() - .filter(|entry| matches!( - entry.content, - EntryContent::Item(ItemContent::AssistantMessage { .. }) - )) - .count(), - expected_items - ); }); } @@ -9355,6 +9358,8 @@ fn an_appended_snapshot_drops_the_superseded_ones_diffs_in_the_same_commit() { &through_pipe(&state, cx, 1, subscribe_events("thread", None)), 1, ); + // The window can be served before the whole log is read and kept. + cx.run_until(|state| state.event_records.contains_key("thread")); let snapshot = |diff: &str| AgentEvent::TurnChangesUpdated { turn_id: "t".into(), changes: vec![agent::FileChange { @@ -10279,9 +10284,10 @@ fn pages_and_outputs_of_a_thread_nobody_opened_are_read_and_not_kept() { query_reply(&through_pipe(&state, cx, 2, read_output), 2), QueryResponse::ItemOutput(output) ); + // The bounded read answers first; the whole log's read finishes after. + cx.run_until(|state| state.log_hydrations.is_empty()); state.read(|state| { assert!(state.resident("cold").is_none()); - assert!(state.log_hydrations.is_empty()); assert!(state.event_records.is_empty()); }); } @@ -11511,7 +11517,7 @@ fn a_finished_child_holds_its_lead_until_settled_and_cancel_never_delivers() { let op = |state: &TestEntity, cx: &mut TestAppContext, op| { let (reply, response) = smol::channel::bounded(1); state.update(cx, |state, cx| state.handle_orchestrate_op(op, reply, cx)); - cx.run_until_parked(); + cx.run_until(|_| !response.is_empty()); response.try_recv().unwrap() }; // Every run here started and ended at `stamp`. From c2a340daa880f3a56af8885080d42e4d25af1be8 Mon Sep 17 00:00:00 2001 From: Tryanks Date: Sat, 24 Oct 2026 07:20:57 +0800 Subject: [PATCH 13/15] Share one remote listing per repository lookup The Forge trait takes the lookup itself: checkout_repository and discover receive a Checkout, so routing through the hosts and the chosen host's discovery read the remotes once, and the second trait method that only forwarded to the first is gone. A branch checked out at the project root reuses the root's listing, branch_head and read_status read theirs once, and GitHub maps remotes through the shared parser instead of a copy of it. --- crates/runtime/src/app/pull_requests.rs | 14 +++++-- crates/runtime/src/app/pull_requests_tests.rs | 12 +++++- crates/services/src/azure/mod.rs | 10 ++--- crates/services/src/azure/repository.rs | 7 +++- crates/services/src/bitbucket/mod.rs | 10 ++--- crates/services/src/bitbucket/repository.rs | 7 +++- crates/services/src/forge.rs | 38 +++++++------------ crates/services/src/forge/checkout.rs | 22 ++++++++--- crates/services/src/forgejo/mod.rs | 11 +++--- crates/services/src/forgejo/repository.rs | 8 +++- crates/services/src/git.rs | 10 ++--- crates/services/src/github/forge.rs | 15 ++++---- crates/services/src/github/repository.rs | 18 +++------ crates/services/src/gitlab/mod.rs | 10 ++--- crates/services/src/gitlab/repository.rs | 8 +++- 15 files changed, 109 insertions(+), 91 deletions(-) diff --git a/crates/runtime/src/app/pull_requests.rs b/crates/runtime/src/app/pull_requests.rs index 4a2304ad2..a25efd4f0 100644 --- a/crates/runtime/src/app/pull_requests.rs +++ b/crates/runtime/src/app/pull_requests.rs @@ -8,7 +8,7 @@ use tcode_protocol::{ CommandResponse, ProtocolError, PullRequestAction, PullRequestActionResult, PullRequestRead, PullRequestReadResponse, QueryResponse, }; -use tcode_services::forge::{Forge, ForgeError, ForgeErrorKind, Summary}; +use tcode_services::forge::{Checkout, Forge, ForgeError, ForgeErrorKind, Summary}; pub(super) struct PullRequestRuntime { pub(super) forge: Arc, @@ -170,7 +170,7 @@ fn resolve_reference( message: format!("This project has no {hosts} repository. Use a full PR URL."), }; let key = forge - .checkout_repository(cwd) + .checkout_repository(&Checkout::new(cwd)) .ok_or_else(no_repository)? .key(number); let url = forge.url(&key).ok_or_else(no_repository)?; @@ -431,7 +431,11 @@ impl AppState { let name = target.repository.ok_or_else(missing)?; let host = target .host - .or_else(|| forge.checkout_repository(&cwd).map(|r| r.host)) + .or_else(|| { + forge + .checkout_repository(&Checkout::new(&cwd)) + .map(|r| r.host) + }) .ok_or_else(|| "Pass host or a full PR URL.".to_owned())?; let invalid = || format!("Invalid {hosts} repository."); let key = forge @@ -1485,7 +1489,9 @@ impl AppState { metas, cwd, root, - host.unblock(move || forge.discover(&read_cwd, &read_root, refresh)), + host.unblock(move || { + forge.discover(&read_cwd, &Checkout::new(&read_root), refresh) + }), )); } for (metas, cwd, root, task) in tasks { diff --git a/crates/runtime/src/app/pull_requests_tests.rs b/crates/runtime/src/app/pull_requests_tests.rs index 2282e9c27..06e390f79 100644 --- a/crates/runtime/src/app/pull_requests_tests.rs +++ b/crates/runtime/src/app/pull_requests_tests.rs @@ -2324,7 +2324,10 @@ fn a_partly_posted_review_keeps_only_unposted_drafts_for_the_next_submission() { fn pull_request_url(&self, _: &str) -> Option<(PullRequestKey, String)> { unreachable!() } - fn resolve_checkout(&self, _: &tcode_services::forge::Checkout<'_>) -> Option { + fn checkout_repository( + &self, + _: &tcode_services::forge::Checkout<'_>, + ) -> Option { unreachable!() } fn repository(&self, _: &str, _: &str) -> Option { @@ -2333,7 +2336,12 @@ fn a_partly_posted_review_keeps_only_unposted_drafts_for_the_next_submission() { fn url(&self, _: &PullRequestKey) -> Option { unreachable!() } - fn discover(&self, _: &Path, _: &Path, _: bool) -> Result, ForgeError> { + fn discover( + &self, + _: &Path, + _: &tcode_services::forge::Checkout<'_>, + _: bool, + ) -> Result, ForgeError> { unreachable!() } fn summary(&self, _: &PullRequestKey) -> Result { diff --git a/crates/services/src/azure/mod.rs b/crates/services/src/azure/mod.rs index 54bfd0e48..f30e7d869 100644 --- a/crates/services/src/azure/mod.rs +++ b/crates/services/src/azure/mod.rs @@ -753,7 +753,7 @@ impl Forge for Azure { repository::pull_request_url(url) } - fn resolve_checkout(&self, checkout: &crate::forge::Checkout<'_>) -> Option { + fn checkout_repository(&self, checkout: &crate::forge::Checkout<'_>) -> Option { repository::resolve(checkout) } @@ -770,14 +770,14 @@ impl Forge for Azure { fn discover( &self, cwd: &Path, - root: &Path, + root: &crate::forge::Checkout<'_>, refresh: bool, ) -> Result, ForgeError> { - let cwd = if cwd.exists() { cwd } else { root }; - let Some(target) = repository::resolve(&crate::forge::Checkout::new(root)) else { + let cwd = if cwd.exists() { cwd } else { root.cwd() }; + let Some(target) = repository::resolve(root) else { return Ok(None); }; - let Some(branch) = repository::branch(cwd) else { + let Some(branch) = repository::branch(root, cwd) else { return Ok(None); }; let slot = ( diff --git a/crates/services/src/azure/repository.rs b/crates/services/src/azure/repository.rs index 4ca0c626a..2666b9cff 100644 --- a/crates/services/src/azure/repository.rs +++ b/crates/services/src/azure/repository.rs @@ -145,8 +145,11 @@ pub(super) fn resolve(checkout: &crate::forge::Checkout<'_>) -> Option Option { - crate::forge::checkout::branch(cwd, remote) +pub(super) fn branch( + root: &crate::forge::Checkout<'_>, + cwd: &Path, +) -> Option { + crate::forge::checkout::branch(root, cwd, remote) } #[cfg(test)] diff --git a/crates/services/src/bitbucket/mod.rs b/crates/services/src/bitbucket/mod.rs index ea1b0413d..ea4c8ab72 100644 --- a/crates/services/src/bitbucket/mod.rs +++ b/crates/services/src/bitbucket/mod.rs @@ -609,7 +609,7 @@ impl Forge for Bitbucket { repository::pull_request_url(url) } - fn resolve_checkout(&self, checkout: &crate::forge::Checkout<'_>) -> Option { + fn checkout_repository(&self, checkout: &crate::forge::Checkout<'_>) -> Option { repository::resolve(checkout) } @@ -626,14 +626,14 @@ impl Forge for Bitbucket { fn discover( &self, cwd: &Path, - root: &Path, + root: &crate::forge::Checkout<'_>, refresh: bool, ) -> Result, ForgeError> { - let cwd = if cwd.exists() { cwd } else { root }; - let Some(target) = repository::resolve(&crate::forge::Checkout::new(root)) else { + let cwd = if cwd.exists() { cwd } else { root.cwd() }; + let Some(target) = repository::resolve(root) else { return Ok(None); }; - let Some(branch) = repository::branch(cwd) else { + let Some(branch) = repository::branch(root, cwd) else { return Ok(None); }; let slot = ( diff --git a/crates/services/src/bitbucket/repository.rs b/crates/services/src/bitbucket/repository.rs index 550b919b9..cb17f1cca 100644 --- a/crates/services/src/bitbucket/repository.rs +++ b/crates/services/src/bitbucket/repository.rs @@ -95,8 +95,11 @@ pub(super) fn resolve(checkout: &crate::forge::Checkout<'_>) -> Option Option { - crate::forge::checkout::branch(cwd, remote) +pub(super) fn branch( + root: &crate::forge::Checkout<'_>, + cwd: &Path, +) -> Option { + crate::forge::checkout::branch(root, cwd, remote) } #[cfg(test)] diff --git a/crates/services/src/forge.rs b/crates/services/src/forge.rs index d0449a405..fb0230a05 100644 --- a/crates/services/src/forge.rs +++ b/crates/services/src/forge.rs @@ -75,11 +75,7 @@ pub trait Forge: Send + Sync { /// The key and canonical URL of a pull request's web URL, or `None` for any other URL. fn pull_request_url(&self, url: &str) -> Option<(PullRequestKey, String)>; /// The repository a checkout's remote names on the host. - fn checkout_repository(&self, cwd: &Path) -> Option { - self.resolve_checkout(&Checkout::new(cwd)) - } - /// Resolve against the same remotes when routing a lookup through multiple hosts. - fn resolve_checkout(&self, checkout: &Checkout<'_>) -> Option; + fn checkout_repository(&self, checkout: &Checkout<'_>) -> Option; /// A repository named as the host writes it, on `host`. fn repository(&self, name: &str, host: &str) -> Option; /// The web URL of a pull request. @@ -90,7 +86,7 @@ pub trait Forge: Send + Sync { fn discover( &self, cwd: &Path, - root: &Path, + root: &Checkout<'_>, refresh: bool, ) -> Result, ForgeError>; @@ -516,10 +512,10 @@ impl Forge for Hosts { }) } - fn resolve_checkout(&self, checkout: &Checkout<'_>) -> Option { + fn checkout_repository(&self, checkout: &Checkout<'_>) -> Option { self.all().into_iter().find_map(|forge| { forge - .resolve_checkout(checkout) + .checkout_repository(checkout) .filter(|repository| self.serves(forge, &repository.host)) }) } @@ -535,7 +531,7 @@ impl Forge for Hosts { fn discover( &self, cwd: &Path, - root: &Path, + root: &Checkout<'_>, refresh: bool, ) -> Result, ForgeError> { let Some(repository) = self.checkout_repository(root) else { @@ -690,19 +686,13 @@ mod tests { let cwd = root.join("checkout"); std::fs::create_dir_all(&cwd).unwrap(); let forge = connect(SettingsStore::new(root.clone()), []); - let git = |args: &[&str]| { - let output = crate::process::command("git") - .current_dir(&cwd) - .args(args) - .output() - .unwrap(); - assert!(output.status.success(), "git {args:?}: {output:?}"); - }; - assert!(forge.checkout_repository(&cwd).is_none()); + let git = |args: &[&str]| crate::git::run_git(&cwd, args).unwrap(); + let repository = || forge.checkout_repository(&Checkout::new(&cwd)); + assert!(repository().is_none()); git(&["init", "-b", "main"]); - assert!(forge.checkout_repository(&cwd).is_none()); + assert!(repository().is_none()); git(&["remote", "add", "origin", "https://github.com/team/app.git"]); - for (url, host, repository) in [ + for (url, host, name) in [ ("https://github.com/team/app.git", "github.com", "team/app"), ( "https://codeberg.org/team/app.git", @@ -723,15 +713,13 @@ mod tests { ] { git(&["remote", "set-url", "origin", url]); assert_eq!( - forge - .checkout_repository(&cwd) - .map(|repository| repository.key(1)), - Some(PullRequestKey::new(host, repository, 1)), + repository().map(|repository| repository.key(1)), + Some(PullRequestKey::new(host, name, 1)), "{url}" ); } git(&["remote", "remove", "origin"]); - assert!(forge.checkout_repository(&cwd).is_none()); + assert!(repository().is_none()); std::fs::remove_dir_all(root).unwrap(); } diff --git a/crates/services/src/forge/checkout.rs b/crates/services/src/forge/checkout.rs index 46c6110d7..65c3e39ef 100644 --- a/crates/services/src/forge/checkout.rs +++ b/crates/services/src/forge/checkout.rs @@ -45,10 +45,10 @@ fn git(cwd: &Path, args: &[&str]) -> Option { } /// The fetch remotes of the checkout that `remote` reads as a repository, by remote name. -fn remotes( +pub(crate) fn remotes( checkout: &Checkout<'_>, - remote: impl Fn(&str) -> Option, -) -> Vec<(String, Repository)> { + remote: impl Fn(&str) -> Option, +) -> Vec<(String, T)> { checkout .remotes() .iter() @@ -77,11 +77,23 @@ pub(crate) struct Branch { pub(crate) source_branch: String, } -pub(crate) fn branch(cwd: &Path, remote: impl Fn(&str) -> Option) -> Option { +/// The branch checked out at `cwd`; `root`'s remote listing serves when that is the root itself. +pub(crate) fn branch( + root: &Checkout<'_>, + cwd: &Path, + remote: impl Fn(&str) -> Option, +) -> Option { + let elsewhere; + let checkout = if cwd == root.cwd() { + root + } else { + elsewhere = Checkout::new(cwd); + &elsewhere + }; let branch = git(cwd, &["symbolic-ref", "--short", "HEAD"])?; let pushed_to = git(cwd, &["config", &format!("branch.{branch}.remote")])?; let merge = git(cwd, &["config", &format!("branch.{branch}.merge")])?; - let source = remotes(&Checkout::new(cwd), remote) + let source = remotes(checkout, remote) .into_iter() .find(|(name, _)| *name == pushed_to)? .1; diff --git a/crates/services/src/forgejo/mod.rs b/crates/services/src/forgejo/mod.rs index 7e718159a..ffe59f106 100644 --- a/crates/services/src/forgejo/mod.rs +++ b/crates/services/src/forgejo/mod.rs @@ -775,7 +775,7 @@ impl Forge for Forgejo { repository::pull_request_url(&self.known(), url) } - fn resolve_checkout(&self, checkout: &crate::forge::Checkout<'_>) -> Option { + fn checkout_repository(&self, checkout: &crate::forge::Checkout<'_>) -> Option { repository::resolve(&self.known(), checkout) } @@ -792,16 +792,15 @@ impl Forge for Forgejo { fn discover( &self, cwd: &Path, - root: &Path, + root: &crate::forge::Checkout<'_>, refresh: bool, ) -> Result, ForgeError> { let known = self.known(); - let cwd = if cwd.exists() { cwd } else { root }; - let Some(repository) = repository::resolve(&known, &crate::forge::Checkout::new(root)) - else { + let cwd = if cwd.exists() { cwd } else { root.cwd() }; + let Some(repository) = repository::resolve(&known, root) else { return Ok(None); }; - let Some(branch) = repository::branch(&known, cwd) else { + let Some(branch) = repository::branch(&known, root, cwd) else { return Ok(None); }; let slot = ( diff --git a/crates/services/src/forgejo/repository.rs b/crates/services/src/forgejo/repository.rs index 3ca860487..d3640a75c 100644 --- a/crates/services/src/forgejo/repository.rs +++ b/crates/services/src/forgejo/repository.rs @@ -167,8 +167,12 @@ pub(super) struct Branch { pub(super) head_branch: String, } -pub(super) fn branch(known: &[String], cwd: &Path) -> Option { - let found = crate::forge::checkout::branch(cwd, |url| remote(known, url))?; +pub(super) fn branch( + known: &[String], + root: &crate::forge::Checkout<'_>, + cwd: &Path, +) -> Option { + let found = crate::forge::checkout::branch(root, cwd, |url| remote(known, url))?; Some(Branch { head_owner: found.source.locator.split('/').next()?.to_owned(), head_branch: found.source_branch, diff --git a/crates/services/src/git.rs b/crates/services/src/git.rs index deda88547..bb04b73f3 100644 --- a/crates/services/src/git.rs +++ b/crates/services/src/git.rs @@ -473,9 +473,8 @@ pub fn read_status(cwd: &Path) -> GitStatus { } let porcelain = run_git(cwd, &["status", "--porcelain=2", "--branch"]).unwrap_or_default(); let numstat = read_numstat(cwd); - let has_origin_remote = run_git(cwd, &["remote"]) - .map(|out| out.lines().any(|line| line.trim() == "origin")) - .unwrap_or(false); + let checkout = crate::forge::Checkout::new(cwd); + let has_origin_remote = checkout.remotes().iter().any(|(name, _)| name == "origin"); let default_branch = run_git(cwd, &["symbolic-ref", "refs/remotes/origin/HEAD"]) .ok() .map(|value| { @@ -491,9 +490,8 @@ pub fn read_status(cwd: &Path) -> GitStatus { default_branch.as_deref(), has_origin_remote, ); - status.github_repository = - crate::github::repository::resolve(&crate::forge::Checkout::new(cwd)) - .map(|repository| format!("{}/{}", repository.owner, repository.name)); + status.github_repository = crate::github::repository::resolve(&checkout) + .map(|repository| format!("{}/{}", repository.owner, repository.name)); status } diff --git a/crates/services/src/github/forge.rs b/crates/services/src/github/forge.rs index bac10ffce..eb9282282 100644 --- a/crates/services/src/github/forge.rs +++ b/crates/services/src/github/forge.rs @@ -99,7 +99,7 @@ impl Forge for GitHub { repository::pull_request_url(url) } - fn resolve_checkout(&self, checkout: &crate::forge::Checkout<'_>) -> Option { + fn checkout_repository(&self, checkout: &crate::forge::Checkout<'_>) -> Option { repository::resolve(checkout).map(neutral) } @@ -114,14 +114,13 @@ impl Forge for GitHub { fn discover( &self, cwd: &Path, - root: &Path, + root: &crate::forge::Checkout<'_>, refresh: bool, ) -> Result, ForgeError> { - let cwd = if cwd.exists() { cwd } else { root }; - let (Some(head), Some(project_repository)) = ( - repository::branch_head(cwd), - repository::resolve(&crate::forge::Checkout::new(root)), - ) else { + let cwd = if cwd.exists() { cwd } else { root.cwd() }; + let (Some(head), Some(project_repository)) = + (repository::branch_head(cwd), repository::resolve(root)) + else { return Ok(None); }; if head.repository != project_repository { @@ -135,7 +134,7 @@ impl Forge for GitHub { if result.key.host != project_repository.host || result.key.repository != project_repository.key(result.key.number).repository || repository::branch_head(cwd).as_ref() != Some(&head) - || repository::resolve(&crate::forge::Checkout::new(root)).as_ref() + || repository::resolve(&crate::forge::Checkout::new(root.cwd())).as_ref() != Some(&project_repository) { return Err(ForgeError { diff --git a/crates/services/src/github/repository.rs b/crates/services/src/github/repository.rs index 8f90dd49c..ab7a88377 100644 --- a/crates/services/src/github/repository.rs +++ b/crates/services/src/github/repository.rs @@ -115,12 +115,8 @@ pub fn git_read(cwd: &Path, args: &[&str]) -> Option { .then(|| String::from_utf8_lossy(&output.stdout).trim().to_string()) } -fn remotes(cwd: &Path) -> Vec<(String, Repository)> { - crate::forge::Checkout::new(cwd) - .remotes() - .iter() - .filter_map(|(name, url)| Some((name.clone(), remote(url)?.0))) - .collect() +fn remotes(checkout: &crate::forge::Checkout<'_>) -> Vec<(String, Repository)> { + crate::forge::checkout::remotes(checkout, |url| Some(remote(url)?.0)) } pub fn resolve(checkout: &crate::forge::Checkout<'_>) -> Option { @@ -131,10 +127,7 @@ pub fn resolve(checkout: &crate::forge::Checkout<'_>) -> Option { return Some(repository); } let fetch = checkout.remotes(); - let remotes: Vec<_> = fetch - .iter() - .filter_map(|(name, url)| Some((name.clone(), remote(url)?.0))) - .collect(); + let remotes = remotes(checkout); if remotes.is_empty() { return None; } @@ -196,7 +189,8 @@ pub struct BranchHead { pub fn branch_head(cwd: &Path) -> Option { let cwd = cwd.canonicalize().ok()?; let branch = git_read(&cwd, &["symbolic-ref", "--short", "HEAD"])?; - let repository = resolve(&crate::forge::Checkout::new(&cwd))?; + let checkout = crate::forge::Checkout::new(&cwd); + let repository = resolve(&checkout)?; let refs = git_read( &cwd, &[ @@ -209,7 +203,7 @@ pub fn branch_head(cwd: &Path) -> Option { .lines() .find(|line| line.split('\0').next() == Some(format!("refs/heads/{branch}").as_str()))?; let parts: Vec<_> = line.split('\0').collect(); - let remotes = remotes(&cwd); + let remotes = remotes(&checkout); let saved = parts.get(1).copied().unwrap_or_default(); let saved_ref = parts.get(2).copied().unwrap_or_default(); if !saved.is_empty() && saved_ref.is_empty() { diff --git a/crates/services/src/gitlab/mod.rs b/crates/services/src/gitlab/mod.rs index fcaa0dd98..dd37c0121 100644 --- a/crates/services/src/gitlab/mod.rs +++ b/crates/services/src/gitlab/mod.rs @@ -594,7 +594,7 @@ impl Forge for GitLab { repository::pull_request_url(&self.known(), url) } - fn resolve_checkout(&self, checkout: &crate::forge::Checkout<'_>) -> Option { + fn checkout_repository(&self, checkout: &crate::forge::Checkout<'_>) -> Option { repository::resolve(&self.known(), checkout) } @@ -611,15 +611,15 @@ impl Forge for GitLab { fn discover( &self, cwd: &Path, - root: &Path, + root: &crate::forge::Checkout<'_>, refresh: bool, ) -> Result, ForgeError> { let known = self.known(); - let cwd = if cwd.exists() { cwd } else { root }; - let Some(target) = repository::resolve(&known, &crate::forge::Checkout::new(root)) else { + let cwd = if cwd.exists() { cwd } else { root.cwd() }; + let Some(target) = repository::resolve(&known, root) else { return Ok(None); }; - let Some(branch) = repository::branch(&known, cwd) else { + let Some(branch) = repository::branch(&known, root, cwd) else { return Ok(None); }; let slot = ( diff --git a/crates/services/src/gitlab/repository.rs b/crates/services/src/gitlab/repository.rs index e044bd7e5..26bae2ebe 100644 --- a/crates/services/src/gitlab/repository.rs +++ b/crates/services/src/gitlab/repository.rs @@ -146,8 +146,12 @@ pub(super) fn resolve( /// The checked-out branch and the project and branch a merge request from it names as its /// source. -pub(super) fn branch(known: &[String], cwd: &Path) -> Option { - crate::forge::checkout::branch(cwd, |url| remote(known, url)) +pub(super) fn branch( + known: &[String], + root: &crate::forge::Checkout<'_>, + cwd: &Path, +) -> Option { + crate::forge::checkout::branch(root, cwd, |url| remote(known, url)) } #[cfg(test)] From 3113fc9972f709fab7b90c6f33bb16a2e496cbe7 Mon Sep 17 00:00:00 2001 From: Tryanks Date: Sat, 24 Oct 2026 07:20:57 +0800 Subject: [PATCH 14/15] ci: report each platform on its own check and fail leaks everywhere - Each platform's Clippy and tests are two jobs, and its required check waits for those two alone, so a failure names the platform it happened on instead of failing one gate and cancelling the others. - Clippy restores the test cache instead of saving a cache of its own. - Leaked output handles fail in the default nextest profile, so the documented local command and CI judge them the same way. - Windows uses two test slots per CPU like the other runners, now that children no longer inherit the test process's output pipes. --- .config/nextest.toml | 8 +- .github/workflows/ci.yml | 192 ++++++++++++++++++++++++--------------- 2 files changed, 121 insertions(+), 79 deletions(-) diff --git a/.config/nextest.toml b/.config/nextest.toml index 837431323..e0828fa5b 100644 --- a/.config/nextest.toml +++ b/.config/nextest.toml @@ -1,8 +1,8 @@ +[profile.default] +# Keep nextest's 200 ms threshold, but do not accept leaked output handles as a pass. +leak-timeout = { period = "200ms", result = "fail" } + [[profile.default.overrides]] # This otherwise starts near the end and leaves the other test workers idle. filter = 'test(=highlight::tests::shipped_syntax_set_compiles_under_active_regex_backend)' priority = 100 - -[profile.ci] -# Keep nextest's 200 ms threshold, but do not accept leaked output handles as a pass. -leak-timeout = { period = "200ms", result = "fail" } diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 66a244f77..b7f409b41 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,56 +21,88 @@ env: RUST_BACKTRACE: 1 jobs: - desktop-work: - name: ${{ matrix.name }} / ${{ matrix.task }} - runs-on: ${{ matrix.os }} + # Not a matrix: a job can only wait for a whole matrix, and each platform's + # required check must wait for that platform's Clippy and tests alone. + linux-clippy: + name: Linux x64 / clippy + runs-on: ubuntu-24.04 timeout-minutes: 60 - strategy: - fail-fast: false - matrix: - task: [clippy, tests] - platform: [linux, macos, windows] - include: - - platform: linux - name: Linux x64 - os: ubuntu-24.04 - - platform: macos - name: macOS arm64 - os: macos-26 - - platform: windows - name: Windows x64 - os: windows-2022 - steps: - - uses: actions/checkout@v7 + steps: &clippy-steps + - &checkout + uses: actions/checkout@v7 - - name: Disable Windows Defender real-time scanning + - &disable-defender + name: Disable Windows Defender real-time scanning if: runner.os == 'Windows' shell: pwsh continue-on-error: true run: Set-MpPreference -DisableRealtimeMonitoring $true - - name: Install stable Rust + - &install-rust + name: Install stable Rust uses: dtolnay/rust-toolchain@stable with: components: rustfmt, clippy - # Check-mode artifacts differ from test builds. Keep each main job's - # cache separate so parallel saves cannot discard the other mode. + # Clippy restores the test jobs' cache but never saves its own: it already + # finishes before the tests, and a second cache per platform would overflow + # the repository's Actions cache quota and evict the test caches. + - name: Restore Cargo build data + uses: Swatinem/rust-cache@v2 + with: + shared-key: ci-${{ runner.os }}-${{ runner.arch }} + save-if: false + + - &install-linux-dependencies + name: Install Linux system dependencies + if: runner.os == 'Linux' + run: | + # The Azure mirror has delivered packages at ~65 kB/s on these runners. + for source in /etc/apt/sources.list.d/ubuntu.sources /etc/apt/apt-mirrors.txt; do + if [[ -f "$source" ]]; then + sudo sed -i 's|http://azure\.archive\.ubuntu\.com/ubuntu|https://archive.ubuntu.com/ubuntu|g' "$source" + fi + done + apt_get=(sudo apt-get -o Acquire::ForceIPv4=true -o Acquire::Retries=3) + "${apt_get[@]}" update + "${apt_get[@]}" install -y --no-install-recommends \ + build-essential clang cmake pkg-config libssl-dev libzstd-dev \ + libasound2-dev libfontconfig-dev libwayland-dev libxkbcommon-dev \ + libxkbcommon-x11-dev libx11-xcb-dev libxcb1-dev libgbm-dev \ + libvulkan-dev xvfb + + - name: Check formatting + run: cargo fmt --all --check + + - name: Run Clippy + run: cargo clippy --workspace --all-targets --locked -- -D warnings + + linux-tests: + name: Linux x64 / tests + runs-on: ubuntu-24.04 + timeout-minutes: 60 + steps: &test-steps + - *checkout + - *disable-defender + - *install-rust + + # Only main writes the cache so pull requests share one warm copy per + # platform instead of evicting each other from the repository quota. - name: Cache Cargo build data uses: Swatinem/rust-cache@v2 with: - shared-key: ci-${{ runner.os }}-${{ runner.arch }}${{ matrix.task == 'clippy' && '-clippy' || '' }} + shared-key: ci-${{ runner.os }}-${{ runner.arch }} save-if: ${{ github.ref == 'refs/heads/main' }} - name: Install cargo-nextest - if: matrix.task == 'tests' && runner.os != 'Windows' + if: runner.os != 'Windows' uses: taiki-e/install-action@v2 with: tool: nextest # Work around install-action's Windows bash startup failure (actions/partner-runner-images#169). - name: Install cargo-nextest on Windows - if: matrix.task == 'tests' && runner.os == 'Windows' + if: runner.os == 'Windows' shell: pwsh run: | $archive = Join-Path $env:RUNNER_TEMP 'nextest.zip' @@ -78,71 +110,81 @@ jobs: Expand-Archive -Path $archive -DestinationPath "$env:USERPROFILE\.cargo\bin" -Force cargo nextest --version - - name: Install Linux system dependencies - if: runner.os == 'Linux' - run: | - # The Azure mirror has delivered packages at ~65 kB/s on these runners. - for source in /etc/apt/sources.list.d/ubuntu.sources /etc/apt/apt-mirrors.txt; do - if [[ -f "$source" ]]; then - sudo sed -i 's|http://azure\.archive\.ubuntu\.com/ubuntu|https://archive.ubuntu.com/ubuntu|g' "$source" - fi - done - apt_get=(sudo apt-get -o Acquire::ForceIPv4=true -o Acquire::Retries=3) - "${apt_get[@]}" update - "${apt_get[@]}" install -y --no-install-recommends \ - build-essential clang cmake pkg-config libssl-dev libzstd-dev \ - libasound2-dev libfontconfig-dev libwayland-dev libxkbcommon-dev \ - libxkbcommon-x11-dev libx11-xcb-dev libxcb1-dev libgbm-dev \ - libvulkan-dev xvfb + - *install-linux-dependencies + # Two slots per CPU: most tests wait on child processes rather than compute. - name: Set nextest test concurrency - if: matrix.task == 'tests' shell: python run: | import os - test_threads = os.cpu_count() - if os.environ["RUNNER_OS"] != "Windows": - test_threads *= 2 - print(f"nextest test threads: {test_threads}") with open(os.environ["GITHUB_ENV"], "a") as env_file: - env_file.write(f"NEXTEST_TEST_THREADS={test_threads}\n") - - - name: Check formatting - if: matrix.task == 'clippy' - run: cargo fmt --all --check - - - name: Run Clippy - if: matrix.task == 'clippy' - run: cargo clippy --workspace --all-targets --locked -- -D warnings + env_file.write(f"NEXTEST_TEST_THREADS={os.cpu_count() * 2}\n") - name: Run tests - if: matrix.task == 'tests' && runner.os != 'Linux' - run: cargo nextest run --workspace --locked --profile ci + if: runner.os != 'Linux' + run: cargo nextest run --workspace --locked - name: Test iOS text input on the host - if: matrix.task == 'tests' && runner.os == 'macOS' + if: runner.os == 'macOS' run: cargo test -p gpui-ios --lib --locked - name: Run tests under Xvfb - if: matrix.task == 'tests' && runner.os == 'Linux' - run: xvfb-run -a cargo nextest run --workspace --locked --profile ci - - # Preserve the existing required check names. A skipped or cancelled worker - # must not let any desktop gate pass. - desktop: - name: ${{ matrix.name }} - needs: desktop-work + if: runner.os == 'Linux' + run: xvfb-run -a cargo nextest run --workspace --locked + + macos-clippy: + name: macOS arm64 / clippy + runs-on: macos-26 + timeout-minutes: 60 + steps: *clippy-steps + + macos-tests: + name: macOS arm64 / tests + runs-on: macos-26 + timeout-minutes: 60 + steps: *test-steps + + windows-clippy: + name: Windows x64 / clippy + runs-on: windows-2022 + timeout-minutes: 60 + steps: *clippy-steps + + windows-tests: + name: Windows x64 / tests + runs-on: windows-2022 + timeout-minutes: 60 + steps: *test-steps + + # The required checks keep their platform names. A skipped or cancelled job + # must not let its platform's check pass. + linux: + name: Linux x64 + needs: [linux-clippy, linux-tests] if: always() runs-on: ubuntu-24.04 timeout-minutes: 5 - strategy: - matrix: - name: [Linux x64, macOS arm64, Windows x64] - steps: - - name: Require all desktop checks + steps: &require-platform + - name: Require the platform's Clippy and tests env: - RESULT: ${{ needs.desktop-work.result }} - run: test "$RESULT" = success + RESULTS: ${{ join(needs.*.result, ' ') }} + run: test "$RESULTS" = "success success" + + macos: + name: macOS arm64 + needs: [macos-clippy, macos-tests] + if: always() + runs-on: ubuntu-24.04 + timeout-minutes: 5 + steps: *require-platform + + windows: + name: Windows x64 + needs: [windows-clippy, windows-tests] + if: always() + runs-on: ubuntu-24.04 + timeout-minutes: 5 + steps: *require-platform dependencies: name: Dependency hygiene From d54e1ae978ccc84b348e887f7779dd238d6619ff Mon Sep 17 00:00:00 2001 From: Tryanks Date: Sat, 24 Oct 2026 07:20:57 +0800 Subject: [PATCH 15/15] Say why the syntax probe substitutes back-references itself --- crates/ui/src/highlight.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/ui/src/highlight.rs b/crates/ui/src/highlight.rs index ff561e3b3..5fea903be 100644 --- a/crates/ui/src/highlight.rs +++ b/crates/ui/src/highlight.rs @@ -543,9 +543,10 @@ mod tests { assert!(SYNTAX_SET.find_syntax_by_name("Plain Text").is_some()); } - /// Mirror of syntect's private `substitute_backrefs_in_regex` with the - /// placeholder substituter its YAML loader validates patterns with; kept - /// in sync with `examples/sanitize_syntaxes.rs`. + /// syntect keeps `substitute_backrefs_in_regex` private, so the probe + /// substitutes back-references with the placeholder its YAML loader + /// validates patterns with, as `examples/sanitize_syntaxes.rs` does when it + /// regenerates the dump. fn substitute_backrefs(regex_str: &str) -> String { let mut result = String::with_capacity(regex_str.len()); let mut last_was_escape = false;