Validate projected requests against their tagged schema variants

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
DottaandPaperclip committed 2026-09-28 12:40:48 -05:00
1 parent afb6985c7e
commit 325a4d1917
1 file changed
+22 -5
@@ -23,6 +23,24 @@ fn project(event: AcpxProviderStateEvent) -> Vec<NormalizedProviderEvent> {
project_acpx_state_event(&context(), &event).unwrap()
}
fn canonical_request_branch(request_kind: &str, request_type: &str) -> Value {
let schema: Value = serde_json::from_str(include_str!(
"../../../../protocol/schemas/request.schema.json"
))
.unwrap();
schema["oneOf"]
.as_array()
.unwrap()
.iter()
.find(|branch| {
branch["properties"]["schema"]["const"] == "paperclip.runtime_request.v2"
&& branch["properties"]["requestKind"]["const"] == request_kind
&& branch["properties"]["type"]["const"] == request_type
})
.expect("canonical v2 request branch")
.clone()
}
fn reduced_semantic_result(
call_id: &str,
operation_id: &str,
@@ -378,6 +396,9 @@ fn projects_only_the_permission_choices_offered_by_the_provider() {
details: json!({"choices":[{"key":"accept","label":"Allow once"},{"key":"cancel","label":"Cancel"}]}),
});
assert_eq!(events[0].event_type, "runtime_request.created");
let schema = canonical_request_branch("permission_approval", "permission");
let validator = jsonschema::validator_for(&schema).unwrap();
assert!(validator.is_valid(&events[0].payload["request"]));
assert_eq!(
events[0].payload["request"]["requestKind"],
"permission_approval"
@@ -528,11 +549,7 @@ fn deterministically_projects_bounded_upstream_request_ids() {
#[test]
fn runtime_request_projection_preserves_durable_identity_boundaries() {
let canonical_request_schema: Value = serde_json::from_str(include_str!(
"../../../../protocol/schemas/request.schema.json"
))
.unwrap();
let mut runtime_request_schema = canonical_request_schema["oneOf"][0].clone();
let mut runtime_request_schema = canonical_request_branch("runtime", "input");
// This test owns identity projection. The question-set validator has its
// own coverage, so replace its remote reference with an unconstrained
// local schema before compiling the canonical runtime-request branch.