Archived
fix: wait for git file suggestion probes before fallback
This commit is contained in:
@@ -76,6 +76,37 @@ describe("file suggestions", () => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("waits for both git probes before falling back in all-file scope", async () => {
|
||||||
|
let releaseUntracked: (() => void) | undefined;
|
||||||
|
let resolved = false;
|
||||||
|
const deps: FileSuggestionDependencies = {
|
||||||
|
execFile: (file, args) => {
|
||||||
|
if (file === "git" && args.join(" ") === "ls-files -z") return Promise.reject(new Error("not a git repository"));
|
||||||
|
if (file === "git" && args.join(" ") === "ls-files --others --exclude-standard -z") {
|
||||||
|
return new Promise<{ stdout: string }>((resolve) => {
|
||||||
|
releaseUntracked = () => {
|
||||||
|
resolve({ stdout: "" });
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (file === "rg") return Promise.resolve({ stdout: "sdk.md\n" });
|
||||||
|
return Promise.reject(new Error(`unexpected command: ${file} ${args.join(" ")}`));
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const suggestions = listFileSuggestions("/repo", "sdk", { scope: "all" }, deps).then((value) => {
|
||||||
|
resolved = true;
|
||||||
|
return value;
|
||||||
|
});
|
||||||
|
await Promise.resolve();
|
||||||
|
|
||||||
|
expect(resolved).toBe(false);
|
||||||
|
expect(releaseUntracked).toBeDefined();
|
||||||
|
|
||||||
|
releaseUntracked?.();
|
||||||
|
await expect(suggestions).resolves.toEqual([{ path: "sdk.md", kind: "other" }]);
|
||||||
|
});
|
||||||
|
|
||||||
it("keeps git untracked files in all-file scope when the broad scan misses them", async () => {
|
it("keeps git untracked files in all-file scope when the broad scan misses them", async () => {
|
||||||
const deps: FileSuggestionDependencies = {
|
const deps: FileSuggestionDependencies = {
|
||||||
execFile: (file, args) => {
|
execFile: (file, args) => {
|
||||||
|
|||||||
@@ -253,13 +253,16 @@ async function listTrackedFiles(cwd: string, exec: CommandRunner): Promise<Clien
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function listGitFiles(cwd: string, exec: CommandRunner): Promise<ClientFileSuggestion[]> {
|
async function listGitFiles(cwd: string, exec: CommandRunner): Promise<ClientFileSuggestion[]> {
|
||||||
const [tracked, untracked] = await Promise.all([
|
const [trackedResult, untrackedResult] = await Promise.allSettled([
|
||||||
git(cwd, ["ls-files", "-z"], exec),
|
git(cwd, ["ls-files", "-z"], exec),
|
||||||
git(cwd, ["ls-files", "--others", "--exclude-standard", "-z"], exec),
|
git(cwd, ["ls-files", "--others", "--exclude-standard", "-z"], exec),
|
||||||
]);
|
] as const);
|
||||||
|
if (trackedResult.status === "rejected") throw trackedResult.reason;
|
||||||
|
if (untrackedResult.status === "rejected") throw untrackedResult.reason;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
...withDirectories(nulRecords(tracked), "tracked"),
|
...withDirectories(nulRecords(trackedResult.value), "tracked"),
|
||||||
...withDirectories(nulRecords(untracked), "untracked"),
|
...withDirectories(nulRecords(untrackedResult.value), "untracked"),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user