Skip to content

Add Swift warning budget CI guard - #3220

Merged
lawrencecchen merged 4 commits into
mainfrom
feat-swift-warning-budget
Apr 28, 2026
Merged

lawrencecchen merged 4 commits into
mainfrom
feat-swift-warning-budget

Conversation

@lawrencecchen

@lawrencecchen lawrencecchen commented Apr 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • add a Swift warning budget parser for cmux-owned Xcode warnings
  • check in the current 196-warning baseline
  • make CI fail only when the Debug app build introduces warnings above the baseline

Test plan

  • ./tests/test_ci_swift_warning_budget.sh
  • ./tests/test_ci_self_hosted_guard.sh
  • ./tests/test_ci_unit_test_spm_retry.sh
  • ./tests/test_ci_scheme_testaction_debug.sh
  • python3 -m py_compile scripts/swift_warning_budget.py
  • python3 scripts/swift_warning_budget.py --log /tmp/cmux-cleanliness-warnscan.log --budget .github/swift-warning-budget.tsv

Summary by CodeRabbit

  • New Features

    • Introduced Swift warning budget validation and a CLI tool to generate and validate warning budgets.
  • Tests

    • Added end-to-end CI tests that exercise budget generation, normalization, exclusions, and failure reporting.
  • Chores

    • CI now captures full build output and runs the warning-budget check as a guard step in the pipeline.

Summary by cubic

Add a Swift warning budget to CI to block new cmux-owned Xcode warnings. CI fails if the Debug app build adds warnings above the checked-in 196-warning baseline.

  • New Features

    • Added scripts/swift_warning_budget.py to parse xcodebuild output, strip ANSI/GitHub timestamp prefixes, normalize messages (remove Swift 6 suffix, unify “non-sendable”, tweak '@preconcurrency' text), dedupe by file/line/column/message, and compare against .github/swift-warning-budget.tsv; ignores vendor, ghostty, homebrew-cmux, SourcePackages, and .ci-source-packages. Resolves absolute paths to repo-relative and preserves Packages/... ownership; prints budget summaries and reduction hints; clean errors on malformed budgets (no traceback).
    • Checked in the initial budget at .github/swift-warning-budget.tsv (196 warnings).
    • Updated CI to tee Debug build output to /tmp/cmux-build-output.txt and validate; added a guard step (tests/test_ci_swift_warning_budget.sh) that verifies CI wiring and tests normalization, path handling, ignore rules, and failure behavior.
  • Migration

    • When fixing warnings, reduce counts in .github/swift-warning-budget.tsv. To refresh intentionally: run python3 scripts/swift_warning_budget.py --log /tmp/cmux-build-output.txt --write-budget.

Written for commit e553f6e. Summary will update on new commits. Review in cubic

@vercel

vercel Bot commented Apr 28, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
cmux Ready Ready Preview, Comment Apr 28, 2026 10:12am
cmux-staging Building Building Preview, Comment Apr 28, 2026 10:12am

@coderabbitai

coderabbitai Bot commented Apr 28, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Adds CI enforcement of a Swift warning budget: captures xcodebuild output to a temp log, runs a new Python CLI to parse/normalize/aggregate Swift compiler warnings against a checked-in TSV budget, and includes a shell test that validates the budget write/validate flows and CI wiring.

Changes

Cohort / File(s) Summary
CI Workflow Integration
.github/workflows/ci.yml
Adds a guard step to run ./tests/test_ci_swift_warning_budget.sh, updates tests-build-and-lag to pipe xcodebuild output through tee into /tmp/cmux-build-output.txt, and invokes python3 scripts/swift_warning_budget.py --log /tmp/cmux-build-output.txt.
Warning Budget Tool
scripts/swift_warning_budget.py
New CLI that cleans ANSI/timestamps, extracts Swift warning:s via regex, normalizes/deduplicates warnings, attributes warnings to repo-owned paths (excludes vendor/Packages/SourcePackages etc.), aggregates counts, and either writes a TSV budget (--write-budget) or validates against an existing TSV (exit codes 0/1/2).
Integration Tests
tests/test_ci_swift_warning_budget.sh
New CI test script that checks CI workflow wiring, generates a synthetic build log including owned/package/vendor warnings, runs the tool in write and validate modes, asserts expected inclusions/exclusions and that over-budget detection fails, and cleans up temp files.

