diff --git a/tests/test_core.py b/tests/test_core.py index 86f7c55..2ec3f4c 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -43,10 +43,16 @@ def tree(): return out.hexdigest() +REAL_HOME = os.path.expanduser("~") + + class Core(unittest.TestCase): def setUp(self): before = tree() self.addCleanup(lambda: self.assertEqual(tree(), before, "a test wrote into the product tree")) + book = os.path.join(REAL_HOME, ".claude", "CLAUDE.md") + mine = open(book).read() if os.path.exists(book) else None + self.addCleanup(lambda: self.assertEqual(open(book).read() if os.path.exists(book) else None, mine, "a test wrote the person's own rules file")) self.tmp = tempfile.mkdtemp(prefix="sisi-test-") self.addCleanup(shutil.rmtree, self.tmp, True) self.data = os.path.join(self.tmp, "data") @@ -1303,8 +1309,10 @@ class Core(unittest.TestCase): out, here = io.StringIO(), os.getcwd() os.chdir(self.tmp) try: + # the temp home too: a rulebook rebuild re-points every agent tool's rules file under the home folder with mock.patch.object(store, "DATA", self.data), mock.patch.object(store, "STATE", os.path.join(self.tmp, "state")), \ - mock.patch.object(store, "LIB", os.path.join(self.tmp, "lib")), contextlib.redirect_stdout(out): + mock.patch.object(store, "LIB", os.path.join(self.tmp, "lib")), mock.patch.object(store, "HOME", self.tmp), \ + mock.patch.dict(os.environ, {k: self.env[k] for k in ("HOME", "CLAUDE_CONFIG_DIR")}), contextlib.redirect_stdout(out): return fn(*args), out.getvalue() finally: os.chdir(here)