feat(import): preserve supported HTTP contracts

This commit is contained in:
bsodfather committed 2026-09-13 03:30:31 +03:00
1 parent 083974c27f
commit f8ee7c9bfe
87 files changed
+7496 -534

No files matched your search

@@ -10,6 +10,7 @@ use super::common::{
};
mod external_references;
mod http_contract;
const OPENAPI3: &str = r#"
openapi: 3.0.3
@@ -77,11 +78,11 @@ async fn previews_openapi_and_creates_draft_operations() {
assert_eq!(preview_job.status, ImportJobStatus::Pending);
assert_eq!(
preview_job.preview_payload["normalization"]["normalizer_version"],
"normalized-ir-v3"
"normalized-ir-v4"
);
assert_eq!(
preview_job.preview_payload["normalization"]["projection_version"],
"preview-v3"
"preview-v4"
);
assert!(preview_job.preview_payload["normalization"]["ir_fingerprint"].is_string());
@@ -451,6 +452,8 @@ async fn apply_fails_closed_for_each_normalization_contract_field_and_digest_sha
#[tokio::test]
#[serial]
async fn legacy_job_without_normalization_contract_replays_until_expiry() {
use sha2::{Digest, Sha256};
let registry = test_registry().await;
let service = test_service(
registry.clone(),
@@ -464,10 +467,22 @@ async fn legacy_job_without_normalization_contract_replays_until_expiry() {
.await
.unwrap();
let job_id: crank_registry::ImportJobId = preview.job_id.as_str().into();
// A legacy job stores the legacy projection and its matching fingerprint,
// not a current projection with only the version metadata removed.
let legacy_preview =
serde_json::to_value(crank_import::rest::preview_document_legacy_v1(OPENAPI3).unwrap())
.unwrap();
let legacy_digest = format!(
"{:x}",
Sha256::digest(serde_json::to_vec(&legacy_preview).unwrap())
);
sqlx::query(
"update import_jobs set preview_payload = preview_payload - 'normalization' where id = $1",
"update import_jobs set preview_payload = (preview_payload - 'normalization') || \
jsonb_build_object('preview', $2::jsonb, 'preview_digest', $3::text) where id = $1",
)
.bind(job_id.as_str())
.bind(legacy_preview)
.bind(legacy_digest)
.execute(registry.pool())
.await
.unwrap();