Tests: in-process helper uses the temp home; guard fails any test that writes the person's own rules file
The new organize test rebuilt the rulebook in-process with the real home folder and re-pointed ~/.claude/CLAUDE.md at a deleted temp store. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
4c32469a58
commit
6477f22933
1 file changed
+9
-1
+9
-1
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user