Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
Merge remote-tracking branch 'origin/main' into claude/help-virtual-branch-note-3ropqy
Elian Dorane48ac89ef493
diff --cc apps/server/src/services/hidden_subtree.spec.tsindex aef73ec7cd,736a60dd06..e115b6710a--- a/apps/server/src/services/hidden_subtree.spec.ts+++ b/apps/server/src/services/hidden_subtree.spec.ts@@@ -32,36 -32,38 +32,36 @@@ describe("Hidden Subtree", () =>expect(childBranches![0].parentNoteId).toStrictEqual("_lbVisibleLaunchers");});- it("should enforce the correct placement of help", () => {- // First, verify the help note exists in its original correct location- const originalBranch = becca.getBranchFromChildAndParent("_help_Vc8PjrjAGuOp", "_help_gh7bpGYxajRS");- expect(originalBranch).toBeDefined();- expect(originalBranch?.parentNoteId).toBe("_help_gh7bpGYxajRS");-- // Move the help note to an incorrect location (_help root instead of its proper parent)- cls.init(() => {- branches.moveBranchToNote(originalBranch!, "_help");- });-- // Verify the note was moved to the wrong location- const movedBranches = becca.notes["_help_Vc8PjrjAGuOp"]?.getParentBranches()- .filter((b) => !b.isDeleted);- expect(movedBranches).toBeDefined();- expect(movedBranches![0].parentNoteId).toBe("_help");+ it("provides the help subtree as virtual notes, with no persisted rows left behind", () => {+ // The help subtree is injected into becca from the bundled meta as virtual notes;- // the fixture DB carried persisted _help rows (dbVersion 239) which migration 240- // must have removed, entity_changes included.++ // the fixture DB carried persisted _help rows which migration 241 must have++ // removed, entity_changes included.+ const helpRoot = becca.getNoteOrThrow("_help");+ expect(helpRoot.isVirtual).toBe(true);+ expect(helpRoot.getParentNotes().map((n) => n.noteId)).toEqual(["_hidden"]);+ expect(helpRoot.getChildNotes().length).toBeGreaterThan(0);++ const page = becca.getNoteOrThrow("_help_Vc8PjrjAGuOp");+ expect(page.isVirtual).toBe(true);++ const sql = getSql();+ expect(sql.getValue(/*sql*/`SELECT COUNT(*) FROM notes WHERE noteId LIKE '\\_help%' ESCAPE '\\'`)).toBe(0);+ expect(sql.getValue(/*sql*/`SELECT COUNT(*) FROM branches WHERE noteId LIKE '\\_help%' ESCAPE '\\' OR parentNoteId LIKE '\\_help%' ESCAPE '\\'`)).toBe(0);+ expect(sql.getValue(/*sql*/`SELECT COUNT(*) FROM attributes WHERE noteId LIKE '\\_help%' ESCAPE '\\'`)).toBe(0);+ expect(sql.getValue(/*sql*/`SELECT COUNT(*) FROM entity_changes WHERE entityId LIKE '\\_help%' ESCAPE '\\'`)).toBe(0);+ });- // Run the hidden subtree integrity check- cls.init(() => {- hiddenSubtreeService.checkHiddenSubtree(true);- });+ it("rejects moving a help note", () => {+ const originalBranch = becca.getBranchFromChildAndParent("_help_Vc8PjrjAGuOp", "_help_gh7bpGYxajRS");+ expect(originalBranch?.isVirtual).toBe(true);- // Verify that the integrity check moved the help note back to its correct location- const correctedBranches = becca.notes["_help_Vc8PjrjAGuOp"]?.getParentBranches()- .filter((b) => !b.isDeleted);- expect(correctedBranches).toBeDefined();- expect(correctedBranches![0].parentNoteId).toBe("_help_gh7bpGYxajRS");+ // validateParentChild rejects the move before anything is touched+ const result = originalBranch && cls.init(() => branches.moveBranchToNote(originalBranch, "_help"));+ expect(Array.isArray(result) ? result[1] : result).toMatchObject({ success: false });- // Ensure the note is no longer under the incorrect parent- const helpRootChildren = becca.notes["_help"]?.getChildNotes();- const incorrectChild = helpRootChildren?.find(note => note.noteId === "_help_Vc8PjrjAGuOp");- expect(incorrectChild).toBeUndefined();+ // structure is unchanged+ const parents = becca.getNoteOrThrow("_help_Vc8PjrjAGuOp").getParentNotes().map((n) => n.noteId);+ expect(parents).toEqual(["_help_gh7bpGYxajRS"]);});it("enforces renames of launcher notes", () => {diff --cc packages/trilium-core/src/index.tsindex cd2eeaac1e,a7d5b5c09e..0907d0282f--- a/packages/trilium-core/src/index.ts+++ b/packages/trilium-core/src/index.ts@@@ -107,17 -129,12 +129,22 @@@ export { default as sync_mutex } from "export { default as setup } from "./services/setup";export { getPlatform, type PlatformProvider } from "./services/platform";export { InAppHelpProvider } from "./services/in_app_help";+export {+ getVirtualNoteContent,+ getVirtualNoteProvider,+ getVirtualNoteProviders,+ registerVirtualNoteProvider,+ unregisterVirtualNoteProvider,+ type VirtualNoteProvider,+ type VirtualSubtreeAttribute,+ type VirtualSubtreeItem+} from "./services/virtual_notes";- export { type ImageProvider, type ImageFormat, type ProcessedImage, getImageProvider } from "./services/image_provider";+ export { type ImageProvider, type ImageFormat, type ImageCompressionOutcome, type ImageCompressionRequest, type ProcessedImage, getImageProvider } from "./services/image_provider";+ export { default as imageCompressionService } from "./services/image_compression";+ export { default as imageInventoryService, type ImageInventoryOptions } from "./services/image_inventory";+ export { default as imageInfoService } from "./services/image_info";+ export { estimateJpegQuality } from "./services/jpeg_quality";+ export { inspectImage, type InspectedImage, UNKNOWN_FORMAT } from "./services/image_inspect";export { type CoreConfig, initConfig, getConfig } from "./services/config";export { default as imageService } from "./services/image";export { t } from "i18next";diff --cc packages/trilium-core/src/migrations/migrations.tsindex 8b9e808694,5e06935d9c..76bf306d89--- a/packages/trilium-core/src/migrations/migrations.ts+++ b/packages/trilium-core/src/migrations/migrations.ts@@@ -9,38 -9,12 +9,44 @@@ export function getMaxMigrationVersion(// Migrations should be kept in descending order, so the latest migration is first.export const MIGRATIONS: (SqlMigration | JsMigration)[] = [+ // The in-app help (`_help` subtree) became virtual — injected into becca from the bundled+ // help meta on every load, never persisted or synced (see services/virtual_notes.ts).+ // Remove the previously persisted rows, including their entity_changes so the deletions+ // don't churn through sync: every instance in a cluster runs this same migration (the+ // accompanying sync-version bump guarantees no un-migrated peers), so all copies converge.+ // User clones of help notes and user attributes on them are dropped by design — the help+ // structure is application-owned. Orphaned blobs are vacuumed by the regular erase job.+ // The rows for indirectly-keyed entities must be removed from entity_changes before their+ // base rows disappear from under the subselects.+ {- version: 240,++ version: 241,+ sql: /*sql*/`+ DELETE FROM entity_changes WHERE entityName = 'branches' AND entityId IN+ (SELECT branchId FROM branches WHERE noteId LIKE '\\_help%' ESCAPE '\\' OR parentNoteId LIKE '\\_help%' ESCAPE '\\');+ DELETE FROM entity_changes WHERE entityName = 'attributes' AND entityId IN+ (SELECT attributeId FROM attributes WHERE noteId LIKE '\\_help%' ESCAPE '\\');+ DELETE FROM entity_changes WHERE entityName = 'revisions' AND entityId IN+ (SELECT revisionId FROM revisions WHERE noteId LIKE '\\_help%' ESCAPE '\\');+ DELETE FROM entity_changes WHERE entityName = 'attachments' AND entityId IN+ (SELECT attachmentId FROM attachments WHERE ownerId LIKE '\\_help%' ESCAPE '\\');+ -- Blanket sweep by ID prefix: catches notes and note_reordering rows directly, plus+ -- tombstones of help branches/attributes deleted (and later erased) by past releases —+ -- their base rows are gone, so the subselects above cannot find them, but branch IDs+ -- ('parentNoteId_noteId') and attribute IDs ('noteId_...') carry the _help prefix.+ DELETE FROM entity_changes WHERE entityId LIKE '\\_help%' ESCAPE '\\';+ DELETE FROM branches WHERE noteId LIKE '\\_help%' ESCAPE '\\' OR parentNoteId LIKE '\\_help%' ESCAPE '\\';+ DELETE FROM attributes WHERE noteId LIKE '\\_help%' ESCAPE '\\';+ DELETE FROM revisions WHERE noteId LIKE '\\_help%' ESCAPE '\\';+ DELETE FROM attachments WHERE ownerId LIKE '\\_help%' ESCAPE '\\';+ DELETE FROM notes WHERE noteId LIKE '\\_help%' ESCAPE '\\';+ `+ },+ // Give every board its own select definition for the label it groups by, so the columns stop+ // living only in the board.json attachment+ {+ version: 240,+ module: () => import("./0240__migrate_board_status_to_select.js")+ },// Turn TOTP back off for installs that had disabled MFA before the enable flag was removed{version: 239,