mirror of
https://github.com/openai/codex.git
synced 2026-11-25 23:30:49 +00:00
Avoid JSON-schema canonicalization (preserve field order)
Motivation: - App-server JSON schema output is already stable; sorting object keys is unnecessary. - Alphabetical key canonicalization is potentially harmful because it obscures intentional ordering (e.g. struct field order) and makes diffs noisier. What changed: - Remove JSON key-sorting from schema emission. - Regenerate vendored JSON schema fixtures. Refs: openai/codex#8956 (fixture sync test pattern)
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
use codex_app_server_protocol::read_schema_fixture_tree;
|
||||
use codex_app_server_protocol::write_schema_fixtures;
|
||||
use similar::TextDiff;
|
||||
use std::path::Path;
|
||||
|
||||
fn schema_root() -> Result<std::path::PathBuf> {
|
||||
codex_utils_cargo_bin::find_resource!("schema").context("resolve schema fixture root")
|
||||
}
|
||||
|
||||
fn read_tree(root: &Path) -> Result<std::collections::BTreeMap<std::path::PathBuf, Vec<u8>>> {
|
||||
read_schema_fixture_tree(root).context("read schema fixture tree")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn schema_fixtures_match_generated() -> Result<()> {
|
||||
let schema_root = schema_root()?;
|
||||
let fixture_tree = read_tree(&schema_root)?;
|
||||
|
||||
let temp_dir = tempfile::tempdir().context("create temp dir")?;
|
||||
write_schema_fixtures(temp_dir.path(), None).context("generate schema fixtures")?;
|
||||
let generated_tree = read_tree(temp_dir.path())?;
|
||||
|
||||
if fixture_tree != generated_tree {
|
||||
let expected = fixture_tree
|
||||
.keys()
|
||||
.map(|p| p.display().to_string())
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
let actual = generated_tree
|
||||
.keys()
|
||||
.map(|p| p.display().to_string())
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
let diff = TextDiff::from_lines(&expected, &actual)
|
||||
.unified_diff()
|
||||
.header("fixture", "generated")
|
||||
.to_string();
|
||||
|
||||
panic!(
|
||||
"Vendored app-server schema fixtures don't match freshly generated output. \
|
||||
Run `just write-app-server-schema` to overwrite with your changes.\n\n{diff}"
|
||||
);
|
||||
}
|
||||
|
||||
// If the file sets match, diff contents for each file for a nicer error.
|
||||
for (path, expected) in &fixture_tree {
|
||||
let actual = generated_tree
|
||||
.get(path)
|
||||
.ok_or_else(|| anyhow::anyhow!("missing generated file: {}", path.display()))?;
|
||||
|
||||
if expected == actual {
|
||||
continue;
|
||||
}
|
||||
|
||||
let expected_str = String::from_utf8_lossy(expected);
|
||||
let actual_str = String::from_utf8_lossy(actual);
|
||||
let diff = TextDiff::from_lines(&expected_str, &actual_str)
|
||||
.unified_diff()
|
||||
.header("fixture", "generated")
|
||||
.to_string();
|
||||
panic!(
|
||||
"Vendored app-server schema fixture {} differs from generated output. \
|
||||
Run `just write-app-server-schema` to overwrite with your changes.\n\n{diff}",
|
||||
path.display()
|
||||
);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user