code: await observed VM state after rename in Wave2 test (#tests)
- Commit
62495a4f0c0f80bf91a4fca3fc125d95a5badafc- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-16 22:41 UTC (19 days ago)
- Parents
b189a33
Wave2VmActionsTest.createRenameDeleteViaActionsAndSettings failed
with "timeout: deleted" in full :code:testDevUnitTest runs while
passing in isolation (reproduced on unmodified origin/main: 628
tests, this the only failure).
Root cause is test-side, not a product race and not shared-state
pollution (each test uses a unique temp project and a fresh
ViewModel). renameNodeImpl renames on Dispatchers.IO and only then
updates nodes in its viewModelScope (Main) continuation. The test
awaited only the disk side effect, File(dir, "renamed.kt").exists(),
which becomes true before that Main continuation runs. It then read
v.nodes.indexOfFirst { renamed.kt } synchronously; under full-suite
load that index is still -1, deleteNode(-1) hits the getOrNull
guard in deleteNodeImpl and silently no-ops, so the file is never
deleted and await("deleted") times out. Product rename/delete are
themselves correct: EditorFileTreeOpsBehaviourTest exercises the
same impls and passes in the same suite, awaiting combined
disk+VM state.
Fix, following the await-observed-state pattern used by the other
VM tests: await "renamed" on the file existing AND nodes showing
renamed.kt, assert the resolved index is >= 0, and await "deleted"
on the file being gone AND nodes no longer showing renamed.kt.
No assertions weakened, no retries, no @Ignore; the added index
assertion makes any recurrence fail at the actual cause.
Verified: single-method and full Wave2VmActionsTest class green;
full :code:testDevUnitTest green twice (628 tests, 0 failures),
the second run with --no-build-cache after cleanTest.Diff
code/src/test/java/com/vayunmathur/code/util/Wave2VmActionsTest.kt
diff --git a/code/src/test/java/com/vayunmathur/code/util/Wave2VmActionsTest.kt b/code/src/test/java/com/vayunmathur/code/util/Wave2VmActionsTest.ktindex 013b9be695..d3271ab705 100644--- a/code/src/test/java/com/vayunmathur/code/util/Wave2VmActionsTest.kt+++ b/code/src/test/java/com/vayunmathur/code/util/Wave2VmActionsTest.kt@@ -168,10 +168,15 @@ class Wave2VmActionsTest { val idx = v.nodes.indexOfFirst { it.entry.name == "new.kt" } assertTrue(idx >= 0) v.actions.renameNode(idx, "renamed.kt")- await("renamed") { File(dir, "renamed.kt").exists() }+ // Await the VM's observed state, not just the disk: the rename lands on disk+ // (Dispatchers.IO) before the viewModelScope continuation updates nodes on+ // Main, so a disk-only wait can return while nodes still says "new.kt".+ // The index read below would then be -1 and deleteNode(-1) a silent no-op.+ await("renamed") { File(dir, "renamed.kt").exists() && v.nodes.any { it.entry.name == "renamed.kt" } } val ridx = v.nodes.indexOfFirst { it.entry.name == "renamed.kt" }+ assertTrue(ridx >= 0) v.actions.deleteNode(ridx)- await("deleted") { !File(dir, "renamed.kt").exists() }+ await("deleted") { !File(dir, "renamed.kt").exists() && v.nodes.none { it.entry.name == "renamed.kt" } } // Settings actions. v.actions.setFontSize(20); assertEquals(20, v.fontSize) v.actions.setTabWidth(2); assertEquals(2, v.tabWidth)