opencode-config/tests/test_dockerfile.py
Sergey 9d654a2201
chore(memory): remove plugin + setup-memory.sh + Rust artifacts (#103)
* chore(memory): remove plugin block from opencode.json

* chore(memory): remove setup-memory.sh and memory-setup.ts

* chore(memory): remove opencode-memory from Dockerfile

* docs(memory): update AGENTS.md and SKILL.md for new tools

* test(memory): drop tests for removed setup-memory.sh and memory-setup.ts

* docs(handoff): add handoff and ADR-045 for plugin/rust removal

* docs(handoff): set PR number

* docs(project-map): update after plugin/rust removal

---------

Co-authored-by: opencode-agent <agent@opencode.local>
2026-07-27 01:47:26 +03:00

118 lines
4.5 KiB
Python

"""Tests for Dockerfile npm install line.
Covers issue #98 acceptance criteria:
- ``Dockerfile`` no longer installs ``@mathew-cf/opencode-memory`` — the
plugin was replaced by 5 TS tools (``.opencode/tools/memory-*.ts``) that
call ``python3 -m src.memory`` directly (PR #101). The npm package is
dead weight in the image and is removed from the global install step.
- ``opencode-ai`` and ``repomix`` remain (regression guard — must not be
dropped when editing the install line).
Checks are raw-text grep assertions (no Docker build needed), mirroring the
belt-and-suspenders style of ``test_docker_compose.py``.
"""
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parent.parent
DOCKERFILE = REPO_ROOT / "Dockerfile"
REMOVED_PLUGIN = "@mathew-cf/opencode-memory"
KEPT_PACKAGES = ("opencode-ai", "repomix")
OPENCODE_AI = "opencode-ai"
def _dockerfile_text() -> str:
"""Read Dockerfile text (asserts the file exists)."""
assert DOCKERFILE.exists(), f"Dockerfile missing: {DOCKERFILE}"
return DOCKERFILE.read_text()
def _npm_install_lines(text: str) -> list[str]:
"""Return every ``npm install -g ...`` line from the Dockerfile."""
return [line for line in text.splitlines() if "npm install -g" in line]
# ── file exists ─────────────────────────────────────────────────────────────
def test_dockerfile_exists():
"""Dockerfile exists at repo root."""
assert DOCKERFILE.exists(), f"Dockerfile missing: {DOCKERFILE}"
# ── @mathew-cf/opencode-memory removed (issue #98 — plugin replaced by TS tools)
def test_memory_plugin_removed_from_npm_install():
"""Dockerfile does NOT install ``@mathew-cf/opencode-memory`` via ``npm install -g``.
The plugin was replaced by 5 TS tools (PR #101) that call
``python3 -m src.memory`` directly — the npm package is no longer needed
inside the container and is removed from the global install step.
"""
lines = _npm_install_lines(_dockerfile_text())
assert lines, "no `npm install -g` line found in Dockerfile"
assert not any(REMOVED_PLUGIN in line for line in lines), (
f"Dockerfile must NOT install {REMOVED_PLUGIN!r} via `npm install -g` — "
"plugin replaced by TS tools (PR #101, cleanup issue #98)"
)
def test_memory_plugin_removed_from_npm_install_raw():
"""Raw text check: the Dockerfile does NOT contain ``@mathew-cf/opencode-memory``.
Belt-and-suspenders alongside the parsed check — catches any lingering
reference to the removed plugin (multi-line install, comment, etc.).
"""
assert REMOVED_PLUGIN not in _dockerfile_text(), (
f"Dockerfile must NOT contain {REMOVED_PLUGIN!r} — plugin replaced by "
"TS tools (PR #101, cleanup issue #98)"
)
# ── opencode-ai still present (regression — must not drop the main package) ──
def test_opencode_ai_present():
"""Dockerfile still installs ``opencode-ai`` (regression guard).
Removing the memory plugin from the npm install line must not
accidentally drop the primary ``opencode-ai`` package.
"""
lines = _npm_install_lines(_dockerfile_text())
assert lines, "no `npm install -g` line found in Dockerfile"
assert any(OPENCODE_AI in line for line in lines), (
f"Dockerfile must still install {OPENCODE_AI!r} — dropping it breaks "
"the container entrypoint"
)
def test_opencode_ai_present_raw():
"""Raw text check: the Dockerfile contains ``opencode-ai``."""
assert OPENCODE_AI in _dockerfile_text(), f"Dockerfile must still contain {OPENCODE_AI!r}"
# ── single npm install line holds the kept packages ──────────────────────────
def test_single_npm_install_line_has_kept_packages():
"""One ``npm install -g`` line installs all kept packages.
Guards against splitting the install across multiple RUN layers (which
would waste image layers and obscure which package is missing).
"""
lines = _npm_install_lines(_dockerfile_text())
install_lines = [line for line in lines if OPENCODE_AI in line]
assert install_lines, f"no `npm install -g` line with {OPENCODE_AI!r}"
main_line = install_lines[0]
for pkg in KEPT_PACKAGES:
assert pkg in main_line, (
f"package {pkg!r} missing from the opencode-ai npm install line: {main_line!r}"
)
if __name__ == "__main__":
import pytest
pytest.main([__file__, "-v"])