@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,977 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Universal QA Static Defect & Assertion Sentinel (Inspired by facebook/infer)
|
|
4
|
+
-------------------------------------------------------------------
|
|
5
|
+
Performs AST-level static analysis across test scripts, specs, and Page Classes.
|
|
6
|
+
Detects:
|
|
7
|
+
1. FAKE_PASS_NO_ASSERTION : Test cases that interact with AUT but lack assertions / verifications.
|
|
8
|
+
2. SWALLOWED_EXCEPTION : Empty catch blocks that hide failures silently.
|
|
9
|
+
3. EXCESSIVE_HARD_DELAY : Thread.sleep >= 3000ms or WebUI.delay >= 5s (flaky anti-pattern).
|
|
10
|
+
4. RESOURCE_LEAK_RISK : Unclosed streams or driver handles lacking finally blocks.
|
|
11
|
+
5. EMPTY_TEST_SCRIPT : Test cases with zero executable statements.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import os
|
|
15
|
+
import sys
|
|
16
|
+
import re
|
|
17
|
+
import json
|
|
18
|
+
import glob
|
|
19
|
+
import ast
|
|
20
|
+
import html as html_lib
|
|
21
|
+
import argparse
|
|
22
|
+
from datetime import datetime
|
|
23
|
+
|
|
24
|
+
# Enforce UTF-8 stdout encoding for Windows console compatibility
|
|
25
|
+
if hasattr(sys.stdout, 'reconfigure'):
|
|
26
|
+
try:
|
|
27
|
+
sys.stdout.reconfigure(encoding='utf-8')
|
|
28
|
+
sys.stderr.reconfigure(encoding='utf-8')
|
|
29
|
+
except Exception:
|
|
30
|
+
pass
|
|
31
|
+
|
|
32
|
+
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
33
|
+
REPO_ROOT = os.path.abspath(os.path.join(SCRIPT_DIR, ".."))
|
|
34
|
+
SCRIPTS_DIR = os.path.join(REPO_ROOT, "Scripts")
|
|
35
|
+
REPORTS_DIR = os.path.join(REPO_ROOT, "reports")
|
|
36
|
+
OUTPUT_JSON = os.path.join(REPORTS_DIR, "infer_linter_report.json")
|
|
37
|
+
|
|
38
|
+
# ANSI Color codes
|
|
39
|
+
GREEN = "\033[92m"
|
|
40
|
+
RED = "\033[91m"
|
|
41
|
+
YELLOW = "\033[93m"
|
|
42
|
+
CYAN = "\033[96m"
|
|
43
|
+
BOLD = "\033[1m"
|
|
44
|
+
RESET = "\033[0m"
|
|
45
|
+
|
|
46
|
+
# Optional Tree-Sitter Integration for compiler-grade AST parsing across TS/Java/C#
|
|
47
|
+
try:
|
|
48
|
+
import tree_sitter # type: ignore # noqa: F401
|
|
49
|
+
HAS_TREE_SITTER = True
|
|
50
|
+
except ImportError:
|
|
51
|
+
HAS_TREE_SITTER = False
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def parse_with_tree_sitter(file_path, content):
|
|
55
|
+
"""
|
|
56
|
+
Optional compiler-grade AST parsing via tree-sitter when installed.
|
|
57
|
+
Extracts syntactic AST nodes for TypeScript, JavaScript, Java, and C#.
|
|
58
|
+
Returns None if tree-sitter is unavailable or grammar is not installed.
|
|
59
|
+
"""
|
|
60
|
+
if not HAS_TREE_SITTER:
|
|
61
|
+
return None
|
|
62
|
+
try:
|
|
63
|
+
from tree_sitter_languages import get_parser # type: ignore
|
|
64
|
+
ext = os.path.splitext(file_path)[1].lower()
|
|
65
|
+
lang_map = {
|
|
66
|
+
".ts": "typescript",
|
|
67
|
+
".js": "javascript",
|
|
68
|
+
".java": "java",
|
|
69
|
+
".cs": "c_sharp",
|
|
70
|
+
}
|
|
71
|
+
lang_name = lang_map.get(ext)
|
|
72
|
+
if not lang_name:
|
|
73
|
+
return None
|
|
74
|
+
parser = get_parser(lang_name)
|
|
75
|
+
return parser.parse(bytes(content, "utf-8"))
|
|
76
|
+
except Exception:
|
|
77
|
+
return None
|
|
78
|
+
|
|
79
|
+
# Generic Detection regexes (including Cypress .should and .and assertions)
|
|
80
|
+
# Note: Standalone expect(...) without chained matcher is caught as DANGLING_ASSERTION_NO_MATCHER.
|
|
81
|
+
ASSERTION_PATTERN = re.compile(
|
|
82
|
+
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'
|
|
83
|
+
r'|\.should\s*\('
|
|
84
|
+
r'|\.and\s*\(',
|
|
85
|
+
re.MULTILINE
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
# Rule L1 & L5: Empty catch / swallowed exceptions across JS/TS/Groovy/Java and Python
|
|
89
|
+
# Also catches try/catch that only console.log/logger.error or promise .catch(() => {})
|
|
90
|
+
EMPTY_CATCH_PATTERN = re.compile(
|
|
91
|
+
r'(?:catch\s*(?:\([^\)]*\))?\s*\{\s*(?:(?:console|logger|log)\.(?:log|warn|error|info)\([^)]*\);?\s*)?\}'
|
|
92
|
+
r'|\.catch\s*\(\s*(?:\([^)]*\)|[a-zA-Z0-9_]+)?\s*=>\s*\{\s*(?:(?:console|logger|log)\.(?:log|warn|error|info)\([^)]*\);?\s*)?\}\s*\)'
|
|
93
|
+
r'|\bexcept(?:\s+[^:]*)?:\s*(?:pass|\.\.\.)(?:\s*$|\s*#))',
|
|
94
|
+
re.MULTILINE
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
# Whitelisted best-effort compatibility calls (UTF-8 console reconfigure, file
|
|
98
|
+
# permission chmod, stream flush, stream set_blocking). An empty catch guarding ONLY these is an
|
|
99
|
+
# intentional no-op-on-failure idiom, not a swallowed test failure.
|
|
100
|
+
BENIGN_TRY_CALL_PATTERN = re.compile(
|
|
101
|
+
r'^[\w\.]*\.(?:reconfigure|chmod|flush|set_blocking)\s*\('
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
# Rule L3: Tautological assertions (e.g. expect(true).toBe(true), assert r == r, assert f() == f(), assert len(x) >= 0)
|
|
105
|
+
TAUTOLOGY_PATTERN = re.compile(
|
|
106
|
+
r'(?:expect(?:\.soft|\.poll)?\s*\(\s*(?:true|1|null|undefined)\s*\)\s*\.\s*(?:toBe|toEqual|toBeTruthy|toBeNull|toBeUndefined)\s*\(\s*(?:true|1|null|undefined)?\s*\)'
|
|
107
|
+
r'|expect(?:\.soft|\.poll)?\s*\(\s*([a-zA-Z0-9_]+)\s*\)\s*\.\s*(?:toBe|toEqual)\s*\(\s*\1\s*\)'
|
|
108
|
+
r'|\bassert\s+(?:True|true|1\s*==\s*1)\b'
|
|
109
|
+
r'|\bassert\s+([a-zA-Z0-9_\.]+(?:\([^)]*\))?)\s*==\s*\1\b'
|
|
110
|
+
r'|\bassert\s+(?:len\s*\([^)]*\)|[a-zA-Z0-9_\.]+\.(?:length|size\(\)))\s*(?:>=\s*0|>\s*-(?:1|0))\b'
|
|
111
|
+
r'|assertEquals\s*\(\s*(?:true|1|null)\s*,\s*(?:true|1|null)\s*\)'
|
|
112
|
+
r'|assertTrue\s*\(\s*(?:true|1)\s*\))',
|
|
113
|
+
re.IGNORECASE
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def find_dangling_expects(clean_code, raw_lines):
|
|
118
|
+
"""
|
|
119
|
+
Detects dangling expect(...) calls lacking chained matchers (e.g. expect(page) without .toBeVisible()).
|
|
120
|
+
Correctly handles nested parentheses like expect(page.locator('#id')).
|
|
121
|
+
"""
|
|
122
|
+
dangling = []
|
|
123
|
+
pattern = re.compile(r'(?:await\s+)?\bexpect(?:\.soft|\.poll)?\s*\(')
|
|
124
|
+
for m in pattern.finditer(clean_code):
|
|
125
|
+
start_idx = m.end()
|
|
126
|
+
depth = 1
|
|
127
|
+
pos = start_idx
|
|
128
|
+
while pos < len(clean_code) and depth > 0:
|
|
129
|
+
ch = clean_code[pos]
|
|
130
|
+
if ch == '(':
|
|
131
|
+
depth += 1
|
|
132
|
+
elif ch == ')':
|
|
133
|
+
depth -= 1
|
|
134
|
+
elif ch in (';', '\n') and depth > 0:
|
|
135
|
+
# Malformed unclosed expect
|
|
136
|
+
break
|
|
137
|
+
pos += 1
|
|
138
|
+
if depth == 0:
|
|
139
|
+
rest = clean_code[pos:].lstrip()
|
|
140
|
+
if not rest.startswith('.'):
|
|
141
|
+
line_no = clean_code[:m.start()].count("\n") + 1
|
|
142
|
+
raw_line = raw_lines[line_no - 1].strip() if line_no <= len(raw_lines) else ""
|
|
143
|
+
dangling.append((line_no, raw_line))
|
|
144
|
+
return dangling
|
|
145
|
+
|
|
146
|
+
# Rule L4: Unawaited Playwright assertions in JS/TS
|
|
147
|
+
# Expanded with all standard Playwright async matchers and optional .not modifier
|
|
148
|
+
PLAYWRIGHT_ASYNC_MATCHERS = (
|
|
149
|
+
r'(?:toBeVisible|toBeHidden|toHaveText|toHaveValue|toHaveCount|toBeEnabled|toBeDisabled|'
|
|
150
|
+
r'toBeChecked|toHaveURL|toContainText|toHaveTitle|toHaveAttribute|toHaveClass|toHaveId|'
|
|
151
|
+
r'toBeFocused|toBeEmpty|toBeAttached|toBeInViewport|toBeOK)'
|
|
152
|
+
)
|
|
153
|
+
UNAWAITED_EXPECT_PATTERN = re.compile(
|
|
154
|
+
r'\bexpect\s*\([^;\n]+\)\s*(?:\.\s*not)?\s*\.\s*' + PLAYWRIGHT_ASYNC_MATCHERS + r'\s*\(',
|
|
155
|
+
re.MULTILINE
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
# Rule 3: Flaky Static Delays across Groovy, Java, Playwright (JS/TS/Python), Pytest/Python, Cypress
|
|
159
|
+
# Millisecond-based delays: Thread.sleep(ms), waitForTimeout(ms), wait_for_timeout(ms), cy.wait(ms)
|
|
160
|
+
MS_DELAY_PATTERN = re.compile(
|
|
161
|
+
r'(?:Thread\.sleep|(?:page\.)?waitForTimeout|(?:page\.)?wait_for_timeout|cy\.wait)\s*\(\s*([^)]+)\s*\)'
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
# Second-based delays: WebUI.delay(sec), time.sleep(sec)
|
|
165
|
+
SEC_DELAY_PATTERN = re.compile(
|
|
166
|
+
r'(?:WebUI\.delay|time\.sleep)\s*\(\s*([^)]+)\s*\)'
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
# Backward-compatibility alias
|
|
170
|
+
THREAD_SLEEP_PATTERN = MS_DELAY_PATTERN
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def strip_comments_and_strings(source_code, preserve_newlines=True):
|
|
174
|
+
"""
|
|
175
|
+
Lexically strips block comments, line comments, multiline strings,
|
|
176
|
+
and quoted literals while preserving line numbering.
|
|
177
|
+
Prevents false-positive / false-negative matches in AST linter.
|
|
178
|
+
"""
|
|
179
|
+
pattern = re.compile(
|
|
180
|
+
r'(?P<TRIPLE_DOUBLE>"""[\s\S]*?""")|'
|
|
181
|
+
r'(?P<TRIPLE_SINGLE>\'\'\'[\s\S]*?\'\'\')|'
|
|
182
|
+
r'(?P<DOUBLE_STRING>"(?:\\.|[^"\\])*")|'
|
|
183
|
+
r'(?P<SINGLE_STRING>\'(?:\\.|[^\'\\])*\')|'
|
|
184
|
+
r'(?P<BLOCK_COMMENT>/\*.*?\*/)|'
|
|
185
|
+
r'(?P<LINE_COMMENT>//[^\r\n]*)|'
|
|
186
|
+
r'(?P<HASH_COMMENT>#[^\r\n]*)',
|
|
187
|
+
re.DOTALL
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
def replacer(match):
|
|
191
|
+
text = match.group(0)
|
|
192
|
+
if preserve_newlines:
|
|
193
|
+
return re.sub(r'[^\r\n]', ' ', text)
|
|
194
|
+
return ' '
|
|
195
|
+
|
|
196
|
+
return pattern.sub(replacer, source_code)
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def _is_benign_empty_catch(clean_code, match_start):
|
|
200
|
+
"""
|
|
201
|
+
True when an empty catch block exclusively guards whitelisted best-effort
|
|
202
|
+
calls (e.g. sys.stdout.reconfigure(), os.chmod()) - an intentional
|
|
203
|
+
no-op-on-failure compatibility idiom rather than a swallowed test failure.
|
|
204
|
+
Conservative by design: only Python-style 'try:' blocks are whitelisted;
|
|
205
|
+
C-style brace bodies still get flagged.
|
|
206
|
+
"""
|
|
207
|
+
body_lines = []
|
|
208
|
+
for line in reversed(clean_code[:match_start].splitlines()):
|
|
209
|
+
stripped = line.strip()
|
|
210
|
+
if not stripped:
|
|
211
|
+
continue
|
|
212
|
+
if re.match(r'try\s*(?:[:{]|$)', stripped):
|
|
213
|
+
return bool(body_lines) and all(BENIGN_TRY_CALL_PATTERN.match(bl) for bl in body_lines)
|
|
214
|
+
body_lines.append(stripped)
|
|
215
|
+
return False
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def load_config(repo_root=None, config_path=None):
|
|
219
|
+
"""Loads configuration from synapse.config.json if present."""
|
|
220
|
+
if config_path and os.path.exists(config_path):
|
|
221
|
+
try:
|
|
222
|
+
with open(config_path, "r", encoding="utf-8") as f:
|
|
223
|
+
return json.load(f)
|
|
224
|
+
except (OSError, json.JSONDecodeError):
|
|
225
|
+
_ = False
|
|
226
|
+
|
|
227
|
+
root = repo_root or REPO_ROOT
|
|
228
|
+
candidates = [
|
|
229
|
+
os.path.join(root, "synapse.config.json"),
|
|
230
|
+
os.path.join(root, ".synapse.json"),
|
|
231
|
+
os.path.join(os.getcwd(), "synapse.config.json"),
|
|
232
|
+
os.path.join(os.getcwd(), ".synapse.json")
|
|
233
|
+
]
|
|
234
|
+
for c in candidates:
|
|
235
|
+
if os.path.exists(c):
|
|
236
|
+
try:
|
|
237
|
+
with open(c, "r", encoding="utf-8") as f:
|
|
238
|
+
return json.load(f)
|
|
239
|
+
except (OSError, json.JSONDecodeError):
|
|
240
|
+
continue
|
|
241
|
+
return {}
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
def load_baseline(baseline_path):
|
|
245
|
+
"""Loads existing baseline findings to suppress known technical debt."""
|
|
246
|
+
if not baseline_path or not os.path.exists(baseline_path):
|
|
247
|
+
return set()
|
|
248
|
+
try:
|
|
249
|
+
with open(baseline_path, "r", encoding="utf-8") as f:
|
|
250
|
+
data = json.load(f)
|
|
251
|
+
items = data.get("defects", data) if isinstance(data, dict) else data
|
|
252
|
+
signatures = set()
|
|
253
|
+
for it in items:
|
|
254
|
+
f_path = it.get("file", "").replace("\\", "/")
|
|
255
|
+
d_type = it.get("type", "").upper()
|
|
256
|
+
d_line = it.get("line")
|
|
257
|
+
signatures.add((f_path, d_type))
|
|
258
|
+
if d_line is not None:
|
|
259
|
+
signatures.add((f_path, d_type, d_line))
|
|
260
|
+
return signatures
|
|
261
|
+
except (OSError, json.JSONDecodeError):
|
|
262
|
+
return set()
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
def save_baseline(baseline_path, all_defects):
|
|
266
|
+
"""Saves current findings into a baseline JSON file."""
|
|
267
|
+
os.makedirs(os.path.dirname(os.path.abspath(baseline_path)), exist_ok=True)
|
|
268
|
+
with open(baseline_path, "w", encoding="utf-8") as f:
|
|
269
|
+
json.dump({
|
|
270
|
+
"generated_at": datetime.now().isoformat(),
|
|
271
|
+
"total_defects": len(all_defects),
|
|
272
|
+
"defects": all_defects
|
|
273
|
+
}, f, indent=2, ensure_ascii=False)
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
def format_sarif(report_data):
|
|
277
|
+
"""Formats findings in standard SARIF 2.1.0 JSON format for GitHub Code Scanning."""
|
|
278
|
+
results = []
|
|
279
|
+
rules_dict = {}
|
|
280
|
+
for d in report_data.get("all_defects", []):
|
|
281
|
+
rule_id = d.get("type", "STATIC_DEFECT")
|
|
282
|
+
if rule_id not in rules_dict:
|
|
283
|
+
rules_dict[rule_id] = {
|
|
284
|
+
"id": rule_id,
|
|
285
|
+
"shortDescription": {"text": d.get("message", rule_id)},
|
|
286
|
+
"defaultConfiguration": {
|
|
287
|
+
"level": "error" if d.get("severity") == "CRITICAL" else "warning"
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
results.append({
|
|
291
|
+
"ruleId": rule_id,
|
|
292
|
+
"level": "error" if d.get("severity") == "CRITICAL" else "warning",
|
|
293
|
+
"message": {"text": d.get("message", "")},
|
|
294
|
+
"locations": [{
|
|
295
|
+
"physicalLocation": {
|
|
296
|
+
"artifactLocation": {"uri": d.get("file", "")},
|
|
297
|
+
"region": {"startLine": max(1, d.get("line", 1))}
|
|
298
|
+
}
|
|
299
|
+
}]
|
|
300
|
+
})
|
|
301
|
+
sarif_doc = {
|
|
302
|
+
"$schema": "https://json.schemastore.org/sarif-2.1.0.json",
|
|
303
|
+
"version": "2.1.0",
|
|
304
|
+
"runs": [{
|
|
305
|
+
"tool": {
|
|
306
|
+
"driver": {
|
|
307
|
+
"name": "synapse-infer-linter",
|
|
308
|
+
"version": "2.3.0",
|
|
309
|
+
"rules": list(rules_dict.values())
|
|
310
|
+
}
|
|
311
|
+
},
|
|
312
|
+
"results": results
|
|
313
|
+
}]
|
|
314
|
+
}
|
|
315
|
+
return json.dumps(sarif_doc, indent=2, ensure_ascii=False)
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
def format_junit(report_data):
|
|
319
|
+
"""Formats findings in standard JUnit XML format."""
|
|
320
|
+
total = max(1, report_data.get("total_scripts", 0))
|
|
321
|
+
defects = report_data.get("all_defects", [])
|
|
322
|
+
failures = len([d for d in defects if d.get("severity") == "CRITICAL"])
|
|
323
|
+
warnings = len([d for d in defects if d.get("severity") != "CRITICAL"])
|
|
324
|
+
lines = [
|
|
325
|
+
'<?xml version="1.0" encoding="utf-8"?>',
|
|
326
|
+
f'<testsuite name="synapse-infer-linter" tests="{max(total, len(defects))}" failures="{failures}" errors="{warnings}">'
|
|
327
|
+
]
|
|
328
|
+
for d in defects:
|
|
329
|
+
cname = d.get("file", "").replace("/", ".").replace("\\", ".")
|
|
330
|
+
tname = f"{d.get('type')}_L{d.get('line', 1)}"
|
|
331
|
+
msg = html_lib.escape(d.get("message", ""))
|
|
332
|
+
tag = "failure" if d.get("severity") == "CRITICAL" else "error"
|
|
333
|
+
lines.append(f' <testcase classname="{cname}" name="{tname}">')
|
|
334
|
+
lines.append(f' <{tag} message="{msg}" type="{d.get("type")}">Line {d.get("line", 1)}: {msg}</{tag}>')
|
|
335
|
+
lines.append(' </testcase>')
|
|
336
|
+
if not defects:
|
|
337
|
+
lines.append(' <testcase classname="synapse.linter" name="clean_run"/>')
|
|
338
|
+
lines.append('</testsuite>')
|
|
339
|
+
return "\n".join(lines)
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
def classify_file_role(file_path: str, content: str = "") -> str:
|
|
343
|
+
"""
|
|
344
|
+
Classifies a source file into:
|
|
345
|
+
- 'CONFIG': Configuration files (playwright.config, cypress.config, conftest, wdio.conf, jest.config)
|
|
346
|
+
- 'PAGE_OBJECT': Page Classes / POM (files in pages/, ending in Page.ts/js/py/groovy/java, or BasePage)
|
|
347
|
+
- 'HELPER': Utilities / Fixtures / Custom Keywords (files in helpers/, fixtures/, utils/, support/)
|
|
348
|
+
- 'TEST_SCRIPT': Test specifications / test cases (test_*, *test, *.spec, *.cy, *.tc, files in tests/, Scripts/)
|
|
349
|
+
"""
|
|
350
|
+
norm = file_path.replace("\\", "/").lower()
|
|
351
|
+
base = os.path.basename(norm)
|
|
352
|
+
parts = norm.split("/")[:-1]
|
|
353
|
+
|
|
354
|
+
# 1. Config files
|
|
355
|
+
if any(cfg in base for cfg in ["playwright.config", "cypress.config", "wdio.conf", "jest.config", "karma.conf", "conftest.py", "tsconfig"]):
|
|
356
|
+
return "CONFIG"
|
|
357
|
+
if any(p in ("config", ".config") for p in parts):
|
|
358
|
+
return "CONFIG"
|
|
359
|
+
|
|
360
|
+
# 2. Page Objects (Clean POM)
|
|
361
|
+
if any(p in ("pages", "page_objects", "page-objects", "po") for p in parts) or \
|
|
362
|
+
("keywords" in parts and "pages" in norm):
|
|
363
|
+
return "PAGE_OBJECT"
|
|
364
|
+
if re.search(r'(^|_)basepage\b', base) or re.search(r'[a-z0-9_]page\.(ts|js|py|groovy|java)$', base):
|
|
365
|
+
return "PAGE_OBJECT"
|
|
366
|
+
if content and (re.search(r'\bclass\s+[A-Za-z0-9_]*Page\b', content) or re.search(r'\bextends\s+BasePage\b', content)):
|
|
367
|
+
return "PAGE_OBJECT"
|
|
368
|
+
|
|
369
|
+
# 3. Helpers & Fixtures / Tools & Utilities / Benchmarks
|
|
370
|
+
if any(p in ("fixtures", "helpers", "utils", "support", "tools", "bin", "benchmarks", "benchmark") for p in parts):
|
|
371
|
+
return "HELPER"
|
|
372
|
+
if any(base.endswith(sfx) for sfx in ("helper.ts", "helper.js", "helper.py", "helper.groovy", "utils.ts", "utils.js", "utils.py", "fixture.ts", "fixture.js")):
|
|
373
|
+
return "HELPER"
|
|
374
|
+
|
|
375
|
+
# 4. Test Scripts
|
|
376
|
+
test_suffixes = ("_test.py", ".spec.ts", ".spec.js", ".test.ts", ".test.js", ".cy.js", ".cy.ts", ".spec.jsx", ".test.jsx", ".tc", "test.java", "tests.java", "spec.groovy")
|
|
377
|
+
if base.startswith("test_") or base.endswith(test_suffixes):
|
|
378
|
+
return "TEST_SCRIPT"
|
|
379
|
+
if any(p in ("tests", "test", "e2e", "specs", "cypress") for p in parts):
|
|
380
|
+
return "TEST_SCRIPT"
|
|
381
|
+
if "scripts" in parts:
|
|
382
|
+
if file_path.endswith((".groovy", ".tc")) or base.startswith("test_") or base.endswith(test_suffixes):
|
|
383
|
+
return "TEST_SCRIPT"
|
|
384
|
+
return "HELPER"
|
|
385
|
+
|
|
386
|
+
# Default fallback: standalone script without directory context
|
|
387
|
+
return "TEST_SCRIPT"
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
def analyze_script(file_path, baseline_set=None, disabled_rules=None):
|
|
391
|
+
"""Performs static rule scanning on a single test script or automation asset."""
|
|
392
|
+
try:
|
|
393
|
+
rel_path = os.path.relpath(file_path, REPO_ROOT)
|
|
394
|
+
except ValueError:
|
|
395
|
+
rel_path = os.path.abspath(file_path)
|
|
396
|
+
|
|
397
|
+
with open(file_path, "r", encoding="utf-8", errors="ignore") as f:
|
|
398
|
+
content = f.read()
|
|
399
|
+
|
|
400
|
+
role = classify_file_role(file_path, content=content)
|
|
401
|
+
|
|
402
|
+
# Config files have zero test assertions by definition
|
|
403
|
+
if role == "CONFIG":
|
|
404
|
+
return {
|
|
405
|
+
"file": rel_path,
|
|
406
|
+
"role": role,
|
|
407
|
+
"defects": [],
|
|
408
|
+
"is_clean": True
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
defects = []
|
|
412
|
+
|
|
413
|
+
# Lexically strip comments and string literals for accurate analysis
|
|
414
|
+
clean_code = strip_comments_and_strings(content, preserve_newlines=True)
|
|
415
|
+
clean_lines = [line.strip() for line in clean_code.splitlines()]
|
|
416
|
+
|
|
417
|
+
raw_lines = content.splitlines()
|
|
418
|
+
|
|
419
|
+
# Code quality checks across all automation assets (Test Scripts, Page Objects, Helpers)
|
|
420
|
+
# Rule 2: Swallowed Exceptions (empty catch blocks)
|
|
421
|
+
for match in EMPTY_CATCH_PATTERN.finditer(clean_code):
|
|
422
|
+
if _is_benign_empty_catch(clean_code, match.start()):
|
|
423
|
+
continue
|
|
424
|
+
line_no = clean_code[:match.start()].count("\n") + 1
|
|
425
|
+
defects.append({
|
|
426
|
+
"type": "SWALLOWED_EXCEPTION",
|
|
427
|
+
"severity": "CRITICAL",
|
|
428
|
+
"line": line_no,
|
|
429
|
+
"message": "Empty catch block detected. Swallowed exceptions cause false-pass test runs."
|
|
430
|
+
})
|
|
431
|
+
|
|
432
|
+
# Rule 3: Flaky Static Delays (Playwright, Cypress, Pytest, Katalon, Java/Groovy)
|
|
433
|
+
for idx, line in enumerate(clean_code.splitlines(), 1):
|
|
434
|
+
raw_line = raw_lines[idx - 1].strip() if idx <= len(raw_lines) else line.strip()
|
|
435
|
+
|
|
436
|
+
# Millisecond delays
|
|
437
|
+
m_ms = MS_DELAY_PATTERN.search(line)
|
|
438
|
+
if m_ms:
|
|
439
|
+
arg = m_ms.group(1).strip()
|
|
440
|
+
# F08: Ignore Cypress route alias waits like cy.wait('@getUsers')
|
|
441
|
+
if arg.startswith(("@", "'@", '"@')):
|
|
442
|
+
pass
|
|
443
|
+
elif arg.isdigit():
|
|
444
|
+
delay_val = int(arg)
|
|
445
|
+
if delay_val > 0:
|
|
446
|
+
is_excessive = delay_val >= 3000
|
|
447
|
+
d_type = "EXCESSIVE_HARD_DELAY" if is_excessive else "HARD_DELAY_ANTI_PATTERN"
|
|
448
|
+
sev = "CRITICAL" if (is_excessive and role == "TEST_SCRIPT") else "WARNING"
|
|
449
|
+
defects.append({
|
|
450
|
+
"type": d_type,
|
|
451
|
+
"severity": sev,
|
|
452
|
+
"line": idx,
|
|
453
|
+
"message": f"Static sleep of {delay_val}ms found ('{raw_line}'). {'Prohibited in test scripts by AGENTS.md Rule 1.4. ' if is_excessive else ''}Replace with dynamic Smart Wait (waitForElement/networkidle)."
|
|
454
|
+
})
|
|
455
|
+
continue
|
|
456
|
+
elif re.match(r'^[a-zA-Z_][a-zA-Z0-9_]*$', arg) and not line.strip().startswith("cy.wait"):
|
|
457
|
+
defects.append({
|
|
458
|
+
"type": "HARD_DELAY_ANTI_PATTERN",
|
|
459
|
+
"severity": "WARNING",
|
|
460
|
+
"line": idx,
|
|
461
|
+
"message": f"Static sleep with variable/expression '{arg}' found ('{raw_line}'). Replace with dynamic Smart Wait."
|
|
462
|
+
})
|
|
463
|
+
continue
|
|
464
|
+
|
|
465
|
+
# Second delays
|
|
466
|
+
m_sec = SEC_DELAY_PATTERN.search(line)
|
|
467
|
+
if m_sec:
|
|
468
|
+
arg = m_sec.group(1).strip()
|
|
469
|
+
try:
|
|
470
|
+
delay_val = float(arg)
|
|
471
|
+
if delay_val > 0:
|
|
472
|
+
delay_ms = int(delay_val * 1000)
|
|
473
|
+
delay_str = f"{delay_val:g}"
|
|
474
|
+
is_excessive = delay_ms >= 3000
|
|
475
|
+
d_type = "EXCESSIVE_HARD_DELAY" if is_excessive else "HARD_DELAY_ANTI_PATTERN"
|
|
476
|
+
sev = "CRITICAL" if (is_excessive and role == "TEST_SCRIPT") else "WARNING"
|
|
477
|
+
defects.append({
|
|
478
|
+
"type": d_type,
|
|
479
|
+
"severity": sev,
|
|
480
|
+
"line": idx,
|
|
481
|
+
"message": f"Static sleep of {delay_str}s ({delay_ms}ms) found ('{raw_line}'). {'Prohibited in test scripts by AGENTS.md Rule 1.4. ' if is_excessive else ''}Replace with dynamic Smart Wait (waitForElement/networkidle)."
|
|
482
|
+
})
|
|
483
|
+
except ValueError:
|
|
484
|
+
if re.match(r'^[a-zA-Z_][a-zA-Z0-9_]*$', arg):
|
|
485
|
+
defects.append({
|
|
486
|
+
"type": "HARD_DELAY_ANTI_PATTERN",
|
|
487
|
+
"severity": "WARNING",
|
|
488
|
+
"line": idx,
|
|
489
|
+
"message": f"Static sleep with variable/expression '{arg}' found ('{raw_line}'). Replace with dynamic Smart Wait."
|
|
490
|
+
})
|
|
491
|
+
|
|
492
|
+
# Test Script Specific Invariants (Do NOT apply to Page Objects or Helpers)
|
|
493
|
+
if role == "TEST_SCRIPT":
|
|
494
|
+
executable_lines = [
|
|
495
|
+
line for line in clean_lines
|
|
496
|
+
if line and not line.startswith("import ") and not line.startswith("package ") and not line.startswith("from ")
|
|
497
|
+
]
|
|
498
|
+
# Rule 1: Empty Test Script
|
|
499
|
+
if len(executable_lines) == 0:
|
|
500
|
+
defects.append({
|
|
501
|
+
"type": "EMPTY_TEST_SCRIPT",
|
|
502
|
+
"severity": "CRITICAL",
|
|
503
|
+
"line": 1,
|
|
504
|
+
"message": "Test script is empty or contains only comments/imports."
|
|
505
|
+
})
|
|
506
|
+
|
|
507
|
+
# Rule 4 (L3): Tautological Assertions
|
|
508
|
+
for idx, line in enumerate(clean_code.splitlines(), 1):
|
|
509
|
+
if TAUTOLOGY_PATTERN.search(line):
|
|
510
|
+
raw_line = raw_lines[idx - 1].strip() if idx <= len(raw_lines) else line.strip()
|
|
511
|
+
defects.append({
|
|
512
|
+
"type": "TAUTOLOGICAL_ASSERTION",
|
|
513
|
+
"severity": "CRITICAL",
|
|
514
|
+
"line": idx,
|
|
515
|
+
"message": f"Tautological assertion detected ('{raw_line}'). Test assertion always evaluates to True without testing system state."
|
|
516
|
+
})
|
|
517
|
+
|
|
518
|
+
# Rule 4.1: Dangling expect(...) calls without chained matcher
|
|
519
|
+
for d_line, d_raw in find_dangling_expects(clean_code, raw_lines):
|
|
520
|
+
defects.append({
|
|
521
|
+
"type": "DANGLING_ASSERTION_NO_MATCHER",
|
|
522
|
+
"severity": "CRITICAL",
|
|
523
|
+
"line": d_line,
|
|
524
|
+
"message": f"Dangling expect() call without matcher detected ('{d_raw}'). expect() returns an expectation object and does not perform any assertion without a matcher (e.g. .toBeVisible(), .toHaveText())."
|
|
525
|
+
})
|
|
526
|
+
|
|
527
|
+
# Rule 4.2: Python AST Compiler-Grade Verification for .py Test Scripts
|
|
528
|
+
if file_path.endswith(".py"):
|
|
529
|
+
try:
|
|
530
|
+
try:
|
|
531
|
+
tree = ast.parse(content, filename=file_path)
|
|
532
|
+
except IndentationError:
|
|
533
|
+
import textwrap
|
|
534
|
+
tree = ast.parse(textwrap.dedent(content), filename=file_path)
|
|
535
|
+
for node in ast.walk(tree):
|
|
536
|
+
if isinstance(node, ast.Assert):
|
|
537
|
+
if isinstance(node.test, ast.Compare) and len(node.test.ops) == 1:
|
|
538
|
+
op = node.test.ops[0]
|
|
539
|
+
right = node.test.comparators[0]
|
|
540
|
+
if isinstance(op, ast.Eq):
|
|
541
|
+
if ast.dump(node.test.left) == ast.dump(right):
|
|
542
|
+
line_no = getattr(node, "lineno", 1)
|
|
543
|
+
raw_line = raw_lines[line_no - 1].strip() if line_no <= len(raw_lines) else ""
|
|
544
|
+
defects.append({
|
|
545
|
+
"type": "TAUTOLOGICAL_ASSERTION",
|
|
546
|
+
"severity": "CRITICAL",
|
|
547
|
+
"line": line_no,
|
|
548
|
+
"message": f"Tautological assertion detected via AST ('{raw_line}'). Both sides of comparison evaluate to identical AST expressions."
|
|
549
|
+
})
|
|
550
|
+
elif isinstance(op, (ast.GtE, ast.Gt)):
|
|
551
|
+
if isinstance(node.test.left, ast.Call) and getattr(node.test.left.func, 'id', None) == 'len':
|
|
552
|
+
if isinstance(right, ast.Constant):
|
|
553
|
+
if (isinstance(op, ast.GtE) and right.value == 0) or (isinstance(op, ast.Gt) and right.value < 0):
|
|
554
|
+
line_no = getattr(node, "lineno", 1)
|
|
555
|
+
raw_line = raw_lines[line_no - 1].strip() if line_no <= len(raw_lines) else ""
|
|
556
|
+
defects.append({
|
|
557
|
+
"type": "TAUTOLOGICAL_ASSERTION",
|
|
558
|
+
"severity": "CRITICAL",
|
|
559
|
+
"line": line_no,
|
|
560
|
+
"message": f"Tautological assertion detected via AST ('{raw_line}'). len() is non-negative by definition."
|
|
561
|
+
})
|
|
562
|
+
elif isinstance(node.test, ast.Constant) and node.test.value is True:
|
|
563
|
+
line_no = getattr(node, "lineno", 1)
|
|
564
|
+
raw_line = raw_lines[line_no - 1].strip() if line_no <= len(raw_lines) else ""
|
|
565
|
+
defects.append({
|
|
566
|
+
"type": "TAUTOLOGICAL_ASSERTION",
|
|
567
|
+
"severity": "CRITICAL",
|
|
568
|
+
"line": line_no,
|
|
569
|
+
"message": f"Tautological assertion detected via AST ('{raw_line}'). Constant True assertion."
|
|
570
|
+
})
|
|
571
|
+
elif isinstance(node, ast.Expr) and isinstance(node.value, ast.Call):
|
|
572
|
+
if getattr(node.value.func, 'id', None) == 'expect':
|
|
573
|
+
line_no = getattr(node, "lineno", 1)
|
|
574
|
+
raw_line = raw_lines[line_no - 1].strip() if line_no <= len(raw_lines) else ""
|
|
575
|
+
defects.append({
|
|
576
|
+
"type": "DANGLING_ASSERTION_NO_MATCHER",
|
|
577
|
+
"severity": "CRITICAL",
|
|
578
|
+
"line": line_no,
|
|
579
|
+
"message": f"Dangling expect() call without matcher detected via AST ('{raw_line}')."
|
|
580
|
+
})
|
|
581
|
+
|
|
582
|
+
# Rule 4.3: Unpaired Dynamic Data Creation without Teardown Cleanup (AGENTS.md Rule 1.3)
|
|
583
|
+
for node in ast.walk(tree):
|
|
584
|
+
if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
|
|
585
|
+
if node.name.startswith("test_") or node.name.endswith("_test"):
|
|
586
|
+
has_creation = False
|
|
587
|
+
creation_node = None
|
|
588
|
+
has_teardown = False
|
|
589
|
+
for child in ast.walk(node):
|
|
590
|
+
if isinstance(child, ast.Call):
|
|
591
|
+
func_name = ""
|
|
592
|
+
if isinstance(child.func, ast.Name):
|
|
593
|
+
func_name = child.func.id
|
|
594
|
+
elif isinstance(child.func, ast.Attribute):
|
|
595
|
+
func_name = child.func.attr
|
|
596
|
+
if re.search(r'^(?:create_entity|insert_entity|seed_data|generate_user|create_customer)\b', func_name, re.IGNORECASE) or func_name in ("uniqueCode", "DataGenerator"):
|
|
597
|
+
has_creation = True
|
|
598
|
+
if not creation_node:
|
|
599
|
+
creation_node = child
|
|
600
|
+
if re.search(r'^(?:delete|teardown|cleanup|drop|purge|remove)\w*', func_name, re.IGNORECASE) or func_name in ("addCleanup", "cleanup"):
|
|
601
|
+
has_teardown = True
|
|
602
|
+
elif isinstance(child, ast.Try) and child.finalbody:
|
|
603
|
+
has_teardown = True
|
|
604
|
+
if has_creation and not has_teardown:
|
|
605
|
+
line_no = getattr(creation_node, "lineno", node.lineno)
|
|
606
|
+
raw_line = raw_lines[line_no - 1].strip() if line_no <= len(raw_lines) else ""
|
|
607
|
+
defects.append({
|
|
608
|
+
"type": "ORPHAN_DATA_RISK",
|
|
609
|
+
"severity": "WARNING",
|
|
610
|
+
"line": line_no,
|
|
611
|
+
"message": f"Test data creation detected without paired teardown cleanup ('{raw_line}'). Risk of DB state pollution per AGENTS.md Rule 1.3."
|
|
612
|
+
})
|
|
613
|
+
except SyntaxError:
|
|
614
|
+
_ = False # synapse-ignore
|
|
615
|
+
|
|
616
|
+
# Rule 5 (L4): Unawaited Playwright Assertions in JS/TS
|
|
617
|
+
if file_path.endswith((".ts", ".tsx", ".js", ".jsx")):
|
|
618
|
+
for match in UNAWAITED_EXPECT_PATTERN.finditer(clean_code):
|
|
619
|
+
prefix = clean_code[max(0, match.start() - 40):match.start()]
|
|
620
|
+
if re.search(r'\b(?:await|return)\s+$', prefix):
|
|
621
|
+
continue
|
|
622
|
+
surrounding = clean_code[max(0, match.start() - 150):match.start()]
|
|
623
|
+
if any(w in surrounding for w in ("Promise.all", "Promise.allSettled", "return ")):
|
|
624
|
+
continue
|
|
625
|
+
line_no = clean_code[:match.start()].count("\n") + 1
|
|
626
|
+
line_text = raw_lines[line_no - 1].strip() if line_no <= len(raw_lines) else ""
|
|
627
|
+
defects.append({
|
|
628
|
+
"type": "UNAWAITED_ASYNC_ASSERTION",
|
|
629
|
+
"severity": "CRITICAL",
|
|
630
|
+
"line": line_no,
|
|
631
|
+
"message": f"Unawaited async Playwright assertion detected: '{line_text}'. Without 'await', assertion returns a Pending Promise that never validates."
|
|
632
|
+
})
|
|
633
|
+
|
|
634
|
+
# Rule 6 (L2 & L6): Missing Assertions / Fake-Pass
|
|
635
|
+
assert_matches = list(ASSERTION_PATTERN.finditer(clean_code))
|
|
636
|
+
tautology_matches = list(TAUTOLOGY_PATTERN.finditer(clean_code))
|
|
637
|
+
has_real_assert = any(
|
|
638
|
+
not any(tm.start() <= am.start() < tm.end() for tm in tautology_matches)
|
|
639
|
+
for am in assert_matches
|
|
640
|
+
)
|
|
641
|
+
|
|
642
|
+
# F06: Check test cases per function block if multiple tests exist
|
|
643
|
+
TEST_BLOCK_PATTERN = re.compile(
|
|
644
|
+
r'(?m)^[ \t]*(?:(?:test|it)(?:\.(?:only|skip))?\s*\(|def\s+test_[a-zA-Z0-9_]+\s*\(|(?:@Test\s+)?(?:public\s+)?(?:void|def)\s+test[a-zA-Z0-9_]*\s*\()'
|
|
645
|
+
)
|
|
646
|
+
test_matches = list(TEST_BLOCK_PATTERN.finditer(clean_code))
|
|
647
|
+
if len(test_matches) >= 2:
|
|
648
|
+
for i, tm in enumerate(test_matches):
|
|
649
|
+
b_start = tm.start()
|
|
650
|
+
b_end = test_matches[i + 1].start() if i + 1 < len(test_matches) else len(clean_code)
|
|
651
|
+
block_code = clean_code[b_start:b_end]
|
|
652
|
+
b_asserts = list(ASSERTION_PATTERN.finditer(block_code))
|
|
653
|
+
b_tauts = list(TAUTOLOGY_PATTERN.finditer(block_code))
|
|
654
|
+
block_has_real_assert = any(
|
|
655
|
+
not any(tt.start() <= ta.start() < tt.end() for tt in b_tauts)
|
|
656
|
+
for ta in b_asserts
|
|
657
|
+
)
|
|
658
|
+
b_has_interactions = any(
|
|
659
|
+
kw in block_code for kw in ["click", "select", "save", "delete", "create", "search", "navigate", "open", "fill", "goto", "post", "get"]
|
|
660
|
+
)
|
|
661
|
+
b_line = clean_code[:b_start].count("\n") + 1
|
|
662
|
+
if b_has_interactions and not block_has_real_assert:
|
|
663
|
+
defects.append({
|
|
664
|
+
"type": "FAKE_PASS_NO_ASSERTION",
|
|
665
|
+
"severity": "WARNING",
|
|
666
|
+
"line": b_line,
|
|
667
|
+
"message": f"Test block starting at line {b_line} performs interactions but contains zero verification/assertion statements."
|
|
668
|
+
})
|
|
669
|
+
else:
|
|
670
|
+
has_interactions = any(
|
|
671
|
+
kw in clean_code for kw in ["click", "select", "save", "delete", "create", "search", "navigate", "open", "fill", "goto", "post", "get"]
|
|
672
|
+
)
|
|
673
|
+
is_explicit_test = any(t in os.path.basename(file_path).lower() for t in ["test", "spec", "tc-", "tc_"])
|
|
674
|
+
|
|
675
|
+
if has_interactions and not has_real_assert:
|
|
676
|
+
defects.append({
|
|
677
|
+
"type": "FAKE_PASS_NO_ASSERTION",
|
|
678
|
+
"severity": "WARNING",
|
|
679
|
+
"line": 1,
|
|
680
|
+
"message": "Test script performs AUT mutations/interactions but contains zero verification/assertion statements."
|
|
681
|
+
})
|
|
682
|
+
elif is_explicit_test and not has_real_assert and not has_interactions and len(executable_lines) > 0:
|
|
683
|
+
defects.append({
|
|
684
|
+
"type": "NO_ASSERTION_IN_TEST",
|
|
685
|
+
"severity": "WARNING",
|
|
686
|
+
"line": 1,
|
|
687
|
+
"message": "Test case file contains executable logic but has no verification or assertion statements."
|
|
688
|
+
})
|
|
689
|
+
|
|
690
|
+
seen_keys = set()
|
|
691
|
+
deduped = []
|
|
692
|
+
for d in defects:
|
|
693
|
+
k = (d.get("type"), d.get("line"))
|
|
694
|
+
if k not in seen_keys:
|
|
695
|
+
seen_keys.add(k)
|
|
696
|
+
deduped.append(d)
|
|
697
|
+
defects = deduped
|
|
698
|
+
|
|
699
|
+
active_defects = []
|
|
700
|
+
disabled = {r.upper() for r in (disabled_rules or [])}
|
|
701
|
+
norm_rel = rel_path.replace("\\", "/")
|
|
702
|
+
|
|
703
|
+
for d in defects:
|
|
704
|
+
d_type = d.get("type", "").upper()
|
|
705
|
+
if d_type in disabled:
|
|
706
|
+
continue
|
|
707
|
+
line_idx = d.get("line", 1)
|
|
708
|
+
|
|
709
|
+
# Check suppression comment (# synapse-ignore or // synapse-ignore)
|
|
710
|
+
suppressed = False
|
|
711
|
+
candidates = []
|
|
712
|
+
if 1 <= line_idx <= len(raw_lines):
|
|
713
|
+
candidates.append(raw_lines[line_idx - 1])
|
|
714
|
+
if line_idx > 1 and line_idx - 1 <= len(raw_lines):
|
|
715
|
+
candidates.append(raw_lines[line_idx - 2])
|
|
716
|
+
for c in candidates:
|
|
717
|
+
if "synapse-ignore" in c.lower():
|
|
718
|
+
m = re.search(r'synapse-ignore:\s*([A-Za-z0-9_,\s\*\-]+)', c, re.IGNORECASE)
|
|
719
|
+
if m:
|
|
720
|
+
rules = [r.strip().upper() for r in m.group(1).split(",") if r.strip()]
|
|
721
|
+
if "*" in rules or "ALL" in rules or d_type in rules:
|
|
722
|
+
suppressed = True
|
|
723
|
+
break
|
|
724
|
+
if suppressed:
|
|
725
|
+
continue
|
|
726
|
+
|
|
727
|
+
# Check baseline suppression
|
|
728
|
+
if baseline_set:
|
|
729
|
+
if (norm_rel, d_type) in baseline_set or (norm_rel, d_type, line_idx) in baseline_set:
|
|
730
|
+
continue
|
|
731
|
+
|
|
732
|
+
active_defects.append(d)
|
|
733
|
+
|
|
734
|
+
defects = active_defects
|
|
735
|
+
|
|
736
|
+
return {
|
|
737
|
+
"file": rel_path,
|
|
738
|
+
"role": role,
|
|
739
|
+
"defects": defects,
|
|
740
|
+
"is_clean": len(defects) == 0
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
|
|
744
|
+
def run_infer_linter(target_dir=None, output_path=None, strict: bool = False,
|
|
745
|
+
output_format="text", baseline_path=None, generate_baseline_path=None, config_path=None):
|
|
746
|
+
"""Scans test scripts across Groovy, TypeScript, JavaScript, Python, and Java with baseline and SARIF support."""
|
|
747
|
+
EXTENSIONS = ("*.groovy", "*.ts", "*.tsx", "*.js", "*.jsx", "*.py", "*.java")
|
|
748
|
+
|
|
749
|
+
cfg = load_config(config_path=config_path)
|
|
750
|
+
linter_cfg = cfg.get("infer_linter", {})
|
|
751
|
+
extra_ignored = set(linter_cfg.get("exclude_paths", []))
|
|
752
|
+
disabled_rules = set(linter_cfg.get("disabled_rules", []))
|
|
753
|
+
baseline_set = load_baseline(baseline_path)
|
|
754
|
+
|
|
755
|
+
if linter_cfg.get("strict") is not None and not strict:
|
|
756
|
+
strict = bool(linter_cfg.get("strict"))
|
|
757
|
+
|
|
758
|
+
if target_dir:
|
|
759
|
+
if os.path.isfile(target_dir):
|
|
760
|
+
script_files = [target_dir]
|
|
761
|
+
scan_dir = os.path.dirname(target_dir)
|
|
762
|
+
elif os.path.isdir(target_dir):
|
|
763
|
+
scan_dir = target_dir
|
|
764
|
+
raw_files = []
|
|
765
|
+
for ext in EXTENSIONS:
|
|
766
|
+
raw_files.extend(glob.glob(os.path.join(scan_dir, "**", ext), recursive=True))
|
|
767
|
+
# Filter out non-test files like tools, __init__.py, node_modules when scanning generic directory
|
|
768
|
+
ignored_parts = {
|
|
769
|
+
"tools", "bin", "node_modules", ".git", "__pycache__", "venv", ".venv",
|
|
770
|
+
"claude-ecosystem-repos", "dist", "build", ".idea", ".vscode", "editors",
|
|
771
|
+
".mypy_cache", ".pytest_cache", ".ruff_cache", ".sandbox_snapshots",
|
|
772
|
+
"graphify-out"
|
|
773
|
+
} | extra_ignored
|
|
774
|
+
script_files = [
|
|
775
|
+
f for f in raw_files
|
|
776
|
+
if not any(part.lower() in ignored_parts for part in os.path.relpath(f, scan_dir).replace("\\", "/").split("/")[:-1])
|
|
777
|
+
and os.path.basename(f) not in {"__init__.py", "setup.py"}
|
|
778
|
+
]
|
|
779
|
+
else:
|
|
780
|
+
scan_dir = target_dir
|
|
781
|
+
script_files = []
|
|
782
|
+
else:
|
|
783
|
+
# Search candidate directories across test frameworks (Katalon, Playwright, Pytest, Cypress)
|
|
784
|
+
script_files = []
|
|
785
|
+
scan_dir = SCRIPTS_DIR
|
|
786
|
+
for cand in ["Scripts", "tests", "test", "e2e", "specs", "cypress"]:
|
|
787
|
+
cand_path = os.path.join(REPO_ROOT, cand)
|
|
788
|
+
if os.path.isdir(cand_path):
|
|
789
|
+
for ext in EXTENSIONS:
|
|
790
|
+
script_files.extend(glob.glob(os.path.join(cand_path, "**", ext), recursive=True))
|
|
791
|
+
if script_files:
|
|
792
|
+
scan_dir = cand_path
|
|
793
|
+
break
|
|
794
|
+
|
|
795
|
+
results = []
|
|
796
|
+
critical_count = 0
|
|
797
|
+
warning_count = 0
|
|
798
|
+
clean_count = 0
|
|
799
|
+
all_defects = []
|
|
800
|
+
|
|
801
|
+
for s in sorted(set(script_files)):
|
|
802
|
+
res = analyze_script(s, baseline_set=baseline_set, disabled_rules=disabled_rules)
|
|
803
|
+
results.append(res)
|
|
804
|
+
crit = sum(1 for d in res["defects"] if d["severity"] == "CRITICAL")
|
|
805
|
+
warn = sum(1 for d in res["defects"] if d["severity"] == "WARNING")
|
|
806
|
+
critical_count += crit
|
|
807
|
+
warning_count += warn
|
|
808
|
+
if res["is_clean"]:
|
|
809
|
+
clean_count += 1
|
|
810
|
+
for d in res["defects"]:
|
|
811
|
+
all_defects.append({
|
|
812
|
+
"file": res["file"],
|
|
813
|
+
"role": res["role"],
|
|
814
|
+
"type": d["type"],
|
|
815
|
+
"severity": d["severity"],
|
|
816
|
+
"line": d["line"],
|
|
817
|
+
"message": d["message"]
|
|
818
|
+
})
|
|
819
|
+
|
|
820
|
+
# If requested to generate a baseline file, save and exit
|
|
821
|
+
if generate_baseline_path:
|
|
822
|
+
save_baseline(generate_baseline_path, all_defects)
|
|
823
|
+
print(f"✅ Generated baseline file with {len(all_defects)} defects at: {generate_baseline_path}")
|
|
824
|
+
return 0
|
|
825
|
+
|
|
826
|
+
total_scripts = len(script_files)
|
|
827
|
+
if total_scripts == 0:
|
|
828
|
+
health_score = 0.0
|
|
829
|
+
clean_pct = 0.0
|
|
830
|
+
else:
|
|
831
|
+
clean_pct = round((clean_count / total_scripts) * 100, 1)
|
|
832
|
+
critical_penalty = (critical_count * 20.0) / total_scripts
|
|
833
|
+
raw_score = (clean_count / total_scripts) * 100.0 - critical_penalty
|
|
834
|
+
health_score = max(0.0, min(100.0, round(raw_score, 1)))
|
|
835
|
+
|
|
836
|
+
if clean_count < total_scripts and health_score >= 100.0:
|
|
837
|
+
health_score = 99.0
|
|
838
|
+
if clean_count == 0 and total_scripts > 0:
|
|
839
|
+
health_score = 0.0
|
|
840
|
+
|
|
841
|
+
defect_scripts = [r for r in results if not r["is_clean"]]
|
|
842
|
+
report_data = {
|
|
843
|
+
"timestamp": datetime.now().isoformat(),
|
|
844
|
+
"total_scripts": total_scripts,
|
|
845
|
+
"clean_scripts": clean_count,
|
|
846
|
+
"critical_defects": critical_count,
|
|
847
|
+
"warnings": warning_count,
|
|
848
|
+
"health_score_pct": health_score,
|
|
849
|
+
"defect_details": defect_scripts,
|
|
850
|
+
"all_defects": all_defects
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
# Handle specialized output formats
|
|
854
|
+
if output_format == "sarif":
|
|
855
|
+
sarif_out = format_sarif(report_data)
|
|
856
|
+
if output_path:
|
|
857
|
+
os.makedirs(os.path.dirname(os.path.abspath(output_path)), exist_ok=True)
|
|
858
|
+
with open(output_path, "w", encoding="utf-8") as f:
|
|
859
|
+
f.write(sarif_out)
|
|
860
|
+
print(f"SARIF 2.1.0 report saved to: {output_path}")
|
|
861
|
+
else:
|
|
862
|
+
print(sarif_out)
|
|
863
|
+
return 1 if critical_count > 0 else 0
|
|
864
|
+
|
|
865
|
+
if output_format == "junit":
|
|
866
|
+
junit_out = format_junit(report_data)
|
|
867
|
+
if output_path:
|
|
868
|
+
os.makedirs(os.path.dirname(os.path.abspath(output_path)), exist_ok=True)
|
|
869
|
+
with open(output_path, "w", encoding="utf-8") as f:
|
|
870
|
+
f.write(junit_out)
|
|
871
|
+
print(f"JUnit XML report saved to: {output_path}")
|
|
872
|
+
else:
|
|
873
|
+
print(junit_out)
|
|
874
|
+
return 1 if critical_count > 0 else 0
|
|
875
|
+
|
|
876
|
+
if output_format == "json":
|
|
877
|
+
json_out = json.dumps(report_data, indent=2, ensure_ascii=False)
|
|
878
|
+
if output_path:
|
|
879
|
+
os.makedirs(os.path.dirname(os.path.abspath(output_path)), exist_ok=True)
|
|
880
|
+
with open(output_path, "w", encoding="utf-8") as f:
|
|
881
|
+
f.write(json_out)
|
|
882
|
+
print(f"JSON report saved to: {output_path}")
|
|
883
|
+
else:
|
|
884
|
+
print(json_out)
|
|
885
|
+
return 1 if critical_count > 0 else 0
|
|
886
|
+
|
|
887
|
+
# Default: Text output with ANSI banner
|
|
888
|
+
print(f"\n{BOLD}{CYAN}======================================================================{RESET}")
|
|
889
|
+
print(f"{BOLD}{CYAN} ENTERPRISE STATIC DEFECT & FAKE-PASS SENTINEL (Meta Infer-Style) {RESET}")
|
|
890
|
+
print(f"{BOLD}{CYAN}======================================================================{RESET}")
|
|
891
|
+
if total_scripts == 0:
|
|
892
|
+
print(f" Target Scope : 0 Test Scripts discovered in {os.path.basename(scan_dir)}/ (No tests found)")
|
|
893
|
+
print(f" Critical Defects : {GREEN}0{RESET}")
|
|
894
|
+
print(f" Warnings / Suggestions : {GREEN}0{RESET}")
|
|
895
|
+
print(" Clean Scripts : 0/0 (N/A)")
|
|
896
|
+
print(f" Codebase Health Score : {YELLOW}N/A (0 test scripts discovered){RESET}")
|
|
897
|
+
else:
|
|
898
|
+
print(f" Target Scope : {total_scripts} Test Scripts in {os.path.basename(scan_dir)}/ (Polyglot)")
|
|
899
|
+
if baseline_set:
|
|
900
|
+
print(f" Baseline Filter : {CYAN}ACTIVE ({len(baseline_set)} known debt items suppressed){RESET}")
|
|
901
|
+
print(f" Critical Defects : {RED if critical_count > 0 else GREEN}{critical_count}{RESET} (Swallowed exceptions, empty scripts)")
|
|
902
|
+
print(f" Warnings / Suggestions : {YELLOW if warning_count > 0 else GREEN}{warning_count}{RESET} (Missing explicit asserts, excessive delays)")
|
|
903
|
+
print(f" Clean Scripts : {GREEN}{clean_count}/{total_scripts} ({clean_pct:.1f}%){RESET}")
|
|
904
|
+
print(f" Codebase Health Score : {GREEN if health_score == 100 else YELLOW}{health_score:.1f}%{RESET}")
|
|
905
|
+
print(f"{BOLD}{CYAN}======================================================================{RESET}\n")
|
|
906
|
+
|
|
907
|
+
if defect_scripts:
|
|
908
|
+
print(f"{BOLD}Detected Items ({len(defect_scripts)} scripts):{RESET}")
|
|
909
|
+
for r in defect_scripts[:10]:
|
|
910
|
+
for d in r["defects"]:
|
|
911
|
+
color = RED if d["severity"] == "CRITICAL" else YELLOW
|
|
912
|
+
print(f" - [{color}{d['severity']}{RESET}] {r['file']}:{d['line']} - {d['message']}")
|
|
913
|
+
if len(defect_scripts) > 10:
|
|
914
|
+
print(f" ... and {len(defect_scripts) - 10} more scripts (see full JSON report).\n")
|
|
915
|
+
|
|
916
|
+
if output_path:
|
|
917
|
+
dest_json = os.path.abspath(output_path)
|
|
918
|
+
elif target_dir and not os.path.abspath(target_dir).startswith(REPO_ROOT):
|
|
919
|
+
# Resolve target project root when scanning a file or subfolder (e.g. Scripts/, tests/)
|
|
920
|
+
abs_target = os.path.abspath(target_dir)
|
|
921
|
+
cur = abs_target if os.path.isdir(abs_target) else os.path.dirname(abs_target)
|
|
922
|
+
proj_root = cur
|
|
923
|
+
user_home = os.path.abspath(os.path.expanduser("~"))
|
|
924
|
+
while cur and cur != os.path.dirname(cur) and cur != REPO_ROOT and cur != user_home:
|
|
925
|
+
if os.path.isfile(os.path.join(cur, ".synapse.json")) or os.path.isdir(os.path.join(cur, ".git")):
|
|
926
|
+
proj_root = cur
|
|
927
|
+
break
|
|
928
|
+
if os.path.basename(cur) in ("Scripts", "tests", "test", "e2e", "specs", "cypress"):
|
|
929
|
+
proj_root = os.path.dirname(cur)
|
|
930
|
+
break
|
|
931
|
+
cur = os.path.dirname(cur)
|
|
932
|
+
dest_json = os.path.join(proj_root, "reports", "infer_linter_report.json")
|
|
933
|
+
else:
|
|
934
|
+
dest_json = OUTPUT_JSON
|
|
935
|
+
|
|
936
|
+
os.makedirs(os.path.dirname(dest_json), exist_ok=True)
|
|
937
|
+
with open(dest_json, "w", encoding="utf-8") as f:
|
|
938
|
+
json.dump(report_data, f, indent=2, ensure_ascii=False)
|
|
939
|
+
print(f"Detailed audit saved to: {dest_json}\n")
|
|
940
|
+
|
|
941
|
+
if strict:
|
|
942
|
+
fake_pass_count = sum(1 for r in results for d in r["defects"] if d["type"] in ("FAKE_PASS_NO_ASSERTION", "NO_ASSERTION_IN_TEST", "DANGLING_ASSERTION_NO_MATCHER"))
|
|
943
|
+
return 0 if (critical_count == 0 and fake_pass_count == 0) else 1
|
|
944
|
+
return 0 if critical_count == 0 else 1
|
|
945
|
+
|
|
946
|
+
|
|
947
|
+
def main():
|
|
948
|
+
parser = argparse.ArgumentParser(description="Universal QA Static Defect & Assertion Sentinel")
|
|
949
|
+
parser.add_argument("target", nargs="?", default=None, help="Target directory or script to scan")
|
|
950
|
+
parser.add_argument("--dir", help="Target directory to scan (defaults to Scripts/)")
|
|
951
|
+
parser.add_argument("--repo", help="Target repository root containing Scripts/")
|
|
952
|
+
parser.add_argument("--out", "--output", dest="output_file", help="Path to save report")
|
|
953
|
+
parser.add_argument("--format", choices=["text", "json", "sarif", "junit"], default="text", help="Output format (default: text)")
|
|
954
|
+
parser.add_argument("--baseline", help="Path to baseline JSON file to ignore known technical debt")
|
|
955
|
+
parser.add_argument("--generate-baseline", dest="generate_baseline", help="Generate a baseline JSON file from current findings")
|
|
956
|
+
parser.add_argument("--config", help="Path to synapse.config.json")
|
|
957
|
+
parser.add_argument("--strict", action="store_true", default=True, help="Treat missing assertions / fake-passes as fatal errors (default: True)")
|
|
958
|
+
parser.add_argument("--no-strict", "--lenient", action="store_false", dest="strict", help="Allow missing assertions with warning only")
|
|
959
|
+
args = parser.parse_args()
|
|
960
|
+
|
|
961
|
+
target_dir = args.dir or args.target
|
|
962
|
+
if not target_dir and args.repo:
|
|
963
|
+
target_dir = os.path.join(args.repo, "Scripts")
|
|
964
|
+
|
|
965
|
+
return run_infer_linter(
|
|
966
|
+
target_dir=target_dir,
|
|
967
|
+
output_path=args.output_file,
|
|
968
|
+
strict=args.strict,
|
|
969
|
+
output_format=args.format,
|
|
970
|
+
baseline_path=args.baseline,
|
|
971
|
+
generate_baseline_path=args.generate_baseline,
|
|
972
|
+
config_path=args.config
|
|
973
|
+
)
|
|
974
|
+
|
|
975
|
+
|
|
976
|
+
if __name__ == "__main__":
|
|
977
|
+
sys.exit(main())
|