From 7296659b10077fbf586dbd835c93d0c356e0b083 Mon Sep 17 00:00:00 2001 From: Ding Ouyang Date: Fri, 6 Nov 2026 13:29:50 +0800 Subject: [PATCH] Add versioned business behavior comparison report contract --- README.md | 3 + docs/versioning.md | 4 +- examples/v0.2.0/behavior-comparison.json | 335 +++++++ schemas/v0.2.0/analysis-response.schema.json | 949 +++++++++++++++++++ scripts/validate_examples.py | 24 + specs/behavior-comparison.md | 27 + 6 files changed, 1341 insertions(+), 1 deletion(-) create mode 100644 examples/v0.2.0/behavior-comparison.json create mode 100644 schemas/v0.2.0/analysis-response.schema.json create mode 100644 specs/behavior-comparison.md diff --git a/README.md b/README.md index e6179b2..efc2e11 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,12 @@ Public data formats for the standalone Genesis Code Intelligence product. The so ## Contents - `schemas/v0.1.0/analysis-response.schema.json`: stable, user-readable Markdown/JSON report contract. +- `schemas/v0.2.0/analysis-response.schema.json`: opt-in report with source-backed business behavior comparisons; all v0.1.0 report fields remain. - `schemas/v0.1.0/flows.schema.json`: machine-readable `.genesis/flows.yaml` contract. - `specs/flows-yaml.md`: lifecycle and field semantics. - `examples/v0.1.0/`: small, synthetic examples with no customer source. +- `examples/v0.2.0/behavior-comparison.json`: synthetic notification/wait comparison, including an explicitly incomplete scope. +- `specs/behavior-comparison.md`: scenario, side-specific evidence, coverage and version handling. The four reports demonstrate a complete result, unresolved dynamic call, missing intent/tests, and stale flow entry. They are protocol examples, not evidence of analyzer accuracy. diff --git a/docs/versioning.md b/docs/versioning.md index bf07aad..f19e198 100644 --- a/docs/versioning.md +++ b/docs/versioning.md @@ -2,4 +2,6 @@ The public report JSON Schema uses semantic version strings in `schema_version`. The `.genesis/flows.yaml` format uses an integer `schema_version` because its format evolves independently. The private CLI-to-service `protocol_version` is maintained in the implementation repository and is not implied by either public format. -The private Pydantic models are the sole source of generated schemas. Changes to a public model require regenerated schemas and example validation in the same change. Changes to internal request/response models require updating the private protocol notes and fixed fixtures. The first implementation accepts an exact version match; compatibility negotiation is deferred until there is a released client and service. +The private Pydantic models are the sole source of generated schemas. Changes to a public model require regenerated schemas and example validation in the same change. Changes to internal request/response models require updating the private protocol notes and fixed fixtures. + +Report v0.1.0 is retained unchanged. A report with a structured `behavior_review` uses v0.2.0, preserving every original report field. Consumers must dispatch on `schema_version` and validate against that exact version; do not feed v0.2.0 into the strict v0.1.0 schema. The implementation's `parse_analysis_response()` accepts both. Flow files still use schema 1. The private HTTP protocol negotiates optional behavior features independently; an older client continues to receive the legacy report content. Public schemas describe report artifacts, not wire service requests. diff --git a/examples/v0.2.0/behavior-comparison.json b/examples/v0.2.0/behavior-comparison.json new file mode 100644 index 0000000..420285d --- /dev/null +++ b/examples/v0.2.0/behavior-comparison.json @@ -0,0 +1,335 @@ +{ + "schema_version": "0.2.0", + "snapshot_id": "sha256:348c1be73023373ed0e1804deaf4efb2933ec349da1c0c9dd295457a56e7f83d", + "analysis_status": "partial", + "section_status": { + "behavior_intent": { + "status": "analyzed", + "reason": null, + "analyzed_scope": "Synthetic submit_report example only" + }, + "flow_impact": { + "status": "analyzed", + "reason": null, + "analyzed_scope": "Synthetic submit_report example only" + }, + "cost_risk": { + "status": "analyzed", + "reason": null, + "analyzed_scope": "Synthetic submit_report example only" + }, + "acceptance_tests": { + "status": "analyzed", + "reason": null, + "analyzed_scope": "Synthetic submit_report example only" + }, + "verification": { + "status": "analyzed", + "reason": null, + "analyzed_scope": "Synthetic submit_report example only" + } + }, + "scope": { + "base_revision": "fixture-normal-five-sections-base", + "head_revision": "fixture-normal-five-sections-head", + "analyzed_files": [ + ".genesis/flows.yaml", + "intent/pr.md", + "intent/task.md", + "src/app.py", + "tests/test_submit.py" + ], + "omitted_inputs": [], + "parser_limitations": [ + "Deterministic fixture facts; no customer code was analyzed." + ], + "execution_mode": "mock" + }, + "findings": [ + { + "finding_id": "F-RULE-WAIT", + "category": "cost_risk", + "statement": "An awaited operation was added before returning; actual added wait is unknown.", + "severity": "low", + "basis": [ + "code_fact" + ], + "evidence_ids": [ + "ev_89e203f9043afb89b9068091", + "ev_6df63ca95d3cb58b96f6d1f7" + ], + "deviation": null, + "condition": null, + "gap": null, + "recommendation": null, + "flow_ids": [], + "estimate_ids": [ + "wait-1" + ] + }, + { + "finding_id": "F-SEM-BEHAVIOR", + "category": "behavior_intent", + "statement": "The head function awaits notify(result) before returning; the base function returns submission directly.", + "severity": "info", + "basis": [ + "code_fact" + ], + "evidence_ids": [ + "ev_89e203f9043afb89b9068091", + "ev_6df63ca95d3cb58b96f6d1f7" + ], + "deviation": null, + "condition": null, + "gap": null, + "recommendation": null, + "flow_ids": [], + "estimate_ids": [] + }, + { + "finding_id": "F-SEM-CLAIM", + "category": "behavior_intent", + "statement": "No success-value check appears before notify in the visible function. If submit returns a failure value instead of raising, the PR's claim is unverified.", + "severity": "medium", + "basis": [ + "code_fact", + "user_intent", + "agent_claim", + "semantic_inference" + ], + "evidence_ids": [ + "ev_6df63ca95d3cb58b96f6d1f7", + "ev_1e751d22d466cffdc5bcb9c1", + "ev_5dd9203ab8839a14297b8fa5" + ], + "deviation": "unverified_claim", + "condition": "Only when submit returns a failure value; exceptions prevent the following notify call.", + "gap": null, + "recommendation": null, + "flow_ids": [], + "estimate_ids": [] + }, + { + "finding_id": "F-SEM-TEST", + "category": "acceptance_tests", + "statement": "The supplied test checks a non-null result; it contains no assertion about notification on failure.", + "severity": "low", + "basis": [ + "code_fact", + "user_intent" + ], + "evidence_ids": [ + "ev_6faad0b1bdfff9c9b6261e4d", + "ev_1e751d22d466cffdc5bcb9c1" + ], + "deviation": null, + "condition": null, + "gap": null, + "recommendation": null, + "flow_ids": [ + "submit-report" + ], + "estimate_ids": [] + } + ], + "estimates": [ + { + "estimate_id": "wait-1", + "flow_ids": [], + "structural_signals": [ + "One additional serial await" + ], + "parameters": [ + { + "name": "added_wait", + "value": null, + "unit": "ms", + "source": null, + "unknown_reason": "No runtime measurements or external implementation supplied" + } + ], + "formula": null, + "amount": null, + "currency": null, + "price_source": null, + "price_date": null, + "assumptions": [], + "unknowns": [ + "Actual latency and failure rate" + ], + "evidence_ids": [ + "ev_89e203f9043afb89b9068091", + "ev_6df63ca95d3cb58b96f6d1f7" + ] + } + ], + "suggestions": [ + { + "suggestion_id": "V-001", + "scenario": "Review the new awaited operation's failure behavior.", + "conditions": [ + "Submission returns a failure value", + "Submission raises an exception" + ], + "suggested_assertions": [ + "No success notification is sent on a failure-valued submission" + ], + "existing_test_evidence_ids": [ + "ev_6faad0b1bdfff9c9b6261e4d" + ], + "rationale": "Distinguish return-value failures from exceptions; test definitions are not executed.", + "questions_for_user": [ + "Which values mean submission failed?", + "Should an awaited operation's failure change the return behavior?" + ], + "evidence_ids": [ + "ev_6df63ca95d3cb58b96f6d1f7" + ] + } + ], + "limitations": [ + { + "code": "mock_fixture", + "message": "Synthetic contract example, not a customer analysis.", + "evidence_ids": [], + "affects_completeness": false + } + ], + "analyzer_version": "0.1.0-mock", + "rule_version": "0.1.0-mock", + "semantic_version": "mock-v1", + "evidence": [ + { + "evidence_id": "ev_89e203f9043afb89b9068091", + "snapshot_id": "sha256:348c1be73023373ed0e1804deaf4efb2933ec349da1c0c9dd295457a56e7f83d", + "side": "base", + "path": "src/app.py", + "range": { + "start_line": 1, + "end_line": 2, + "start_column": null, + "end_column": null + }, + "snippet_digest": "sha256:37b82a7da7a16b0788e23b4481e4f79fdac7b17ecaf2e99cb643878a0178751e", + "kind": "code" + }, + { + "evidence_id": "ev_6df63ca95d3cb58b96f6d1f7", + "snapshot_id": "sha256:348c1be73023373ed0e1804deaf4efb2933ec349da1c0c9dd295457a56e7f83d", + "side": "head", + "path": "src/app.py", + "range": { + "start_line": 1, + "end_line": 4, + "start_column": null, + "end_column": null + }, + "snippet_digest": "sha256:bfb2ed982e86a11e90c1e514342e5378eaac2b75437d1c6332fb9cc990b5ace7", + "kind": "code" + }, + { + "evidence_id": "ev_17747a64e05ffff55266df1b", + "snapshot_id": "sha256:348c1be73023373ed0e1804deaf4efb2933ec349da1c0c9dd295457a56e7f83d", + "side": "base", + "path": ".genesis/flows.yaml", + "range": { + "start_line": 1, + "end_line": 9, + "start_column": null, + "end_column": null + }, + "snippet_digest": "sha256:04a254461546fece9246c49f90901dce5e7407b985dbb599a05f9d3aca706f3e", + "kind": "flow" + }, + { + "evidence_id": "ev_afc8b812c5a4c2486e9283c2", + "snapshot_id": "sha256:348c1be73023373ed0e1804deaf4efb2933ec349da1c0c9dd295457a56e7f83d", + "side": "head", + "path": ".genesis/flows.yaml", + "range": { + "start_line": 1, + "end_line": 9, + "start_column": null, + "end_column": null + }, + "snippet_digest": "sha256:04a254461546fece9246c49f90901dce5e7407b985dbb599a05f9d3aca706f3e", + "kind": "flow" + }, + { + "evidence_id": "ev_5dd9203ab8839a14297b8fa5", + "snapshot_id": "sha256:348c1be73023373ed0e1804deaf4efb2933ec349da1c0c9dd295457a56e7f83d", + "side": "head", + "path": "intent/pr.md", + "range": { + "start_line": 1, + "end_line": 1, + "start_column": null, + "end_column": null + }, + "snippet_digest": "sha256:9929b358104171c1c3c15fa719949cc0fa90baa9dc76a3aca2a807f486ad2084", + "kind": "intent" + }, + { + "evidence_id": "ev_1e751d22d466cffdc5bcb9c1", + "snapshot_id": "sha256:348c1be73023373ed0e1804deaf4efb2933ec349da1c0c9dd295457a56e7f83d", + "side": "head", + "path": "intent/task.md", + "range": { + "start_line": 1, + "end_line": 1, + "start_column": null, + "end_column": null + }, + "snippet_digest": "sha256:4a4c4ab25ce9fae85ba0e59458dedadb0d3329f785da9fbc875538ff1a4cb5b9", + "kind": "intent" + }, + { + "evidence_id": "ev_6faad0b1bdfff9c9b6261e4d", + "snapshot_id": "sha256:348c1be73023373ed0e1804deaf4efb2933ec349da1c0c9dd295457a56e7f83d", + "side": "head", + "path": "tests/test_submit.py", + "range": { + "start_line": 1, + "end_line": 3, + "start_column": null, + "end_column": null + }, + "snippet_digest": "sha256:ff9704d3f8a48bd8fe000b634911b152aea5abf8870bb8b8317e9a090b20fba4", + "kind": "test" + } + ], + "behavior_review": { + "version": "1", + "coverage": { + "status": "insufficient_context", + "reason": "Synthetic example; caller and notification implementation are absent.", + "analyzed_scope": null + }, + "changes": [ + { + "change_id": "report-notification", + "scenario": "提交报告并通知", + "condition": "按各版本的调用方式执行 submit_report,第三方提交返回结果。", + "before": "直接返回第三方提交结果。", + "after": "等待通知完成后才返回提交结果;函数现在需要异步调用。", + "before_evidence_ids": [ + "ev_89e203f9043afb89b9068091" + ], + "after_evidence_ids": [ + "ev_6df63ca95d3cb58b96f6d1f7" + ], + "explanation": "新增 await notify(result),放在提交与返回之间。", + "impact": "完成时间包含通知等待;若通知抛出异常,当前函数不会正常返回结果。", + "preserved_behavior": "第三方提交调用仍是同步调用。", + "evidence_ids": [ + "ev_89e203f9043afb89b9068091", + "ev_6df63ca95d3cb58b96f6d1f7" + ], + "finding_ids": [], + "limitations": [ + "未提供调用方及通知实现,无法确认调用方适配、通知耗时及失败概率。" + ] + } + ] + } +} diff --git a/schemas/v0.2.0/analysis-response.schema.json b/schemas/v0.2.0/analysis-response.schema.json new file mode 100644 index 0000000..f36c22c --- /dev/null +++ b/schemas/v0.2.0/analysis-response.schema.json @@ -0,0 +1,949 @@ +{ + "$defs": { + "AnalysisScope": { + "additionalProperties": false, + "properties": { + "analyzed_files": { + "items": { + "type": "string" + }, + "title": "Analyzed Files", + "type": "array" + }, + "base_revision": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Base Revision" + }, + "execution_mode": { + "enum": [ + "mock", + "offline", + "semantic" + ], + "title": "Execution Mode", + "type": "string" + }, + "head_revision": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Head Revision" + }, + "omitted_inputs": { + "default": [], + "items": { + "type": "string" + }, + "title": "Omitted Inputs", + "type": "array" + }, + "parser_limitations": { + "default": [], + "items": { + "type": "string" + }, + "title": "Parser Limitations", + "type": "array" + } + }, + "required": [ + "analyzed_files", + "execution_mode" + ], + "title": "AnalysisScope", + "type": "object" + }, + "AnalysisStatus": { + "enum": [ + "complete", + "partial", + "failed" + ], + "title": "AnalysisStatus", + "type": "string" + }, + "BehaviorChange": { + "additionalProperties": false, + "description": "Source-backed semantic comparison, never an inferred user requirement.", + "properties": { + "after": { + "anyOf": [ + { + "maxLength": 2000, + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "title": "After" + }, + "after_evidence_ids": { + "default": [], + "items": { + "type": "string" + }, + "maxItems": 16, + "title": "After Evidence Ids", + "type": "array" + }, + "before": { + "anyOf": [ + { + "maxLength": 2000, + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Before" + }, + "before_evidence_ids": { + "default": [], + "items": { + "type": "string" + }, + "maxItems": 16, + "title": "Before Evidence Ids", + "type": "array" + }, + "change_id": { + "maxLength": 128, + "minLength": 1, + "title": "Change Id", + "type": "string" + }, + "condition": { + "maxLength": 1000, + "minLength": 1, + "title": "Condition", + "type": "string" + }, + "evidence_ids": { + "items": { + "type": "string" + }, + "maxItems": 24, + "minItems": 1, + "title": "Evidence Ids", + "type": "array" + }, + "explanation": { + "maxLength": 2000, + "minLength": 1, + "title": "Explanation", + "type": "string" + }, + "finding_ids": { + "default": [], + "items": { + "type": "string" + }, + "maxItems": 24, + "title": "Finding Ids", + "type": "array" + }, + "impact": { + "maxLength": 2000, + "minLength": 1, + "title": "Impact", + "type": "string" + }, + "limitations": { + "default": [], + "items": { + "type": "string" + }, + "maxItems": 8, + "title": "Limitations", + "type": "array" + }, + "preserved_behavior": { + "anyOf": [ + { + "maxLength": 1000, + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Preserved Behavior" + }, + "scenario": { + "maxLength": 500, + "minLength": 1, + "title": "Scenario", + "type": "string" + } + }, + "required": [ + "change_id", + "scenario", + "condition", + "explanation", + "impact", + "evidence_ids" + ], + "title": "BehaviorChange", + "type": "object" + }, + "BehaviorReview": { + "additionalProperties": false, + "properties": { + "changes": { + "default": [], + "items": { + "$ref": "#/$defs/BehaviorChange" + }, + "maxItems": 12, + "title": "Changes", + "type": "array" + }, + "coverage": { + "$ref": "#/$defs/CapabilityStatus" + }, + "version": { + "const": "1", + "default": "1", + "title": "Version", + "type": "string" + } + }, + "required": [ + "coverage" + ], + "title": "BehaviorReview", + "type": "object" + }, + "CapabilityStatus": { + "additionalProperties": false, + "properties": { + "analyzed_scope": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Analyzed Scope" + }, + "reason": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Reason" + }, + "status": { + "$ref": "#/$defs/SectionStatus" + } + }, + "required": [ + "status" + ], + "title": "CapabilityStatus", + "type": "object" + }, + "EstimateParameter": { + "additionalProperties": false, + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "source": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Source" + }, + "unit": { + "title": "Unit", + "type": "string" + }, + "unknown_reason": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Unknown Reason" + }, + "value": { + "anyOf": [ + { + "type": "number" + }, + { + "type": "null" + } + ], + "title": "Value" + } + }, + "required": [ + "name", + "value", + "unit" + ], + "title": "EstimateParameter", + "type": "object" + }, + "EvidenceBasis": { + "enum": [ + "code_fact", + "semantic_inference", + "conditional_estimate", + "user_intent", + "agent_claim" + ], + "title": "EvidenceBasis", + "type": "string" + }, + "EvidenceKind": { + "enum": [ + "code", + "intent", + "flow", + "test", + "config" + ], + "title": "EvidenceKind", + "type": "string" + }, + "EvidenceRef": { + "additionalProperties": false, + "properties": { + "evidence_id": { + "minLength": 1, + "title": "Evidence Id", + "type": "string" + }, + "kind": { + "$ref": "#/$defs/EvidenceKind" + }, + "path": { + "minLength": 1, + "title": "Path", + "type": "string" + }, + "range": { + "$ref": "#/$defs/ReferenceRange" + }, + "side": { + "$ref": "#/$defs/EvidenceSide" + }, + "snapshot_id": { + "minLength": 1, + "title": "Snapshot Id", + "type": "string" + }, + "snippet_digest": { + "pattern": "^sha256:[0-9a-f]{64}$", + "title": "Snippet Digest", + "type": "string" + } + }, + "required": [ + "evidence_id", + "snapshot_id", + "side", + "path", + "range", + "snippet_digest", + "kind" + ], + "title": "EvidenceRef", + "type": "object" + }, + "EvidenceSide": { + "enum": [ + "base", + "head" + ], + "title": "EvidenceSide", + "type": "string" + }, + "Finding": { + "additionalProperties": false, + "properties": { + "basis": { + "items": { + "$ref": "#/$defs/EvidenceBasis" + }, + "minItems": 1, + "title": "Basis", + "type": "array" + }, + "category": { + "$ref": "#/$defs/FindingCategory" + }, + "condition": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Condition" + }, + "deviation": { + "anyOf": [ + { + "$ref": "#/$defs/IntentDeviation" + }, + { + "type": "null" + } + ], + "default": null + }, + "estimate_ids": { + "default": [], + "items": { + "type": "string" + }, + "title": "Estimate Ids", + "type": "array" + }, + "evidence_ids": { + "items": { + "type": "string" + }, + "title": "Evidence Ids", + "type": "array" + }, + "finding_id": { + "minLength": 1, + "title": "Finding Id", + "type": "string" + }, + "flow_ids": { + "default": [], + "items": { + "type": "string" + }, + "title": "Flow Ids", + "type": "array" + }, + "gap": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Gap" + }, + "recommendation": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Recommendation" + }, + "severity": { + "$ref": "#/$defs/Severity" + }, + "statement": { + "minLength": 1, + "title": "Statement", + "type": "string" + } + }, + "required": [ + "finding_id", + "category", + "statement", + "severity", + "basis", + "evidence_ids" + ], + "title": "Finding", + "type": "object" + }, + "FindingCategory": { + "enum": [ + "behavior_intent", + "flow_impact", + "cost_risk", + "acceptance_tests", + "verification" + ], + "title": "FindingCategory", + "type": "string" + }, + "ImpactEstimate": { + "additionalProperties": false, + "properties": { + "amount": { + "anyOf": [ + { + "type": "number" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Amount" + }, + "assumptions": { + "default": [], + "items": { + "type": "string" + }, + "title": "Assumptions", + "type": "array" + }, + "currency": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Currency" + }, + "estimate_id": { + "title": "Estimate Id", + "type": "string" + }, + "evidence_ids": { + "items": { + "type": "string" + }, + "title": "Evidence Ids", + "type": "array" + }, + "flow_ids": { + "default": [], + "items": { + "type": "string" + }, + "title": "Flow Ids", + "type": "array" + }, + "formula": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Formula" + }, + "parameters": { + "default": [], + "items": { + "$ref": "#/$defs/EstimateParameter" + }, + "title": "Parameters", + "type": "array" + }, + "price_date": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Price Date" + }, + "price_source": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Price Source" + }, + "structural_signals": { + "default": [], + "items": { + "type": "string" + }, + "title": "Structural Signals", + "type": "array" + }, + "unknowns": { + "default": [], + "items": { + "type": "string" + }, + "title": "Unknowns", + "type": "array" + } + }, + "required": [ + "estimate_id", + "evidence_ids" + ], + "title": "ImpactEstimate", + "type": "object" + }, + "IntentDeviation": { + "enum": [ + "missing_in_code", + "unrequested_change", + "unverified_claim" + ], + "title": "IntentDeviation", + "type": "string" + }, + "Limitation": { + "additionalProperties": false, + "properties": { + "affects_completeness": { + "default": false, + "title": "Affects Completeness", + "type": "boolean" + }, + "code": { + "title": "Code", + "type": "string" + }, + "evidence_ids": { + "default": [], + "items": { + "type": "string" + }, + "title": "Evidence Ids", + "type": "array" + }, + "message": { + "title": "Message", + "type": "string" + } + }, + "required": [ + "code", + "message" + ], + "title": "Limitation", + "type": "object" + }, + "ReferenceRange": { + "additionalProperties": false, + "properties": { + "end_column": { + "anyOf": [ + { + "minimum": 0, + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "title": "End Column" + }, + "end_line": { + "minimum": 1, + "title": "End Line", + "type": "integer" + }, + "start_column": { + "anyOf": [ + { + "minimum": 0, + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Start Column" + }, + "start_line": { + "minimum": 1, + "title": "Start Line", + "type": "integer" + } + }, + "required": [ + "start_line", + "end_line" + ], + "title": "ReferenceRange", + "type": "object" + }, + "SectionStatus": { + "enum": [ + "analyzed", + "insufficient_context", + "unsupported" + ], + "title": "SectionStatus", + "type": "string" + }, + "SectionStatuses": { + "additionalProperties": false, + "properties": { + "acceptance_tests": { + "$ref": "#/$defs/CapabilityStatus" + }, + "behavior_intent": { + "$ref": "#/$defs/CapabilityStatus" + }, + "cost_risk": { + "$ref": "#/$defs/CapabilityStatus" + }, + "flow_impact": { + "$ref": "#/$defs/CapabilityStatus" + }, + "verification": { + "$ref": "#/$defs/CapabilityStatus" + } + }, + "required": [ + "behavior_intent", + "flow_impact", + "cost_risk", + "acceptance_tests", + "verification" + ], + "title": "SectionStatuses", + "type": "object" + }, + "Severity": { + "enum": [ + "info", + "low", + "medium", + "high" + ], + "title": "Severity", + "type": "string" + }, + "VerificationSuggestion": { + "additionalProperties": false, + "properties": { + "conditions": { + "default": [], + "items": { + "type": "string" + }, + "title": "Conditions", + "type": "array" + }, + "evidence_ids": { + "items": { + "type": "string" + }, + "title": "Evidence Ids", + "type": "array" + }, + "existing_test_evidence_ids": { + "default": [], + "items": { + "type": "string" + }, + "title": "Existing Test Evidence Ids", + "type": "array" + }, + "questions_for_user": { + "default": [], + "items": { + "type": "string" + }, + "title": "Questions For User", + "type": "array" + }, + "rationale": { + "minLength": 1, + "title": "Rationale", + "type": "string" + }, + "scenario": { + "minLength": 1, + "title": "Scenario", + "type": "string" + }, + "suggested_assertions": { + "default": [], + "items": { + "type": "string" + }, + "title": "Suggested Assertions", + "type": "array" + }, + "suggestion_id": { + "title": "Suggestion Id", + "type": "string" + } + }, + "required": [ + "suggestion_id", + "scenario", + "rationale", + "evidence_ids" + ], + "title": "VerificationSuggestion", + "type": "object" + } + }, + "additionalProperties": false, + "description": "Opt-in public report v0.2.0; the v0.1.0 schema remains unchanged.", + "properties": { + "analysis_status": { + "$ref": "#/$defs/AnalysisStatus" + }, + "analyzer_version": { + "minLength": 1, + "title": "Analyzer Version", + "type": "string" + }, + "behavior_review": { + "$ref": "#/$defs/BehaviorReview" + }, + "estimates": { + "default": [], + "items": { + "$ref": "#/$defs/ImpactEstimate" + }, + "title": "Estimates", + "type": "array" + }, + "evidence": { + "items": { + "$ref": "#/$defs/EvidenceRef" + }, + "title": "Evidence", + "type": "array" + }, + "findings": { + "default": [], + "items": { + "$ref": "#/$defs/Finding" + }, + "title": "Findings", + "type": "array" + }, + "limitations": { + "default": [], + "items": { + "$ref": "#/$defs/Limitation" + }, + "title": "Limitations", + "type": "array" + }, + "rule_version": { + "minLength": 1, + "title": "Rule Version", + "type": "string" + }, + "schema_version": { + "const": "0.2.0", + "default": "0.2.0", + "title": "Schema Version", + "type": "string" + }, + "scope": { + "$ref": "#/$defs/AnalysisScope" + }, + "section_status": { + "$ref": "#/$defs/SectionStatuses" + }, + "semantic_version": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "title": "Semantic Version" + }, + "snapshot_id": { + "minLength": 1, + "title": "Snapshot Id", + "type": "string" + }, + "suggestions": { + "default": [], + "items": { + "$ref": "#/$defs/VerificationSuggestion" + }, + "title": "Suggestions", + "type": "array" + } + }, + "required": [ + "snapshot_id", + "analysis_status", + "section_status", + "scope", + "analyzer_version", + "rule_version", + "evidence", + "behavior_review" + ], + "title": "BehaviorAnalysisResponse", + "type": "object" +} diff --git a/scripts/validate_examples.py b/scripts/validate_examples.py index 6c5e0d2..edfb3d3 100644 --- a/scripts/validate_examples.py +++ b/scripts/validate_examples.py @@ -38,6 +38,30 @@ def check_refs(value): if report["analysis_status"] == "complete": assert all(section["status"] == "analyzed" for section in report["section_status"].values()) assert not any(item["affects_completeness"] for item in report["limitations"]) + comparison_schema = json.loads((ROOT / "schemas/v0.2.0/analysis-response.schema.json").read_text()) + Draft202012Validator.check_schema(comparison_schema) + comparison_reports = sorted((ROOT / "examples/v0.2.0").glob("*.json")) + assert comparison_reports + for path in comparison_reports: + report = json.loads(path.read_text()) + Draft202012Validator(comparison_schema).validate(report) + assert report["scope"]["execution_mode"] == "mock" + refs = {item["evidence_id"]: item for item in report["evidence"]} + findings = {item["finding_id"] for item in report["findings"]} + changes = report["behavior_review"]["changes"] + assert len({change["change_id"] for change in changes}) == len(changes) + for change in changes: + assert set(change["finding_ids"]) <= findings + for label, side in (("before", "base"), ("after", "head")): + ids = change[label + "_evidence_ids"] + assert (change[label] is not None) == bool(ids) + assert all(refs[ident]["kind"] == "code" and refs[ident]["side"] == side for ident in ids) + assert set(change["evidence_ids"]) <= refs.keys() + assert any(refs[ident]["kind"] == "code" for ident in change["evidence_ids"]) + assert change["before"] is not None or change["after"] is not None + assert (change["before"] is not None and change["after"] is not None) or change["limitations"] + if report["analysis_status"] == "complete": + assert report["behavior_review"]["coverage"]["status"] == "analyzed" flows = yaml.safe_load((ROOT / "examples/v0.1.0/flows.yaml").read_text()) validators["flows"].validate(flows) assert len({flow["id"] for flow in flows["flows"]}) == len(flows["flows"]) diff --git a/specs/behavior-comparison.md b/specs/behavior-comparison.md new file mode 100644 index 0000000..38009ed --- /dev/null +++ b/specs/behavior-comparison.md @@ -0,0 +1,27 @@ +# Business behavior comparisons + +Report v0.2.0 adds the required `behavior_review` object to all fields of v0.1.0. The original five sections, findings, estimates, verification suggestions and limitations remain. The comparison is semantic inference from frozen source, not a user requirement, runtime observation or test result. + +`behavior_review.version` is `1`. `coverage` uses the same status/reason/analyzed-scope structure as section coverage. `changes` contains at most 12 comparisons. An empty array may mean no supported comparison was produced; read coverage and the five sections before inferring safety or absence of change. + +Each comparison contains: + +| Field | Meaning | +| --- | --- | +| `change_id` | Unique within the report | +| `scenario`, `condition` | Concrete use case and trigger under which the explanation applies | +| `before`, `after` | Source-backed behavior of each revision, or `null` when that side cannot be described | +| `before_evidence_ids`, `after_evidence_ids` | Selected code evidence belonging to base or head respectively | +| `explanation`, `impact` | Why the connected code changes the behavior, and the observable consequence | +| `preserved_behavior` | Relevant behavior that remains, or `null` when no supported statement is available | +| `evidence_ids` | Evidence supporting the explanation, including at least one code reference | +| `finding_ids` | Existing local/semantic findings in the same report; may be empty | +| `limitations` | Missing links, conditional assumptions and unresolved scope | + +A described side needs nonempty side-specific references. At least one side must be described. An unavailable side needs an explicit limitation; absence of a selected excerpt does not prove absence of code or behavior. Source references retain the report snapshot, side, path, range and digest identity. Finding references cannot introduce findings that are absent from the report. + +Some constraints (reference existence, side and kind, unique change IDs, finding linkage) require semantic validation in addition to JSON Schema. A `complete` report also requires analyzed comparison coverage, every original section analyzed, and no completeness-affecting limitations. Partial comparisons still retain supported changes. These checks do not prove a natural-language claim is correct. + +The concise and detailed Markdown reports are deterministic presentations of this same object. Neither renderer generates a second model answer. Internal AST/behavior-unit formats are intentionally separate from this public report contract. + +The synthetic example describes an asynchronous notification added between submitting a report and returning its result. Its scope is partial because the caller and notification implementation are absent. It demonstrates the format, not measured analyzer accuracy.