Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/ci/ci-gate-filters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ harness:

memory_plugin:
- ".github/workflows/memory-plugin-verification.yml"
- "platform/node-tools/**"
- "src/clawops/assets/platform/node-tools/**"
- "src/clawops/strongclaw_node_tools.py"
- "platform/plugins/memory-lancedb-pro/**"
- "platform/plugins/strongclaw-hypermemory/**"
- "src/clawops/assets/platform/plugins/memory-lancedb-pro/**"
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/memory-plugin-verification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
cache: npm
cache-dependency-path: platform/plugins/memory-lancedb-pro/package-lock.json
cache-dependency-path: |
platform/node-tools/package-lock.json
platform/plugins/memory-lancedb-pro/package-lock.json
- uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6
with:
python-version: "3.12"
Expand All @@ -51,7 +53,7 @@ jobs:
- run: uv sync --locked
- run: PYTHONPATH=src uv run python -m clawops config --asset-root . memory --set-profile memory-lancedb-pro --output "$RUNNER_TEMP/openclaw.json"
- run: python3 ./tests/scripts/memory_plugin_verification.py run-clawops-memory-migration --repo-root . --runner-temp "$RUNNER_TEMP"
- run: python3 ./tests/scripts/memory_plugin_verification.py run-vendored-host-checks --repo-root . --package-spec "openclaw@2026.3.13"
- run: python3 ./tests/scripts/memory_plugin_verification.py run-vendored-host-checks --repo-root .
verify-hypermemory-qdrant:
name: Run Hypermemory Qdrant Checks
runs-on: ubuntu-latest
Expand Down
7 changes: 1 addition & 6 deletions tests/scripts/memory_plugin_verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

from tests.utils.helpers._ci_workflows.common import CiWorkflowError # noqa: E402
from tests.utils.helpers._ci_workflows.memory_plugin import ( # noqa: E402
DEFAULT_OPENCLAW_PACKAGE_SPEC,
run_clawops_memory_migration,
run_vendored_host_checks,
wait_for_qdrant,
Expand All @@ -32,7 +31,6 @@ def _parse_args(argv: list[str] | None = None) -> argparse.Namespace:
help="Run vendored memory plugin host-functional checks.",
)
vendored_parser.add_argument("--repo-root", type=Path, default=REPO_ROOT)
vendored_parser.add_argument("--package-spec", default=DEFAULT_OPENCLAW_PACKAGE_SPEC)

