fix(hidden_subtree): visible launchers broken due to branch enforcement

This commit is contained in:
Elian Doran 2025-07-28 12:20:14 +03:00
parent 115e9e0202
commit bb9e7b1c6e
No known key found for this signature in database
3 changed files with 51 additions and 9 deletions

View File

@ -0,0 +1,34 @@
import { describe, it } from "vitest";
import cls from "./cls.js";
import hiddenSubtreeService from "./hidden_subtree.js";
import sql_init from "./sql_init.js";
import branches from "./branches.js";
import becca from "../becca/becca.js";
describe("Hidden Subtree", () => {
describe("Launcher movement persistence", () => {
beforeAll(async () => {
sql_init.initializeDb();
await sql_init.dbReady;
cls.init(() => hiddenSubtreeService.checkHiddenSubtree());
});
it("should persist launcher movement between visible and available after integrity check", async () => {
// Move backend log to visible launchers.
const backendLogBranch = becca.getBranchFromChildAndParent("_lbBackendLog", "_lbAvailableLaunchers");
expect(backendLogBranch).toBeDefined();
// Move launcher to visible launchers.
cls.init(() => {
branches.moveBranchToNote(backendLogBranch!, "_lbVisibleLaunchers");
hiddenSubtreeService.checkHiddenSubtree();
});
// Ensure the launcher is still in visible launchers.
const childBranches = backendLogBranch?.childNote.getParentBranches()
.filter((b) => !b.isDeleted);
expect(childBranches).toBeDefined();
expect(childBranches![0].parentNoteId).toStrictEqual("_lbVisibleLaunchers");
});
});
});

View File

@ -369,6 +369,7 @@ function checkHiddenSubtreeRecursively(parentNoteId: string, item: HiddenSubtree
// Clean up any branches that shouldn't exist according to the meta definition
// For hidden subtree notes, we want to ensure they only exist in their designated locations
if (item.enforceBranches) {
const expectedParents = getExpectedParentIds(item.id, hiddenSubtreeDefinition);
const currentBranches = note.getParentBranches();
@ -382,6 +383,7 @@ function checkHiddenSubtreeRecursively(parentNoteId: string, item: HiddenSubtree
}
}
}
}
const attrs = [...(item.attributes || [])];

View File

@ -43,4 +43,10 @@ export interface HiddenSubtreeItem {
| "quickSearch"
| "aiChatLauncher";
command?: keyof typeof Command;
/**
* If set to true, then branches will be enforced to be in the correct place.
* This is useful for ensuring that the launcher is always in the correct place, even if
* the user moves it around.
*/
enforceBranches?: boolean;
}