When right clicking actor on foundry, show action to force sync to dragonroll #96

Closed
opened 2026-10-15 22:13:12 +00:00 by Syndria98 · 42 comments
Owner

When doing that, make that it replaces everything of that actor that is saved on dragonroll

When doing that, make that it replaces everything of that actor that is saved on dragonroll
Syndria98 added the ai-ready label 2026-10-15 22:13:12 +00:00
Agent added the working label 2026-10-15 22:33:32 +00:00
Collaborator

I'll start by exploring the repository structure to understand the Foundry module and how sync currently works.

I'll start by exploring the repository structure to understand the Foundry module and how sync currently works.
Collaborator

Let me search for key patterns: context menus, the existing "Force Sync" feature, and actor sync functions.

Let me search for key patterns: context menus, the existing "Force Sync" feature, and actor sync functions.
Collaborator

Let me read the existing Force Sync feature and the actor sync logic in detail.

Let me read the existing Force Sync feature and the actor sync logic in detail.
Collaborator

Now let me look at the existing context menu registration and the actor directory hook at the end of the file.

Now let me look at the existing context menu registration and the actor directory hook at the end of the file.
Collaborator

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.

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.
Collaborator

Now let me read the /sync/snapshot route to understand the full request flow.

Now let me read the `/sync/snapshot` route to understand the full request flow.
Collaborator

Let me read the module README and the relevant tests to understand conventions and current coverage.

Let me read the module README and the relevant tests to understand conventions and current coverage.
Collaborator

Let me examine the existing tests to understand how the module's context-menu and force-sync behavior is tested.

Let me examine the existing tests to understand how the module's context-menu and force-sync behavior is tested.
Collaborator

Let me look at the actor Foundry mapper and model to understand exactly which fields force-sync replaces.

Let me look at the actor Foundry mapper and model to understand exactly which fields force-sync replaces.
Collaborator

Let me read the Actor model to understand all fields that a "replace everything" would need to reset.

Let me read the Actor model to understand all fields that a "replace everything" would need to reset.
Collaborator

Let me look at how the backend sync behavior is tested, to follow test conventions.

Let me look at how the backend sync behavior is tested, to follow test conventions.
Collaborator

Let me check all callers of pushFoundryActors and how full snapshots are sent, to place the new flag safely.

