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
@@ -21,5 +21,6 @@ pub(super) fn invalid_path_item() -> ImportFinding {
|
||||
severity: ImportFindingSeverity::Error,
|
||||
message: "Path Item имеет неверную структуру и не был интерпретирован.".to_owned(),
|
||||
operation_key: None,
|
||||
source_location: None,
|
||||
}
|
||||
}
|
||||
@@ -127,6 +127,8 @@ pub fn candidate_from_operation(
|
||||
key: operation.key.clone(),
|
||||
method: operation.method,
|
||||
path: operation.path.clone(),
|
||||
status: String::new(),
|
||||
source_location: operation.source_location.clone(),
|
||||
security_requirements: Default::default(),
|
||||
security_schemes: BTreeMap::new(),
|
||||
operation_id: operation.operation_id.clone(),
|
||||
|
||||
@@ -27,10 +27,10 @@ mod swagger2_findings;
|
||||
|
||||
pub use model::{
|
||||
ExternalDocumentSnapshot, HISTORICAL_NORMALIZER_VERSION, HISTORICAL_PROJECTION_VERSION,
|
||||
ImportFinding, ImportFindingSeverity, ImportGroupPreview, ImportOperationCandidate,
|
||||
ImportPreview, ImportSourcePreview, NORMALIZER_VERSION, NormalizationConfig, NormalizedFinding,
|
||||
NormalizedIr, NormalizedOperation, NormalizedParameter, NormalizedReference,
|
||||
NormalizedRequestBodyVariant, NormalizedResponseVariant, NormalizedSchema,
|
||||
ImportFinding, ImportFindingSeverity, ImportGroupPreview, ImportNameConflict,
|
||||
ImportOperationCandidate, ImportPreview, ImportSourcePreview, NORMALIZER_VERSION,
|
||||
NormalizationConfig, NormalizedFinding, NormalizedIr, NormalizedOperation, NormalizedParameter,
|
||||
NormalizedReference, NormalizedRequestBodyVariant, NormalizedResponseVariant, NormalizedSchema,
|
||||
NormalizedSchemaConstraints, NormalizedSchemaKind, NormalizedSecurityRequirements,
|
||||
NormalizedSecurityScheme, NormalizedSecuritySchemeKind, PROJECTION_VERSION,
|
||||
ResolvedReferenceEdge, ResolvedReferenceGraph, ResolvedReferenceNode, RestImportCandidate,
|
||||
|
||||
@@ -10,7 +10,7 @@ use serde_json::Value;
|
||||
/// deliberately travel with an import job: changing either contract must not
|
||||
/// silently reinterpret a pending preview.
|
||||
pub const NORMALIZER_VERSION: &str = "normalized-ir-v5";
|
||||
pub const PROJECTION_VERSION: &str = "preview-v5";
|
||||
pub const PROJECTION_VERSION: &str = "preview-v6";
|
||||
pub const HISTORICAL_NORMALIZER_VERSION: &str = "normalized-ir-v4";
|
||||
pub const HISTORICAL_PROJECTION_VERSION: &str = "preview-v4";
|
||||
|
||||
@@ -496,6 +496,10 @@ pub struct ImportFinding {
|
||||
pub message: String,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub operation_key: Option<String>,
|
||||
/// RFC 6901 source pointer of the finding. Optional so preview payloads
|
||||
/// persisted before this field was introduced still deserialize.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub source_location: Option<SourceLocation>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
@@ -514,6 +518,17 @@ pub struct ImportPreview {
|
||||
pub groups: Vec<ImportGroupPreview>,
|
||||
#[serde(default)]
|
||||
pub findings: Vec<ImportFinding>,
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub conflicts: Vec<ImportNameConflict>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct ImportNameConflict {
|
||||
pub operation_key: String,
|
||||
pub conflict_type: String,
|
||||
pub proposed_name: String,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub source_location: Option<SourceLocation>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
@@ -528,6 +543,13 @@ pub struct ImportOperationCandidate {
|
||||
pub key: String,
|
||||
pub method: HttpMethod,
|
||||
pub path: String,
|
||||
/// Workspace-aware readiness is attached by the API after immutable replay.
|
||||
#[serde(default, skip_serializing_if = "String::is_empty")]
|
||||
pub status: String,
|
||||
/// RFC 6901 pointer of the source operation. Optional so preview payloads
|
||||
/// persisted before this field was introduced still deserialize.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub source_location: Option<SourceLocation>,
|
||||
#[serde(
|
||||
default,
|
||||
skip_serializing_if = "NormalizedSecurityRequirements::is_empty"
|
||||
@@ -583,6 +605,10 @@ pub struct RestImportOperation {
|
||||
pub key: String,
|
||||
pub method: HttpMethod,
|
||||
pub path: String,
|
||||
/// Authoritative RFC 6901 pointer of the operation when it was produced by
|
||||
/// the normalizer. Parser state only; never persisted.
|
||||
#[serde(skip)]
|
||||
pub source_location: Option<SourceLocation>,
|
||||
#[serde(
|
||||
default,
|
||||
skip_serializing_if = "NormalizedSecurityRequirements::is_empty"
|
||||
|
||||
@@ -23,6 +23,7 @@ pub(super) fn preview_from_ir(ir: &crate::rest::model::NormalizedIr) -> ImportPr
|
||||
severity: finding.severity.clone(),
|
||||
message: finding.message.clone(),
|
||||
operation_key: finding.operation_key.clone(),
|
||||
source_location: Some(finding.location.clone()),
|
||||
})
|
||||
.collect();
|
||||
preview_from_operations(
|
||||
@@ -99,6 +100,7 @@ fn preview_from_operations<'a>(
|
||||
source: source.clone(),
|
||||
groups: groups.into_values().collect(),
|
||||
findings,
|
||||
conflicts: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,6 +109,7 @@ pub(super) fn operation_from_normalized(operation: &NormalizedOperation) -> Rest
|
||||
key: operation.key.clone(),
|
||||
method: operation.method,
|
||||
path: operation.path.clone(),
|
||||
source_location: Some(operation.location.clone()),
|
||||
security_requirements: operation.security_requirements.clone(),
|
||||
operation_id: operation.operation_id.clone(),
|
||||
summary: operation.summary.clone(),
|
||||
@@ -162,6 +165,7 @@ pub(super) fn operation_from_normalized(operation: &NormalizedOperation) -> Rest
|
||||
severity: finding.severity.clone(),
|
||||
message: finding.message.clone(),
|
||||
operation_key: finding.operation_key.clone(),
|
||||
source_location: Some(finding.location.clone()),
|
||||
})
|
||||
.collect(),
|
||||
internal_finding_locations: Vec::new(),
|
||||
|
||||
@@ -170,6 +170,7 @@ fn parse_document_v2(root: &Value) -> Result<RestImportDocument, ImportParseErro
|
||||
key: format!("{} {}", method_name.to_uppercase(), path),
|
||||
method,
|
||||
path: path.clone(),
|
||||
source_location: None,
|
||||
security_requirements,
|
||||
operation_id: operation_value
|
||||
.get("operationId")
|
||||
@@ -280,6 +281,7 @@ pub fn parse_document_legacy_v1(root: &Value) -> Result<RestImportDocument, Impo
|
||||
key: format!("{} {}", method_name.to_uppercase(), path),
|
||||
method,
|
||||
path: path.clone(),
|
||||
source_location: None,
|
||||
security_requirements: Default::default(),
|
||||
operation_id: operation
|
||||
.get("operationId")
|
||||
|
||||
@@ -155,6 +155,8 @@ pub fn candidate_from_operation(
|
||||
key: operation.key.clone(),
|
||||
method: operation.method,
|
||||
path: operation.path.clone(),
|
||||
status: String::new(),
|
||||
source_location: operation.source_location.clone(),
|
||||
security_requirements: operation.security_requirements.clone(),
|
||||
security_schemes: security_schemes.clone(),
|
||||
operation_id: operation.operation_id.clone(),
|
||||
|
||||
@@ -8,6 +8,7 @@ pub fn document_finding(code: &str, message: impl Into<String>) -> ImportFinding
|
||||
severity: ImportFindingSeverity::Warning,
|
||||
message: message.into(),
|
||||
operation_key: None,
|
||||
source_location: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +18,7 @@ pub fn document_blocker(code: &str, message: impl Into<String>) -> ImportFinding
|
||||
severity: ImportFindingSeverity::Error,
|
||||
message: message.into(),
|
||||
operation_key: None,
|
||||
source_location: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +32,7 @@ pub fn operation_finding(
|
||||
severity: ImportFindingSeverity::Warning,
|
||||
message: message.into(),
|
||||
operation_key: Some(operation_key.to_owned()),
|
||||
source_location: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +46,7 @@ pub fn operation_info(
|
||||
severity: ImportFindingSeverity::Info,
|
||||
message: message.into(),
|
||||
operation_key: Some(operation_key.to_owned()),
|
||||
source_location: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,7 +129,7 @@ pub fn operation_recommendations(operation: &RestImportOperation) -> Vec<ImportF
|
||||
),
|
||||
));
|
||||
}
|
||||
findings
|
||||
with_operation_location(findings, operation)
|
||||
}
|
||||
|
||||
pub fn candidate_recommendations(
|
||||
@@ -179,6 +183,18 @@ pub fn candidate_recommendations(
|
||||
));
|
||||
}
|
||||
|
||||
with_operation_location(findings, operation)
|
||||
}
|
||||
|
||||
fn with_operation_location(
|
||||
mut findings: Vec<ImportFinding>,
|
||||
operation: &RestImportOperation,
|
||||
) -> Vec<ImportFinding> {
|
||||
for finding in &mut findings {
|
||||
if finding.source_location.is_none() {
|
||||
finding.source_location = operation.source_location.clone();
|
||||
}
|
||||
}
|
||||
findings
|
||||
}
|
||||
|
||||
|
||||
@@ -169,6 +169,7 @@ fn parse_document_v2(root: &Value) -> Result<RestImportDocument, ImportParseErro
|
||||
key: format!("{} {}", method_name.to_uppercase(), path),
|
||||
method,
|
||||
path: path.clone(),
|
||||
source_location: None,
|
||||
security_requirements,
|
||||
operation_id: operation_value
|
||||
.get("operationId")
|
||||
@@ -281,6 +282,7 @@ pub fn parse_document_legacy_v1(root: &Value) -> Result<RestImportDocument, Impo
|
||||
key: format!("{} {}", method_name.to_uppercase(), path),
|
||||
method,
|
||||
path: path.clone(),
|
||||
source_location: None,
|
||||
security_requirements: Default::default(),
|
||||
operation_id: operation
|
||||
.get("operationId")
|
||||
|
||||
@@ -196,7 +196,16 @@ fn ac_2_manifest_covers_fifty_provenanced_specs_with_exact_expectations() {
|
||||
"corpus fixtures are single-operation exact oracles"
|
||||
);
|
||||
let expected = &document.expected_preview["operations"][0];
|
||||
let actual_candidate = serde_json::to_value(candidates[0]).unwrap();
|
||||
let mut actual_candidate = serde_json::to_value(candidates[0]).unwrap();
|
||||
// Corpus snapshots freeze the pre-location semantic candidate.
|
||||
// Source provenance is covered by dedicated preview assertions.
|
||||
actual_candidate
|
||||
.as_object_mut()
|
||||
.unwrap()
|
||||
.remove("source_location");
|
||||
for finding in actual_candidate["findings"].as_array_mut().unwrap() {
|
||||
finding.as_object_mut().unwrap().remove("source_location");
|
||||
}
|
||||
assert_eq!(
|
||||
actual_candidate,
|
||||
expected["candidate"],
|
||||
@@ -224,13 +233,24 @@ fn ac_2_manifest_covers_fifty_provenanced_specs_with_exact_expectations() {
|
||||
"candidate canonical digest in {}",
|
||||
document.file
|
||||
);
|
||||
let mut actual_preview = serde_json::to_value(&preview).unwrap();
|
||||
for group in actual_preview["groups"].as_array_mut().unwrap() {
|
||||
for candidate in group["operations"].as_array_mut().unwrap() {
|
||||
candidate.as_object_mut().unwrap().remove("source_location");
|
||||
for finding in candidate["findings"].as_array_mut().unwrap() {
|
||||
finding.as_object_mut().unwrap().remove("source_location");
|
||||
}
|
||||
}
|
||||
}
|
||||
for finding in actual_preview["findings"].as_array_mut().unwrap() {
|
||||
finding.as_object_mut().unwrap().remove("source_location");
|
||||
}
|
||||
assert_eq!(
|
||||
hex(canonical_json(&serde_json::to_value(&preview).unwrap())),
|
||||
hex(canonical_json(&actual_preview)),
|
||||
document.expected_preview["canonical_preview_digest"],
|
||||
"preview canonical digest in {}",
|
||||
document.file
|
||||
);
|
||||
let actual_preview = serde_json::to_value(&preview).unwrap();
|
||||
assert_eq!(
|
||||
actual_preview,
|
||||
document.expected_preview["canonical_preview"],
|
||||
|
||||
@@ -96,6 +96,19 @@ definitions:
|
||||
assert_eq!(operation.draft.input_mapping.rules.len(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn historical_preview_without_locations_still_deserializes() {
|
||||
let old = serde_json::to_value(preview_document_legacy_v1(OPENAPI3).unwrap()).unwrap();
|
||||
let replay: crank_import::rest::ImportPreview = serde_json::from_value(old).unwrap();
|
||||
assert!(replay.groups[0].operations[0].source_location.is_none());
|
||||
assert!(
|
||||
replay.groups[0].operations[0]
|
||||
.findings
|
||||
.iter()
|
||||
.all(|finding| finding.source_location.is_none())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn previews_swagger2_and_resolves_local_definitions() {
|
||||
let preview = preview_document(SWAGGER2).unwrap();
|
||||
@@ -511,6 +524,26 @@ paths:
|
||||
assert!(codes.contains(&"missing_summary"));
|
||||
assert!(codes.contains(&"missing_description"));
|
||||
assert!(codes.contains(&"missing_response_schema"));
|
||||
assert_eq!(
|
||||
operation
|
||||
.source_location
|
||||
.as_ref()
|
||||
.map(|location| location.pointer.as_str()),
|
||||
Some("/paths/~1items/get")
|
||||
);
|
||||
assert!(operation.findings.iter().any(|finding| {
|
||||
finding.code == "missing_operation_id"
|
||||
&& finding
|
||||
.source_location
|
||||
.as_ref()
|
||||
.is_some_and(|location| location.pointer == "/paths/~1items/get/operationId")
|
||||
}));
|
||||
assert!(
|
||||
operation
|
||||
.findings
|
||||
.iter()
|
||||
.all(|finding| finding.source_location.is_some())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -656,6 +689,13 @@ paths:
|
||||
.filter(|finding| finding.code == "unsupported_http_method")
|
||||
.count();
|
||||
assert_eq!(unsupported, 2);
|
||||
assert!(preview.findings.iter().any(|finding| {
|
||||
finding.code == "unsupported_http_method"
|
||||
&& finding
|
||||
.source_location
|
||||
.as_ref()
|
||||
.is_some_and(|location| location.pointer == "/paths/~1health/trace")
|
||||
}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user