commit 3496b118416cd1f8ab6229a2cf91b2faa156882c
parent 7daebbc484b721ed0804ebee89b95204fcd9a1fa
Author: triesap <tyson@radroots.org>
Date: Sat, 21 Feb 2026 02:05:33 +0000
core: stabilize ts-rs export drift tests
- invoke explicit ts-rs export before asserting generated file contents
- keep core drift assertions focused on required public sdk model symbols
- validate literal union output for unit and unit-dimension contract values
- run cargo check and cargo test for `radroots-core` with ts-rs enabled
Diffstat:
1 file changed, 54 insertions(+), 0 deletions(-)
diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs
@@ -31,3 +31,57 @@ pub use unit::{
RadrootsCoreUnitParseError, convert_mass_decimal, convert_unit_decimal, convert_volume_decimal,
parse_mass_unit, parse_volume_unit,
};
+
+#[cfg(all(test, feature = "ts-rs", feature = "std"))]
+mod ts_export_tests {
+ use crate::RadrootsCoreDiscount;
+ use std::{
+ fs,
+ path::{Path, PathBuf},
+ };
+ use ts_rs::TS;
+
+ fn workspace_root(manifest_dir: &Path) -> PathBuf {
+ let parent = manifest_dir.parent().unwrap_or(manifest_dir);
+ if parent.file_name().and_then(|name| name.to_str()) == Some("crates") {
+ parent.parent().unwrap_or(parent).to_path_buf()
+ } else {
+ parent.to_path_buf()
+ }
+ }
+
+ fn ts_export_dir() -> PathBuf {
+ if let Some(export_dir) = option_env!("TS_RS_EXPORT_DIR") {
+ return PathBuf::from(export_dir);
+ }
+ let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
+ workspace_root(&manifest_dir)
+ .join("target")
+ .join("ts-rs")
+ .join("core")
+ }
+
+ fn export_types() {
+ RadrootsCoreDiscount::export_all().expect("export core ts-rs definitions");
+ }
+
+ #[test]
+ fn exports_core_types_file() {
+ export_types();
+ let path = ts_export_dir().join("types.ts");
+ let raw = fs::read_to_string(path).expect("read generated core types");
+ assert!(raw.contains("export type RadrootsCoreMoney"));
+ assert!(raw.contains("export type RadrootsCoreQuantity"));
+ assert!(raw.contains("export type RadrootsCoreQuantityPrice"));
+ assert!(raw.contains("export type RadrootsCoreDiscount"));
+ }
+
+ #[test]
+ fn exports_unit_literal_values() {
+ export_types();
+ let path = ts_export_dir().join("types.ts");
+ let raw = fs::read_to_string(path).expect("read generated core types");
+ assert!(raw.contains("\"each\" | \"kg\" | \"g\" | \"oz\" | \"lb\" | \"l\" | \"ml\""));
+ assert!(raw.contains("\"count\" | \"mass\" | \"volume\""));
+ }
+}