fix(import): align external URI identity with HTTP transport
CI / Rust Checks (pull_request) Successful in 25m55s
CI / UI Checks (pull_request) Successful in 5s
CI / Community Image Smoke (pull_request) Successful in 7m42s
CI / Frontend E2E (pull_request) Successful in 12m39s
CI / Deploy (pull_request) Skipped

Share pure URL canonicalization between snapshot materialization and resolution. Preserve historical v5/v6 previews while advancing normalization to v6 and the support matrix to 1.0.4. Cover encoded-dot paths, apostrophe queries, relative children, and no-refetch apply/replay.
This commit is contained in:
bsodfather committed 2026-10-11 08:33:43 +03:00
1 parent 178093e81b
commit 9e9c326c3e
22 files changed
+1669 -353

No files matched your search

+88 -61
View File
@@ -31,7 +31,7 @@ fn ac_1_support_matrix_rows_have_exact_construct_contracts() {
let matrix_text = fs::read_to_string(tests_root().join("support-matrix.yaml"))
.expect("support matrix exists");
let matrix: serde_yaml::Value = serde_yaml::from_str(&matrix_text).expect("valid YAML");
assert_eq!(matrix["matrix_version"].as_str(), Some("1.0.3"));
assert_eq!(matrix["matrix_version"].as_str(), Some("1.0.4"));
assert!(
matrix["compatibility_impact"]
.as_str()
@@ -696,73 +696,100 @@ fn ac_1_support_matrix_rows_have_exact_construct_contracts() {
row["specification_version"] == version && row["construct_id"] == construct
})
.unwrap();
let reference = if external {
"https://schemas.example.test/root.yaml#/Item"
} else if version == "Swagger 2.0" {
// The allowlisted-external row must exercise the same transport
// canonicalization the materializer keys snapshots with. The
// expected keys below are static literals, independent of the
// production `canonical_external_document_uri` helper: a
// percent-encoded dot segment collapses to its parent path and an
// apostrophe in the query is percent-encoded (`%27`).
let external_document = "Item: { type: object, properties: { id: { type: string } } }";
let external_variants: [(&str, &str); 3] = [
(
"https://schemas.example.test/root.yaml#/Item",
"https://schemas.example.test/root.yaml",
),
(
"https://schemas.example.test/a/%2e%2e/root.yaml#/Item",
"https://schemas.example.test/root.yaml",
),
(
"https://schemas.example.test/schema.json?filter='x'#/Item",
"https://schemas.example.test/schema.json?filter=%27x%27",
),
];
let local_reference = if version == "Swagger 2.0" {
"#/definitions/Item"
} else {
"#/components/schemas/Item"
};
let schema = json!({"$ref":reference});
let response = if version == "Swagger 2.0" {
json!({"description":"ok","schema":schema})
let variants = if external {
external_variants
.iter()
.map(|(reference, canonical_uri)| (*reference, Some(*canonical_uri)))
.collect::<Vec<_>>()
} else {
json!({"description":"ok","content":{"application/json":{"schema":schema}}})
vec![(local_reference, None)]
};
let probe = if version == "Swagger 2.0" {
let mut root = json!({"swagger":"2.0","info":{"title":"Reference probe","version":"1"},"paths":{"/probe":{"get":{"operationId":"referenceProbe","responses":{"200":response}}}}});
if !external {
root["definitions"] =
json!({"Item":{"type":"object","properties":{"id":{"type":"string"}}}});
}
root
} else {
let mut root = json!({"openapi":if version == "OpenAPI 3.0" {"3.0.3"} else {"3.1.0"},
"info":{"title":"Reference probe","version":"1"},"servers":[{"url":"https://matrix.example.test"}],"paths":{"/probe":{"get":{"operationId":"referenceProbe","responses":{"200":response}}}}});
if !external {
root["components"] = json!({"schemas":{"Item":{"type":"object","properties":{"id":{"type":"string"}}}}});
}
root
};
let source = serde_json::to_string(&probe).unwrap();
let ir = if external {
let external_source =
"Item: { type: object, properties: { id: { type: string } } }";
let snapshot = crank_import::rest::ExternalDocumentSnapshot {
canonical_uri: "https://schemas.example.test/root.yaml".to_owned(),
digest: SourceDigest::parse(hex(external_source.as_bytes())).unwrap(),
document: external_source.to_owned(),
for (reference, canonical_uri) in variants {
let schema = json!({"$ref":reference});
let response = if version == "Swagger 2.0" {
json!({"description":"ok","schema":schema})
} else {
json!({"description":"ok","content":{"application/json":{"schema":schema}}})
};
let digest = SourceDigest::parse(hex(source.as_bytes())).unwrap();
normalize_verified_bundle(
&source,
digest,
&[snapshot],
&NormalizationConfig::default(),
)
.unwrap()
} else {
normalize(&source).unwrap()
};
validate_normalized_ir(&ir).unwrap();
assert_eq!(row["status"], "supported");
assert!(
!ir.reference_graph.edges.is_empty(),
"{version} {construct} did not resolve through a source-backed edge"
);
assert!(
ir.unresolved_references.is_empty(),
"{version} {construct} remains unresolved"
);
assert!(
matches!(
ir.operations[0].response_variants[0].schema.as_ref().map(|schema| &schema.kind),
Some(NormalizedSchemaKind::Object { properties, .. }) if properties.contains_key("id")
),
"{version} {construct} resolved schema was not projected into the operation"
);
assert_actionable(&ir, &format!("{version} {construct}"));
assert_eq!(row["expected_finding"], "none");
let probe = if version == "Swagger 2.0" {
let mut root = json!({"swagger":"2.0","info":{"title":"Reference probe","version":"1"},"paths":{"/probe":{"get":{"operationId":"referenceProbe","responses":{"200":response}}}}});
if !external {
root["definitions"] =
json!({"Item":{"type":"object","properties":{"id":{"type":"string"}}}});
}
root
} else {
let mut root = json!({"openapi":if version == "OpenAPI 3.0" {"3.0.3"} else {"3.1.0"},
"info":{"title":"Reference probe","version":"1"},"servers":[{"url":"https://matrix.example.test"}],"paths":{"/probe":{"get":{"operationId":"referenceProbe","responses":{"200":response}}}}});
if !external {
root["components"] = json!({"schemas":{"Item":{"type":"object","properties":{"id":{"type":"string"}}}}});
}
root
};
let source = serde_json::to_string(&probe).unwrap();
let ir = if let Some(canonical_uri) = canonical_uri {
let snapshot = crank_import::rest::ExternalDocumentSnapshot {
canonical_uri: canonical_uri.to_owned(),
digest: SourceDigest::parse(hex(external_document.as_bytes())).unwrap(),
document: external_document.to_owned(),
};
let digest = SourceDigest::parse(hex(source.as_bytes())).unwrap();
normalize_verified_bundle(
&source,
digest,
&[snapshot],
&NormalizationConfig::default(),
)
.unwrap()
} else {
normalize(&source).unwrap()
};
validate_normalized_ir(&ir).unwrap();
assert_eq!(row["status"], "supported");
assert!(
!ir.reference_graph.edges.is_empty(),
"{version} {construct} did not resolve through a source-backed edge ({reference})"
);
assert!(
ir.unresolved_references.is_empty(),
"{version} {construct} remains unresolved ({reference})"
);
assert!(
matches!(
ir.operations[0].response_variants[0].schema.as_ref().map(|schema| &schema.kind),
Some(NormalizedSchemaKind::Object { properties, .. }) if properties.contains_key("id")
),
"{version} {construct} resolved schema was not projected into the operation ({reference})"
);
assert_actionable(&ir, &format!("{version} {construct} {reference}"));
assert_eq!(row["expected_finding"], "none");
}
probed(construct);
}
for code in 200..300 {