Files
codex/codex-rs/execpolicy-legacy/tests/suite/head.rs
Michael Bolin 61dfe0b86c chore: clean up argument-comment lint and roll out all-target CI on macOS (#16054)
## Why

`argument-comment-lint` was green in CI even though the repo still had
many uncommented literal arguments. The main gap was target coverage:
the repo wrapper did not force Cargo to inspect test-only call sites, so
examples like the `latest_session_lookup_params(true, ...)` tests in
`codex-rs/tui_app_server/src/lib.rs` never entered the blocking CI path.

This change cleans up the existing backlog, makes the default repo lint
path cover all Cargo targets, and starts rolling that stricter CI
enforcement out on the platform where it is currently validated.

## What changed

- mechanically fixed existing `argument-comment-lint` violations across
the `codex-rs` workspace, including tests, examples, and benches
- updated `tools/argument-comment-lint/run-prebuilt-linter.sh` and
`tools/argument-comment-lint/run.sh` so non-`--fix` runs default to
`--all-targets` unless the caller explicitly narrows the target set
- fixed both wrappers so forwarded cargo arguments after `--` are
preserved with a single separator
- documented the new default behavior in
`tools/argument-comment-lint/README.md`
- updated `rust-ci` so the macOS lint lane keeps the plain wrapper
invocation and therefore enforces `--all-targets`, while Linux and
Windows temporarily pass `-- --lib --bins`

That temporary CI split keeps the stricter all-targets check where it is
already cleaned up, while leaving room to finish the remaining Linux-
and Windows-specific target-gated cleanup before enabling
`--all-targets` on those runners. The Linux and Windows failures on the
intermediate revision were caused by the wrapper forwarding bug, not by
additional lint findings in those lanes.

## Validation

- `bash -n tools/argument-comment-lint/run.sh`
- `bash -n tools/argument-comment-lint/run-prebuilt-linter.sh`
- shell-level wrapper forwarding check for `-- --lib --bins`
- shell-level wrapper forwarding check for `-- --tests`
- `just argument-comment-lint`
- `cargo test` in `tools/argument-comment-lint`
- `cargo test -p codex-terminal-detection`

## Follow-up

- Clean up remaining Linux-only target-gated callsites, then switch the
Linux lint lane back to the plain wrapper invocation.
- Clean up remaining Windows-only target-gated callsites, then switch
the Windows lint lane back to the plain wrapper invocation.
2026-03-27 19:00:44 -07:00

137 lines
3.9 KiB
Rust

use codex_execpolicy_legacy::ArgMatcher;
use codex_execpolicy_legacy::ArgType;
use codex_execpolicy_legacy::Error;
use codex_execpolicy_legacy::ExecCall;
use codex_execpolicy_legacy::MatchedArg;
use codex_execpolicy_legacy::MatchedExec;
use codex_execpolicy_legacy::MatchedOpt;
use codex_execpolicy_legacy::Policy;
use codex_execpolicy_legacy::Result;
use codex_execpolicy_legacy::ValidExec;
use codex_execpolicy_legacy::get_default_policy;
extern crate codex_execpolicy_legacy;
#[expect(clippy::expect_used)]
fn setup() -> Policy {
get_default_policy().expect("failed to load default policy")
}
#[test]
fn test_head_no_args() {
let policy = setup();
let head = ExecCall::new("head", &[]);
// It is actually valid to call `head` without arguments: it will read from
// stdin instead of from a file. Though recall that a command rejected by
// the policy is not "unsafe:" it just means that this library cannot
// *guarantee* that the command is safe.
//
// If we start verifying individual components of a shell command, such as:
// `find . -name | head -n 10`, then it might be important to allow the
// no-arg case.
assert_eq!(
Err(Error::VarargMatcherDidNotMatchAnything {
program: "head".to_string(),
matcher: ArgMatcher::ReadableFiles,
}),
policy.check(&head)
)
}
#[test]
fn test_head_one_file_no_flags() -> Result<()> {
let policy = setup();
let head = ExecCall::new("head", &["src/extension.ts"]);
assert_eq!(
Ok(MatchedExec::Match {
exec: ValidExec::new(
"head",
vec![MatchedArg::new(
/*index*/ 0,
ArgType::ReadableFile,
"src/extension.ts"
)?],
&["/bin/head", "/usr/bin/head"]
)
}),
policy.check(&head)
);
Ok(())
}
#[test]
fn test_head_one_flag_one_file() -> Result<()> {
let policy = setup();
let head = ExecCall::new("head", &["-n", "100", "src/extension.ts"]);
assert_eq!(
Ok(MatchedExec::Match {
exec: ValidExec {
program: "head".to_string(),
flags: vec![],
opts: vec![
MatchedOpt::new("-n", "100", ArgType::PositiveInteger)
.expect("should validate")
],
args: vec![MatchedArg::new(
/*index*/ 2,
ArgType::ReadableFile,
"src/extension.ts"
)?],
system_path: vec!["/bin/head".to_string(), "/usr/bin/head".to_string()],
}
}),
policy.check(&head)
);
Ok(())
}
#[test]
fn test_head_invalid_n_as_0() {
let policy = setup();
let head = ExecCall::new("head", &["-n", "0", "src/extension.ts"]);
assert_eq!(
Err(Error::InvalidPositiveInteger {
value: "0".to_string(),
}),
policy.check(&head)
)
}
#[test]
fn test_head_invalid_n_as_nonint_float() {
let policy = setup();
let head = ExecCall::new("head", &["-n", "1.5", "src/extension.ts"]);
assert_eq!(
Err(Error::InvalidPositiveInteger {
value: "1.5".to_string(),
}),
policy.check(&head)
)
}
#[test]
fn test_head_invalid_n_as_float() {
let policy = setup();
let head = ExecCall::new("head", &["-n", "1.0", "src/extension.ts"]);
assert_eq!(
Err(Error::InvalidPositiveInteger {
value: "1.0".to_string(),
}),
policy.check(&head)
)
}
#[test]
fn test_head_invalid_n_as_negative_int() {
let policy = setup();
let head = ExecCall::new("head", &["-n", "-1", "src/extension.ts"]);
assert_eq!(
Err(Error::OptionFollowedByOptionInsteadOfValue {
program: "head".to_string(),
option: "-n".to_string(),
value: "-1".to_string(),
}),
policy.check(&head)
)
}