94 lines
3.3 KiB
Rust
94 lines
3.3 KiB
Rust
use super::*;
|
|
|
|
#[tokio::test]
|
|
#[serial]
|
|
async fn exact_v5_contract_replays_saved_preview_without_source_locations() {
|
|
use sha2::{Digest, Sha256};
|
|
|
|
fn remove_source_locations(value: &mut serde_json::Value) {
|
|
match value {
|
|
serde_json::Value::Object(object) => {
|
|
object.remove("source_location");
|
|
for value in object.values_mut() {
|
|
remove_source_locations(value);
|
|
}
|
|
}
|
|
serde_json::Value::Array(values) => {
|
|
for value in values {
|
|
remove_source_locations(value);
|
|
}
|
|
}
|
|
_ => {}
|
|
}
|
|
}
|
|
|
|
let registry = test_registry().await;
|
|
let service = test_service(
|
|
registry.clone(),
|
|
test_storage_root("openapi_import_v5_compatibility"),
|
|
test_auth_settings(),
|
|
test_secret_crypto(),
|
|
);
|
|
let workspace_id = WorkspaceId::new("ws_default");
|
|
let preview = service
|
|
.preview_openapi_import(&workspace_id, openapi_upload())
|
|
.await
|
|
.unwrap();
|
|
let job_id: crank_registry::ImportJobId = preview.job_id.as_str().into();
|
|
let mut payload = registry
|
|
.get_import_job(&workspace_id, &job_id)
|
|
.await
|
|
.unwrap()
|
|
.unwrap()
|
|
.preview_payload;
|
|
|
|
// A preview persisted under v5 has the then-current projection and digest,
|
|
// without the source_location fields added by v6.
|
|
let persisted_preview = payload
|
|
.get_mut("preview")
|
|
.expect("newly saved job includes its preview");
|
|
assert!(persisted_preview.to_string().contains("source_location"));
|
|
remove_source_locations(persisted_preview);
|
|
let digest = format!(
|
|
"{:x}",
|
|
Sha256::digest(serde_json::to_vec(persisted_preview).unwrap())
|
|
);
|
|
payload["normalization"]["normalizer_version"] = "normalized-ir-v5".into();
|
|
payload["normalization"]["projection_version"] = "preview-v5".into();
|
|
payload["normalization"]["config"]["normalizer_version"] = "normalized-ir-v5".into();
|
|
payload["normalization"]["config"]["projection_version"] = "preview-v5".into();
|
|
payload["preview_digest"] = digest.into();
|
|
// If v5 is reparsed, this deliberately absent dependency makes the replay fail.
|
|
payload["dependency_snapshots"] = serde_json::json!([{
|
|
"source_id": "src_openapi_dep_v5_must_not_be_read",
|
|
"digest": format!("sha256:{}", "0".repeat(64)),
|
|
"canonical_uri": "https://schemas.example.test/v5.yaml"
|
|
}]);
|
|
sqlx::query("update import_jobs set preview_payload = $1::jsonb where id = $2")
|
|
.bind(serde_json::to_string(&payload).unwrap())
|
|
.bind(job_id.as_str())
|
|
.execute(registry.pool())
|
|
.await
|
|
.unwrap();
|
|
|
|
let result = service
|
|
.create_openapi_import(
|
|
&workspace_id,
|
|
&job_id,
|
|
OpenApiImportCreatePayload {
|
|
selected_operation_keys: vec!["GET /v2/latest".to_owned()],
|
|
server_url: Some("https://api.frankfurter.dev".to_owned()),
|
|
conflict_mode: "skip".to_owned(),
|
|
},
|
|
)
|
|
.await
|
|
.unwrap();
|
|
assert_eq!(result.created.len(), 1);
|
|
let completed = registry
|
|
.get_import_job(&workspace_id, &job_id)
|
|
.await
|
|
.unwrap()
|
|
.unwrap();
|
|
assert_eq!(completed.status, ImportJobStatus::Completed);
|
|
}
|