✅ Gremlins MVP: unit and CLI tests with a fake claude
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
||||
|
||||
from grm import launch # noqa: E402
|
||||
|
||||
RUN = {"argv": ["/x/claude", "-p", "--model", "claude-opus-5-5[1m]", "--tools", "Bash,Read"]}
|
||||
|
||||
|
||||
class ArgvTest(unittest.TestCase):
|
||||
def test_fork_argv_extends_stored_argv(self):
|
||||
"""B2: the stored argv byte for byte, then --resume <base> --fork-session."""
|
||||
a = launch.fork_argv(RUN, "base-sid", "new-sid")
|
||||
n = len(RUN["argv"])
|
||||
self.assertEqual(a[:n], RUN["argv"])
|
||||
self.assertEqual(a[n:n + 3], ["--resume", "base-sid", "--fork-session"])
|
||||
self.assertIn("new-sid", a[n + 3:])
|
||||
self.assertEqual(len(RUN["argv"]), n) # the stored list is not mutated
|
||||
|
||||
def test_resume_argv_has_no_fork(self):
|
||||
"""B7: resume the base without forking."""
|
||||
a = launch.resume_argv(RUN, "base-sid")
|
||||
self.assertEqual(a[:len(RUN["argv"])], RUN["argv"])
|
||||
self.assertEqual(a[len(RUN["argv"]):], ["--resume", "base-sid"])
|
||||
self.assertNotIn("--fork-session", a)
|
||||
|
||||
|
||||
class ScrubTest(unittest.TestCase):
|
||||
def test_scrub_drops_pins_and_cleans_path(self):
|
||||
"""B8: SCRUB_DROP and UV_* dropped, pinned vars set, venv PATH entries removed."""
|
||||
venv = os.path.abspath(os.path.join(os.sep, "tmp", "venv"))
|
||||
keep = os.path.abspath(os.path.join(os.sep, "usr", "bin"))
|
||||
environ = {"PATH": os.pathsep.join([os.path.join(venv, "bin"), keep]),
|
||||
"VIRTUAL_ENV": venv, "UV_CACHE_DIR": "c", "ANTHROPIC_API_KEY": "k",
|
||||
"CLAUDE_CODE_SESSION_ID": "s", "DISABLE_AUTOUPDATER": "0", "OTHER": "o"}
|
||||
env = launch.scrubbed_env("/bin/claude", environ)
|
||||
for k in launch.SCRUB_DROP:
|
||||
self.assertNotIn(k, env)
|
||||
self.assertNotIn("UV_CACHE_DIR", env)
|
||||
for k, v in launch.SCRUB_PINNED.items():
|
||||
self.assertEqual(env[k], v)
|
||||
self.assertEqual(env[launch.SCRUB_PINNED_BINARY], "/bin/claude")
|
||||
self.assertEqual(env["PATH"], keep)
|
||||
self.assertEqual(env["OTHER"], "o")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user