Skip to content

ci: fix the Homebrew setup script exit trap - #1290

Closed
davidtai wants to merge 3 commits into
masterfrom
ci/homebrew-script-trap-fix
Closed

davidtai wants to merge 3 commits into
masterfrom
ci/homebrew-script-trap-fix

Conversation

@davidtai

@davidtai davidtai commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Since #1288, Integration Tests on master fail in the "Set up Homebrew" step. Homebrew installs, but the script then fails at exit. This PR fixes the exit trap in scripts/setup-macos-homebrew.sh and adds an offline test of the install path through to script exit.

Linked issue

None. Follow-up to #1288.

The failure

Master run 36799584075 (Integration Tests on 5544167), step "Set up Homebrew":

==> Installation successful!
./scripts/setup-macos-homebrew.sh: line 63: installer: unbound variable
##[error]Process completed with exit code 1.

Cause

install_brew declared installer as local and set trap 'rm -f "$installer"' EXIT. The trap runs when the script exits, after install_brew has returned. At that time the local variable is gone, so set -u stops the script with exit code 1. The #1288 test covered only the path where brew is already installed, so it did not run the trap.

Fix

  • installer is now a global variable, so the trap can still read it at exit.
  • The script accepts test-only overrides for the installer URL, the installer SHA-256 and the fixed brew locations. It reads them only when SETUP_MACOS_HOMEBREW_TEST=1. No workflow sets that variable, so CI always uses the pinned values.

New test