migration_parser = subparsers.add_parser(
"run-clawops-memory-migration",
Expand All @@ -54,10 +52,7 @@ def main(argv: list[str] | None = None) -> int:
args = _parse_args(argv)
try:
if args.command == "run-vendored-host-checks":
run_vendored_host_checks(
Path(args.repo_root).expanduser().resolve(),
package_spec=str(args.package_spec),
)
run_vendored_host_checks(Path(args.repo_root).expanduser().resolve())
return 0
if args.command == "run-clawops-memory-migration":
run_clawops_memory_migration(
Expand Down
39 changes: 39 additions & 0 deletions tests/suites/contracts/repo/test_node_tools_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

from clawops import platform_compat
from clawops.strongclaw_node_tools import NODE_TOOLS_ASSET_DIR, load_node_tools_bundle
from tests.utils.helpers.ci_node_installs import (
find_floating_node_commands,
find_floating_node_installs,
)
from tests.utils.helpers.node_tools import find_version_mentions
from tests.utils.helpers.repo import REPO_ROOT

Expand Down Expand Up @@ -88,3 +92,38 @@ def test_node_tools_bundle_ships_in_package_data() -> None:
package_data = pyproject["tool"]["setuptools"]["package-data"]["clawops.assets"]

assert "platform/node-tools/*" in package_data


@pytest.mark.parametrize(
("command", "floating"),
[
("npm install --prefix /tmp/x --no-fund openclaw@2026.3.13", True),
("npm --prefix /tmp/x i -g acpx", True),
("npm install --prefix <expr> --no-fund --no-audit <expr>", True),
("npx -y openclaw@2026.3.13 --version", True),
("npm exec --package=acpx@0.3.0 -- acpx --help", True),
("echo ready && npm add left-pad", True),
("npm ci --omit=dev --no-audit --no-fund", False),
("npm --prefix platform/plugins/strongclaw-hypermemory run test:openclaw-host", False),
("npm install --package-lock-only --ignore-scripts", False),
("npm run install-deps", False),
("npx tsc --noEmit", False),
("pnpm install openclaw", False),
],
)
def test_floating_node_command_detector(command: str, floating: bool) -> None:
"""The detector flags resolving installs and OpenClaw/ACPX npx runs, not locked commands."""
assert bool(find_floating_node_commands(command)) is floating


def test_ci_never_installs_node_packages_outside_a_lock() -> None:
"""CI installs OpenClaw/ACPX only via `npm ci` of a committed lock, never a floating install."""
findings = [
f"{finding.path}: {finding.command}" for finding in find_floating_node_installs(REPO_ROOT)
]

assert findings == [], (
"install from platform/node-tools with `npm ci` "
"(tests/utils/helpers/_ci_workflows/memory_plugin.install_locked_node_tools): "
+ ", ".join(findings)
)
13 changes: 13 additions & 0 deletions tests/suites/unit/ci/test_ci_gate_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@ def test_memory_plugin_package_change_routes_to_memory_compatibility_and_fresh_h
assert selection.docs_parity_required is False


@pytest.mark.parametrize(
"changed_path",
[
"platform/node-tools/package-lock.json",
"src/clawops/assets/platform/node-tools/package.json",
"src/clawops/strongclaw_node_tools.py",
],
)
def test_node_tools_change_routes_to_memory_plugin_lane(changed_path: str) -> None:
"""The memory-plugin lane installs OpenClaw from the node-tools lock, so bumps must run it."""
assert _select(changed_path).memory_plugin is True


def test_lockfile_change_routes_to_dependency_review_without_heavy_local_runtime() -> None:
selection = _select("uv.lock")

Expand Down
122 changes: 109 additions & 13 deletions tests/suites/unit/ci/test_memory_plugin_verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,58 @@

from __future__ import annotations

import shutil
from pathlib import Path
from typing import Any

import pytest

from clawops.strongclaw_node_tools import (
LOCK_FILE_NAME,
MANIFEST_FILE_NAME,
NODE_TOOLS_ASSET_DIR,
LocalPrefixWriter,
NodeToolsBundle,
NodeToolsError,
PrefixWriter,
load_node_tools_bundle,
)
from tests.plugins.infrastructure.context import TestContext
from tests.scripts import memory_plugin_verification as memory_plugin_script
from tests.utils.helpers import ci_workflows
from tests.utils.helpers._ci_workflows import memory_plugin as memory_plugin_helpers
from tests.utils.helpers._ci_workflows.common import CiWorkflowError
from tests.utils.helpers.repo import REPO_ROOT


def test_run_vendored_host_checks_installs_cli_and_clears_aws_env(
def _seed_node_tools_bundle(repo_root: Path) -> None:
"""Copy the committed node-tools manifest and lock into a scratch repo root."""
target_dir = repo_root / NODE_TOOLS_ASSET_DIR
target_dir.mkdir(parents=True)
for file_name in (MANIFEST_FILE_NAME, LOCK_FILE_NAME):
shutil.copyfile(REPO_ROOT / NODE_TOOLS_ASSET_DIR / file_name, target_dir / file_name)


def test_run_vendored_host_checks_installs_locked_cli_and_clears_aws_env(
test_context: TestContext,
tmp_path: Path,
) -> None:
"""Vendored host checks should prefix PATH and clear ambient AWS variables."""
"""Host checks install the committed lock, prefix PATH, and clear ambient AWS variables."""
repo_root = tmp_path / "repo"
plugin_dir = repo_root / "platform" / "plugins" / "memory-lancedb-pro"
plugin_dir.mkdir(parents=True)
_seed_node_tools_bundle(repo_root)
staged: list[tuple[NodeToolsBundle, Path, PrefixWriter]] = []
smoked: list[tuple[Path, NodeToolsBundle]] = []
seen_calls: list[tuple[list[str], Path | None, dict[str, str] | None]] = []

def fake_stage(bundle: NodeToolsBundle, target_dir: Path, writer: PrefixWriter) -> None:
assert target_dir.is_dir()
staged.append((bundle, target_dir, writer))

def fake_smoke(bin_dir: Path, bundle: NodeToolsBundle) -> None:
smoked.append((bin_dir, bundle))

def fake_run_checked(
command: list[str],
*,
Expand All @@ -33,24 +66,87 @@ def fake_run_checked(
seen_calls.append((command, cwd, env))
return None

test_context.patch.patch_object(memory_plugin_helpers, "stage_node_tools_tree", new=fake_stage)
test_context.patch.patch_object(memory_plugin_helpers, "smoke_test_node_tools", new=fake_smoke)
test_context.patch.patch_object(memory_plugin_helpers, "run_checked", new=fake_run_checked)
test_context.env.set("PATH", "/usr/bin")
test_context.env.set("AWS_PROFILE", "default")
test_context.env.set("AWS_REGION", "us-east-1")

ci_workflows.run_vendored_host_checks(repo_root)

install_command, install_cwd, install_env = seen_calls[0]
assert install_command[:4] == ["npm", "install", "--prefix", install_command[3]]
assert install_cwd == repo_root.resolve()
assert install_env is None

_, npm_ci_cwd, npm_ci_env = seen_calls[1]
assert npm_ci_cwd == plugin_dir.resolve()
assert npm_ci_env is not None
assert "AWS_PROFILE" not in npm_ci_env
assert "AWS_REGION" not in npm_ci_env
assert npm_ci_env["PATH"].startswith(str(Path(install_command[3]) / "node_modules" / ".bin"))
committed = load_node_tools_bundle(REPO_ROOT / NODE_TOOLS_ASSET_DIR)
[(bundle, tool_dir, writer)] = staged
assert bundle.digest == committed.digest
assert bundle.manifest_path == (repo_root / NODE_TOOLS_ASSET_DIR / MANIFEST_FILE_NAME).resolve()
assert isinstance(writer, LocalPrefixWriter)
bin_dir = tool_dir / "node_modules" / ".bin"
assert smoked == [(bin_dir, bundle)]
assert not tool_dir.exists()

assert [(command, cwd) for command, cwd, _ in seen_calls] == [
(["npm", "ci", "--no-fund", "--no-audit"], plugin_dir.resolve()),
(["npm", "run", "test:openclaw-host"], plugin_dir.resolve()),
]
for _, _, env in seen_calls:
assert env is not None
assert "AWS_PROFILE" not in env
assert "AWS_REGION" not in env
assert env["PATH"] == f"{bin_dir}:/usr/bin"


def test_run_vendored_host_checks_reports_locked_install_failure(
test_context: TestContext,
tmp_path: Path,
) -> None:
"""A failed locked install surfaces as a CI error and skips the plugin checks."""
repo_root = tmp_path / "repo"
_seed_node_tools_bundle(repo_root)
tool_dirs: list[Path] = []
seen_commands: list[list[str]] = []

def failing_stage(bundle: NodeToolsBundle, target_dir: Path, writer: PrefixWriter) -> None:
del bundle, writer
tool_dirs.append(target_dir)
raise NodeToolsError("npm ci failed in /tmp (ETARGET)")

def fake_run_checked(command: list[str], **kwargs: Any) -> Any:
del kwargs
seen_commands.append(command)
return None

test_context.patch.patch_object(
memory_plugin_helpers, "stage_node_tools_tree", new=failing_stage
)
test_context.patch.patch_object(memory_plugin_helpers, "run_checked", new=fake_run_checked)

with pytest.raises(CiWorkflowError, match=r"locked node-tools install failed: .*ETARGET"):
ci_workflows.run_vendored_host_checks(repo_root)

assert seen_commands == []
assert [tool_dir.exists() for tool_dir in tool_dirs] == [False]


def test_main_dispatches_run_vendored_host_checks(
test_context: TestContext,
tmp_path: Path,
) -> None:
"""The CLI dispatches host checks with only the repo root; no package spec is accepted."""
seen_roots: list[Path] = []
test_context.patch.patch_object(
memory_plugin_script, "run_vendored_host_checks", new=seen_roots.append
)

exit_code = memory_plugin_script.main(
["run-vendored-host-checks", "--repo-root", str(tmp_path / "repo")]
)

assert exit_code == 0
assert seen_roots == [(tmp_path / "repo").resolve()]
with pytest.raises(SystemExit):
memory_plugin_script.main(
["run-vendored-host-checks", "--package-spec", "openclaw@2026.3.13"]
)


def test_wait_for_qdrant_retries_until_ready(test_context: TestContext) -> None:
Expand Down
43 changes: 23 additions & 20 deletions tests/utils/helpers/_ci_workflows/memory_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@
import urllib.request
from pathlib import Path

from clawops.platform_compat import DEFAULT_OPENCLAW_VERSION
from clawops.strongclaw_node_tools import (
LocalPrefixWriter,
NodeToolsError,
load_node_tools_bundle,
resolve_node_tools_dir,
smoke_test_node_tools,
stage_node_tools_tree,
)
from tests.utils.helpers._ci_workflows.common import CiWorkflowError, run_checked

DEFAULT_OPENCLAW_PACKAGE_SPEC = f"openclaw@{DEFAULT_OPENCLAW_VERSION}"
AWS_CREDENTIAL_ENV_VARS = (
"AWS_PROFILE",
"AWS_ACCESS_KEY_ID",
Expand All @@ -24,29 +30,26 @@
)


def run_vendored_host_checks(
repo_root: Path,
*,
package_spec: str = DEFAULT_OPENCLAW_PACKAGE_SPEC,
) -> None:
def install_locked_node_tools(repo_root: Path, tool_dir: Path) -> Path:
"""Install the committed OpenClaw/ACPX lock into *tool_dir* and return its bin directory."""
try:
bundle = load_node_tools_bundle(resolve_node_tools_dir(repo_root))
stage_node_tools_tree(bundle, tool_dir, LocalPrefixWriter())
bin_dir = tool_dir / "node_modules" / ".bin"
smoke_test_node_tools(bin_dir, bundle)
except NodeToolsError as exc:
raise CiWorkflowError(f"locked node-tools install failed: {exc}") from exc
return bin_dir


def run_vendored_host_checks(repo_root: Path) -> None:
"""Run the vendored memory plugin host-functional verification."""
resolved_repo_root = repo_root.expanduser().resolve()
tool_dir = Path(tempfile.mkdtemp(prefix="strongclaw-openclaw-cli."))
try:
run_checked(
[
"npm",
"install",
"--prefix",
str(tool_dir),
"--no-fund",
"--no-audit",
package_spec,
],
cwd=resolved_repo_root,
)
bin_dir = install_locked_node_tools(resolved_repo_root, tool_dir)
env = dict(os.environ)
env["PATH"] = f"{tool_dir / 'node_modules' / '.bin'}:{env.get('PATH', '')}"
env["PATH"] = f"{bin_dir}:{env.get('PATH', '')}"
for key in AWS_CREDENTIAL_ENV_VARS:
env.pop(key, None)
plugin_dir = resolved_repo_root / "platform" / "plugins" / "memory-lancedb-pro"
Expand Down
Loading
Loading