diff --git a/codex-rs/app-server-protocol/src/export.rs b/codex-rs/app-server-protocol/src/export.rs index fe563a9362..bdfaa48f75 100644 --- a/codex-rs/app-server-protocol/src/export.rs +++ b/codex-rs/app-server-protocol/src/export.rs @@ -36,7 +36,7 @@ use std::thread; use std::time::Instant; use ts_rs::TS; -const HEADER: &str = "// GENERATED CODE! DO NOT MODIFY BY HAND!\n\n"; +pub(crate) const GENERATED_TS_HEADER: &str = "// GENERATED CODE! DO NOT MODIFY BY HAND!\n\n"; const IGNORED_DEFINITIONS: &[&str] = &["Option<()>"]; const JSON_V1_ALLOWLIST: &[&str] = &["InitializeParams", "InitializeResponse"]; const SPECIAL_DEFINITIONS: &[&str] = &[ @@ -1835,13 +1835,13 @@ fn prepend_header_if_missing(path: &Path) -> Result<()> { .with_context(|| format!("Failed to read {}", path.display()))?; } - if content.starts_with(HEADER) { + if content.starts_with(GENERATED_TS_HEADER) { return Ok(()); } let mut f = fs::File::create(path) .with_context(|| format!("Failed to open {} for writing", path.display()))?; - f.write_all(HEADER.as_bytes()) + f.write_all(GENERATED_TS_HEADER.as_bytes()) .with_context(|| format!("Failed to write header to {}", path.display()))?; f.write_all(content.as_bytes()) .with_context(|| format!("Failed to write content to {}", path.display()))?; @@ -1909,9 +1909,10 @@ fn generate_index_ts(out_dir: &Path) -> Result { entries.push("export * as v2 from \"./v2\";\n".to_string()); } - let mut content = - String::with_capacity(HEADER.len() + entries.iter().map(String::len).sum::()); - content.push_str(HEADER); + let mut content = String::with_capacity( + GENERATED_TS_HEADER.len() + entries.iter().map(String::len).sum::(), + ); + content.push_str(GENERATED_TS_HEADER); for line in &entries { content.push_str(line); } diff --git a/codex-rs/app-server-protocol/src/schema_fixtures.rs b/codex-rs/app-server-protocol/src/schema_fixtures.rs index dcd84b5315..36dcf7402c 100644 --- a/codex-rs/app-server-protocol/src/schema_fixtures.rs +++ b/codex-rs/app-server-protocol/src/schema_fixtures.rs @@ -1,3 +1,4 @@ +use crate::export::GENERATED_TS_HEADER; use anyhow::Context; use anyhow::Result; use serde_json::Map; @@ -95,6 +96,12 @@ fn read_file_bytes(path: &Path) -> Result> { let text = String::from_utf8(bytes) .with_context(|| format!("expected UTF-8 TypeScript in {}", path.display()))?; let text = text.replace("\r\n", "\n").replace('\r', "\n"); + // Fixture comparisons care about schema content, not whether the generator + // re-prepended the standard banner to every TypeScript file. + let text = text + .strip_prefix(GENERATED_TS_HEADER) + .unwrap_or(&text) + .to_string(); return Ok(text.into_bytes()); } Ok(bytes) diff --git a/codex-rs/app-server-protocol/tests/schema_fixtures.rs b/codex-rs/app-server-protocol/tests/schema_fixtures.rs index a82488e208..9e40005886 100644 --- a/codex-rs/app-server-protocol/tests/schema_fixtures.rs +++ b/codex-rs/app-server-protocol/tests/schema_fixtures.rs @@ -13,7 +13,14 @@ use std::time::Instant; #[test] fn typescript_schema_fixtures_match_generated() -> Result<()> { assert_schema_fixtures_match_generated("typescript", |output_dir| { - generate_ts_with_options(output_dir, None, GenerateTsOptions::default()) + generate_ts_with_options( + output_dir, + None, + GenerateTsOptions { + ensure_headers: false, + ..GenerateTsOptions::default() + }, + ) }) }