Files
oh-my-pi/packages/coding-agent/test/autocomplete-max-visible.test.ts
T
oldschoola 14252e71cb fix: Windows test failures — path handling, EBUSY, SQLite handle leaks
Fix all Windows-specific test failures caused by path handling problems
and EBUSY errors from unclosed SQLite database handles.

Root causes fixed:
1. POSIX path assumptions: replaced hard-coded file:///tmp, /repo, etc.
   with pathToFileURL/path.resolve/path.join computed expectations
2. shortenPath() now normalizes backslashes to forward slashes after ~
   and respects home directory boundaries
3. HistoryStorage.resetInstance() leaked its Database — added #close()
   that finalizes all prepared statements and closes the DB
4. AgentStorage gained the same resetInstance()/#close() pattern
5. SqliteAuthCredentialStore.close() leaked one-off prepared statements
   from inline this.#db.prepare() calls — wrapped each in try/finally
6. model-cache.ts used a process-global DB even for custom dbPath —
   now opens/closes per-call via withModelCacheDb
7. createAgentSession leaked AuthStorage on construction failure —
   added ownsAuthStorage cleanup in catch block
8. MnemopiBackend.removeDbFiles() now truly best-effort (catches errors)
9. TempDir retry window expanded from 4x10ms to 40x25ms
10. TempDir prefix convention: non-@ prefixes created dirs relative to
    cwd instead of os.tmpdir() — all test temp dirs now use @ prefix
11. Shell-escaped interpolated paths in bash tool tests
12. git core.autocrlf false in autoresearch test repo init

All 522 previously-failing Windows tests now pass.
2026-06-18 21:32:38 -07:00

83 lines
3.1 KiB
TypeScript

import { afterEach, beforeEach, describe, expect, it, vi } from "bun:test";
import * as fs from "node:fs";
import * as path from "node:path";
import { resetSettingsForTest, Settings } from "@oh-my-pi/pi-coding-agent/config/settings";
import { SelectorController } from "@oh-my-pi/pi-coding-agent/modes/controllers/selector-controller";
import { AgentStorage } from "@oh-my-pi/pi-coding-agent/session/agent-storage";
import { getProjectAgentDir, TempDir } from "@oh-my-pi/pi-utils";
import { YAML } from "bun";
import { beginSettingsTest, restoreSettingsTestState, type SettingsTestState } from "./helpers/settings-test-state";
describe("autocompleteMaxVisible setting", () => {
let settingsState: SettingsTestState | undefined;
let tempDir: TempDir;
let agentDir: string;
let projectDir: string;
beforeEach(() => {
settingsState = beginSettingsTest();
tempDir = TempDir.createSync("test-autocomplete-settings-");
agentDir = path.join(tempDir.path(), "agent");
projectDir = path.join(tempDir.path(), "project");
fs.mkdirSync(agentDir, { recursive: true });
fs.mkdirSync(getProjectAgentDir(projectDir), { recursive: true });
});
afterEach(async () => {
AgentStorage.resetInstance();
restoreSettingsTestState(settingsState);
settingsState = undefined;
if (tempDir) {
try {
await tempDir.remove();
} catch {}
tempDir = undefined as unknown as TempDir;
}
});
it("should persist and read back a configured value", async () => {
const settings = await Settings.init({ cwd: projectDir, agentDir });
settings.set("autocompleteMaxVisible", 10);
await settings.flush();
// Re-init to verify persistence
resetSettingsForTest();
const settings2 = await Settings.init({ cwd: projectDir, agentDir });
expect(settings2.get("autocompleteMaxVisible")).toBe(10);
});
it("should read from config.yml", async () => {
await Bun.write(path.join(agentDir, "config.yml"), YAML.stringify({ autocompleteMaxVisible: 15 }, null, 2));
const settings = await Settings.init({ cwd: projectDir, agentDir });
expect(settings.get("autocompleteMaxVisible")).toBe(15);
});
it("should let project config.yml override global config.yml", async () => {
await Bun.write(path.join(agentDir, "config.yml"), YAML.stringify({ autocompleteMaxVisible: 15 }, null, 2));
await Bun.write(
path.join(getProjectAgentDir(projectDir), "config.yml"),
YAML.stringify({ autocompleteMaxVisible: 20 }, null, 2),
);
const settings = await Settings.init({ cwd: projectDir, agentDir });
expect(settings.get("autocompleteMaxVisible")).toBe(20);
});
it("should coerce submenu string values for live editor updates", () => {
const setAutocompleteMaxVisible = vi.fn();
const controller = new SelectorController({
editor: { setAutocompleteMaxVisible },
} as unknown as ConstructorParameters<typeof SelectorController>[0]);
controller.handleSettingChange("autocompleteMaxVisible", "10");
expect(setAutocompleteMaxVisible).toHaveBeenCalledWith(10);
});
it("should work with isolated instances", () => {
const settings = Settings.isolated({ autocompleteMaxVisible: 12 });
expect(settings.get("autocompleteMaxVisible")).toBe(12);
});
});