use super::*;
use crate::style::LINKED_FALLBACK_EXACT_TOKEN_REASON;
use crate::{
OmenaQueryBundleEmissionPathV0, OmenaQueryBundlePlanInputV0, OmenaQueryClosedWorldBlockerV0,
OmenaQueryClosedWorldDecisionParityV0, OmenaQueryClosedWorldOutcomeV0,
OmenaQueryConsumerBuildOptionsV0, OmenaQueryExecutionEvidenceScopeV0,
OmenaQueryExternalSifInputV0, OmenaQueryLinkedSourceMapGranularityV0,
OmenaQueryTransformClassNameRewriteV0, OmenaQueryTransformExecutionContextV0,
OmenaQueryTransformModuleCssModuleContextV0,
attach_omena_query_consumer_build_source_map_v3_with_sources_and_resolution_inputs,
run_omena_query_bundle, run_omena_query_bundle_with_execution_scope_evidence_and_options,
run_omena_query_bundle_with_module_css_module_contexts_and_options,
run_omena_query_bundle_with_semantic_inputs,
run_omena_query_bundle_with_semantic_inputs_and_options,
run_omena_query_bundle_with_token_ownership_census_and_options,
summarize_omena_query_bundle_code_split_source_map_v3,
summarize_omena_query_bundle_code_split_workspace_plan, summarize_omena_query_bundle_evidence,
validate_omena_query_closed_world_decision_parity,
};
use omena_parser::ClosedWorldInterfaceHashAvailabilityV0;
use omena_query_transform_runner::{
TRANSFORM_PASS_CATALOG_LEN, all_transform_pass_kinds,
with_transform_pass_sort_ordinal_overrides_for_test,
};
use omena_sif::{
OmenaSifExportsV1, OmenaSifGeneratorV1, OmenaSifSourceSyntaxV1, OmenaSifSourceV1, OmenaSifV1,
};
#[test]
fn exposes_transform_plan_facade_from_source() {
let source = r#"
@use "./tokens" as tokens;
@value primary from "./colors.module.css";
.button {
composes: reset from "./reset.module.css";
color: tokens.$brand;
}
"#;
let target_support = OmenaQueryTargetFeatureSupportV0 {
vendor_prefix_required: true,
supports_light_dark: false,
supports_color_mix: true,
supports_oklch_oklab: true,
supports_color_function: true,
supports_relative_color: true,
supports_logical_properties: true,
supports_css_nesting: false,
supports_css_scope: true,
supports_cascade_layers: true,
};
let target_options = OmenaQueryTargetTransformOptionsV0 {
allow_logical_to_physical: false,
allow_scope_flatten: false,
allow_layer_flatten: false,
enable_supports_static_eval: false,
enable_media_static_eval: false,
enable_container_static_eval: false,
drop_dark_mode_media_queries: false,
};
let summary = summarize_omena_query_transform_plan_from_source(
"Button.module.scss",
source,
"legacy-webview",
target_support,
target_options,
default_omena_query_transform_print_options(),
);
assert_eq!(summary.product, "omena-query.transform-plan");
assert_eq!(summary.dialect, "scss");
assert_eq!(summary.target_query, None);
assert!(summary.bundle.required_pass_ids.contains(&"import-inline"));
assert!(
summary
.bundle
.required_pass_ids
.contains(&"composes-resolution")
);
assert!(
summary
.target
.required_pass_ids
.contains(&"light-dark-lowering")
);
assert!(summary.target.required_pass_ids.contains(&"nesting-unwrap"));
assert!(summary.combined_pass_ids.contains(&"print-css"));
assert_eq!(summary.combined_violated_dag_edge_count, 0);
assert_eq!(summary.print.css, source);
assert_eq!(summary.print.css, summary.execution.output_css);
assert!(summary.ready_surfaces.contains(&"cascadeProofObligations"));
assert_eq!(
summary.execution.product,
"omena-transform-passes.execution"
);
assert_eq!(summary.execution.output_css, source);
assert_eq!(
summary.execution.executed_pass_ids,
vec![
"value-resolution",
"light-dark-lowering",
"nesting-unwrap",
"vendor-prefixing",
"print-css"
]
);
assert!(
summary
.execution
.planned_only_pass_ids
.contains(&"css-modules-class-hashing")
);
assert_eq!(summary.execution.pass_plan.violated_dag_edge_count, 0);
}
#[test]
fn transform_plan_order_is_invariant_under_reversed_sort_ordinals() {
let source = r#"
@import "./tokens.css";
@value primary from "./colors.module.css";
.card {
composes: reset from "./reset.module.css";
color: light-dark(red, blue);
margin-inline-start: 1rem;
& .title { color: color-mix(in srgb, red 50%, blue); }
}
@layer theme { .card { color: oklch(60% 0.2 20); } }
@supports not (display: grid) { .fallback { display: block; } }
@media not all { .dead { color: red; } }
"#;
let target_support = OmenaQueryTargetFeatureSupportV0 {
vendor_prefix_required: true,
supports_light_dark: false,
supports_color_mix: false,
supports_oklch_oklab: false,
supports_color_function: false,
supports_relative_color: false,
supports_logical_properties: false,
supports_css_nesting: false,
supports_css_scope: false,
supports_cascade_layers: false,
};
let target_options = OmenaQueryTargetTransformOptionsV0 {
allow_logical_to_physical: false,
allow_scope_flatten: false,
allow_layer_flatten: false,
enable_supports_static_eval: true,
enable_media_static_eval: true,
enable_container_static_eval: true,
drop_dark_mode_media_queries: true,
};
let baseline = summarize_omena_query_transform_plan_from_source(
"Card.module.scss",
source,
"legacy-webview",
target_support,
target_options,
default_omena_query_transform_print_options(),
);
let mut reversed_ordinals = [0u8; TRANSFORM_PASS_CATALOG_LEN];
for kind in all_transform_pass_kinds() {
reversed_ordinals[(kind.ordinal() - 1) as usize] =
(TRANSFORM_PASS_CATALOG_LEN as u8 + 1).saturating_sub(kind.ordinal());
}
let permuted = with_transform_pass_sort_ordinal_overrides_for_test(reversed_ordinals, || {
summarize_omena_query_transform_plan_from_source(
"Card.module.scss",
source,
"legacy-webview",
target_support,
target_options,
default_omena_query_transform_print_options(),
)
});
assert!(baseline.bundle.required_pass_ids.len() >= 3);
assert!(baseline.target.required_pass_ids.len() >= 8);
assert_eq!(
baseline.target.blocked_pass_ids,
vec!["logical-to-physical", "scope-flatten", "layer-flatten"]
);
assert_eq!(
baseline.combined_pass_ids,
baseline.combined_plan.ordered_pass_ids
);
assert_eq!(
permuted.combined_pass_ids,
permuted.combined_plan.ordered_pass_ids
);
assert_eq!(permuted.combined_pass_ids, baseline.combined_pass_ids);
}
#[test]
fn exposes_transform_plan_minified_print_mode() {
let source = "/* remove */ .button { color: red; margin: 0px; }";
let summary = summarize_omena_query_transform_plan_from_source(
"Button.module.css",
source,
"modern",
modern_omena_query_target_feature_support(),
OmenaQueryTargetTransformOptionsV0::default(),
OmenaQueryTransformPrintOptionsV0 {
mode: OmenaQueryTransformPrintMode::Minified,
include_source_map: true,
},
);
assert_eq!(summary.product, "omena-query.transform-plan");
assert_eq!(summary.execution.output_css, source);
assert_eq!(summary.print.css, ".button{color:red;margin:0px}");
assert!(summary.print.provenance_preserved);
assert!(!summary.print.source_map_segments.is_empty());
assert!(
summary
.print
.source_map_segments
.iter()
.all(|segment| segment.generated_end <= summary.print.css.len())
);
}
#[test]
fn consumer_build_summary_can_attach_source_map_v3() -> Result<(), String> {
let source = "/* remove */ .button { color: red; }\n.card { color: blue; }";
let mut summary = execute_omena_query_consumer_build_style_source(
"Button.module.css",
source,
&[
"comment-strip".to_string(),
"whitespace-strip".to_string(),
"print-css".to_string(),
],
);
attach_omena_query_consumer_build_source_map_v3(&mut summary, source);
let source_map = summary
.source_map_v3
.as_ref()
.ok_or_else(|| "consumer build should attach Source Map V3 on request".to_string())?;
assert_eq!(source_map.version, 3);
assert_eq!(source_map.file, "Button.module.css");
assert_eq!(source_map.sources, vec!["Button.module.css"]);
assert_eq!(source_map.sources_content, vec![source]);
assert!(!source_map.mappings.is_empty());
assert!(source_map.x_omena_segment_count > 0);
assert!(summary.ready_surfaces.contains(&"sourceMapV3Serializer"));
Ok(())
}
#[test]
fn consumer_build_source_map_v3_preserves_bundle_import_origins() -> Result<(), String> {
let sources = vec![
OmenaQueryStyleSourceInputV0 {
style_path: "src/App.css".to_string(),
style_source: r#"@import "./theme/tokens.css"; .app { color: green; }"#.to_string(),
},
OmenaQueryStyleSourceInputV0 {
style_path: "src/theme/tokens.css".to_string(),
style_source: r#"@import "./base.css"; .token { color: blue; }"#.to_string(),
},
OmenaQueryStyleSourceInputV0 {
style_path: "src/theme/base.css".to_string(),
style_source: ".base { color: red; }".to_string(),
},
];
let mut summary = execute_omena_query_consumer_build_style_sources(
"src/App.css",
&sources,
&["import-inline".to_string(), "print-css".to_string()],
&[],
)?;
attach_omena_query_consumer_build_bundle_summary(&mut summary, &sources[0].style_source);
attach_omena_query_consumer_build_source_map_v3_with_sources(&mut summary, &sources, &[]);
assert!(
summary
.execution
.output_css
.contains(".base { color: red; }")
);
assert!(
summary
.execution
.output_css
.contains(".token { color: blue; }")
);
assert!(!summary.execution.output_css.contains("@import"));
let source_map = summary
.source_map_v3
.as_ref()
.ok_or_else(|| "consumer build should attach bundle-aware Source Map V3".to_string())?;
assert!(source_map.sources.contains(&"src/App.css".to_string()));
assert!(
source_map
.sources
.contains(&"src/theme/tokens.css".to_string())
);
assert!(
source_map
.sources
.contains(&"src/theme/base.css".to_string())
);
assert!(
source_map
.sources
.iter()
.position(|source| source == "src/theme/tokens.css")
.and_then(|index| source_map.sources_content.get(index))
.is_some_and(|content| content == r#"@import "./base.css"; .token { color: blue; }"#)
);
assert!(
source_map
.sources
.iter()
.position(|source| source == "src/theme/base.css")
.and_then(|index| source_map.sources_content.get(index))
.is_some_and(|content| content == ".base { color: red; }")
);
assert!(source_map.x_omena_pass_ids.contains(&"import-inline"));
assert!(
summary
.ready_surfaces
.contains(&"bundleSourceMapOriginChain")
);
Ok(())
}
#[test]
fn bundle_outcome_preserves_missing_dependency_as_a_typed_blocker() -> Result<(), String> {
let sources = vec![OmenaQueryStyleSourceInputV0 {
style_path: "src/app.css".to_string(),
style_source: "@import \"./missing.css\"; .app { color: green; }".to_string(),
}];
let result = run_omena_query_bundle_with_semantic_inputs(
OmenaQueryBundlePlanInputV0 {
target_style_path: "src/app.css",
style_sources: &sources,
source_map_sources: &sources,
requested_pass_ids: &["print-css".to_string()],
context: &OmenaQueryTransformExecutionContextV0::default(),
resolution_inputs: &OmenaQueryStyleResolutionInputsV0::default(),
asset_rewrites: Vec::new(),
bundle_entry_style_paths: &[],
},
&[],
)?;
assert!(matches!(
&result.closed_world_outcome,
OmenaQueryClosedWorldOutcomeV0::Open { blockers }
if matches!(
blockers.as_slice(),
[OmenaQueryClosedWorldBlockerV0::MissingDependency {
source_path,
import_source,
}] if source_path == "src/app.css" && import_source == "./missing.css"
)
));
assert!(result.closed_world_decision_parity.equivalent);
assert!(result.closed_world_decision_parity.legacy_open_decision);
Ok(())
}
#[test]
fn closed_world_decision_parity_rejects_each_direction_of_disagreement() {
for parity in [
OmenaQueryClosedWorldDecisionParityV0 {
legacy_open_decision: true,
typed_outcome_open: false,
equivalent: true,
},
OmenaQueryClosedWorldDecisionParityV0 {
legacy_open_decision: false,
typed_outcome_open: false,
equivalent: false,
},
] {
assert!(validate_omena_query_closed_world_decision_parity(&parity).is_err());
}
}
#[test]
fn consumer_build_source_map_v3_preserves_alias_resolved_import_origins() -> Result<(), String> {
let sources = vec![
OmenaQueryStyleSourceInputV0 {
style_path: "/workspace/src/App.css".to_string(),
style_source: r#"@import "@styles/tokens.css"; .app { color: green; }"#.to_string(),
},
OmenaQueryStyleSourceInputV0 {
style_path: "/workspace/src/styles/tokens.css".to_string(),
style_source: ".token { color: blue; }".to_string(),
},
];
let resolution_inputs = OmenaQueryStyleResolutionInputsV0 {
package_manifests: vec![],
tsconfig_path_mappings: vec![OmenaQueryTsconfigPathMappingV0 {
base_path: "/workspace".to_string(),
pattern: "@styles/*".to_string(),
target_patterns: vec!["src/styles/*".to_string()],
}],
bundler_path_mappings: vec![],
..Default::default()
};
let mut summary =
execute_omena_query_consumer_build_style_sources_with_context_and_resolution_inputs(
"/workspace/src/App.css",
&sources,
&["import-inline".to_string(), "print-css".to_string()],
&OmenaQueryTransformExecutionContextV0::default(),
&resolution_inputs,
)?;
attach_omena_query_consumer_build_source_map_v3_with_sources_and_resolution_inputs(
&mut summary,
&sources,
&resolution_inputs,
);
assert!(
summary
.execution
.output_css
.contains(".token { color: blue; }")
);
assert!(!summary.execution.output_css.contains("@import"));
let source_map = summary.source_map_v3.as_ref().ok_or_else(|| {
"consumer build should attach alias-aware bundle Source Map V3".to_string()
})?;
assert!(
source_map
.sources
.contains(&"/workspace/src/styles/tokens.css".to_string())
);
assert!(
source_map
.sources
.iter()
.position(|source| source == "/workspace/src/styles/tokens.css")
.and_then(|index| source_map.sources_content.get(index))
.is_some_and(|content| content == ".token { color: blue; }")
);
assert!(
summary
.ready_surfaces
.contains(&"bundleSourceMapOriginChain")
);
Ok(())
}
#[test]
fn bundle_code_split_source_map_preserves_split_origin() {
let source = r#"@import "./base.css"; .token { color: blue; }"#;
let generated = r#"@import "theme-base-css-1.css"; .token { color: blue; }"#;
let source_map = summarize_omena_query_bundle_code_split_source_map_v3(
"theme-tokens-css-1.css",
generated,
"src/theme/tokens.css",
source,
);
assert_eq!(source_map.version, 3);
assert_eq!(source_map.file, "theme-tokens-css-1.css");
assert_eq!(source_map.sources, vec!["src/theme/tokens.css"]);
assert_eq!(source_map.sources_content, vec![source]);
assert!(!source_map.mappings.is_empty());
assert_eq!(source_map.x_omena_segment_count, 1);
assert_eq!(source_map.x_omena_pass_ids, vec!["code-split-emission"]);
}
#[test]
fn consumer_build_summary_can_attach_bundle_asset_urls() -> Result<(), String> {
let source = r#".button { background-image: url("./assets/icon.svg"); }"#;
let mut summary = execute_omena_query_consumer_build_style_source(
"src/Button.module.css",
source,
&["print-css".to_string()],
);
attach_omena_query_consumer_build_bundle_summary(&mut summary, source);
let bundle = summary
.bundle
.as_ref()
.ok_or_else(|| "consumer build should attach bundle summary on request".to_string())?;
assert_eq!(bundle.asset_urls.len(), 1);
assert_eq!(bundle.asset_urls[0].normalized_url, "./assets/icon.svg");
assert_eq!(
bundle.asset_urls[0].resolved_path.as_deref(),
Some("src/assets/icon.svg")
);
assert!(bundle.code_splitting_required);
assert_eq!(bundle.code_split_chunks.len(), 2);
assert!(summary.ready_surfaces.contains(&"bundleAssetUrlResolution"));
assert!(summary.ready_surfaces.contains(&"bundleCodeSplitPlan"));
Ok(())
}
#[test]
fn bundle_code_split_workspace_plan_surfaces_entry_config_and_shared_boundaries()
-> Result<(), String> {
let sources = vec![
OmenaQueryStyleSourceInputV0 {
style_path: "src/app.css".to_string(),
style_source: r#"@import "./theme/tokens.css"; .app { color: green; }"#.to_string(),
},
OmenaQueryStyleSourceInputV0 {
style_path: "src/admin.css".to_string(),
style_source: r#"@import "./theme/tokens.css"; .admin { color: green; }"#.to_string(),
},
OmenaQueryStyleSourceInputV0 {
style_path: "src/theme/tokens.css".to_string(),
style_source: ".token { color: blue; }".to_string(),
},
];
let plan = summarize_omena_query_bundle_code_split_workspace_plan(
"src/app.css",
&["src/admin.css".to_string()],
&sources,
&OmenaQueryStyleResolutionInputsV0::default(),
)?;
let output_for = |source_path: &str| {
plan.outputs
.iter()
.find(|output| output.source_path == source_path)
.ok_or_else(|| format!("missing output for {source_path}"))
};
assert_eq!(plan.product, "omena-query.bundle-code-split-workspace-plan");
assert_eq!(plan.configured_entry_count, 1);
assert_eq!(plan.shared_boundary_count, 1);
assert!(plan.ready_surfaces.contains(&"bundleCodeSplitPlan"));
assert!(plan.ready_surfaces.contains(&"bundleCodeSplitBoundaryPlan"));
assert!(plan.ready_surfaces.contains(&"bundleCodeSplitEntryConfig"));
assert!(
plan.ready_surfaces
.contains(&"bundleCodeSplitSharedChunkPlan")
);
assert_eq!(output_for("src/app.css")?.split_boundary, "entry");
assert!(output_for("src/app.css")?.is_entry);
assert_eq!(output_for("src/admin.css")?.split_boundary, "entryConfig");
assert!(output_for("src/admin.css")?.is_entry);
let shared = output_for("src/theme/tokens.css")?;
assert_eq!(shared.split_boundary, "shared");
assert!(!shared.is_entry);
assert_eq!(
shared.reachable_from_entries,
vec!["src/admin.css".to_string(), "src/app.css".to_string()]
);
Ok(())
}
#[test]
fn bundle_code_split_workspace_plan_traverses_module_dependencies_without_reparsing()
-> Result<(), String> {
let sass_sources = vec![
OmenaQueryStyleSourceInputV0 {
style_path: "src/entry.scss".to_string(),
style_source: include_str!(
"../../tests/fixtures/bundle-code-split-dependencies/sass/entry.scss"
)
.to_string(),
},
OmenaQueryStyleSourceInputV0 {
style_path: "src/_tokens.scss".to_string(),
style_source: include_str!(
"../../tests/fixtures/bundle-code-split-dependencies/sass/_tokens.scss"
)
.to_string(),
},
];
let (sass_plan, sass_parse) = omena_parser::with_omena_parser_parse_instrumentation(|| {
summarize_omena_query_bundle_code_split_workspace_plan(
"src/entry.scss",
&[],
&sass_sources,
&OmenaQueryStyleResolutionInputsV0::default(),
)
});
let sass_plan = sass_plan?;
assert_eq!(sass_parse.parse_invocation_count, sass_sources.len() as u64);
assert_eq!(sass_plan.output_count, 2);
assert!(sass_plan.outputs.iter().any(|output| {
output.source_path == "src/_tokens.scss"
&& output.split_boundary == "styleDependency"
&& !output.is_entry
}));
let shared_sass_sources = vec![
sass_sources[0].clone(),
OmenaQueryStyleSourceInputV0 {
style_path: "src/admin.scss".to_string(),
style_source: include_str!(
"../../tests/fixtures/bundle-code-split-dependencies/sass/admin.scss"
)
.to_string(),
},
sass_sources[1].clone(),
];
let (shared_sass_plan, shared_sass_parse) =
omena_parser::with_omena_parser_parse_instrumentation(|| {
summarize_omena_query_bundle_code_split_workspace_plan(
"src/entry.scss",
&["src/admin.scss".to_string()],
&shared_sass_sources,
&OmenaQueryStyleResolutionInputsV0::default(),
)
});
let shared_sass_plan = shared_sass_plan?;
assert_eq!(
shared_sass_parse.parse_invocation_count,
shared_sass_sources.len() as u64
);
assert_eq!(shared_sass_plan.output_count, 3);
assert!(shared_sass_plan.outputs.iter().any(|output| {
output.source_path == "src/_tokens.scss"
&& output.split_boundary == "shared"
&& output.reachable_from_entries
== vec!["src/admin.scss".to_string(), "src/entry.scss".to_string()]
}));
let css_sources = vec![
OmenaQueryStyleSourceInputV0 {
style_path: "src/entry.css".to_string(),
style_source: include_str!(
"../../tests/fixtures/bundle-code-split-dependencies/css/entry.css"
)
.to_string(),
},
OmenaQueryStyleSourceInputV0 {
style_path: "src/shared.css".to_string(),
style_source: include_str!(
"../../tests/fixtures/bundle-code-split-dependencies/css/shared.css"
)
.to_string(),
},
];
let (css_plan, css_parse) = omena_parser::with_omena_parser_parse_instrumentation(|| {
summarize_omena_query_bundle_code_split_workspace_plan(
"src/entry.css",
&[],
&css_sources,
&OmenaQueryStyleResolutionInputsV0::default(),
)
});
let css_plan = css_plan?;
assert_eq!(css_parse.parse_invocation_count, css_sources.len() as u64);
assert_eq!(css_plan.output_count, 2);
assert!(css_plan.outputs.iter().any(|output| {
output.source_path == "src/shared.css"
&& output.split_boundary == "styleDependency"
&& !output.is_entry
}));
Ok(())
}
#[test]
fn bundle_operation_facade_matches_consumer_build_source_map() -> Result<(), String> {
let sources = vec![
OmenaQueryStyleSourceInputV0 {
style_path: "src/app.css".to_string(),
style_source: r#"@import "./theme/tokens.css"; .app { color: green; }"#.to_string(),
},
OmenaQueryStyleSourceInputV0 {
style_path: "src/theme/tokens.css".to_string(),
style_source:
".token-a { color: blue; }\n.token-b { color: cyan; }\n.token-c { color: navy; }"
.to_string(),
},
];
let pass_ids = vec!["import-inline".to_string(), "print-css".to_string()];
let context = OmenaQueryTransformExecutionContextV0::default();
let resolution_inputs = OmenaQueryStyleResolutionInputsV0::default();
let artifact = run_omena_query_bundle(OmenaQueryBundlePlanInputV0 {
target_style_path: "src/app.css",
style_sources: &sources,
source_map_sources: &sources,
requested_pass_ids: &pass_ids,
context: &context,
resolution_inputs: &resolution_inputs,
asset_rewrites: Vec::new(),
bundle_entry_style_paths: &[],
})?;
let mut summary =
execute_omena_query_consumer_build_style_sources_with_context_and_resolution_inputs(
"src/app.css",
&sources,
&pass_ids,
&context,
&resolution_inputs,
)?;
attach_omena_query_consumer_build_source_map_v3_with_sources_and_resolution_inputs(
&mut summary,
&sources,
&resolution_inputs,
);
assert_eq!(artifact.product, "omena-query.bundle-artifact");
assert_eq!(artifact.output_css, summary.execution.output_css);
let summary_source_map = summary
.source_map_v3
.ok_or_else(|| "consumer summary should carry a source map".to_string())?;
assert_eq!(artifact.source_map_v3, summary_source_map);
assert_eq!(artifact.per_pass_provenance, artifact.execution.outcomes);
let scoped = run_omena_query_bundle_with_execution_scope_evidence_and_options(
OmenaQueryBundlePlanInputV0 {
target_style_path: "src/app.css",
style_sources: &sources,
source_map_sources: &sources,
requested_pass_ids: &pass_ids,
context: &context,
resolution_inputs: &resolution_inputs,
asset_rewrites: Vec::new(),
bundle_entry_style_paths: &[],
},
&[],
&OmenaQueryConsumerBuildOptionsV0 {
bundle_emission_path: OmenaQueryBundleEmissionPathV0::LinkedOrder,
..OmenaQueryConsumerBuildOptionsV0::default()
},
)?;
let execution_scope = scoped
.execution_scope
.ok_or_else(|| "linked bundle should expose execution scope".to_string())?;
let entry = execution_scope
.module_executions
.iter()
.find(|module| module.module_instance == execution_scope.entry_module_instance)
.ok_or_else(|| "linked bundle should retain entry byte facts".to_string())?;
assert_eq!(
entry.input_byte_len,
scoped.bundle_result.artifact.execution.input_byte_len
);
assert_eq!(
scoped.bundle_result.artifact.per_pass_provenance,
scoped.bundle_result.artifact.execution.outcomes
);
let entry_disposition = execution_scope
.source_map_dispositions
.iter()
.find(|disposition| disposition.module_instance.module().as_str() == "src/app.css")
.ok_or_else(|| "linked entry should report its source-map disposition".to_string())?;
assert_eq!(
entry_disposition.granularity,
OmenaQueryLinkedSourceMapGranularityV0::WholeModuleFallback
);
assert_eq!(
entry_disposition.fallback_reason,
Some(LINKED_FALLBACK_EXACT_TOKEN_REASON)
);
let leaf_disposition = execution_scope
.source_map_dispositions
.iter()
.find(|disposition| disposition.module_instance.module().as_str() == "src/theme/tokens.css")
.ok_or_else(|| "linked leaf should report its source-map disposition".to_string())?;
assert_eq!(
leaf_disposition.granularity,
OmenaQueryLinkedSourceMapGranularityV0::CstAnchors
);
assert_eq!(leaf_disposition.segment_count, 3);
assert!(execution_scope.field_scopes.iter().any(|field| {
field.field_name == "outcomes" && field.scope == OmenaQueryExecutionEvidenceScopeV0::Entry
}));
assert!(artifact.ready_surfaces.contains(&"bundleOperationFacade"));
assert!(
artifact
.code_split_outputs
.iter()
.any(|output| output.source_path == "src/theme/tokens.css")
);
Ok(())
}
#[test]
fn bundle_operation_uses_the_consumer_effective_default_plan() -> Result<(), String> {
let sources = vec![OmenaQueryStyleSourceInputV0 {
style_path: "src/app.module.css".to_string(),
style_source: ".app { color: #ffffff; margin: 0px; }".to_string(),
}];
let result = run_omena_query_bundle_with_semantic_inputs(
OmenaQueryBundlePlanInputV0 {
target_style_path: "src/app.module.css",
style_sources: &sources,
source_map_sources: &sources,
requested_pass_ids: &[],
context: &OmenaQueryTransformExecutionContextV0::default(),
resolution_inputs: &OmenaQueryStyleResolutionInputsV0::default(),
asset_rewrites: Vec::new(),
bundle_entry_style_paths: &[],
},
&[],
)?;
assert!(!result.artifact.execution.requested_pass_ids.is_empty());
for closed_world_pass in [
"layer-flatten",
"tree-shake-class",
"tree-shake-keyframes",
"tree-shake-value",
"tree-shake-custom-property",
] {
assert!(
!result
.artifact
.execution
.requested_pass_ids
.contains(&closed_world_pass)
);
}
assert!(result.artifact.output_css.starts_with("._"));
assert!(
result
.artifact
.output_css
.ends_with("_app{color:#fff;margin:0}")
);
assert!(result.closed_world_decision_parity.equivalent);
Ok(())
}
#[test]
fn bundle_emission_path_selects_linked_order_without_changing_the_default() -> Result<(), String> {
let sources = vec![
OmenaQueryStyleSourceInputV0 {
style_path: "src/app.css".to_string(),
style_source: r#"@import "./tokens.css"; .app { color: green; }"#.to_string(),
},
OmenaQueryStyleSourceInputV0 {
style_path: "src/tokens.css".to_string(),
style_source: ".token { color: blue; }".to_string(),
},
];
let pass_ids = vec!["import-inline".to_string(), "print-css".to_string()];
let context = OmenaQueryTransformExecutionContextV0::default();
let resolution_inputs = OmenaQueryStyleResolutionInputsV0::default();
let run = |options: &OmenaQueryConsumerBuildOptionsV0| {
run_omena_query_bundle_with_semantic_inputs_and_options(
OmenaQueryBundlePlanInputV0 {
target_style_path: "src/app.css",
style_sources: &sources,
source_map_sources: &sources,
requested_pass_ids: &pass_ids,
context: &context,
resolution_inputs: &resolution_inputs,
asset_rewrites: Vec::new(),
bundle_entry_style_paths: &[],
},
&[],
options,
)
};
let legacy = run(&OmenaQueryConsumerBuildOptionsV0::default())?;
let linked = run(&OmenaQueryConsumerBuildOptionsV0 {
bundle_emission_path: OmenaQueryBundleEmissionPathV0::LinkedOrder,
..OmenaQueryConsumerBuildOptionsV0::default()
})?;
assert_eq!(
legacy.artifact.emission_path,
OmenaQueryBundleEmissionPathV0::ImportInlineLegacy
);
assert_eq!(
linked.artifact.emission_path,
OmenaQueryBundleEmissionPathV0::LinkedOrder
);
assert_ne!(legacy.artifact.output_css, linked.artifact.output_css);
assert!(
legacy
.artifact
.output_css
.find(".token")
.is_some_and(|token_index| legacy
.artifact
.output_css
.find(".app")
.is_some_and(|app_index| token_index < app_index))
);
assert!(
linked
.artifact
.output_css
.find(".token")
.is_some_and(|token_index| linked
.artifact
.output_css
.find(".app")
.is_some_and(|app_index| token_index < app_index))
);
assert_eq!(linked.artifact.output_css.matches(".app").count(), 1);
assert_eq!(linked.artifact.output_css.matches(".token").count(), 1);
assert!(!linked.artifact.output_css.contains("@import"));
assert_eq!(linked.artifact.source_map_v3.x_omena_segment_count, 2);
assert_eq!(
linked.artifact.source_map_v3.x_omena_pass_ids,
vec!["linked-order-emission"]
);
assert!(
linked
.artifact
.source_map_v3
.sources
.contains(&"src/app.css".to_string())
);
assert!(
linked
.artifact
.source_map_v3
.sources
.contains(&"src/tokens.css".to_string())
);
assert!(
linked
.artifact
.execution
.css_import_inlines
.iter()
.all(|inline| inline.replacement_css.is_empty())
);
Ok(())
}
#[test]
fn strict_css_module_token_integrity_uses_module_qualified_preimages() -> Result<(), String> {
let pass_ids = Vec::<String>::new();
let context = OmenaQueryTransformExecutionContextV0::default();
let resolution_inputs = OmenaQueryStyleResolutionInputsV0::default();
let run = |sources: &[OmenaQueryStyleSourceInputV0],
emission_path: OmenaQueryBundleEmissionPathV0| {
run_omena_query_bundle_with_semantic_inputs_and_options(
OmenaQueryBundlePlanInputV0 {
target_style_path: "src/app.module.css",
style_sources: sources,
source_map_sources: sources,
requested_pass_ids: &pass_ids,
context: &context,
resolution_inputs: &resolution_inputs,
asset_rewrites: Vec::new(),
bundle_entry_style_paths: &[],
},
&[],
&OmenaQueryConsumerBuildOptionsV0 {
verification_profile: crate::OmenaQueryBuildVerificationProfileV0::Strict,
bundle_emission_path: emission_path,
},
)
};
let clean = vec![OmenaQueryStyleSourceInputV0 {
style_path: "src/app.module.css".to_string(),
style_source: ".card { color: green; }".to_string(),
}];
for emission_path in [
OmenaQueryBundleEmissionPathV0::ImportInlineLegacy,
OmenaQueryBundleEmissionPathV0::LinkedOrder,
] {
run(&clean, emission_path)?;
let result = run_omena_query_bundle_with_token_ownership_census_and_options(
OmenaQueryBundlePlanInputV0 {
target_style_path: "src/app.module.css",
style_sources: &clean,
source_map_sources: &clean,
requested_pass_ids: &pass_ids,
context: &context,
resolution_inputs: &resolution_inputs,
asset_rewrites: Vec::new(),
bundle_entry_style_paths: &[],
},
&[],
&OmenaQueryConsumerBuildOptionsV0 {
verification_profile: crate::OmenaQueryBuildVerificationProfileV0::Descriptive,
bundle_emission_path: emission_path,
},
)?;
let census = &result.ownership_census;
assert!(census.complete);
assert_eq!(census.module_token_collision_count, 0);
assert_eq!(census.unattributed_emitted_tokens, Vec::<String>::new());
assert_eq!(census.token_ownerships.len(), 1);
assert_eq!(census.token_ownerships[0].module_instances.len(), 1);
assert_eq!(
census.token_ownerships[0].module_instances[0]
.module()
.as_str(),
"src/app.module.css"
);
}
let same_ordinal = vec![
OmenaQueryStyleSourceInputV0 {
style_path: "src/app.module.css".to_string(),
style_source: "@import './dependency.module.css'; .shared { color: green; }"
.to_string(),
},
OmenaQueryStyleSourceInputV0 {
style_path: "src/dependency.module.css".to_string(),
style_source: ".shared { color: blue; }".to_string(),
},
];
for emission_path in [
OmenaQueryBundleEmissionPathV0::ImportInlineLegacy,
OmenaQueryBundleEmissionPathV0::LinkedOrder,
] {
run(&same_ordinal, emission_path)?;
}
let descriptive_ownership = run_omena_query_bundle_with_token_ownership_census_and_options(
OmenaQueryBundlePlanInputV0 {
target_style_path: "src/app.module.css",
style_sources: &same_ordinal,
source_map_sources: &same_ordinal,
requested_pass_ids: &pass_ids,
context: &context,
resolution_inputs: &resolution_inputs,
asset_rewrites: Vec::new(),
bundle_entry_style_paths: &[],
},
&[],
&OmenaQueryConsumerBuildOptionsV0 {
verification_profile: crate::OmenaQueryBuildVerificationProfileV0::Descriptive,
bundle_emission_path: OmenaQueryBundleEmissionPathV0::LinkedOrder,
},
)?;
let ownership_census = &descriptive_ownership.ownership_census;
assert!(ownership_census.complete);
assert_eq!(ownership_census.module_token_collision_count, 0);
assert_eq!(ownership_census.token_ownerships.len(), 2);
let serialized_census =
serde_json::to_value(ownership_census).map_err(|error| error.to_string())?;
assert_eq!(
serialized_census["product"],
"omena-query.css-module-token-ownership-census"
);
assert_eq!(serialized_census["moduleTokenCollisionCount"], 0);
let distinct_contexts = [
("src/app.module.css", "_entry_override"),
("src/dependency.module.css", "_dependency_override"),
]
.into_iter()
.map(|(style_path, rewritten_name)| {
OmenaQueryTransformModuleCssModuleContextV0::new(
omena_parser::ModuleInstanceKeyV0::unconfigured(omena_parser::ModuleIdV0::new(
format!("/workspace/{style_path}"),
)),
)
.with_class_name_rewrites(vec![OmenaQueryTransformClassNameRewriteV0 {
original_name: "shared".to_string(),
rewritten_name: rewritten_name.to_string(),
}])
})
.collect::<Vec<_>>();
for emission_path in [
OmenaQueryBundleEmissionPathV0::ImportInlineLegacy,
OmenaQueryBundleEmissionPathV0::LinkedOrder,
] {
let result = run_omena_query_bundle_with_module_css_module_contexts_and_options(
OmenaQueryBundlePlanInputV0 {
target_style_path: "src/app.module.css",
style_sources: &same_ordinal,
source_map_sources: &same_ordinal,
requested_pass_ids: &pass_ids,
context: &context,
resolution_inputs: &resolution_inputs,
asset_rewrites: Vec::new(),
bundle_entry_style_paths: &[],
},
&[],
&OmenaQueryConsumerBuildOptionsV0 {
verification_profile: crate::OmenaQueryBuildVerificationProfileV0::Descriptive,
bundle_emission_path: emission_path,
},
"/workspace",
&distinct_contexts,
)?;
let output = result.bundle_result.artifact.output_css.as_str();
assert!(output.contains("._entry_override"), "{output}");
assert!(output.contains("._dependency_override"), "{output}");
println!("per-module-token-bytes path={emission_path:?} output={output:?}");
}
let forced_contexts = same_ordinal
.iter()
.map(|source| {
OmenaQueryTransformModuleCssModuleContextV0::new(
omena_parser::ModuleInstanceKeyV0::unconfigured(omena_parser::ModuleIdV0::new(
format!("/workspace/{}", source.style_path),
)),
)
.with_class_name_rewrites(vec![OmenaQueryTransformClassNameRewriteV0 {
original_name: "shared".to_string(),
rewritten_name: "_forced_shared".to_string(),
}])
})
.collect::<Vec<_>>();
for emission_path in [
OmenaQueryBundleEmissionPathV0::ImportInlineLegacy,
OmenaQueryBundleEmissionPathV0::LinkedOrder,
] {
let error = match run_omena_query_bundle_with_module_css_module_contexts_and_options(
OmenaQueryBundlePlanInputV0 {
target_style_path: "src/app.module.css",
style_sources: &same_ordinal,
source_map_sources: &same_ordinal,
requested_pass_ids: &pass_ids,
context: &context,
resolution_inputs: &resolution_inputs,
asset_rewrites: Vec::new(),
bundle_entry_style_paths: &[],
},
&[],
&OmenaQueryConsumerBuildOptionsV0 {
verification_profile: crate::OmenaQueryBuildVerificationProfileV0::Strict,
bundle_emission_path: emission_path,
},
"/workspace",
&forced_contexts,
) {
Err(error) => error,
Ok(_) => return Err("forced equal module tokens must fail closed".to_string()),
};
assert!(error.contains("pathScope=bothPaths"), "{error}");
assert!(error.contains("src/app.module.css"), "{error}");
assert!(error.contains("src/dependency.module.css"), "{error}");
assert!(error.contains("shared"), "{error}");
assert!(error.contains("_forced_shared"), "{error}");
println!("forced-collision path={emission_path:?} error={error:?}");
}
let different_ordinals = vec![
OmenaQueryStyleSourceInputV0 {
style_path: "src/app.module.css".to_string(),
style_source: "@import './dependency.module.css'; .lead {} .shared { color: green; }"
.to_string(),
},
OmenaQueryStyleSourceInputV0 {
style_path: "src/dependency.module.css".to_string(),
style_source: ".shared { color: blue; }".to_string(),
},
];
run(
&different_ordinals,
OmenaQueryBundleEmissionPathV0::ImportInlineLegacy,
)?;
run(
&different_ordinals,
OmenaQueryBundleEmissionPathV0::LinkedOrder,
)?;
Ok(())
}
#[test]
fn legacy_css_module_emission_preserves_dependency_before_entry_source_order() -> Result<(), String>
{
let sources = vec![
OmenaQueryStyleSourceInputV0 {
style_path: "src/app.module.css".to_string(),
style_source: "@import './z-base.module.css'; .entry { color: blue; }".to_string(),
},
OmenaQueryStyleSourceInputV0 {
style_path: "src/z-base.module.css".to_string(),
style_source: ".base { color: red; }".to_string(),
},
];
let result = run_default_css_module_token_census(
&sources,
&[],
&OmenaQueryTransformExecutionContextV0::default(),
)?;
let output = result.bundle_result.artifact.output_css;
let compact_output = output.split_ascii_whitespace().collect::<String>();
let dependency_rule = compact_output
.find("color:red")
.ok_or_else(|| format!("dependency order probe is absent from {output:?}"))?;
let entry_rule = compact_output
.find("color:#00f")
.ok_or_else(|| format!("entry order probe is absent from {output:?}"))?;
// The default compatibility path owns source-order semantics: imported
// modules are emitted before the importing entry, independently of path sort.
assert!(
dependency_rule < entry_rule,
"legacy CSS module emission reordered entry before dependency: {output:?}"
);
Ok(())
}
#[test]
fn strict_css_module_token_integrity_accepts_the_selected_module_context() -> Result<(), String> {
let sources = vec![
OmenaQueryStyleSourceInputV0 {
style_path: "src/app.module.css".to_string(),
style_source: "@import './dependency.module.css'; .entry { color: green; }".to_string(),
},
OmenaQueryStyleSourceInputV0 {
style_path: "src/dependency.module.css".to_string(),
style_source: ".dependency { color: blue; }".to_string(),
},
];
let pass_ids = Vec::<String>::new();
let context = OmenaQueryTransformExecutionContextV0::default();
let resolution_inputs = OmenaQueryStyleResolutionInputsV0::default();
let run = |emission_path| {
run_omena_query_bundle_with_semantic_inputs_and_options(
OmenaQueryBundlePlanInputV0 {
target_style_path: "src/app.module.css",
style_sources: &sources,
source_map_sources: &sources,
requested_pass_ids: &pass_ids,
context: &context,
resolution_inputs: &resolution_inputs,
asset_rewrites: Vec::new(),
bundle_entry_style_paths: &[],
},
&[],
&OmenaQueryConsumerBuildOptionsV0 {
verification_profile: crate::OmenaQueryBuildVerificationProfileV0::Strict,
bundle_emission_path: emission_path,
},
)
};
run(OmenaQueryBundleEmissionPathV0::ImportInlineLegacy)?;
run(OmenaQueryBundleEmissionPathV0::LinkedOrder)?;
let forced_context = vec![
OmenaQueryTransformModuleCssModuleContextV0::new(
omena_parser::ModuleInstanceKeyV0::unconfigured(omena_parser::ModuleIdV0::new(
"src/dependency.module.css",
)),
)
.with_class_name_rewrites(vec![OmenaQueryTransformClassNameRewriteV0 {
original_name: "dependency".to_string(),
rewritten_name: "_forced_dependency".to_string(),
}]),
];
for emission_path in [
OmenaQueryBundleEmissionPathV0::ImportInlineLegacy,
OmenaQueryBundleEmissionPathV0::LinkedOrder,
] {
let selected = run_omena_query_bundle_with_module_css_module_contexts_and_options(
OmenaQueryBundlePlanInputV0 {
target_style_path: "src/app.module.css",
style_sources: &sources,
source_map_sources: &sources,
requested_pass_ids: &pass_ids,
context: &context,
resolution_inputs: &resolution_inputs,
asset_rewrites: Vec::new(),
bundle_entry_style_paths: &[],
},
&[],
&OmenaQueryConsumerBuildOptionsV0 {
verification_profile: crate::OmenaQueryBuildVerificationProfileV0::Strict,
bundle_emission_path: emission_path,
},
".",
&forced_context,
)?;
assert!(
selected
.bundle_result
.artifact
.output_css
.contains("._forced_dependency"),
"{:?}",
selected.bundle_result.artifact.output_css
);
}
let descriptive_mismatch = run_omena_query_bundle_with_token_ownership_census_and_options(
OmenaQueryBundlePlanInputV0 {
target_style_path: "src/app.module.css",
style_sources: &sources,
source_map_sources: &sources,
requested_pass_ids: &pass_ids,
context: &context,
resolution_inputs: &resolution_inputs,
asset_rewrites: Vec::new(),
bundle_entry_style_paths: &[],
},
&[],
&OmenaQueryConsumerBuildOptionsV0 {
verification_profile: crate::OmenaQueryBuildVerificationProfileV0::Descriptive,
bundle_emission_path: OmenaQueryBundleEmissionPathV0::ImportInlineLegacy,
},
)?;
assert_eq!(
descriptive_mismatch
.ownership_census
.interface_mismatches
.len(),
0
);
Ok(())
}
#[test]
fn token_integrity_workspace_root_keeps_ownership_admission_in_census_key_space()
-> Result<(), String> {
let run = |workspace_root: Option<&str>| -> Result<crate::OmenaQueryBundleExecutionScopeResultV0, String> {
let prefix = workspace_root.map_or("", |_| "/workspace/");
let entry_path = format!("{prefix}src/app.module.css");
let dependency_path = format!("{prefix}src/dependency.module.css");
let sources = vec![
OmenaQueryStyleSourceInputV0 {
style_path: entry_path.clone(),
style_source: "@import './dependency.module.css'; .entry-live { color: green; } .shared { padding: 8px; } .entry-dead { color: tan; }".to_string(),
},
OmenaQueryStyleSourceInputV0 {
style_path: dependency_path,
style_source: ".dependency-live { color: blue; } .shared { margin: 4px; } .dependency-dead { color: gray; }".to_string(),
},
];
let pass_ids = vec!["tree-shake-class".to_string()];
let context = OmenaQueryTransformExecutionContextV0 {
reachable_class_names: vec![
"entry-live".to_string(),
"dependency-live".to_string(),
],
..OmenaQueryTransformExecutionContextV0::default()
};
let input = OmenaQueryBundlePlanInputV0 {
target_style_path: entry_path.as_str(),
style_sources: &sources,
source_map_sources: &sources,
requested_pass_ids: &pass_ids,
context: &context,
resolution_inputs: &OmenaQueryStyleResolutionInputsV0::default(),
asset_rewrites: Vec::new(),
bundle_entry_style_paths: &[],
};
let options = OmenaQueryConsumerBuildOptionsV0 {
bundle_emission_path: OmenaQueryBundleEmissionPathV0::LinkedOrder,
..OmenaQueryConsumerBuildOptionsV0::default()
};
match workspace_root {
Some(root) => run_omena_query_bundle_with_module_css_module_contexts_and_options(
input,
&[],
&options,
root,
&[],
),
None => run_omena_query_bundle_with_execution_scope_evidence_and_options(
input,
&[],
&options,
),
}
};
for workspace_root in [None, Some("/workspace")] {
let result = run(workspace_root)?;
let scope = result
.execution_scope
.as_ref()
.ok_or_else(|| "linked ownership fixture should retain execution scope".to_string())?;
let output = result.bundle_result.artifact.output_css.as_str();
println!(
"ownership-key-space root={workspace_root:?} refused={} shared={} entry_dead={} dependency_dead={}",
scope.bundle_execution.aggregate_closed_world_refusal_count,
output.contains(".shared"),
output.contains(".entry-dead"),
output.contains(".dependency-dead"),
);
assert_eq!(
scope.bundle_execution.aggregate_closed_world_refusal_count, 2,
"workspace-root normalization lost the ownership refusal: {output:?}"
);
for module in &scope.bundle_execution.module_executions {
assert_eq!(module.execution.closed_world_admission.refused_count, 1);
assert!(
module
.execution
.closed_world_admission
.refusal_reasons
.iter()
.flat_map(|event| event.reasons.iter())
.any(|reason| match reason {
OmenaQueryTransformStrictPolicyReasonV0::OwnershipNotSeparable {
token,
module_paths,
} => {
let normalized_paths = module_paths
.iter()
.map(|path| {
path.strip_prefix("/workspace/").unwrap_or(path.as_str())
})
.collect::<BTreeSet<_>>();
token == "shared"
&& normalized_paths
== BTreeSet::from([
"src/app.module.css",
"src/dependency.module.css",
])
}
_ => false,
})
);
}
for retained in [".shared", ".entry-dead", ".dependency-dead"] {
assert!(
output.contains(retained),
"ownership refusal did not retain {retained}: {output:?}"
);
}
}
Ok(())
}
#[test]
fn token_integrity_selected_shape_is_injective_on_import_inline_bytes() -> Result<(), String> {
let sources = vec![
OmenaQueryStyleSourceInputV0 {
style_path: "src/app.module.css".to_string(),
style_source: "@import './dependency.module.css'; .shared { color: green; } .a\\62 c { color: red; } .abc { color: black; }"
.to_string(),
},
OmenaQueryStyleSourceInputV0 {
style_path: "src/dependency.module.css".to_string(),
style_source: ".shared { color: blue; }".to_string(),
},
];
let pass_ids = Vec::<String>::new();
let context = OmenaQueryTransformExecutionContextV0::default();
let resolution_inputs = OmenaQueryStyleResolutionInputsV0::default();
let result = run_omena_query_bundle_with_token_ownership_census_and_options(
OmenaQueryBundlePlanInputV0 {
target_style_path: "src/app.module.css",
style_sources: &sources,
source_map_sources: &sources,
requested_pass_ids: &pass_ids,
context: &context,
resolution_inputs: &resolution_inputs,
asset_rewrites: Vec::new(),
bundle_entry_style_paths: &[],
},
&[],
&OmenaQueryConsumerBuildOptionsV0 {
verification_profile: crate::OmenaQueryBuildVerificationProfileV0::Descriptive,
bundle_emission_path: OmenaQueryBundleEmissionPathV0::ImportInlineLegacy,
},
)?;
assert!(result.ownership_census.complete);
assert_eq!(result.ownership_census.module_token_collision_count, 0);
assert_eq!(
result.ownership_census.interface_mismatches,
Vec::<omena_query_transform_runner::CssModuleTokenInterfaceMismatchV0>::new()
);
let emitted_tokens = result
.ownership_census
.token_ownerships
.iter()
.map(|ownership| ownership.emitted_token.as_str())
.collect::<BTreeSet<_>>();
println!(
"selected-shape-bytes output={:?} emitted_tokens={emitted_tokens:?}",
result.bundle_result.artifact.output_css
);
assert_eq!(emitted_tokens.len(), 4);
assert_eq!(
result
.ownership_census
.token_ownerships
.iter()
.flat_map(|ownership| ownership.original_names.iter().map(String::as_str))
.collect::<BTreeSet<_>>(),
BTreeSet::from([r"a\62 c", "abc", "shared"])
);
Ok(())
}
fn run_default_css_module_token_census(
sources: &[OmenaQueryStyleSourceInputV0],
requested_pass_ids: &[String],
context: &OmenaQueryTransformExecutionContextV0,
) -> Result<crate::OmenaQueryBundleTokenOwnershipResultV0, String> {
let resolution_inputs = OmenaQueryStyleResolutionInputsV0::default();
run_omena_query_bundle_with_token_ownership_census_and_options(
OmenaQueryBundlePlanInputV0 {
target_style_path: "src/app.module.css",
style_sources: sources,
source_map_sources: sources,
requested_pass_ids,
context,
resolution_inputs: &resolution_inputs,
asset_rewrites: Vec::new(),
bundle_entry_style_paths: &[],
},
&[],
&OmenaQueryConsumerBuildOptionsV0 {
verification_profile: crate::OmenaQueryBuildVerificationProfileV0::Strict,
bundle_emission_path: OmenaQueryBundleEmissionPathV0::ImportInlineLegacy,
},
)
}
#[test]
fn token_integrity_default_path_scopes_every_declared_dependency_class() -> Result<(), String> {
let sources = vec![
OmenaQueryStyleSourceInputV0 {
style_path: "src/app.module.css".to_string(),
style_source: "@import './dependency.module.css'; .entry { color: green; }".to_string(),
},
OmenaQueryStyleSourceInputV0 {
style_path: "src/dependency.module.css".to_string(),
style_source:
".a { color: blue; } .dead { color: black; } @media (min-width: 1px) { .m { color: red; } }"
.to_string(),
},
];
let result = run_default_css_module_token_census(
&sources,
&[],
&OmenaQueryTransformExecutionContextV0::default(),
)?;
let census = &result.ownership_census;
assert!(census.complete);
assert_eq!(census.modeled_preimage_count, 4);
assert_eq!(census.token_ownerships.len(), 4);
assert_eq!(census.module_token_collision_count, 0);
assert!(census.interface_mismatches.is_empty());
let output = result.bundle_result.artifact.output_css.as_str();
println!("dependency-scope-bytes output={output:?}");
for raw_name in [".entry", ".a", ".dead", ".m"] {
assert!(
!output.contains(raw_name),
"unscoped {raw_name} in {output}"
);
}
Ok(())
}
#[test]
fn token_integrity_default_path_tree_shakes_media_nested_dependency_classes() -> Result<(), String>
{
let sources = vec![
OmenaQueryStyleSourceInputV0 {
style_path: "src/app.module.css".to_string(),
style_source: "@import './dependency.module.css'; .entry { color: green; }".to_string(),
},
OmenaQueryStyleSourceInputV0 {
style_path: "src/dependency.module.css".to_string(),
style_source:
".a { color: blue; } .dead { color: black; } @media (min-width: 1px) { .m { color: red; } }"
.to_string(),
},
];
let context = OmenaQueryTransformExecutionContextV0 {
reachable_class_names: vec!["entry".to_string(), "a".to_string(), "m".to_string()],
..OmenaQueryTransformExecutionContextV0::default()
};
let result = run_default_css_module_token_census(
&sources,
&[
"import-inline".to_string(),
"tree-shake-class".to_string(),
"css-modules-class-hashing".to_string(),
"print-css".to_string(),
],
&context,
)?;
let output = result.bundle_result.artifact.output_css.as_str();
println!("media-tree-shake-bytes output={output:?}");
assert!(output.contains("@media"), "{output}");
assert!(output.contains("color: red"), "{output}");
assert!(!output.contains("color: black"), "{output}");
assert!(!output.contains(".m"), "{output}");
assert!(result.ownership_census.interface_mismatches.is_empty());
Ok(())
}
#[test]
fn token_integrity_default_path_removes_resolved_dependency_composes_declarations()
-> Result<(), String> {
let sources = vec![
OmenaQueryStyleSourceInputV0 {
style_path: "src/app.module.css".to_string(),
style_source: "@import './dependency.module.css'; .entry { color: green; }".to_string(),
},
OmenaQueryStyleSourceInputV0 {
style_path: "src/dependency.module.css".to_string(),
style_source: ".child { composes: base from './base.module.css'; color: blue; }"
.to_string(),
},
OmenaQueryStyleSourceInputV0 {
style_path: "src/base.module.css".to_string(),
style_source: ".base { color: red; }".to_string(),
},
];
let result = run_default_css_module_token_census(
&sources,
&[],
&OmenaQueryTransformExecutionContextV0::default(),
)?;
let output = result.bundle_result.artifact.output_css.as_str();
println!("resolved-composes-bytes output={output:?}");
// FALSIFIER: deleting the dependency rules together with `composes` must
// not satisfy this arm; both producer-authored declarations remain live.
assert!(!output.contains("composes"), "{output}");
assert!(output.contains("color:red"), "{output}");
assert!(output.contains("color:#00f"), "{output}");
let owned_names = result
.ownership_census
.token_ownerships
.iter()
.flat_map(|ownership| ownership.original_names.iter().map(String::as_str))
.collect::<BTreeSet<_>>();
assert!(owned_names.contains("base"), "{owned_names:?}");
assert!(owned_names.contains("child"), "{owned_names:?}");
assert!(result.ownership_census.interface_mismatches.is_empty());
Ok(())
}
#[test]
fn token_integrity_default_path_scopes_non_ascii_dependency_classes() -> Result<(), String> {
let sources = vec![
OmenaQueryStyleSourceInputV0 {
style_path: "src/app.module.css".to_string(),
style_source: "@import './dependency.module.css'; .entry { color: green; }".to_string(),
},
OmenaQueryStyleSourceInputV0 {
style_path: "src/dependency.module.css".to_string(),
style_source: ".카드 { color: blue; }".to_string(),
},
];
let result = run_default_css_module_token_census(
&sources,
&[],
&OmenaQueryTransformExecutionContextV0::default(),
)?;
let output = result.bundle_result.artifact.output_css.as_str();
println!("non-ascii-scope-bytes output={output:?}");
assert!(!output.contains(".카드"), "{output}");
assert!(result.ownership_census.interface_mismatches.is_empty());
assert!(
result
.ownership_census
.token_ownerships
.iter()
.any(|ownership| { ownership.original_names.iter().any(|name| name == "카드") })
);
Ok(())
}
#[test]
fn bundle_paths_consume_package_export_resolution() -> Result<(), String> {
let sources = vec![
OmenaQueryStyleSourceInputV0 {
style_path: "src/app.css".to_string(),
style_source: include_str!(
"../../tests/fixtures/bundle-package-exports/src/entry.css"
)
.to_string(),
},
OmenaQueryStyleSourceInputV0 {
style_path: "node_modules/@acme/theme/dist/tokens.css".to_string(),
style_source: include_str!(
"../../tests/fixtures/bundle-package-exports/node_modules/@acme/theme/dist/tokens.css"
)
.to_string(),
},
];
let pass_ids = vec!["import-inline".to_string(), "print-css".to_string()];
let context = OmenaQueryTransformExecutionContextV0::default();
let resolution_inputs = OmenaQueryStyleResolutionInputsV0 {
package_manifests: vec![OmenaQueryStylePackageManifestV0 {
package_json_path: "node_modules/@acme/theme/package.json".to_string(),
package_json_source: include_str!(
"../../tests/fixtures/bundle-package-exports/node_modules/@acme/theme/package.json"
)
.to_string(),
}],
..OmenaQueryStyleResolutionInputsV0::default()
};
let run = |options: &OmenaQueryConsumerBuildOptionsV0,
style_sources: &[OmenaQueryStyleSourceInputV0]| {
run_omena_query_bundle_with_semantic_inputs_and_options(
OmenaQueryBundlePlanInputV0 {
target_style_path: "src/app.css",
style_sources,
source_map_sources: style_sources,
requested_pass_ids: &pass_ids,
context: &context,
resolution_inputs: &resolution_inputs,
asset_rewrites: Vec::new(),
bundle_entry_style_paths: &[],
},
&[],
options,
)
};
let default_result = run(&OmenaQueryConsumerBuildOptionsV0::default(), &sources)?;
let linked_result = run(
&OmenaQueryConsumerBuildOptionsV0 {
bundle_emission_path: OmenaQueryBundleEmissionPathV0::LinkedOrder,
..OmenaQueryConsumerBuildOptionsV0::default()
},
&sources,
)?;
assert!(
default_result
.artifact
.output_css
.contains(".package-token")
);
assert!(linked_result.artifact.output_css.contains(".package-token"));
let mut missing_sources = sources;
missing_sources[0].style_source =
include_str!("../../tests/fixtures/bundle-package-exports/src/missing.css").to_string();
let missing_result = run(
&OmenaQueryConsumerBuildOptionsV0::default(),
&missing_sources,
)
.map_err(|error| format!("typed open outcome should remain observable: {error}"))?;
assert!(matches!(
missing_result.closed_world_outcome,
OmenaQueryClosedWorldOutcomeV0::Open { ref blockers }
if blockers.iter().any(|blocker| matches!(
blocker,
OmenaQueryClosedWorldBlockerV0::MissingDependency {
import_source,
..
} if import_source == "@acme/theme/missing.css"
))
));
Ok(())
}
#[test]
fn bundle_evidence_consumes_sif_hashes_and_precision_deterministically() -> Result<(), String> {
let sources = vec![
OmenaQueryStyleSourceInputV0 {
style_path: "src/app.css".to_string(),
style_source: "@import \"./tokens.css\"; .app { color: green; }".to_string(),
},
OmenaQueryStyleSourceInputV0 {
style_path: "src/tokens.css".to_string(),
style_source: ".token { color: blue; }".to_string(),
},
];
let sif = OmenaSifV1::from_static_exports(
"src/app.css",
OmenaSifGeneratorV1 {
name: "fixture".to_string(),
version: "1".to_string(),
toolchain_id: "fixture@1".to_string(),
},
OmenaSifSourceV1 {
syntax: OmenaSifSourceSyntaxV1::Css,
},
OmenaSifExportsV1::default(),
Vec::new(),
sources[0].style_source.as_bytes(),
)
.map_err(|error| error.to_string())?;
let external_sifs = vec![OmenaQueryExternalSifInputV0 {
canonical_url: "src/app.css".to_string(),
sif,
}];
let pass_ids = vec!["import-inline".to_string(), "print-css".to_string()];
let context = OmenaQueryTransformExecutionContextV0::default();
let resolution_inputs = OmenaQueryStyleResolutionInputsV0::default();
let result = run_omena_query_bundle_with_semantic_inputs(
OmenaQueryBundlePlanInputV0 {
target_style_path: "src/app.css",
style_sources: &sources,
source_map_sources: &sources,
requested_pass_ids: &pass_ids,
context: &context,
resolution_inputs: &resolution_inputs,
asset_rewrites: Vec::new(),
bundle_entry_style_paths: &[],
},
&external_sifs,
)?;
let bundle = result
.closed_world_outcome
.bundle()
.ok_or_else(|| "fixture should produce a closed-world bundle".to_string())?;
let entries = bundle.interface_hashes().entries();
assert_eq!(entries.len(), 2);
assert_eq!(
entries
.iter()
.filter(|entry| matches!(
entry.availability,
ClosedWorldInterfaceHashAvailabilityV0::Known { .. }
))
.count(),
2,
"every local module now carries a deterministic interface hash"
);
let source_precision = bundle
.source_precision()
.ok_or_else(|| "bundle should carry source precision".to_string())?;
assert_eq!(source_precision.unknown_source_count, 2);
assert_eq!(source_precision.conservative_source_count, 0);
let evidence = summarize_omena_query_bundle_evidence(&result);
let first = serde_json::to_vec_pretty(&evidence).map_err(|error| error.to_string())?;
let second = serde_json::to_vec_pretty(&summarize_omena_query_bundle_evidence(&result))
.map_err(|error| error.to_string())?;
assert_eq!(first, second);
assert!(
!String::from_utf8_lossy(&first)
.to_lowercase()
.contains("exhaustive")
);
assert_eq!(
evidence
.reachability
.as_ref()
.map(|reachability| reachability.guarantee),
Some(omena_evidence_graph::GuaranteeKindV0::NotClaimedExactTraversal)
);
assert!(result.closed_world_decision_parity.equivalent);
Ok(())
}
#[test]
fn transform_plan_keeps_plain_css_imports_out_of_scss_evaluator() {
let source = r#"@import "./tokens.css"; .button { color: red; }"#;
let summary = summarize_omena_query_transform_plan_from_source(
"App.css",
source,
"modern",
modern_omena_query_target_feature_support(),
OmenaQueryTargetTransformOptionsV0::default(),
default_omena_query_transform_print_options(),
);
assert_eq!(summary.product, "omena-query.transform-plan");
assert!(summary.bundle.import_inline_required);
assert!(!summary.bundle.module_evaluation_required);
assert_eq!(summary.bundle.required_pass_ids, vec!["import-inline"]);
assert!(!summary.combined_pass_ids.contains(&"scss-module-evaluate"));
assert!(summary.combined_pass_ids.contains(&"import-inline"));
}
#[test]
fn exposes_transform_plan_egg_witnesses_from_source_execution() {
let source = ".a:is(.ready) { width: calc(7 + 0); } .b:is(.x, .x) { color: red; } .c:where(.y, .y) { color: blue; }";
let target_support = OmenaQueryTargetFeatureSupportV0 {
vendor_prefix_required: false,
supports_light_dark: true,
supports_color_mix: true,
supports_oklch_oklab: true,
supports_color_function: true,
supports_relative_color: true,
supports_logical_properties: true,
supports_css_nesting: true,
supports_css_scope: true,
supports_cascade_layers: true,
};
let target_options = OmenaQueryTargetTransformOptionsV0 {
allow_logical_to_physical: false,
allow_scope_flatten: false,
allow_layer_flatten: false,
enable_supports_static_eval: false,
enable_media_static_eval: false,
enable_container_static_eval: false,
drop_dark_mode_media_queries: false,
};
let summary = summarize_omena_query_transform_plan_from_source(
"Button.css",
source,
"modern",
target_support,
target_options,
default_omena_query_transform_print_options(),
);
assert_eq!(
summary.egg.planned_pass_ids,
vec!["selector-is-where-compression", "calc-reduction"]
);
assert!(
summary
.ready_surfaces
.contains(&"transformEggExecutionWitnesses")
);
assert_eq!(summary.egg_witnesses.len(), 4);
assert!(
summary
.egg_witnesses
.iter()
.all(|witness| witness.execution.accepted)
);
assert!(summary.execution.output_css.contains(".a.ready"));
assert!(summary.execution.output_css.contains(".b.x"));
assert!(summary.execution.output_css.contains(".c:where(.y)"));
assert!(summary.execution.output_css.contains("width: 7"));
assert!(
summary.egg_witnesses.iter().any(|witness| {
witness.source_kind == "selectorIsDedup" && witness.css_after == ".x"
})
);
assert!(summary.egg_witnesses.iter().any(|witness| {
witness.source_kind == "selectorWhereDedup" && witness.css_after == ":where(.y)"
}));
}
#[test]
fn exposes_target_stale_prefix_removal_egg_witnesses_from_source_execution() {
let source = ".a { -webkit-user-select: none; user-select: none; }";
let summary = summarize_omena_query_transform_plan_from_source(
"Button.css",
source,
"modern",
OmenaQueryTargetFeatureSupportV0 {
vendor_prefix_required: false,
supports_light_dark: true,
supports_color_mix: true,
supports_oklch_oklab: true,
supports_color_function: true,
supports_relative_color: true,
supports_logical_properties: true,
supports_css_nesting: true,
supports_css_scope: true,
supports_cascade_layers: true,
},
OmenaQueryTargetTransformOptionsV0 {
allow_logical_to_physical: false,
allow_scope_flatten: false,
allow_layer_flatten: false,
enable_supports_static_eval: false,
enable_media_static_eval: false,
enable_container_static_eval: false,
drop_dark_mode_media_queries: false,
},
default_omena_query_transform_print_options(),
);
assert!(
summary
.target
.planned_pass_ids
.contains(&"stale-prefix-removal")
);
assert!(summary.combined_pass_ids.contains(&"stale-prefix-removal"));
assert!(!summary.execution.output_css.contains("-webkit-user-select"));
assert!(summary.execution.output_css.contains("user-select: none"));
assert!(summary.egg.planned_pass_ids.is_empty());
assert!(summary.egg_witnesses.iter().any(|witness| {
witness.pass_id == "stale-prefix-removal"
&& witness.source_kind == "stalePrefixExactPeer"
&& witness.css_before == "-webkit-user-select: none;"
&& witness.css_after == "user-select: none;"
&& witness.execution.accepted
}));
}
#[test]
fn exposes_transform_plan_custom_property_fixed_point() {
let source = r#":root { --brand: red; --alias: var(--brand); --shadow: 0 0 var(--alias); --cycle-a: var(--cycle-b); --cycle-b: var(--cycle-a); } .card { color: var(--alias); box-shadow: var(--shadow); }"#;
let summary = summarize_omena_query_transform_plan_from_source(
"tokens.css",
source,
"modern",
modern_omena_query_target_feature_support(),
OmenaQueryTargetTransformOptionsV0 {
allow_logical_to_physical: false,
allow_scope_flatten: false,
allow_layer_flatten: false,
enable_supports_static_eval: false,
enable_media_static_eval: false,
enable_container_static_eval: false,
drop_dark_mode_media_queries: false,
},
default_omena_query_transform_print_options(),
);
assert!(
summary
.ready_surfaces
.contains(&"customPropertyLeastFixedPoint")
);
assert_eq!(summary.custom_property_fixed_point.input_count, 5);
assert_eq!(summary.custom_property_fixed_point.resolved_count, 3);
assert_eq!(
summary.custom_property_fixed_point.guaranteed_invalid_count,
2
);
assert!(
summary
.custom_property_fixed_point
.entries
.iter()
.any(|entry| entry.name == "--alias" && entry.changed)
);
assert!(
summary
.custom_property_fixed_point
.entries
.iter()
.any(|entry| entry.name == "--shadow" && entry.changed)
);
}
#[cfg(feature = "transform-catalog-trace")]
#[test]
fn transform_execute_transform_catalog_trace_is_explicit_opt_in_product_lane() {
let source = r#".a { color : red ; /* remove */ content : "x y" ; }"#;
let requested_pass_ids = vec![
"comment-strip".to_string(),
"whitespace-strip".to_string(),
"print-css".to_string(),
];
let summary = execute_omena_query_transform_passes_from_source_with_transform_catalog_trace(
"Button.css",
source,
&requested_pass_ids,
);
assert_eq!(
summary.product,
"omena-query.transform-execute-transform-catalog-trace"
);
assert_eq!(
summary.product_scope,
"explicitOptInTransformCatalogTraceProductLane"
);
assert!(!summary.default_product_mechanism);
assert!(!summary.global_transform_theorem_claimed);
assert_eq!(
summary.execution.execution.output_css,
r#".a{color:red;content:"x y"}"#
);
assert_eq!(
summary.transform_catalog_trace().product,
"omena-lawvere.model-trace"
);
assert_eq!(
summary.transform_catalog_trace().ordered_pass_ids,
summary.execution.execution.ordered_pass_ids
);
assert_eq!(
summary.parallel_plan.scheduler_status,
"independenceDataReady"
);
assert!(!summary.parallel_plan.executor_consumes_plan);
assert_eq!(summary.reorderability_certificates.len(), 1);
assert_eq!(summary.differential_witnesses.len(), 1);
assert_eq!(
summary.reorderability_certificates[0].commute_witness,
"requiresCheckedIndependenceCertificate"
);
assert!(!summary.reorderability_certificates[0].accepted);
assert_eq!(summary.differential_witnesses[0].fixture_count, 1);
assert_eq!(summary.differential_witnesses[0].mismatch_count, 0);
assert!(summary.differential_witnesses[0].accepted);
assert!(
summary
.ready_surfaces
.contains(&"transformCatalogDifferentialReorderabilityCertificate")
);
}
#[cfg(feature = "transform-catalog-trace")]
#[test]
#[allow(deprecated)]
fn compatibility_and_canonical_transform_execution_keep_distinct_exact_wire_projections()
-> Result<(), serde_json::Error> {
let source = r#".a { color : red ; /* remove */ content : "x y" ; }"#;
let requested_pass_ids = vec![
"comment-strip".to_string(),
"whitespace-strip".to_string(),
"print-css".to_string(),
];
let compatibility = compatibility_transform_execution_serialized_projection_v0(
"Button.css",
source,
&requested_pass_ids,
)?;
assert_eq!(
compatibility,
COMPATIBILITY_TRANSFORM_EXECUTION_EXPECTED_WIRE_V0
);
let summary = execute_omena_query_transform_passes_from_source_with_transform_catalog_trace(
"Button.css",
source,
&requested_pass_ids,
);
let trace = summary.transform_catalog_trace();
let canonical = serde_json::to_string(&serde_json::json!({
"product": summary.product,
"productScope": summary.product_scope,
"readySurfaces": summary.ready_surfaces,
"traceFeatureGate": trace.feature_gate,
"traceTheoryVersion": trace.theory_version,
"traceClusterFeatureGate": trace.rank_clusters[0].feature_gate,
"traceClusterTheoryVersion": trace.rank_clusters[0].theory_version,
"planFeatureGate": summary.parallel_plan.feature_gate,
"planClusterFeatureGate": summary.parallel_plan.rank_clusters[0].feature_gate,
"planClusterTheoryVersion": summary.parallel_plan.rank_clusters[0].theory_version,
"certificateFeatureGate": summary.reorderability_certificates[0].feature_gate,
"certificateTheoryVersion": summary.reorderability_certificates[0].theory_version,
"witnessFeatureGate": summary.differential_witnesses[0].feature_gate,
"witnessTheoryVersion": summary.differential_witnesses[0].theory_version,
}))?;
assert_eq!(
canonical,
r#"{"product":"omena-query.transform-execute-transform-catalog-trace","productScope":"explicitOptInTransformCatalogTraceProductLane","readySurfaces":["queryTransformExecutionHandoff","transformCatalogModelTrace","transformCatalogParallelPlanTrace","transformCatalogDifferentialReorderabilityCertificate"],"traceFeatureGate":"transform-catalog-saturation","traceTheoryVersion":"css-transform-catalog-v0","traceClusterFeatureGate":"transform-catalog-saturation","traceClusterTheoryVersion":"css-transform-catalog-v0","planFeatureGate":"transform-catalog-saturation","planClusterFeatureGate":"transform-catalog-saturation","planClusterTheoryVersion":"css-transform-catalog-v0","certificateFeatureGate":"transform-catalog-saturation","certificateTheoryVersion":"css-transform-catalog-v0","witnessFeatureGate":"transform-catalog-saturation","witnessTheoryVersion":"css-transform-catalog-v0"}"#
);
Ok(())
}
#[cfg(feature = "transform-catalog-trace")]
#[test]
fn transform_execute_transform_catalog_trace_exposes_rejected_differential_witness() {
let source = r#".a { & .b { color: red; } } .a .b { color: red; }"#;
let requested_pass_ids = vec![
"rule-deduplication".to_string(),
"nesting-unwrap".to_string(),
];
let summary = execute_omena_query_transform_passes_from_source_with_transform_catalog_trace(
"Nested.css",
source,
&requested_pass_ids,
);
assert_eq!(
summary.product_scope,
"explicitOptInTransformCatalogTraceProductLane"
);
assert!(!summary.default_product_mechanism);
assert!(!summary.global_transform_theorem_claimed);
assert_eq!(summary.reorderability_certificates.len(), 1);
assert_eq!(summary.differential_witnesses.len(), 1);
assert_eq!(
summary.reorderability_certificates[0].differential_mismatch_count,
1
);
assert!(!summary.reorderability_certificates[0].accepted);
assert_eq!(summary.differential_witnesses[0].fixture_count, 1);
assert_eq!(summary.differential_witnesses[0].equal_fixture_count, 0);
assert_eq!(summary.differential_witnesses[0].mismatch_count, 1);
assert!(!summary.differential_witnesses[0].accepted);
}
#[test]
fn exposes_transform_plan_facade_from_browserslist_target_query() {
let source = ".button { display: flex; color: light-dark(#000, #fff); }";
let target_options = OmenaQueryTargetTransformOptionsV0 {
allow_logical_to_physical: true,
allow_scope_flatten: true,
allow_layer_flatten: true,
enable_supports_static_eval: false,
enable_media_static_eval: false,
enable_container_static_eval: false,
drop_dark_mode_media_queries: false,
};
let summary = summarize_omena_query_transform_plan_from_target_query(
"Button.module.css",
source,
"ie 11",
target_options,
default_omena_query_transform_print_options(),
);
assert!(summary.target_query.is_some());
let Some(target_query) = summary.target_query.as_ref() else {
return;
};
assert_eq!(target_query.profile_id, "browserslist-resolved");
assert_eq!(target_query.resolved_targets, vec!["ie 11"]);
assert_eq!(target_query.resolution_error, None);
assert_eq!(summary.target, target_query.transform_plan);
assert!(
summary
.target
.required_pass_ids
.contains(&"vendor-prefixing")
);
assert!(
summary
.target
.required_pass_ids
.contains(&"light-dark-lowering")
);
assert_eq!(summary.combined_violated_dag_edge_count, 0);
}
#[test]
fn exposes_transform_execution_runner_from_source() {
let source = r#".a { color: red; /* remove */ content: "/* keep */"; }"#;
let summary = execute_omena_query_transform_passes_from_source(
"Button.module.css",
source,
&[
"comment-strip".to_string(),
"print-css".to_string(),
"unknown-transform-pass".to_string(),
],
);
assert_eq!(summary.product, "omena-query.transform-execute");
assert_eq!(summary.style_path, "Button.module.css");
assert_eq!(summary.unknown_pass_ids, vec!["unknown-transform-pass"]);
assert_eq!(
summary.execution.product,
"omena-transform-passes.execution"
);
assert_eq!(summary.execution.mutation_count, 1);
assert_eq!(
summary.execution.output_css,
r#".a { color: red; content: "/* keep */"; }"#
);
assert_eq!(
summary.execution.executed_pass_ids,
vec!["comment-strip", "print-css"]
);
assert!(
summary
.ready_surfaces
.contains(&"transformExecutionRuntime")
);
}
#[test]
fn exposes_native_css_static_eval_execution_runner_from_source() {
let source = r#"@function --gap(--size <length>: 1rem) returns <length> { result: var(--size); } .card { gap: --gap(2rem); display: if(supports(display: grid): grid; else: block); margin: if(media(width >= 1px): 1rem; else: 2rem); } @when supports(display: grid) { .grid { display: grid; } } @else { .fallback { display: block; } }"#;
let summary = execute_omena_query_transform_passes_from_source(
"Native.css",
source,
&[
"native-css-static-eval".to_string(),
"print-css".to_string(),
],
);
assert_eq!(summary.product, "omena-query.transform-execute");
assert_eq!(summary.unknown_pass_ids, Vec::<String>::new());
assert_eq!(summary.execution.mutation_count, 3);
assert!(summary.execution.output_css.contains("gap: 2rem"));
assert!(summary.execution.output_css.contains("display: grid"));
assert!(
summary
.execution
.output_css
.contains(".grid { display: grid; }")
);
assert!(
summary
.execution
.output_css
.contains("margin: if(media(width >= 1px): 1rem; else: 2rem)")
);
assert!(!summary.execution.output_css.contains("--gap(2rem)"));
assert!(!summary.execution.output_css.contains("@when"));
assert!(!summary.execution.output_css.contains(".fallback"));
assert!(
!summary
.execution
.output_css
.contains("display: if(supports")
);
assert_eq!(
summary.execution.executed_pass_ids,
vec!["native-css-static-eval", "print-css"]
);
}
#[test]
fn exposes_transform_execution_cascade_proof_obligations_from_source() {
let source = r#".a { margin-top: 1px; margin-right: 2px; margin-bottom: 1px; margin-left: 2px; }
@supports (display: grid) { .grid { display: grid; } }
"#;
let summary = execute_omena_query_transform_passes_from_source(
"Button.module.css",
source,
&[
"shorthand-combining".to_string(),
"supports-static-eval".to_string(),
"print-css".to_string(),
],
);
assert_eq!(
summary.execution.cascade_proof_obligations.product,
"omena-transform-passes.cascade-proof-obligations"
);
assert_eq!(
summary.execution.cascade_proof_obligations.obligation_count,
2
);
assert_eq!(
summary.execution.cascade_proof_obligations.accepted_count,
2
);
assert!(
summary
.execution
.cascade_proof_obligations
.checked_pass_ids
.contains(&"shorthand-combining")
);
assert!(
summary
.execution
.cascade_proof_obligations
.checked_pass_ids
.contains(&"supports-static-eval")
);
assert!(
summary
.execution
.cascade_proof_obligations
.obligations
.iter()
.any(|obligation| {
obligation.proof_product == "omena-cascade.shorthand-combination-proof"
})
);
assert!(
summary
.execution
.cascade_proof_obligations
.obligations
.iter()
.any(|obligation| obligation.proof_product == "omena-cascade.supports-static-eval")
);
}
#[test]
fn lists_transform_pass_summaries_from_query() {
let passes = list_omena_query_transform_pass_summaries();
assert_eq!(passes.len(), 44);
assert!(passes.iter().any(|pass| pass.id == "whitespace-strip"));
assert!(
passes
.iter()
.any(|pass| pass.id == "relative-color-lowering")
);
assert!(passes.iter().any(|pass| pass.id == "container-static-eval"));
assert!(
passes
.iter()
.any(|pass| pass.id == "native-css-static-eval")
);
assert!(passes.iter().any(|pass| {
pass.id == "native-css-static-eval"
&& pass.explicit_opt_in_required
&& pass.dialect_restriction == Some("css-only")
&& pass.spec_snapshot == Some("css-values-5-if-css-mixins-1-function-ed-2026-06-22")
&& pass.opt_in_policy
== Some("explicit-pass-id-required-default-consumer-build-excludes")
}));
assert!(passes.iter().any(|pass| pass.id == "print-css"));
}