mirror of
https://github.com/openai/codex.git
synced 2026-04-24 14:45:27 +00:00
codex: fix flaky schema fixture timeout (#13593)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
},
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user