From fb96348d0244b4b0c3463ee6e7ed9bb7cb79f072 Mon Sep 17 00:00:00 2001 From: Weksa Date: Sat, 14 Nov 2026 04:07:48 +0000 Subject: [PATCH] Pin V18: validate cases and the encoder-shaped request through admit Co-Authored-By: Claude Sonnet 5.5 --- crates/weksa/tests/context.rs | 35 +++++++++++++++++++++++++ crates/weksa/tests/validate.rs | 47 ++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/crates/weksa/tests/context.rs b/crates/weksa/tests/context.rs index d2550de..a8993fc 100644 --- a/crates/weksa/tests/context.rs +++ b/crates/weksa/tests/context.rs @@ -593,6 +593,41 @@ mod lowering { assert!(Prompt::lower(&read, &item, &away(), "en-US", &inv, &held, &empty).is_ok()); } + /// The packet the encoder emits for a request: frame:3, no consent, source + /// ModelDecomposition. Admission refuses it, so no lowering view exists. + #[test] + fn an_encoder_request_never_reaches_a_lowerer() { + let cast = InventoryStore::open(&data("interlingua/inventory.cc")).unwrap(); + let entities = EntityStore::open(&data("entity/entity.cc")).unwrap(); + let corpus = CorpusStore::open(&data("corpus/corpus.cc")).unwrap(); + let dir = tempfile::tempdir().unwrap(); + let mut store = PacketStore::open(&dir.path().join("p.cc")).unwrap(); + let mut packet = proof_packet(); + packet.provenance.source = weksa::packet::ProvenanceSource::ModelDecomposition; + packet.predications[0].frame = weksa::InvId::parse("frame:3").unwrap(); + match store.admit(packet.clone(), &cast, &corpus, &entities) { + Err(weksa::StoreError::Invalid(r)) => assert_eq!( + r, + vec![weksa::Refusal::V18RequestWithoutConsent { + predication: weksa::packet::NodeId::parse("n4").unwrap() + }] + ), + other => panic!("expected V18, got {:?}", other.map(|_| ())), + } + // Not blanket: telemetry that records the consent admits and lowers. + packet.provenance.source = weksa::packet::ProvenanceSource::GameTelemetry; + packet.discourse.addressee_consent = Some(weksa::packet::NodeId::parse("n4").unwrap()); + drop(store); + let view = admitted(packet, &cast, "corpus/corpus.cc", &entities); + let item = CorpusItemId::parse("item:nibu:1").unwrap(); + let held = Held(vec![nibu(&[("en-US", &["Nibu"])])]); + let empty = weksa::Ontology::empty(); + assert!( + Prompt::lower(&view, &item, &away(), "en-US", &cast.inventory().unwrap(), &held, &empty) + .is_ok() + ); + } + fn dao(index: usize) -> (LoweringInput, Inventory, EntityStore, CorpusItemId) { let inv = InventoryStore::open(&data("daodejing/inventory.cc")).unwrap(); let entities = EntityStore::open(&data("daodejing/entity.cc")).unwrap(); diff --git a/crates/weksa/tests/validate.rs b/crates/weksa/tests/validate.rs index b46cd85..057e92f 100644 --- a/crates/weksa/tests/validate.rs +++ b/crates/weksa/tests/validate.rs @@ -740,6 +740,53 @@ fn a_source_that_only_read_wording_cannot_set_consent() { } } +// V18: a request frame is licensed by the packet's own consent record. + +/// The committed inventory, where `frame:3` is `request_intervention`. +fn cast_refusals(p: &Packet) -> Vec { + let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../../data/interlingua/inventory.cc"); + let inv = weksa::InventoryStore::open(&path).unwrap().inventory().unwrap(); + validate(p, &inv).err().unwrap_or_default() +} + +fn requesting() -> Packet { + let mut p = proof_packet(); + p.predications[0].frame = iv("frame:3"); + p.discourse.addressee_consent = Some(nd("n4")); + p +} + +#[test] +fn a_request_frame_needs_consent_naming_its_predication() { + assert_eq!(cast_refusals(&requesting()), vec![]); + let mut p = requesting(); + p.discourse.addressee_consent = None; + assert_eq!( + cast_refusals(&p), + vec![Refusal::V18RequestWithoutConsent { predication: nd("n4") }] + ); + p.discourse.addressee_consent = Some(nd("n5")); + assert_eq!( + cast_refusals(&p), + vec![Refusal::V18RequestWithoutConsent { predication: nd("n4") }] + ); + let mut p = requesting(); + p.provenance.source = ProvenanceSource::GameTelemetry; + assert_eq!(cast_refusals(&p), vec![]); +} + +#[test] +fn model_source_consent_is_v15_alone() { + let mut p = requesting(); + p.provenance.source = ProvenanceSource::ModelDecomposition; + assert_eq!( + cast_refusals(&p), + vec![Refusal::V15ConsentSource { + source: ProvenanceSource::ModelDecomposition + }] + ); +} + // V17: the addressee is someone spoken to, a referent. #[test]