-
Notifications
You must be signed in to change notification settings - Fork 6
ENG-2019: Extract shared cross-space node discovery into packages/database #1216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sid597
wants to merge
24
commits into
main
Choose a base branch
from
eng-2019-extract-shared-cross-space-node-discovery-into
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+484
−531
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
da4d214
[ENG-1855] Add Roam shared-node import discovery
sid597 b805ddf
[ENG-1855] Keep discovery dialog open
sid597 6d2b17a
[ENG-1855] Fix discovery dialog dismissing on keyboard launch
sid597 aba903d
[ENG-1855] Use getAllPages for ResourceAccess pagination
sid597 3b91d1b
[ENG-2019] Add shared cross-space node discovery module to packages/d…
sid597 6dccc48
[ENG-2019] Swap Roam shared-node discovery onto the shared module
sid597 69fa231
[ENG-2019] Swap Obsidian import listing onto the shared module
sid597 0f0adf9
[ENG-2019] Narrow Json metadata without any-casts in Obsidian mapper
sid597 9f7f93e
Avoid racing Supabase context initialization
sid597 2fa228c
Merge remote-tracking branch 'origin/main' into eng-1855-add-roam-sha…
sid597 d70f4d1
[ENG-1855] Address shared-node discovery review feedback
sid597 f35b7ca
[ENG-1855] Match UTC parsing with Obsidian
sid597 a587350
[ENG-1855] Defer shared discovery refactor to ENG-2019
sid597 d4071b4
[ENG-1855] Exclude relations from shared-node discovery
sid597 9d2f8c6
Merge remote-tracking branch 'origin/eng-1855-add-roam-shared-node-im…
sid597 d4d437d
[ENG-2019] Use the Platform enum for shared discovery types
sid597 9ab3603
[ENG-2019] Stop fetching full text during shared-node discovery
sid597 7542d59
[ENG-2019] Filter current space and order uniquely in the ResourceAcc…
sid597 c4e68cd
[ENG-2019] Alias the Platform enum locally to match existing usage
sid597 74b6de3
Merge remote-tracking branch 'origin/main' into eng-2019-extract-shar…
sid597 612e651
[ENG-2019] Address review: drop groupIds param, rename candidate nami…
sid597 3130758
[ENG-2019] Address review: derive RID directly and drop per-space que…
sid597 66fe6cb
[ENG-2019] Query shared nodes directly from RLS-scoped views
sid597 c512f49
[ENG-2019] Rename buildSharedNodes input from concepts to nodes
sid597 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
187 changes: 28 additions & 159 deletions
187
apps/roam/src/utils/__tests__/discoverSharedNodes.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,179 +1,48 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { buildDiscoveredSharedNodes } from "~/utils/discoverSharedNodes"; | ||
|
|
||
| type BuildArgs = Parameters<typeof buildDiscoveredSharedNodes>[0]; | ||
|
|
||
| const resources: BuildArgs["resources"] = [ | ||
| { space_id: 20, source_local_id: "node-1" }, | ||
| { space_id: 20, source_local_id: "schema-1" }, | ||
| ]; | ||
| const spaces: BuildArgs["spaces"] = [ | ||
| { | ||
| id: 20, | ||
| name: "Research vault", | ||
| platform: "Obsidian", | ||
| url: "obsidian:vault-a", | ||
| }, | ||
| ]; | ||
| const concepts: BuildArgs["concepts"] = [ | ||
| { | ||
| is_schema: false, | ||
| last_modified: "2026-06-14T12:00:00", | ||
| schema_id: 200, | ||
| source_local_id: "node-1", | ||
| space_id: 20, | ||
| }, | ||
| ]; | ||
| const contents: BuildArgs["contents"] = [ | ||
| { | ||
| content_type: "text/plain", | ||
| last_modified: "2026-06-14T13:00:00", | ||
| source_local_id: "node-1", | ||
| space_id: 20, | ||
| text: "EVD - REM sleep and recall", | ||
| variant: "direct", | ||
| }, | ||
| { | ||
| content_type: "text/markdown", | ||
| last_modified: "2026-06-14T15:00:00", | ||
| source_local_id: "node-1", | ||
| space_id: 20, | ||
| text: "# EVD - REM sleep and recall", | ||
| variant: "full", | ||
| }, | ||
| ]; | ||
| const sourceNodeRid = "orn:obsidian.note:vault-a/node-1"; | ||
|
|
||
| const build = ({ | ||
| conceptsOverride = concepts, | ||
| contentsOverride = contents, | ||
| currentSpaceId = 10, | ||
| importedSourceRids = new Set<string>(), | ||
| resourcesOverride = resources, | ||
| spacesOverride = spaces, | ||
| }: { | ||
| conceptsOverride?: typeof concepts; | ||
| contentsOverride?: typeof contents; | ||
| currentSpaceId?: number; | ||
| importedSourceRids?: ReadonlySet<string>; | ||
| resourcesOverride?: typeof resources; | ||
| spacesOverride?: typeof spaces; | ||
| } = {}) => | ||
| buildDiscoveredSharedNodes({ | ||
| concepts: conceptsOverride, | ||
| contents: contentsOverride, | ||
| currentSpaceId, | ||
| importedSourceRids, | ||
| resources: resourcesOverride, | ||
| spaces: spacesOverride, | ||
| }); | ||
|
|
||
| describe("buildDiscoveredSharedNodes", () => { | ||
| it("builds a group-shared contract node with stable source identity", () => { | ||
| expect(build({ importedSourceRids: new Set([sourceNodeRid]) })).toEqual([ | ||
| import { toDiscoveredSharedNodes } from "~/utils/discoverSharedNodes"; | ||
| import type { SharedNode } from "@repo/database/lib/sharedNodes"; | ||
|
|
||
| const sharedNode: SharedNode = { | ||
| rid: "orn:obsidian.note:vault-a/node-1", | ||
| sourceLocalId: "node-1", | ||
| spaceId: 20, | ||
| spaceName: "Research vault", | ||
| spaceUri: "obsidian:vault-a", | ||
| platform: "Obsidian", | ||
| title: "EVD - REM sleep and recall", | ||
| created: "2026-06-14T12:30:00.000Z", | ||
| lastModified: "2026-06-14T15:00:00.000Z", | ||
| authorId: 7, | ||
| directMetadata: null, | ||
| }; | ||
|
|
||
| describe("toDiscoveredSharedNodes", () => { | ||
| it("maps a shared node to the exact discovered shared node shape", () => { | ||
| expect( | ||
| toDiscoveredSharedNodes({ | ||
| sharedNodes: [sharedNode], | ||
| importedSourceRids: new Set([sharedNode.rid]), | ||
| }), | ||
| ).toEqual([ | ||
| { | ||
| alreadyImported: true, | ||
| modifiedAt: "2026-06-14T15:00:00.000Z", | ||
| sourceApp: "Obsidian", | ||
| sourceNodeId: "node-1", | ||
| sourceNodeRid, | ||
| sourceNodeRid: "orn:obsidian.note:vault-a/node-1", | ||
| sourceSpaceId: "obsidian:vault-a", | ||
| sourceSpaceName: "Research vault", | ||
| title: "EVD - REM sleep and recall", | ||
| }, | ||
| ]); | ||
| }); | ||
|
|
||
| it("does not discover shared resources from the current space", () => { | ||
| expect(build({ currentSpaceId: 20 })).toEqual([]); | ||
| }); | ||
|
|
||
| it("requires the exact shared resource identity", () => { | ||
| expect( | ||
| build({ | ||
| resourcesOverride: [{ space_id: 21, source_local_id: "node-1" }], | ||
| }), | ||
| ).toEqual([]); | ||
| }); | ||
|
|
||
| it.each([ | ||
| { | ||
| name: "schema concept", | ||
| conceptsOverride: [{ ...concepts[0], is_schema: true }], | ||
| contentsOverride: contents, | ||
| }, | ||
| { | ||
| name: "missing node type", | ||
| conceptsOverride: [{ ...concepts[0], schema_id: null }], | ||
| contentsOverride: contents, | ||
| }, | ||
| { | ||
| name: "missing direct content", | ||
| conceptsOverride: concepts, | ||
| contentsOverride: [contents[1]], | ||
| }, | ||
| { | ||
| name: "missing full content", | ||
| conceptsOverride: concepts, | ||
| contentsOverride: [contents[0]], | ||
| }, | ||
| { | ||
| name: "untyped full content", | ||
| conceptsOverride: concepts, | ||
| contentsOverride: [contents[0], { ...contents[1], content_type: null }], | ||
| }, | ||
| ])("filters a node with $name", ({ conceptsOverride, contentsOverride }) => { | ||
| expect(build({ conceptsOverride, contentsOverride })).toEqual([]); | ||
| }); | ||
|
|
||
| it("matches imports by RID rather than source-local ID alone", () => { | ||
| expect( | ||
| build({ | ||
| toDiscoveredSharedNodes({ | ||
| sharedNodes: [sharedNode], | ||
| importedSourceRids: new Set(["orn:obsidian.note:another-vault/node-1"]), | ||
| })[0]?.alreadyImported, | ||
| ).toBe(false); | ||
| }); | ||
|
|
||
| it.each([ | ||
| "orn:obsidian.note:vault-a/node-1", | ||
| "https://example.com/shared/node-1", | ||
| ])("preserves a RID-shaped source-local ID: %s", (rid) => { | ||
| expect( | ||
| build({ | ||
| conceptsOverride: [{ ...concepts[0], source_local_id: rid }], | ||
| contentsOverride: contents.map((content) => ({ | ||
| ...content, | ||
| source_local_id: rid, | ||
| })), | ||
| resourcesOverride: [{ space_id: 20, source_local_id: rid }], | ||
| })[0]?.sourceNodeRid, | ||
| ).toBe(rid); | ||
| }); | ||
|
|
||
| it("sorts newest nodes first", () => { | ||
| const olderConcept = { | ||
| ...concepts[0], | ||
| last_modified: "2026-06-10T12:00:00", | ||
| source_local_id: "node-2", | ||
| }; | ||
| const olderContents = contents.map((content) => ({ | ||
| ...content, | ||
| last_modified: "2026-06-10T12:00:00", | ||
| source_local_id: "node-2", | ||
| text: | ||
| content.variant === "direct" | ||
| ? "Older shared node" | ||
| : "# Older shared node", | ||
| })); | ||
| expect( | ||
| build({ | ||
| conceptsOverride: [olderConcept, concepts[0]], | ||
| contentsOverride: [...olderContents, ...contents], | ||
| resourcesOverride: [ | ||
| ...resources, | ||
| { space_id: 20, source_local_id: "node-2" }, | ||
| ], | ||
| }).map((node) => node.sourceNodeId), | ||
| ).toEqual(["node-1", "node-2"]); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not moved — replaced. This query's semantics (any cross-space row, RLS-only, unpaginated) are superseded by the shared module's gated listing; the variant-grouping/direct-preference logic it did by hand is what
buildSharedNodeCandidatesdoes behind the gate.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like a few specific functions weren't replaced 1:1. Could you walk through those decisions? For example:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
text (title)
modifiedAt