chore: import upstream snapshot with attribution
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
CI / coverage-report (push) Has been cancelled
CI / test-kubernetes (push) Has been cancelled
CI / should-run-thorough (push) Has been cancelled
CI / test-thorough (cloudwatch-demo) (push) Has been cancelled
CI / test-thorough (flink-ecs) (push) Has been cancelled
CI / test-thorough (upstream-lambda) (push) Has been cancelled
CI / test-thorough (prefect-ecs-fargate) (push) Has been cancelled
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Has been cancelled
Benchmark image — build + push to ECR (any adapter) / build + push (push) Has been cancelled
CI / quality (ubuntu-latest) (push) Has been cancelled
CI / test (tools-runtime) (push) Has been cancelled
CI / test (e2e-general) (push) Has been cancelled
CI / test (cli-runtime) (push) Has been cancelled
CI / test (e2e-provider-and-openclaw) (push) Has been cancelled
CI / test (integrations-and-misc) (push) Has been cancelled
Release / verify (push) Has been cancelled
Release / build-python-dist (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Has been cancelled
Release / publish-release (push) Has been cancelled
Release / publish-main-release (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Has been cancelled
Release / prepare (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Has been cancelled
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Has been cancelled

This commit is contained in:
wehub-resource-sync
2026-07-13 13:10:45 +08:00
commit 4b6817381b
3933 changed files with 525247 additions and 0 deletions
@@ -0,0 +1,59 @@
"""Read-only discovery commands stash a compact observation for the agent.
This is what lets the observe→answer loop summarize "is sentry installed?" from
the actual ``/integrations`` output instead of leaving the user with a raw table.
"""
from __future__ import annotations
from surfaces.interactive_shell.command_registry.integrations import (
_MAX_OBSERVATION_DETAIL_CHARS,
_record_integration_show_observation,
_record_integrations_observation,
)
from surfaces.interactive_shell.session import Session
def test_records_status_lines_for_each_service() -> None:
session = Session()
results = [
{"service": "datadog", "source": "local store", "status": "passed", "detail": "Connected."},
{"service": "sentry", "source": "-", "status": "missing", "detail": "Not configured."},
]
_record_integrations_observation(session, results)
assert session.agent.last_observation is not None
obs = session.agent.last_observation
assert "datadog: passed" in obs
assert "sentry: missing" in obs
assert "Not configured." in obs
def test_truncates_long_detail() -> None:
session = Session()
long_detail = "x" * (_MAX_OBSERVATION_DETAIL_CHARS + 50)
_record_integrations_observation(
session, [{"service": "datadog", "status": "passed", "detail": long_detail}]
)
assert session.agent.last_observation is not None
# Detail is bounded (ellipsis substituted for the tail) so prompts stay cheap.
assert "" in session.agent.last_observation
assert long_detail not in session.agent.last_observation
def test_skips_rows_without_a_service_name() -> None:
session = Session()
_record_integrations_observation(session, [{"service": "", "status": "missing"}])
assert session.agent.last_observation is None
def test_show_observation_renders_key_values() -> None:
session = Session()
_record_integration_show_observation(
session, {"service": "datadog", "status": "passed", "monitors": "14"}
)
assert session.agent.last_observation is not None
assert "service: datadog" in session.agent.last_observation
assert "monitors: 14" in session.agent.last_observation
@@ -0,0 +1,124 @@
"""Configuring an integration mid-session refreshes the session's known state.
Regression: after ``/integrations setup sentry`` saved sentry to the local
store, the assistant still answered "Sentry is not integrated" because the
session's ``configured_integrations`` snapshot was only taken at REPL boot and
never refreshed. The setup/remove (and /mcp connect|disconnect) paths must
re-resolve the env + store integration set so the same session reflects the
change.
"""
from __future__ import annotations
from typing import Any
from rich.console import Console
from surfaces.interactive_shell.command_registry import integrations as _integrations
from surfaces.interactive_shell.session import Session
def _console() -> Console:
return Console(force_terminal=False, no_color=True)
def _noop_cli_command(*_args: Any, **_kwargs: Any) -> bool:
"""Stand in for the setup/remove subprocess so no child process is spawned."""
return True
def test_refresh_integration_state_rehydrates_and_clears_cache(monkeypatch: Any) -> None:
monkeypatch.setattr(
"platform.harness_ports.configured_integration_services",
lambda: ["gitlab", "sentry"],
)
refreshed = {"gitlab": {"token": "x"}, "sentry": {"dsn": "y"}}
monkeypatch.setattr(
"core.agent_harness.session.integration_resolution.resolve_integrations",
lambda: refreshed,
)
session = Session()
# Stale boot-time snapshot + a cached resolution from an earlier turn.
session.configured_integrations = ("gitlab",)
session.configured_integrations_known = True
session.resolved_integrations_cache = {"gitlab": {}}
session.refresh_integration_state()
assert session.resolved_integrations_cache == refreshed
assert session.configured_integrations_known is True
assert session.configured_integrations == ("gitlab", "sentry")
def test_setup_subcommand_refreshes_configured_integrations(monkeypatch: Any) -> None:
# The setup subprocess is replaced with a no-op; the store mutation is
# simulated by flipping what effective resolution returns afterwards.
monkeypatch.setattr(_integrations, "run_cli_command", _noop_cli_command)
store: dict[str, dict[str, Any]] = {"gitlab": {}}
monkeypatch.setattr(
"platform.harness_ports.configured_integration_services",
lambda: list(store),
)
monkeypatch.setattr(
"core.agent_harness.session.integration_resolution.resolve_integrations",
lambda: dict(store),
)
session = Session()
session.hydrate_configured_integrations()
assert session.configured_integrations == ("gitlab",)
# The user runs `/integrations setup sentry`; setup writes sentry to store.
store["sentry"] = {}
handled = _integrations._cmd_integrations(session, _console(), ["setup", "sentry"])
assert handled is True
assert "sentry" in session.configured_integrations
def test_remove_subcommand_refreshes_configured_integrations(monkeypatch: Any) -> None:
monkeypatch.setattr(_integrations, "run_cli_command", _noop_cli_command)
store: dict[str, dict[str, Any]] = {"gitlab": {}, "sentry": {}}
monkeypatch.setattr(
"platform.harness_ports.configured_integration_services",
lambda: list(store),
)
monkeypatch.setattr(
"core.agent_harness.session.integration_resolution.resolve_integrations",
lambda: dict(store),
)
session = Session()
session.hydrate_configured_integrations()
assert "sentry" in session.configured_integrations
store.pop("sentry")
handled = _integrations._cmd_integrations(session, _console(), ["remove", "sentry"])
assert handled is True
assert "sentry" not in session.configured_integrations
def test_mcp_connect_refreshes_configured_integrations(monkeypatch: Any) -> None:
monkeypatch.setattr(_integrations, "run_cli_command", _noop_cli_command)
store: dict[str, dict[str, Any]] = {"gitlab": {}}
monkeypatch.setattr(
"platform.harness_ports.configured_integration_services",
lambda: list(store),
)
monkeypatch.setattr(
"core.agent_harness.session.integration_resolution.resolve_integrations",
lambda: dict(store),
)
session = Session()
session.hydrate_configured_integrations()
store["github_mcp"] = {}
handled = _integrations._cmd_mcp(session, _console(), ["connect", "github_mcp"])
assert handled is True
assert "github_mcp" in session.configured_integrations
@@ -0,0 +1,34 @@
from __future__ import annotations
from surfaces.interactive_shell.command_registry import repl_data
def test_configured_integration_names_reads_catalog_without_verify(monkeypatch) -> None:
monkeypatch.setattr(
"integrations.verify.resolve_effective_integrations",
lambda: {"aws": {}, "grafana": {}},
)
verify_calls: list[str | None] = []
monkeypatch.setattr(
"integrations.verify.verify_integrations",
lambda service=None, **_kwargs: verify_calls.append(service) or [],
)
assert repl_data.configured_integration_names() == ["aws", "grafana"]
assert verify_calls == []
def test_verify_integration_checks_one_service(monkeypatch) -> None:
calls: list[str | None] = []
def _verify(service: str | None = None, **kwargs: object) -> list[dict[str, str]]:
calls.append(service)
return [{"service": service or "", "source": "env", "status": "ok", "detail": "ok"}]
monkeypatch.setattr("integrations.verify.verify_integrations", _verify)
row = repl_data.verify_integration("aws")
assert calls == ["aws"]
assert row is not None
assert row["service"] == "aws"
@@ -0,0 +1,102 @@
"""Tests for slash-command MCP catalog."""
from __future__ import annotations
from core.agent_harness.tools.action_tools import get_action_tool
from surfaces.interactive_shell.command_registry import SLASH_COMMANDS
from surfaces.interactive_shell.command_registry.slash_catalog import (
_MCP_BY_COMMAND,
build_slash_command_specs,
format_slash_catalog_text,
slash_invoke_input_schema,
slash_invoke_tool_description,
)
_MIN_LLM_DESCRIPTION_LEN = 20
def test_slash_catalog_covers_all_registered_commands() -> None:
registered = set(SLASH_COMMANDS.keys())
catalogued = set(_MCP_BY_COMMAND)
missing = sorted(registered - catalogued)
stale = sorted(catalogued - registered)
assert not missing, (
"Add _MCP_BY_COMMAND entries in surfaces/interactive_shell/command_registry/"
f"slash_catalog.py for: {missing}. See surfaces/interactive_shell/AGENTS.md "
"(Slash commands → REPL + CLI parity)."
)
assert not stale, (
"Remove stale _MCP_BY_COMMAND keys from slash_catalog.py (no longer in "
f"SLASH_COMMANDS): {stale}"
)
specs = build_slash_command_specs()
assert len(specs) == len(SLASH_COMMANDS)
def test_slash_command_specs_have_mcp_metadata() -> None:
for spec in build_slash_command_specs():
assert len(spec.llm_description) >= _MIN_LLM_DESCRIPTION_LEN, spec.name
assert spec.use_cases, spec.name
def test_slash_invoke_tool_description_lists_every_command() -> None:
description = slash_invoke_tool_description()
for name in SLASH_COMMANDS:
assert name in description
def test_slash_invoke_description_is_not_a_natural_language_router() -> None:
description = slash_invoke_tool_description().lower()
assert "explicit slash-command operations" in description
assert "do not use this as a natural-language router" in description
assert "assistant_handoff" in description
assert "read-only discovery" in description
def test_slash_invoke_schema_enum_matches_slash_commands() -> None:
schema = slash_invoke_input_schema()
command = schema["properties"]["command"]
assert set(command["enum"]) == set(SLASH_COMMANDS.keys())
def test_registered_slash_invoke_uses_catalog() -> None:
entry = get_action_tool("slash_invoke")
assert entry is not None
assert len(entry.description) > 200
assert set(entry.input_schema["properties"]["command"]["enum"]) == set(SLASH_COMMANDS.keys())
def test_format_slash_catalog_text_compact_is_non_empty() -> None:
text = format_slash_catalog_text(compact=True)
assert text
assert "**/health**" in text
def test_model_catalog_excludes_natural_language_status_questions() -> None:
spec = next(spec for spec in build_slash_command_specs() if spec.name == "/model")
assert "explicit /model command operations" in spec.llm_description.lower()
assert "asks to run /model show" in " ".join(spec.use_cases).lower()
anti_examples = " ".join(spec.anti_examples).lower()
assert "which model is being used now" in anti_examples
assert "what model/provider" in anti_examples
assert "openai is configured" in anti_examples
assert "assistant_handoff" in anti_examples
def test_status_and_tools_catalog_exclude_natural_language_status_questions() -> None:
specs = {spec.name: spec for spec in build_slash_command_specs()}
status = specs["/status"]
assert "explicit /status command operation" in status.llm_description.lower()
assert "explicitly types /status" in " ".join(status.use_cases).lower()
assert "current session status" in " ".join(status.anti_examples).lower()
assert "assistant_handoff" in " ".join(status.anti_examples).lower()
tools = specs["/tools"]
assert "explicit /tools command operation" in tools.llm_description.lower()
assert "explicitly types /tools" in " ".join(tools.use_cases).lower()
assert "what tools or capabilities" in " ".join(tools.anti_examples).lower()
assert "assistant_handoff" in " ".join(tools.anti_examples).lower()
@@ -0,0 +1,118 @@
"""Tests for slash typo suggestion helpers."""
from __future__ import annotations
import io
import pytest
from rich.console import Console
from surfaces.interactive_shell.command_registry import SLASH_COMMANDS, dispatch_slash
from surfaces.interactive_shell.command_registry.suggestions import (
format_invalid_subcommand_message,
format_unknown_slash_message,
resolve_literal_slash_typo,
subcommand_hints,
)
from surfaces.interactive_shell.runtime.action_turn import run_action_tool_turn
from surfaces.interactive_shell.session import Session
def _capture() -> tuple[Console, io.StringIO]:
buf = io.StringIO()
return Console(file=buf, force_terminal=False, highlight=False), buf
def test_format_unknown_slash_message_without_suggestion_points_to_help() -> None:
message = format_unknown_slash_message(
"/made-up",
command_names=tuple(SLASH_COMMANDS),
)
assert message == "Unknown command: /made-up. Type /help for the full command list."
def test_format_unknown_slash_message_with_suggestion() -> None:
message = format_unknown_slash_message(
"/modle",
command_names=tuple(SLASH_COMMANDS),
)
assert "Did you mean /model?" in message
assert "Type /help" in message
def test_resolve_literal_slash_typo_unknown_root() -> None:
typo = resolve_literal_slash_typo("/invest", SLASH_COMMANDS)
assert typo is not None
assert typo.outcome == "unknown_command"
assert "Did you mean /investigate?" in typo.message
@pytest.mark.parametrize(
"command_line",
[
"/resume redis",
"/help model",
"/help /model",
"/integrations ls",
"/tools ls",
"/tools tool",
"/mcp ls",
],
)
def test_resolve_literal_slash_typo_allows_free_form_first_args(command_line: str) -> None:
assert resolve_literal_slash_typo(command_line, SLASH_COMMANDS) is None
def test_dispatch_invalid_subcommand_is_handled_by_command_handler(
monkeypatch: pytest.MonkeyPatch,
) -> None:
monkeypatch.setattr(
"surfaces.interactive_shell.command_registry.integrations.repl_data.load_verified_integrations",
lambda: [],
)
session = Session()
console, buf = _capture()
assert dispatch_slash("/integrations bogus", session, console) is True
assert "unknown subcommand" in buf.getvalue().lower()
assert resolve_literal_slash_typo("/integrations bogus", SLASH_COMMANDS) is None
def test_subcommand_hints_ignores_usage_placeholders() -> None:
resume = SLASH_COMMANDS["/resume"]
assert subcommand_hints(resume) == ()
help_cmd = SLASH_COMMANDS["/help"]
assert subcommand_hints(help_cmd) == ()
def test_format_invalid_subcommand_message_lists_known_subcommands() -> None:
cmd = SLASH_COMMANDS["/integrations"]
message = format_invalid_subcommand_message(cmd, ["bogus"])
assert "Invalid subcommand: bogus" in message
assert "/integrations list" in message
def test_dispatch_unknown_command_records_full_response_and_outcome() -> None:
session = Session()
console, buf = _capture()
assert dispatch_slash("/modle", session, console) is True
output = buf.getvalue()
assert "Unknown command" in output
latest = session.history[-1]
assert latest["ok"] is False
assert latest["slash_outcome"] == "unknown_command"
assert latest["response_text"] == latest["response_text"].strip()
assert "Type /help" in latest["response_text"]
def test_run_action_tool_turn_handles_unknown_literal_slash_before_tool_validation() -> None:
session = Session()
console, buf = _capture()
result = run_action_tool_turn("/invest", session, console)
assert result.handled is True
assert result.response_text
assert "Unknown command" in result.response_text
assert "Unknown command" in buf.getvalue()
latest = session.history[-1]
assert latest["type"] == "slash"
assert latest["slash_outcome"] == "unknown_command"
assert latest["response_text"] == result.response_text