bugx-cli 0.1.0 → 0.1.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/README.md +193 -185
- 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/README.md +3 -2
- 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/bugx-social-preview.svg +71 -0
- package/core/assets/bugx-wechat-group.png +0 -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/audit_packs/README.md +2 -0
- package/core/audit_packs/pitfalls/auth_crypto.json +64 -0
- package/core/audit_packs/pitfalls/file_ssrf_cmd.json +64 -0
- package/core/audit_packs/pitfalls/go_backend.json +66 -0
- package/core/audit_packs/pitfalls/java_spring.json +64 -0
- package/core/audit_packs/pitfalls/js_ts_web.json +67 -0
- package/core/audit_packs/pitfalls/python_web.json +82 -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 +81 -11
- package/core/cloud_sync/cloud_onboard.py +42 -1
- package/core/cloud_sync/consent.py +33 -3
- package/core/cloud_sync/flywheel_client.py +186 -15
- 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 +670 -442
- 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 +6 -3
- package/core/launch_phases/SPEC.md +1 -1
- package/core/launch_phases/common.py +21 -2
- package/core/launch_phases/finding_confirm_phase.py +170 -5
- 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 +144 -8
- 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 +66 -36
- package/core/launch_phases/pre_state_builder.py +23 -176
- package/core/launch_phases/report_sharing.py +3 -7
- package/core/launch_phases/round_orchestrator.py +129 -58
- package/core/launch_phases/semantic_recon.py +545 -0
- 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 +13 -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/verify_loop.py +767 -0
- package/core/launch_phases/worker_barriers.py +15 -5
- package/core/launch_phases/worker_orchestrator.py +105 -25
- package/core/launch_phases/worker_prior.py +115 -0
- package/core/ledger/README.md +2 -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 +555 -10
- package/core/ledger/fp_ledger.py +255 -0
- 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 +2 -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 +57 -15
- package/core/planning/prompt_policy_engine.py +386 -0
- 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/README.md +4 -2
- package/core/prompts/command_routing_en.md +2 -2
- package/core/prompts/command_routing_zh.md +2 -2
- package/core/prompts/policies/prompt_policies.json +101 -0
- package/core/prompts/stages/stage_repair.md +1 -1
- package/core/prompts/stages/stage_verify.defensive.md +42 -0
- package/core/prompts/stages/stage_verify.md +44 -0
- 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/report_share.py +0 -8
- 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 +2 -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/pitfall_packs.py +277 -0
- 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/global_telemetry.py +20 -0
- 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 +193 -185
- 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 +172 -69
- package/interfaces/cli/bugx_cli/commands/advisory.py +1 -1
- package/interfaces/cli/bugx_cli/commands/agent.py +461 -134
- package/interfaces/cli/bugx_cli/commands/audit.py +10 -9
- package/interfaces/cli/bugx_cli/commands/autonomous.py +1 -1
- package/interfaces/cli/bugx_cli/commands/cloud.py +31 -22
- 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 +5 -4
- package/interfaces/cli/bugx_cli/commands/lifecycle.py +3 -3
- package/interfaces/cli/bugx_cli/commands/plugin.py +58 -23
- 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/project.py +6 -13
- package/interfaces/cli/bugx_cli/commands/report.py +2 -6
- package/interfaces/cli/bugx_cli/commands/system.py +524 -169
- package/interfaces/cli/bugx_cli/common.py +21 -15
- 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 +35 -16
- 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 +30 -15
- package/pyproject.toml +60 -9
- package/scripts/ensure-python.mjs +7 -7
- package/scripts/sync-version.mjs +10 -21
- package/scripts/test-npm-wrapper.mjs +1 -1
- package/core/assets/bugx-hero-cn.png +0 -0
- package/core/assets/bugx-hero-en.png +0 -0
- 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
|
@@ -256,6 +256,77 @@ def reports_for(target: str, root: Path | None = None,
|
|
|
256
256
|
return [desktop_report(platform), android_report(root), ios_report(platform)]
|
|
257
257
|
|
|
258
258
|
|
|
259
|
+
def is_available(target: str = "all") -> tuple[bool, str]:
|
|
260
|
+
"""降级契约:机械探测平台测试环境前置条件(<5ms,零阻塞、零子进程)。
|
|
261
|
+
|
|
262
|
+
只做 PATH 工具存在性与主机平台判定,不查询设备(设备查询属 check/status
|
|
263
|
+
慢路径)。返回 (available, detail):任一所选目标的必需通道工具在场即 True。
|
|
264
|
+
"""
|
|
265
|
+
host = host_name()
|
|
266
|
+
missing: list[str] = []
|
|
267
|
+
present: list[str] = []
|
|
268
|
+
targets = ("desktop", "android", "ios") if target == "all" else (target,)
|
|
269
|
+
wanted: set[str] = set()
|
|
270
|
+
if host == "unsupported":
|
|
271
|
+
return False, f"不支持的主机平台: {sys.platform};无任何平台测试通道"
|
|
272
|
+
if "desktop" in targets:
|
|
273
|
+
capture_by_host = {
|
|
274
|
+
"macos": ("screencapture", "appium"),
|
|
275
|
+
"windows": ("powershell", "WinAppDriver", "appium"),
|
|
276
|
+
"linux": ("gnome-screenshot", "scrot", "import", "appium"),
|
|
277
|
+
}
|
|
278
|
+
wanted.update(capture_by_host[host])
|
|
279
|
+
if "android" in targets:
|
|
280
|
+
wanted.add("adb")
|
|
281
|
+
if "ios" in targets:
|
|
282
|
+
wanted.update(("xcrun", "xcodebuild"))
|
|
283
|
+
for name in sorted(wanted):
|
|
284
|
+
(present if _which(name) else missing).append(name)
|
|
285
|
+
if present:
|
|
286
|
+
detail = f"主机 {host};通道工具在场: {', '.join(present)}"
|
|
287
|
+
else:
|
|
288
|
+
detail = f"主机 {host};所需通道工具全部缺失: {', '.join(sorted(wanted))}"
|
|
289
|
+
if missing:
|
|
290
|
+
detail += f";缺失: {', '.join(missing)}"
|
|
291
|
+
return bool(present), detail
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
def run_static_degraded(
|
|
295
|
+
target: str = "all", root: Path | str | None = None,
|
|
296
|
+
) -> dict:
|
|
297
|
+
"""降级路径:仅做 PATH 工具存在性静态检测,不查询设备/模拟器。
|
|
298
|
+
|
|
299
|
+
降级契约:输出与成功路径(check/status,status=READY)**可区分**——
|
|
300
|
+
status="degraded" + degraded=True + degraded_reason + checks_not_run;
|
|
301
|
+
设备可用性一律标注未验证,禁止把"工具在场"写成"目标可运行"。
|
|
302
|
+
"""
|
|
303
|
+
root_path = Path(root) if root is not None else None
|
|
304
|
+
available, availability_detail = is_available(target)
|
|
305
|
+
warnings = [
|
|
306
|
+
"降级模式:仅完成 PATH 工具存在性静态检测;设备/模拟器可用性未验证,"
|
|
307
|
+
"禁止把工具在场当成可运行目标"
|
|
308
|
+
]
|
|
309
|
+
payload: dict[str, Any] = {
|
|
310
|
+
"probe": "platform",
|
|
311
|
+
"status": "degraded",
|
|
312
|
+
"degraded": True,
|
|
313
|
+
"degraded_reason": (
|
|
314
|
+
"device_query_skipped" if available else "channel_tools_missing"
|
|
315
|
+
),
|
|
316
|
+
"success": True,
|
|
317
|
+
"target": target,
|
|
318
|
+
"root": str(root_path) if root_path is not None else None,
|
|
319
|
+
"findings": [],
|
|
320
|
+
"evidence": {
|
|
321
|
+
"availability_detail": availability_detail,
|
|
322
|
+
"host": host_name(),
|
|
323
|
+
},
|
|
324
|
+
"warnings": warnings,
|
|
325
|
+
"checks_not_run": ["adb-devices", "simctl-booted", "xctrace-devices"],
|
|
326
|
+
}
|
|
327
|
+
return payload
|
|
328
|
+
|
|
329
|
+
|
|
259
330
|
def summary_dict(reports: list[Report], *, root: Path | None = None) -> dict[str, Any]:
|
|
260
331
|
"""构建单根标准环境探测报告字典。"""
|
|
261
332
|
eval_reports = reports
|
|
@@ -321,7 +392,17 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
321
392
|
parser.add_argument("--json", action="store_true")
|
|
322
393
|
parser.add_argument("--envelope", action="store_true", default=True)
|
|
323
394
|
parser.add_argument("--no-envelope", dest="envelope", action="store_false")
|
|
395
|
+
parser.add_argument(
|
|
396
|
+
"--static-degraded", action="store_true",
|
|
397
|
+
help="显式执行降级路径(仅 PATH 工具存在性检测;输出 status=degraded,"
|
|
398
|
+
"不查询设备/模拟器)",
|
|
399
|
+
)
|
|
324
400
|
args = parser.parse_args(argv)
|
|
401
|
+
if args.static_degraded:
|
|
402
|
+
print(json.dumps(
|
|
403
|
+
run_static_degraded(args.target, args.root), ensure_ascii=False, indent=2,
|
|
404
|
+
))
|
|
405
|
+
return 0
|
|
325
406
|
reports = reports_for(args.target, args.root)
|
|
326
407
|
print_reports(reports, as_json=args.json, envelope=args.envelope, root=args.root)
|
|
327
408
|
if all(report.ready for report in reports):
|
|
@@ -37,6 +37,15 @@ PROBE_TIMEOUT_BUDGET: dict[str, float] = {
|
|
|
37
37
|
# 结果翻转。这里给出显式预算,消除该非确定性。
|
|
38
38
|
"platform": 30.0,
|
|
39
39
|
"memory": 20.0,
|
|
40
|
+
# mobile 探针逐 tier 拉起 adb/xcrun/maestro/appium 子进程,且 maestro 是
|
|
41
|
+
# JVM 工具:冷启动 --version 实测 7.5s(arm64 本机);版本探测已并行+2s
|
|
42
|
+
# 硬顶后单跑 ~3.4s,但 pre 并行跑全部探针时 CPU 争抢实测 5.13s,沿用
|
|
43
|
+
# default 5.0s 仍临界假超时并触发「安装决策」阻断链
|
|
44
|
+
# (F-RSI-20261118-004/005)。15s 提供 3x 余量,与 platform 冷启动策略一致。
|
|
45
|
+
"mobile": 15.0,
|
|
46
|
+
# openwiki 冷启动读索引约 2.3s,并行满载时临界 5s;建议性探针假超时
|
|
47
|
+
# 只产生噪音告警,同样的预算策略消除翻转。
|
|
48
|
+
"openwiki": 10.0,
|
|
40
49
|
"default": 5.0,
|
|
41
50
|
}
|
|
42
51
|
PROBE_TIMEOUT_MAX_SECONDS = 120.0
|
|
@@ -192,6 +201,17 @@ _BUILTIN_PROBES: tuple[ProbeDescriptor, ...] = (
|
|
|
192
201
|
# 设备/工具状态为宿主级;形态、目标平台由报告重投影处理。
|
|
193
202
|
cache_scope="host",
|
|
194
203
|
),
|
|
204
|
+
ProbeDescriptor(
|
|
205
|
+
name="android",
|
|
206
|
+
script="android_probe.py",
|
|
207
|
+
domain="mobile",
|
|
208
|
+
accepts_root=True,
|
|
209
|
+
description="Android 探针(Manifest 静态语义 + adb 动态 Intent)",
|
|
210
|
+
priority=59,
|
|
211
|
+
lifecycle="runtime",
|
|
212
|
+
readiness_args=("check",),
|
|
213
|
+
required=False,
|
|
214
|
+
),
|
|
195
215
|
ProbeDescriptor(
|
|
196
216
|
name="ios_binary",
|
|
197
217
|
script="ios_binary_probe.py",
|
|
@@ -472,15 +492,19 @@ def _cached_profile(
|
|
|
472
492
|
|
|
473
493
|
|
|
474
494
|
def _cached_probe_is_reusable(name: str, report: Mapping[str, Any]) -> bool:
|
|
475
|
-
"""
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
495
|
+
"""判定缓存的探针报告能否复用(跳过本次重探)。
|
|
496
|
+
|
|
497
|
+
F-RSI-20261118-005 深层语义:``BLOCKED``/``DEGRADED`` 是**环境时刻相关**
|
|
498
|
+
的失败结论——宿主环境恢复(如模拟器启动)后,30 分钟 TTL 内的缓存自锁
|
|
499
|
+
会让恢复不可见(真机实证:模拟器就绪后 pre 仍连续阻断)。因此失败/降级
|
|
500
|
+
结论一律不可复用(每次重查,成本仅几秒);只有 ``READY``/``NOT_APPLICABLE``
|
|
501
|
+
/``ABSENT`` 才进入 30 分钟复用窗口。Codebase Memory 额外校验版本 pin:
|
|
502
|
+
其就绪依赖可替换的外部可执行文件,缓存的成功必须证明当前精确 pin。
|
|
481
503
|
"""
|
|
482
504
|
status = str(report.get("status", "")).upper()
|
|
483
|
-
if status
|
|
505
|
+
if status in {"BLOCKED", "DEGRADED"}:
|
|
506
|
+
return False
|
|
507
|
+
if status not in {"READY", "NOT_APPLICABLE", "ABSENT"}:
|
|
484
508
|
return False
|
|
485
509
|
if name != "codebase-memory":
|
|
486
510
|
return True
|
|
@@ -1667,3 +1691,80 @@ def run_preflight_probes(
|
|
|
1667
1691
|
pass
|
|
1668
1692
|
|
|
1669
1693
|
return profile
|
|
1694
|
+
|
|
1695
|
+
|
|
1696
|
+
def is_available() -> tuple[bool, str]:
|
|
1697
|
+
"""降级契约:机械探活内置探针注册表完整性(零子进程、零探针执行)。
|
|
1698
|
+
|
|
1699
|
+
判定两条机械事实:注册表非空,且每个内置描述符声明的脚本文件真实存在。
|
|
1700
|
+
脚本缺失说明引擎安装损坏,调用方必须走 ``run_static_degraded`` 只输出
|
|
1701
|
+
静态注册表快照,禁止伪装探针执行就绪。
|
|
1702
|
+
"""
|
|
1703
|
+
if not _REGISTRY:
|
|
1704
|
+
return False, "探针注册表为空;没有可分发的探针"
|
|
1705
|
+
# 描述符 script 相对引擎根(core/)解析,复用与执行链相同的
|
|
1706
|
+
# _resolve_probe_script 候选规则,避免把「脚本已迁移」误报成「脚本缺失」。
|
|
1707
|
+
core_dir = Path(__file__).resolve().parent.parent
|
|
1708
|
+
missing = sorted(
|
|
1709
|
+
descriptor.script
|
|
1710
|
+
for descriptor in _REGISTRY.values()
|
|
1711
|
+
if not _resolve_probe_script(core_dir, descriptor.script).is_file()
|
|
1712
|
+
)
|
|
1713
|
+
if missing:
|
|
1714
|
+
return False, f"探针脚本缺失: {', '.join(missing)}"
|
|
1715
|
+
return True, f"{len(_REGISTRY)} 个内置探针脚本齐全"
|
|
1716
|
+
|
|
1717
|
+
|
|
1718
|
+
def run_static_degraded(name: str | None = None) -> dict[str, Any]:
|
|
1719
|
+
"""降级契约:不执行任何探针子进程,只输出注册表静态快照。
|
|
1720
|
+
|
|
1721
|
+
输出与成功路径(``run_probe_readiness`` / profile 合成的真实探针执行报告)
|
|
1722
|
+
字段级可区分:``status="degraded"`` + ``degraded=True`` + ``degraded_reason``,
|
|
1723
|
+
每个条目只含描述符元数据并显式声明 ``executed=False``,禁止把静态快照
|
|
1724
|
+
伪装成探针执行结果。
|
|
1725
|
+
"""
|
|
1726
|
+
available, availability_detail = is_available()
|
|
1727
|
+
probes = list_probes()
|
|
1728
|
+
if name:
|
|
1729
|
+
descriptor = get_probe(name)
|
|
1730
|
+
probes = [descriptor] if descriptor is not None else []
|
|
1731
|
+
unknown = descriptor is None
|
|
1732
|
+
else:
|
|
1733
|
+
unknown = False
|
|
1734
|
+
entries = [
|
|
1735
|
+
{
|
|
1736
|
+
"name": p.name,
|
|
1737
|
+
"script": p.script,
|
|
1738
|
+
"domain": p.domain,
|
|
1739
|
+
"lifecycle": p.lifecycle,
|
|
1740
|
+
"priority": p.priority,
|
|
1741
|
+
"accepts_root": p.accepts_root,
|
|
1742
|
+
"required": p.required,
|
|
1743
|
+
"critical": p.critical,
|
|
1744
|
+
"cache_scope": p.cache_scope,
|
|
1745
|
+
"readiness_action_declared": p.readiness_args is not None,
|
|
1746
|
+
"executed": False,
|
|
1747
|
+
}
|
|
1748
|
+
for p in probes
|
|
1749
|
+
]
|
|
1750
|
+
return {
|
|
1751
|
+
"schema_version": 1,
|
|
1752
|
+
"success": bool(entries) and not unknown,
|
|
1753
|
+
"status": "degraded",
|
|
1754
|
+
"degraded": True,
|
|
1755
|
+
"degraded_reason": (
|
|
1756
|
+
"unknown_probe" if unknown
|
|
1757
|
+
else "static_mode_forced" if available else "probe_registry_incomplete"
|
|
1758
|
+
),
|
|
1759
|
+
"probe_mode": "static_degraded",
|
|
1760
|
+
"registry_total": len(_REGISTRY),
|
|
1761
|
+
"count": len(entries),
|
|
1762
|
+
"entries": entries,
|
|
1763
|
+
"findings": [],
|
|
1764
|
+
"evidence": {"availability_detail": availability_detail},
|
|
1765
|
+
"metadata": {
|
|
1766
|
+
"degraded_mode": "registry_snapshot_only",
|
|
1767
|
+
"probe_execution_skipped": True,
|
|
1768
|
+
"fallback": "注册表不可用或探针执行被跳过时只提供描述符元数据;禁止据此判定环境就绪",
|
|
1769
|
+
},
|
|
1770
|
+
}
|
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""core/probes/sast_fixture_corpus.py — SAST 规则回归语料运行器。
|
|
3
|
+
|
|
4
|
+
规则改动最容易出的两类事故,都只有「跑一遍真语料」才能发现:
|
|
5
|
+
|
|
6
|
+
* **假阳性**:新加的判据把 ``RegExp.exec``、列表式 ``subprocess.run`` 一起报了;
|
|
7
|
+
* **假阴性**:判据收得过紧,把 ``urlopen(base + "/health")`` 这类真阳性误杀了。
|
|
8
|
+
|
|
9
|
+
后者更危险——它让规则"看起来更干净",实际是漏报。所以语料里正向用例的数量
|
|
10
|
+
不少于负向用例。
|
|
11
|
+
|
|
12
|
+
语料本身是**长期证据资产**,存放在 ``verification/sast-fixtures/<rule_id>/``,
|
|
13
|
+
不受 ``AGENTS.md`` 中"测试过程文件必须清理"的约束(``verification/`` 是证据域)。
|
|
14
|
+
用例文件用 ``.fixture`` 后缀而不是 ``.py``/``.js``:语料里是故意写成有漏洞的代码,
|
|
15
|
+
不能让它们被仓库全量 SAST 扫成告警,也不能被当成单元测试源码收集。
|
|
16
|
+
|
|
17
|
+
每个用例是一个独立文件,头部声明契约(``case`` 可省略,默认取文件名)::
|
|
18
|
+
|
|
19
|
+
# bugx-sast-fixture: rule=SEC-SSRF-001 lang=python expect=hit
|
|
20
|
+
# bugx-sast-fixture-xfail: <仅当期望与当前规则实现不符时出现,写明缺陷原因>
|
|
21
|
+
|
|
22
|
+
``expect=hit`` 要求该 rule_id 命中,``expect=miss`` 要求不命中。``xfail`` 表示
|
|
23
|
+
"这是规则的已知缺陷,用例保持红状态作为待修目标"——**不要**为了让套件变绿而把
|
|
24
|
+
期望改成当前行为。
|
|
25
|
+
|
|
26
|
+
用法::
|
|
27
|
+
|
|
28
|
+
python3 -m core.probes.sast_fixture_corpus --root .
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
from __future__ import annotations
|
|
32
|
+
|
|
33
|
+
import argparse
|
|
34
|
+
import shutil
|
|
35
|
+
import sys
|
|
36
|
+
import tempfile
|
|
37
|
+
from dataclasses import dataclass
|
|
38
|
+
from pathlib import Path
|
|
39
|
+
|
|
40
|
+
FIXTURE_DIR = Path("verification") / "sast-fixtures"
|
|
41
|
+
HEADER_PREFIX = "# bugx-sast-fixture:"
|
|
42
|
+
XFAIL_PREFIX = "# bugx-sast-fixture-xfail:"
|
|
43
|
+
|
|
44
|
+
# 语料里声明的语言 -> 临时文件后缀(解析器按后缀判语言)
|
|
45
|
+
LANG_SUFFIX = {"python": ".py", "javascript": ".js", "typescript": ".ts"}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@dataclass
|
|
49
|
+
class FixtureCase:
|
|
50
|
+
path: Path
|
|
51
|
+
case_id: str
|
|
52
|
+
rule_id: str
|
|
53
|
+
language: str
|
|
54
|
+
expect_hit: bool
|
|
55
|
+
xfail_reason: str
|
|
56
|
+
source: str
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@dataclass
|
|
60
|
+
class CaseOutcome:
|
|
61
|
+
case: FixtureCase
|
|
62
|
+
hit: bool
|
|
63
|
+
matched_rule_ids: tuple[str, ...]
|
|
64
|
+
|
|
65
|
+
@property
|
|
66
|
+
def is_xfail(self) -> bool:
|
|
67
|
+
return bool(self.case.xfail_reason)
|
|
68
|
+
|
|
69
|
+
@property
|
|
70
|
+
def ok(self) -> bool:
|
|
71
|
+
"""结果符合契约。xfail 用例"仍然失败"才算符合。"""
|
|
72
|
+
return self.hit == self.case.expect_hit
|
|
73
|
+
|
|
74
|
+
@property
|
|
75
|
+
def xpass(self) -> bool:
|
|
76
|
+
"""xfail 用例意外变绿:说明缺陷已修,标记该摘掉了。"""
|
|
77
|
+
return self.is_xfail and self.ok
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _resolve_root(root: Path | str | None) -> Path:
|
|
81
|
+
if root is not None:
|
|
82
|
+
return Path(root).expanduser().resolve()
|
|
83
|
+
# 默认取本模块所在仓库根,保证从任意 cwd 调用都能找到语料
|
|
84
|
+
return Path(__file__).resolve().parents[2]
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def _parse_header(text: str) -> tuple[dict[str, str], str]:
|
|
88
|
+
"""解析头部契约,返回 (字段字典, xfail 原因)。"""
|
|
89
|
+
fields: dict[str, str] = {}
|
|
90
|
+
xfail_reason = ""
|
|
91
|
+
for line in text.splitlines()[:6]:
|
|
92
|
+
stripped = line.strip()
|
|
93
|
+
if stripped.startswith(XFAIL_PREFIX):
|
|
94
|
+
xfail_reason = stripped[len(XFAIL_PREFIX):].strip()
|
|
95
|
+
continue
|
|
96
|
+
if not stripped.startswith(HEADER_PREFIX):
|
|
97
|
+
continue
|
|
98
|
+
for token in stripped[len(HEADER_PREFIX):].split():
|
|
99
|
+
if "=" in token:
|
|
100
|
+
key, value = token.split("=", 1)
|
|
101
|
+
fields[key.strip()] = value.strip()
|
|
102
|
+
return fields, xfail_reason
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def load_cases(root: Path | str | None = None) -> tuple[list[FixtureCase], list[str]]:
|
|
106
|
+
"""读取全部用例。返回 (用例列表, 结构错误明细)。"""
|
|
107
|
+
base = _resolve_root(root) / FIXTURE_DIR
|
|
108
|
+
if not base.is_dir():
|
|
109
|
+
return [], [f"语料目录不存在: {base}"]
|
|
110
|
+
|
|
111
|
+
cases: list[FixtureCase] = []
|
|
112
|
+
errors: list[str] = []
|
|
113
|
+
for path in sorted(base.rglob("*.fixture")):
|
|
114
|
+
try:
|
|
115
|
+
text = path.read_text(encoding="utf-8")
|
|
116
|
+
except OSError as exc:
|
|
117
|
+
errors.append(f"{path}: 读取失败 ({exc})")
|
|
118
|
+
continue
|
|
119
|
+
fields, xfail_reason = _parse_header(text)
|
|
120
|
+
missing = [k for k in ("rule", "lang", "expect") if k not in fields]
|
|
121
|
+
if missing:
|
|
122
|
+
errors.append(f"{path}: 头部缺少字段 {','.join(missing)}")
|
|
123
|
+
continue
|
|
124
|
+
language = fields["lang"]
|
|
125
|
+
if language not in LANG_SUFFIX:
|
|
126
|
+
errors.append(f"{path}: 不支持的语言 {language!r}")
|
|
127
|
+
continue
|
|
128
|
+
expect = fields["expect"]
|
|
129
|
+
if expect not in {"hit", "miss"}:
|
|
130
|
+
errors.append(f"{path}: expect 只能是 hit/miss,实际 {expect!r}")
|
|
131
|
+
continue
|
|
132
|
+
cases.append(
|
|
133
|
+
FixtureCase(
|
|
134
|
+
path=path,
|
|
135
|
+
case_id=fields.get("case", path.stem),
|
|
136
|
+
rule_id=fields["rule"],
|
|
137
|
+
language=language,
|
|
138
|
+
expect_hit=expect == "hit",
|
|
139
|
+
xfail_reason=xfail_reason,
|
|
140
|
+
source=text,
|
|
141
|
+
)
|
|
142
|
+
)
|
|
143
|
+
if not cases and not errors:
|
|
144
|
+
errors.append(f"语料目录为空: {base}")
|
|
145
|
+
return cases, errors
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def _strip_header(text: str) -> str:
|
|
149
|
+
"""剥掉头部契约行,只把纯源码交给引擎。
|
|
150
|
+
|
|
151
|
+
头部用 ``#`` 注释(Python 合法、JS 不合法),且不应参与匹配:否则 JS 用例
|
|
152
|
+
会把 ``# bugx-sast-fixture: ...`` 当成代码文本一起扫。
|
|
153
|
+
"""
|
|
154
|
+
lines = text.splitlines()
|
|
155
|
+
index = 0
|
|
156
|
+
while index < len(lines) and (
|
|
157
|
+
not lines[index].strip()
|
|
158
|
+
or lines[index].lstrip().startswith((HEADER_PREFIX, XFAIL_PREFIX))
|
|
159
|
+
):
|
|
160
|
+
index += 1
|
|
161
|
+
return "\n".join(lines[index:]) + "\n"
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def _run_case(case: FixtureCase, workdir: Path, matcher) -> CaseOutcome:
|
|
165
|
+
"""把用例源码写成临时源文件后交给规则引擎,返回命中的 rule_id 集合。"""
|
|
166
|
+
from core.retrieval.universal_code_matcher import UniversalCodeMatcher
|
|
167
|
+
|
|
168
|
+
target = workdir / f"{case.case_id}{LANG_SUFFIX[case.language]}"
|
|
169
|
+
target.write_text(_strip_header(case.source), encoding="utf-8")
|
|
170
|
+
parsed = UniversalCodeMatcher.parse_file(target, rel_path=target.name)
|
|
171
|
+
findings = matcher.match_file(parsed)
|
|
172
|
+
rule_ids = tuple(sorted({f["rule_id"] for f in findings}))
|
|
173
|
+
return CaseOutcome(case=case, hit=case.rule_id in rule_ids, matched_rule_ids=rule_ids)
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def run_cases(root: Path | str | None = None) -> tuple[list[CaseOutcome], list[str]]:
|
|
177
|
+
"""执行全部用例,返回 (逐例结果, 结构错误明细)。"""
|
|
178
|
+
from core.probes.sast_rules import BUILTIN_RULES, SASTRuleMatcher
|
|
179
|
+
|
|
180
|
+
cases, errors = load_cases(root)
|
|
181
|
+
known_rules = {rule.id for rule in BUILTIN_RULES}
|
|
182
|
+
runnable: list[FixtureCase] = []
|
|
183
|
+
for case in cases:
|
|
184
|
+
if case.rule_id not in known_rules:
|
|
185
|
+
errors.append(f"{case.path}: 未知规则 ID {case.rule_id}")
|
|
186
|
+
continue
|
|
187
|
+
runnable.append(case)
|
|
188
|
+
|
|
189
|
+
matcher = SASTRuleMatcher(BUILTIN_RULES)
|
|
190
|
+
workdir = Path(tempfile.mkdtemp(prefix="bugx-sast-fixture-"))
|
|
191
|
+
outcomes: list[CaseOutcome] = []
|
|
192
|
+
try:
|
|
193
|
+
for case in runnable:
|
|
194
|
+
outcomes.append(_run_case(case, workdir, matcher))
|
|
195
|
+
finally:
|
|
196
|
+
shutil.rmtree(workdir, ignore_errors=True)
|
|
197
|
+
return outcomes, errors
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def _summarize(outcomes: list[CaseOutcome], errors: list[str]) -> tuple[int, int, list[str]]:
|
|
201
|
+
passed = 0
|
|
202
|
+
failed = len(errors)
|
|
203
|
+
details: list[str] = list(errors)
|
|
204
|
+
|
|
205
|
+
for outcome in outcomes:
|
|
206
|
+
case = outcome.case
|
|
207
|
+
actual = "hit" if outcome.hit else "miss"
|
|
208
|
+
expected = "hit" if case.expect_hit else "miss"
|
|
209
|
+
if outcome.xpass:
|
|
210
|
+
failed += 1
|
|
211
|
+
details.append(
|
|
212
|
+
f"XPASS {case.case_id} [{case.rule_id}] 结果已符合期望,缺陷可能已修复,"
|
|
213
|
+
f"请复核并删除 xfail 标记({case.path})"
|
|
214
|
+
)
|
|
215
|
+
elif outcome.ok or outcome.is_xfail:
|
|
216
|
+
# 符合契约,或已知缺陷被稳定复现(xfail)
|
|
217
|
+
passed += 1
|
|
218
|
+
else:
|
|
219
|
+
failed += 1
|
|
220
|
+
details.append(
|
|
221
|
+
f"FAIL {case.case_id} [{case.rule_id}] expect={expected} actual={actual}"
|
|
222
|
+
f" matched={','.join(outcome.matched_rule_ids) or '-'}"
|
|
223
|
+
)
|
|
224
|
+
return passed, failed, details
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
def known_defects(outcomes: list[CaseOutcome]) -> list[str]:
|
|
228
|
+
"""已知缺陷(xfail 且仍未达期望)的逐条说明,用于交付报告与套件输出。"""
|
|
229
|
+
lines: list[str] = []
|
|
230
|
+
for outcome in outcomes:
|
|
231
|
+
case = outcome.case
|
|
232
|
+
if not case.xfail_reason or outcome.ok:
|
|
233
|
+
continue
|
|
234
|
+
actual = "hit" if outcome.hit else "miss"
|
|
235
|
+
expected = "hit" if case.expect_hit else "miss"
|
|
236
|
+
lines.append(
|
|
237
|
+
f"{case.case_id} [{case.rule_id}] expect={expected} actual={actual}:{case.xfail_reason}"
|
|
238
|
+
)
|
|
239
|
+
return lines
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def verify(root: Path | str | None = None) -> tuple[int, int, list[str]]:
|
|
243
|
+
"""跑全部用例,返回 (通过数, 失败数, 失败明细)。
|
|
244
|
+
|
|
245
|
+
``xfail`` 用例"仍然不达期望"计入通过——它是被稳定复现的已知缺陷,不该让套件
|
|
246
|
+
常红(常红等于没人看)。真正的回归才算失败;xfail 用例若意外变绿(XPASS)同样
|
|
247
|
+
记为失败,提示把标记摘掉,否则缺陷修好了也没人知道。
|
|
248
|
+
"""
|
|
249
|
+
outcomes, errors = run_cases(root)
|
|
250
|
+
return _summarize(outcomes, errors)
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
def main(argv: list[str] | None = None) -> int:
|
|
254
|
+
parser = argparse.ArgumentParser(
|
|
255
|
+
prog="sast_fixture_corpus",
|
|
256
|
+
description=(
|
|
257
|
+
"SAST 规则回归语料运行器:"
|
|
258
|
+
"用 verification/sast-fixtures 下的语料校验内置规则行为"
|
|
259
|
+
),
|
|
260
|
+
)
|
|
261
|
+
parser.add_argument(
|
|
262
|
+
"--root",
|
|
263
|
+
default=None,
|
|
264
|
+
help="仓库根目录(含 verification/sast-fixtures),默认取模块所在仓库",
|
|
265
|
+
)
|
|
266
|
+
parser.add_argument("--json", action="store_true", help="以 JSON 输出结果")
|
|
267
|
+
parser.add_argument("--verbose", action="store_true", help="逐条打印用例结果")
|
|
268
|
+
args = parser.parse_args(argv)
|
|
269
|
+
|
|
270
|
+
outcomes, errors = run_cases(args.root)
|
|
271
|
+
passed, failed, details = _summarize(outcomes, errors)
|
|
272
|
+
|
|
273
|
+
xfail_total = sum(1 for o in outcomes if o.is_xfail)
|
|
274
|
+
hits = sum(1 for o in outcomes if o.case.expect_hit)
|
|
275
|
+
misses = len(outcomes) - hits
|
|
276
|
+
defects = known_defects(outcomes)
|
|
277
|
+
|
|
278
|
+
if args.json:
|
|
279
|
+
import json
|
|
280
|
+
|
|
281
|
+
print(
|
|
282
|
+
json.dumps(
|
|
283
|
+
{
|
|
284
|
+
"total": len(outcomes),
|
|
285
|
+
"expected_hit": hits,
|
|
286
|
+
"expected_miss": misses,
|
|
287
|
+
"xfail": xfail_total,
|
|
288
|
+
"passed": passed,
|
|
289
|
+
"failed": failed,
|
|
290
|
+
"details": details,
|
|
291
|
+
"known_defects": defects,
|
|
292
|
+
"cases": [
|
|
293
|
+
{
|
|
294
|
+
"case": o.case.case_id,
|
|
295
|
+
"rule_id": o.case.rule_id,
|
|
296
|
+
"language": o.case.language,
|
|
297
|
+
"expect": "hit" if o.case.expect_hit else "miss",
|
|
298
|
+
"actual": "hit" if o.hit else "miss",
|
|
299
|
+
"xfail": bool(o.case.xfail_reason),
|
|
300
|
+
"ok": o.ok and not o.xpass,
|
|
301
|
+
}
|
|
302
|
+
for o in outcomes
|
|
303
|
+
],
|
|
304
|
+
},
|
|
305
|
+
ensure_ascii=False,
|
|
306
|
+
indent=2,
|
|
307
|
+
)
|
|
308
|
+
)
|
|
309
|
+
else:
|
|
310
|
+
if args.verbose:
|
|
311
|
+
for o in outcomes:
|
|
312
|
+
if o.xpass:
|
|
313
|
+
mark = "XPASS"
|
|
314
|
+
elif o.is_xfail:
|
|
315
|
+
mark = "XFAIL"
|
|
316
|
+
elif o.ok:
|
|
317
|
+
mark = "PASS"
|
|
318
|
+
else:
|
|
319
|
+
mark = "FAIL"
|
|
320
|
+
print(
|
|
321
|
+
f"{mark:5} {o.case.case_id:38} {o.case.rule_id:14} "
|
|
322
|
+
f"{'hit' if o.hit else 'miss':4} (expect {'hit' if o.case.expect_hit else 'miss'})"
|
|
323
|
+
)
|
|
324
|
+
print(
|
|
325
|
+
f"SAST 规则回归语料: 共 {len(outcomes)} 例 "
|
|
326
|
+
f"(应命中 {hits} / 应不命中 {misses}),xfail {xfail_total} 例"
|
|
327
|
+
)
|
|
328
|
+
print(f"通过 {passed},失败 {failed}")
|
|
329
|
+
for line in details:
|
|
330
|
+
print(f" - {line}")
|
|
331
|
+
if defects:
|
|
332
|
+
print("已知缺陷(xfail,待修;修好后套件会报 XPASS):")
|
|
333
|
+
for line in defects:
|
|
334
|
+
print(f" - {line}")
|
|
335
|
+
|
|
336
|
+
return 0 if failed == 0 else 1
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
if __name__ == "__main__":
|
|
340
|
+
sys.exit(main())
|