Skip to content

feat(when): allow when clauses to branch on the host OS via the os variable#336

Merged
fohte merged 3 commits into
mainfrom
fohte/add-os-cel-variable
May 4, 2026
Merged

feat(when): allow when clauses to branch on the host OS via the os variable#336
fohte merged 3 commits into
mainfrom
fohte/add-os-cel-variable

Conversation

@fohte
Copy link
Copy Markdown
Owner

@fohte fohte commented May 4, 2026

Purpose

  • One runok config should be able to absorb behavioural differences between macOS and Linux
    • For example, denying BSD sed on macOS to steer users toward GNU gsed while leaving sed allowed on Linux (where sed already is GNU sed) cannot be expressed today, because when clauses have no way to inspect the host OS.

Approach

  • Add an os string variable to when clauses
    • The value matches Rust's std::env::consts::OS ("macos", "linux", "windows", "freebsd", and so on).
Design decisions

Shape of the os value

Decision Design Pros Cons
Chosen A single string (os == "macos") Matches the value runok already branches on internally via cfg!(target_os = ...); the most common case is also the shortest form. Derived information such as the family (unix / windows) requires a separate variable later.
Rejected A map (something like os.name, os.family) A family-level branch could be written against a single variable. No current use case needs family-level branching, so the API would be widened pre-emptively.

fohte added 2 commits May 4, 2026 14:45
intent(when): let one runok config express macOS/Linux-specific rules
  (e.g. deny BSD `sed` on macOS while allowing GNU `sed` on Linux),
  which previously had no expression in `when` clauses
decision(when): expose a single string equal to `std::env::consts::OS`
  rather than a structured map (`os.name` / `os.family`) — keeps the
  common case `os == "macos"` short and matches the runtime value the
  binary already branches on; a richer shape can be layered on later
  without breaking the string form
rejected(when): reading shell built-ins via `env` (`OSTYPE`,
  `__CFBundleIdentifier`, `HOMEBREW_PREFIX`) — not exported to child
  processes, missing under cron/CI, and not OS-distinguishing on
  Linuxbrew
intent(when): unblock docs build and follow the project's `indoc!` test
  rule before pushing
@codecov
Copy link
Copy Markdown

codecov Bot commented May 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.73%. Comparing base (49f6212) to head (57bbfc2).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #336      +/-   ##
==========================================
- Coverage   88.74%   88.73%   -0.01%     
==========================================
  Files          53       53              
  Lines       12163    12166       +3     
==========================================
+ Hits        10794    10796       +2     
- Misses       1369     1370       +1     
Flag Coverage Δ
Linux 88.55% <100.00%> (+<0.01%) ⬆️
macOS 89.90% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new os variable to CEL expressions within when clauses, enabling rules to be conditioned on the host operating system. The changes include updating the ExprContext to store the OS identifier (sourced from Rust's std::env::consts::OS), exposing this variable to the CEL evaluator, and adding corresponding documentation and tests. I have no feedback to provide.

intent(releases): match the PR-link convention used by every other
  entry in next.md so the changelog stays traceable
@fohte fohte merged commit f882338 into main May 4, 2026
10 checks passed
@fohte fohte deleted the fohte/add-os-cel-variable branch May 4, 2026 06:20
@fohte-bot fohte-bot Bot mentioned this pull request May 4, 2026
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