scripts/test-setup-macos-homebrew.sh now also tests the install path:

  • PATH holds only system tools and a stub uname, so the script finds no brew and runs the install path on Linux too.
  • A local fake installer (file:// URL, with its own SHA-256) creates a fake brew. The script runs it through to exit.
  • The test checks that the installer ran with NONINTERACTIVE=1 HOMEBREW_NO_ANALYTICS=1, that $GITHUB_ENV and $GITHUB_PATH hold the new prefix, and that the exit trap deleted the installer.
  • A wrong SHA-256 must stop the step before the installer runs.

The "Release Integrity" job already runs this test.

Diagrams

Before

flowchart LR
  classDef bad fill:#fde2e1,stroke:#c0392b,color:#000
  classDef step fill:#e8f0fe,stroke:#3366cc,color:#000
  I["install_brew<br/>local installer"]:::step --> R["return: variable gone"]:::step
  R --> X["EXIT trap reads $installer"]:::bad --> F["unbound variable<br/>step fails"]:::bad
Loading

After

flowchart LR
  classDef good fill:#e3f6e8,stroke:#2e8b57,color:#000
  classDef step fill:#e8f0fe,stroke:#3366cc,color:#000
  I["install_brew<br/>global installer"]:::step --> R["return"]:::step
  R --> X["EXIT trap deletes installer"]:::good --> P["Install Postgres<br/>and later steps run"]:::good
  T["test: fake installer<br/>through to exit"]:::good -.-> X
Loading

Blue: unchanged. Red: the failing path. Green: the fixed path and the new test.

Test plan

  • ./scripts/test-setup-macos-homebrew.sh passes with the fix.
  • With only the fix line set back to master's local installer, the test fails in the same way as master run 36799584075:
    install path failed:
    .../runner-temp/homebrew-install.zJKrDk: OK
    Homebrew 0.0.0-test
    .../scripts/setup-macos-homebrew.sh: line 73: installer: unbound variable
    
    Master's script as merged has no test overrides, so the test cannot drive it unchanged. The only other difference from master in the trap code is the override lines.
  • shellcheck is clean on both scripts. actionlint is clean on integration.yml, benchmarks.yml and ci.yml, and no workflow changed.
  • make docs-impact-check BASE=origin/master, make docs-check (with libs/mlx-swift-lm checked out shallow): pass
  • Proof on CI: the Integration Tests run on this PR gets past "Set up Homebrew" and runs the later steps.

Components touched

  • coordinator (Go)
  • provider (Rust, legacy)
  • provider-swift (Swift CLI)
  • console-ui (Next.js)
  • enclave (Swift)
  • infra / CI / release
  • docs

Protocol / interface changes

  • No protocol/interface changes
  • Yes — described above and matching side updated

Documentation impact

  • Canonical documentation updated (docs/developer/test.md, CHANGELOG.md)
  • No documentation needed — reason:

Notes for reviewers

  • This PR changes no deployment or production state.

🤖 Generated with Claude Code

Refactor Pass

A dedicated refactor subagent reviewed the diff against the AGENTS.md structure, clean-code and refactor rules. Outcome: one test-only cleanup commit, f54164d. The production script is unchanged.

  • test-setup-macos-homebrew.sh now checks that RUNNER_TEMP is empty after the wrong-checksum run as well. Before, only the success run checked the failure path.
  • The fake installer is built with one sed redirect instead of sed -i.bak, and the wrong digest uses printf '%064d' 0.
  • Mutation checks: a local installer makes the test fail with unbound variable, and removing the EXIT trap makes the new failure-path check fail.

Validation on the final tree: shellcheck on both scripts, the script test (ok), git diff --check, make docs-impact-check BASE=origin/master, and make docs-check (326 OK) all pass.

Probably redundant: master already has the core fix. Commit b1c14ed, folded into #1287, puts the installer path into the trap string with printf %q, and its test stubs curl, shasum and uname. That fix is also why this branch conflicts with master. This PR still adds three things master lacks: a full run of the real install path with a file:// URL, a wrong-checksum test, and a test-only SETUP_MACOS_HOMEBREW_TEST override in the production script. The new AGENTS.md discourages that kind of override. If the extra tests are still wanted, move them onto master's stub approach. Otherwise, close this PR.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

davidtai and others added 2 commits September 30, 2026 20:44
The EXIT trap ran after install_brew returned, when the local variable
was gone, so set -u failed the step after a successful install.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Run setup-macos-homebrew.sh with a local fake installer and its own
checksum, selected by test-only overrides that need
SETUP_MACOS_HOMEBREW_TEST=1. The test fails with "installer: unbound
variable" when the exit-trap fix is removed, and checks that a wrong
checksum stops the installer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Oct 1, 2026

Copy link
Copy Markdown

Deployment failed for project d-inference with the following error:

You don't have permission to create a Preview Deployment for this Vercel project: d-inference.

View Documentation: https://vercel.com/docs/accounts/team-members-and-roles

@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Threat model review — advisory

Reviewed head f54164d71cdb against base 55441677e490.

Reviewers: anthropic/claude-opus-5.5: completed; openai/gpt-6-astra: completed

No actionable findings in the reviewed text. This is not a security approval.

Coverage: 4 changed file(s), complete before/after text, and a cross-file threat-model review.

Models: anthropic/claude-opus-5.5, openai/gpt-6-astra. Findings require human validation; this review never requests changes or blocks merging.

Gajesh2007
Gajesh2007 previously approved these changes Oct 1, 2026
Assert installer cleanup directly after the wrong-checksum run, write the
fake installed brew with one sed redirect, and spell the bad digest as
printf '%064d' 0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Oct 4, 2026

Copy link
Copy Markdown

Deployment failed for project eigen-homepages-darkbloom with the following error:

You don't have permission to create a Preview Deployment for this Vercel project: eigen-homepages-darkbloom.

View Documentation: https://vercel.com/docs/accounts/team-members-and-roles

@vercel

vercel Bot commented Oct 4, 2026

Copy link
Copy Markdown

Deployment failed for project d-inference-landing with the following error:

You don't have permission to create a Preview Deployment for this Vercel project: d-inference-landing.

View Documentation: https://vercel.com/docs/accounts/team-members-and-roles

@vercel

vercel Bot commented Oct 4, 2026

Copy link
Copy Markdown

Deployment failed for project d-inference-console-ui-dev with the following error:

You don't have permission to create a Preview Deployment for this Vercel project: d-inference-console-ui-dev.

View Documentation: https://vercel.com/docs/accounts/team-members-and-roles

@davidtai

davidtai commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator Author

Closing: master already has this fix (b1c14ed, through #1287). The evidence is in the Refactor Pass section of this PR body.

@davidtai davidtai closed this Oct 5, 2026
@davidtai
davidtai deleted the ci/homebrew-script-trap-fix branch October 5, 2026 00:42
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.

2 participants