codex: fix flaky schema fixture timeout (#13593)

This commit is contained in:
Ahmed Ibrahim
2026-03-06 18:08:01 -08:00
parent f60933bc8c
commit c38f0516c6
3 changed files with 22 additions and 7 deletions

View File

@@ -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<PathBuf> {
entries.push("export * as v2 from \"./v2\";\n".to_string());
}
let mut content =
String::with_capacity(HEADER.len() + entries.iter().map(String::len).sum::<usize>());
content.push_str(HEADER);
let mut content = String::with_capacity(
GENERATED_TS_HEADER.len() + entries.iter().map(String::len).sum::<usize>(),
);
content.push_str(GENERATED_TS_HEADER);
for line in &entries {
content.push_str(line);
}

View File

@@ -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<Vec<u8>> {
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)

View File

@@ -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()
},
)
})
}