patchi 0.7.5__py3-none-any.whl
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.
- patchi/__init__.py +1 -0
- patchi/__main__.py +13 -0
- patchi/cli/__init__.py +0 -0
- patchi/cli/command_families.py +235 -0
- patchi/cli/commands/__init__.py +0 -0
- patchi/cli/commands/access_cmd.py +65 -0
- patchi/cli/commands/agent_stats_cmd.py +273 -0
- patchi/cli/commands/agents_cmd.py +187 -0
- patchi/cli/commands/ai_cmd.py +308 -0
- patchi/cli/commands/assure_cmd.py +538 -0
- patchi/cli/commands/audit_cmd.py +286 -0
- patchi/cli/commands/auto_cmd.py +110 -0
- patchi/cli/commands/blame_cmd.py +53 -0
- patchi/cli/commands/chains_cmd.py +327 -0
- patchi/cli/commands/charter_cmd.py +173 -0
- patchi/cli/commands/chat_cmd.py +597 -0
- patchi/cli/commands/check_cmd.py +232 -0
- patchi/cli/commands/cleanup_cmd.py +328 -0
- patchi/cli/commands/cockpit_cmd.py +208 -0
- patchi/cli/commands/commands_cmd.py +160 -0
- patchi/cli/commands/cross_repo_cmd.py +113 -0
- patchi/cli/commands/deps_cmd.py +110 -0
- patchi/cli/commands/dev_check_cmd.py +342 -0
- patchi/cli/commands/dev_cmd.py +445 -0
- patchi/cli/commands/doctor_cmd.py +457 -0
- patchi/cli/commands/findings_cmd.py +187 -0
- patchi/cli/commands/fix_cmd.py +648 -0
- patchi/cli/commands/fix_review_cmd.py +273 -0
- patchi/cli/commands/heatmap_cmd.py +62 -0
- patchi/cli/commands/help_cmd.py +159 -0
- patchi/cli/commands/hosted_cmd.py +980 -0
- patchi/cli/commands/init.py +456 -0
- patchi/cli/commands/key_cmd.py +571 -0
- patchi/cli/commands/learn_cmd.py +140 -0
- patchi/cli/commands/link_cmd.py +104 -0
- patchi/cli/commands/log_cmd.py +57 -0
- patchi/cli/commands/memory_cmd.py +215 -0
- patchi/cli/commands/model_cmd.py +207 -0
- patchi/cli/commands/notify_cmd.py +213 -0
- patchi/cli/commands/notify_prompts.py +29 -0
- patchi/cli/commands/patch_cmd.py +231 -0
- patchi/cli/commands/plan_cmd.py +128 -0
- patchi/cli/commands/plugins_cmd.py +307 -0
- patchi/cli/commands/queue_cmd.py +152 -0
- patchi/cli/commands/quick_cmd.py +159 -0
- patchi/cli/commands/ready_cmd.py +292 -0
- patchi/cli/commands/report_cmd.py +416 -0
- patchi/cli/commands/restrict_cmd.py +127 -0
- patchi/cli/commands/review_cmd.py +225 -0
- patchi/cli/commands/rules_cmd.py +233 -0
- patchi/cli/commands/scan_cmd.py +1908 -0
- patchi/cli/commands/settings_cmd.py +45 -0
- patchi/cli/commands/status_cmd.py +679 -0
- patchi/cli/commands/test_cmd.py +1052 -0
- patchi/cli/commands/trend_cmd.py +296 -0
- patchi/cli/commands/undo_cmd.py +235 -0
- patchi/cli/commands/update_cmd.py +345 -0
- patchi/cli/commands/verify_cmd.py +56 -0
- patchi/cli/commands/vr_cmd.py +440 -0
- patchi/cli/commands/watch_cmd.py +304 -0
- patchi/cli/commands/web_cmd.py +114 -0
- patchi/cli/console.py +101 -0
- patchi/cli/display/__init__.py +1 -0
- patchi/cli/display/live_audit.py +269 -0
- patchi/cli/display/live_progress.py +169 -0
- patchi/cli/framework.py +241 -0
- patchi/cli/logo.py +128 -0
- patchi/cli/main.py +222 -0
- patchi/cli/registry.py +1171 -0
- patchi/cli/style.py +68 -0
- patchi/cli/themes.py +187 -0
- patchi/cli/ux.py +444 -0
- patchi/core/__init__.py +0 -0
- patchi/core/agents/__init__.py +0 -0
- patchi/core/agents/api_fuzzer_agent.py +141 -0
- patchi/core/agents/attack_agent.py +242 -0
- patchi/core/agents/base.py +1012 -0
- patchi/core/agents/bug_predictor_agent.py +58 -0
- patchi/core/agents/build_tool_validator.py +150 -0
- patchi/core/agents/cache.py +192 -0
- patchi/core/agents/chaos_agent.py +133 -0
- patchi/core/agents/cicd_generator.py +240 -0
- patchi/core/agents/comment_scanner.py +280 -0
- patchi/core/agents/console_logging_agent.py +156 -0
- patchi/core/agents/coordinator.py +858 -0
- patchi/core/agents/core_scanner.py +269 -0
- patchi/core/agents/coverage_prioritizer.py +181 -0
- patchi/core/agents/dead_code_hygiene.py +296 -0
- patchi/core/agents/dead_code_scanner.py +692 -0
- patchi/core/agents/dependency_scanner.py +725 -0
- patchi/core/agents/doc_claim_agent.py +573 -0
- patchi/core/agents/duplicate_scanner.py +568 -0
- patchi/core/agents/env_scanner.py +410 -0
- patchi/core/agents/feature_flag_agent.py +89 -0
- patchi/core/agents/frontend_framework_agent.py +133 -0
- patchi/core/agents/goroutine_agent.py +82 -0
- patchi/core/agents/governor.py +1972 -0
- patchi/core/agents/i18n_agent.py +95 -0
- patchi/core/agents/license_compliance.py +247 -0
- patchi/core/agents/linking_agent.py +251 -0
- patchi/core/agents/memory_profiler_agent.py +102 -0
- patchi/core/agents/modernization_agent.py +84 -0
- patchi/core/agents/mutation_agent.py +174 -0
- patchi/core/agents/nl_query_agent.py +74 -0
- patchi/core/agents/promise_rejection_agent.py +100 -0
- patchi/core/agents/refactoring_agent.py +286 -0
- patchi/core/agents/resource_leak_agent.py +91 -0
- patchi/core/agents/route_graph_scanner.py +951 -0
- patchi/core/agents/run_agent.py +106 -0
- patchi/core/agents/rust_unwrap_agent.py +100 -0
- patchi/core/agents/sbom_generator.py +284 -0
- patchi/core/agents/scanners.py +67 -0
- patchi/core/agents/side/__init__.py +1 -0
- patchi/core/agents/side/build_agent.py +65 -0
- patchi/core/agents/side/format_agent.py +50 -0
- patchi/core/agents/side/install_agent.py +63 -0
- patchi/core/agents/side_file_scanner.py +549 -0
- patchi/core/agents/snapshot_drift_detector.py +146 -0
- patchi/core/agents/spa_route_inventory.py +203 -0
- patchi/core/agents/test_scanner.py +442 -0
- patchi/core/agents/tool_health.py +109 -0
- patchi/core/agents/tool_runner.py +162 -0
- patchi/core/agents/type_scanner.py +168 -0
- patchi/core/agents/ui_scanner.py +558 -0
- patchi/core/ai/__init__.py +20 -0
- patchi/core/ai/agent_audit.py +153 -0
- patchi/core/ai/agent_profiler.py +277 -0
- patchi/core/ai/client.py +499 -0
- patchi/core/ai/cost_tracker.py +107 -0
- patchi/core/ai/model_router.py +318 -0
- patchi/core/ai/orchestrator.py +625 -0
- patchi/core/ai/prompts.py +681 -0
- patchi/core/ai/smart.py +302 -0
- patchi/core/ai/tool_executor.py +24 -0
- patchi/core/ai/tools/__init__.py +10 -0
- patchi/core/ai/tools/executor.py +621 -0
- patchi/core/ai/tools/realize.py +1160 -0
- patchi/core/ai/tools/registry.py +1577 -0
- patchi/core/assurance/__init__.py +33 -0
- patchi/core/assurance/builder.py +211 -0
- patchi/core/assurance/graph.py +342 -0
- patchi/core/assurance/invariants.py +168 -0
- patchi/core/atomic.py +61 -0
- patchi/core/attackers/__init__.py +17 -0
- patchi/core/attackers/api_abuse.py +89 -0
- patchi/core/attackers/auth_bypass.py +73 -0
- patchi/core/attackers/base.py +91 -0
- patchi/core/attackers/business_logic.py +88 -0
- patchi/core/attackers/planner.py +108 -0
- patchi/core/attackers/priv_escalation.py +88 -0
- patchi/core/attackers/recon.py +87 -0
- patchi/core/brain/__init__.py +0 -0
- patchi/core/brain/ast_utils/__init__.py +81 -0
- patchi/core/brain/ast_utils/assignments.py +219 -0
- patchi/core/brain/ast_utils/calls.py +139 -0
- patchi/core/brain/ast_utils/config.py +132 -0
- patchi/core/brain/ast_utils/control_flow.py +74 -0
- patchi/core/brain/ast_utils/dead_symbols.py +205 -0
- patchi/core/brain/ast_utils/decorators.py +108 -0
- patchi/core/brain/ast_utils/helpers.py +144 -0
- patchi/core/brain/ast_utils/imports.py +169 -0
- patchi/core/brain/ast_utils/scan.py +143 -0
- patchi/core/brain/ast_utils/taint.py +310 -0
- patchi/core/brain/audit.py +379 -0
- patchi/core/brain/baseline.py +195 -0
- patchi/core/brain/blast_radius.py +312 -0
- patchi/core/brain/body_tags.py +144 -0
- patchi/core/brain/brain.py +1161 -0
- patchi/core/brain/brain_context.py +393 -0
- patchi/core/brain/brain_watcher.py +340 -0
- patchi/core/brain/charter.py +473 -0
- patchi/core/brain/classifier.py +214 -0
- patchi/core/brain/cockpit.py +350 -0
- patchi/core/brain/code_query.py +710 -0
- patchi/core/brain/contract.py +889 -0
- patchi/core/brain/contract_diff.py +155 -0
- patchi/core/brain/council.py +800 -0
- patchi/core/brain/cross_repo.py +104 -0
- patchi/core/brain/dead_code_tools.py +157 -0
- patchi/core/brain/doc_validator.py +197 -0
- patchi/core/brain/domain_activator.py +2183 -0
- patchi/core/brain/enriched_context.py +220 -0
- patchi/core/brain/file_corpus.py +220 -0
- patchi/core/brain/framework.py +953 -0
- patchi/core/brain/freshness.py +273 -0
- patchi/core/brain/git_aware.py +206 -0
- patchi/core/brain/heatmap.py +104 -0
- patchi/core/brain/ignore_parser.py +153 -0
- patchi/core/brain/import_graph.py +486 -0
- patchi/core/brain/languages.py +397 -0
- patchi/core/brain/layered_brain.py +419 -0
- patchi/core/brain/learning.py +229 -0
- patchi/core/brain/orphaned_endpoints.py +313 -0
- patchi/core/brain/personas/__init__.py +648 -0
- patchi/core/brain/personas/bad_user.py +165 -0
- patchi/core/brain/personas/base.py +349 -0
- patchi/core/brain/proactive.py +807 -0
- patchi/core/brain/project_context.py +121 -0
- patchi/core/brain/project_reader.py +521 -0
- patchi/core/brain/reasoning.py +269 -0
- patchi/core/brain/route_detector/__init__.py +15 -0
- patchi/core/brain/route_detector/base.py +31 -0
- patchi/core/brain/route_detector/csharp.py +209 -0
- patchi/core/brain/route_detector/file_based.py +81 -0
- patchi/core/brain/route_detector/go.py +152 -0
- patchi/core/brain/route_detector/java.py +195 -0
- patchi/core/brain/route_detector/javascript.py +197 -0
- patchi/core/brain/route_detector/php.py +158 -0
- patchi/core/brain/route_detector/python.py +193 -0
- patchi/core/brain/route_detector/registry.py +25 -0
- patchi/core/brain/route_detector/ruby.py +134 -0
- patchi/core/brain/route_detector/rust.py +216 -0
- patchi/core/brain/route_detector/swift.py +118 -0
- patchi/core/brain/route_mapper.py +265 -0
- patchi/core/brain/scanner.py +2136 -0
- patchi/core/brain/secrets.py +280 -0
- patchi/core/brain/symbol_graph.py +1955 -0
- patchi/core/brain/team.py +28 -0
- patchi/core/brain/trace_log.py +132 -0
- patchi/core/brain/type_checker/__init__.py +65 -0
- patchi/core/brain/type_checker/base.py +60 -0
- patchi/core/brain/type_checker/csharp.py +59 -0
- patchi/core/brain/type_checker/dart.py +59 -0
- patchi/core/brain/type_checker/go.py +81 -0
- patchi/core/brain/type_checker/java.py +75 -0
- patchi/core/brain/type_checker/kotlin.py +75 -0
- patchi/core/brain/type_checker/php.py +88 -0
- patchi/core/brain/type_checker/python.py +87 -0
- patchi/core/brain/type_checker/rust.py +81 -0
- patchi/core/brain/type_checker/swift.py +59 -0
- patchi/core/brain/type_checker/typescript.py +298 -0
- patchi/core/brain/understander.py +130 -0
- patchi/core/brain/verify.py +379 -0
- patchi/core/campaigns/__init__.py +14 -0
- patchi/core/campaigns/base.py +62 -0
- patchi/core/campaigns/data_flow_abuse.py +153 -0
- patchi/core/campaigns/orchestrator.py +140 -0
- patchi/core/campaigns/state_transitions.py +178 -0
- patchi/core/ci_bundle.py +104 -0
- patchi/core/config.py +311 -0
- patchi/core/constants.py +245 -0
- patchi/core/debug/__init__.py +25 -0
- patchi/core/debug/adapters/__init__.py +11 -0
- patchi/core/debug/adapters/codelldb.py +379 -0
- patchi/core/debug/adapters/node.py +222 -0
- patchi/core/debug/adapters/powershell.py +210 -0
- patchi/core/debug/adapters/python.py +244 -0
- patchi/core/debug/capture.py +210 -0
- patchi/core/debug/dap_client.py +268 -0
- patchi/core/detector/__init__.py +0 -0
- patchi/core/detector/audit.py +194 -0
- patchi/core/detector/bus.py +226 -0
- patchi/core/detector/dispatcher.py +275 -0
- patchi/core/detector/event.py +254 -0
- patchi/core/detector/sigma_engine.py +378 -0
- patchi/core/detector/triage.py +289 -0
- patchi/core/export/sarif.py +113 -0
- patchi/core/fix/__init__.py +17 -0
- patchi/core/fix/applier.py +574 -0
- patchi/core/fix/base.py +510 -0
- patchi/core/fix/code_fixer.py +169 -0
- patchi/core/fix/dead_code_remover.py +131 -0
- patchi/core/fix/fix_agents.py +775 -0
- patchi/core/fix/patch.py +444 -0
- patchi/core/fix/risk_gate.py +383 -0
- patchi/core/fix/security_fixer.py +93 -0
- patchi/core/fix/verify_loop.py +204 -0
- patchi/core/fuzz/__init__.py +8 -0
- patchi/core/fuzz/corpus.py +137 -0
- patchi/core/fuzz/input_fuzzer.py +256 -0
- patchi/core/fuzz/sequence_fuzzer.py +162 -0
- patchi/core/fuzz/state_fuzzer.py +236 -0
- patchi/core/health.py +407 -0
- patchi/core/hosted/__init__.py +1 -0
- patchi/core/hosted/anomaly.py +298 -0
- patchi/core/hosted/audit_log.py +102 -0
- patchi/core/hosted/compliance_report.py +148 -0
- patchi/core/hosted/ip_reputation.py +169 -0
- patchi/core/hosted/log_parsers.py +251 -0
- patchi/core/hosted/tokens.py +127 -0
- patchi/core/hosted/watchlist.py +164 -0
- patchi/core/hosted/webhooks.py +156 -0
- patchi/core/memory.py +437 -0
- patchi/core/notifications/__init__.py +18 -0
- patchi/core/notifications/channels.py +192 -0
- patchi/core/notifications/digest.py +141 -0
- patchi/core/notifications/escalation.py +158 -0
- patchi/core/notifications/notifier.py +182 -0
- patchi/core/notifications/quiet_hours.py +69 -0
- patchi/core/plugins/__init__.py +48 -0
- patchi/core/plugins/analyzer.py +326 -0
- patchi/core/plugins/analyzers/__init__.py +6 -0
- patchi/core/plugins/analyzers/dead_code_analyzer.py +120 -0
- patchi/core/plugins/analyzers/secret_scanner.py +158 -0
- patchi/core/plugins/analyzers/todo_scanner.py +115 -0
- patchi/core/plugins/registry.py +335 -0
- patchi/core/queue.py +375 -0
- patchi/core/reliability/__init__.py +13 -0
- patchi/core/reliability/chaos.py +163 -0
- patchi/core/reliability/fault_injector.py +172 -0
- patchi/core/reliability/idempotency.py +128 -0
- patchi/core/reliability/recovery.py +147 -0
- patchi/core/runtime/__init__.py +5 -0
- patchi/core/runtime/tracer.py +230 -0
- patchi/core/scan_bus.py +156 -0
- patchi/core/security/__init__.py +1 -0
- patchi/core/security/ai_validator.py +462 -0
- patchi/core/security/app_mapper.py +216 -0
- patchi/core/security/app_profile.py +464 -0
- patchi/core/security/attack_feedback.py +141 -0
- patchi/core/security/attack_scenarios/__init__.py +1 -0
- patchi/core/security/attack_tree.py +176 -0
- patchi/core/security/auth_audit_agent.py +344 -0
- patchi/core/security/authz_agent.py +602 -0
- patchi/core/security/auto_fix_proactive.py +620 -0
- patchi/core/security/auto_fixer.py +660 -0
- patchi/core/security/auto_ticket.py +53 -0
- patchi/core/security/bandit_agent.py +152 -0
- patchi/core/security/blast_radius.py +226 -0
- patchi/core/security/browser_tester.py +333 -0
- patchi/core/security/business_logic_agent.py +263 -0
- patchi/core/security/catch_block_auditor.py +395 -0
- patchi/core/security/cdn_cache_agent.py +357 -0
- patchi/core/security/chain_analyzer.py +321 -0
- patchi/core/security/chain_to_assurance.py +168 -0
- patchi/core/security/charter.py +510 -0
- patchi/core/security/cloud_waf_detector.py +295 -0
- patchi/core/security/codeql_agent.py +233 -0
- patchi/core/security/compliance_agent.py +348 -0
- patchi/core/security/confidence_gate.py +423 -0
- patchi/core/security/container_scanner.py +282 -0
- patchi/core/security/crypto_agent.py +378 -0
- patchi/core/security/cve_monitor.py +262 -0
- patchi/core/security/dast_agent.py +865 -0
- patchi/core/security/defectdojo.py +238 -0
- patchi/core/security/defenders/__init__.py +75 -0
- patchi/core/security/defenders/auth_middleware.py +115 -0
- patchi/core/security/defenders/base.py +97 -0
- patchi/core/security/defenders/block_ip.py +71 -0
- patchi/core/security/defenders/block_ws_origin.py +36 -0
- patchi/core/security/defenders/crypto_fix.py +118 -0
- patchi/core/security/defenders/enforce_rate_limit.py +108 -0
- patchi/core/security/defenders/fix_code.py +93 -0
- patchi/core/security/defenders/invalidate_session.py +40 -0
- patchi/core/security/defenders/patch_config.py +70 -0
- patchi/core/security/defenders/rotate_secret.py +54 -0
- patchi/core/security/defenders/suspend_account.py +41 -0
- patchi/core/security/defenders/update_dependency.py +160 -0
- patchi/core/security/defense_layer.py +217 -0
- patchi/core/security/dependency_vulnerability_agent.py +616 -0
- patchi/core/security/detection_pipeline.py +289 -0
- patchi/core/security/dns_security_agent.py +497 -0
- patchi/core/security/domain_activator_v2.py +913 -0
- patchi/core/security/domain_loader.py +1004 -0
- patchi/core/security/domains/__init__.py +0 -0
- patchi/core/security/email_authentication_agent.py +417 -0
- patchi/core/security/env_var_validator.py +304 -0
- patchi/core/security/evidence.py +100 -0
- patchi/core/security/falco_runtime_agent.py +387 -0
- patchi/core/security/fix-playbooks/__init__.py +0 -0
- patchi/core/security/gated_finding.py +85 -0
- patchi/core/security/git_diff_activator.py +367 -0
- patchi/core/security/governance.py +208 -0
- patchi/core/security/gradual_gate.py +34 -0
- patchi/core/security/history.py +315 -0
- patchi/core/security/iac_scanner.py +250 -0
- patchi/core/security/ignore_expiry.py +111 -0
- patchi/core/security/ignore_learner.py +416 -0
- patchi/core/security/injection_agent.py +319 -0
- patchi/core/security/insecure_randomness_agent.py +288 -0
- patchi/core/security/intent_analyzer.py +326 -0
- patchi/core/security/jwt_agent.py +453 -0
- patchi/core/security/kubernetes_agent.py +638 -0
- patchi/core/security/layer2_orchestrator.py +341 -0
- patchi/core/security/llm_security_agent.py +252 -0
- patchi/core/security/misconfig_agent.py +600 -0
- patchi/core/security/mobile_security_agent.py +474 -0
- patchi/core/security/network_agent.py +376 -0
- patchi/core/security/noise_filter.py +274 -0
- patchi/core/security/orchestrator.py +313 -0
- patchi/core/security/pattern_context.py +125 -0
- patchi/core/security/pattern_loader.py +101 -0
- patchi/core/security/pentest/__init__.py +4 -0
- patchi/core/security/pentest/base.py +58 -0
- patchi/core/security/pentest/dalfox_adapter.py +40 -0
- patchi/core/security/pentest/ffuf_adapter.py +48 -0
- patchi/core/security/pentest/nuclei_adapter.py +50 -0
- patchi/core/security/pentest/registry.py +80 -0
- patchi/core/security/pentest/shannon_adapter.py +107 -0
- patchi/core/security/pentest/sqlmap_adapter.py +56 -0
- patchi/core/security/pentest/zap_adapter.py +52 -0
- patchi/core/security/plan_auditor.py +276 -0
- patchi/core/security/policy_engine.py +272 -0
- patchi/core/security/prechecks.py +172 -0
- patchi/core/security/precommit_hook.py +247 -0
- patchi/core/security/privacy_agent.py +361 -0
- patchi/core/security/push_notification_agent.py +417 -0
- patchi/core/security/pysa_agent.py +143 -0
- patchi/core/security/reasoning.py +442 -0
- patchi/core/security/red_team_agent.py +184 -0
- patchi/core/security/red_team_engine.py +1142 -0
- patchi/core/security/remediation.py +360 -0
- patchi/core/security/request_interceptor.py +294 -0
- patchi/core/security/runtime_validator.py +245 -0
- patchi/core/security/saml_sso_agent.py +401 -0
- patchi/core/security/sast_agent.py +213 -0
- patchi/core/security/sast_gate.py +95 -0
- patchi/core/security/scheduler.py +287 -0
- patchi/core/security/secrets_runtime_agent.py +476 -0
- patchi/core/security/security_agents.py +175 -0
- patchi/core/security/security_config.py +551 -0
- patchi/core/security/security_probe.py +762 -0
- patchi/core/security/security_taint.py +1005 -0
- patchi/core/security/sensitive_data_agent.py +271 -0
- patchi/core/security/service_mesh_agent.py +412 -0
- patchi/core/security/session_management_agent.py +245 -0
- patchi/core/security/ssrf_agent.py +422 -0
- patchi/core/security/supply_chain.py +449 -0
- patchi/core/security/threat_model_generator.py +378 -0
- patchi/core/security/threat_model_updater.py +196 -0
- patchi/core/security/tool_adapters.py +135 -0
- patchi/core/security/tool_verify.py +173 -0
- patchi/core/security/websocket_security_agent.py +188 -0
- patchi/core/snapshot.py +242 -0
- patchi/core/tenant.py +386 -0
- patchi/core/testing/__init__.py +17 -0
- patchi/core/testing/_browser.py +147 -0
- patchi/core/testing/ads_agent.py +141 -0
- patchi/core/testing/api_contract_agent.py +450 -0
- patchi/core/testing/app_discovery_agent.py +641 -0
- patchi/core/testing/app_launcher.py +184 -0
- patchi/core/testing/browser_test_agent.py +516 -0
- patchi/core/testing/e2e_flow_agent.py +354 -0
- patchi/core/testing/flake_detector_agent.py +292 -0
- patchi/core/testing/gate.py +31 -0
- patchi/core/testing/live_test_runner.py +304 -0
- patchi/core/testing/live_v2/__init__.py +1 -0
- patchi/core/testing/live_v2/browser_pool.py +349 -0
- patchi/core/testing/live_v2/browser_test_runner.py +313 -0
- patchi/core/testing/live_v2/runner.py +626 -0
- patchi/core/testing/live_v2/screenshot_manager.py +474 -0
- patchi/core/testing/live_v2/stress_orchestrator.py +523 -0
- patchi/core/testing/live_v2/video_recorder.py +303 -0
- patchi/core/testing/regression_agent.py +302 -0
- patchi/core/testing/security_test_agent.py +253 -0
- patchi/core/testing/stress_test_agent.py +203 -0
- patchi/core/testing/test_agents.py +50 -0
- patchi/core/testing/test_config.py +194 -0
- patchi/core/testing/ui_accessibility_agent.py +324 -0
- patchi/core/testing/ui_button_agent.py +294 -0
- patchi/core/testing/ui_layout_agent.py +330 -0
- patchi/core/testing/unit_test_agent.py +1149 -0
- patchi/core/testing/visual_regression_agent.py +260 -0
- patchi/web/__init__.py +1 -0
- patchi/web/api/__init__.py +1 -0
- patchi/web/api/brain_map.py +114 -0
- patchi/web/api/charts.py +47 -0
- patchi/web/api/chat.py +224 -0
- patchi/web/api/cicd.py +576 -0
- patchi/web/api/dast_evidence.py +49 -0
- patchi/web/api/dev_check.py +320 -0
- patchi/web/api/fix.py +134 -0
- patchi/web/api/guard.py +65 -0
- patchi/web/api/hosted.py +128 -0
- patchi/web/api/hosted_v2.py +234 -0
- patchi/web/api/live_testing.py +699 -0
- patchi/web/api/scan.py +582 -0
- patchi/web/api/smart.py +111 -0
- patchi/web/api/tenant.py +117 -0
- patchi/web/api/tools.py +85 -0
- patchi/web/api_legacy.py +2401 -0
- patchi/web/app.py +310 -0
- patchi/web/events.py +483 -0
- patchi/web/routes/__init__.py +1 -0
- patchi/web/routes/assurance.py +541 -0
- patchi/web/routes/brain.py +36 -0
- patchi/web/routes/charter.py +227 -0
- patchi/web/routes/chat.py +23 -0
- patchi/web/routes/dashboard.py +558 -0
- patchi/web/routes/dashboard_v2.py +402 -0
- patchi/web/routes/findings.py +330 -0
- patchi/web/routes/guard.py +35 -0
- patchi/web/routes/history.py +126 -0
- patchi/web/routes/landing.py +52 -0
- patchi/web/routes/live_testing.py +24 -0
- patchi/web/routes/review.py +57 -0
- patchi/web/routes/self_improvement.py +110 -0
- patchi/web/routes/settings.py +49 -0
- patchi/web/routes/tokens.py +29 -0
- patchi/web/spawn.py +139 -0
- patchi/web/ws.py +141 -0
- patchi-0.7.5.dist-info/METADATA +315 -0
- patchi-0.7.5.dist-info/RECORD +496 -0
- patchi-0.7.5.dist-info/WHEEL +5 -0
- patchi-0.7.5.dist-info/licenses/LICENSE +60 -0
- patchi-0.7.5.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
"""
|
|
2
|
+
UIAccessibilityAgent — Real WCAG accessibility testing via Playwright + axe-core.
|
|
3
|
+
|
|
4
|
+
Injects axe-core into every page and runs comprehensive accessibility checks:
|
|
5
|
+
- Color contrast (WCAG 2.1 AA)
|
|
6
|
+
- Missing alt text on images
|
|
7
|
+
- Missing form labels
|
|
8
|
+
- Keyboard navigation and focus order
|
|
9
|
+
- ARIA attributes and roles
|
|
10
|
+
- Heading hierarchy
|
|
11
|
+
- Landmark regions
|
|
12
|
+
- Screen reader compatibility
|
|
13
|
+
- Touch target sizes (WCAG 2.5.5)
|
|
14
|
+
|
|
15
|
+
Screenshots are captured per page and linked to findings; HTTP/console errors
|
|
16
|
+
are surfaced so a11y runs don't silently no-op on broken pages.
|
|
17
|
+
|
|
18
|
+
Requires: playwright, axe-core (injected from CDN)
|
|
19
|
+
"""
|
|
20
|
+
from __future__ import annotations
|
|
21
|
+
|
|
22
|
+
import logging
|
|
23
|
+
|
|
24
|
+
from ..agents.base import (
|
|
25
|
+
AgentDomain,
|
|
26
|
+
AgentGroup,
|
|
27
|
+
AgentInput,
|
|
28
|
+
AgentResult,
|
|
29
|
+
BaseAgent,
|
|
30
|
+
Severity,
|
|
31
|
+
make_finding,
|
|
32
|
+
register,
|
|
33
|
+
)
|
|
34
|
+
from ._browser import (
|
|
35
|
+
discover_routes,
|
|
36
|
+
find_server,
|
|
37
|
+
open_page,
|
|
38
|
+
save_screenshot,
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
# axe-core CDN for injection
|
|
42
|
+
AXE_CORE_JS = "https://cdnjs.cloudflare.com/ajax/libs/axe-core/4.8.4/axe.min.js"
|
|
43
|
+
|
|
44
|
+
AXE_RULES_BY_SEVERITY = {
|
|
45
|
+
"critical": [
|
|
46
|
+
"color-contrast", "image-alt", "label", "select-name", "button-name",
|
|
47
|
+
"input-image-alt", "aria-required-attr", "valid-lang", "doc-title",
|
|
48
|
+
],
|
|
49
|
+
"serious": [
|
|
50
|
+
"aria-allowed-attr", "aria-hidden-body", "aria-hidden-focus", "bypass",
|
|
51
|
+
"definition-list", "dlitem", "duplicate-id", "heading-order", "html-has-lang",
|
|
52
|
+
"html-lang-valid", "landmark-banner-is-top-level", "landmark-contentinfo-is-top-level",
|
|
53
|
+
"landmark-main-is-top-level", "landmark-no-duplicate-banner", "landmark-one-main",
|
|
54
|
+
"meta-viewport", "region",
|
|
55
|
+
],
|
|
56
|
+
"moderate": [
|
|
57
|
+
"color-contrast-enhanced", "css-orientation-lock", "frame-title",
|
|
58
|
+
"heading-level", "html-xml-lang-mismatch", "identical-links-same-purpose",
|
|
59
|
+
"label-title-only", "link-in-text-block", "p-as-heading", "table-duplicate-name",
|
|
60
|
+
],
|
|
61
|
+
"minor": [
|
|
62
|
+
"css-orientation-lock", "definition-list", "dlitem", "link-name",
|
|
63
|
+
"list", "listitem", "meter-name", "scrollable-region-focusable", "tabindex",
|
|
64
|
+
],
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
_log = logging.getLogger("patchi.testing.ui_accessibility_agent")
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
@register
|
|
72
|
+
class UIAccessibilityAgent(BaseAgent):
|
|
73
|
+
"""Real WCAG accessibility testing via Playwright + axe-core injection."""
|
|
74
|
+
|
|
75
|
+
group = AgentGroup.TEST
|
|
76
|
+
domain = AgentDomain.VISUAL
|
|
77
|
+
name = "UIAccessibilityAgent"
|
|
78
|
+
description = "axe-core WCAG testing: contrast, alt text, labels, keyboard nav, ARIA"
|
|
79
|
+
timeout = 180
|
|
80
|
+
|
|
81
|
+
def _run(self, inp: AgentInput, result: AgentResult) -> None:
|
|
82
|
+
try:
|
|
83
|
+
from playwright.sync_api import sync_playwright # noqa: F401
|
|
84
|
+
except ImportError:
|
|
85
|
+
self.skip(result, "playwright not installed — pip install playwright && playwright install chromium")
|
|
86
|
+
return
|
|
87
|
+
|
|
88
|
+
base_url = find_server(inp.root, inp.config, inp.extra)
|
|
89
|
+
if not base_url:
|
|
90
|
+
self.skip(result, "no running server found — start `p web` (default :1612)")
|
|
91
|
+
return
|
|
92
|
+
|
|
93
|
+
routes = discover_routes(inp.config, inp.extra)
|
|
94
|
+
if not routes:
|
|
95
|
+
self.skip(result, "no routes discovered")
|
|
96
|
+
return
|
|
97
|
+
|
|
98
|
+
screenshot_dir = inp.root / ".patchi" / "evidence" / "screenshots" / "ui_accessibility"
|
|
99
|
+
total_violations = 0
|
|
100
|
+
all_violations = []
|
|
101
|
+
pages_tested = 0
|
|
102
|
+
error_pages = 0
|
|
103
|
+
|
|
104
|
+
with sync_playwright() as pw:
|
|
105
|
+
browser = pw.chromium.launch(headless=True)
|
|
106
|
+
|
|
107
|
+
for page_path in routes[:15]:
|
|
108
|
+
ps = open_page(browser, f"{base_url}{page_path}")
|
|
109
|
+
page = ps.page
|
|
110
|
+
try:
|
|
111
|
+
slug = page_path.strip("/").replace("/", "_") or "root"
|
|
112
|
+
shot = save_screenshot(page, screenshot_dir, slug)
|
|
113
|
+
rel = str(shot.relative_to(inp.root)) if shot else None
|
|
114
|
+
|
|
115
|
+
if ps.status and ps.status >= 400:
|
|
116
|
+
error_pages += 1
|
|
117
|
+
result.add_finding(
|
|
118
|
+
make_finding(
|
|
119
|
+
agent=self.name,
|
|
120
|
+
finding_type="page_error",
|
|
121
|
+
severity=Severity.HIGH,
|
|
122
|
+
file=page_path,
|
|
123
|
+
message=f"HTTP {ps.status} on {page_path} (a11y test skipped)",
|
|
124
|
+
extra={"screenshot": rel},
|
|
125
|
+
)
|
|
126
|
+
)
|
|
127
|
+
continue
|
|
128
|
+
|
|
129
|
+
for ce in ps.console_errors[:5]:
|
|
130
|
+
result.add_finding(
|
|
131
|
+
make_finding(
|
|
132
|
+
agent=self.name,
|
|
133
|
+
finding_type="console_error",
|
|
134
|
+
severity=Severity.LOW,
|
|
135
|
+
file=page_path,
|
|
136
|
+
message=f"Console error on {page_path}: {ce[:160]}",
|
|
137
|
+
extra={"screenshot": rel},
|
|
138
|
+
)
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
violations = self._run_axe_core(page, page_path)
|
|
142
|
+
total_violations += len(violations)
|
|
143
|
+
all_violations.extend(violations)
|
|
144
|
+
|
|
145
|
+
kb_issues = self._test_keyboard_navigation(page, page_path)
|
|
146
|
+
for issue in kb_issues:
|
|
147
|
+
if rel:
|
|
148
|
+
issue.extra = {**(issue.extra or {}), "screenshot": rel}
|
|
149
|
+
result.add_finding(issue)
|
|
150
|
+
|
|
151
|
+
pages_tested += 1
|
|
152
|
+
finally:
|
|
153
|
+
page.close()
|
|
154
|
+
|
|
155
|
+
browser.close()
|
|
156
|
+
|
|
157
|
+
for v in all_violations:
|
|
158
|
+
severity = self._map_impact(v.get("impact", "moderate"))
|
|
159
|
+
result.add_finding(
|
|
160
|
+
make_finding(
|
|
161
|
+
agent=self.name,
|
|
162
|
+
finding_type="a11y_violation",
|
|
163
|
+
severity=severity,
|
|
164
|
+
file=v.get("file", ""),
|
|
165
|
+
message=f"[{v.get('impact', '?')}] {v.get('id', 'unknown')}: {v.get('description', '')}",
|
|
166
|
+
detail=self._format_violation(v),
|
|
167
|
+
extra={"rule": v.get("id", ""), "wcag_tags": v.get("tags", []),
|
|
168
|
+
"screenshot": v.get("screenshot")},
|
|
169
|
+
)
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
if total_violations == 0 and error_pages == 0 and pages_tested > 0:
|
|
173
|
+
result.add_finding(
|
|
174
|
+
make_finding(
|
|
175
|
+
agent=self.name,
|
|
176
|
+
finding_type="a11y_summary",
|
|
177
|
+
severity=Severity.INFO,
|
|
178
|
+
file="(all pages)",
|
|
179
|
+
message=f"Accessibility PASSED: {pages_tested} pages, 0 violations",
|
|
180
|
+
)
|
|
181
|
+
)
|
|
182
|
+
elif pages_tested > 0 or error_pages > 0:
|
|
183
|
+
result.add_finding(
|
|
184
|
+
make_finding(
|
|
185
|
+
agent=self.name,
|
|
186
|
+
finding_type="a11y_summary",
|
|
187
|
+
severity=Severity.HIGH if (total_violations or error_pages) else Severity.MEDIUM,
|
|
188
|
+
file="(all pages)",
|
|
189
|
+
message=f"Accessibility: {total_violations} violations, {error_pages} error pages across {pages_tested} pages",
|
|
190
|
+
)
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
result.data["suite"] = {
|
|
194
|
+
"runner": "axe_core",
|
|
195
|
+
"pages_tested": pages_tested,
|
|
196
|
+
"total_violations": total_violations,
|
|
197
|
+
"violations": all_violations[:50],
|
|
198
|
+
}
|
|
199
|
+
result.files_scanned = pages_tested
|
|
200
|
+
|
|
201
|
+
def _run_axe_core(self, page, page_path: str) -> list[dict]:
|
|
202
|
+
"""Inject axe-core and run accessibility audit."""
|
|
203
|
+
violations = []
|
|
204
|
+
try:
|
|
205
|
+
page.add_script_tag(url=AXE_CORE_JS)
|
|
206
|
+
page.wait_for_function("typeof axe !== 'undefined'", timeout=10000)
|
|
207
|
+
|
|
208
|
+
axe_results = page.evaluate("""async () => {
|
|
209
|
+
try {
|
|
210
|
+
const results = await axe.run(document, {
|
|
211
|
+
runOnly: ['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa', 'best-practice']
|
|
212
|
+
});
|
|
213
|
+
return {
|
|
214
|
+
violations: results.violations.map(v => ({
|
|
215
|
+
id: v.id,
|
|
216
|
+
impact: v.impact,
|
|
217
|
+
description: v.description,
|
|
218
|
+
help: v.help,
|
|
219
|
+
helpUrl: v.helpUrl,
|
|
220
|
+
tags: v.tags,
|
|
221
|
+
nodes: v.nodes.map(n => ({
|
|
222
|
+
target: n.target,
|
|
223
|
+
html: n.html ? n.html.substring(0, 200) : '',
|
|
224
|
+
failureSummary: n.failureSummary,
|
|
225
|
+
})),
|
|
226
|
+
})),
|
|
227
|
+
passes: results.passes.length,
|
|
228
|
+
incomplete: results.incomplete.length,
|
|
229
|
+
inapplicable: results.inapplicable.length,
|
|
230
|
+
};
|
|
231
|
+
} catch (e) {
|
|
232
|
+
return { error: e.message, violations: [] };
|
|
233
|
+
}
|
|
234
|
+
}""")
|
|
235
|
+
|
|
236
|
+
if axe_results.get("error"):
|
|
237
|
+
return violations
|
|
238
|
+
|
|
239
|
+
for v in axe_results.get("violations", []):
|
|
240
|
+
v["file"] = page_path
|
|
241
|
+
v["passes"] = axe_results.get("passes", 0)
|
|
242
|
+
v["incomplete"] = axe_results.get("incomplete", 0)
|
|
243
|
+
violations.append(v)
|
|
244
|
+
|
|
245
|
+
except Exception as e:
|
|
246
|
+
_log.warning("UIAccessibilityAgent._run_axe_core failed (offline?): %s", e)
|
|
247
|
+
|
|
248
|
+
return violations
|
|
249
|
+
|
|
250
|
+
def _test_keyboard_navigation(self, page, page_path: str) -> list:
|
|
251
|
+
"""Test that all interactive elements are keyboard accessible."""
|
|
252
|
+
findings = []
|
|
253
|
+
try:
|
|
254
|
+
focused_elements = []
|
|
255
|
+
for _ in range(30):
|
|
256
|
+
page.keyboard.press("Tab")
|
|
257
|
+
page.wait_for_timeout(100)
|
|
258
|
+
|
|
259
|
+
focused = page.evaluate("""() => {
|
|
260
|
+
const el = document.activeElement;
|
|
261
|
+
if (!el || el === document.body) return null;
|
|
262
|
+
return {
|
|
263
|
+
tag: el.tagName.toLowerCase(),
|
|
264
|
+
id: el.id || '',
|
|
265
|
+
role: el.getAttribute('role') || '',
|
|
266
|
+
tabindex: el.getAttribute('tabindex'),
|
|
267
|
+
ariaLabel: el.getAttribute('aria-label') || '',
|
|
268
|
+
text: (el.innerText || '').substring(0, 50),
|
|
269
|
+
};
|
|
270
|
+
}""")
|
|
271
|
+
|
|
272
|
+
if focused:
|
|
273
|
+
focused_elements.append(focused)
|
|
274
|
+
|
|
275
|
+
interactive_no_focus = page.evaluate("""() => {
|
|
276
|
+
const issues = [];
|
|
277
|
+
document.querySelectorAll('button, a[href], input, select, textarea, [onclick]').forEach(el => {
|
|
278
|
+
const tabindex = el.getAttribute('tabindex');
|
|
279
|
+
if (tabindex === '-1') {
|
|
280
|
+
issues.push({
|
|
281
|
+
tag: el.tagName.toLowerCase(),
|
|
282
|
+
id: el.id || '',
|
|
283
|
+
text: (el.innerText || '').substring(0, 50),
|
|
284
|
+
issue: 'Interactive element has tabindex=-1 (not keyboard accessible)',
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
return issues;
|
|
289
|
+
}""")
|
|
290
|
+
|
|
291
|
+
for issue in interactive_no_focus:
|
|
292
|
+
findings.append(
|
|
293
|
+
make_finding(
|
|
294
|
+
agent=self.name,
|
|
295
|
+
finding_type="keyboard_inaccessible",
|
|
296
|
+
severity=Severity.HIGH,
|
|
297
|
+
file=page_path,
|
|
298
|
+
message=f"Keyboard inaccessible: <{issue['tag']}> — {issue['issue']}",
|
|
299
|
+
detail=f"id={issue.get('id', 'none')}, text={issue.get('text', '')}",
|
|
300
|
+
)
|
|
301
|
+
)
|
|
302
|
+
|
|
303
|
+
except Exception as e:
|
|
304
|
+
_log.warning("UIAccessibilityAgent._test_keyboard_navigation failed: %s", e)
|
|
305
|
+
|
|
306
|
+
return findings
|
|
307
|
+
|
|
308
|
+
def _map_impact(self, impact: str) -> Severity:
|
|
309
|
+
return {
|
|
310
|
+
"critical": Severity.CRITICAL,
|
|
311
|
+
"serious": Severity.HIGH,
|
|
312
|
+
"moderate": Severity.MEDIUM,
|
|
313
|
+
"minor": Severity.LOW,
|
|
314
|
+
}.get((impact or "").lower(), Severity.MEDIUM)
|
|
315
|
+
|
|
316
|
+
def _format_violation(self, v: dict) -> str:
|
|
317
|
+
lines = [f"Rule: {v.get('id', '?')}"]
|
|
318
|
+
lines.append(f"Impact: {v.get('impact', '?')}")
|
|
319
|
+
lines.append(f"Help: {v.get('help', '?')}")
|
|
320
|
+
lines.append(f"WCAG: {', '.join(v.get('tags', [])[:5])}")
|
|
321
|
+
for node in v.get("nodes", [])[:3]:
|
|
322
|
+
lines.append(f" Element: {node.get('html', '')[:100]}")
|
|
323
|
+
lines.append(f" Fix: {node.get('failureSummary', '')[:100]}")
|
|
324
|
+
return "\n".join(lines)
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
"""
|
|
2
|
+
UIButtonAgent — Interactive button and click-action testing via Playwright.
|
|
3
|
+
|
|
4
|
+
Tests every interactive element:
|
|
5
|
+
- Discovers all buttons, links, and clickable elements
|
|
6
|
+
- Verifies buttons are clickable (not covered, not disabled unexpectedly)
|
|
7
|
+
- Tests button hover, focus, and active states
|
|
8
|
+
- Clicks buttons and checks for JS errors / broken handlers
|
|
9
|
+
- Verifies buttons have meaningful text or aria-labels
|
|
10
|
+
- Checks for buttons that do nothing (no action)
|
|
11
|
+
- Screenshots each page and links evidence to findings
|
|
12
|
+
|
|
13
|
+
Requires: playwright
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
import logging
|
|
19
|
+
|
|
20
|
+
from ..agents.base import (
|
|
21
|
+
AgentDomain,
|
|
22
|
+
AgentGroup,
|
|
23
|
+
AgentInput,
|
|
24
|
+
AgentResult,
|
|
25
|
+
BaseAgent,
|
|
26
|
+
Severity,
|
|
27
|
+
make_finding,
|
|
28
|
+
register,
|
|
29
|
+
)
|
|
30
|
+
from ._browser import (
|
|
31
|
+
discover_routes,
|
|
32
|
+
find_server,
|
|
33
|
+
open_page,
|
|
34
|
+
save_screenshot,
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
_log = logging.getLogger("patchi.testing.ui_button_agent")
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@register
|
|
41
|
+
class UIButtonAgent(BaseAgent):
|
|
42
|
+
"""Interactive button and click-action testing."""
|
|
43
|
+
|
|
44
|
+
group = AgentGroup.TEST
|
|
45
|
+
domain = AgentDomain.VISUAL
|
|
46
|
+
name = "UIButtonAgent"
|
|
47
|
+
description = "Button/click testing: clickability, handlers, JS errors, empty actions"
|
|
48
|
+
timeout = 180
|
|
49
|
+
|
|
50
|
+
def _run(self, inp: AgentInput, result: AgentResult) -> None:
|
|
51
|
+
try:
|
|
52
|
+
from playwright.sync_api import sync_playwright # noqa: F401
|
|
53
|
+
except ImportError:
|
|
54
|
+
self.skip(result, "playwright not installed — pip install playwright && playwright install chromium")
|
|
55
|
+
return
|
|
56
|
+
|
|
57
|
+
base_url = find_server(inp.root, inp.config, inp.extra)
|
|
58
|
+
if not base_url:
|
|
59
|
+
self.skip(result, "no running server found — start `p web` (default :1612)")
|
|
60
|
+
return
|
|
61
|
+
|
|
62
|
+
routes = discover_routes(inp.config, inp.extra)
|
|
63
|
+
if not routes:
|
|
64
|
+
self.skip(result, "no routes discovered")
|
|
65
|
+
return
|
|
66
|
+
|
|
67
|
+
screenshot_dir = inp.root / ".patchi" / "evidence" / "screenshots" / "ui_button"
|
|
68
|
+
total_issues = 0
|
|
69
|
+
pages_tested = 0
|
|
70
|
+
error_pages = 0
|
|
71
|
+
|
|
72
|
+
with sync_playwright() as pw:
|
|
73
|
+
browser = pw.chromium.launch(headless=True)
|
|
74
|
+
|
|
75
|
+
for page_path in routes[:15]:
|
|
76
|
+
ps = open_page(browser, f"{base_url}{page_path}")
|
|
77
|
+
page = ps.page
|
|
78
|
+
try:
|
|
79
|
+
slug = page_path.strip("/").replace("/", "_") or "root"
|
|
80
|
+
shot = save_screenshot(page, screenshot_dir, slug)
|
|
81
|
+
rel = str(shot.relative_to(inp.root)) if shot else None
|
|
82
|
+
|
|
83
|
+
if ps.status and ps.status >= 400:
|
|
84
|
+
error_pages += 1
|
|
85
|
+
result.add_finding(
|
|
86
|
+
make_finding(
|
|
87
|
+
agent=self.name,
|
|
88
|
+
finding_type="page_error",
|
|
89
|
+
severity=Severity.HIGH,
|
|
90
|
+
file=page_path,
|
|
91
|
+
message=f"HTTP {ps.status} on {page_path} (button test skipped)",
|
|
92
|
+
extra={"screenshot": rel},
|
|
93
|
+
)
|
|
94
|
+
)
|
|
95
|
+
continue
|
|
96
|
+
|
|
97
|
+
for ce in ps.console_errors[:5]:
|
|
98
|
+
result.add_finding(
|
|
99
|
+
make_finding(
|
|
100
|
+
agent=self.name,
|
|
101
|
+
finding_type="console_error",
|
|
102
|
+
severity=Severity.LOW,
|
|
103
|
+
file=page_path,
|
|
104
|
+
message=f"Console error on {page_path}: {ce[:160]}",
|
|
105
|
+
extra={"screenshot": rel},
|
|
106
|
+
)
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
buttons = self._find_buttons(page)
|
|
110
|
+
issues = self._analyze_buttons(buttons, page_path)
|
|
111
|
+
for issue in issues:
|
|
112
|
+
if rel:
|
|
113
|
+
issue.extra = {**(issue.extra or {}), "screenshot": rel}
|
|
114
|
+
result.add_finding(issue)
|
|
115
|
+
total_issues += 1
|
|
116
|
+
|
|
117
|
+
interaction_issues = self._capture_interactions(page, page_path, rel, base_url)
|
|
118
|
+
for issue in interaction_issues:
|
|
119
|
+
result.add_finding(issue)
|
|
120
|
+
total_issues += 1
|
|
121
|
+
|
|
122
|
+
pages_tested += 1
|
|
123
|
+
finally:
|
|
124
|
+
page.close()
|
|
125
|
+
|
|
126
|
+
browser.close()
|
|
127
|
+
|
|
128
|
+
if total_issues == 0 and error_pages == 0 and pages_tested > 0:
|
|
129
|
+
result.add_finding(
|
|
130
|
+
make_finding(
|
|
131
|
+
agent=self.name,
|
|
132
|
+
finding_type="button_summary",
|
|
133
|
+
severity=Severity.INFO,
|
|
134
|
+
file="(all pages)",
|
|
135
|
+
message=f"Button testing PASSED: {pages_tested} pages, 0 issues",
|
|
136
|
+
)
|
|
137
|
+
)
|
|
138
|
+
elif pages_tested > 0 or error_pages > 0:
|
|
139
|
+
result.add_finding(
|
|
140
|
+
make_finding(
|
|
141
|
+
agent=self.name,
|
|
142
|
+
finding_type="button_summary",
|
|
143
|
+
severity=Severity.MEDIUM,
|
|
144
|
+
file="(all pages)",
|
|
145
|
+
message=f"Button issues: {total_issues} across {pages_tested} pages ({error_pages} error pages)",
|
|
146
|
+
)
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
result.data["suite"] = {
|
|
150
|
+
"runner": "button_test",
|
|
151
|
+
"pages_tested": pages_tested,
|
|
152
|
+
"total_issues": total_issues,
|
|
153
|
+
}
|
|
154
|
+
result.files_scanned = pages_tested
|
|
155
|
+
|
|
156
|
+
def _find_buttons(self, page) -> list:
|
|
157
|
+
return page.evaluate("""() => {
|
|
158
|
+
const buttons = [];
|
|
159
|
+
document.querySelectorAll('button, a[href], input[type=submit], input[type=button], [role=button], .btn, [class*=btn]').forEach(el => {
|
|
160
|
+
const r = el.getBoundingClientRect();
|
|
161
|
+
if (r.width > 0 && r.height > 0) {
|
|
162
|
+
buttons.push({
|
|
163
|
+
tag: el.tagName.toLowerCase(),
|
|
164
|
+
type: el.getAttribute('type') || '',
|
|
165
|
+
text: (el.innerText || '').trim().substring(0, 50),
|
|
166
|
+
ariaLabel: el.getAttribute('aria-label') || '',
|
|
167
|
+
title: el.getAttribute('title') || '',
|
|
168
|
+
id: el.id || '',
|
|
169
|
+
classes: (el.className || '').substring(0, 80),
|
|
170
|
+
x: Math.round(r.x),
|
|
171
|
+
y: Math.round(r.y),
|
|
172
|
+
w: Math.round(r.width),
|
|
173
|
+
h: Math.round(r.height),
|
|
174
|
+
href: el.getAttribute('href') || '',
|
|
175
|
+
disabled: el.disabled || el.hasAttribute('disabled'),
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
return buttons;
|
|
180
|
+
}""")
|
|
181
|
+
|
|
182
|
+
def _analyze_buttons(self, buttons: list, page_path: str) -> list:
|
|
183
|
+
findings = []
|
|
184
|
+
for b in buttons:
|
|
185
|
+
if b["disabled"]:
|
|
186
|
+
continue
|
|
187
|
+
label = b["text"] or b["ariaLabel"] or b["title"]
|
|
188
|
+
if not label and b["tag"] not in ("a",):
|
|
189
|
+
findings.append(
|
|
190
|
+
make_finding(
|
|
191
|
+
agent=self.name,
|
|
192
|
+
finding_type="button_no_label",
|
|
193
|
+
severity=Severity.MEDIUM,
|
|
194
|
+
file=page_path,
|
|
195
|
+
message=f"Button has no text/aria-label: <{b['tag']}> '{b['classes'][:40]}'",
|
|
196
|
+
extra={"selector": f"{b['tag']}#{b['id']}"},
|
|
197
|
+
)
|
|
198
|
+
)
|
|
199
|
+
if b["w"] > 0 and b["h"] > 0 and (b["w"] < 24 or b["h"] < 24):
|
|
200
|
+
findings.append(
|
|
201
|
+
make_finding(
|
|
202
|
+
agent=self.name,
|
|
203
|
+
finding_type="button_too_small",
|
|
204
|
+
severity=Severity.LOW,
|
|
205
|
+
file=page_path,
|
|
206
|
+
message=f"Button too small ({b['w']}x{b['h']}px): '{label[:30]}'",
|
|
207
|
+
extra={"selector": f"{b['tag']}#{b['id']}"},
|
|
208
|
+
)
|
|
209
|
+
)
|
|
210
|
+
if b["tag"] == "button" and b["type"] == "submit" and not b["text"] and not b["ariaLabel"]:
|
|
211
|
+
findings.append(
|
|
212
|
+
make_finding(
|
|
213
|
+
agent=self.name,
|
|
214
|
+
finding_type="submit_no_label",
|
|
215
|
+
severity=Severity.MEDIUM,
|
|
216
|
+
file=page_path,
|
|
217
|
+
message=f"Submit button has no label: <button type=submit> '{b['classes'][:40]}'",
|
|
218
|
+
extra={"selector": f"button#{b['id']}"},
|
|
219
|
+
)
|
|
220
|
+
)
|
|
221
|
+
return findings
|
|
222
|
+
|
|
223
|
+
def _capture_interactions(self, page, page_path: str, rel: str | None, base_url: str) -> list:
|
|
224
|
+
findings = []
|
|
225
|
+
try:
|
|
226
|
+
locators = page.locator('button:not([disabled]), a[href], [role=button]:not([disabled])')
|
|
227
|
+
count = locators.count()
|
|
228
|
+
if count == 0:
|
|
229
|
+
return findings
|
|
230
|
+
captured = []
|
|
231
|
+
|
|
232
|
+
def _on_pageerror(exc):
|
|
233
|
+
captured.append(str(exc))
|
|
234
|
+
|
|
235
|
+
def _on_console(msg):
|
|
236
|
+
if msg.type == "error":
|
|
237
|
+
captured.append(str(getattr(msg, "text", msg)))
|
|
238
|
+
|
|
239
|
+
page.on("pageerror", _on_pageerror)
|
|
240
|
+
page.on("console", _on_console)
|
|
241
|
+
clicked = 0
|
|
242
|
+
url = f"{base_url}{page_path}"
|
|
243
|
+
for i in range(min(count, 8)):
|
|
244
|
+
captured.clear()
|
|
245
|
+
try:
|
|
246
|
+
# reset to a clean page state so locators never go stale
|
|
247
|
+
page.goto(url, wait_until="load", timeout=15000)
|
|
248
|
+
loc = locators.nth(i)
|
|
249
|
+
tag = loc.evaluate("e => e.tagName.toLowerCase()")
|
|
250
|
+
if tag == "button" and loc.evaluate("e => e.type") == "submit":
|
|
251
|
+
continue # don't submit forms during tests
|
|
252
|
+
href = loc.evaluate("e => e.getAttribute('href') || ''")
|
|
253
|
+
if href and (href.startswith("http") or href.startswith("mailto:")):
|
|
254
|
+
continue # leave site / external
|
|
255
|
+
try:
|
|
256
|
+
label = loc.evaluate("e => (e.innerText || e.getAttribute('aria-label') || '').trim().substring(0, 30)")
|
|
257
|
+
except Exception:
|
|
258
|
+
label = "?"
|
|
259
|
+
except Exception:
|
|
260
|
+
continue
|
|
261
|
+
try:
|
|
262
|
+
loc.click(timeout=2000, force=True)
|
|
263
|
+
page.wait_for_timeout(400)
|
|
264
|
+
except Exception:
|
|
265
|
+
findings.append(
|
|
266
|
+
make_finding(
|
|
267
|
+
agent=self.name,
|
|
268
|
+
finding_type="button_no_action",
|
|
269
|
+
severity=Severity.LOW,
|
|
270
|
+
file=page_path,
|
|
271
|
+
message=f"Button click failed/had no handler: <{tag}> '{label}'",
|
|
272
|
+
extra={"screenshot": rel},
|
|
273
|
+
)
|
|
274
|
+
)
|
|
275
|
+
else:
|
|
276
|
+
if captured:
|
|
277
|
+
findings.append(
|
|
278
|
+
make_finding(
|
|
279
|
+
agent=self.name,
|
|
280
|
+
finding_type="button_js_error",
|
|
281
|
+
severity=Severity.HIGH,
|
|
282
|
+
file=page_path,
|
|
283
|
+
message=f"Button click raised JS error: <{tag}> '{label}': {captured[0][:160]}",
|
|
284
|
+
extra={"screenshot": rel},
|
|
285
|
+
)
|
|
286
|
+
)
|
|
287
|
+
clicked += 1
|
|
288
|
+
if clicked >= 6:
|
|
289
|
+
break
|
|
290
|
+
page.remove_listener("pageerror", _on_pageerror)
|
|
291
|
+
page.remove_listener("console", _on_console)
|
|
292
|
+
except Exception as e:
|
|
293
|
+
_log.warning("UIButtonAgent._capture_interactions failed: %s", e)
|
|
294
|
+
return findings
|