From c34aa3c0042797292561b73ea54741c274e9e683 Mon Sep 17 00:00:00 2001 From: Bradley Mackey Date: Fri, 25 Sep 2026 14:35:43 +0100 Subject: [PATCH] Fix the flaky race cancellation tests and find rbenv's Ruby when validating The "Cancellation is always checked before returning" tests cancelled their task after creating it, so the task could run the race to completion first and get `.noTasksScheduled`. They now wait for the cancellation before racing. validate.sh now puts rbenv's shims on PATH, so shells that haven't run `rbenv init` use the Ruby from .ruby-version instead of skipping the Fastlane check. Co-Authored-By: Claude Opus 5.5 --- .../FoundationExtensionsTests/Task+RaceTests.swift | 10 ++++++++-- scripts/validate.sh | 5 +++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Vault/Tests/FoundationExtensionsTests/Task+RaceTests.swift b/Vault/Tests/FoundationExtensionsTests/Task+RaceTests.swift index 1a5dbfeb3..c123e1f00 100644 --- a/Vault/Tests/FoundationExtensionsTests/Task+RaceTests.swift +++ b/Vault/Tests/FoundationExtensionsTests/Task+RaceTests.swift @@ -14,8 +14,11 @@ enum TaskRaceTests { @Test("Cancellation is always checked before returning") func noScheduledTasksCancelledThrowsCancellation() async throws { + let cancellationWaiter = TaskCancellationWaiter() let parent = Task { - try await Task.race(firstResolved: [TaskRace]()) + // Only race once cancelled, as the task might otherwise run to completion before `cancel()`. + await cancellationWaiter.waitForTaskCancellation() + return try await Task.race(firstResolved: [TaskRace]()) } parent.cancel() @@ -143,8 +146,11 @@ enum TaskRaceTests { @Test("Cancellation is always checked before returning") func noScheduledTasksCancelledThrowsCancellation() async throws { + let cancellationWaiter = TaskCancellationWaiter() let parent = Task { - try await Task.race(firstValue: [TaskRace]()) + // Only race once cancelled, as the task might otherwise run to completion before `cancel()`. + await cancellationWaiter.waitForTaskCancellation() + return try await Task.race(firstValue: [TaskRace]()) } parent.cancel() diff --git a/scripts/validate.sh b/scripts/validate.sh index de92a2b89..4e1099939 100755 --- a/scripts/validate.sh +++ b/scripts/validate.sh @@ -171,6 +171,11 @@ destination="id=$udid" step "Lint" make -C Vault lint fastlane_note="" +# Shells that haven't run `rbenv init` (non-interactive ones, like an agent's) +# would otherwise find the system Ruby and skip this check. +if command -v rbenv >/dev/null; then + PATH="$(rbenv root)/shims:$PATH" +fi ruby_version=$(cat "$worktree/.ruby-version") if [ "$(cd "$worktree" && ruby -e 'print RUBY_VERSION' 2>/dev/null)" = "$ruby_version" ]; then step "Fastlane config" /bin/bash -c \