mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
61dfe0b86c
## 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.
137 lines
5.1 KiB
Rust
137 lines
5.1 KiB
Rust
use super::build_recent_work_section;
|
|
use super::build_workspace_section_with_user_root;
|
|
use chrono::TimeZone;
|
|
use chrono::Utc;
|
|
use codex_protocol::ThreadId;
|
|
use codex_state::ThreadMetadata;
|
|
use pretty_assertions::assert_eq;
|
|
use std::fs;
|
|
use std::path::PathBuf;
|
|
use std::process::Command;
|
|
use tempfile::TempDir;
|
|
|
|
fn thread_metadata(cwd: &str, title: &str, first_user_message: &str) -> ThreadMetadata {
|
|
ThreadMetadata {
|
|
id: ThreadId::new(),
|
|
rollout_path: PathBuf::from("/tmp/rollout.jsonl"),
|
|
created_at: Utc
|
|
.timestamp_opt(1_709_251_100, 0)
|
|
.single()
|
|
.expect("valid timestamp"),
|
|
updated_at: Utc
|
|
.timestamp_opt(1_709_251_200, 0)
|
|
.single()
|
|
.expect("valid timestamp"),
|
|
source: "cli".to_string(),
|
|
agent_path: None,
|
|
agent_nickname: None,
|
|
agent_role: None,
|
|
model_provider: "test-provider".to_string(),
|
|
model: Some("gpt-5".to_string()),
|
|
reasoning_effort: None,
|
|
cwd: PathBuf::from(cwd),
|
|
cli_version: "test".to_string(),
|
|
title: title.to_string(),
|
|
sandbox_policy: "workspace-write".to_string(),
|
|
approval_mode: "never".to_string(),
|
|
tokens_used: 0,
|
|
first_user_message: Some(first_user_message.to_string()),
|
|
archived_at: None,
|
|
git_sha: None,
|
|
git_branch: Some("main".to_string()),
|
|
git_origin_url: None,
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn workspace_section_requires_meaningful_structure() {
|
|
let cwd = TempDir::new().expect("tempdir");
|
|
assert_eq!(
|
|
build_workspace_section_with_user_root(cwd.path(), /*user_root*/ None),
|
|
None
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn workspace_section_includes_tree_when_entries_exist() {
|
|
let cwd = TempDir::new().expect("tempdir");
|
|
fs::create_dir(cwd.path().join("docs")).expect("create docs dir");
|
|
fs::write(cwd.path().join("README.md"), "hello").expect("write readme");
|
|
|
|
let section = build_workspace_section_with_user_root(cwd.path(), /*user_root*/ None)
|
|
.expect("workspace section");
|
|
assert!(section.contains("Working directory tree:"));
|
|
assert!(section.contains("- docs/"));
|
|
assert!(section.contains("- README.md"));
|
|
}
|
|
|
|
#[test]
|
|
fn workspace_section_includes_user_root_tree_when_distinct() {
|
|
let root = TempDir::new().expect("tempdir");
|
|
let cwd = root.path().join("cwd");
|
|
let git_root = root.path().join("git");
|
|
let user_root = root.path().join("home");
|
|
|
|
fs::create_dir_all(cwd.join("docs")).expect("create cwd docs dir");
|
|
fs::write(cwd.join("README.md"), "hello").expect("write cwd readme");
|
|
fs::create_dir_all(git_root.join(".git")).expect("create git dir");
|
|
fs::write(git_root.join("Cargo.toml"), "[workspace]").expect("write git root marker");
|
|
fs::create_dir_all(user_root.join("code")).expect("create user root child");
|
|
fs::write(user_root.join(".zshrc"), "export TEST=1").expect("write home file");
|
|
|
|
let section = build_workspace_section_with_user_root(cwd.as_path(), Some(user_root))
|
|
.expect("workspace section");
|
|
assert!(section.contains("User root tree:"));
|
|
assert!(section.contains("- code/"));
|
|
assert!(!section.contains("- .zshrc"));
|
|
}
|
|
|
|
#[test]
|
|
fn recent_work_section_groups_threads_by_cwd() {
|
|
let root = TempDir::new().expect("tempdir");
|
|
let repo = root.path().join("repo");
|
|
let workspace_a = repo.join("workspace-a");
|
|
let workspace_b = repo.join("workspace-b");
|
|
let outside = root.path().join("outside");
|
|
|
|
fs::create_dir(&repo).expect("create repo dir");
|
|
Command::new("git")
|
|
.env("GIT_CONFIG_GLOBAL", "/dev/null")
|
|
.env("GIT_CONFIG_NOSYSTEM", "1")
|
|
.args(["init"])
|
|
.current_dir(&repo)
|
|
.output()
|
|
.expect("git init");
|
|
fs::create_dir_all(&workspace_a).expect("create workspace a");
|
|
fs::create_dir_all(&workspace_b).expect("create workspace b");
|
|
fs::create_dir_all(&outside).expect("create outside dir");
|
|
|
|
let recent_threads = vec![
|
|
thread_metadata(
|
|
workspace_a.to_string_lossy().as_ref(),
|
|
"Investigate realtime startup context",
|
|
"Log the startup context before sending it",
|
|
),
|
|
thread_metadata(
|
|
workspace_b.to_string_lossy().as_ref(),
|
|
"Trim websocket startup payload",
|
|
"Remove memories from the realtime startup context",
|
|
),
|
|
thread_metadata(outside.to_string_lossy().as_ref(), "", "Inspect flaky test"),
|
|
];
|
|
let current_cwd = workspace_a;
|
|
let repo = fs::canonicalize(repo).expect("canonicalize repo");
|
|
|
|
let section = build_recent_work_section(current_cwd.as_path(), &recent_threads)
|
|
.expect("recent work section");
|
|
assert!(section.contains(&format!("### Git repo: {}", repo.display())));
|
|
assert!(section.contains("Recent sessions: 2"));
|
|
assert!(section.contains("User asks:"));
|
|
assert!(section.contains(&format!(
|
|
"- {}: Log the startup context before sending it",
|
|
current_cwd.display()
|
|
)));
|
|
assert!(section.contains(&format!("### Directory: {}", outside.display())));
|
|
assert!(section.contains(&format!("- {}: Inspect flaky test", outside.display())));
|
|
}
|