Let me check all callers of `pushFoundryActors` and how full snapshots are sent, to place the new flag safely.
Collaborator

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(...) with fullSync: false. On the backend, saveFoundryActor then does if (!fullSync || actor.isNew) Object.assign(actor, fields), so the fields the mapper emits are overwritten. However, foundryActorToCharacter intentionally 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 replace flag (distinct from fullSync, 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.

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(...)` with `fullSync: false`. On the backend, `saveFoundryActor` then does `if (!fullSync || actor.isNew) Object.assign(actor, fields)`, so the fields the mapper emits *are* overwritten. However, `foundryActorToCharacter` **intentionally 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 `replace` flag (distinct from `fullSync`, 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.
Collaborator

There's a route-level test harness. Let me study it to follow conventions and see how saveFoundryActor writers are exposed.

There's a route-level test harness. Let me study it to follow conventions and see how `saveFoundryActor` writers are exposed.
Collaborator

Let me see the exports of foundry-link.js and its requires, to wire the new flag consistently.

Let me see the exports of `foundry-link.js` and its requires, to wire the new flag consistently.
Collaborator

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).

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).
Collaborator

No tests assert the exact snapshot body shape, so adding a replace field is safe. Let me establish a green baseline before making changes.

No tests assert the exact snapshot body shape, so adding a `replace` field is safe. Let me establish a green baseline before making changes.
Collaborator

Baseline is green. Now let me implement the changes. First, the backend mapper foundryActorToCharacter to support a replace mode.

Baseline is green. Now let me implement the changes. First, the backend mapper `foundryActorToCharacter` to support a `replace` mode.
Collaborator

Now update the proficiencies field to respect replace:

Now update the `proficiencies` field to respect `replace`:
Collaborator

Now update the conditional fields block to emit empty values when replacing:

Now update the conditional fields block to emit empty values when replacing:
Collaborator

Let me verify the mapper edits:

Let me verify the mapper edits:
Collaborator

Now the backend route: add replace to saveFoundryActor and pass it to the mapper.

Now the backend route: add `replace` to `saveFoundryActor` and pass it to the mapper.
Collaborator

Now wire replace through the /sync/snapshot route:

Now wire `replace` through the `/sync/snapshot` route:
Collaborator

Now the module: add replace to pushFoundryActors and its request body.

Now the module: add `replace` to `pushFoundryActors` and its request body.
Collaborator

Now update forceSyncActorsToDragonroll to send the replace flag and document it:

Now update `forceSyncActorsToDragonroll` to send the replace flag and document it:
Collaborator

Update the context-menu comment to mention the replace behavior:

Update the context-menu comment to mention the replace behavior:
Collaborator

Update the module README to describe the replace behavior:

Update the module README to describe the replace behavior:
Collaborator

Now let me add tests. First, the module-side assertions in foundry-sync-toggle.test.js:

Now let me add tests. First, the module-side assertions in `foundry-sync-toggle.test.js`:
Collaborator

Add a live-sync assertion showing a normal change does not send replace:

Add a live-sync assertion showing a normal change does not send `replace`:
Collaborator

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:

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:
Collaborator

Let me review the mapper-level tests in character-sheet-details.test.js to optionally add a focused replace test there.

Let me review the mapper-level tests in `character-sheet-details.test.js` to optionally add a focused `replace` test there.
Collaborator

The existing test at line 407 covers the live "don't clear" case. Let me add a focused mapper test contrasting replace. I need MODULE_ID — let me confirm it's defined in that file.

The existing test at line 407 covers the live "don't clear" case. Let me add a focused mapper test contrasting `replace`. I need `MODULE_ID` — let me confirm it's defined in that file.
Collaborator

MODULE_ID is available. Let me add the focused mapper test:

`MODULE_ID` is available. Let me add the focused mapper test:
Collaborator

Now let me run the affected tests:

Now let me run the affected tests:
Collaborator

One test failed. Let me see the failure detail.

One test failed. Let me see the failure detail.
Collaborator

assert.notOk isn't exposed by node:assert/strict in this Node build. The live push explicitly sets replace: false, so I'll assert equality.

`assert.notOk` isn't exposed by `node:assert/strict` in this Node build. The live push explicitly sets `replace: false`, so I'll assert equality.
Collaborator

All green. Now let me run the full test suite to ensure nothing else regressed.

All green. Now let me run the full test suite to ensure nothing else regressed.
Collaborator

All 347 tests pass. Let me review the complete diff for coherence.

All 347 tests pass. Let me review the complete diff for coherence.
Collaborator

The diff is clean and backward compatible. Let me verify the actorType flag behavior I chose to leave untouched, to confirm it's a deliberate round-trip preservation and not an oversight.

The diff is clean and backward compatible. Let me verify the `actorType` flag behavior I chose to leave untouched, to confirm it's a deliberate round-trip preservation and not an oversight.
Collaborator

The actorType flag is a deliberate DR-side classification (foundryActorToCharacter prefers it, and Foundry's own actor.type is 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 like folder/discordUserId) untouched is correct — the replace covers all the sheet content fields a user sees and edits.

Let me review the test diff:

The `actorType` flag is a deliberate DR-side classification (`foundryActorToCharacter` prefers it, and Foundry's own `actor.type` is 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 like `folder`/`discordUserId`) untouched is correct — the replace covers all the sheet content fields a user sees and edits. Let me review the test diff:
Collaborator

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 replace mode, kept separate from fullSync (which means preserve edits + prune):

  • Module (dragonroll-foundry/scripts/api.js): right-click Force Sync now sends replace: true. Live changes and the reconnect full snapshot keep replace: false.
  • Backend (routes/foundry-link.js): /sync/snapshot reads replace and passes it through saveFoundryActor → 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.
  • Mapper (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 carries replace: true; a live change sends replace: 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 via npm test since the workspace installs no deps; I ran the node --test runner directly.) No files were committed or pushed.

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 **`replace`** mode, kept separate from `fullSync` (which means *preserve edits + prune*): - **Module** (`dragonroll-foundry/scripts/api.js`): right-click Force Sync now sends `replace: true`. Live changes and the reconnect full snapshot keep `replace: false`. - **Backend** (`routes/foundry-link.js`): `/sync/snapshot` reads `replace` and passes it through `saveFoundryActor` → `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. - **Mapper** (`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 carries `replace: true`; a live change sends `replace: 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 via `npm test` since the workspace installs no deps; I ran the `node --test` runner directly.) No files were committed or pushed.
Collaborator

Implementation is ready for review: #102

Implementation is ready for review: https://git.aranroig.com/Syndria98/dragonroll/pulls/102
Agent added help wanted and removed working labels 2026-10-15 22:53:04 +00:00
Sign in to join this conversation.
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Syndria98/dragonroll#96