From 7a9fabfa2c37b9c5f87aa42ce97c6212036ed6c5 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Tue, 22 Sep 2026 11:51:35 +0200 Subject: [PATCH] CultNet selection: port the C# alias rule into cultnet-rs, delete the hash matcher Self's ruling, 2026-09-22 ("the C# reference's alias rule is the rule"): an alias is a schema *name* with a trailing .vN suffix, resolved against the descriptor's declared name - never against a hash id. C#'s production call sites (CultNetSelection.cs:438, CultNetSelectionEvaluator.cs:88,340) all use the descriptor overload of CultNetSchemaAliasMatching.Matches, never the bare id-vs-id overload. - Row gains schema_name() (defaults to schema_id() for rows with no separate name, e.g. raw wire records); RowSet gains schema_name(schema_id) -> Option. Both stand in for CultDocumentDescriptor.SchemaName, which this crate has no type for (D7). - schema_alias::matches/matches_any now take (candidate, schema_id, schema_name) and resolve a candidate's inferred name against the declared name, exactly as the C# descriptor overload does - not against schema_id's own inferred name, which is what the deleted hash-stripping matcher did. - Every call site (reachable_schemas, the cites.target door check, matches_schema_keys_fields's D6 fast path, matches_citation) now resolves and passes a schema's name instead of comparing two schema-id strings. - Deleted: the hash-stripping schema_alias::matches(candidate, schema_id) two-string overload. A hash-shaped alias (".v1") is not a wire form either runtime's production rule ever resolves. Behaviour verified against a standalone run of the exact C# algorithm (CultNetSchemaAliasMatching, CultNetDatabase.cs:47-97) covering exact-id match, bare-name match, .vN alias resolution, MatchesAny's empty-matches-all convention, ordinal case sensitivity, ".v" with no trailing digits, and multiple ".v" markers (last one wins) - every case is now a Rust unit test in schema_alias::tests. Test fixture (tests/selection.rs) updated: the fixture's hashAlias entries are now a shared negative check (neither runtime resolves them), and the nameAlias entries now resolve in Rust too, fixing the confirmed cross-runtime defect (schemas_by_name_alias). Regenerated contracts/cultnet/interop/selection-vectors.rs-written.json (15 -> 16 vectors): added refuses_cites_target_by_hash_shaped_alias, renamed hop_by_role_cites_hash_alias to hop_by_role_cites_name_alias. cultnet-rs: cargo test 223/223. C# reader (rs-written.json): 14/16 - the two failures are both the pending unmatched-cites.target door refusal (CultNetSelection.cs:361-391 has no such check yet), not a Rust defect; the other Hands' C# door fix covers both. Co-Authored-By: Claude Sonnet 5 --- .../interop/selection-vectors.rs-written.json | 32 ++-- packages/cultnet-rs/src/selection.rs | 152 ++++++++++++++---- packages/cultnet-rs/tests/selection.rs | 140 ++++++++++++---- 3 files changed, 251 insertions(+), 73 deletions(-) diff --git a/contracts/cultnet/interop/selection-vectors.rs-written.json b/contracts/cultnet/interop/selection-vectors.rs-written.json index aaf3d532..2a0a3c68 100644 --- a/contracts/cultnet/interop/selection-vectors.rs-written.json +++ b/contracts/cultnet/interop/selection-vectors.rs-written.json @@ -104,8 +104,8 @@ ] }, { - "name": "hop_by_role_cites_hash_alias", - "selectionMessagePackBase64": "g6VjaXRlc4KmdGFyZ2V0gqhzY2hlbWFJZNlKc2hhMjU2OmZmMzVmM2Q5ZDZkZTNmMTA2NmI5MzY5ZTczZmU2Yzc2NDhlODgzNjhkMThlZmMyMjc1Yzk5NDczMGNkODRjZmYudjGpcmVjb3JkS2V5pGEtZXGkcm9sZaZEZXNpZ26qcHJvamVjdGlvbqZoZWFkZXKqZGVzY2VuZGluZ8I=", + "name": "hop_by_role_cites_name_alias", + "selectionMessagePackBase64": "g6VjaXRlc4KmdGFyZ2V0gqhzY2hlbWFJZKlsZWFmX2EudjmpcmVjb3JkS2V5pGEtZXGkcm9sZaZEZXNpZ26qcHJvamVjdGlvbqZoZWFkZXKqZGVzY2VuZGluZ8I=", "asOf": 1, "expectedIds": [ "sha256:9d0bc9aebc3619b07aabf564f98667afde41444c1b866661d777687d443608dc/citer-1" @@ -125,6 +125,15 @@ "name": "schemas_by_hash_alias", "selectionMessagePackBase64": "g6dzY2hlbWFzkdlKc2hhMjU2OmZmMzVmM2Q5ZDZkZTNmMTA2NmI5MzY5ZTczZmU2Yzc2NDhlODgzNjhkMThlZmMyMjc1Yzk5NDczMGNkODRjZmYudjGqcHJvamVjdGlvbqZoZWFkZXKqZGVzY2VuZGluZ8I=", "asOf": 1, + "expectedIds": [], + "matched": 0, + "hasNext": false, + "expectedEdges": [] + }, + { + "name": "schemas_by_name_alias", + "selectionMessagePackBase64": "g6dzY2hlbWFzkalsZWFmX2EudjmqcHJvamVjdGlvbqZoZWFkZXKqZGVzY2VuZGluZ8I=", + "asOf": 1, "expectedIds": [ "sha256:ff35f3d9d6de3f1066b9369e73fe6c7648e88368d18efc2275c994730cd84cff/a-lo", "sha256:ff35f3d9d6de3f1066b9369e73fe6c7648e88368d18efc2275c994730cd84cff/a-eq", @@ -138,15 +147,6 @@ "hasNext": false, "expectedEdges": [] }, - { - "name": "schemas_by_name_alias", - "selectionMessagePackBase64": "g6dzY2hlbWFzkalsZWFmX2EudjmqcHJvamVjdGlvbqZoZWFkZXKqZGVzY2VuZGluZ8I=", - "asOf": 1, - "expectedIds": [], - "matched": 0, - "hasNext": false, - "expectedEdges": [] - }, { "name": "float_tie_exact_ge", "selectionMessagePackBase64": "g6ZmaWVsZHORg6VpbmRleKRtYXNzom9womdlpm51bWJlcqoyMjMzNzU5LjI1qnByb2plY3Rpb26maGVhZGVyqmRlc2NlbmRpbmfC", @@ -199,6 +199,16 @@ "matched": 0, "hasNext": false, "expectedEdges": [] + }, + { + "name": "refuses_cites_target_by_hash_shaped_alias", + "selectionMessagePackBase64": "g6VjaXRlc4KmdGFyZ2V0gqhzY2hlbWFJZNlKc2hhMjU2OmZmMzVmM2Q5ZDZkZTNmMTA2NmI5MzY5ZTczZmU2Yzc2NDhlODgzNjhkMThlZmMyMjc1Yzk5NDczMGNkODRjZmYudjGpcmVjb3JkS2V5pGEtZXGkcm9sZaZEZXNpZ26qcHJvamVjdGlvbqZoZWFkZXKqZGVzY2VuZGluZ8I=", + "asOf": 1, + "expectedRefusalField": "cites.target.schemaId", + "expectedIds": [], + "matched": 0, + "hasNext": false, + "expectedEdges": [] } ] } \ No newline at end of file diff --git a/packages/cultnet-rs/src/selection.rs b/packages/cultnet-rs/src/selection.rs index 596f6b2b..6dc48da3 100644 --- a/packages/cultnet-rs/src/selection.rs +++ b/packages/cultnet-rs/src/selection.rs @@ -441,33 +441,53 @@ pub mod canonical_number { // --------------------------------------------------------------------------------------------- /// The one schema-identity rule (R-E), ported from the C# reference's -/// `CultNetSchemaAliasMatching.Matches(string, string)` / `MatchesAny`. `selection.schemas` and -/// `cites.target.schemaId` both go through this - D7: Rust carries no `CultDocumentDescriptor` -/// knowledge, so (unlike the C# reference's richer descriptor-aware overload) this only ever -/// compares two schema-id strings, exactly or by their inferred name (the part before a trailing -/// `.v`). +/// `CultNetSchemaAliasMatching.Matches(string, CultDocumentDescriptor)` / `MatchesAny` - +/// **Self's ruling, 2026-09-22 ("the C# reference's alias rule is the rule")**: an alias is a +/// schema *name* with a trailing `.v` suffix, resolved against the schema's declared name, +/// never against its hash id. C#'s production call sites (`CultNetSelection.cs:438`, +/// `CultNetSelectionEvaluator.cs:88,340`) all use the descriptor overload, never the bare +/// `Matches(string, string)` id-vs-id overload, so that is the behaviour this module ports. D7 +/// still holds: Rust carries no `CultDocumentDescriptor` type, so `RowSet::schema_name`/ +/// `Row::schema_name` stand in for it - the consumer supplies a schema's declared name the same way +/// it supplies everything else `Row`/`RowSet` expose. pub mod schema_alias { - /// `true` when `candidate` names `schema_id` exactly, or the two share an inferred name. - /// Mirrors `CultNetSchemaAliasMatching.Matches(string candidate, string schemaId)`. - pub fn matches(candidate: &str, schema_id: &str) -> bool { - if candidate == schema_id { + /// `true` when `candidate` names `schema_id` exactly, names `schema_name` exactly, or + /// `candidate`'s inferred name (the part before a trailing `.v` marker, or the whole of + /// `candidate` when it carries no such marker) equals `schema_name` exactly. Ordinal + /// (case-sensitive) comparison throughout, matching C#'s `StringComparison.Ordinal`. Mirrors + /// `CultNetSchemaAliasMatching.Matches(string candidate, CultDocumentDescriptor descriptor)` + /// (`CultNetDatabase.cs:71-84`) with its `SchemaVersion`/`CompatibleSchemaIds` checks folded + /// away: this crate's `Row`/`RowSet` expose no equivalent of either, and no fixture or call site + /// needs them (`CultNetSelection.cs:438` and `CultNetSelectionEvaluator.cs:88,340` are this + /// port's only production callers, and neither reaches for a schema's version string or its + /// compatibility list). + pub fn matches(candidate: &str, schema_id: &str, schema_name: &str) -> bool { + if candidate == schema_id || candidate == schema_name { return true; } let candidate_name = infer_schema_name(candidate).unwrap_or(candidate); - let schema_name = infer_schema_name(schema_id).unwrap_or(schema_id); candidate_name == schema_name } - /// `true` when `candidates` is empty (no filter) or any candidate matches `schema_id`. - /// Mirrors `CultNetSchemaAliasMatching.MatchesAny(IReadOnlyList, string)`. - pub fn matches_any(candidates: &[String], schema_id: &str) -> bool { - candidates.is_empty() || candidates.iter().any(|candidate| matches(candidate, schema_id)) + /// `true` when `candidates` is empty (no filter) or any candidate matches `schema_id`/ + /// `schema_name`. Mirrors `CultNetSchemaAliasMatching.MatchesAny(IReadOnlyList, + /// CultDocumentDescriptor)`. + pub fn matches_any(candidates: &[String], schema_id: &str, schema_name: &str) -> bool { + candidates.is_empty() + || candidates + .iter() + .any(|candidate| matches(candidate, schema_id, schema_name)) } /// The part of `schema_id` before a trailing `.v` marker, or `None` when `schema_id` - /// carries no such marker (real hashed ids, e.g. `"sha256:"`, carry none on their own - - /// aliasing only bridges two ids that share the same unversioned name). Mirrors - /// `CultNetSchemaAliasMatching.InferSchemaName`. + /// carries no such marker: the marker is absent, sits at position 0 (`".v5"`, C#'s `marker <= 0` + /// refusing a zero index too), has nothing after it (`"a.v"`), or what follows `.v` is not every + /// byte a digit (`"a.vx"`, `"a.v5x"`). A `schema_id` with more than one `.v` marker + /// resolves at the *last* one (`"a.v5.v2"` -> `Some("a.v5")`), matching C#'s + /// `LastIndexOf(".v", Ordinal)`. Byte-for-byte port of ASCII digit classification: C#'s + /// `char.IsDigit` is Unicode-aware but every marker byte here is ASCII, so `is_ascii_digit` + /// agrees on every input this rule ever sees. Mirrors + /// `CultNetSchemaAliasMatching.InferSchemaName` (`CultNetDatabase.cs:86-96`). fn infer_schema_name(schema_id: &str) -> Option<&str> { let marker = schema_id.rfind(".v")?; if marker == 0 { @@ -486,25 +506,68 @@ pub mod schema_alias { #[test] fn matches_exact_ids() { - assert!(matches("sha256:abc", "sha256:abc")); - assert!(!matches("sha256:abc", "sha256:def")); + assert!(matches("sha256:abc", "sha256:abc", "leaf_a")); + assert!(!matches("sha256:abc", "sha256:def", "leaf_a")); } #[test] - fn matches_by_inferred_name_across_versions() { - assert!(matches("sha256:abc.v1", "sha256:abc.v2")); - assert!(matches("sha256:abc", "sha256:abc.v1")); - assert!(matches("sha256:abc.v1", "sha256:abc")); + fn matches_exact_name() { + assert!(matches("leaf_a", "sha256:abc", "leaf_a")); + assert!(!matches("leaf_b", "sha256:abc", "leaf_a")); + } + + #[test] + fn matches_by_inferred_name_alias_against_the_declared_name() { + assert!(matches("leaf_a.v9", "sha256:abc", "leaf_a")); + assert!(matches("leaf_a.v0", "sha256:abc", "leaf_a")); + assert!(!matches("leaf_b.v9", "sha256:abc", "leaf_a")); + } + + // R-E, the confirmed cross-runtime defect this cut fixes: a hash with a synthetic ".v1" + // appended is not a wire form C#'s production rule ever resolves (it strips the ".v1" and + // compares the bare hash text against the declared *name*, "leaf_a" - never equal to a + // hash). Sections of docs/cultnet-selection-cut.md call this "hashAlias"; it is a negative + // check in both runtimes now, not an alias either one resolves. + #[test] + fn does_not_match_a_hash_shaped_alias() { + assert!(!matches("sha256:abc.v1", "sha256:abc", "leaf_a")); } #[test] fn does_not_match_a_real_hashed_id_with_no_shared_name() { - assert!(!matches("sha256:abc", "sha256:xyz")); + assert!(!matches("sha256:abc", "sha256:xyz", "leaf_a")); } #[test] fn matches_any_empty_candidates_matches_everything() { - assert!(matches_any(&[], "sha256:anything")); + assert!(matches_any(&[], "sha256:anything", "leaf_a")); + } + + // Case sensitivity: C#'s StringComparison.Ordinal is case-sensitive throughout, on the + // exact-id check, the exact-name check and the inferred-name comparison alike. + #[test] + fn every_comparison_is_case_sensitive() { + assert!(!matches("SHA256:ABC", "sha256:abc", "leaf_a")); + assert!(!matches("LEAF_A", "sha256:abc", "leaf_a")); + assert!(!matches("LEAF_A.v9", "sha256:abc", "leaf_a")); + assert!(!matches("leaf_a.V9", "sha256:abc", "leaf_a")); // ".V9", not ".v9" - no marker + } + + // Edge handling of ".v" with no digits after it: InferSchemaName returns None, so the + // candidate falls back to itself, verbatim - it only matches a schema whose *name* equals + // that literal string. + #[test] + fn a_trailing_dot_v_with_no_digits_falls_back_to_the_literal_candidate() { + assert!(!matches("leaf_a.v", "sha256:abc", "leaf_a")); + assert!(matches("leaf_a.v", "sha256:abc", "leaf_a.v")); + } + + // Edge handling of multiple dots: the *last* ".v" marker wins, matching C#'s + // LastIndexOf(".v", Ordinal) - not the first. + #[test] + fn multiple_dot_v_markers_resolve_at_the_last_one() { + assert!(matches("a.v5.v2", "sha256:abc", "a.v5")); + assert!(!matches("a.v5.v2", "sha256:abc", "a")); } #[test] @@ -868,6 +931,16 @@ impl From for SelectionRefusal { /// surface supplies the C# evaluator. pub trait Row { fn schema_id(&self) -> &str; + /// This row's declared schema *name* (C#'s `CultDocumentDescriptor.SchemaName`) - the alias + /// matcher's name-comparison target (R-E, `schema_alias::matches`). A row whose owner supplies + /// no separate name (e.g. a raw wire record with only a hash id) falls back to `schema_id()`, + /// which is the same "no name known" behaviour the C# reference has none of: every C# document + /// descriptor always carries a real `SchemaName`, so this default exists only for Rust rows + /// that genuinely have nothing better, and it costs them nothing they had before (the fallback + /// still matches an exact id, just never a name alias). + fn schema_name(&self) -> &str { + self.schema_id() + } fn record_key(&self) -> &str; /// The sequence of the commit that last wrote this row. The row owner supplies it; the /// evaluator never reads a clock. @@ -888,6 +961,9 @@ impl Row for &T { fn schema_id(&self) -> &str { (**self).schema_id() } + fn schema_name(&self) -> &str { + (**self).schema_name() + } fn record_key(&self) -> &str { (**self).record_key() } @@ -910,6 +986,9 @@ impl Row for &T { pub trait RowSet { /// Every schema id this row set knows about - the universe `selection.schemas` narrows. fn all_schema_ids(&self) -> Vec; + /// `schema_id`'s declared name (C#'s `CultDocumentDescriptor.SchemaName`) - the alias matcher's + /// name-comparison target (R-E). `None` when `schema_id` is not one of `all_schema_ids()`. + fn schema_name(&self, schema_id: &str) -> Option; /// The declared index aliases a schema carries (inherited or own). fn declared_indexes(&self, schema_id: &str) -> Vec; /// The declared reference roles a schema carries. @@ -1003,11 +1082,10 @@ pub fn validate(selection: &Selection, row_set: &impl RowSet) -> Result<(), Sele } // R-E: cites.target.schemaId goes through the one schema-identity rule too. An unmatched // target is refused at the door, never silently answered with an empty page. - if !row_set - .all_schema_ids() - .iter() - .any(|schema_id| schema_alias::matches(&cites.target.schema_id, schema_id)) - { + if !row_set.all_schema_ids().iter().any(|schema_id| { + let name = row_set.schema_name(schema_id).unwrap_or_else(|| schema_id.clone()); + schema_alias::matches(&cites.target.schema_id, schema_id, &name) + }) { return Err(SelectionInvalid::new( "cites.target.schemaId", Some(cites.target.schema_id.clone()), @@ -1059,7 +1137,10 @@ pub fn reachable_schemas(selection: &Selection, row_set: &impl RowSet) -> Vec all .into_iter() - .filter(|id| schema_alias::matches_any(schemas, id)) + .filter(|id| { + let name = row_set.schema_name(id).unwrap_or_else(|| id.clone()); + schema_alias::matches_any(schemas, id, &name) + }) .collect(), } } @@ -1220,7 +1301,9 @@ fn matches_schema_keys_fields(row: &R, selection: &Selection) -> bool { // `false` (matches nothing), which is what a present-but-empty list must do until something // upstream (the v1 door, or v0's own lowering) turns it into `None` or refuses it outright. if let Some(schemas) = &selection.schemas - && !schemas.iter().any(|candidate| schema_alias::matches(candidate, row.schema_id())) + && !schemas + .iter() + .any(|candidate| schema_alias::matches(candidate, row.schema_id(), row.schema_name())) { return false; } @@ -1593,7 +1676,10 @@ fn matches_citation( }; ensure_within_declared_target(row_set, &role, citer, *resolved)?; // R-E: the target's schema id is matched through the one alias rule, not exact equality. - if !schema_alias::matches(&citation.target.schema_id, resolved.schema_id()) { + let resolved_name = row_set + .schema_name(resolved.schema_id()) + .unwrap_or_else(|| resolved.schema_id().to_string()); + if !schema_alias::matches(&citation.target.schema_id, resolved.schema_id(), &resolved_name) { continue; } edge_sink.push(EdgeMatch { diff --git a/packages/cultnet-rs/tests/selection.rs b/packages/cultnet-rs/tests/selection.rs index 17ed9964..fde97e0e 100644 --- a/packages/cultnet-rs/tests/selection.rs +++ b/packages/cultnet-rs/tests/selection.rs @@ -111,15 +111,30 @@ fn leaf_b() -> &'static str { fn citer() -> &'static str { &fixture_schema("citer").schema_id } -// The alias form cultnet_rs::selection::schema_alias resolves (a synthetic ".v1" appended to the -// real hash - see the module comment above). +// R-E/shared-fixture ruling: the fixture's map key ("leaf_a", "leaf_b", "citer") *is* each +// schema's declared name (C#'s CultDocumentDescriptor.SchemaName) - what RowSet::schema_name/ +// Row::schema_name now expose, and what nameAlias's ".v9" suffix resolves against. +fn leaf_a_name() -> &'static str { + "leaf_a" +} +fn leaf_b_name() -> &'static str { + "leaf_b" +} +fn citer_name() -> &'static str { + "citer" +} +const NARROW_CITER_NAME: &str = "narrow_citer"; +// R-E, Self's ruling 2026-09-22 ("the C# reference's alias rule is the rule"): a hash id with a +// synthetic ".v1" appended is not a wire form either runtime's production rule resolves - +// CultNetSchemaAliasMatching's descriptor overload strips the ".v1" and compares the bare hash +// text against the declared *name* ("leaf_a"), never equal. This is now a shared negative check +// (see does_not_match_a_hash_shaped_alias below and the parity vectors this file writes). fn leaf_a_hash_alias() -> &'static str { &fixture_schema("leaf_a").hash_alias } -// The alias form only CultNetSchemaAliasMatching's descriptor overload resolves ("leaf_a.v9") - -// this crate's schema_alias never sees a descriptor's human name, so a vector built with this -// alias is expected to fail here even though the C# reference resolves it for real (the report's -// confirmed defect). +// The alias form the C# reference's descriptor overload resolves ("leaf_a.v9") - and, as of this +// cut's fix, the alias form this crate's schema_alias resolves too, through Row::schema_name/ +// RowSet::schema_name now standing in for CultDocumentDescriptor.SchemaName. fn leaf_a_name_alias() -> &'static str { &fixture_schema("leaf_a").name_alias } @@ -193,10 +208,29 @@ impl FixtureRow { } } +// Shared by Row::schema_name and RowSet::schema_name below - one place that knows which fixture +// schema id carries which declared name. +fn schema_name_for(schema_id: &str) -> Option<&'static str> { + if schema_id == leaf_a() { + Some(leaf_a_name()) + } else if schema_id == leaf_b() { + Some(leaf_b_name()) + } else if schema_id == citer() { + Some(citer_name()) + } else if schema_id == NARROW_CITER { + Some(NARROW_CITER_NAME) + } else { + None + } +} + impl Row for FixtureRow { fn schema_id(&self) -> &str { self.schema_id } + fn schema_name(&self) -> &str { + schema_name_for(self.schema_id).unwrap_or(self.schema_id) + } fn record_key(&self) -> &str { self.record_key } @@ -232,6 +266,9 @@ impl RowSet for FixtureRowSet { NARROW_CITER.into(), ] } + fn schema_name(&self, schema_id: &str) -> Option { + schema_name_for(schema_id).map(str::to_string) + } fn declared_indexes(&self, schema_id: &str) -> Vec { if schema_id == leaf_a() || schema_id == leaf_b() { vec!["kind".into(), "mass".into()] @@ -1039,17 +1076,22 @@ fn write_selection_vectors_for_the_reference() { ..Selection::default() }, ), - // R-E: the same citation, but the target is named by this crate's own resolvable alias - // (leaf_a_hash_alias(): the real hash with a synthetic ".v1" appended) rather than the exact - // id - schema_alias strips the trailing ".v1" from either side and compares the bare hash. + // R-E: the same citation, but the target is named by the alias form C#'s production rule + // resolves ("leaf_a.v9", stripped to "leaf_a" and compared against the schema's declared + // name) - as of this cut's fix, Row::schema_name/RowSet::schema_name give this crate's own + // schema_alias the same name to resolve against, so this now agrees with the reference too. ( - "hop_by_role_cites_hash_alias", + "hop_by_role_cites_name_alias", Selection { - cites: Some(Citation { target: rr(leaf_a_hash_alias(), "a-eq"), role: Some("Design".into()) }), + cites: Some(Citation { target: rr(leaf_a_name_alias(), "a-eq"), role: Some("Design".into()) }), ..Selection::default() }, ), - // R-E: `schemas` reaches a schema by the same hash alias. + // R-E, Self's ruling 2026-09-22 ("the C# reference's alias rule is the rule"): a hash id + // with a synthetic ".v1" appended is not a wire form either runtime's production rule + // resolves - it strips the ".v1" and compares the bare hash text against the schema's + // declared *name* ("leaf_a"), never equal. This is a shared negative check now: both + // runtimes give an empty reachable set for `schemas`, hence empty expected_ids here. ( "schemas_by_hash_alias", Selection { @@ -1057,15 +1099,12 @@ fn write_selection_vectors_for_the_reference() { ..Selection::default() }, ), - // R-E, the reverse probe of SelectionParityVectorTests.Cases's schemas_by_name_alias: - // schema_alias has no concept of a schema's human name, only its hash id - // (Row::schema_id()), so "leaf_a.v9" resolves to nothing here and this vector's - // expected_ids come out empty even though CultNetSchemaAliasMatching's descriptor overload - // (the only overload any C# call site uses) really does resolve it - it strips the ".v9" and - // compares "leaf_a" to ParityLeafA's descriptor.SchemaName. The C# reader - // (SelectionVectorsWrittenByRustDecodeAndEvaluateIdenticallyInTheReference) therefore - // disagrees with this file's empty expected_ids: confirmed cross-runtime defect: see the - // report. + // R-E: `schemas` reaches a schema by its name alias - as of this cut's fix, this crate's + // schema_alias resolves it the same way CultNetSchemaAliasMatching's descriptor overload + // does (the only overload any C# call site uses): strip the trailing ".v9" and compare + // "leaf_a" to the schema's declared name. Previously this crate's alias matcher had no + // concept of a schema's name at all and gave an empty result here, disagreeing with the + // reference - that cross-runtime defect is what this cut fixes. ( "schemas_by_name_alias", Selection { @@ -1172,6 +1211,20 @@ fn write_selection_vectors_for_the_reference() { }, "cites.target.schemaId", ), + // R-E, Self's ruling 2026-09-22: a hash-shaped alias resolves to no known schema in either + // runtime now (see schemas_by_hash_alias above), so naming one as a cites.target is the + // same "unmatched target" refusal as any other unresolvable schema id. + ( + "refuses_cites_target_by_hash_shaped_alias", + Selection { + cites: Some(Citation { + target: rr(leaf_a_hash_alias(), "a-eq"), + role: Some("Design".into()), + }), + ..Selection::default() + }, + "cites.target.schemaId", + ), ]; for (name, selection, expected_field) in refusal_cases { let bytes = rmp_serde::to_vec_named(&selection).expect("encodes"); @@ -1293,16 +1346,31 @@ fn cursor_digest_does_not_collide_on_differently_split_lists() { // ------------------------------------------------------------------------------------------ #[test] -fn schemas_reaches_a_schema_by_its_unversioned_alias() { +fn schemas_reaches_a_schema_by_its_unversioned_name_alias() { + let rows = base_rows(); + let selection = Selection { + schemas: Some(vec![leaf_a_name_alias().into()]), + ..Selection::default() + }; + let evaluation = select(&FixtureRowSet, &rows, &selection, 1).unwrap(); + let mut ids: Vec<&str> = evaluation.rows.iter().map(Row::record_key).collect(); + ids.sort_unstable(); + assert_eq!(ids, vec!["a-eq", "a-lo", "shared-1", "shared-3"], "every leaf_a row, by name alias"); +} + +// R-E, Self's ruling 2026-09-22: a hash-shaped alias (".v1") is not a wire form the C# +// reference's production rule ever resolves - it strips the ".v1" and compares the bare hash text +// against the schema's declared *name*, never equal. `schemas` never refuses (unlike cites.target +// below), so an unresolved alias just narrows reachability to nothing. +#[test] +fn schemas_does_not_reach_a_schema_by_a_hash_shaped_alias() { let rows = base_rows(); let selection = Selection { schemas: Some(vec![leaf_a_hash_alias().into()]), ..Selection::default() }; let evaluation = select(&FixtureRowSet, &rows, &selection, 1).unwrap(); - let mut ids: Vec<&str> = evaluation.rows.iter().map(Row::record_key).collect(); - ids.sort_unstable(); - assert_eq!(ids, vec!["a-eq", "a-lo", "shared-1", "shared-3"], "every leaf_a row, by alias"); + assert!(evaluation.rows.is_empty(), "a hash-shaped alias must not resolve to leaf_a"); } // R-E, at the fast path `matches()` uses directly (the v0 snapshot server's own caller, @@ -1323,16 +1391,29 @@ fn matches_treats_an_empty_but_present_schemas_list_as_matching_nothing() { } #[test] -fn cites_target_resolves_through_the_alias_matcher() { +fn cites_target_resolves_through_the_name_alias_matcher() { let rows = base_rows(); let selection = Selection { - cites: Some(Citation { target: rr(leaf_a_hash_alias(), "a-eq"), role: Some("Design".into()) }), + cites: Some(Citation { target: rr(leaf_a_name_alias(), "a-eq"), role: Some("Design".into()) }), ..Selection::default() }; let evaluation = select(&FixtureRowSet, &rows, &selection, 1).unwrap(); assert_eq!(evaluation.rows.iter().map(Row::record_key).collect::>(), vec!["citer-1"]); } +// R-E, Self's ruling 2026-09-22: a hash-shaped alias resolves to no known schema (see +// schemas_does_not_reach_a_schema_by_a_hash_shaped_alias above), so a cites.target naming one is +// refused at the door (R-E's unmatched-target rule), not silently answered with an empty page. +#[test] +fn cites_target_by_a_hash_shaped_alias_is_refused_as_unmatched() { + let selection = Selection { + cites: Some(Citation { target: rr(leaf_a_hash_alias(), "a-eq"), role: Some("Design".into()) }), + ..Selection::default() + }; + let error = validate(&selection, &FixtureRowSet).expect_err("hash-shaped alias must be refused"); + assert_eq!(error.field, "cites.target.schemaId"); +} + #[test] fn validate_refuses_a_cites_target_schema_that_matches_no_known_schema() { let selection = Selection { @@ -1348,8 +1429,9 @@ fn validate_refuses_a_cites_target_schema_that_matches_no_known_schema() { #[test] fn schema_alias_module_is_reachable_from_the_crate_root() { - assert!(schema_alias::matches(leaf_a_hash_alias(), leaf_a())); - assert!(!schema_alias::matches(leaf_a_hash_alias(), leaf_b())); + assert!(schema_alias::matches(leaf_a_name_alias(), leaf_a(), leaf_a_name())); + assert!(!schema_alias::matches(leaf_a_name_alias(), leaf_a(), leaf_b_name())); + assert!(!schema_alias::matches(leaf_a_hash_alias(), leaf_a(), leaf_a_name())); } // ------------------------------------------------------------------------------------------