Files
codex/codex-rs/app-server-protocol/tests/schema_fixtures.rs
T
Michael Bolin 3b069fda39 Vendor app-server protocol schema fixtures
Motivation:
- Keep `codex app-server` protocol artifacts (TypeScript + JSON Schema) checked in for consumers (e.g. IDE integrations) and make changes reviewable.
- Prevent drift between generated output (`codex app-server generate-ts` / `codex app-server generate-json-schema`) and what is vendored in the repo.

What changed:
- Vendor generated artifacts under `codex-rs/app-server-protocol/schema/typescript/` and `codex-rs/app-server-protocol/schema/json/`.
- Add `just write-app-server-schema` to fully regenerate fixtures (including deleting stale files).
- Add a fixture sync test for `codex-app-server-protocol` to assert the vendored trees match freshly generated output.
- Canonicalize JSON schema output (sorted object keys) for deterministic diffs.
- Wire Bazel test data so remote tests can read the vendored fixtures.

Refs: openai/codex#8956 (config.schema.json vendoring + sync test pattern)
2026-02-01 22:22:25 -08:00

70 lines
2.3 KiB
Rust

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() -> std::path::PathBuf {
let fixture_path =
codex_utils_cargo_bin::find_resource!("schema").expect("resolve schema fixture root");
fixture_path
}
fn read_tree(root: &Path) -> std::collections::BTreeMap<std::path::PathBuf, Vec<u8>> {
read_schema_fixture_tree(root).expect("read schema fixture tree")
}
#[test]
fn schema_fixtures_match_generated() {
let schema_root = schema_root();
let fixture_tree = read_tree(&schema_root);
let temp_dir = tempfile::tempdir().expect("create temp dir");
write_schema_fixtures(temp_dir.path(), None).expect("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)
.unwrap_or_else(|| panic!("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()
);
}
}