mirror of
https://github.com/openai/codex.git
synced 2026-05-04 21:32:21 +03:00
## 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.
131 lines
4.3 KiB
Rust
131 lines
4.3 KiB
Rust
use crate::CitationStreamParser;
|
|
use crate::ProposedPlanParser;
|
|
use crate::ProposedPlanSegment;
|
|
use crate::StreamTextChunk;
|
|
use crate::StreamTextParser;
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Default)]
|
|
pub struct AssistantTextChunk {
|
|
pub visible_text: String,
|
|
pub citations: Vec<String>,
|
|
pub plan_segments: Vec<ProposedPlanSegment>,
|
|
}
|
|
|
|
impl AssistantTextChunk {
|
|
pub fn is_empty(&self) -> bool {
|
|
self.visible_text.is_empty() && self.citations.is_empty() && self.plan_segments.is_empty()
|
|
}
|
|
}
|
|
|
|
/// Parses assistant text streaming markup in one pass:
|
|
/// - strips `<oai-mem-citation>` tags and extracts citation payloads
|
|
/// - in plan mode, also strips `<proposed_plan>` blocks and emits plan segments
|
|
#[derive(Debug, Default)]
|
|
pub struct AssistantTextStreamParser {
|
|
plan_mode: bool,
|
|
citations: CitationStreamParser,
|
|
plan: ProposedPlanParser,
|
|
}
|
|
|
|
impl AssistantTextStreamParser {
|
|
pub fn new(plan_mode: bool) -> Self {
|
|
Self {
|
|
plan_mode,
|
|
..Self::default()
|
|
}
|
|
}
|
|
|
|
pub fn push_str(&mut self, chunk: &str) -> AssistantTextChunk {
|
|
let citation_chunk = self.citations.push_str(chunk);
|
|
let mut out = self.parse_visible_text(citation_chunk.visible_text);
|
|
out.citations = citation_chunk.extracted;
|
|
out
|
|
}
|
|
|
|
pub fn finish(&mut self) -> AssistantTextChunk {
|
|
let citation_chunk = self.citations.finish();
|
|
let mut out = self.parse_visible_text(citation_chunk.visible_text);
|
|
if self.plan_mode {
|
|
let mut tail = self.plan.finish();
|
|
if !tail.is_empty() {
|
|
out.visible_text.push_str(&tail.visible_text);
|
|
out.plan_segments.append(&mut tail.extracted);
|
|
}
|
|
}
|
|
out.citations = citation_chunk.extracted;
|
|
out
|
|
}
|
|
|
|
fn parse_visible_text(&mut self, visible_text: String) -> AssistantTextChunk {
|
|
if !self.plan_mode {
|
|
return AssistantTextChunk {
|
|
visible_text,
|
|
..AssistantTextChunk::default()
|
|
};
|
|
}
|
|
let plan_chunk: StreamTextChunk<ProposedPlanSegment> = self.plan.push_str(&visible_text);
|
|
AssistantTextChunk {
|
|
visible_text: plan_chunk.visible_text,
|
|
plan_segments: plan_chunk.extracted,
|
|
..AssistantTextChunk::default()
|
|
}
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::AssistantTextStreamParser;
|
|
use crate::ProposedPlanSegment;
|
|
use pretty_assertions::assert_eq;
|
|
|
|
#[test]
|
|
fn parses_citations_across_seed_and_delta_boundaries() {
|
|
let mut parser = AssistantTextStreamParser::new(/*plan_mode*/ false);
|
|
|
|
let seeded = parser.push_str("hello <oai-mem-citation>doc");
|
|
let parsed = parser.push_str("1</oai-mem-citation> world");
|
|
let tail = parser.finish();
|
|
|
|
assert_eq!(seeded.visible_text, "hello ");
|
|
assert_eq!(seeded.citations, Vec::<String>::new());
|
|
assert_eq!(parsed.visible_text, " world");
|
|
assert_eq!(parsed.citations, vec!["doc1".to_string()]);
|
|
assert_eq!(tail.visible_text, "");
|
|
assert_eq!(tail.citations, Vec::<String>::new());
|
|
}
|
|
|
|
#[test]
|
|
fn parses_plan_segments_after_citation_stripping() {
|
|
let mut parser = AssistantTextStreamParser::new(/*plan_mode*/ true);
|
|
|
|
let seeded = parser.push_str("Intro\n<proposed");
|
|
let parsed = parser.push_str("_plan>\n- step <oai-mem-citation>doc</oai-mem-citation>\n");
|
|
let tail = parser.push_str("</proposed_plan>\nOutro");
|
|
let finish = parser.finish();
|
|
|
|
assert_eq!(seeded.visible_text, "Intro\n");
|
|
assert_eq!(
|
|
seeded.plan_segments,
|
|
vec![ProposedPlanSegment::Normal("Intro\n".to_string())]
|
|
);
|
|
assert_eq!(parsed.visible_text, "");
|
|
assert_eq!(parsed.citations, vec!["doc".to_string()]);
|
|
assert_eq!(
|
|
parsed.plan_segments,
|
|
vec![
|
|
ProposedPlanSegment::ProposedPlanStart,
|
|
ProposedPlanSegment::ProposedPlanDelta("- step \n".to_string()),
|
|
]
|
|
);
|
|
assert_eq!(tail.visible_text, "Outro");
|
|
assert_eq!(
|
|
tail.plan_segments,
|
|
vec![
|
|
ProposedPlanSegment::ProposedPlanEnd,
|
|
ProposedPlanSegment::Normal("Outro".to_string()),
|
|
]
|
|
);
|
|
assert!(finish.is_empty());
|
|
}
|
|
}
|