Sequence Diagram

sequenceDiagram
    participant CI as CI Workflow
    participant Build as xcodebuild
    participant Log as /tmp/cmux-build-output.txt
    participant Tool as swift_warning_budget.py
    participant TSV as Budget TSV

    CI->>Build: trigger xcodebuild (capture stdout+stderr)
    Build-->>Log: write combined build output (via tee)
    CI->>Tool: run python3 scripts/swift_warning_budget.py --log /tmp/cmux-build-output.txt [--write-budget?]
    Tool->>Log: read log (strip ANSI/timestamps)
    Tool->>Tool: extract & normalize Swift warnings (regex, normalize text)
    Tool->>Tool: filter warnings to repo-owned paths (exclude vendors/packages)
    Tool->>TSV: write budget TSV (--write-budget) or load existing TSV (validate)
    Tool->>CI: exit 0 (ok) / 1 (budget exceeded) / 2 (missing/invalid budget)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

codex

Poem

🐰 I munched the build log, nibbling each line,
Stripped colors and timestamps till warnings align.
TSV carrots stacked tidy and neat,
CI counts them carefully—no excess to meet.
Hop, hop—our garden of builds stays sweet!

🚥 Pre-merge checks | ✅ 4 | ❌ 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 (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add Swift warning budget CI guard' directly corresponds to the main change: introducing a Swift warning budget enforcement system in CI with new parser script, budget baseline file, and CI workflow integration.
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.
Description check ✅ Passed PR description is comprehensive with clear Summary, detailed Testing section listing multiple test cases and verification commands, and a complete Checklist indicating all items are addressed.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat-swift-warning-budget

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 and usage tips.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9140f7e965

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/swift_warning_budget.py Outdated
Comment thread scripts/swift_warning_budget.py Outdated
@greptile-apps

greptile-apps Bot commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR introduces a Swift warning budget system: a Python parser (scripts/swift_warning_budget.py) that extracts cmux-owned warnings from xcodebuild output and compares them against a checked-in TSV baseline (196 warnings across 89 buckets), with CI integration that captures build output via tee and fails the build if new warnings are introduced. The implementation is well-structured — deduplication at the exact (file, line, col, message) level, correct vendor/package exclusion via IGNORED_PATH_PARTS, and pipefail-safe pipeline in the build step.

Confidence Score: 4/5

Safe to merge; all findings are P2 style/robustness suggestions with no impact on the warning budget enforcement logic itself.

Only P2 findings: unhandled ValueError in main() produces a traceback on malformed budget files, brittle string patterns in the test script, and a theoretical path-extraction edge case for unusual workspace layouts. Core logic is correct — dedup, filtering, comparison, and CI plumbing all work as intended.

scripts/swift_warning_budget.py — error handling in main(); tests/test_ci_swift_warning_budget.sh — brittle ci.yml pattern matching.

Important Files Changed

Filename Overview
scripts/swift_warning_budget.py New Python script that parses xcodebuild output, extracts cmux-owned warnings, and compares against a checked-in TSV budget. Logic is sound; two minor P2 concerns: unhandled ValueError from load_budget and first-occurrence path extraction that can misattribute warnings when workspace paths include OWNED_ROOT components.
.github/workflows/ci.yml Adds tee capture of xcodebuild output to /tmp file and a follow-on warning-budget validation step. set -euo pipefail is already present so pipefail correctly propagates xcodebuild failures; the warning-budget step is correctly skipped on build failure by default GitHub Actions behavior.
tests/test_ci_swift_warning_budget.sh Shell test covering dedup, vendor/package exclusion, write-budget, pass, and fail scenarios correctly. Minor concern: CI-guard section uses brittle literal-string matching against ci.yml that would break on valid reformatting of the xcodebuild invocation.
.github/swift-warning-budget.tsv Checked-in baseline of 196 cmux-owned Swift warnings across 89 entries, establishing the initial budget; no issues found.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[CI: Build app step\nxcodebuild ... build] -->|2>&1 pipe| B[tee /tmp/cmux-build-output.txt]
    A -->|exit code via pipefail| C{Build succeeded?}
    C -->|No| D[Step fails\nSubsequent steps skipped]
    C -->|Yes| E[Validate Swift warning budget step\npython3 scripts/swift_warning_budget.py\n--log /tmp/cmux-build-output.txt]
    E --> F[collect_warnings\nParse log line-by-line\nStrip ANSI, match WARNING_RE\nDeduplicate by file+line+col+msg\nFilter vendor/SourcePackages/ghostty]
    F --> G[WarningBudget Counter\nkeyed by rel_path + message]
    E --> H[load_budget\n.github/swift-warning-budget.tsv]
    H --> I[Allowed Counter\n196 warnings baseline]
    G --> J[compare_budget]
    I --> J
    J -->|actual > allowed for any key| K[Exit 1\nPrint budget exceeded\nList new warnings]
    J -->|actual <= allowed for all keys| L[Exit 0\nOptionally suggest reductions]
Loading

Reviews (1): Last reviewed commit: "ci: add Swift warning budget" | Re-trigger Greptile

Comment thread scripts/swift_warning_budget.py
Comment thread tests/test_ci_swift_warning_budget.sh Outdated
Comment thread scripts/swift_warning_budget.py Outdated

@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.

🧹 Nitpick comments (1)
tests/test_ci_swift_warning_budget.sh (1)

38-51: Make the TSV assertions fixed-string checks.

These greps are matching literal budget rows, so grep -Fq is safer than regex matching for the AppDelegate.swift entry and the negative checks.

♻️ Proposed fix
-if ! grep -q $'1\tSources/AppDelegate.swift\tadd' "$BUDGET"; then
+if ! grep -Fq $'1\tSources/AppDelegate.swift\tadd' "$BUDGET"; then
   echo "expected AppDelegate preconcurrency warning budget entry" >&2
   exit 1
 fi
 
-if grep -q 'vendor/bonsplit' "$BUDGET"; then
+if grep -Fq 'vendor/bonsplit' "$BUDGET"; then
   echo "vendor warning should not be included" >&2
   exit 1
 fi
 
-if grep -q 'SourcePackages' "$BUDGET"; then
+if grep -Fq 'SourcePackages' "$BUDGET"; then
   echo "package warning should not be included" >&2
   exit 1
 fi
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/test_ci_swift_warning_budget.sh` around lines 38 - 51, The greps in
tests/test_ci_swift_warning_budget.sh should use fixed-string matching to avoid
regex interpretation; replace the three grep -q calls that check the literal TSV
entries (the positive check for $'1\tSources/AppDelegate.swift\tadd' and the two
negative checks for 'vendor/bonsplit' and 'SourcePackages') with grep -Fq so
they perform fixed-string matches against the BUDGET file variable.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tests/test_ci_swift_warning_budget.sh`:
- Around line 38-51: The greps in tests/test_ci_swift_warning_budget.sh should
use fixed-string matching to avoid regex interpretation; replace the three grep
-q calls that check the literal TSV entries (the positive check for
$'1\tSources/AppDelegate.swift\tadd' and the two negative checks for
'vendor/bonsplit' and 'SourcePackages') with grep -Fq so they perform
fixed-string matches against the BUDGET file variable.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 93fbfa7c-92bb-4531-8d06-c86cae542f0c

📥 Commits

Reviewing files that changed from the base of the PR and between 822e4e3 and 9140f7e.

⛔ Files ignored due to path filters (1)
  • .github/swift-warning-budget.tsv is excluded by !**/*.tsv
📒 Files selected for processing (3)
  • .github/workflows/ci.yml
  • scripts/swift_warning_budget.py
  • tests/test_ci_swift_warning_budget.sh

@lawrencecchen
lawrencecchen force-pushed the feat-swift-warning-budget branch from 9140f7e to 285f06c Compare April 28, 2026 09:45

@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.

🧹 Nitpick comments (1)
tests/test_ci_swift_warning_budget.sh (1)

33-58: Expand exclusion assertions to include ghostty and homebrew-cmux.

The parser ignores four path families, but this test only validates two (vendor, SourcePackages). Adding ghostty and homebrew-cmux fixtures will close a regression gap.

Suggested patch
 cat >"$LOG" <<'LOG'
 /Users/example/cmux/Sources/AppDelegate.swift:10:1: warning: add '@preconcurrency' to suppress 'Sendable'-related warnings from module 'ObjectiveC'
 /Users/example/cmux/Sources/AppDelegate.swift:10:1: warning: add '@preconcurrency' to suppress 'Sendable'-related warnings from module 'ObjectiveC'
 /Users/example/cmux/Sources/AppDelegate.swift:42:9: warning: result of call to 'closePanel(_:force:)' is unused
 2026-04-28T09:40:13.8874600Z /Users/example/cmux/Sources/AppDelegate.swift:44:9: warning: capture of 'observer' with non-Sendable type '(any NSObjectProtocol)?' in a '@Sendable' closure; this is an error in the Swift 6 language mode
 2026-04-28T09:40:13.8874610Z /Users/example/cmux/Sources/AppDelegate.swift:44:9: warning: capture of 'observer' with non-sendable type '(any NSObjectProtocol)?' in a '@Sendable' closure
 /Users/example/cmux/vendor/bonsplit/Sources/Bonsplit/Public/BonsplitView.swift:1:1: warning: ignored vendor warning
+/Users/example/cmux/ghostty/Sources/Ghostty/GhosttyView.swift:1:1: warning: ignored ghostty warning
+/Users/example/cmux/homebrew-cmux/Sources/Formula/cmux.rb:1:1: warning: ignored homebrew warning
 /tmp/cmux/SourcePackages/checkouts/posthog-ios/PostHog/PostHogSDK.swift:1:1: warning: ignored package warning
 warning: Run script build phase 'Run Script' will be run during every build
 LOG
@@
 if grep -q 'vendor/bonsplit' "$BUDGET"; then
   echo "vendor warning should not be included" >&2
   exit 1
 fi
 
+if grep -q 'ghostty/' "$BUDGET"; then
+  echo "ghostty warning should not be included" >&2
+  exit 1
+fi
+
+if grep -q 'homebrew-cmux/' "$BUDGET"; then
+  echo "homebrew-cmux warning should not be included" >&2
+  exit 1
+fi
+
 if grep -q 'SourcePackages' "$BUDGET"; then
   echo "package warning should not be included" >&2
   exit 1
 fi
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/test_ci_swift_warning_budget.sh` around lines 33 - 58, Test currently
only asserts exclusion of 'vendor' and 'SourcePackages' entries; add similar
negative assertions for the two other ignored path families by updating
tests/test_ci_swift_warning_budget.sh to also grep the budget file for 'ghostty'
and 'homebrew-cmux' and fail if either is present (mirror the existing grep -q
checks that echo "vendor warning should not be included" and "SourcePackages"
check). Ensure the failure messages reference the new fixtures (e.g., "ghostty
warning should not be included" and "homebrew-cmux warning should not be
included") and keep the checks after the other budget validations that run
python3 scripts/swift_warning_budget.py.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tests/test_ci_swift_warning_budget.sh`:
- Around line 33-58: Test currently only asserts exclusion of 'vendor' and
'SourcePackages' entries; add similar negative assertions for the two other
ignored path families by updating tests/test_ci_swift_warning_budget.sh to also
grep the budget file for 'ghostty' and 'homebrew-cmux' and fail if either is
present (mirror the existing grep -q checks that echo "vendor warning should not
be included" and "SourcePackages" check). Ensure the failure messages reference
the new fixtures (e.g., "ghostty warning should not be included" and
"homebrew-cmux warning should not be included") and keep the checks after the
other budget validations that run python3 scripts/swift_warning_budget.py.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f45415c1-8b0b-4b77-afd4-c86d9f3c6caa

📥 Commits

Reviewing files that changed from the base of the PR and between 9140f7e and 285f06c.

⛔ Files ignored due to path filters (1)
  • .github/swift-warning-budget.tsv is excluded by !**/*.tsv
📒 Files selected for processing (3)
  • .github/workflows/ci.yml
  • scripts/swift_warning_budget.py
  • tests/test_ci_swift_warning_budget.sh
🚧 Files skipped from review as they are similar to previous changes (2)
  • scripts/swift_warning_budget.py
  • .github/workflows/ci.yml

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 285f06cad3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tests/test_ci_swift_warning_budget.sh

@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

🧹 Nitpick comments (1)
tests/test_ci_swift_warning_budget.sh (1)

19-26: Tighten CI wiring assertions to reduce false passes.

The token check at Line 22 ("tee") is very broad; unrelated text can satisfy it. Prefer a stricter snippet/pattern that asserts teeing to the expected build log path in one check.

Suggested hardening
 required_tokens = {
     "workflow guard step": "Validate Swift warning budget guard",
     "guard test script": "./tests/test_ci_swift_warning_budget.sh",
-    "build log tee": "tee",
-    "build log path": "cmux-build-output.txt",
+    "build log tee path": "tee /tmp/cmux-build-output.txt",
     "budget script": "scripts/swift_warning_budget.py",
     "budget log argument": "--log",
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/test_ci_swift_warning_budget.sh` around lines 19 - 26, The current
required_tokens entry "build log tee": "tee" is too permissive; update the value
to assert tee is writing to the expected file by matching the exact invocation
(combine the "tee" token with the "build log path" value), e.g., require a
snippet like "tee cmux-build-output.txt" or a pipe form " | tee
cmux-build-output.txt"; modify the required_tokens map entry "build log tee"
accordingly so the CI asserts teeing to the expected build log path.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/test_ci_swift_warning_budget.sh`:
- Around line 76-79: Replace the regex grep call in the budget-check conditional
that currently uses grep -q '.ci-source-packages' "$BUDGET" with a fixed-string
search so the literal token ".ci-source-packages" is matched; update the command
to use grep -F (e.g., change the grep invocation in the if condition) to prevent
accidental matches like "xci-source-packages".

---

Nitpick comments:
In `@tests/test_ci_swift_warning_budget.sh`:
- Around line 19-26: The current required_tokens entry "build log tee": "tee" is
too permissive; update the value to assert tee is writing to the expected file
by matching the exact invocation (combine the "tee" token with the "build log
path" value), e.g., require a snippet like "tee cmux-build-output.txt" or a pipe
form " | tee cmux-build-output.txt"; modify the required_tokens map entry "build
log tee" accordingly so the CI asserts teeing to the expected build log path.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: e7143b36-1550-4dd1-9a27-991d5611b3da

📥 Commits

Reviewing files that changed from the base of the PR and between 285f06c and 039e645.

📒 Files selected for processing (2)
  • scripts/swift_warning_budget.py
  • tests/test_ci_swift_warning_budget.sh
🚧 Files skipped from review as they are similar to previous changes (1)
  • scripts/swift_warning_budget.py

Comment thread tests/test_ci_swift_warning_budget.sh Outdated
@lawrencecchen
lawrencecchen merged commit 8fba6de into main Apr 28, 2026
25 checks passed
@lawrencecchen
lawrencecchen deleted the feat-swift-warning-budget branch April 28, 2026 10:21

This branch was successfully deployed

1 active deployment
Preview – cmux — e553f6ec Deployed Apr 28, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant