|
1 | 1 | // Run only in a subprocess (see startup-scan-failure.test.ts): the parent gives it a PATH without |
2 | 2 | // ripgrep and a proxy that refuses connections, so ripgrep can be neither found nor downloaded. |
| 3 | +// The test preload gives this process its own data directory, so no cached ripgrep is found there. |
3 | 4 | import { expect, test } from "bun:test" |
| 5 | +import fs from "node:fs/promises" |
| 6 | +import path from "node:path" |
4 | 7 |
|
5 | | -test("instance startup survives a file scan that cannot get ripgrep", async () => { |
| 8 | +test("a startup scan that cannot get ripgrep is handled, and a later search recovers", async () => { |
6 | 9 | const { tmpdir } = await import("../../fixture/fixture") |
7 | 10 | const { bootstrap } = await import("../../../src/cli/bootstrap") |
8 | 11 | const { Ripgrep } = await import("../../../src/file/ripgrep") |
| 12 | + const { File } = await import("../../../src/file") |
9 | 13 | await using dir = await tmpdir({ git: true }) |
10 | | - let started = false |
| 14 | + await using fake = await tmpdir() |
| 15 | + let found: string[] = [] |
11 | 16 | await bootstrap(dir.path, async () => { |
12 | | - started = true |
| 17 | + // The scan bootstrap started shares this lookup, so it has failed too by the time this settles. |
| 18 | + // One more macrotask lets an unhandled rejection from that scan surface while the test runs. |
| 19 | + expect(await Ripgrep.filepath().then(() => "found", () => "failed")).toBe("failed") |
| 20 | + await new Promise((resolve) => setTimeout(resolve, 0)) |
| 21 | + |
| 22 | + // While ripgrep is still unavailable a search fails, and that failure must not stick. |
| 23 | + expect(await File.search({ query: "recovered" }).then(() => "ok", () => "failed")).toBe("failed") |
| 24 | + |
| 25 | + // Ripgrep becomes available: a stand-in that lists one file. |
| 26 | + await fs.writeFile(path.join(fake.path, "rg"), "#!/bin/sh\necho recovered.txt\n", { mode: 0o755 }) |
| 27 | + process.env.PATH = `${fake.path}${path.delimiter}${process.env.PATH}` |
| 28 | + found = await File.search({ query: "recovered", type: "file" }) |
13 | 29 | }) |
14 | | - expect(started).toBe(true) |
15 | | - // The scan bootstrap started shares this lookup, so it has failed too by the time this settles. |
16 | | - // One more macrotask lets an unhandled rejection from that scan surface before the test ends. |
17 | | - expect(await Ripgrep.filepath().then(() => "found", () => "failed")).toBe("failed") |
18 | | - await new Promise((resolve) => setTimeout(resolve, 0)) |
| 30 | + expect(found).toContain("recovered.txt") |
19 | 31 | }) |
0 commit comments