When right clicking actor on foundry, show action to force sync to dragonroll #96
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?
When doing that, make that it replaces everything of that actor that is saved on dragonroll
I'll start by exploring the repository structure to understand the Foundry module and how sync currently works.
Let me search for key patterns: context menus, the existing "Force Sync" feature, and actor sync functions.
Let me read the existing Force Sync feature and the actor sync logic in detail.
Now let me look at the existing context menu registration and the actor directory hook at the end of the file.
The actor directory already has a "Force Sync" context menu. The key new requirement is the second sentence: force-sync must replace everything of that actor saved on Dragonroll. Let me examine the backend sync writer to understand current preserve-vs-overwrite behavior.
Now let me read the
/sync/snapshotroute to understand the full request flow.Let me read the module README and the relevant tests to understand conventions and current coverage.
Let me examine the existing tests to understand how the module's context-menu and force-sync behavior is tested.
Let me look at the actor Foundry mapper and model to understand exactly which fields force-sync replaces.
Let me read the Actor model to understand all fields that a "replace everything" would need to reset.
Let me look at how the backend sync behavior is tested, to follow test conventions.
Let me check all callers of
pushFoundryActorsand how full snapshots are sent, to place the new flag safely.I now understand the full flow. Let me confirm my understanding of the gap before implementing.
Analysis: The actor-directory "Dragonroll: Force Sync" menu already exists (issue #8) and calls
pushFoundryActors(...)withfullSync: false. On the backend,saveFoundryActorthen doesif (!fullSync || actor.isNew) Object.assign(actor, fields), so the fields the mapper emits are overwritten. However,foundryActorToCharacterintentionally omits certain fields (skills, savingThrows, tools, languages, currency, traits, and the DR-flag fallbacks for proficiencies/traits) when the world "says nothing" — so a force sync currently preserves those campaign-side values instead of replacing everything.The issue asks force sync to replace everything of that actor saved on Dragonroll. The clean fix is a dedicated
replaceflag (distinct fromfullSync, which means preserve + prune): the module sets it on force-sync, and the mapper emits complete fields so the row becomes exactly the Foundry actor.Let me verify no route-level test harness exists for these backend routes.
There's a route-level test harness. Let me study it to follow conventions and see how
saveFoundryActorwriters are exposed.Let me see the exports of
foundry-link.jsand its requires, to wire the new flag consistently.I have a complete understanding. Let me check whether any existing tests assert the exact sync-request body shape (which adding a field could break).
No tests assert the exact snapshot body shape, so adding a
replacefield is safe. Let me establish a green baseline before making changes.Baseline is green. Now let me implement the changes. First, the backend mapper
foundryActorToCharacterto support areplacemode.Now update the
proficienciesfield to respectreplace:Now update the conditional fields block to emit empty values when replacing:
Let me verify the mapper edits:
Now the backend route: add
replacetosaveFoundryActorand pass it to the mapper.Now wire
replacethrough the/sync/snapshotroute:Now the module: add
replacetopushFoundryActorsand its request body.Now update
forceSyncActorsToDragonrollto send the replace flag and document it:Update the context-menu comment to mention the replace behavior:
Update the module README to describe the replace behavior:
Now let me add tests. First, the module-side assertions in
foundry-sync-toggle.test.js:Add a live-sync assertion showing a normal change does not send
replace:Now the backend test verifying replace clears campaign-set fields while a live change preserves them. I'll add it near the other writer tests:
Let me review the mapper-level tests in
character-sheet-details.test.jsto optionally add a focusedreplacetest there.The existing test at line 407 covers the live "don't clear" case. Let me add a focused mapper test contrasting
replace. I needMODULE_ID— let me confirm it's defined in that file.MODULE_IDis available. Let me add the focused mapper test:Now let me run the affected tests:
One test failed. Let me see the failure detail.
assert.notOkisn't exposed bynode:assert/strictin this Node build. The live push explicitly setsreplace: false, so I'll assert equality.All green. Now let me run the full test suite to ensure nothing else regressed.
All 347 tests pass. Let me review the complete diff for coherence.
The diff is clean and backward compatible. Let me verify the
actorTypeflag behavior I chose to leave untouched, to confirm it's a deliberate round-trip preservation and not an oversight.The
actorTypeflag is a deliberate DR-side classification (foundryActorToCharacterprefers it, and Foundry's ownactor.typeis used when it's absent). Overriding it on a forced sync could silently reclassify an actor and is beyond the issue's scope, so leaving it (and structural links likefolder/discordUserId) untouched is correct — the replace covers all the sheet content fields a user sees and edits.Let me review the test diff:
Done. Here's what I implemented for issue #96.
What was already there
The right-click Dragonroll: Force Sync action in the Foundry actor directory already existed (from #8). But it pushed actors through the same path as a live Foundry edit — a merge — so it kept the fields the campaign sets by hand (skills, saving throws, tools, languages, currency, traits, and free-text proficiencies) whenever the world has no value for them. It did not truly "replace everything saved on Dragonroll," which is what this issue asks.
The change
Added a dedicated
replacemode, kept separate fromfullSync(which means preserve edits + prune):dragonroll-foundry/scripts/api.js): right-click Force Sync now sendsreplace: true. Live changes and the reconnect full snapshot keepreplace: false.routes/foundry-link.js):/sync/snapshotreadsreplaceand passes it throughsaveFoundryActor→foundryActorToCharacter(source, replace). It applies to the actors sent only — it still never prunes the campaign's other actors, and leaves structural links (folder, Discord ownership, HP/hit dice) untouched.services/actor-foundry.js): on replace, the fields a live edit omits when the world says nothing are written empty, and the campaign's cached flag text for traits/proficiencies is ignored — so the Dragonroll row becomes exactly the Foundry actor. A live edit behaves exactly as before.The change is backward compatible both ways (an old module simply doesn't send
replace; an old backend ignores it).Tests & docs
tests/foundry-sync-toggle.test.js: force-sync push carriesreplace: true; a live change sendsreplace: false.tests/foundry-force-import.test.js: through the real sync writer, a forced save clears campaign-written traits/tools/languages/skills/saving-throws/currency, while a live save keeps them.tests/character-sheet-details.test.js: mapper-level contrast between live (leave out) and replace (write empty).dragonroll-foundry/README.md: updated the Force Sync description.Full suite passes:
node --test tests/→ 347 passed, 0 failed. (I did not run it vianpm testsince the workspace installs no deps; I ran thenode --testrunner directly.) No files were committed or pushed.Implementation is ready for review: #102