import { chmodSync, mkdirSync, mkdtempSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; import { describe, expect, test } from "bun:test"; import { scanPathEntries } from "./command_index"; describe("command index", () => { test("keeps the first PATH match for duplicate names", () => { const root = tempDir("duplicates"); const first = join(root, "first"); const second = join(root, "second"); mkdirSync(first, { recursive: true }); mkdirSync(second, { recursive: true }); createExecutable(join(first, "demo")); createExecutable(join(second, "demo")); createExecutable(join(second, "later")); expect(scanPathEntries([first, second]).names).toEqual(["demo", "later"]); }); }); function createExecutable(path: string): void { writeFileSync(path, "#!/bin/sh\nexit 0\n"); chmodSync(path, 0o755); } function tempDir(label: string): string { return mkdtempSync(join(tmpdir(), `tool-query-${label}-`)); }