_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
+4
-1
@@ -210,8 +210,11 @@ def scope_lines(scope, cwd=None, migrate=True):
|
||||
if migrate:
|
||||
return _migrate(cwd)[0]
|
||||
dest, old = path(PROJECT, cwd), _legacy(cwd)
|
||||
# The store copy first, the project file second: `_move` writes the project file before it removes the store
|
||||
# copy, so a no-lock reader either reads the copy before it goes or knows the project file is already complete.
|
||||
ls = lines(old)
|
||||
raw = store.regular(dest, True)[1] if dest and not os.path.islink(os.path.dirname(dest)) else None
|
||||
return list(dict.fromkeys((_parse(raw.decode("utf-8", "replace")) if raw is not None else []) + lines(old)))
|
||||
return list(dict.fromkeys(ls + ((_parse(raw.decode("utf-8", "replace"))) if raw is not None else [])))
|
||||
|
||||
|
||||
_in_store = lambda p: p.startswith(os.path.join(store.DATA, ""))
|
||||
|
||||
@@ -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