Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

test(fs): wait for fallback IO after the mocked Git deadline

new-Beginnerbe6c23393f0a
diff --git a/apps/desktop/test/fs-index-git-deadline.test.mjs b/apps/desktop/test/fs-index-git-deadline.test.mjs
index cf6b080c0..8498b127d 100644
--- a/apps/desktop/test/fs-index-git-deadline.test.mjs
+++ b/apps/desktop/test/fs-index-git-deadline.test.mjs
@@ -8,7 +8,7 @@ import { fileURLToPath } from "node:url";
import test from "node:test";
import { buildSync } from "esbuild";
-test("workspace file index and search fall back at the Git deadline without a close event", async t => {
+test("workspace file index and search fall back at the Git deadline without a close event", { timeout: 5_000 }, async t => {
const root = await mkdtemp(join(tmpdir(), "pi-index-deadline-"));
await writeFile(join(root, "note.txt"), "fixture");
const require = createRequire(import.meta.url);
@@ -33,15 +33,16 @@ test("workspace file index and search fall back at the Git deadline without a cl
const module = { exports: {} };
new Function("require", "module", "exports", result.outputFiles[0].text)(require, module, module.exports);
t.mock.timers.enable({ apis: ["setTimeout"] });
- let listing;
- const pending = module.exports.getWorkspaceFileIndex(root).then(value => { listing = value; });
+ const pending = module.exports.getWorkspaceFileIndex(root);
await ready;
- t.mock.timers.tick(4000);
- for (let tick = 0; tick < 20 && !listing; tick++) await new Promise(resolve => setImmediate(resolve));
+ t.mock.timers.tick(3_999);
+ assert.equal(killed, false, "Git must remain running before its deadline");
+ t.mock.timers.tick(1);
assert.equal(killed, true);
+ // The deadline starts fallback; real disk IO need not finish in a fixed number of event-loop turns.
+ const listing = await pending;
assert.ok(listing, "the file index must settle without Git close");
assert.deepEqual(listing.entries, [{ path: "note.txt", kind: "file" }]);
- await pending;
assert.deepEqual((await module.exports.searchWorkspaceFiles(root, "note")).entries, listing.entries);
} finally {
t.mock.timers.reset();