Fix CLI tests for context and collection filter

- Update add-context test to use virtual path format (qmd://collection/)
- Fix collection filter test to provide explicit collection names with --name
- Add debug output for failing tests
This commit is contained in:
Tobi Lutke 2025-12-13 14:19:41 -05:00
parent d32ec1991b
commit a26a7f3a3c
No known key found for this signature in database

View File

@ -337,12 +337,19 @@ describe("CLI Add-Context Command", () => {
});
test("adds context to a path", async () => {
// First add a collection to get its name
const listResult = await runQmd(["collection", "list"]);
const collectionName = listResult.stdout.split('\n')[0].trim();
// Add context to the collection root using virtual path
const { stdout, exitCode } = await runQmd([
"add-context",
"notes",
"context",
"add",
`qmd://${collectionName}/`,
"Personal notes and meeting logs",
]);
expect(exitCode).toBe(0);
expect(stdout).toContain("✓ Added context");
});
test("requires path and text arguments", async () => {
@ -422,21 +429,24 @@ describe("CLI Search with Collection Filter", () => {
beforeEach(async () => {
// Use a fresh database for this test suite
localDbPath = getFreshDbPath();
// Create multiple collections
await runQmd(["collection", "add", ".", "--mask", "notes/*.md"], { dbPath: localDbPath });
await runQmd(["collection", "add", ".", "--mask", "docs/*.md"], { dbPath: localDbPath });
// Create multiple collections with explicit names
await runQmd(["collection", "add", ".", "--name", "notes", "--mask", "notes/*.md"], { dbPath: localDbPath });
await runQmd(["collection", "add", ".", "--name", "docs", "--mask", "docs/*.md"], { dbPath: localDbPath });
});
test("filters search by collection name", async () => {
const { stdout, exitCode } = await runQmd([
const { stdout, stderr, exitCode } = await runQmd([
"search",
"-c",
"notes",
"meeting",
], { dbPath: localDbPath });
if (exitCode !== 0) {
console.log("Collection filter search failed:");
console.log("stdout:", stdout);
console.log("stderr:", stderr);
}
expect(exitCode).toBe(0);
// Should find results from notes collection
expect(stdout.toLowerCase()).toContain("meeting");
});
});