协作头脑风暴
brainstorming
在实现前澄清需求、探索设计选择,并形成清晰的开发方向。
behavior-preservation-checker【开发与工程】Compare runtime behavior between original and migrated repositories to detect behavioral differences, regressions, and semantic changes. Use when validating code migrations, refactorings, language ports, framework upgrades, or any transformation that should preserve behavior. Automatically compares test results, execution traces, API responses, and o…
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Validate that a migrated or refactored codebase preserves the original behavior by automatically comparing runtime behavior, test results, execution traces, and observable outputs between two repository versions.
Prepare both repositories for comparison:
# Clone or locate repositories
ORIGINAL_REPO=/path/to/original
MIGRATED_REPO=/path/to/migrated
# Ensure both are at comparable states
cd $ORIGINAL_REPO && git checkout main
cd $MIGRATED_REPO && git checkout main
Use the comparison script to analyze behavioral differences:
python scripts/behavior_checker.py \
--original $ORIGINAL_REPO \
--migrated $MIGRATED_REPO \
--output behavior_report.json
Examine the generated report for:
Follow actionable guidance to resolve behavioral differences.
Run the same test suite on both repositories and compare results:
Workflow:
Example:
# Run on original
cd $ORIGINAL_REPO
pytest tests/ --json-report --json-report-file=original_results.json
# Run on migrated
cd $MIGRATED_REPO
pytest tests/ --json-report --json-report-file=migrated_results.json
# Compare
python scripts/compare_test_results.py \
original_results.json \
migrated_results.json
Capture and compare execution traces:
Workflow:
Example:
# Trace original
python scripts/trace_execution.py \
--repo $ORIGINAL_REPO \
--input test_inputs.json \
--output original_trace.json
# Trace migrated
python scripts/trace_execution.py \
--repo $MIGRATED_REPO \
--input test_inputs.json \
--output migrated_trace.json
# Compare traces
python scripts/compare_traces.py \
original_trace.json \
migrated_trace.json
Compare program outputs for identical inputs:
Workflow:
Example:
# Test API endpoints
python scripts/compare_api_outputs.py \
--original-url http://localhost:8000 \
--migrated-url http://localhost:8001 \
--test-cases api_test_cases.json
Use property-based testing to find behavioral differences:
Workflow:
Example:
# Property: sorting should produce same result
from hypothesis import given, strategies as st
@given(st.lists(st.integers()))
def test_sort_equivalence(input_list):
original_result = original_sort(input_list)
migrated_result = migrated_sort(input_list)
assert original_result == migrated_result
What to check:
Severity levels:
What to check:
Example divergence:
Original trace:
calculate(x=10) -> 20
validate(20) -> True
save(20) -> Success
Migrated trace:
calculate(x=10) -> 21 # ← Difference!
validate(21) -> True
save(21) -> Success
What to check:
Tolerance levels:
# Exact match required
assert original_output == migrated_output
# Numerical tolerance
assert abs(original_value - migrated_value) < 0.001
# Structural equivalence (ignore formatting)
assert json.loads(original) == json.loads(migrated)
Symptom: Different outputs for same inputs
Diagnosis:
python scripts/isolate_difference.py \
--original $ORIGINAL_REPO \
--migrated $MIGRATED_REPO \
--failing-test test_calculation
Guidance:
Symptom: Tests pass in original but fail in migrated with "not implemented" or "attribute error"
Diagnosis:
python scripts/find_missing_functions.py \
--original $ORIGINAL_REPO \
--migrated $MIGRATED_REPO
Guidance:
Symptom: Different response structure or status codes
Diagnosis:
python scripts/compare_api_contracts.py \
--original-spec openapi_original.yaml \
--migrated-spec openapi_migrated.yaml
Guidance:
Symptom: Migrated version is significantly slower
Diagnosis:
python scripts/benchmark_comparison.py \
--original $ORIGINAL_REPO \
--migrated $MIGRATED_REPO \
--iterations 100
Guidance:
Symptom: Tests fail intermittently or depend on execution order
Diagnosis:
python scripts/detect_state_issues.py \
--repo $MIGRATED_REPO \
--test-suite tests/
Guidance:
The behavior checker generates a comprehensive JSON report:
{
"summary": {
"total_tests": 150,
"passed_both": 140,
"failed_both": 2,
"passed_original_failed_migrated": 5,
"failed_original_passed_migrated": 3,
"behavioral_equivalence": "92.7%"
},
"differences": [
{
"type": "test_failure",
"test_name": "test_user_authentication",
"severity": "critical",
"original_result": "passed",
"migrated_result": "failed",
"error_message": "AssertionError: Expected 200, got 401",
"guidance": "Check authentication logic in migrated version",
"affected_files": ["auth/login.py"]
}
],
"recommendations": [
"Fix 5 critical test failures before deployment",
"Review 3 output differences for correctness"
]
}