@teevee98/synapse-hub 0.0.0-stage → 3.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/agents/api-engineer.md +67 -0
- package/.agents/agents/failure-analyst.md +75 -0
- package/.agents/agents/live-explorer.md +70 -0
- package/.agents/agents/orchestrator.md +104 -0
- package/.agents/agents/perf-engineer.md +74 -0
- package/.agents/agents/pom-crafter.md +112 -0
- package/.agents/agents/quality-gatekeeper.md +87 -0
- package/.agents/agents/test-designer.md +73 -0
- package/.agents/agents/test-runner.md +67 -0
- package/.agents/rules/author-integrity-guard.md +33 -0
- package/.agents/rules/communication-style.md +18 -0
- package/.agents/rules/context-engineering.md +37 -0
- package/.agents/rules/git-push-protocol.md +33 -0
- package/.agents/rules/graphify.md +14 -0
- package/.agents/rules/lessons-learned.md +25 -0
- package/.agents/rules/mandatory-playwright-live.md +25 -0
- package/.agents/rules/mobile_appium_rules.md +43 -0
- package/.agents/rules/performance_testing_rules.md +35 -0
- package/.agents/rules/skill-precedence.md +29 -0
- package/.agents/rules/systematic-debugging.md +36 -0
- package/.agents/skills/actor-qa-swarm/SKILL.md +77 -0
- package/.agents/skills/actor-qa-swarm/examples/broker_sharding_sample.json +12 -0
- package/.agents/skills/agent-orchestration-multi-agent-optimize/SKILL.md +88 -0
- package/.agents/skills/agent-orchestration-multi-agent-optimize/examples/swarm_workload_config.json +15 -0
- package/.agents/skills/agentless-qa-repair/SKILL.md +69 -0
- package/.agents/skills/agentless-qa-repair/examples/healing_report_sample.json +17 -0
- package/.agents/skills/agentless-qa-repair/examples/three_phase_repair_workflow.md +40 -0
- package/.agents/skills/antigravity-test-sentinel/SKILL.md +63 -0
- package/.agents/skills/antigravity-test-sentinel/examples/dod_gate_policy.json +11 -0
- package/.agents/skills/antigravity-test-sentinel/examples/sprint_dod_enforcement.md +47 -0
- package/.agents/skills/api-network-mocking-interception/SKILL.md +142 -0
- package/.agents/skills/api-network-mocking-interception/examples/network_route_stub.json +9 -0
- package/.agents/skills/api-spec-to-e2e-matrix/SKILL.md +80 -0
- package/.agents/skills/api-spec-to-e2e-matrix/examples/sample_openapi.json +19 -0
- package/.agents/skills/architecture-decision-records/SKILL.md +64 -0
- package/.agents/skills/architecture-decision-records/examples/0001-record-architecture-decisions.md +12 -0
- package/.agents/skills/auth-session-and-cookie-manager/SKILL.md +75 -0
- package/.agents/skills/auth-session-and-cookie-manager/examples/multi_role_auth_matrix.md +70 -0
- package/.agents/skills/auth-session-and-cookie-manager/examples/storage_state_sample.json +11 -0
- package/.agents/skills/backend-load-and-stress-patterns/SKILL.md +85 -0
- package/.agents/skills/backend-load-and-stress-patterns/examples/k6_load_test_sample.js +13 -0
- package/.agents/skills/backend-load-and-stress-patterns/references/k6_load_template.js +82 -0
- package/.agents/skills/bats-testing-patterns/SKILL.md +100 -0
- package/.agents/skills/bats-testing-patterns/examples/cli_runner_test.bats +6 -0
- package/.agents/skills/bats-testing-patterns/resources/implementation-playbook.md +614 -0
- package/.agents/skills/clean-pom-crafter/SKILL.md +110 -0
- package/.agents/skills/clean-pom-crafter/examples/standard_test_case.groovy +28 -0
- package/.agents/skills/clean-pom-crafter/references/pom_patterns.groovy +138 -0
- package/.agents/skills/code-refactoring-refactor-clean/SKILL.md +64 -0
- package/.agents/skills/code-refactoring-refactor-clean/examples/refactored_page_sample.groovy +9 -0
- package/.agents/skills/code-refactoring-refactor-clean/examples/refactored_playwright_pom.ts +52 -0
- package/.agents/skills/code-refactoring-refactor-clean/resources/implementation-playbook.md +881 -0
- package/.agents/skills/consumer-driven-contract-testing/SKILL.md +147 -0
- package/.agents/skills/consumer-driven-contract-testing/examples/order_service_pact.json +45 -0
- package/.agents/skills/db-state-verifier-and-seeder/SKILL.md +123 -0
- package/.agents/skills/db-state-verifier-and-seeder/examples/db_fixture_seed.json +12 -0
- package/.agents/skills/e2e-testing-patterns/SKILL.md +103 -0
- package/.agents/skills/e2e-testing-patterns/examples/playwright_sharded_config.ts +12 -0
- package/.agents/skills/e2e-testing-patterns/resources/implementation-playbook.md +522 -0
- package/.agents/skills/event-stream-qa-orchestrator/SKILL.md +79 -0
- package/.agents/skills/event-stream-qa-orchestrator/examples/timeline_sample.jsonl +2 -0
- package/.agents/skills/failure-autopsy-and-healing/SKILL.md +66 -0
- package/.agents/skills/failure-autopsy-and-healing/examples/closed_loop_healing_walkthrough.md +48 -0
- package/.agents/skills/failure-autopsy-and-healing/examples/sample_junit_failure.xml +8 -0
- package/.agents/skills/failure-autopsy-and-healing/references/healing_matrix.md +64 -0
- package/.agents/skills/failure-autopsy-and-healing/references/qa_investigation_protocol.md +56 -0
- package/.agents/skills/failure-autopsy-and-healing/scripts/triage_failures.sh +83 -0
- package/.agents/skills/file-and-report-validator/SKILL.md +90 -0
- package/.agents/skills/file-and-report-validator/examples/sample_export_schema.json +14 -0
- package/.agents/skills/flaky-test-sentinel-and-quarantine/SKILL.md +114 -0
- package/.agents/skills/flaky-test-sentinel-and-quarantine/examples/quarantine_registry.json +11 -0
- package/.agents/skills/gherkin-to-suite/SKILL.md +103 -0
- package/.agents/skills/gherkin-to-suite/examples/checkout.feature +39 -0
- package/.agents/skills/gherkin-to-suite/examples/suite_report_sample.json +334 -0
- package/.agents/skills/github-actions-templates/SKILL.md +77 -0
- package/.agents/skills/github-actions-templates/examples/matrix_test_pipeline.yml +8 -0
- package/.agents/skills/graphify-impact-analyzer/SKILL.md +76 -0
- package/.agents/skills/graphify-impact-analyzer/examples/dependency_blast_radius.json +8 -0
- package/.agents/skills/katalon-cli-runner/SKILL.md +76 -0
- package/.agents/skills/katalon-cli-runner/examples/headless_kre_exec.sh +3 -0
- package/.agents/skills/katalon-cli-runner/references/groovy-patterns.md +209 -0
- package/.agents/skills/katalon-cli-runner/references/katalon-api.md +155 -0
- package/.agents/skills/katalon-cli-runner/references/runner_commands.md +67 -0
- package/.agents/skills/lam-script-generator/SKILL.md +123 -0
- package/.agents/skills/lam-script-generator/examples/user_story_sample.md +8 -0
- package/.agents/skills/lean-code-ladder/SKILL.md +94 -0
- package/.agents/skills/lean-code-ladder/examples/ladder_walkthrough.md +37 -0
- package/.agents/skills/lean-impact-scoreboard/SKILL.md +48 -0
- package/.agents/skills/lean-impact-scoreboard/examples/sample_benchmark_gain.md +20 -0
- package/.agents/skills/lean-impact-scoreboard/examples/sample_scoreboard.md +15 -0
- package/.agents/skills/meta-prompt-crafter/SKILL.md +107 -0
- package/.agents/skills/meta-prompt-crafter/examples/qa_prompt_template.md +35 -0
- package/.agents/skills/mipro-prompt-compiler/SKILL.md +59 -0
- package/.agents/skills/mipro-prompt-compiler/examples/compiled_module_sample.json +22 -0
- package/.agents/skills/mipro-prompt-compiler/examples/dspy_assertion_optimizer_case.md +46 -0
- package/.agents/skills/mobile-appium-som/SKILL.md +88 -0
- package/.agents/skills/mobile-appium-som/examples/BaseScreen.java +88 -0
- package/.agents/skills/mobile-appium-som/examples/LoginScreen.java +46 -0
- package/.agents/skills/mobile-appium-som/examples/TC_MobileLogin.java +43 -0
- package/.agents/skills/persistent-planning-files/SKILL.md +108 -0
- package/.agents/skills/persistent-planning-files/examples/task_plan_example.md +56 -0
- package/.agents/skills/playwright-live-interaction/SKILL.md +131 -0
- package/.agents/skills/playwright-live-interaction/examples/live_probe_script.js +5 -0
- package/.agents/skills/playwright-live-interaction/references/advanced_superpowers.md +160 -0
- package/.agents/skills/playwright-live-interaction/references/compact_accessibility_snapshots.md +75 -0
- package/.agents/skills/playwright-live-interaction/references/recipes.md +388 -0
- package/.agents/skills/playwright-live-interaction/references/swarm_orchestration.md +134 -0
- package/.agents/skills/playwright-webapp-testing/SKILL.md +93 -0
- package/.agents/skills/playwright-webapp-testing/examples/server_lifecycle_playwright.py +63 -0
- package/.agents/skills/qa-aci-interface/SKILL.md +67 -0
- package/.agents/skills/qa-aci-interface/examples/surgical_code_window_walkthrough.md +40 -0
- package/.agents/skills/qa-aci-interface/examples/surgical_edit_sample.json +12 -0
- package/.agents/skills/qa-memory-os/SKILL.md +80 -0
- package/.agents/skills/qa-memory-os/examples/archival_memory_sample.json +21 -0
- package/.agents/skills/rbt-manual-testing/SKILL.md +137 -0
- package/.agents/skills/rbt-manual-testing/examples/checkout_rbt_manual_suite.md +25 -0
- package/.agents/skills/rbt-manual-testing/references/field_validation_checklist.md +29 -0
- package/.agents/skills/repo-quality-audit/SKILL.md +68 -0
- package/.agents/skills/repo-quality-audit/examples/sample_audit_walkthrough.md +15 -0
- package/.agents/skills/repo-quality-audit/examples/sample_repo_audit.md +33 -0
- package/.agents/skills/review-spec/SKILL.md +60 -0
- package/.agents/skills/review-spec/examples/pocock_grilling_decision_rubric.md +40 -0
- package/.agents/skills/review-spec/examples/sample_spec_review.md +33 -0
- package/.agents/skills/security-dast-sentinel/SKILL.md +119 -0
- package/.agents/skills/security-dast-sentinel/examples/dast_scan_config.json +10 -0
- package/.agents/skills/security-dast-sentinel/references/AI-AND-LLM.md +113 -0
- package/.agents/skills/security-dast-sentinel/references/ATTACK-CLASSES.md +89 -0
- package/.agents/skills/security-dast-sentinel/references/dast_recipes.ts +33 -0
- package/.agents/skills/self-healing-locator/SKILL.md +86 -0
- package/.agents/skills/self-healing-locator/examples/aom_diff_sample.json +16 -0
- package/.agents/skills/senior-code-review/SKILL.md +108 -0
- package/.agents/skills/senior-code-review/examples/sample_review_walkthrough.md +29 -0
- package/.agents/skills/skillspector-security-guard/SKILL.md +57 -0
- package/.agents/skills/skillspector-security-guard/examples/audit_threat_vectors_report.json +35 -0
- package/.agents/skills/skillspector-security-guard/examples/safe_mcp_config.json +12 -0
- package/.agents/skills/surgical-coding-principles/SKILL.md +89 -0
- package/.agents/skills/surgical-coding-principles/examples/surgical_vs_scope_creep.md +46 -0
- package/.agents/skills/synthetic-test-data-generator/SKILL.md +135 -0
- package/.agents/skills/synthetic-test-data-generator/examples/idempotent_data_recipe.json +9 -0
- package/.agents/skills/systematic-debugging/SKILL.md +100 -0
- package/.agents/skills/systematic-debugging/examples/four_phase_case.md +44 -0
- package/.agents/skills/technical-debt-harvester/SKILL.md +70 -0
- package/.agents/skills/technical-debt-harvester/examples/sample_debt_ledger.md +25 -0
- package/.agents/skills/technical-debt-harvester/examples/sample_ledger_output.md +20 -0
- package/.agents/skills/test-driven-development/SKILL.md +114 -0
- package/.agents/skills/test-driven-development/examples/red_green_refactor_qa.md +78 -0
- package/.agents/skills/token-and-context-optimizer/SKILL.md +70 -0
- package/.agents/skills/token-and-context-optimizer/examples/distilled_log_sample.txt +3 -0
- package/.agents/skills/token-and-context-optimizer/references/context_engineering_guide.md +49 -0
- package/.agents/skills/tot-exploratory-testing/SKILL.md +59 -0
- package/.agents/skills/tot-exploratory-testing/examples/payment_gateway_tot_tree.json +62 -0
- package/.agents/skills/tot-exploratory-testing/examples/tot_graph_sample.json +35 -0
- package/.agents/skills/verification-before-completion/SKILL.md +100 -0
- package/.agents/skills/verification-before-completion/examples/evidence_log_example.md +46 -0
- package/.agents/skills/visual-regression-sentinel/SKILL.md +82 -0
- package/.agents/skills/visual-regression-sentinel/examples/visual_mask_rules.json +9 -0
- package/.agents/skills/wcag-audit-patterns/SKILL.md +77 -0
- package/.agents/skills/wcag-audit-patterns/examples/wcag_compliance_checklist.json +10 -0
- package/.agents/skills/wcag-audit-patterns/resources/implementation-playbook.md +541 -0
- package/.agents/skills/web-agent-gym-benchmarking/SKILL.md +62 -0
- package/.agents/skills/web-agent-gym-benchmarking/examples/benchmark_report_sample.json +22 -0
- package/.agents/skills/web-agent-gym-benchmarking/examples/enterprise_tasks_suite.json +38 -0
- package/.agents/skills/web-vitals-and-performance-profiler/SKILL.md +65 -0
- package/.agents/skills/web-vitals-and-performance-profiler/examples/cwv_budget_policy.json +6 -0
- package/.agents/skills/web-vitals-and-performance-profiler/examples/playwright_cwv_profiler_fixture.ts +118 -0
- package/.agents/templates/completion_report.md +57 -0
- package/.agents/workflows/analyze_requirement_document.md +18 -0
- package/.agents/workflows/export_testcases_excel.md +32 -0
- package/.agents/workflows/generate_combinatorial_test_data.md +28 -0
- package/.agents/workflows/generate_cross_module_test_plan.md +37 -0
- package/.agents/workflows/generate_manual_testcases_rbt.md +56 -0
- package/.agents/workflows/generate_requirements_from_website.md +25 -0
- package/.agents/workflows/generate_testcases_from_requirements.md +21 -0
- package/.agents/workflows/graphify.md +10 -0
- package/.agents/workflows/test-impact.md +15 -0
- package/.agents/workflows/verify.md +34 -0
- package/.cursor/rules/agents.mdc +16 -0
- package/.cursor/rules/language.mdc +7 -0
- package/.cursor/rules/synapse-qa.mdc +24 -0
- package/.cursorrules +27 -0
- package/.dockerignore +53 -0
- package/.pre-commit-hooks.yaml +14 -0
- package/.windsurfrules +26 -0
- package/AGENTS.md +86 -0
- package/CLAUDE.md +54 -0
- package/Dockerfile +81 -0
- package/LICENSE +52 -0
- package/NOTICE +264 -0
- package/README.en.md +172 -0
- package/README.md +171 -2
- package/action.yml +51 -0
- package/agentskills.json +16 -0
- package/bin/agent-qa.js +138 -0
- package/docker-compose.yml +74 -0
- package/docs/ARCHITECTURE.en.md +197 -0
- package/docs/ARCHITECTURE.md +198 -0
- package/docs/CI_CD_INTEGRATION.en.md +170 -0
- package/docs/CI_CD_INTEGRATION.md +170 -0
- package/docs/CLI_REFERENCE.en.md +175 -0
- package/docs/CLI_REFERENCE.md +177 -0
- package/docs/CONTRIBUTING.en.md +49 -0
- package/docs/CONTRIBUTING.md +49 -0
- package/docs/PERFORMANCE_AUDIT_REPORT.md +784 -0
- package/docs/PLUGIN_DEVELOPMENT_GUIDE.md +127 -0
- package/docs/QUALITY_GATES.en.md +121 -0
- package/docs/QUALITY_GATES.md +121 -0
- package/docs/TOKEN_QUOTA_PLAYBOOK.md +41 -0
- package/docs/TOOL_CATALOG.md +129 -0
- package/docs/adopted-ecosystem-tools.md +96 -0
- package/docs/research/EXTERNAL_AGENT_SKILLS_SURVEY.md +1062 -0
- package/docs/research/agent_skill_training_analysis.md +1359 -0
- package/docs/schemas/synapse.config.schema.json +87 -0
- package/package.json +94 -4
- package/plugin.json +31 -0
- package/scripts/generate_skill_examples.py +244 -0
- package/scripts/install.ps1 +112 -0
- package/scripts/install_global_plugin.ps1 +94 -0
- package/scripts/install_global_plugin.sh +49 -0
- package/scripts/lint_skills.ps1 +57 -0
- package/scripts/package_dist.py +337 -0
- package/scripts/setup.sh +59 -0
- package/scripts/update_hub.ps1 +19 -0
- package/scripts/update_hub.sh +15 -0
- package/skills_manifest.json +854 -0
- package/synapse.config.json +32 -0
- package/templates/PROJECT_AI_GUIDE_TEMPLATE.md +111 -0
- package/templates/PROJECT_STATE_TEMPLATE.md +20 -0
- package/templates/ai_bridges/CLAUDE.md +54 -0
- package/templates/ai_bridges/copilot-instructions.md +20 -0
- package/templates/ai_bridges/cursor_synapse_qa.mdc +24 -0
- package/templates/ai_bridges/windsurfrules +26 -0
- package/templates/ci/github-actions-synapse.yml +95 -0
- package/templates/ci/gitlab-ci-synapse.yml +16 -0
- package/templates/ui/index.html +1069 -0
- package/templates/welcome.html.tmpl +2079 -0
- package/tools/.infer_baseline.json +30 -0
- package/tools/TOOLS_RUNBOOK.md +1553 -0
- package/tools/TOOL_CATALOG.json +1769 -0
- package/tools/__init__.py +43 -0
- package/tools/_openapi_parser.py +158 -0
- package/tools/agent_canary.py +525 -0
- package/tools/agentless_patcher.py +417 -0
- package/tools/analyze_project.py +258 -0
- package/tools/api_drift_sentinel.py +208 -0
- package/tools/api_fuzzer.py +762 -0
- package/tools/author_integrity.py +184 -0
- package/tools/auto_heal.py +271 -0
- package/tools/auto_heal_reflexion.py +532 -0
- package/tools/autogen_qa_broker.py +844 -0
- package/tools/benchmark_swarm_context.py +394 -0
- package/tools/browser_helpers.js +746 -0
- package/tools/browsergym_eval.py +236 -0
- package/tools/bug_reporter.py +252 -0
- package/tools/bump_version.py +423 -0
- package/tools/cache_resolver.py +1214 -0
- package/tools/check_env.py +426 -0
- package/tools/check_version_sync.py +256 -0
- package/tools/ci_healing_hook.py +126 -0
- package/tools/cli.py +1598 -0
- package/tools/config_decoupler.py +253 -0
- package/tools/contract_validator.py +141 -0
- package/tools/core/__init__.py +70 -0
- package/tools/core/adapters.py +431 -0
- package/tools/core/circuit_breaker.py +263 -0
- package/tools/core/cli_runtime.py +66 -0
- package/tools/core/file_lock.py +159 -0
- package/tools/core/i18n.py +394 -0
- package/tools/core/memory_bus.py +905 -0
- package/tools/core/process_supervisor.py +332 -0
- package/tools/core/telemetry.py +329 -0
- package/tools/count_tokens.py +1267 -0
- package/tools/create_mock_docx.py +104 -0
- package/tools/dashboard_generator.py +2419 -0
- package/tools/db_sandbox.py +675 -0
- package/tools/debt_harvester.py +237 -0
- package/tools/distill_log.py +161 -0
- package/tools/dspy_qa_signatures.py +356 -0
- package/tools/e2e_flow_prober.py +132 -0
- package/tools/export_postman_collection.py +945 -0
- package/tools/flaky_detector.py +389 -0
- package/tools/fsm_enforcer.py +450 -0
- package/tools/fsm_middleware.py +401 -0
- package/tools/fuzz_payloads.py +197 -0
- package/tools/generate_allure_report.py +88 -0
- package/tools/generate_api_matrix.py +193 -0
- package/tools/generate_jmx_plan.py +1322 -0
- package/tools/generate_sbom.py +252 -0
- package/tools/generate_tc_from_story.py +203 -0
- package/tools/generate_test_reports.py +133 -0
- package/tools/generate_tool_catalog.py +482 -0
- package/tools/gherkin_suite.py +758 -0
- package/tools/git_pre_commit_guard.py +298 -0
- package/tools/goldfish_review.py +366 -0
- package/tools/heal/__init__.py +28 -0
- package/tools/heal_pr_automator.py +220 -0
- package/tools/heuristic_locator_matcher.py +351 -0
- package/tools/hub_publisher.py +623 -0
- package/tools/humanize_linter.py +438 -0
- package/tools/infer_linter.py +977 -0
- package/tools/init_config.py +307 -0
- package/tools/interview_story.py +116 -0
- package/tools/jira_sync.py +566 -0
- package/tools/jtl_analyzer.py +474 -0
- package/tools/lint/__init__.py +30 -0
- package/tools/lint_ai_docs.py +374 -0
- package/tools/lookup_tc.py +165 -0
- package/tools/lookup_xpath.py +167 -0
- package/tools/matrix_sharder.py +148 -0
- package/tools/mcp/__init__.py +18 -0
- package/tools/mcp_docx_server.ps1 +13 -0
- package/tools/mcp_docx_server.py +851 -0
- package/tools/mcp_excel_server.ps1 +13 -0
- package/tools/mcp_excel_server.py +441 -0
- package/tools/mcp_server.py +724 -0
- package/tools/md_to_xlsx.py +327 -0
- package/tools/micro_mutator.py +887 -0
- package/tools/mipro_assertion_tuner.py +210 -0
- package/tools/network_mock_shield.py +311 -0
- package/tools/newman_analyzer.py +384 -0
- package/tools/omni_emitter.py +579 -0
- package/tools/omni_parser.py +450 -0
- package/tools/omni_transpiler.py +168 -0
- package/tools/openxml_guard.py +438 -0
- package/tools/output_formatter.py +182 -0
- package/tools/package_release.py +325 -0
- package/tools/perf/__init__.py +24 -0
- package/tools/pinpoint_failure.py +190 -0
- package/tools/project_state.py +171 -0
- package/tools/qa_event_stream.py +358 -0
- package/tools/repo_map.py +346 -0
- package/tools/report/__init__.py +32 -0
- package/tools/reversible_sandbox.py +344 -0
- package/tools/safety_firewall.py +437 -0
- package/tools/security_coverage_ledger.py +538 -0
- package/tools/security_scanner.py +229 -0
- package/tools/senior_code_review.py +393 -0
- package/tools/setup_project.py +770 -0
- package/tools/skill_collision_guard.py +304 -0
- package/tools/skill_profiles.py +217 -0
- package/tools/skill_vault.py +481 -0
- package/tools/skillspector.py +1278 -0
- package/tools/smart_visual_masker.py +132 -0
- package/tools/spec_drift_sentinel.py +438 -0
- package/tools/swe_qa_aci.py +369 -0
- package/tools/synapse_observer.py +485 -0
- package/tools/synapse_qa_bench.py +190 -0
- package/tools/sync_agent_rules.py +274 -0
- package/tools/telemetry_correlator.py +397 -0
- package/tools/template_excel_exporter.py +514 -0
- package/tools/templates/jmeter-distributed/README.md +54 -0
- package/tools/templates/jmeter-distributed/docker-compose.yml +83 -0
- package/tools/test_impact.py +419 -0
- package/tools/test_memory_os.py +462 -0
- package/tools/textgrad_mutation_optimizer.py +237 -0
- package/tools/tms_sync_bridge.py +834 -0
- package/tools/tot_exploratory_tester.py +239 -0
- package/tools/trace_data_flow.py +240 -0
- package/tools/traffic_session_converter.py +256 -0
- package/tools/trend_analytics.py +314 -0
- package/tools/ui_server.py +401 -0
- package/tools/universal_ir.py +488 -0
- package/tools/update_sentinel.py +383 -0
- package/tools/validate_groovy_scripts.py +173 -0
- package/tools/verify_all.py +1259 -0
- package/tools/visual_diff_canvas.py +143 -0
- package/tools/visual_som_helper.py +550 -0
- package/tools/watch_mode.py +308 -0
- package/tools/wcag_audit.py +239 -0
- package/tools/welcome_page.py +290 -0
|
@@ -0,0 +1,887 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Assertion Sensitivity & Syntactic Micro-Mutation Sentinel (Heuristic)
|
|
4
|
+
---------------------------------------------------------------------
|
|
5
|
+
Evaluates the true defect-catching efficacy of test suites by injecting
|
|
6
|
+
syntactic micro-mutants (inverting operators, flipping booleans, altering boundaries)
|
|
7
|
+
to eradicate 'Tautological Tests' (tests that pass unconditionally without valid assertions).
|
|
8
|
+
|
|
9
|
+
Features:
|
|
10
|
+
- Atomic syntactic fault injection across Groovy, Python, TypeScript, JavaScript
|
|
11
|
+
- Static assertion sensitivity analysis (killing mutants when valid assertions verify downstream logic)
|
|
12
|
+
- Dynamic test execution mode (--test-cmd) for live mutant verification
|
|
13
|
+
- Quality Gatekeeper threshold enforcement (--min-score, default: 80.0%)
|
|
14
|
+
|
|
15
|
+
Implementation Note:
|
|
16
|
+
Static evaluation is a lightweight, heuristic assertion-sensitivity analysis
|
|
17
|
+
(fast, polyglot, token-free), not a compiler-grade mutation testing tool like Stryker or mutmut.
|
|
18
|
+
It measures whether test logic is bounded by active downstream assertions rather than passing unconditionally.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
import os
|
|
22
|
+
import re
|
|
23
|
+
import sys
|
|
24
|
+
import json
|
|
25
|
+
import shlex
|
|
26
|
+
import html as html_lib
|
|
27
|
+
import argparse
|
|
28
|
+
import subprocess
|
|
29
|
+
from datetime import datetime, timezone
|
|
30
|
+
from pathlib import Path
|
|
31
|
+
from typing import List, Dict, Any, Tuple, Optional
|
|
32
|
+
|
|
33
|
+
# Enforce UTF-8 stdout encoding and guard against non-blocking stream BlockingIOError
|
|
34
|
+
for stream in (sys.stdout, sys.stderr):
|
|
35
|
+
if hasattr(stream, 'fileno'):
|
|
36
|
+
try:
|
|
37
|
+
os.set_blocking(stream.fileno(), True)
|
|
38
|
+
except Exception:
|
|
39
|
+
pass
|
|
40
|
+
if hasattr(stream, 'reconfigure'):
|
|
41
|
+
try:
|
|
42
|
+
stream.reconfigure(encoding='utf-8')
|
|
43
|
+
except Exception:
|
|
44
|
+
pass
|
|
45
|
+
|
|
46
|
+
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
47
|
+
HUB_ROOT = os.path.abspath(os.path.join(SCRIPT_DIR, ".."))
|
|
48
|
+
|
|
49
|
+
if SCRIPT_DIR not in sys.path:
|
|
50
|
+
sys.path.insert(0, SCRIPT_DIR)
|
|
51
|
+
|
|
52
|
+
try:
|
|
53
|
+
import test_impact
|
|
54
|
+
except ImportError:
|
|
55
|
+
try:
|
|
56
|
+
from tools import test_impact
|
|
57
|
+
except ImportError:
|
|
58
|
+
test_impact = None
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def resolve_scoped_test_cmd(scoped_template: str, target_file: str, repo_root: Optional[str] = None) -> Tuple[str, List[str]]:
|
|
62
|
+
"""
|
|
63
|
+
Resolves dynamic test runner command targeting only test cases impacted
|
|
64
|
+
by changes to target_file via test_impact.py.
|
|
65
|
+
"""
|
|
66
|
+
root = repo_root or HUB_ROOT
|
|
67
|
+
try:
|
|
68
|
+
rel_path = os.path.relpath(target_file, root).replace("\\", "/") if os.path.isabs(target_file) else target_file.replace("\\", "/")
|
|
69
|
+
|
|
70
|
+
except ValueError:
|
|
71
|
+
rel_path = target_file.replace("\\", "/")
|
|
72
|
+
impacted: List[str] = []
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
if test_impact and hasattr(test_impact, "get_impacted_test_files"):
|
|
76
|
+
try:
|
|
77
|
+
impacted = test_impact.get_impacted_test_files([rel_path], repo_root=root)
|
|
78
|
+
except Exception as err:
|
|
79
|
+
sys.stderr.write(f"Notice: Failed to compute test impact for {rel_path}: {err}\n")
|
|
80
|
+
impacted = []
|
|
81
|
+
|
|
82
|
+
if not impacted:
|
|
83
|
+
# Fallback: if target is itself a test script, run on target
|
|
84
|
+
if "tests/" in rel_path or "Scripts/" in rel_path or rel_path.endswith(("_test.py", ".spec.ts", ".test.ts", ".groovy")) or os.path.basename(rel_path).startswith("test_"):
|
|
85
|
+
impacted = [rel_path]
|
|
86
|
+
|
|
87
|
+
tests_str = " ".join(impacted) if impacted else ""
|
|
88
|
+
if "{test_files}" in scoped_template:
|
|
89
|
+
cmd = scoped_template.replace("{test_files}", tests_str).strip()
|
|
90
|
+
elif "{tests}" in scoped_template:
|
|
91
|
+
cmd = scoped_template.replace("{tests}", tests_str).strip()
|
|
92
|
+
else:
|
|
93
|
+
cmd = f"{scoped_template} {tests_str}".strip() if tests_str else scoped_template.strip()
|
|
94
|
+
|
|
95
|
+
return cmd, impacted
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
# Syntax mutation rules: (Pattern, Replacement, Description)
|
|
99
|
+
MUTATION_RULES = [
|
|
100
|
+
(r"\btrue\b", "false", "Boolean Inversion (true -> false)"),
|
|
101
|
+
(r"\bfalse\b", "true", "Boolean Inversion (false -> true)"),
|
|
102
|
+
(r"\bTrue\b", "False", "Boolean Inversion (True -> False)"),
|
|
103
|
+
(r"\bFalse\b", "True", "Boolean Inversion (False -> True)"),
|
|
104
|
+
(r"\s==\s", " != ", "Equality Inversion (== -> !=)"),
|
|
105
|
+
(r"\s!=\s", " == ", "Inequality Inversion (!= -> ==)"),
|
|
106
|
+
(r"\s>=\s", " < ", "Relational Inversion (>= -> <)"),
|
|
107
|
+
(r"\s<=\s", " > ", "Relational Inversion (<= -> >)"),
|
|
108
|
+
(r"\s>\s", " <= ", "Boundary Shift (> -> <=)"),
|
|
109
|
+
(r"\s<\s", " >= ", "Boundary Shift (< -> >=)"),
|
|
110
|
+
(r"\band\b", "or", "Logical Inversion (and -> or)"),
|
|
111
|
+
(r"\bor\b", "and", "Logical Inversion (or -> and)"),
|
|
112
|
+
(r"\s&&\s", " || ", "Logical AND Inversion (&& -> ||)"),
|
|
113
|
+
(r"\s\|\|\s", " && ", "Logical OR Inversion (|| -> &&)"),
|
|
114
|
+
(r"\s\bis\s", " is not ", "Identity Inversion (is -> is not)"),
|
|
115
|
+
(r"\s\bis not\s", " is ", "Identity Inversion (is not -> is)"),
|
|
116
|
+
(r"\s\+\s", " - ", "Arithmetic Inversion (+ -> -)"),
|
|
117
|
+
(r"\s-\s", " + ", "Arithmetic Inversion (- -> +)"),
|
|
118
|
+
(r"\breturn\s+true\b", "return false", "Return Value Inversion (return true -> return false)"),
|
|
119
|
+
(r"\breturn\s+false\b", "return true", "Return Value Inversion (return false -> return true)"),
|
|
120
|
+
(r"\breturn\s+True\b", "return False", "Return Value Inversion (return True -> return False)"),
|
|
121
|
+
(r"\breturn\s+False\b", "return True", "Return Value Inversion (return False -> return True)"),
|
|
122
|
+
(r"\breturn\s+0\b", "return -1", "Return Value Shift (return 0 -> return -1)"),
|
|
123
|
+
(r"\s\?\?\s", " || ", "Nullish Coalescing Inversion (?? -> ||)"),
|
|
124
|
+
]
|
|
125
|
+
|
|
126
|
+
# Action statement pattern for Statement Deletion Mutants
|
|
127
|
+
ACTION_STATEMENT_PATTERN = re.compile(
|
|
128
|
+
r'\.(click|submit|save|update|delete|send|fill|press|type|execute|check|uncheck|hover|dragTo|selectOption|clear|focus|setInputFiles)\s*\(',
|
|
129
|
+
re.IGNORECASE
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
# Assertion and verification patterns
|
|
133
|
+
ASSERTION_PATTERN = re.compile(
|
|
134
|
+
r'\b(verify[A-Za-z0-9_]*|assert[A-Za-z0-9_]*|waitForToast|checkStatus|assertEquals|assertTrue|assertFalse|assertThat|expect|ensure[A-Z][A-Za-z0-9_]*Exists)\b'
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
# Tautological / fake assertions that do not test application logic
|
|
138
|
+
TAUTOLOGY_PATTERN = re.compile(
|
|
139
|
+
r'(?:assert\s+(?:true|1\s*==\s*1)\b'
|
|
140
|
+
r'|\bassert\s+([a-zA-Z0-9_\.]+(?:\([^)]*\))?)\s*==\s*\1\b'
|
|
141
|
+
r'|\bassert\s+(?:len\s*\([^)]*\)|[a-zA-Z0-9_\.]+\.(?:length|size\(\)))\s*(?:>=\s*0|>\s*-(?:1|0))\b'
|
|
142
|
+
r'|assertEquals\s*\(\s*([a-zA-Z_]\w*)\s*,\s*\1\s*\)'
|
|
143
|
+
r'|expect\s*\(\s*([a-zA-Z_]\w*)\s*\)\.toBe\s*\(\s*\1\s*\)'
|
|
144
|
+
r'|assertTrue\s*\(\s*true\s*\))',
|
|
145
|
+
re.IGNORECASE
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
EMPTY_CATCH_PATTERN = re.compile(
|
|
149
|
+
r'catch\s*\([^\)]*\)\s*\{\s*\}',
|
|
150
|
+
re.MULTILINE
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def is_inside_quotes(line: str, pos: int) -> bool:
|
|
155
|
+
"""Determines whether a character position in a line is enclosed within string quotes."""
|
|
156
|
+
in_single = False
|
|
157
|
+
in_double = False
|
|
158
|
+
escaped = False
|
|
159
|
+
for i, ch in enumerate(line):
|
|
160
|
+
if i == pos:
|
|
161
|
+
return in_single or in_double
|
|
162
|
+
if escaped:
|
|
163
|
+
escaped = False
|
|
164
|
+
continue
|
|
165
|
+
if ch == '\\':
|
|
166
|
+
escaped = True
|
|
167
|
+
continue
|
|
168
|
+
if ch == "'" and not in_double:
|
|
169
|
+
in_single = not in_single
|
|
170
|
+
elif ch == '"' and not in_single:
|
|
171
|
+
in_double = not in_double
|
|
172
|
+
return in_single or in_double
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def mask_non_executable_contexts(code: str) -> str:
|
|
176
|
+
"""Replaces multiline strings, docstrings, comments and string fixtures with blank lines
|
|
177
|
+
to preserve exact line numbering while eliminating false positives during static analysis."""
|
|
178
|
+
lines = code.splitlines(keepends=True)
|
|
179
|
+
in_ml = False
|
|
180
|
+
ml_char = ""
|
|
181
|
+
masked = []
|
|
182
|
+
triple_d = '"""'
|
|
183
|
+
triple_s = "'''"
|
|
184
|
+
|
|
185
|
+
for line in lines:
|
|
186
|
+
stripped = line.strip()
|
|
187
|
+
if in_ml:
|
|
188
|
+
if ml_char in stripped:
|
|
189
|
+
in_ml = False
|
|
190
|
+
ml_char = ""
|
|
191
|
+
masked.append("\n")
|
|
192
|
+
continue
|
|
193
|
+
|
|
194
|
+
for q in (triple_d, triple_s):
|
|
195
|
+
if q in stripped and stripped.count(q) % 2 == 1:
|
|
196
|
+
in_ml = True
|
|
197
|
+
ml_char = q
|
|
198
|
+
break
|
|
199
|
+
|
|
200
|
+
if in_ml:
|
|
201
|
+
masked.append("\n")
|
|
202
|
+
else:
|
|
203
|
+
# Mask string fixtures containing catch blocks or test code samples
|
|
204
|
+
if "catch" in stripped and ('"' in stripped or "'" in stripped):
|
|
205
|
+
masked.append("\n")
|
|
206
|
+
else:
|
|
207
|
+
masked.append(line)
|
|
208
|
+
|
|
209
|
+
return "".join(masked)
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def generate_mutants_for_code(code: str, file_path: str = "") -> List[Dict[str, Any]]:
|
|
213
|
+
"""
|
|
214
|
+
Generates single-point syntactic mutants from source code string.
|
|
215
|
+
Each mutant represents exactly one atomic fault injection.
|
|
216
|
+
Only generates mutants on active executable lines, ignoring comments, multiline strings & runners.
|
|
217
|
+
"""
|
|
218
|
+
lines = code.splitlines(keepends=True)
|
|
219
|
+
mutants = []
|
|
220
|
+
mutant_id = 1
|
|
221
|
+
in_multiline = False
|
|
222
|
+
ml_char = ""
|
|
223
|
+
triple_d = '"""'
|
|
224
|
+
triple_s = "'''"
|
|
225
|
+
|
|
226
|
+
for line_idx, line in enumerate(lines):
|
|
227
|
+
stripped = line.strip()
|
|
228
|
+
|
|
229
|
+
# Track multiline docstrings and string assignments
|
|
230
|
+
if in_multiline:
|
|
231
|
+
if ml_char in stripped:
|
|
232
|
+
in_multiline = False
|
|
233
|
+
ml_char = ""
|
|
234
|
+
continue
|
|
235
|
+
|
|
236
|
+
for q in (triple_d, triple_s):
|
|
237
|
+
if q in stripped and stripped.count(q) % 2 == 1:
|
|
238
|
+
in_multiline = True
|
|
239
|
+
ml_char = q
|
|
240
|
+
break
|
|
241
|
+
|
|
242
|
+
if in_multiline:
|
|
243
|
+
continue
|
|
244
|
+
|
|
245
|
+
# Skip pure comments or imports
|
|
246
|
+
if stripped.startswith(("//", "#", "/*", "*", "import", "package", "from")):
|
|
247
|
+
continue
|
|
248
|
+
|
|
249
|
+
# Skip test runner boilerplate, entry points, and file writing harness logic
|
|
250
|
+
if re.search(r"\b(if\s+__name__\s*==|unittest\.main\(\)|sys\.exit\(|\.write\()", stripped):
|
|
251
|
+
continue
|
|
252
|
+
|
|
253
|
+
# Skip tuples/lists of mock code templates in data fixtures
|
|
254
|
+
if stripped.startswith("(") and ('"' in stripped or "'" in stripped):
|
|
255
|
+
continue
|
|
256
|
+
|
|
257
|
+
# Statement Deletion Mutant (Simulates omitted UI action or bypassed step)
|
|
258
|
+
if ACTION_STATEMENT_PATTERN.search(stripped) and not ASSERTION_PATTERN.search(stripped):
|
|
259
|
+
indent = line[:len(line) - len(line.lstrip())]
|
|
260
|
+
if file_path.endswith((".py", ".pyw")):
|
|
261
|
+
mutated_line = f"{indent}pass # MUTANT_DELETED: {stripped}\n"
|
|
262
|
+
else:
|
|
263
|
+
mutated_line = f"{indent}// MUTANT_DELETED: {stripped}\n"
|
|
264
|
+
mutated_lines = list(lines)
|
|
265
|
+
mutated_lines[line_idx] = mutated_line
|
|
266
|
+
mutants.append({
|
|
267
|
+
"id": f"MUT-{mutant_id:04d}",
|
|
268
|
+
"file": file_path,
|
|
269
|
+
"line": line_idx + 1,
|
|
270
|
+
"original_snippet": line.strip(),
|
|
271
|
+
"mutated_snippet": mutated_line.strip(),
|
|
272
|
+
"description": "Statement Deletion (Omit critical action/mutation call)",
|
|
273
|
+
"mutated_code": "".join(mutated_lines),
|
|
274
|
+
"status": "SURVIVED"
|
|
275
|
+
})
|
|
276
|
+
mutant_id += 1
|
|
277
|
+
if len(mutants) >= 20:
|
|
278
|
+
return mutants
|
|
279
|
+
|
|
280
|
+
for pattern, replacement, desc in MUTATION_RULES:
|
|
281
|
+
matches = list(re.finditer(pattern, line))
|
|
282
|
+
for m in matches:
|
|
283
|
+
start, end = m.span()
|
|
284
|
+
# Skip mutations occurring inside string literals
|
|
285
|
+
if is_inside_quotes(line, start):
|
|
286
|
+
continue
|
|
287
|
+
|
|
288
|
+
# Skip arithmetic mutation on string concatenations
|
|
289
|
+
if desc.startswith("Arithmetic Inversion"):
|
|
290
|
+
left = line[:start].rstrip()
|
|
291
|
+
right = line[end:].lstrip()
|
|
292
|
+
if left.endswith(('"', "'")) or right.startswith(('"', "'")):
|
|
293
|
+
continue
|
|
294
|
+
if re.search(r'\b(?:String|str|println|print|log|logInfo|comment|append)\b', line, re.IGNORECASE):
|
|
295
|
+
if "'" in line or '"' in line:
|
|
296
|
+
continue
|
|
297
|
+
|
|
298
|
+
mutated_line = line[:start] + replacement + line[end:]
|
|
299
|
+
mutated_lines = list(lines)
|
|
300
|
+
mutated_lines[line_idx] = mutated_line
|
|
301
|
+
mutated_code = "".join(mutated_lines)
|
|
302
|
+
|
|
303
|
+
mutants.append({
|
|
304
|
+
"id": f"MUT-{mutant_id:04d}",
|
|
305
|
+
"file": file_path,
|
|
306
|
+
"line": line_idx + 1,
|
|
307
|
+
"original_snippet": line.strip(),
|
|
308
|
+
"mutated_snippet": mutated_line.strip(),
|
|
309
|
+
"description": desc,
|
|
310
|
+
"mutated_code": mutated_code,
|
|
311
|
+
"status": "SURVIVED"
|
|
312
|
+
})
|
|
313
|
+
mutant_id += 1
|
|
314
|
+
|
|
315
|
+
# Cap per file to avoid combinatorial explosion
|
|
316
|
+
if len(mutants) >= 20:
|
|
317
|
+
return mutants
|
|
318
|
+
|
|
319
|
+
return mutants
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
def evaluate_mutation_score(killed_count: int, total_count: int) -> float:
|
|
323
|
+
"""Calculates mutation score as percentage of mutants killed."""
|
|
324
|
+
if total_count == 0:
|
|
325
|
+
return 0.0
|
|
326
|
+
return round((killed_count / total_count) * 100.0, 2)
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
def evaluate_mutants_statically(code: str, mutants: List[Dict[str, Any]]) -> Tuple[List[Dict[str, Any]], float]:
|
|
330
|
+
"""
|
|
331
|
+
Static assertion sensitivity evaluation:
|
|
332
|
+
- If file has zero assertions or only tautological assertions (e.g. assert true): all mutants SURVIVE.
|
|
333
|
+
- If mutant alters an assertion directly: mutant is KILLED.
|
|
334
|
+
- If mutant alters logic that is verified downstream by an active assertion: mutant is KILLED.
|
|
335
|
+
- If mutant is inside an unasserted block or swallowed exception: mutant SURVIVES.
|
|
336
|
+
"""
|
|
337
|
+
if not mutants:
|
|
338
|
+
return mutants, 0.0
|
|
339
|
+
|
|
340
|
+
lines = code.splitlines()
|
|
341
|
+
has_empty_catch = bool(EMPTY_CATCH_PATTERN.search(code))
|
|
342
|
+
|
|
343
|
+
# Identify lines containing assertions
|
|
344
|
+
assertion_entries = []
|
|
345
|
+
for idx, line in enumerate(lines, start=1):
|
|
346
|
+
s = line.strip()
|
|
347
|
+
if s.startswith(("//", "#", "/*")):
|
|
348
|
+
continue
|
|
349
|
+
if ASSERTION_PATTERN.search(s) and not TAUTOLOGY_PATTERN.search(s):
|
|
350
|
+
assertion_entries.append((idx, s))
|
|
351
|
+
|
|
352
|
+
# Zero valid assertions across code -> all mutants survive (Fake Pass!)
|
|
353
|
+
if not assertion_entries:
|
|
354
|
+
for m in mutants:
|
|
355
|
+
m["status"] = "SURVIVED"
|
|
356
|
+
m["reason"] = "No valid assertions found in test script (Fake-Pass Trap)"
|
|
357
|
+
return mutants, 0.0
|
|
358
|
+
|
|
359
|
+
COMMON_KEYWORDS = {
|
|
360
|
+
"if", "else", "def", "return", "for", "in", "and", "or", "not", "val", "var",
|
|
361
|
+
"let", "const", "True", "False", "None", "null", "int", "str", "float", "bool",
|
|
362
|
+
"function", "class", "this", "self"
|
|
363
|
+
}
|
|
364
|
+
DOMAIN_TEST_NOISE = {
|
|
365
|
+
"page", "await", "expect", "browser", "driver", "window", "document",
|
|
366
|
+
"locator", "WebUI", "findTestObject", "cy", "playwright"
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
killed_count = 0
|
|
370
|
+
for m in mutants:
|
|
371
|
+
m_line = m["line"]
|
|
372
|
+
snippet = m["original_snippet"]
|
|
373
|
+
|
|
374
|
+
# Case 1: Mutation directly in an assertion statement
|
|
375
|
+
if ASSERTION_PATTERN.search(snippet):
|
|
376
|
+
if TAUTOLOGY_PATTERN.search(snippet):
|
|
377
|
+
m["status"] = "SURVIVED"
|
|
378
|
+
m["reason"] = "Mutant in tautological/dummy assertion - cannot kill mutant without genuine assertion logic"
|
|
379
|
+
continue
|
|
380
|
+
m["status"] = "KILLED"
|
|
381
|
+
m["reason"] = "Direct assertion mutation caught by verification condition"
|
|
382
|
+
killed_count += 1
|
|
383
|
+
continue
|
|
384
|
+
|
|
385
|
+
# Case 2: Mutation in logic followed by downstream assertions with variable dataflow linkage
|
|
386
|
+
tokens = (set(re.findall(r'\b[a-zA-Z_][a-zA-Z0-9_]*\b', snippet)) - COMMON_KEYWORDS - DOMAIN_TEST_NOISE)
|
|
387
|
+
tokens = {t for t in tokens if len(t) > 1}
|
|
388
|
+
downstream = [
|
|
389
|
+
(a_line, a_text) for a_line, a_text in assertion_entries
|
|
390
|
+
if a_line >= m_line and a_line - m_line <= 45
|
|
391
|
+
]
|
|
392
|
+
if downstream and not has_empty_catch and tokens:
|
|
393
|
+
# 1-hop dataflow propagation across intermediate lines between m_line and downstream assertions
|
|
394
|
+
max_line = min(len(lines), m_line + 45)
|
|
395
|
+
dataflow_tokens = set(tokens)
|
|
396
|
+
|
|
397
|
+
# If current line is an argument or continuation of a multiline assignment (e.g. res = func(...)),
|
|
398
|
+
# look backward up to 8 lines to capture the enclosing target variable.
|
|
399
|
+
for back_idx in range(max(0, m_line - 8), m_line):
|
|
400
|
+
asgn_back = re.match(r'^\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*=', lines[back_idx])
|
|
401
|
+
if asgn_back:
|
|
402
|
+
dataflow_tokens.add(asgn_back.group(1))
|
|
403
|
+
|
|
404
|
+
for idx in range(m_line, max_line):
|
|
405
|
+
l_code = lines[idx]
|
|
406
|
+
asgn = re.match(r'^\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*=', l_code)
|
|
407
|
+
if asgn:
|
|
408
|
+
tgt = asgn.group(1)
|
|
409
|
+
if any(re.search(rf'\b{re.escape(t)}\b', l_code) for t in dataflow_tokens):
|
|
410
|
+
dataflow_tokens.add(tgt)
|
|
411
|
+
destruct = re.match(r'^\s*(?:(?:const|let|var|val)\s+)?[\{\(]([^\}\)]+)[\}\)]\s*=', l_code)
|
|
412
|
+
if destruct:
|
|
413
|
+
vars_in_destruct = [v.strip().split(':')[0].strip() for v in destruct.group(1).split(',') if v.strip()]
|
|
414
|
+
if any(re.search(rf'\b{re.escape(t)}\b', l_code) for t in dataflow_tokens):
|
|
415
|
+
for v in vars_in_destruct:
|
|
416
|
+
if re.match(r'^[a-zA-Z_][a-zA-Z0-9_]*$', v):
|
|
417
|
+
dataflow_tokens.add(v)
|
|
418
|
+
|
|
419
|
+
# Check if any assertion references the variables mutated in this logic branch or downstream dataflow
|
|
420
|
+
has_variable_link = any(any(re.search(rf'\b{re.escape(tok)}\b', a_text) for tok in dataflow_tokens) for _, a_text in downstream)
|
|
421
|
+
if has_variable_link:
|
|
422
|
+
m["status"] = "KILLED"
|
|
423
|
+
m["reason"] = f"Logic mutant caught by downstream assertion referencing mutated state (line {downstream[0][0]})"
|
|
424
|
+
killed_count += 1
|
|
425
|
+
continue
|
|
426
|
+
|
|
427
|
+
# Case 3: Action statement deletion caught by downstream verification in the same test step
|
|
428
|
+
if m["description"].startswith("Statement Deletion") and downstream and not has_empty_catch:
|
|
429
|
+
near_downstream = [a for a in downstream if 0 <= a[0] - m_line <= 25]
|
|
430
|
+
if near_downstream:
|
|
431
|
+
m["status"] = "KILLED"
|
|
432
|
+
m["reason"] = f"Action statement deletion caught by downstream verification (line {near_downstream[0][0]})"
|
|
433
|
+
killed_count += 1
|
|
434
|
+
continue
|
|
435
|
+
|
|
436
|
+
m["status"] = "SURVIVED"
|
|
437
|
+
m["reason"] = "Mutant survived: no downstream assertion validates the mutated variables"
|
|
438
|
+
|
|
439
|
+
score = evaluate_mutation_score(killed_count, len(mutants))
|
|
440
|
+
return mutants, score
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
def evaluate_mutants_dynamically(file_path: str, code: str, mutants: List[Dict[str, Any]], test_cmd: str, timeout: float = 60.0) -> Tuple[List[Dict[str, Any]], float]:
|
|
444
|
+
"""
|
|
445
|
+
Executes live mutation testing by injecting mutants into disk file and executing test_cmd.
|
|
446
|
+
If the test command fails (exit code != 0), the mutant is KILLED by the test suite.
|
|
447
|
+
If the test command passes (exit code == 0), the mutant SURVIVED (unasserted logic branch).
|
|
448
|
+
Safely restores original file content in all cases.
|
|
449
|
+
"""
|
|
450
|
+
if not mutants:
|
|
451
|
+
return mutants, 0.0
|
|
452
|
+
|
|
453
|
+
use_shell = (sys.platform == "win32") and isinstance(test_cmd, str)
|
|
454
|
+
cmd_args = test_cmd if use_shell else (shlex.split(test_cmd, posix=sys.platform != "win32") if isinstance(test_cmd, str) else test_cmd)
|
|
455
|
+
|
|
456
|
+
# F15: Baseline execution check - test suite must be GREEN on pristine code
|
|
457
|
+
try:
|
|
458
|
+
baseline_proc = subprocess.run(
|
|
459
|
+
cmd_args,
|
|
460
|
+
shell=use_shell,
|
|
461
|
+
capture_output=True,
|
|
462
|
+
timeout=int(timeout),
|
|
463
|
+
text=True
|
|
464
|
+
)
|
|
465
|
+
if baseline_proc.returncode != 0:
|
|
466
|
+
for m in mutants:
|
|
467
|
+
m["status"] = "SURVIVED"
|
|
468
|
+
m["reason"] = f"Baseline test run failed (exit code {baseline_proc.returncode}). Tests must pass on clean code before mutation."
|
|
469
|
+
return mutants, 0.0
|
|
470
|
+
except subprocess.TimeoutExpired:
|
|
471
|
+
for m in mutants:
|
|
472
|
+
m["status"] = "SURVIVED"
|
|
473
|
+
m["reason"] = f"Baseline execution error: timed out after {int(timeout)} seconds"
|
|
474
|
+
return mutants, 0.0
|
|
475
|
+
except Exception as e:
|
|
476
|
+
for m in mutants:
|
|
477
|
+
m["status"] = "SURVIVED"
|
|
478
|
+
m["reason"] = f"Baseline execution error: {e}"
|
|
479
|
+
return mutants, 0.0
|
|
480
|
+
|
|
481
|
+
killed_count = 0
|
|
482
|
+
valid_mutants_count = 0
|
|
483
|
+
abs_path = os.path.abspath(file_path)
|
|
484
|
+
backup_path = abs_path + ".synapse_mutator_bak"
|
|
485
|
+
|
|
486
|
+
# F3 Safety Discipline: Create a dedicated atomic backup file
|
|
487
|
+
# and guarantee recovery via try/finally and os.replace
|
|
488
|
+
try:
|
|
489
|
+
with open(backup_path, "w", encoding="utf-8") as bf:
|
|
490
|
+
bf.write(code)
|
|
491
|
+
|
|
492
|
+
for m in mutants:
|
|
493
|
+
mutated_code = m["mutated_code"]
|
|
494
|
+
|
|
495
|
+
# F14: Syntax validation for Python - discard invalid syntactic mutants
|
|
496
|
+
if file_path.endswith((".py", ".pyw")):
|
|
497
|
+
try:
|
|
498
|
+
compile(mutated_code, file_path, "exec")
|
|
499
|
+
except SyntaxError:
|
|
500
|
+
m["status"] = "INVALID_SYNTAX"
|
|
501
|
+
m["reason"] = "Mutant generated invalid Python syntax; discarded to prevent false killed verdict"
|
|
502
|
+
continue
|
|
503
|
+
|
|
504
|
+
valid_mutants_count += 1
|
|
505
|
+
with open(abs_path, "w", encoding="utf-8") as f:
|
|
506
|
+
f.write(mutated_code)
|
|
507
|
+
|
|
508
|
+
try:
|
|
509
|
+
proc = subprocess.run(
|
|
510
|
+
cmd_args,
|
|
511
|
+
shell=use_shell,
|
|
512
|
+
capture_output=True,
|
|
513
|
+
timeout=int(timeout),
|
|
514
|
+
text=True
|
|
515
|
+
)
|
|
516
|
+
if proc.returncode != 0:
|
|
517
|
+
m["status"] = "KILLED"
|
|
518
|
+
m["reason"] = f"Dynamic test caught mutant: command failed (exit code {proc.returncode})"
|
|
519
|
+
killed_count += 1
|
|
520
|
+
else:
|
|
521
|
+
m["status"] = "SURVIVED"
|
|
522
|
+
m["reason"] = "Dynamic test suite passed unconditionally: missing assertion for this mutant."
|
|
523
|
+
except subprocess.TimeoutExpired:
|
|
524
|
+
# F16: Inconclusive timeout does not count as killed
|
|
525
|
+
m["status"] = "TIMED_OUT"
|
|
526
|
+
m["reason"] = f"Mutant execution timed out (> {int(timeout)}s): inconclusive assertion sensitivity"
|
|
527
|
+
except Exception as e:
|
|
528
|
+
m["status"] = "SURVIVED"
|
|
529
|
+
m["reason"] = f"Test execution error: {e}"
|
|
530
|
+
finally:
|
|
531
|
+
# Atomic restore guaranteed from backup file
|
|
532
|
+
if os.path.exists(backup_path):
|
|
533
|
+
with open(backup_path, "r", encoding="utf-8") as bf:
|
|
534
|
+
clean_content = bf.read()
|
|
535
|
+
with open(abs_path, "w", encoding="utf-8") as f:
|
|
536
|
+
f.write(clean_content)
|
|
537
|
+
try:
|
|
538
|
+
os.remove(backup_path)
|
|
539
|
+
except OSError as err:
|
|
540
|
+
sys.stderr.write(f"Notice: Could not remove backup: {err}\n")
|
|
541
|
+
else:
|
|
542
|
+
with open(abs_path, "w", encoding="utf-8") as f:
|
|
543
|
+
f.write(code)
|
|
544
|
+
|
|
545
|
+
total_eval = valid_mutants_count if valid_mutants_count > 0 else len(mutants)
|
|
546
|
+
score = evaluate_mutation_score(killed_count, total_eval)
|
|
547
|
+
return mutants, score
|
|
548
|
+
|
|
549
|
+
|
|
550
|
+
def is_targetable_source_file(filename: str) -> bool:
|
|
551
|
+
"""Checks whether a file is an actionable test/page script rather than a config/declaration file."""
|
|
552
|
+
base = os.path.basename(filename).lower()
|
|
553
|
+
if base in {"conftest.py", "setup.py", "__init__.py"}:
|
|
554
|
+
return False
|
|
555
|
+
if base.endswith(".d.ts"):
|
|
556
|
+
return False
|
|
557
|
+
if any(cfg in base for cfg in [".config.", "config.", ".conf.", "conf."]):
|
|
558
|
+
return False
|
|
559
|
+
return True
|
|
560
|
+
|
|
561
|
+
|
|
562
|
+
def scan_directory_for_mutants(target_dir: str) -> List[Dict[str, Any]]:
|
|
563
|
+
"""Scans target test/page scripts and generates a collection of mutants."""
|
|
564
|
+
all_mutants = []
|
|
565
|
+
target_path = Path(target_dir)
|
|
566
|
+
|
|
567
|
+
valid_exts = {".groovy", ".py", ".ts", ".js"}
|
|
568
|
+
for root, _, files in os.walk(target_path):
|
|
569
|
+
for f in files:
|
|
570
|
+
if any(f.endswith(ext) for ext in valid_exts) and is_targetable_source_file(f):
|
|
571
|
+
full_path = os.path.join(root, f)
|
|
572
|
+
try:
|
|
573
|
+
with open(full_path, "r", encoding="utf-8", errors="ignore") as fp:
|
|
574
|
+
code = fp.read()
|
|
575
|
+
rel_path = os.path.relpath(full_path, target_dir)
|
|
576
|
+
file_mutants = generate_mutants_for_code(code, file_path=rel_path)
|
|
577
|
+
all_mutants.extend(file_mutants)
|
|
578
|
+
except (OSError, UnicodeDecodeError):
|
|
579
|
+
code = ""
|
|
580
|
+
return all_mutants
|
|
581
|
+
|
|
582
|
+
|
|
583
|
+
def evaluate_target(
|
|
584
|
+
target_path: str,
|
|
585
|
+
min_score: float = 80.0,
|
|
586
|
+
test_cmd: str = "",
|
|
587
|
+
scoped_test_cmd: str = "",
|
|
588
|
+
timeout: float = 60.0,
|
|
589
|
+
min_file_score: float = 0.0
|
|
590
|
+
) -> Dict[str, Any]:
|
|
591
|
+
"""
|
|
592
|
+
Evaluates target file or directory for mutation robustness.
|
|
593
|
+
Dispatches to live test execution if test_cmd or scoped_test_cmd is provided, or static heuristic otherwise.
|
|
594
|
+
When scoped_test_cmd is passed, dynamically resolves impacted test cases via test_impact.py.
|
|
595
|
+
"""
|
|
596
|
+
target = os.path.abspath(target_path)
|
|
597
|
+
all_mutants = []
|
|
598
|
+
if scoped_test_cmd:
|
|
599
|
+
exec_mode = "DYNAMIC_SCOPED"
|
|
600
|
+
elif test_cmd:
|
|
601
|
+
exec_mode = "DYNAMIC"
|
|
602
|
+
else:
|
|
603
|
+
exec_mode = "STATIC"
|
|
604
|
+
|
|
605
|
+
impacted_map: Dict[str, List[str]] = {}
|
|
606
|
+
|
|
607
|
+
# Determine effective repository root
|
|
608
|
+
eff_root = HUB_ROOT
|
|
609
|
+
curr_p = os.path.dirname(target) if os.path.isfile(target) else target
|
|
610
|
+
while curr_p and os.path.dirname(curr_p) != curr_p:
|
|
611
|
+
if os.path.exists(os.path.join(curr_p, ".git")) or os.path.exists(os.path.join(curr_p, "skills_manifest.json")):
|
|
612
|
+
eff_root = curr_p
|
|
613
|
+
break
|
|
614
|
+
curr_p = os.path.dirname(curr_p)
|
|
615
|
+
|
|
616
|
+
if os.path.isfile(target):
|
|
617
|
+
with open(target, "r", encoding="utf-8", errors="ignore") as f:
|
|
618
|
+
code = f.read()
|
|
619
|
+
mutants = generate_mutants_for_code(code, file_path=os.path.basename(target))
|
|
620
|
+
if scoped_test_cmd:
|
|
621
|
+
resolved_cmd, impacted_files = resolve_scoped_test_cmd(scoped_test_cmd, target, repo_root=eff_root)
|
|
622
|
+
impacted_map[os.path.basename(target)] = impacted_files
|
|
623
|
+
if ("{test_files}" in scoped_test_cmd or "{tests}" in scoped_test_cmd) and not impacted_files:
|
|
624
|
+
for m in mutants:
|
|
625
|
+
m["status"] = "SURVIVED"
|
|
626
|
+
m["reason"] = "No impacted test cases identified by test_impact analysis to verify this target."
|
|
627
|
+
evaluated_mutants = mutants
|
|
628
|
+
score = 0.0
|
|
629
|
+
else:
|
|
630
|
+
evaluated_mutants, score = evaluate_mutants_dynamically(target, code, mutants, resolved_cmd, timeout=timeout)
|
|
631
|
+
elif test_cmd:
|
|
632
|
+
evaluated_mutants, score = evaluate_mutants_dynamically(target, code, mutants, test_cmd, timeout=timeout)
|
|
633
|
+
else:
|
|
634
|
+
masked_code = mask_non_executable_contexts(code)
|
|
635
|
+
evaluated_mutants, score = evaluate_mutants_statically(masked_code, mutants)
|
|
636
|
+
all_mutants.extend(evaluated_mutants)
|
|
637
|
+
file_scores = {os.path.basename(target): score}
|
|
638
|
+
else:
|
|
639
|
+
valid_exts = {".groovy", ".py", ".ts", ".js"}
|
|
640
|
+
file_scores = {}
|
|
641
|
+
for root, _, files in os.walk(target):
|
|
642
|
+
for filename in files:
|
|
643
|
+
if any(filename.endswith(ext) for ext in valid_exts) and is_targetable_source_file(filename):
|
|
644
|
+
file_full = os.path.join(root, filename)
|
|
645
|
+
try:
|
|
646
|
+
with open(file_full, "r", encoding="utf-8", errors="ignore") as fp:
|
|
647
|
+
code = fp.read()
|
|
648
|
+
rel_path = os.path.relpath(file_full, target)
|
|
649
|
+
f_mutants = generate_mutants_for_code(code, file_path=rel_path)
|
|
650
|
+
if f_mutants:
|
|
651
|
+
if scoped_test_cmd:
|
|
652
|
+
resolved_cmd, impacted_files = resolve_scoped_test_cmd(scoped_test_cmd, file_full, repo_root=eff_root)
|
|
653
|
+
impacted_map[rel_path] = impacted_files
|
|
654
|
+
if ("{test_files}" in scoped_test_cmd or "{tests}" in scoped_test_cmd) and not impacted_files:
|
|
655
|
+
for m in f_mutants:
|
|
656
|
+
m["status"] = "SURVIVED"
|
|
657
|
+
m["reason"] = "No impacted test cases identified by test_impact analysis to verify this target."
|
|
658
|
+
eval_m = f_mutants
|
|
659
|
+
f_score = 0.0
|
|
660
|
+
else:
|
|
661
|
+
eval_m, f_score = evaluate_mutants_dynamically(file_full, code, f_mutants, resolved_cmd, timeout=timeout)
|
|
662
|
+
elif test_cmd:
|
|
663
|
+
eval_m, f_score = evaluate_mutants_dynamically(file_full, code, f_mutants, test_cmd, timeout=timeout)
|
|
664
|
+
else:
|
|
665
|
+
masked_code = mask_non_executable_contexts(code)
|
|
666
|
+
eval_m, f_score = evaluate_mutants_statically(masked_code, f_mutants)
|
|
667
|
+
all_mutants.extend(eval_m)
|
|
668
|
+
file_scores[rel_path] = f_score
|
|
669
|
+
except (OSError, UnicodeDecodeError):
|
|
670
|
+
code = ""
|
|
671
|
+
|
|
672
|
+
killed_count = sum(1 for m in all_mutants if m["status"] == "KILLED")
|
|
673
|
+
score = evaluate_mutation_score(killed_count, len(all_mutants))
|
|
674
|
+
|
|
675
|
+
killed = sum(1 for m in all_mutants if m["status"] == "KILLED")
|
|
676
|
+
survived = sum(1 for m in all_mutants if m["status"] == "SURVIVED")
|
|
677
|
+
no_mutants = (len(all_mutants) == 0)
|
|
678
|
+
passed = (score >= min_score) and not no_mutants
|
|
679
|
+
|
|
680
|
+
failed_files = {}
|
|
681
|
+
if not os.path.isfile(target) and min_file_score > 0.0:
|
|
682
|
+
failed_files = {f: s for f, s in file_scores.items() if s < min_file_score}
|
|
683
|
+
if failed_files:
|
|
684
|
+
passed = False
|
|
685
|
+
|
|
686
|
+
report_res = {
|
|
687
|
+
"target": target,
|
|
688
|
+
"mode": exec_mode,
|
|
689
|
+
"is_heuristic_static": (exec_mode == "STATIC"),
|
|
690
|
+
"total_mutants": len(all_mutants),
|
|
691
|
+
"killed": killed,
|
|
692
|
+
"survived": survived,
|
|
693
|
+
"mutation_score": score,
|
|
694
|
+
"static_assertion_sensitivity_score": score if exec_mode == "STATIC" else None,
|
|
695
|
+
"runtime_mutation_kill_score": score if "DYNAMIC" in exec_mode else None,
|
|
696
|
+
"no_mutants_generated": no_mutants,
|
|
697
|
+
"min_score": min_score,
|
|
698
|
+
"min_file_score": min_file_score,
|
|
699
|
+
"passed": passed,
|
|
700
|
+
"mutants": all_mutants
|
|
701
|
+
}
|
|
702
|
+
if scoped_test_cmd:
|
|
703
|
+
report_res["scoped_test_cmd"] = scoped_test_cmd
|
|
704
|
+
report_res["impacted_test_files"] = impacted_map
|
|
705
|
+
if not os.path.isfile(target):
|
|
706
|
+
report_res["file_scores"] = file_scores
|
|
707
|
+
if failed_files:
|
|
708
|
+
report_res["failed_files"] = failed_files
|
|
709
|
+
return report_res
|
|
710
|
+
|
|
711
|
+
|
|
712
|
+
|
|
713
|
+
def format_sarif(report: Dict[str, Any]) -> str:
|
|
714
|
+
"""Formats survived mutants in SARIF 2.1.0 format for GitHub Code Scanning."""
|
|
715
|
+
results = []
|
|
716
|
+
rules_dict = {}
|
|
717
|
+
for m in report.get("mutants", []):
|
|
718
|
+
if m.get("status") == "SURVIVED":
|
|
719
|
+
rule_id = "SYNAPSE_MUTANT_SURVIVED"
|
|
720
|
+
if rule_id not in rules_dict:
|
|
721
|
+
rules_dict[rule_id] = {
|
|
722
|
+
"id": rule_id,
|
|
723
|
+
"shortDescription": {"text": "Syntactic micro-mutant survived downstream assertion check"},
|
|
724
|
+
"defaultConfiguration": {"level": "error"}
|
|
725
|
+
}
|
|
726
|
+
results.append({
|
|
727
|
+
"ruleId": rule_id,
|
|
728
|
+
"level": "error",
|
|
729
|
+
"message": {"text": f"Mutant survived: {m.get('description', '')} ({m.get('original_snippet', '')} -> {m.get('mutated_snippet', '')})"},
|
|
730
|
+
"locations": [{
|
|
731
|
+
"physicalLocation": {
|
|
732
|
+
"artifactLocation": {"uri": m.get("file", report.get("target", ""))},
|
|
733
|
+
"region": {"startLine": max(1, m.get("line", 1))}
|
|
734
|
+
}
|
|
735
|
+
}]
|
|
736
|
+
})
|
|
737
|
+
sarif_doc = {
|
|
738
|
+
"$schema": "https://json.schemastore.org/sarif-2.1.0.json",
|
|
739
|
+
"version": "2.1.0",
|
|
740
|
+
"runs": [{
|
|
741
|
+
"tool": {
|
|
742
|
+
"driver": {
|
|
743
|
+
"name": "synapse-micro-mutator",
|
|
744
|
+
"version": "2.3.0",
|
|
745
|
+
"rules": list(rules_dict.values())
|
|
746
|
+
}
|
|
747
|
+
},
|
|
748
|
+
"results": results
|
|
749
|
+
}]
|
|
750
|
+
}
|
|
751
|
+
return json.dumps(sarif_doc, indent=2, ensure_ascii=False)
|
|
752
|
+
|
|
753
|
+
|
|
754
|
+
def format_junit(report: Dict[str, Any]) -> str:
|
|
755
|
+
"""Formats mutation evaluation in standard JUnit XML format."""
|
|
756
|
+
total = max(1, report.get("total_mutants", 0))
|
|
757
|
+
survived = report.get("survived", 0)
|
|
758
|
+
lines = [
|
|
759
|
+
'<?xml version="1.0" encoding="utf-8"?>',
|
|
760
|
+
f'<testsuite name="synapse-micro-mutator" tests="{total}" failures="{survived}" errors="0">'
|
|
761
|
+
]
|
|
762
|
+
for m in report.get("mutants", []):
|
|
763
|
+
cname = (m.get("file") or report.get("target", "")).replace("/", ".").replace("\\", ".")
|
|
764
|
+
clean_desc = re.sub(r'[^a-zA-Z0-9_]', '_', m.get('description', 'mutant'))
|
|
765
|
+
tname = f"Mutant_L{m.get('line', 1)}_{clean_desc}"
|
|
766
|
+
lines.append(f' <testcase classname="{cname}" name="{tname}">')
|
|
767
|
+
if m.get("status") == "SURVIVED":
|
|
768
|
+
desc = html_lib.escape(m.get("description", ""))
|
|
769
|
+
orig = html_lib.escape(m.get("original_snippet", ""))
|
|
770
|
+
mut = html_lib.escape(m.get("mutated_snippet", ""))
|
|
771
|
+
reason = html_lib.escape(m.get("reason", "Downstream assertions failed to kill mutant"))
|
|
772
|
+
lines.append(f' <failure message="Mutant survived: {desc}" type="MUTANT_SURVIVED">Line {m.get("line", 1)}: {orig} -> {mut}. Reason: {reason}</failure>')
|
|
773
|
+
lines.append(' </testcase>')
|
|
774
|
+
if not report.get("mutants"):
|
|
775
|
+
lines.append(' <testcase classname="synapse.mutator" name="clean_run"/>')
|
|
776
|
+
lines.append('</testsuite>')
|
|
777
|
+
return "\n".join(lines)
|
|
778
|
+
|
|
779
|
+
|
|
780
|
+
def main():
|
|
781
|
+
parser = argparse.ArgumentParser(description="Assertion Sensitivity & Syntactic Micro-Mutation Sentinel (Heuristic)")
|
|
782
|
+
parser.add_argument("target", nargs="?", default=os.getcwd(), help="Target script or directory to mutate")
|
|
783
|
+
parser.add_argument("--min-score", "--threshold", type=float, default=80.0, dest="min_score",
|
|
784
|
+
help="Minimum assertion sensitivity percentage required to pass Quality Gate (default: 80.0)")
|
|
785
|
+
parser.add_argument("--min-file-score", type=float, default=0.0, help="Minimum assertion sensitivity percentage required per file (default: 0.0)")
|
|
786
|
+
parser.add_argument("--timeout", type=float, default=60.0, help="Per-mutant test execution timeout in seconds (default: 60.0)")
|
|
787
|
+
parser.add_argument("--test-cmd", default="", help="Optional dynamic test execution command to verify mutants")
|
|
788
|
+
parser.add_argument("--scoped-test-cmd", default="", help="Dynamic test command scoped to impacted test cases via test_impact.py (e.g. 'pytest {test_files}' or 'pytest')")
|
|
789
|
+
parser.add_argument("--allow-empty", action="store_true", help="Pass Quality Gate even if 0 mutants were generated")
|
|
790
|
+
parser.add_argument("--dry-run", action="store_true", default=False, help="Scan and list mutants without modifying files")
|
|
791
|
+
parser.add_argument("--json", action="store_true", help="Output results in JSON format")
|
|
792
|
+
parser.add_argument("--baseline", default=None, help="Path to JSON file to record or compare mutation baseline metrics")
|
|
793
|
+
parser.add_argument("--format", choices=["text", "json", "sarif", "junit"], default="text",
|
|
794
|
+
help="Output format: text (default), json, sarif, or junit")
|
|
795
|
+
args = parser.parse_args()
|
|
796
|
+
|
|
797
|
+
effective_test_cmd = "" if args.dry_run else args.test_cmd
|
|
798
|
+
effective_scoped_cmd = "" if args.dry_run else args.scoped_test_cmd
|
|
799
|
+
report = evaluate_target(
|
|
800
|
+
args.target,
|
|
801
|
+
min_score=args.min_score,
|
|
802
|
+
test_cmd=effective_test_cmd,
|
|
803
|
+
scoped_test_cmd=effective_scoped_cmd,
|
|
804
|
+
timeout=args.timeout,
|
|
805
|
+
min_file_score=args.min_file_score
|
|
806
|
+
)
|
|
807
|
+
if report.get("no_mutants_generated") and args.allow_empty:
|
|
808
|
+
report["passed"] = True
|
|
809
|
+
|
|
810
|
+
if args.baseline:
|
|
811
|
+
baseline_dir = os.path.dirname(os.path.abspath(args.baseline))
|
|
812
|
+
if baseline_dir:
|
|
813
|
+
os.makedirs(baseline_dir, exist_ok=True)
|
|
814
|
+
baseline_record = {
|
|
815
|
+
"target": report.get("target"),
|
|
816
|
+
"mode": report.get("mode"),
|
|
817
|
+
"total_mutants": report.get("total_mutants", 0),
|
|
818
|
+
"killed": report.get("killed", 0),
|
|
819
|
+
"survived": report.get("survived", 0),
|
|
820
|
+
"mutation_score": report.get("mutation_score", 0.0),
|
|
821
|
+
"min_score": report.get("min_score", 80.0),
|
|
822
|
+
"passed": report.get("passed", False),
|
|
823
|
+
"recorded_at": datetime.now(timezone.utc).isoformat() if "timezone" in globals() else str(datetime.now())
|
|
824
|
+
}
|
|
825
|
+
try:
|
|
826
|
+
with open(args.baseline, "w", encoding="utf-8") as bf:
|
|
827
|
+
json.dump(baseline_record, bf, indent=2)
|
|
828
|
+
report["baseline_recorded"] = args.baseline
|
|
829
|
+
except Exception as e:
|
|
830
|
+
sys.stderr.write(f"Notice: Failed to record baseline: {e}\n")
|
|
831
|
+
|
|
832
|
+
output_format = "json" if args.json else args.format
|
|
833
|
+
|
|
834
|
+
if output_format == "json":
|
|
835
|
+
print(json.dumps(report, indent=2))
|
|
836
|
+
elif output_format == "sarif":
|
|
837
|
+
print(format_sarif(report))
|
|
838
|
+
elif output_format == "junit":
|
|
839
|
+
print(format_junit(report))
|
|
840
|
+
else:
|
|
841
|
+
mode_tag = "LIVE DYNAMIC RUNNER" if "DYNAMIC" in report.get("mode", "") else "STATIC HEURISTIC"
|
|
842
|
+
if report.get("mode") == "DYNAMIC_SCOPED":
|
|
843
|
+
mode_desc = f"LIVE DYNAMIC RUNNER [SCOPED TEST IMPACT] (template: '{args.scoped_test_cmd}')"
|
|
844
|
+
elif report.get("mode") == "DYNAMIC":
|
|
845
|
+
mode_desc = f"LIVE DYNAMIC RUNNER (cmd: '{args.test_cmd}')"
|
|
846
|
+
else:
|
|
847
|
+
mode_desc = "STATIC HEURISTIC (fast heuristic assertion sensitivity scan; pass --test-cmd or --scoped-test-cmd for dynamic run)"
|
|
848
|
+
score_label = "Runtime Mutation Kill Score" if "DYNAMIC" in report.get("mode", "") else "Static Assertion Sensitivity"
|
|
849
|
+
|
|
850
|
+
print("\n======================================================================")
|
|
851
|
+
print(f" ASSERTION SENSITIVITY & SYNTACTIC MUTATION SENTINEL [{mode_tag}] ")
|
|
852
|
+
print("======================================================================")
|
|
853
|
+
print(f" Target Scope : {report['target']}")
|
|
854
|
+
print(f" Evaluation Mode : {mode_desc}")
|
|
855
|
+
print(f" Mutants Injected : {report['total_mutants']}")
|
|
856
|
+
print(f" Mutants Caught/Killed : {report['killed']}")
|
|
857
|
+
print(f" Mutants Survived : {report['survived']}")
|
|
858
|
+
if report.get("no_mutants_generated"):
|
|
859
|
+
print(" ⚠️ Notice : Zero syntactic mutants generated. Target lacks mutable logic expressions.")
|
|
860
|
+
print(f" {score_label:<22}: {report['mutation_score']}% (Required: >={report['min_score']}%)")
|
|
861
|
+
print("======================================================================\n")
|
|
862
|
+
|
|
863
|
+
for m in report['mutants'][:6]:
|
|
864
|
+
status_tag = "[KILLED] " if m["status"] == "KILLED" else "[SURVIVED]"
|
|
865
|
+
print(f"{status_tag} Line {m['line']}: {m['description']}")
|
|
866
|
+
print(f" Original: {m['original_snippet']}")
|
|
867
|
+
print(f" Mutated : {m['mutated_snippet']}")
|
|
868
|
+
print(f" Verdict : {m.get('reason', '')}\n")
|
|
869
|
+
|
|
870
|
+
if len(report['mutants']) > 6:
|
|
871
|
+
print(f"... and {len(report['mutants']) - 6} more mutants evaluated.\n")
|
|
872
|
+
|
|
873
|
+
if report["passed"]:
|
|
874
|
+
print(f"✅ [QUALITY GATE PASSED] {score_label} {report['mutation_score']}% >= {report['min_score']}% threshold.")
|
|
875
|
+
else:
|
|
876
|
+
if report.get("no_mutants_generated"):
|
|
877
|
+
print("❌ [REJECTED BY QUALITY GATEKEEPER] Zero mutants generated for target scope.")
|
|
878
|
+
print(" 👉 Provide test scripts with mutable logic/relational operations, or use --allow-empty.")
|
|
879
|
+
else:
|
|
880
|
+
print(f"❌ [REJECTED BY QUALITY GATEKEEPER] {score_label} {report['mutation_score']}% < {report['min_score']}%.")
|
|
881
|
+
print(" 👉 Increase test assertion sensitivity or eliminate tautological/unasserted blocks.")
|
|
882
|
+
|
|
883
|
+
return 0 if report["passed"] else 1
|
|
884
|
+
|
|
885
|
+
|
|
886
|
+
if __name__ == "__main__":
|
|
887
|
+
sys.exit(main())
|