Sync foundry folder colors #57

Closed
opened 2026-10-15 12:31:38 +00:00 by Syndria98 · 7 comments
Owner

Make that folder colors sync through dragonroll and foundry

Make that folder colors sync through dragonroll and foundry
Syndria98 added the ai-ready label 2026-10-15 12:31:38 +00:00
Agent added the working label 2026-10-15 13:26:17 +00:00
Collaborator

I'll start by exploring the repo structure and the Foundry sync code.

I'll start by exploring the repo structure and the Foundry sync code.
Collaborator

Now let me implement the backend side of the sync:

Now let me implement the backend side of the sync:
Collaborator

Let me verify how the existing test harness behaves by running a loadable copy of it:

Let me verify how the existing test harness behaves by running a loadable copy of it:
Collaborator

I'll now update the test file — fixing the harness gaps that prevent it from running, plus adding color coverage:

I'll now update the test file — fixing the harness gaps that prevent it from running, plus adding color coverage:
Collaborator

I'm done. Here's what I changed and how I verified it.

Feature: folder colours sync between Foundry and Dragonroll

Foundry folder colours now travel both ways along the item-folder tree that already syncs (#44).

Backend — backend/src/routes/foundry-link.js

  • New foundryFolderColor(source) normalises a pushed folder colour: undefined = the push says nothing about colours (older module) → the campaign's colour stays; null = the world shows no colour → the campaign's colour comes off; anything else is the colour.
  • orderFoundryFolderSources carries it, syncFoundryItemFolders applies it alongside name/nesting (world still owns name and nesting; a folder created from a coloured push arrives coloured).
  • GET /sync/items now answers {items, folders} — the campaign's item folders with color and foundryFolderId, the same shape the app's own /item/list uses — so the colour a user picks in Dragonroll has a way home.

Foundry module — dragonroll-foundry/scripts/api.js

  • worldItemFolderSnapshots() reports each folder's color (null when uncoloured) with every tree push.
  • applyDragonrollFolderColors(), run from the existing item reconcile, writes the campaign's colour onto the matching world folder — only when it differs, only for world item-directory folders, and held in a new syncingFolderIds set so the updateFolder hook does not echo it straight back to the campaign. It runs before the D&D 5e gate, since a colour is system-agnostic while writing items is not. Autosync off still stops everything.

Docs: one bullet in AGENTS.md §4 and two in dragonroll-foundry/README.md (rule + route table), plus the echo-suppression note.

The Dragonroll UI needed nothing: Folder.color, the sidebar colour menu and the sidebar's 5-second entry refetch were already there.

Tests (tests/item-folder-sync.test.js)

8 new tests: colour in → campaign (new folder and re-colour), world un-colouring clears it, an older module that sends no colour leaves it alone, /sync/items returns the coloured item folders (and not the note folders); module side: the tree carries colours, a GM recolour pushes one, a campaign colour lands on the world folder without echoing back, a cleared colour clears the world folder, autosync off writes nothing.

node --test tests/ → 188 pass, 25 fail. Two notes on that number:

  • This test file could not run at all before: its module-scope await made Node 20.20 read it as an ES module (require is not defined), and its harness did not stub node:crypto, wrote seeded rows without a campaign, or gave the actor/folder stubs the update / updateEmbeddedDocuments they call. I repaired those harness gaps, which is why the file contributes 27 passes now.
  • The remaining 25 failures are pre-existing and unrelated: 22 in map-pins / map-tokens (require("../models/Folder") is not stubbed) and 3 in this file that were masked by it not loading — the Folder.find( regex assertion over note.js/folder.js, and the two BuildItemRows sidebar-ordering tests. None touch files I changed; I left them alone.

One landmine found while doing this, untouched because it is unrelated: dragonroll-foundry/scripts/api.js:1279 calls scheduleDragonrollCharacterSync(15000), which is never defined — so a failed startup character sync throws a ReferenceError instead of scheduling its retry.

I'm done. Here's what I changed and how I verified it. ## Feature: folder colours sync between Foundry and Dragonroll Foundry folder colours now travel both ways along the item-folder tree that already syncs (#44). **Backend — `backend/src/routes/foundry-link.js`** - New `foundryFolderColor(source)` normalises a pushed folder colour: `undefined` = the push says nothing about colours (older module) → the campaign's colour stays; `null` = the world shows no colour → the campaign's colour comes off; anything else is the colour. - `orderFoundryFolderSources` carries it, `syncFoundryItemFolders` applies it alongside name/nesting (world still owns name and nesting; a folder created from a coloured push arrives coloured). - `GET /sync/items` now answers `{items, folders}` — the campaign's item folders with `color` and `foundryFolderId`, the same shape the app's own `/item/list` uses — so the colour a user picks in Dragonroll has a way home. **Foundry module — `dragonroll-foundry/scripts/api.js`** - `worldItemFolderSnapshots()` reports each folder's `color` (`null` when uncoloured) with every tree push. - `applyDragonrollFolderColors()`, run from the existing item reconcile, writes the campaign's colour onto the matching world folder — only when it differs, only for world item-directory folders, and held in a new `syncingFolderIds` set so the `updateFolder` hook does not echo it straight back to the campaign. It runs before the D&D 5e gate, since a colour is system-agnostic while writing items is not. Autosync off still stops everything. **Docs:** one bullet in `AGENTS.md` §4 and two in `dragonroll-foundry/README.md` (rule + route table), plus the echo-suppression note. The Dragonroll UI needed nothing: `Folder.color`, the sidebar colour menu and the sidebar's 5-second entry refetch were already there. ## Tests (`tests/item-folder-sync.test.js`) 8 new tests: colour in → campaign (new folder and re-colour), world un-colouring clears it, an older module that sends no colour leaves it alone, `/sync/items` returns the coloured item folders (and not the note folders); module side: the tree carries colours, a GM recolour pushes one, a campaign colour lands on the world folder without echoing back, a cleared colour clears the world folder, autosync off writes nothing. `node --test tests/` → **188 pass, 25 fail**. Two notes on that number: - This test file could not run at all before: its module-scope `await` made Node 20.20 read it as an ES module (`require is not defined`), and its harness did not stub `node:crypto`, wrote seeded rows without a `campaign`, or gave the actor/folder stubs the `update` / `updateEmbeddedDocuments` they call. I repaired those harness gaps, which is why the file contributes 27 passes now. - The remaining 25 failures are pre-existing and unrelated: 22 in `map-pins` / `map-tokens` (`require("../models/Folder") is not stubbed`) and 3 in this file that were masked by it not loading — the `Folder.find(` regex assertion over `note.js`/`folder.js`, and the two `BuildItemRows` sidebar-ordering tests. None touch files I changed; I left them alone. One landmine found while doing this, untouched because it is unrelated: `dragonroll-foundry/scripts/api.js:1279` calls `scheduleDragonrollCharacterSync(15000)`, which is never defined — so a failed startup character sync throws a `ReferenceError` instead of scheduling its retry.
Collaborator

Implementation is ready for review: #66

Implementation is ready for review: https://git.aranroig.com/Syndria98/dragonroll/pulls/66
Collaborator

The automated implementation stopped because of an internal error. Please check the worker logs for details.

The automated implementation stopped because of an internal error. Please check the worker logs for details.
Agent removed the working label 2026-10-15 13:58:44 +00:00
Sign in to join this conversation.
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Syndria98/dragonroll#57