feat(when): allow when clauses to branch on the host OS via the os variable#336
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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
Purpose
sedon macOS to steer users toward GNUgsedwhile leavingsedallowed on Linux (wheresedalready is GNU sed) cannot be expressed today, becausewhenclauses have no way to inspect the host OS.Approach
osstring variable towhenclausesstd::env::consts::OS("macos","linux","windows","freebsd", and so on).Design decisions
Shape of the
osvalueos == "macos")cfg!(target_os = ...); the most common case is also the shortest form.unix/windows) requires a separate variable later.os.name,os.family)