Skip to content

fix: detect app-host tests from embedded bundle - #9217

Closed
austinywang wants to merge 2 commits into
mainfrom
fix-ci-app-host-test-mode
Closed

austinywang wants to merge 2 commits into
mainfrom
fix-ci-app-host-test-mode

Conversation

@austinywang

@austinywang austinywang commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • detect app-host test launches from the embedded .xctest bundle
  • keep existing Xcode environment keys as compatibility fallbacks
  • add separate failing-test and fix commits for the regression

Why

Restoring the workflow guard exposed intermittent SIGSEGV crashes on the sentry-init thread before XCTest could connect. Xcode 26.3 does not reliably pass its XCTest environment keys or TestAction environment variables to the app-host process. The app-host test artifact is deterministic: the built app contains cmuxTests.xctest under Contents/PlugIns before launch. Shipping app bundles do not contain an .xctest plug-in.

This unblocks the app-host shards and the nightly build. During the #9208 outage all macOS CI jobs were skipped, so PRs merged in that window were never built or tested and need to be re-checked.

Tests

  • behavior regression in MacSentryStartupPolicyTests
  • bash tests/test_ghostty_zig_version_sync.sh
  • full ci.yml workflow dispatch on the final PR head

Follow-up to #9208.

Summary by CodeRabbit

  • Bug Fixes

    • Improved detection of app-host test runs, including tests embedded in .xctest bundles.
    • Prevented telemetry startup during embedded test execution, even when standard test environment indicators are unavailable.
  • Tests

    • Added coverage verifying that embedded app-host tests do not start telemetry.

@coderabbitai

coderabbitai Bot commented Jul 30, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

MacSentryStartupPolicy now identifies embedded .xctest bundles in the main application and disables Sentry startup for app-host tests. Related XCTest detection documentation and unit-test coverage were updated.

Changes

Sentry test detection

Layer / File(s) Summary
Embedded bundle policy and coverage
Sources/App/MacSentryStartupPolicy.swift, Sources/AppDelegate.swift, cmuxTests/SentryEventScrubberTests.swift
The startup policy checks the main bundle’s built-in plug-ins for .xctest entries, documentation describes the app-host test case, and a unit test verifies Sentry remains disabled.Estimated code review effort: 2 (Simple)

Possibly related PRs

  • manaflow-ai/cmux#8786: Centralizes XCTest/Sentry startup gating around MacSentryStartupPolicy, which this change extends with embedded bundle detection.

Suggested reviewers: azooz2003-bit

