Skip to content

Build your personal knowledge base with Trilium Notes

fix(core): register help provider in standalone test env; harden injection edge cases

Claude8ed7264c0664
diff --git a/apps/standalone/src/test_setup.ts b/apps/standalone/src/test_setup.ts
index 08e73f1116..103b33ece5 100644
--- a/apps/standalone/src/test_setup.ts
+++ b/apps/standalone/src/test_setup.ts
@@ -10,6 +10,7 @@ import { beforeAll } from "vitest";
import StandaloneBackupService from "./lightweight/backup_provider.js";
import BrowserExecutionContext from "./lightweight/cls_provider.js";
import BrowserCryptoProvider from "./lightweight/crypto_provider.js";
+import StandaloneInAppHelpProvider from "./lightweight/in_app_help_provider.js";
import StandalonePlatformProvider from "./lightweight/platform_provider.js";
import BrowserSqlProvider from "./lightweight/sql_provider.js";
import BrowserZipProvider from "./lightweight/zip_provider.js";
@@ -124,6 +125,9 @@ beforeAll(async () => {
});
},
platform: new StandalonePlatformProvider(""),
+ // Mirrors production (local-server-worker): registers the _help virtual note
+ // provider so the virtual help subtree exists in this environment's becca too.
+ inAppHelp: new StandaloneInAppHelpProvider(),
backup: new StandaloneBackupService(options),
image: standaloneImageProvider,
schema: schemaSql,
diff --git a/packages/trilium-core/src/becca/becca_loader.ts b/packages/trilium-core/src/becca/becca_loader.ts
index 47c8ad8256..02c6ffe54e 100644
--- a/packages/trilium-core/src/becca/becca_loader.ts
+++ b/packages/trilium-core/src/becca/becca_loader.ts
@@ -104,8 +104,11 @@ function injectVirtualSubtrees() {
.getChildBranches()
.reduce((max, childBranch) => Math.max(max, childBranch?.notePosition ?? 0), 0);
- subtree.forEach((item, index) => injectVirtualItem(provider, provider.parentNoteId, item, basePosition + (index + 1) * 10));
+ // Set before injecting: should injection throw mid-subtree, the already-injected
+ // notes still need the target-relation backfill below.
injectedAny = true;
+
+ subtree.forEach((item, index) => injectVirtualItem(provider, provider.parentNoteId, item, basePosition + (index + 1) * 10));
} catch (e) {
// A broken provider must never take down the becca load.
log.error(`Virtual note provider '${provider.namespace}' failed, skipping: ${e instanceof Error ? (e.stack ?? e.message) : String(e)}`);
@@ -187,11 +190,13 @@ function injectVirtualItem(provider: VirtualNoteProvider, parentNoteId: string,
}
attributeDefs.forEach((def, index) => {
- // Deterministic ID, unique thanks to the note-ID prefix; the index suffix disambiguates
- // multiple same-named attributes on one note.
- let attributeId = `v_${item.id}_${def.type.charAt(0)}${def.name}`;
- if (becca.attributes[attributeId]) {
- attributeId = `${attributeId}_${index}`;
+ // Deterministic ID, unique thanks to the note-ID prefix; the counter suffix
+ // disambiguates multiple same-named attributes on one note, probing until free so
+ // pathological names (e.g. "x" colliding with an explicit "x_1") cannot overwrite.
+ const baseAttributeId = `v_${item.id}_${def.type.charAt(0)}${def.name}`;
+ let attributeId = baseAttributeId;
+ for (let suffix = 1; becca.attributes[attributeId]; suffix++) {
+ attributeId = `${baseAttributeId}_${suffix}`;
}
const attribute = new BAttribute({
diff --git a/packages/trilium-core/src/services/hidden_subtree.spec.ts b/packages/trilium-core/src/services/hidden_subtree.spec.ts
index faca394a6f..78b4d971f1 100644
--- a/packages/trilium-core/src/services/hidden_subtree.spec.ts
+++ b/packages/trilium-core/src/services/hidden_subtree.spec.ts
@@ -52,8 +52,10 @@ describe("hidden_subtree (real DB)", () => {
expect(hidden.getParentBranches().some((b) => b.parentNoteId === "root")).toBe(true);
// A representative set of the declared children must exist and sit
- // directly under _hidden.
- for (const childId of ["_search", "_options", "_help", "_taskStates", "_lbRoot"]) {
+ // directly under _hidden. (_help is deliberately absent: it is a virtual
+ // subtree owned by the in-app help provider, not by checkHiddenSubtree —
+ // see in_app_help.spec.ts.)
+ for (const childId of ["_search", "_options", "_taskStates", "_lbRoot"]) {
const child = becca.notes[childId];
expect(child, `${childId} should exist`).toBeDefined();
expect(