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,16 +369,18 @@ function checkHiddenSubtreeRecursively(parentNoteId: string, item: HiddenSubtree
// Clean up any branches that shouldn't exist according to the meta definition // 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 // For hidden subtree notes, we want to ensure they only exist in their designated locations
const expectedParents = getExpectedParentIds(item.id, hiddenSubtreeDefinition); if (item.enforceBranches) {
const currentBranches = note.getParentBranches(); const expectedParents = getExpectedParentIds(item.id, hiddenSubtreeDefinition);
const currentBranches = note.getParentBranches();
for (const currentBranch of currentBranches) { for (const currentBranch of currentBranches) {
// Only delete branches that are not in the expected locations // Only delete branches that are not in the expected locations
// and are within the hidden subtree structure (avoid touching user-created clones) // and are within the hidden subtree structure (avoid touching user-created clones)
if (!expectedParents.includes(currentBranch.parentNoteId) && if (!expectedParents.includes(currentBranch.parentNoteId) &&
isWithinHiddenSubtree(currentBranch.parentNoteId)) { isWithinHiddenSubtree(currentBranch.parentNoteId)) {
log.info(`Removing unexpected branch for note '${item.id}' from parent '${currentBranch.parentNoteId}'`); log.info(`Removing unexpected branch for note '${item.id}' from parent '${currentBranch.parentNoteId}'`);
currentBranch.markAsDeleted(); currentBranch.markAsDeleted();
}
} }
} }
} }

View File

@ -43,4 +43,10 @@ export interface HiddenSubtreeItem {
| "quickSearch" | "quickSearch"
| "aiChatLauncher"; | "aiChatLauncher";
command?: keyof typeof Command; 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;
} }