story 2-12-preview-partial-mode: implemented and reviewed via bmad-loop
This commit is contained in:
1 parent
d1ba0bd0e4
commit
ab35d67177
56 files changed
+5801
-376
No files matched your search
@@ -0,0 +1,142 @@
|
||||
use super::*;
|
||||
|
||||
use admin_api::service::OpenApiImportPlanCreatePayload;
|
||||
use std::fmt::Write as _;
|
||||
|
||||
const OPERATION_COUNT: usize = 2_000;
|
||||
const MAX_UPLOAD_BYTES: usize = 256 * 1024;
|
||||
const MAX_STORED_PLAN_BYTES: usize = 16 * 1024 * 1024;
|
||||
|
||||
fn large_openapi_document() -> String {
|
||||
let mut document = String::from(
|
||||
"openapi: 3.0.3\n\
|
||||
info: { title: Large preview, version: '1' }\n\
|
||||
servers: [{ url: 'https://api.example.test' }]\n\
|
||||
paths:\n",
|
||||
);
|
||||
for index in 0..OPERATION_COUNT {
|
||||
writeln!(
|
||||
document,
|
||||
" /p{index:04}:\n get:\n operationId: o{index:04}\n responses: {{ '200': {{ description: ok }} }}"
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
document
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn previews_and_plans_two_thousand_operations_without_catalog_mutation() {
|
||||
let registry = test_registry().await;
|
||||
let service = test_service(
|
||||
registry.clone(),
|
||||
test_storage_root("openapi_large_preview"),
|
||||
test_auth_settings(),
|
||||
test_secret_crypto(),
|
||||
);
|
||||
let workspace_id = WorkspaceId::new("ws_default");
|
||||
let document = large_openapi_document();
|
||||
assert!(
|
||||
document.len() <= MAX_UPLOAD_BYTES,
|
||||
"generated document is {} bytes, over the 256 KiB upload limit",
|
||||
document.len()
|
||||
);
|
||||
|
||||
let preview = service
|
||||
.preview_openapi_import(
|
||||
&workspace_id,
|
||||
OpenApiUpload {
|
||||
bytes: document.into_bytes(),
|
||||
mime_type: "application/yaml".to_owned(),
|
||||
locale: OpenApiUploadLocale::En,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.expect("valid 2,000-operation OpenAPI document should preview");
|
||||
let preview_candidates = preview
|
||||
.preview
|
||||
.groups
|
||||
.iter()
|
||||
.flat_map(|group| &group.operations)
|
||||
.collect::<Vec<_>>();
|
||||
assert_eq!(preview_candidates.len(), OPERATION_COUNT);
|
||||
assert_eq!(preview_candidates[0].key, "GET /p0000");
|
||||
assert_eq!(preview_candidates[OPERATION_COUNT - 1].key, "GET /p1999");
|
||||
assert!(preview_candidates.iter().all(|candidate| {
|
||||
candidate.status == "actionable"
|
||||
&& candidate.method == crank_core::HttpMethod::Get
|
||||
&& candidate.path.starts_with("/p")
|
||||
}));
|
||||
|
||||
let job_id: crank_registry::ImportJobId = preview.job_id.as_str().into();
|
||||
let plan = service
|
||||
.create_openapi_import_plan(
|
||||
&workspace_id,
|
||||
&job_id,
|
||||
OpenApiImportPlanCreatePayload {
|
||||
selection_mode: "full".to_owned(),
|
||||
selected_operation_keys: Vec::new(),
|
||||
server_url: None,
|
||||
decisions: Vec::new(),
|
||||
},
|
||||
)
|
||||
.await
|
||||
.expect("full plan should include all 2,000 operations");
|
||||
assert_eq!(plan.counts.selected, OPERATION_COUNT);
|
||||
assert_eq!(plan.counts.actionable, OPERATION_COUNT);
|
||||
assert_eq!(plan.counts.excluded, 0);
|
||||
assert_eq!(plan.counts.blocked, 0);
|
||||
assert_eq!(plan.candidates.len(), OPERATION_COUNT);
|
||||
assert!(plan.candidates.iter().all(|candidate| {
|
||||
candidate.state == "actionable" && candidate.action.as_deref() == Some("create")
|
||||
}));
|
||||
|
||||
let plan_id = plan.plan_reference.as_str().into();
|
||||
let stored = registry
|
||||
.get_import_plan(&workspace_id, &plan_id)
|
||||
.await
|
||||
.unwrap()
|
||||
.expect("full plan should be persisted and readable");
|
||||
let stored_payload_bytes = serde_json::to_vec(&stored.payload).unwrap().len();
|
||||
assert!(
|
||||
stored_payload_bytes <= MAX_STORED_PLAN_BYTES,
|
||||
"stored plan payload is {stored_payload_bytes} bytes, over 16 MiB"
|
||||
);
|
||||
let stored_candidates = stored.payload["candidates"]
|
||||
.as_array()
|
||||
.expect("stored plan contains its full candidate list");
|
||||
assert_eq!(stored_candidates.len(), OPERATION_COUNT);
|
||||
assert!(stored_candidates.iter().all(|candidate| {
|
||||
candidate["state"] == "actionable" && candidate["decision"]["action"] == "create"
|
||||
}));
|
||||
assert_eq!(stored.payload["counts"]["selected"], OPERATION_COUNT);
|
||||
assert_eq!(stored.payload["counts"]["actionable"], OPERATION_COUNT);
|
||||
|
||||
let revalidated = service
|
||||
.revalidate_openapi_import_plan(&workspace_id, &plan_id)
|
||||
.await
|
||||
.expect("revalidating the unchanged plan should be read-only and current");
|
||||
assert_eq!(revalidated.revalidation_status, "current");
|
||||
assert!(!revalidated.revalidation_required);
|
||||
assert_eq!(revalidated.counts.selected, OPERATION_COUNT);
|
||||
assert_eq!(revalidated.counts.actionable, OPERATION_COUNT);
|
||||
assert_eq!(revalidated.counts.excluded, 0);
|
||||
assert_eq!(revalidated.counts.blocked, 0);
|
||||
assert_eq!(revalidated.candidates.len(), OPERATION_COUNT);
|
||||
|
||||
let (operations, operation_versions) = sqlx::query_as::<_, (i64, i64)>(
|
||||
"select
|
||||
(select count(*) from operations where workspace_id = $1),
|
||||
(select count(*) from operation_versions ov
|
||||
join operations o on o.id = ov.operation_id where o.workspace_id = $1)",
|
||||
)
|
||||
.bind(workspace_id.as_str())
|
||||
.fetch_one(registry.pool())
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(operations, 0, "preview and plan must not create operations");
|
||||
assert_eq!(
|
||||
operation_versions, 0,
|
||||
"preview and plan must not create operation versions"
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user