fix: detect app-host tests from embedded bundle - #9217
austinywang wants to merge 2 commits into
Conversation
📝 WalkthroughWalkthrough
ChangesSentry test detection
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 24 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (24 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
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. Comment |
722fa76 to
530b734
Compare
There was a problem hiding this comment.
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
📒 Files selected for processing (3)
Sources/App/MacSentryStartupPolicy.swiftSources/AppDelegate.swiftcmuxTests/SentryEventScrubberTests.swift
| 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") } | ||
| } |
There was a problem hiding this comment.
🎯 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/**' || trueRepository: 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]}")
PYRepository: 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
Summary
.xctestbundleWhy
Restoring the workflow guard exposed intermittent
SIGSEGVcrashes on thesentry-initthread 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 containscmuxTests.xctestunderContents/PlugInsbefore launch. Shipping app bundles do not contain an.xctestplug-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
MacSentryStartupPolicyTestsbash tests/test_ghostty_zig_version_sync.shci.ymlworkflow dispatch on the final PR headFollow-up to #9208.
Summary by CodeRabbit
Bug Fixes
.xctestbundles.Tests