fix: thread-local CRDT and content store for test isolation
Tests shared a global CRDT singleton and content store HashMap, causing flaky failures when parallel tests wrote items that polluted each other's assertions. 3-5 random test failures per run. Both CRDT_STATE and CONTENT_STORE now use thread_local! in test mode so each test thread gets its own isolated instance. Production code is unchanged — it still uses the global OnceLock singletons. Also fixed 3 tests (create_story_writes_correct_content, next_item_number_increments_from_existing_bugs, next_item_number_scans_archived_too) that relied on leaked state from other tests — they now write to the content store explicitly. Result: 1902 passed, 0 failed across 5 consecutive runs. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -315,10 +315,13 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn create_story_writes_correct_content() {
|
||||
crate::db::ensure_content_store();
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let backlog = tmp.path().join(".huskies/work/1_backlog");
|
||||
fs::create_dir_all(&backlog).unwrap();
|
||||
fs::write(backlog.join("36_story_existing.md"), "").unwrap();
|
||||
// Also write to content store so next_item_number sees it.
|
||||
crate::db::write_item_with_content("36_story_existing", "1_backlog", "---\nname: Existing\n---\n");
|
||||
|
||||
let number = super::super::next_item_number(tmp.path()).unwrap();
|
||||
// The number must be >= 37 (at least higher than the existing "36_story_existing.md"),
|
||||
|
||||
Reference in New Issue
Block a user