🚥 Pre-merge checks | ✅ 24 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (24 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: detecting app-host tests from the embedded bundle.
Description check ✅ Passed The description covers Summary, Why, and Tests well; it only omits some template sections like Demo Video and Checklist.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Cmux Swift Actor Isolation ✅ Passed Patch adds a Sendable value helper and docs only; no new implicit MainActor, shared mutable Sendable, or background UI-store access appears.
Cmux Swift Blocking Runtime ✅ Passed No new semaphore/wait/sleep/sync/lock primitives were introduced; the change only adds XCTest bundle detection and a test.
Cmux Browser Automation Off-Main ✅ Passed PR only changes MacSentry startup policy/comment/test files; no browser.* socket-automation code or policy-routing files were touched, so the rule isn’t implicated.
Cmux Expensive Synchronous Load ✅ Passed PASS: The diff only adds a bounded plug-ins-dir check during app launch; it doesn't introduce RestorableAgentSessionIndex.load(), agent-history JSON, or other interactive heavy loads.
Cmux Cache Substitution Correctness ✅ Passed No cache substitution: the new .xctest check reads the app bundle’s plug-ins directory directly for a startup guard, not a persistence/history/snapshot path.
Cmux No Hacky Sleeps ✅ Passed PR only changes Swift app logic and tests; no TypeScript/JS/shell/build/runtime script sleeps, polling, or wall-clock waits were added.
Cmux Algorithmic Complexity ✅ Passed Added one startup directory scan over the app’s built-in plug-ins; it’s a small fixed-size bundle collection, not a nested or hot-path scan.
Cmux Swift Concurrency ✅ Passed Touched Swift changes are synchronous bundle detection/comment/test updates; no new DispatchQueue, Combine, completion-handler, or fire-and-forget Task patterns were added.
Cmux Swift @Concurrent ✅ Passed The PR adds only synchronous XCTest-bundle detection and a test; no nonisolated async work or @concurrent annotation changes violate the rule.
Cmux Swift Package Boundaries ✅ Passed The change is app-lifecycle startup gating in the app target, which the rule explicitly allows as app-target glue; no reusable domain logic was moved in.
Cmux Swiftpm Lockfiles ✅ Passed PR only changes source/test files; no Package.swift, Package.resolved, .gitignore, workflow, or Xcode project files were touched.
Cmux Swift Logging ✅ Passed Changed Swift code only adds XCTest bundle detection and a comment; no new print/debugPrint/dump/NSLog or unsafe Logger changes were introduced.
Cmux User-Facing Error Privacy ✅ Passed Diff only changes XCTest startup logic, an internal comment, and tests; no user-facing error, alert, or recovery copy was added.
Cmux Full Internationalization ✅ Passed The PR only changes startup logic, a developer comment, and tests; no user-facing text or localization assets were added or altered.
Cmux Swiftui State Layout ✅ Passed No SwiftUI state/layout changes were introduced; the diff only updates XCTest detection logic and a comment in AppDelegate.
Cmux Architecture Rethink ✅ Passed Small local startup-policy fix: one owner (MacSentryStartupPolicy) adds a platform bridge for embedded .xctest detection, with no timing, locks, or duplicate lifecycle wiring.
Cmux Swift Auxiliary Window Close Shortcuts ✅ Passed PR only updates XCTest startup detection/comment and a test; it adds no user-visible window code or cmuxAuxiliaryWindowIdentifiers changes.
Cmux Source Artifacts ✅ Passed Only hand-written Swift source files changed; no local outputs, caches, build artifacts, or scratch dirs were added.
Cmux No Test Or Debug Seam In Production Source ✅ Passed Only private helper/comment changes were added; no #if DEBUG, test-only naming, or visibility-widening seam in Sources/ production code.
Cmux No Ambient Global State ✅ Passed PASS: The new helper stays private inside MacSentryStartupPolicy; no new top-level funcs, mutable globals, or singletons were introduced.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-ci-app-host-test-mode

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@austinywang
austinywang force-pushed the fix-ci-app-host-test-mode branch from 722fa76 to 530b734 Compare July 30, 2026 08:26
@austinywang austinywang changed the title fix: declare app-host test launch mode fix: detect app-host tests from embedded bundle Jul 30, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@Sources/App/MacSentryStartupPolicy.swift`:
- Around line 41-53: Update the policy method surrounding
hasEmbeddedXCTestBundle() to remove the unrelated compatibility/test-marker
check and use one fresh, structured XCTest detection source. Distinguish
successful enumeration with an actual .xctest entry from missing or failed
bundle inspection, and make unsupported or ambiguous results fail closed so only
confirmed XCTest environments suppress Sentry.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 44895a7a-2fa0-4c26-94fe-6e6ff2c42799

📥 Commits

Reviewing files that changed from the base of the PR and between 722fa76 and 530b734.

📒 Files selected for processing (3)
  • Sources/App/MacSentryStartupPolicy.swift
  • Sources/AppDelegate.swift
  • cmuxTests/SentryEventScrubberTests.swift

Comment on lines +41 to +53
if hasEmbeddedXCTestBundle() { return true }
return false
}

private static func hasEmbeddedXCTestBundle() -> Bool {
guard
let plugInsPath = Bundle.main.builtInPlugInsPath,
let plugInNames = try? FileManager.default.contentsOfDirectory(atPath: plugInsPath)
else {
return false
}
return plugInNames.contains { $0.hasSuffix(".xctest") }
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== locate file =="
git ls-files | rg '(^|/)MacSentryStartupPolicy\.swift$' || true

echo "== file outline/stats =="
if [ -f Sources/App/MacSentryStartupPolicy.swift ]; then
  wc -l Sources/App/MacSentryStartupPolicy.swift
  ast-grep outline Sources/App/MacSentryStartupPolicy.swift || true
  echo "== relevant file contents =="
  cat -n Sources/App/MacSentryStartupPolicy.swift
fi

echo "== usages =="
rg -n "isRunningUnderXCTest|MacSentryStartupPolicy|Sentry|SentryStartup|hasEmbeddedXCTestBundle|running under XCTest" . --glob '!**/DerivedData/**' --glob '!**/.build/**' || true

Repository: manaflow-ai/cmux

Length of output: 50372


🏁 Script executed:

#!/bin/bash
set -euo pipefail

python3 - <<'PY'
from pathlib import Path
p=Path('Sources/App/MacSentryStartupPolicy.swift')
if not p.exists():
    raise SystemExit
s=p.read_text()
checks=[
    'static func isRunningUnderXCTest',
    'hasEmbeddedXCTestBundle()',
    'Bundle.main.builtInPlugInsPath',
    'contentsOfDirectory(atPath:',
    'XCTEST_RUNNER',
    'TESTING',
    'XCTest'
]
for term in checks:
    count=s.count(term)
    print(f"{term}: {count}")
# Print function bodies around identifiers.
text=s.splitlines()
for name in ['isRunningUnderXCTest','hasEmbeddedXCTestBundle']:
    idx=None
    for i,line in enumerate(text,1):
        if name in line and ('func ' in line or 'private static func' in line):
            idx=max(1,i-3); break
    if idx:
        print(f"\n-- {name} --")
        for j in range(idx, min(len(text), idx+35)+1):
            print(f"{j:4}: {text[j-1]}")
PY

Repository: manaflow-ai/cmux

Length of output: 2122


Make XCTest detection fail-closed and single-sourced.

Line 41 adds an unrelated check before return false, so the policy currently accepts many compatibility/test markers and hasEmbeddedXCTestBundle() as authoritative test signals instead of using a single, fresh XCTest source. hasEmbeddedXCTestBundle() also treats missing .xctest entries the same as bundle enumeration failures, making an inherited or stale test marker enough to suppress Sentry in a normal app. Collapse these checks to one structured authority and make unsupported/ambiguous signals fail closed.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Sources/App/MacSentryStartupPolicy.swift` around lines 41 - 53, Update the
policy method surrounding hasEmbeddedXCTestBundle() to remove the unrelated
compatibility/test-marker check and use one fresh, structured XCTest detection
source. Distinguish successful enumeration with an actual .xctest entry from
missing or failed bundle inspection, and make unsupported or ambiguous results
fail closed so only confirmed XCTest environments suppress Sentry.

Sources: Coding guidelines, Path instructions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale-revisit Closed after 30+ days without activity; preserved for possible revisit or reopening.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants