Merge pull request #312 from 0xble/fix/empty-collection-deactivate
fix(index): deactivate stale docs on empty collection updates
This commit is contained in:
commit
72e96d16c0
@ -1428,11 +1428,11 @@ async function indexFiles(pwd?: string, globPattern: string = DEFAULT_GLOB, coll
|
||||
});
|
||||
|
||||
const total = files.length;
|
||||
if (total === 0) {
|
||||
const hasNoFiles = total === 0;
|
||||
if (hasNoFiles) {
|
||||
progress.clear();
|
||||
console.log("No files found matching pattern.");
|
||||
closeDb();
|
||||
return;
|
||||
// Continue so the deactivation pass can mark previously indexed docs as inactive.
|
||||
}
|
||||
|
||||
let indexed = 0, updated = 0, unchanged = 0, processed = 0;
|
||||
|
||||
@ -395,6 +395,43 @@ describe("CLI Update Command", () => {
|
||||
expect(exitCode).toBe(0);
|
||||
expect(stdout).toContain("Updating");
|
||||
});
|
||||
|
||||
test("deactivates stale docs when collection has zero matching files", async () => {
|
||||
const { dbPath, configDir } = await createIsolatedTestEnv("update-empty");
|
||||
const collectionDir = join(testDir, `update-empty-${Date.now()}`);
|
||||
await mkdir(collectionDir, { recursive: true });
|
||||
|
||||
const docPath = join(collectionDir, "only.md");
|
||||
const token = `stale-proof-${Date.now()}`;
|
||||
await writeFile(
|
||||
docPath,
|
||||
`---
|
||||
date: 2026-03-06
|
||||
---
|
||||
# Empty Collection Deactivation
|
||||
${token}
|
||||
`
|
||||
);
|
||||
|
||||
const add = await runQmd(
|
||||
["collection", "add", collectionDir, "--name", "empty-check"],
|
||||
{ dbPath, configDir }
|
||||
);
|
||||
expect(add.exitCode).toBe(0);
|
||||
|
||||
const before = await runQmd(["get", "qmd://empty-check/only.md"], { dbPath, configDir });
|
||||
expect(before.exitCode).toBe(0);
|
||||
expect(before.stdout).toContain(token);
|
||||
|
||||
unlinkSync(docPath);
|
||||
|
||||
const update = await runQmd(["update"], { dbPath, configDir });
|
||||
expect(update.exitCode).toBe(0);
|
||||
expect(update.stdout).toContain("No files found matching pattern.");
|
||||
|
||||
const after = await runQmd(["get", "qmd://empty-check/only.md"], { dbPath, configDir });
|
||||
expect(after.exitCode).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("CLI Add-Context Command", () => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user