b8e4da23d0
- Added a setup-system-deps action with preloaded-runner guards and apt fallbacks. - Updated CI workflows to download Linux x64 native artifacts and gate on native job success. - Renamed coding-agent fast mode to singleton in scripts and test partitioning logic. - Added settings test-state begin/restore helpers with recursive cleanup in affected tests.
80 lines
3.0 KiB
TypeScript
80 lines
3.0 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it, vi } from "bun:test";
|
|
import * as fs from "node:fs";
|
|
import * as os from "node:os";
|
|
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 { getProjectAgentDir, Snowflake } 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 testDir = "";
|
|
let agentDir: string;
|
|
let projectDir: string;
|
|
|
|
beforeEach(() => {
|
|
settingsState = beginSettingsTest();
|
|
testDir = path.join(os.tmpdir(), "test-autocomplete-settings", Snowflake.next());
|
|
agentDir = path.join(testDir, "agent");
|
|
projectDir = path.join(testDir, "project");
|
|
fs.mkdirSync(agentDir, { recursive: true });
|
|
fs.mkdirSync(getProjectAgentDir(projectDir), { recursive: true });
|
|
});
|
|
|
|
afterEach(() => {
|
|
restoreSettingsTestState(settingsState);
|
|
settingsState = undefined;
|
|
if (testDir && fs.existsSync(testDir)) {
|
|
fs.rmSync(testDir, { recursive: true, force: true });
|
|
}
|
|
testDir = "";
|
|
});
|
|
|
|
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);
|
|
});
|
|
});
|