fix(import): единая идентичность внешних URI (#96)
Единая transport-canonical идентичность внешних документов; normalizer v6 с immutable historical replay; matrix 1.0.4 / corpus 1.0.5. PR CI run840 success, локальная приёмка и independent review выполнены. Co-authored-by: bsodfather <bsodfather@gmail.com>
This commit was merged in pull request #96.
This commit is contained in:
1 parent
178093e81b
commit
1b6db09bd1
22 files changed
+1669
-353
No files matched your search
@@ -91,3 +91,173 @@ async fn exact_v5_contract_replays_saved_preview_without_source_locations() {
|
||||
.unwrap();
|
||||
assert_eq!(completed.status, ImportJobStatus::Completed);
|
||||
}
|
||||
|
||||
// Deterministic baseline source for the v5/v6 replay characterization. It uses
|
||||
// a local reference so the preview is self-contained (no external dependency
|
||||
// or ephemeral fixture port) while still exercising the reference graph.
|
||||
const URI_PREVIEW_DOCUMENT: &str = r#"
|
||||
openapi: 3.1.0
|
||||
info: { title: URI preview parity, version: '1' }
|
||||
servers: [{ url: https://api.example.test }]
|
||||
paths:
|
||||
/items:
|
||||
get:
|
||||
operationId: listItems
|
||||
responses:
|
||||
'200':
|
||||
description: ok
|
||||
content: { application/json: { schema: { $ref: '#/components/schemas/Item' } } }
|
||||
components:
|
||||
schemas:
|
||||
Item: { type: object, required: [id], properties: { id: { type: string } } }
|
||||
"#;
|
||||
|
||||
fn uri_preview_upload() -> OpenApiUpload {
|
||||
OpenApiUpload {
|
||||
bytes: URI_PREVIEW_DOCUMENT.as_bytes().to_vec(),
|
||||
mime_type: "application/yaml".to_owned(),
|
||||
locale: OpenApiUploadLocale::En,
|
||||
}
|
||||
}
|
||||
|
||||
fn v5_v6_fixture_path() -> std::path::PathBuf {
|
||||
std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("tests/integration/openapi_import/fixtures/v5-v6-uri-preview.json")
|
||||
}
|
||||
|
||||
// AC-4 (history): a preview persisted under the historical (v5, v6) contract
|
||||
// must replay unchanged, and a new preview of the same source must use the
|
||||
// current contract. Captured from baseline execution before the URI change.
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn v5_v6_uri_preview_replays_unchanged_and_new_preview_uses_current_contract() {
|
||||
let fixture_text = std::fs::read_to_string(v5_v6_fixture_path())
|
||||
.expect("baseline v5/v6 URI preview fixture must be captured before the change");
|
||||
let fixture: serde_json::Value = serde_json::from_str(&fixture_text).unwrap();
|
||||
assert_eq!(
|
||||
fixture["normalization"]["normalizer_version"],
|
||||
serde_json::json!("normalized-ir-v5")
|
||||
);
|
||||
assert_eq!(
|
||||
fixture["normalization"]["projection_version"],
|
||||
serde_json::json!("preview-v6")
|
||||
);
|
||||
let fixture_preview = fixture["preview"].clone();
|
||||
let fixture_digest = fixture["preview_digest"].clone();
|
||||
|
||||
let registry = test_registry().await;
|
||||
let service = test_service(
|
||||
registry.clone(),
|
||||
test_storage_root("openapi_import_v5_v6_replay"),
|
||||
test_auth_settings(),
|
||||
test_secret_crypto(),
|
||||
);
|
||||
let workspace_id = WorkspaceId::new("ws_default");
|
||||
|
||||
// A current preview of the same bytes must use the current contract.
|
||||
let fresh = service
|
||||
.preview_openapi_import(&workspace_id, uri_preview_upload())
|
||||
.await
|
||||
.unwrap();
|
||||
let job_id: crank_registry::ImportJobId = fresh.job_id.as_str().into();
|
||||
let fresh_job = registry
|
||||
.get_import_job(&workspace_id, &job_id)
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
fresh_job.preview_payload["source"]["digest"], fixture["source"]["digest"],
|
||||
"fixture must refer to the exact captured source bytes"
|
||||
);
|
||||
assert_eq!(
|
||||
fresh_job.preview_payload["normalization"]["normalizer_version"],
|
||||
serde_json::json!(crank_import::rest::NORMALIZER_VERSION)
|
||||
);
|
||||
assert_eq!(
|
||||
fresh_job.preview_payload["normalization"]["projection_version"],
|
||||
serde_json::json!(crank_import::rest::PROJECTION_VERSION)
|
||||
);
|
||||
|
||||
// Bind the historical payload to this run's freshly registered source blob.
|
||||
let mut payload = fixture.clone();
|
||||
payload["source"]["source_id"] = fresh_job.preview_payload["source"]["source_id"].clone();
|
||||
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 /items".to_owned()],
|
||||
server_url: None,
|
||||
conflict_mode: "skip".to_owned(),
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(result.created.len(), 1);
|
||||
|
||||
// The historical preview is replayed from its saved projection, never
|
||||
// recomputed under the current normalizer.
|
||||
let completed = registry
|
||||
.get_import_job(&workspace_id, &job_id)
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
assert_eq!(completed.status, ImportJobStatus::Completed);
|
||||
assert_eq!(completed.preview_payload["preview"], fixture_preview);
|
||||
assert_eq!(
|
||||
completed.preview_payload["normalization"]["normalizer_version"],
|
||||
serde_json::json!("normalized-ir-v5")
|
||||
);
|
||||
assert_eq!(
|
||||
completed.preview_payload["normalization"]["projection_version"],
|
||||
serde_json::json!("preview-v6")
|
||||
);
|
||||
assert_eq!(completed.preview_payload["preview_digest"], fixture_digest);
|
||||
}
|
||||
|
||||
// AC-4 (version RED): a fresh preview of the fixture source must be stamped with
|
||||
// the approved v6 normalizer contract. This is the version RED, distinct from
|
||||
// the URI transport RED: it pins the exact approved literals instead of
|
||||
// following the current `NORMALIZER_VERSION`/`PROJECTION_VERSION` constants,
|
||||
// which do not by themselves prove the approved v6 value. Deliberately no
|
||||
// if-current branch and no skip: the assertion is unconditional and is expected
|
||||
// to fail until the implementation bumps the normalizer to `normalized-ir-v6`.
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn fresh_preview_matches_approved_v6_normalizer_contract() {
|
||||
let registry = test_registry().await;
|
||||
let service = test_service(
|
||||
registry.clone(),
|
||||
test_storage_root("openapi_import_v5_v6_version_contract"),
|
||||
test_auth_settings(),
|
||||
test_secret_crypto(),
|
||||
);
|
||||
let workspace_id = WorkspaceId::new("ws_default");
|
||||
let fresh = service
|
||||
.preview_openapi_import(&workspace_id, uri_preview_upload())
|
||||
.await
|
||||
.unwrap();
|
||||
let job_id: crank_registry::ImportJobId = fresh.job_id.as_str().into();
|
||||
let fresh_job = registry
|
||||
.get_import_job(&workspace_id, &job_id)
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
fresh_job.preview_payload["normalization"]["normalizer_version"],
|
||||
serde_json::json!("normalized-ir-v6"),
|
||||
"approved normalizer contract is normalized-ir-v6"
|
||||
);
|
||||
assert_eq!(
|
||||
fresh_job.preview_payload["normalization"]["projection_version"],
|
||||
serde_json::json!("preview-v6"),
|
||||
"approved projection contract is preview-v6"
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user