Files
codex/codex-rs/app-server-protocol/src/precomputed_exports_tests.rs
T
Michael Bolin acd540f158 Precompute app-server protocol exports (#36212)
## Why

Normal app-server protocol builds do not need the `ts-rs` and `schemars`
implementations used to generate schema exports.

## What changed

- Embed compressed stable and experimental TypeScript and JSON schema exports,
  and serve the existing export APIs from those artifacts.
- Use no-op schema derives in non-test builds while keeping the real generators
  available for fixture regeneration and tests.
- Move schema fixture regeneration behind a Python helper and update
  `just write-app-server-schema --experimental` to refresh the experimental
  embedded exports.

## Testing

- Verify embedded exports match freshly generated stable and experimental
  schemas.
- Verify export options and on-disk output remain compatible.

GitOrigin-RevId: e8536338b457e6eec34bdf29ec0684144bd13734
2026-07-30 19:47:30 +00:00

70 lines
2.2 KiB
Rust

use crate::GenerateTsOptions;
use crate::generate_internal_json_schema;
use crate::generate_json_with_experimental;
use crate::generate_ts_with_options;
use crate::precomputed_exports::GENERATED_TS_HEADER;
use crate::precomputed_exports::decode_precomputed_exports;
use crate::schema_fixtures::collect_export_files_recursive;
use anyhow::Context;
use anyhow::Result;
use pretty_assertions::assert_eq;
use std::path::Path;
#[test]
fn precomputed_exports_are_written_to_disk() -> Result<()> {
let output_dir = tempfile::tempdir().context("create export temp dir")?;
let typescript_dir = output_dir.path().join("typescript");
let json_dir = output_dir.path().join("json");
let internal_json_dir = output_dir.path().join("internal-json");
generate_ts_with_options(
&typescript_dir,
/*prettier*/ None,
GenerateTsOptions::default(),
)?;
generate_json_with_experimental(&json_dir, /*experimental_api*/ false)?;
generate_internal_json_schema(&internal_json_dir)?;
let exports = decode_precomputed_exports(/*experimental_api*/ false)?;
assert_eq!(
collect_export_files_recursive(&typescript_dir)?,
exports.typescript
);
assert_eq!(
collect_export_files_recursive(&json_dir)?,
exports.json_schema
);
assert_eq!(
collect_export_files_recursive(&internal_json_dir)?,
exports.internal_json_schema
);
Ok(())
}
#[test]
fn typescript_export_options_preserve_generator_behavior() -> Result<()> {
let output_dir = tempfile::tempdir().context("create TypeScript export temp dir")?;
generate_ts_with_options(
output_dir.path(),
/*prettier*/ None,
GenerateTsOptions {
generate_indices: false,
ensure_headers: false,
..GenerateTsOptions::default()
},
)?;
let files = collect_export_files_recursive(output_dir.path())?;
assert!(!files.keys().any(|path| {
Path::new(path)
.file_name()
.is_some_and(|name| name == "index.ts")
}));
assert!(
files
.values()
.all(|contents| !contents.starts_with(GENERATED_TS_HEADER))
);
Ok(())
}