e22d123009
- Converted readdirSync, readFileSync, and statSync to async readdir, readFile, stat across skills and agent discovery. - Made scanDirectoryForSkills async and refactored custom directory scanning to use Promise.all for concurrent processing. - Updated agent discovery to use fs/promises for async file reading and refactored helper patterns. - Added AgentParsingError exception class for better error handling during agent parsing. - Added filesystem error type guards (isEnoent, isEacces, isPerm, etc.) to pi-utils for safe error checking. - Added color manipulation utilities to pi-utils for accessibility features. - Added color-blind mode setting to settings manager. - Migrated plugins, settings, and config modules from sync to async file operations. - Updated error handling to use new pi-utils type guards for type-safe checking.
61 lines
1.9 KiB
TypeScript
61 lines
1.9 KiB
TypeScript
import { describe, expect, it } from "bun:test";
|
|
import { CombinedAutocompleteProvider } from "@oh-my-pi/pi-tui/autocomplete";
|
|
|
|
describe("CombinedAutocompleteProvider", () => {
|
|
describe("extractPathPrefix", () => {
|
|
it("extracts / from 'hey /' when forced", async () => {
|
|
const provider = new CombinedAutocompleteProvider([], "/tmp");
|
|
const lines = ["hey /"];
|
|
const cursorLine = 0;
|
|
const cursorCol = 5; // After the "/"
|
|
|
|
const result = await provider.getForceFileSuggestions(lines, cursorLine, cursorCol);
|
|
|
|
expect(result).not.toBeNull();
|
|
if (result) {
|
|
expect(result.prefix).toBe("/");
|
|
}
|
|
});
|
|
|
|
it("extracts /A from '/A' when forced", async () => {
|
|
const provider = new CombinedAutocompleteProvider([], "/tmp");
|
|
const lines = ["/A"];
|
|
const cursorLine = 0;
|
|
const cursorCol = 2; // After the "A"
|
|
|
|
const result = await provider.getForceFileSuggestions(lines, cursorLine, cursorCol);
|
|
|
|
// This might return null if /A doesn't match anything, which is fine
|
|
// We're mainly testing that the prefix extraction works
|
|
if (result) {
|
|
expect(result.prefix).toBe("/A");
|
|
}
|
|
});
|
|
|
|
it("does not trigger for slash commands", async () => {
|
|
const provider = new CombinedAutocompleteProvider([], "/tmp");
|
|
const lines = ["/model"];
|
|
const cursorLine = 0;
|
|
const cursorCol = 6; // After "model"
|
|
|
|
const result = await provider.getForceFileSuggestions(lines, cursorLine, cursorCol);
|
|
|
|
expect(result).toBe(null);
|
|
});
|
|
|
|
it("triggers for absolute paths after slash command argument", async () => {
|
|
const provider = new CombinedAutocompleteProvider([], "/tmp");
|
|
const lines = ["/command /"];
|
|
const cursorLine = 0;
|
|
const cursorCol = 10; // After the second "/"
|
|
|
|
const result = await provider.getForceFileSuggestions(lines, cursorLine, cursorCol);
|
|
|
|
expect(result).not.toBeNull();
|
|
if (result) {
|
|
expect(result.prefix).toBe("/");
|
|
}
|
|
});
|
|
});
|
|
});
|