14252e71cb
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.
88 lines
2.5 KiB
TypeScript
88 lines
2.5 KiB
TypeScript
/**
|
|
* Regression test for issue #905.
|
|
*
|
|
* Model listing did not include providers contributed by extensions
|
|
* (via `pi.registerProvider(...)`), regardless of whether the extension was
|
|
* supplied via `-e <path>` or configured under `extensions:` in the user
|
|
* settings. The original `--list-models` short-circuit in `runRootCommand`
|
|
* exited before extensions were loaded.
|
|
*
|
|
* Contract under test: the `omp models` listing entry point loads extensions
|
|
* (CLI `-e` paths and configured `settings.extensions`) before listing, so
|
|
* extension-registered providers/models appear in the output.
|
|
*/
|
|
|
|
import { afterAll, beforeAll, expect, test } from "bun:test";
|
|
import * as fs from "node:fs/promises";
|
|
import { AuthStorage } from "@oh-my-pi/pi-ai";
|
|
import { runModelsListing } from "@oh-my-pi/pi-coding-agent/cli/models-cli";
|
|
import { ModelRegistry } from "@oh-my-pi/pi-coding-agent/config/model-registry";
|
|
import { TempDir } from "@oh-my-pi/pi-utils";
|
|
|
|
let tmp: TempDir;
|
|
let extPath: string;
|
|
let dbPath: string;
|
|
|
|
beforeAll(async () => {
|
|
tmp = await TempDir.create("@issue-905-");
|
|
extPath = tmp.join("ext.ts");
|
|
dbPath = tmp.join("auth.db");
|
|
await fs.writeFile(
|
|
extPath,
|
|
`export default function (pi) {
|
|
pi.registerProvider("test-gw", {
|
|
baseUrl: "https://example.com/v1",
|
|
apiKey: "literal-test-key",
|
|
api: "openai-completions",
|
|
models: [{
|
|
id: "test-model",
|
|
name: "Test Model",
|
|
reasoning: false,
|
|
input: ["text"],
|
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
contextWindow: 128000,
|
|
maxTokens: 4096,
|
|
}],
|
|
});
|
|
}
|
|
`,
|
|
);
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await Bun.sleep(0);
|
|
await tmp.remove();
|
|
});
|
|
|
|
test("omp models surfaces extension-registered providers (issue #905)", async () => {
|
|
const authStorage = await AuthStorage.create(dbPath);
|
|
try {
|
|
const modelRegistry = new ModelRegistry(authStorage);
|
|
|
|
const captured: string[] = [];
|
|
const originalWrite = process.stdout.write.bind(process.stdout);
|
|
process.stdout.write = ((chunk: string | Uint8Array) => {
|
|
captured.push(typeof chunk === "string" ? chunk : Buffer.from(chunk).toString("utf8"));
|
|
return true;
|
|
}) as typeof process.stdout.write;
|
|
|
|
try {
|
|
await runModelsListing({
|
|
modelRegistry,
|
|
cwd: tmp.path(),
|
|
action: "ls",
|
|
additionalExtensionPaths: [extPath],
|
|
disableExtensionDiscovery: true,
|
|
});
|
|
} finally {
|
|
process.stdout.write = originalWrite;
|
|
}
|
|
|
|
const output = captured.join("");
|
|
expect(output).toContain("test-gw");
|
|
expect(output).toContain("test-model");
|
|
} finally {
|
|
authStorage.close();
|
|
}
|
|
});
|