bugx-cli 0.1.0 → 0.1.1
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/README.md +190 -186
- package/core/README.md +2 -2
- package/core/agent/README.md +2 -1
- package/core/agent/agent_artifacts.py +8 -6
- package/core/agent/agent_eval.py +136 -54
- package/core/agent/agent_execution.py +218 -52
- package/core/agent/agent_orchestrator.py +14 -8
- package/core/agent/agent_targets.py +8 -2
- package/core/agent/feature_baseline.py +150 -0
- package/core/assets/axe-core/LICENSE-3RD-PARTY.txt +66 -0
- package/core/assets/axe-core/LICENSE.txt +362 -0
- package/core/assets/axe-core/UPSTREAM.md +10 -0
- package/core/assets/axe-core/axe.min.js +12 -0
- package/core/assets/bugx-hero-en.svg +74 -0
- package/core/assets/bugx-hero-zh.svg +74 -0
- package/core/assets/codex.png +0 -0
- package/core/assets/dsh.png +0 -0
- package/core/assets/webui-chatgpt.jpg +0 -0
- package/core/assets/webui-session.jpg +0 -0
- package/core/assets/webui-skills.jpg +0 -0
- package/core/assets/webui-studio.jpg +0 -0
- package/core/assets/webui-zcode.jpg +0 -0
- package/core/assets/zcode.png +0 -0
- package/core/autonomous_cve/SPEC.md +1 -1
- package/core/autonomous_cve/attack_graph_store.py +152 -106
- package/core/autonomous_cve/behavior_graph.py +8 -2
- package/core/autonomous_cve/verifier.py +4 -1
- package/core/bugx.md +1 -1
- package/core/bugx_paths.py +43 -8
- package/core/cli-help.txt +66 -0
- package/core/cloud_sync/SPEC.md +1 -1
- package/core/cloud_sync/cloud_client.py +25 -6
- package/core/cloud_sync/cloud_onboard.py +42 -1
- package/core/cloud_sync/flywheel_client.py +16 -7
- package/core/cloud_sync/network_transport.py +24 -3
- package/core/cloud_sync/sensitive_filter.py +2 -2
- package/core/cloud_sync/sync_push.py +12 -10
- package/core/contracts/AGENT_GUIDE.md +6 -9
- package/core/contracts/README.md +2 -2
- package/core/contracts/bugx-runtime-contract.md +1 -1
- package/core/contracts/bugx-worker.md +1 -1
- package/core/contracts/engine_gap_contracts.py +86 -3
- package/core/coverage/coverage_discovery.py +599 -29
- package/core/coverage/coverage_evidence.py +47 -0
- package/core/coverage/coverage_forensics.py +9 -0
- package/core/coverage/coverage_validate.py +6 -1
- package/core/dev_harness/SPEC.md +1 -1
- package/core/engine-integrity.json +591 -419
- package/core/fuzzing/concurrency_fuzzer.py +53 -0
- package/core/fuzzing/differential_oracle.py +562 -27
- package/core/fuzzing/fuzz_input.py +109 -6
- package/core/fuzzing/stateful_fuzzer.py +72 -0
- package/core/governance/secret_redactor.py +22 -10
- package/core/host_acp/SPEC.md +1 -1
- package/core/host_acp/__init__.py +4 -4
- package/core/host_acp/claude.py +59 -1
- package/core/host_acp/cline.py +64 -1
- package/core/host_acp/codex.py +56 -1
- package/core/host_acp/dsh.py +59 -1
- package/core/host_acp/opencode.py +56 -1
- package/core/host_acp/pi.py +59 -1
- package/core/host_acp/zcode.py +59 -1
- package/core/host_runtime/SPEC.md +1 -1
- package/core/host_runtime/adapters.py +1 -1
- package/core/host_runtime/cline.py +13 -0
- package/core/host_runtime/host_evaluators.py +44 -4
- package/core/host_runtime/host_probe.py +1 -1
- package/core/host_runtime/host_provider_arbitrator.py +116 -62
- package/core/host_runtime/host_registry.py +15 -8
- package/core/host_runtime/mcp_registry_gate.py +12 -1
- package/core/host_runtime/pi.py +102 -0
- package/core/host_runtime/provider_facts.py +66 -0
- package/core/hosts/SPEC.md +1 -1
- package/core/hosts/__init__.py +6 -2
- package/core/hosts/_dsh_usage.py +1 -1
- package/core/hosts/base.py +32 -4
- package/core/hosts/claude.py +55 -0
- package/core/hosts/cline.py +6 -2
- package/core/hosts/codex.py +58 -0
- package/core/hosts/dsh.py +9 -1
- package/core/hosts/opencode.py +6 -6
- package/core/hosts/pi.py +159 -2
- package/core/infra/README.md +4 -2
- package/core/infra/__init__.py +2 -0
- package/core/infra/build_info.py +22 -3
- package/core/infra/client_metadata.py +1 -1
- package/core/infra/json_utils.py +22 -0
- package/core/launch_phases/README.md +2 -2
- package/core/launch_phases/SPEC.md +1 -1
- package/core/launch_phases/common.py +21 -2
- package/core/launch_phases/finding_confirm_phase.py +5 -1
- package/core/launch_phases/finding_settlement.py +188 -1
- package/core/launch_phases/judge_phase.py +69 -12
- package/core/launch_phases/orchestrator_controls.py +11 -7
- package/core/launch_phases/post_coverage_sync.py +9 -2
- package/core/launch_phases/post_phase.py +139 -3
- package/core/launch_phases/post_receipt.py +12 -1
- package/core/launch_phases/pre_phase.py +3 -3
- package/core/launch_phases/pre_recon_scout.py +53 -36
- package/core/launch_phases/pre_state_builder.py +23 -176
- package/core/launch_phases/round_orchestrator.py +15 -32
- package/core/launch_phases/session_runtime.py +56 -9
- package/core/launch_phases/startup_gates.py +36 -8
- package/core/launch_phases/startup_interaction.py +68 -12
- package/core/launch_phases/startup_version_gate.py +9 -3
- package/core/launch_phases/supervisor_bridge.py +46 -17
- package/core/launch_phases/supervisor_coverage.py +8 -2
- package/core/launch_phases/supervisor_degraded.py +1 -9
- package/core/launch_phases/worker_barriers.py +15 -5
- package/core/launch_phases/worker_orchestrator.py +105 -25
- package/core/ledger/README.md +1 -1
- package/core/ledger/SPEC.md +1 -1
- package/core/ledger/_facade.py +2 -1
- package/core/ledger/archive_ops.py +60 -2
- package/core/ledger/cli.py +6 -1
- package/core/ledger/export_ops.py +6 -1
- package/core/ledger/finding_confirmation.py +48 -6
- package/core/ledger/finding_lifecycle.py +428 -5
- package/core/ledger/finding_verification.py +44 -8
- package/core/ledger/incidents.py +10 -4
- package/core/ledger/patterns.py +10 -7
- package/core/ledger/receipt_contract.py +17 -1
- package/core/ledger/sync_ops.py +21 -16
- package/core/ledger/tool_experience.py +2 -1
- package/core/ledger/verify_life.py +88 -17
- package/core/locales/en-US.json +2 -2
- package/core/locales/zh-CN.json +2 -2
- package/core/mcp_handlers/SPEC.md +1 -1
- package/core/mcp_handlers/base.py +23 -3
- package/core/mcp_handlers/channel_lifecycle.py +85 -30
- package/core/mcp_handlers/retrieval_handlers.py +11 -1
- package/core/mcp_handlers/rpc_server.py +6 -1
- package/core/mcp_handlers/supervisor_handlers.py +32 -6
- package/core/mcp_handlers/tool_table.py +15 -0
- package/core/mcp_runtime_support/environment.py +0 -38
- package/core/mcp_runtime_support/verifier.py +0 -52
- package/core/metadata.txt +2 -3
- package/core/planning/README.md +1 -1
- package/core/planning/domain_router.py +4 -2
- package/core/planning/dynamic_flow_analyzer.py +219 -14
- package/core/planning/judge_pipeline.py +87 -4
- package/core/planning/prompt_harness.py +7 -5
- package/core/planning/spec_harvester.py +4 -4
- package/core/probes/INTERFACE.md +11 -1
- package/core/probes/SPEC.md +11 -1
- package/core/probes/__init__.py +46 -40
- package/core/probes/android_probe.py +177 -9
- package/core/probes/codebase_memory_probe.py +57 -0
- package/core/probes/desktop_probe.py +104 -0
- package/core/probes/differential_probe.py +99 -21
- package/core/probes/efficiency_probe.py +64 -0
- package/core/probes/ios_binary_probe.py +105 -1
- package/core/probes/memory_probe.py +66 -0
- package/core/probes/miniprogram_probe.py +75 -13
- package/core/probes/mobile_probe.py +215 -30
- package/core/probes/native_probe.py +88 -0
- package/core/probes/openwiki_probe.py +70 -0
- package/core/probes/pattern_probe.py +106 -0
- package/core/probes/platform_probe.py +81 -0
- package/core/probes/probe_registry.py +108 -7
- package/core/probes/sast_fixture_corpus.py +340 -0
- package/core/probes/sast_probe.py +553 -52
- package/core/probes/sast_rules.py +668 -28
- package/core/probes/sca_scanner.py +48 -0
- package/core/probes/ui_accessibility.py +149 -0
- package/core/probes/ui_audit.py +513 -0
- package/core/probes/ui_contract.py +273 -0
- package/core/probes/ui_evidence.py +212 -0
- package/core/probes/ui_measurements.py +314 -0
- package/core/probes/ui_repair.py +250 -0
- package/core/probes/ui_review.py +133 -0
- package/core/probes/ui_storybook.py +107 -0
- package/core/probes/ui_tokens.py +185 -0
- package/core/probes/ui_visual_diff.py +131 -0
- package/core/probes/web_probe.py +373 -18
- package/core/project_profiler/SPEC.md +1 -1
- package/core/project_profiler/arbitrator.py +6 -1
- package/core/project_profiler/detector.py +8 -1
- package/core/project_profiler/strategy.py +51 -15
- package/core/prompts/command_routing_en.md +2 -2
- package/core/prompts/command_routing_zh.md +2 -2
- package/core/prompts/stages/stage_repair.md +1 -1
- package/core/repair/README.md +1 -1
- package/core/repair/l7_repair_loop.py +1 -4
- package/core/repair/rsi_fixer.py +4 -4
- package/core/repair/rsi_loop.py +1 -3
- package/core/repair/rsi_repair.py +7 -7
- package/core/repair/rsi_scope.py +27 -8
- package/core/report_engine/SPEC.md +1 -1
- package/core/report_engine/attestation.py +8 -4
- package/core/report_engine/finding_report.py +2 -1
- package/core/report_engine/models.py +7 -9
- package/core/report_engine/sast_bridge.py +2 -2
- package/core/report_engine/server.py +18 -8
- package/core/report_engine/web-conformance.md +123 -18
- package/core/report_engine/web_conformance.py +21 -52
- package/core/retrieval/README.md +1 -1
- package/core/retrieval/SPEC.md +1 -1
- package/core/retrieval/code_analyzer.py +50 -14
- package/core/retrieval/context_assembler.py +7 -1
- package/core/retrieval/knowledge_sync.py +108 -14
- package/core/retrieval/symbol_index.py +25 -6
- package/core/retrieval/universal_code_matcher.py +234 -49
- package/core/runtime/README.md +1 -1
- package/core/runtime/bugx_logging.py +78 -7
- package/core/runtime/fixture_solidify.py +5 -10
- package/core/runtime/incident_eval.py +1 -1
- package/core/runtime/model_runner.py +4 -41
- package/core/runtime/platform_adapter.py +2 -2
- package/core/runtime/prep_validate.py +4 -2
- package/core/runtime/project_settings.py +2 -1
- package/core/runtime/scenario_eval.py +50 -8
- package/core/skills/bugx_docs_mcp_server.py +3 -1
- package/core/skills/bugx_mcp_server.py +29 -2
- package/core/skills/tools_kb.py +1 -1
- package/core/supervisor/README.md +1 -1
- package/core/supervisor/SPEC.md +1 -1
- package/core/supervisor/budget_governor.py +503 -9
- package/core/supervisor/checkpoint_pipeline.py +248 -6
- package/core/supervisor/checkpoint_sync.py +13 -0
- package/core/supervisor/claim_events.py +1 -1
- package/core/supervisor/finding_workflow.py +22 -5
- package/core/supervisor/lease_manager.py +1 -1
- package/core/supervisor/lifecycle_blocks.py +6 -1
- package/core/supervisor/rejection_remedies.py +52 -5
- package/core/supervisor/serial_authorization.py +48 -4
- package/core/supervisor/task_scheduler.py +2 -2
- package/core/supervisor/worker_checkpoint.py +8 -1
- package/core/supervisor/worker_runtime.py +8 -2
- package/core/supervisor_types/worker_claim.py +9 -0
- package/core/webui/README.md +1 -1
- package/core/webui/SPEC.md +2 -1
- package/core/webui/adapters/claude.py +5 -1
- package/core/webui/adapters/cline.py +10 -2
- package/core/webui/adapters/codex.py +5 -1
- package/core/webui/adapters/dsh.py +5 -1
- package/core/webui/docs_session_service.py +2 -2
- package/core/webui/mcp_inspector.py +11 -7
- package/core/webui/static/00-base.css +1060 -0
- package/core/webui/static/01-monitoring.css +802 -0
- package/core/webui/static/02-header-actions.css +321 -0
- package/core/webui/static/03-trigger-popover.css +697 -0
- package/core/webui/static/04-composer.css +628 -0
- package/core/webui/static/05-skills-center.css +878 -0
- package/core/webui/static/06-mcp-center.css +623 -0
- package/core/webui/static/07-skill-detail.css +265 -0
- package/core/webui/static/08-files-management.css +167 -0
- package/core/webui/static/09-files-center.css +386 -0
- package/core/webui/static/10-icons.css +105 -0
- package/core/webui/static/11-project-options.css +185 -0
- package/core/webui/static/12-profile-tab.css +383 -0
- package/core/webui/static/design-tokens.css +113 -0
- package/core/webui/static/index.html +14 -1
- package/core/webui/workspace_service.py +1 -1
- package/docs/07_distribution/01_README_NPM.md +190 -186
- package/ecosystem/integrations/README.md +1 -1
- package/ecosystem/integrations/dsh/mcp/package.json +1 -1
- package/ecosystem/integrations/dsh/skills/bugx-dsh/SKILL.md +1 -1
- package/ecosystem/integrations/dsh/ui/package.json +1 -1
- package/ecosystem/integrations/opencode/bugx-mcp-manifest.json +4 -4
- package/ecosystem/integrations/opencode/mcp-lock.json +14 -6
- package/ecosystem/integrations/opencode/opencode.json +23 -12
- package/ecosystem/integrations/pi/extensions/bugx/manifest.json +1 -1
- package/ecosystem/integrations/qoder/connector-meta.json +1 -1
- package/ecosystem/integrations/workbuddy/connector-meta.json +1 -1
- package/ecosystem/integrations/workbuddy/skills/bugx/SKILL.md +1 -1
- package/ecosystem/plugins/bugx/.claude-plugin/plugin.json +1 -1
- package/ecosystem/plugins/bugx/.codex-plugin/plugin.json +1 -1
- package/ecosystem/plugins/bugx/.zcode-plugin/plugin.json +1 -1
- package/ecosystem/plugins/bugx/skills/bugx/SKILL.md +2 -2
- package/ecosystem/plugins/bugx/skills/bugx-dsh/SKILL.md +1 -1
- package/ecosystem/plugins/bugx/skills/bugx-opencode/SKILL.md +1 -1
- package/ecosystem/plugins/bugx/skills/bugx-zcode/SKILL.md +1 -1
- package/interfaces/bin/bugx.js +37 -0
- package/interfaces/cli/bugx_cli/__init__.py +4 -2
- package/interfaces/cli/bugx_cli/cli.py +11 -4
- package/interfaces/cli/bugx_cli/commands/advisory.py +1 -1
- package/interfaces/cli/bugx_cli/commands/agent.py +339 -73
- package/interfaces/cli/bugx_cli/commands/audit.py +2 -2
- package/interfaces/cli/bugx_cli/commands/autonomous.py +1 -1
- package/interfaces/cli/bugx_cli/commands/cloud.py +4 -3
- package/interfaces/cli/bugx_cli/commands/doctor.py +449 -204
- package/interfaces/cli/bugx_cli/commands/interaction.py +5 -1
- package/interfaces/cli/bugx_cli/commands/knowledge.py +2 -0
- package/interfaces/cli/bugx_cli/commands/lifecycle.py +3 -3
- package/interfaces/cli/bugx_cli/commands/plugin.py +55 -20
- package/interfaces/cli/bugx_cli/commands/plugin_claude.py +7 -7
- package/interfaces/cli/bugx_cli/commands/plugin_funide.py +2 -1
- package/interfaces/cli/bugx_cli/commands/plugin_zcode.py +1 -1
- package/interfaces/cli/bugx_cli/commands/report.py +2 -6
- package/interfaces/cli/bugx_cli/commands/system.py +11 -11
- package/interfaces/cli/bugx_cli/common.py +15 -7
- package/interfaces/cli/bugx_cli/host_adapters.py +29 -54
- package/interfaces/cli/bugx_cli/hosts/registry.py +8 -6
- package/interfaces/cli/bugx_cli/infra/ai_advisor.py +157 -27
- package/interfaces/cli/bugx_cli/infra/engine_installer.py +18 -10
- package/interfaces/cli/bugx_cli/infra/host_sync.py +11 -8
- package/interfaces/cli/bugx_cli/infra/mcp_advisor.py +76 -5
- package/interfaces/cli/bugx_cli/infra/security.py +13 -6
- package/package.json +2 -1
- package/pyproject.toml +20 -8
- package/scripts/ensure-python.mjs +7 -7
- package/scripts/sync-version.mjs +10 -21
- package/scripts/test-npm-wrapper.mjs +1 -1
- package/core/webui/static/project-settings.css +0 -6458
- package/docs/07_distribution/README.md +0 -16
- package/docs/README.md +0 -121
- package/interfaces/README.md +0 -143
- package/interfaces/bin/README.md +0 -35
- package/interfaces/cli/README.md +0 -90
- package/scripts/README.md +0 -118
|
@@ -729,3 +729,51 @@ class SCAScanner:
|
|
|
729
729
|
except Exception:
|
|
730
730
|
pass
|
|
731
731
|
return deps
|
|
732
|
+
|
|
733
|
+
|
|
734
|
+
def is_available(scanner: "SCAScanner | None" = None) -> tuple[bool, str]:
|
|
735
|
+
"""降级契约:机械探活离线漏洞通告库是否非空(纯内存检查,零 I/O)。
|
|
736
|
+
|
|
737
|
+
通告库为空时依赖清单解析(``collect_dependencies``)仍然可用,但无法
|
|
738
|
+
给出任何漏洞裁决;调用方必须走 ``run_static_degraded`` 显式声明
|
|
739
|
+
``vulnerabilities_scanned=False``,禁止把纯依赖枚举伪装成 SCA 扫描。
|
|
740
|
+
"""
|
|
741
|
+
instance = scanner if scanner is not None else SCAScanner()
|
|
742
|
+
if not instance.advisories:
|
|
743
|
+
return False, "离线漏洞通告库为空;依赖清单解析可用但漏洞裁决不可用"
|
|
744
|
+
return True, f"{len(instance.advisories)} 条离线通告就绪"
|
|
745
|
+
|
|
746
|
+
|
|
747
|
+
def run_static_degraded(root: Path, *, scanner: "SCAScanner | None" = None) -> dict:
|
|
748
|
+
"""降级契约:只输出依赖清单静态事实,不做漏洞裁决,绝不伪装扫描完成。
|
|
749
|
+
|
|
750
|
+
输出与成功路径(``scan_project`` 返回的漏洞 findings 列表)字段级可区分:
|
|
751
|
+
本契约返回结构化 dict,``status="degraded"`` + ``degraded=True`` +
|
|
752
|
+
``degraded_reason``,并显式声明 ``vulnerabilities_scanned=False``。
|
|
753
|
+
"""
|
|
754
|
+
instance = scanner if scanner is not None else SCAScanner()
|
|
755
|
+
db_ok = bool(instance.advisories)
|
|
756
|
+
dependencies = instance.collect_dependencies(root)
|
|
757
|
+
return {
|
|
758
|
+
"schema_version": 1,
|
|
759
|
+
"success": bool(dependencies) or db_ok,
|
|
760
|
+
"status": "degraded",
|
|
761
|
+
"degraded": True,
|
|
762
|
+
"degraded_reason": (
|
|
763
|
+
"static_mode_forced" if db_ok else "advisory_db_empty_no_verdicts"
|
|
764
|
+
),
|
|
765
|
+
"probe_mode": "static_degraded",
|
|
766
|
+
"root": str(root),
|
|
767
|
+
"vulnerabilities_scanned": False,
|
|
768
|
+
"total_dependencies": len(dependencies),
|
|
769
|
+
"dependencies": dependencies,
|
|
770
|
+
"findings": [],
|
|
771
|
+
"evidence": {
|
|
772
|
+
"advisory_count": len(instance.advisories),
|
|
773
|
+
"availability_detail": "advisory_db_ready" if db_ok else "advisory_db_empty",
|
|
774
|
+
},
|
|
775
|
+
"metadata": {
|
|
776
|
+
"degraded_mode": "dependency_manifest_facts_only",
|
|
777
|
+
"fallback": "补齐漏洞通告库或接入外部 SCA 工具后才能给出漏洞裁决;禁止凭依赖枚举虚报风险",
|
|
778
|
+
},
|
|
779
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"""Runtime accessibility checks and declarative keyboard journey execution."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import hashlib
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
AXE_VERSION = "4.14.0"
|
|
10
|
+
AXE_SHA256 = "20c09fe157a8a34a30e241aaa1fcdade657734f08ab379ecfbeb7d45cc46e878"
|
|
11
|
+
AXE_TAGS = ("wcag2a", "wcag2aa", "wcag21a", "wcag21aa", "wcag22aa")
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def load_axe() -> str:
|
|
15
|
+
path = Path(__file__).resolve().parents[1] / "assets/axe-core/axe.min.js"
|
|
16
|
+
source = path.read_bytes()
|
|
17
|
+
if hashlib.sha256(source).hexdigest() != AXE_SHA256:
|
|
18
|
+
raise ValueError("bundled axe-core hash mismatch")
|
|
19
|
+
return source.decode("utf-8")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def scan_accessibility(page: Any, source: str, selector: str | None = None) -> dict:
|
|
23
|
+
"""Run the bundled engine and retain its automated and incomplete results."""
|
|
24
|
+
from playwright.sync_api import Error
|
|
25
|
+
|
|
26
|
+
metadata = {"version": AXE_VERSION, "sha256": AXE_SHA256, "tags": list(AXE_TAGS),
|
|
27
|
+
"scope": selector or "document"}
|
|
28
|
+
try:
|
|
29
|
+
page.evaluate(source)
|
|
30
|
+
result = page.evaluate(r"""
|
|
31
|
+
async ({tags, version, selector}) => {
|
|
32
|
+
if (window.axe?.version !== version) throw new Error('axe-core did not load');
|
|
33
|
+
const context = selector ? document.querySelector(selector) : document;
|
|
34
|
+
if (!context) throw new Error('accessibility scope is unavailable');
|
|
35
|
+
let timer;
|
|
36
|
+
try {
|
|
37
|
+
const result = await Promise.race([
|
|
38
|
+
axe.run(context, {runOnly: {type: 'tag', values: tags},
|
|
39
|
+
resultTypes: ['violations', 'incomplete']}),
|
|
40
|
+
new Promise((_, reject) => {
|
|
41
|
+
timer = setTimeout(() => reject(new Error('axe-core timed out')), 5000);
|
|
42
|
+
}),
|
|
43
|
+
]);
|
|
44
|
+
const summarize = (rules) => rules.map(rule => ({
|
|
45
|
+
id: rule.id, impact: rule.impact, help: rule.help, url: rule.helpUrl,
|
|
46
|
+
node_count: rule.nodes.length,
|
|
47
|
+
targets: rule.nodes.slice(0, 16).map(node => node.target),
|
|
48
|
+
}));
|
|
49
|
+
return {violations: summarize(result.violations), incomplete: summarize(result.incomplete),
|
|
50
|
+
passed_rules: result.passes.length};
|
|
51
|
+
} finally {
|
|
52
|
+
clearTimeout(timer);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
""", {"tags": list(AXE_TAGS), "version": AXE_VERSION, "selector": selector})
|
|
56
|
+
except Error as exc:
|
|
57
|
+
return {**metadata, "status": "BLOCKED", "reason": str(exc).splitlines()[0][:280]}
|
|
58
|
+
status = "FAIL" if result["violations"] else (
|
|
59
|
+
"UNVERIFIED" if result["incomplete"] or not result["passed_rules"] else "PASS"
|
|
60
|
+
)
|
|
61
|
+
return {**metadata, **result, "status": status}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
_FOCUS_SAMPLE = r"""
|
|
65
|
+
({focus, indicator}) => {
|
|
66
|
+
const active = document.activeElement;
|
|
67
|
+
const identify = node => node && ({
|
|
68
|
+
tag: node.localName, id: node.id || null, role: node.getAttribute('role')
|
|
69
|
+
});
|
|
70
|
+
const one = selector => {
|
|
71
|
+
const rows = document.querySelectorAll(selector);
|
|
72
|
+
return rows.length === 1 ? rows[0] : null;
|
|
73
|
+
};
|
|
74
|
+
const target = one(focus);
|
|
75
|
+
const marker = one(indicator);
|
|
76
|
+
const shown = node => {
|
|
77
|
+
const box = node.getBoundingClientRect();
|
|
78
|
+
if (!node.checkVisibility({checkOpacity: true, checkVisibilityCSS: true}) ||
|
|
79
|
+
box.width <= 0 || box.height <= 0) return false;
|
|
80
|
+
const left = Math.max(0, box.left), right = Math.min(innerWidth, box.right);
|
|
81
|
+
const top = Math.max(0, box.top), bottom = Math.min(innerHeight, box.bottom);
|
|
82
|
+
if (left >= right || top >= bottom) return false;
|
|
83
|
+
const hit = document.elementFromPoint((left + right) / 2, (top + bottom) / 2);
|
|
84
|
+
return !!hit && (node.contains(hit) || hit.contains(node));
|
|
85
|
+
};
|
|
86
|
+
let paint = null;
|
|
87
|
+
if (marker) {
|
|
88
|
+
const s = getComputedStyle(marker);
|
|
89
|
+
const outline = s.outlineStyle !== 'none' && parseFloat(s.outlineWidth) > 0 &&
|
|
90
|
+
s.outlineColor !== 'transparent' && !/,\s*0\)$/.test(s.outlineColor);
|
|
91
|
+
const shadowColors = s.boxShadow.match(/rgba?\([^)]*\)/g) || [];
|
|
92
|
+
const shadow = s.boxShadow !== 'none' &&
|
|
93
|
+
shadowColors.some(color => !/,\s*0\)$/.test(color));
|
|
94
|
+
paint = {
|
|
95
|
+
outline: outline ? [s.outlineStyle, s.outlineWidth, s.outlineColor, s.outlineOffset] : null,
|
|
96
|
+
shadow: shadow ? s.boxShadow : null,
|
|
97
|
+
border: s.borderTopStyle !== 'none' && parseFloat(s.borderTopWidth) > 0 ?
|
|
98
|
+
[s.borderTopWidth, s.borderTopStyle, s.borderTopColor] : null,
|
|
99
|
+
background: s.backgroundColor,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
active: identify(active), matched: !!target && target === active,
|
|
104
|
+
shown: !!target && shown(target), marker_shown: !!marker && shown(marker), paint,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
"""
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def keyboard_journey(page: Any, steps: list[dict]) -> dict:
|
|
111
|
+
"""Press real browser keys and assert each declared focus transition."""
|
|
112
|
+
from playwright.sync_api import TimeoutError
|
|
113
|
+
|
|
114
|
+
results = []
|
|
115
|
+
for step in steps:
|
|
116
|
+
selector = step["focus"]
|
|
117
|
+
targets = {"focus": selector, "indicator": step.get("indicator", selector)}
|
|
118
|
+
before = page.evaluate(_FOCUS_SAMPLE, targets)
|
|
119
|
+
page.keyboard.press(step["key"])
|
|
120
|
+
try:
|
|
121
|
+
page.wait_for_function(
|
|
122
|
+
"""selector => {
|
|
123
|
+
const nodes = document.querySelectorAll(selector);
|
|
124
|
+
return nodes.length === 1 && nodes[0] === document.activeElement;
|
|
125
|
+
}""",
|
|
126
|
+
arg=selector, timeout=900,
|
|
127
|
+
).dispose()
|
|
128
|
+
except TimeoutError:
|
|
129
|
+
pass
|
|
130
|
+
observed = page.evaluate(_FOCUS_SAMPLE, targets)
|
|
131
|
+
old, new = before["paint"], observed["paint"]
|
|
132
|
+
if not observed["matched"] or not observed["shown"]:
|
|
133
|
+
status, reason = "FAIL", "expected focus was not reached or was obscured"
|
|
134
|
+
elif not observed["marker_shown"] or new is None:
|
|
135
|
+
status, reason = "FAIL", "declared indicator target is missing or obscured"
|
|
136
|
+
elif old is None or before["matched"]:
|
|
137
|
+
status, reason = "UNVERIFIED", "no unfocused indicator sample for this step"
|
|
138
|
+
elif any(new[field] and new[field] != old[field]
|
|
139
|
+
for field in ("outline", "shadow", "border", "background")):
|
|
140
|
+
status, reason = "PASS", "focus target and indicator change observed"
|
|
141
|
+
else:
|
|
142
|
+
status, reason = "FAIL", "no visible change in the declared indicator styles"
|
|
143
|
+
results.append({**step, "status": status, "reason": reason, "before": before, "after": observed})
|
|
144
|
+
if status == "FAIL":
|
|
145
|
+
break
|
|
146
|
+
status = "FAIL" if any(row["status"] == "FAIL" for row in results) else (
|
|
147
|
+
"UNVERIFIED" if not results or any(row["status"] == "UNVERIFIED" for row in results) else "PASS"
|
|
148
|
+
)
|
|
149
|
+
return {"status": status, "steps": results, "planned_steps": len(steps)}
|