Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix flaky grok signature-sniff tests racing async scratch-dir cleanup

[._.]/ Adam Eivy5572925cca94
diff --git a/server/services/imageGen/grok.test.js b/server/services/imageGen/grok.test.js
index fbfe2648ff..2a1e7f2180 100644
--- a/server/services/imageGen/grok.test.js
+++ b/server/services/imageGen/grok.test.js
@@ -253,9 +253,16 @@ describe('grok provider — directed-path harvest', () => {
}
expect(failedListener).toHaveBeenCalledTimes(1);
expect(failedListener.mock.calls[0][0].error).toMatch(/non-image file/);
- // The rejected junk never reaches the gallery, and the scratch dir is gone.
+ // The rejected junk never reaches the gallery. Scratch-dir removal is
+ // fire-and-forget alongside the 'failed' event (not awaited before it),
+ // so give it a moment to land on disk rather than racing it.
expect(existsSync(join(FAKE_IMAGES_DIR, job.filename))).toBe(false);
- expect(existsSync(join(tmpdir(), `portos-grok-${job.jobId}`))).toBe(false);
+ const scratchDir = join(tmpdir(), `portos-grok-${job.jobId}`);
+ const scratchDeadline = Date.now() + 3000;
+ while (Date.now() < scratchDeadline && existsSync(scratchDir)) {
+ await new Promise((r) => setTimeout(r, 50));
+ }
+ expect(existsSync(scratchDir)).toBe(false);
}, 12000);
it('fails with the stdout narration when grok exits 0 but wrote no file', async () => {
diff --git a/server/services/videoGen/grok.test.js b/server/services/videoGen/grok.test.js
index aa0144d6be..83ba92dc54 100644
--- a/server/services/videoGen/grok.test.js
+++ b/server/services/videoGen/grok.test.js
@@ -195,7 +195,15 @@ describe('videoGen/grok — harvest and finalize', () => {
expect(failed).toHaveBeenCalledTimes(1);
expect(failed.mock.calls[0][0].error).toMatch(/non-MP4 file/);
expect(existsSync(join(FAKE_VIDEOS_DIR, job.filename))).toBe(false);
- expect(existsSync(scratchDirFor(job.jobId))).toBe(false);
+ // Scratch-dir removal is fire-and-forget alongside the 'failed' event
+ // (not awaited before it), so give it a moment to land on disk rather
+ // than racing it.
+ const scratchDir = scratchDirFor(job.jobId);
+ const scratchDeadline = Date.now() + 3000;
+ while (Date.now() < scratchDeadline && existsSync(scratchDir)) {
+ await new Promise((r) => setTimeout(r, 50));
+ }
+ expect(existsSync(scratchDir)).toBe(false);
}, 16000);
it('fails with the narration tail when grok exits 0 with no file', async () => {