_move and _apply write the project file first and remove or commit the store copy second, so a reader that never waits must read the store copy first: it then either sees the lines there or the project file is already complete. Reading the project file first could miss both (fault 6). Adds a deterministic test that runs a whole move between the two reads. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cb442e7d6f
commit
f7f37dffe3
2 files changed
+24
-1
No files matched your search
@@ -922,6 +922,26 @@ class Core(unittest.TestCase):
|
||||
self.assertEqual(len([l for l in got if learned in l]), 1, (n, rep, got))
|
||||
self.assertFalse(os.path.exists(old), (n, rep))
|
||||
|
||||
def test_a_rules_read_between_a_moves_two_writes_still_sees_the_old_rules(self):
|
||||
"""A session start that does not wait reads while another start moves the old rules into `.sisi/rules.md`;
|
||||
the reader sits between its two reads while the move commits, so it must still see every line."""
|
||||
from sisi import rules, store
|
||||
p = self.project("mid-move")
|
||||
row = "- Old store rule read while the move commits [owner 2026-11-20]"
|
||||
old, dest = self.legacy(p, row + "\n"), os.path.join(p, ".sisi", "rules.md")
|
||||
fired, orig = [], store.regular
|
||||
def regular(path, load=False):
|
||||
out = orig(path, load)
|
||||
if load and os.path.realpath(path) == os.path.realpath(dest) and not fired:
|
||||
fired.append(1) # the reader has read one copy: the whole move commits before it reads the other
|
||||
self.assertEqual(rules._move(dest, old), "")
|
||||
return out
|
||||
with mock.patch.object(store, "regular", regular):
|
||||
got = self.in_process(lambda: rules.scope_lines(rules.PROJECT, p, migrate=False))[0]
|
||||
self.assertIn(row, got)
|
||||
self.assertIn(row, self.read(dest)) # the injected move really did complete
|
||||
self.assertFalse(os.path.exists(old))
|
||||
|
||||
def test_old_rules_land_in_the_main_checkout_from_a_linked_worktree(self):
|
||||
tracked = "- Checked in rule from the main branch [owner 2026-11-20]\n"
|
||||
self.mkdir(self.proj, ".sisi")
|
||||
|
||||
Reference in new issue
Block a user