Don't show all items on the items sidebar #67
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Right now, the items entries are all the items on the foundry items tab, but also the items that the character contain. Can you make that it only appears the items that are on the items tab on foundry? In other words, make them equal
I'll start by exploring the repo structure and finding the relevant files.
Let me look at the test files and the frontend item components to understand the items sidebar.
Now let me look at the Foundry module side, which decides what gets synced.
Now let me look at how the sidebar fetches items and how the Foundry module sends actor snapshots with embedded items.
Let me look at the tests directory to understand existing test conventions and what covers this sync behavior.
Let me look at the reconcile function and how items come back to Foundry, to understand full implications.
Let me look at the remaining relevant tests and the item list route to fully understand current behavior before changing anything.
Let me check the item route (frontend-facing list) and the module README's sync description.
Let me verify no existing tests depend on actor-embedded items becoming Item rows, and check the foundry-sync-toggle test.
Let me check for any test that asserts actor-embedded gear creates an Item row (which would depend on current behavior).
Let me confirm no test asserts that actor-only gear becomes an Item row (dedup-by-name), which my change would reverse.
Let me examine
forceSyncActorsToDragonrolland confirm no other path relies on embedded items becoming Item rows.Let me check whether any test regex-matches the specific comments I plan to touch, before editing.
Let me read the full harness of the existing sync test so I can write focused new tests in the same style.
I have a clear picture. Let me confirm the root cause with a quick baseline test run before changing anything.
Baseline is green (233 tests). The root cause is clear:
snapshotItemSourcesinbackend/src/routes/foundry-link.jsmerges both the world's item directory (body.items= Foundry's "items tab") and every actor's embedded items (actor.items). Gear that exists only inside a character therefore becomes its own DragonrollItemdocument and shows up in the sidebar.The fix is to make the campaign's
Itemcollection mirror the world item directory only. Actor inventory is stored separately on the actor document (foundryActorToCharacterreadsfoundryActor.items), so dropping embedded items from the item sync won't affect character sheets.Let me make the backend change.
Now update the prune comment, which referenced actor copies, and the
saveFoundryItemname-dedup comment that assumed actor copies reached it.Let me check the folder section comment and the item-delete comment which also reference actor-embedded items.
Now let me update the module README and AGENTS.md, which document the old dedup-with-actor-copies behavior.
Let me verify the README doesn't have a leftover dangling line after my edit.
There's a leftover line. Let me remove it.
Now update AGENTS.md, whose §4 describes items being synced per-carrier.
Now let me check the remaining tests won't break, then add focused tests. Let me look at the exact insertion point and confirm the actor-only sync tests don't expect item rows.
The existing actor-reconcile tests are unrelated to item sync. Now let me add focused backend tests for issue #67 into the sync-route harness file, which already loads
foundry-link.jswith stubbed models.Let me verify no existing test relies on the old merge/prune behavior that my change flips.
The existing tests are unaffected by my change (they pass world items via
items:). Now let me add focused tests for issue #67 using the existing stub harness.Now let me add focused tests for issue #67 into the existing sync-route harness.
Let me run the test suite.
All 237 pass. Let me confirm my 4 new tests actually ran and verify they're meaningful by checking they exercise the new behavior (fail against the old merge logic).
Let me prove the new tests are meaningful by temporarily restoring the old backend logic and confirming they fail.
The two key tests fail against the old logic and pass with my fix — confirming they're meaningful. Tests 11 and 12 pass in both (they assert invariants preserved by the change). Let me verify my change is intact and the full suite is green.
Let me review the final diff of the core backend change to ensure coherence.
The change is complete and coherent. Let me do a final syntax check on the two source files I edited (not just comments).
The change is complete and verified. Here's a summary of what I did for Syndria98/dragonroll#67 — "Don't show all items on the items sidebar".
Root cause
The campaign's items sidebar lists
Itemdocuments. On a Foundry snapshot, the backend'ssnapshotItemSources(backend/src/routes/foundry-link.js) merged both the world's item directory (game.items= Foundry's "items tab") and every character's embedded inventory items. So gear that a character carried but that was not on the world's items tab became its ownItemrow and cluttered the sidebar.Fix
snapshotItemSourcesnow reads onlybody.items— the world's item directory — so the campaign's item list equals Foundry's items tab. The full-snapshot prune (which already keys on the world directory's ids) therefore also drops gear that only characters carried.Character inventories are unaffected: they live on the actor document via
foundryActorToCharacter(which reads the actor's embeddeditems), and the module still sends those inside each actor's snapshot — the backend simply no longer turns them intoItemrows.Files changed
backend/src/routes/foundry-link.js— the one-line behavioural fix (snapshotItemSources), plus comment updates that referenced the old actor-copy merge and "one item per carrier" dedup.dragonroll-foundry/scripts/api.js— comment at the snapshot push (code still sends world items + actor inventory; only the explanation changes).dragonroll-foundry/README.md&AGENTS.md— updated the item-sync rules to state the item list mirrors the world's item directory only.tests/item-folder-sync.test.js— 4 new tests: actor gear stays off the list; the list is the world's whole directory; a shared item is listed once as its world entry; and a full snapshot prunes gear only an actor carried.Verification
node --test tests/→ 237 pass, 0 fail (was 233).an actor's gear is kept off…anda full snapshot prunes gear that only an actor carried) fail against the old logic and pass with the fix, confirming they're meaningful regressions.node --checkpasses on both edited JS files.No commit/push made, per instructions.
Implementation is ready for review: #75