Compare commits

1 Commits
Author SHA1 Message Date
Jason b70f10dd38 Fix Foundry v14 actor ownership updates 2026-12-02 21:38:56 -05:00
5 changed files with 64 additions and 16 deletions

No files matched your search

+5 -5
View File
@@ -1,4 +1,4 @@
# Install Player Workshop 2.0.0 # Install Player Workshop 2.0.1
## 1. Before you start ## 1. Before you start
@@ -11,12 +11,12 @@
### Gitea ### Gitea
1. Open or clone `CheddahBoxMB/player-workshop` on your Gitea server. Extract the ZIP into the root of the repository on `main`, so `module.json`, `README.md`, `INSTALL.md`, `scripts/`, and `tests/` are side by side. Commit those files and push `main`. 1. Open or clone `CheddahBoxMB/player-workshop` on your Gitea server. Extract the ZIP into the root of the repository on `main`, so `module.json`, `README.md`, `INSTALL.md`, `scripts/`, and `tests/` are side by side. Commit those files and push `main`.
2. In Gitea, open **Releases → New Release**. Select or create tag `v2.0.0` at the commit you pushed. Upload this exact `player-workshop.zip` as the release attachment and publish the release. If `v2.0.0` was already published with different bytes, use the manual install for this copy or follow the README to create a new version and tag. 2. In Gitea, open **Releases → New Release**. Create tag `v2.0.1` at the commit you pushed. Attach the ZIP with the filename `player-workshop.zip` and publish the release.
3. From the Foundry host, confirm both URLs below are reachable without signing in. These addresses come from the supplied manifest. If your Gitea address or repo path differs, edit `url`, `manifest`, and `download` in `module.json` before committing and build the release ZIP from that commit as described in the README. 3. From the Foundry host, confirm both URLs below are reachable without signing in. These addresses come from the supplied manifest. If your Gitea address or repo path differs, edit `url`, `manifest`, and `download` in `module.json` before committing and build the release ZIP from that commit as described in the README.
```sh ```sh
curl -fsSL 'http://192.168.100.15:3000/CheddahBoxMB/player-workshop/raw/branch/main/module.json' curl -fsSL 'http://192.168.100.15:3000/CheddahBoxMB/player-workshop/raw/branch/main/module.json'
curl -fsSL -o /tmp/player-workshop.zip 'http://192.168.100.15:3000/CheddahBoxMB/player-workshop/releases/download/v2.0.0/player-workshop.zip' curl -fsSL -o /tmp/player-workshop.zip 'http://192.168.100.15:3000/CheddahBoxMB/player-workshop/releases/download/v2.0.1/player-workshop.zip'
unzip -t /tmp/player-workshop.zip unzip -t /tmp/player-workshop.zip
``` ```
@@ -27,7 +27,7 @@
1. Stop Foundry. Find its configured **User Data** directory, then open `Data/modules/` under it. 1. Stop Foundry. Find its configured **User Data** directory, then open `Data/modules/` under it.
2. If `player-workshop/` already exists, move the old folder somewhere outside `Data/modules/` as a backup. 2. If `player-workshop/` already exists, move the old folder somewhere outside `Data/modules/` as a backup.
3. Create `player-workshop/` and extract this ZIP into that folder. The final path must be `Data/modules/player-workshop/module.json`. 3. Create `player-workshop/` and extract this ZIP into that folder. The final path must be `Data/modules/player-workshop/module.json`.
4. Start Foundry and confirm **Player Workshop 2.0.0** appears under **Add-on Modules**. 4. Start Foundry and confirm **Player Workshop 2.0.1** appears under **Add-on Modules**.
## 3. Set up a world ## 3. Set up a world
@@ -38,7 +38,7 @@
## 4. Test on a duplicate world ## 4. Test on a duplicate world
- [ ] As GM, run generic provisioning twice. Confirm a single Testing Grounds scene, four homebrew compendia, and no duplicate personal folders. If you intend to use named setup, test it on a duplicate of the actual campaign and compare the eight actor IDs and ownership entries before and after. - [ ] As GM, run generic provisioning twice. Confirm a single Testing Grounds scene, four homebrew compendia, and no duplicate personal folders. If testing named setup, use a duplicate of the actual campaign. In the Actors sidebar, open **Configure Ownership** for Akupara Kurma and verify that Austin and Jason are Owners and that other player ownership was removed. Confirm the actor is in **Active Campaign → Austin** and compare the eight actor IDs and ownership entries before and after.
- [ ] As a regular Player and as a Trusted Player, create a PC and an item using the normal sidebars. Confirm auto-filing and explicit Owner access. Try opening and editing the other player's test document and confirm its privacy. Open the PC's normal D&D5e sheet and try advancement there. - [ ] As a regular Player and as a Trusted Player, create a PC and an item using the normal sidebars. Confirm auto-filing and explicit Owner access. Try opening and editing the other player's test document and confirm its privacy. Open the PC's normal D&D5e sheet and try advancement there.
- [ ] Upload a portrait or token image and assign it. Enter Testing Grounds and place an owned token. Publish an item to a community pack. As GM, approve a snapshot and confirm the approved compendium is locked after approval. - [ ] Upload a portrait or token image and assign it. Enter Testing Grounds and place an owned token. Publish an item to a community pack. As GM, approve a snapshot and confirm the approved compendium is locked after approval.
- [ ] Export a character ZIP containing an embedded spell, effects, and artwork. As another player in a provisioned duplicate world, import the ZIP and inspect ownership, level, HP, inventory, spell/effect links, and images. If you use Tokenizer or another character builder, enable it after the standalone test and try its normal workflow. - [ ] Export a character ZIP containing an embedded spell, effects, and artwork. As another player in a provisioned duplicate world, import the ZIP and inspect ownership, level, HP, inventory, spell/effect links, and images. If you use Tokenizer or another character builder, enable it after the standalone test and try its normal workflow.
+6 -3
View File
@@ -1,4 +1,4 @@
# Player Workshop 2.0.0 # Player Workshop 2.0.1
Player Workshop is a standalone Foundry VTT module for player-owned D&D characters, homebrew, and artwork. GM setup creates a shared Testing Grounds scene and personal folders. Players use the normal D&D5e sheets for character creation and advancement, and **Player Vault** for organization, artwork, publishing, and exports. Player Workshop is a standalone Foundry VTT module for player-owned D&D characters, homebrew, and artwork. GM setup creates a shared Testing Grounds scene and personal folders. Players use the normal D&D5e sheets for character creation and advancement, and **Player Vault** for organization, artwork, publishing, and exports.
@@ -7,6 +7,8 @@ Player Workshop is a standalone Foundry VTT module for player-owned D&D characte
- **Author** — CheddahBoxMB. - **Author** — CheddahBoxMB.
- **Install and update** — Follow [INSTALL.md](INSTALL.md) for Gitea, manual installation, and the test-world checklist. - **Install and update** — Follow [INSTALL.md](INSTALL.md) for Gitea, manual installation, and the test-world checklist.
Version 2.0.1 fixes a Foundry v14 ownership validation error during named Phandelver setup. The module replaces each affected actor's ownership map and moves that actor in one document update, preserving its ID.
## At the table ## At the table
Open **Player Vault** from the Actors sidebar or the Player Workshop settings menu. The vault lists world actors and items for which your account has explicit Owner access. After GM setup, new root-level PCs and items created by provisioned players are filed in their personal folders. Players can also organize owned actors, upload and assign images, and place their own tokens in Testing Grounds using Foundry's native permissions. Open **Player Vault** from the Actors sidebar or the Player Workshop settings menu. The vault lists world actors and items for which your account has explicit Owner access. After GM setup, new root-level PCs and items created by provisioned players are filed in their personal folders. Players can also organize owned actors, upload and assign images, and place their own tokens in Testing Grounds using Foundry's native permissions.
@@ -36,13 +38,14 @@ git archive --format=zip --output=../player-workshop-release/player-workshop.zip
unzip -t ../player-workshop-release/player-workshop.zip unzip -t ../player-workshop-release/player-workshop.zip
``` ```
Upload `player-workshop.zip` as a Gitea release attachment and verify the raw manifest and ZIP URLs from the Foundry host. Use the ZIP attached to this package for the initial `v2.0.0` release. Upload `player-workshop.zip` as a Gitea release attachment and verify the raw manifest and ZIP URLs from the Foundry host.
## Validation for this build ## Validation for this build
All 15 Node tests pass. The checks cover setup planning and reruns, routing, ownership, ZIP round trips, validation of incoming archive data, and embedded ID options on vault import. The release ZIP was checked after extraction, including all eight JavaScript files and the root manifest. The regression test for imported IDs fails against the previous build and passes with this one. A live Foundry test on a duplicate world remains pending. See [INSTALL.md](INSTALL.md#4-test-on-a-duplicate-world) for the GM and player checks. All 16 Node tests pass. The ownership regression test rejects the update shape used in 2.0.0 and confirms that 2.0.1 moves the same actor and assigns the intended owners. The other checks cover setup planning and reruns, routing, ZIP round trips, incoming archive validation, and embedded ID options on vault import. The release ZIP was checked after extraction, including all eight JavaScript files and the root manifest. Live testing of the fix on Foundry 14.371 remains pending. See [INSTALL.md](INSTALL.md#4-test-on-a-duplicate-world) for the GM and player checks.
- [Foundry VTT 14.371](https://foundryvtt.com/releases/14.371) - [Foundry VTT 14.371](https://foundryvtt.com/releases/14.371)
- [Official D&D5e system](https://foundryvtt.com/packages/dnd5e) - [Official D&D5e system](https://foundryvtt.com/packages/dnd5e)
- [Foundry module manifest and archive](https://foundryvtt.com/article/module-development/) - [Foundry module manifest and archive](https://foundryvtt.com/article/module-development/)
- [Foundry v14 document update operators](https://foundryvtt.com/api/v14/modules/foundry.documents.html)
- [Foundry v14 document creation options](https://foundryvtt.com/api/v14/interfaces/foundry.abstract.types.DatabaseCreateOperation.html) - [Foundry v14 document creation options](https://foundryvtt.com/api/v14/interfaces/foundry.abstract.types.DatabaseCreateOperation.html)
+2 -2
View File
@@ -2,7 +2,7 @@
"id": "player-workshop", "id": "player-workshop",
"title": "Player Workshop", "title": "Player Workshop",
"description": "Player-owned character workshop, artwork, homebrew publishing, portable ZIP archives and GM-controlled setup.", "description": "Player-owned character workshop, artwork, homebrew publishing, portable ZIP archives and GM-controlled setup.",
"version": "2.0.0", "version": "2.0.1",
"authors": [ "authors": [
{ {
"name": "CheddahBoxMB" "name": "CheddahBoxMB"
@@ -29,5 +29,5 @@
], ],
"url": "http://192.168.100.15:3000/CheddahBoxMB/player-workshop", "url": "http://192.168.100.15:3000/CheddahBoxMB/player-workshop",
"manifest": "http://192.168.100.15:3000/CheddahBoxMB/player-workshop/raw/branch/main/module.json", "manifest": "http://192.168.100.15:3000/CheddahBoxMB/player-workshop/raw/branch/main/module.json",
"download": "http://192.168.100.15:3000/CheddahBoxMB/player-workshop/releases/download/v2.0.0/player-workshop.zip" "download": "http://192.168.100.15:3000/CheddahBoxMB/player-workshop/releases/download/v2.0.1/player-workshop.zip"
} }
+2 -4
View File
@@ -123,10 +123,8 @@ export async function applyPlan(game,constants,api,plan,log) {
const folder=lookup(game,'Actor',path); const folder=lookup(game,'Actor',path);
const current=actor.toObject().ownership ?? {}; const current=actor.toObject().ownership ?? {};
if(actor.folder?.id===folder.id && equal(current,ownership))continue; if(actor.folder?.id===folder.id && equal(current,ownership))continue;
const patch={folder:folder.id}; // Replace the ownership map as a field so former owners are removed in the same update.
for(const key of Object.keys(current))if(!(key in ownership))patch[`ownership.-=${key}`]=null; await actor.update({folder: folder.id, ownership: globalThis._replace(ownership)});
for(const [key,level] of Object.entries(ownership))patch[`ownership.${key}`]=level;
await actor.update(patch);
if(actor.folder?.id!==folder.id || !equal(actor.toObject().ownership,ownership))throw Error(`Actor ownership/folder verification failed: ${actor.name}`); if(actor.folder?.id!==folder.id || !equal(actor.toObject().ownership,ownership))throw Error(`Actor ownership/folder verification failed: ${actor.name}`);
log.push(`Organized ${actor.name}`); log.push(`Organized ${actor.name}`);
} }
+49 -2
View File
@@ -1,14 +1,47 @@
import test from 'node:test'; import test from 'node:test';
import assert from 'node:assert/strict'; import assert from 'node:assert/strict';
import {ID,PLAYERS,ROWS,PACKS,ENABLE,DISABLE,lookup,preflight,applyPlan,routeNew,artPaths,desiredPermissions} from '../scripts/core.mjs'; import {ID,PLAYERS,ROWS,PACKS,ENABLE,DISABLE,lookup,preflight,applyPlan,routeNew,artPaths,desiredPermissions} from '../scripts/core.mjs';
const replacement = Symbol('Foundry forced replacement');
const formerOwnerId = 'formerOwner00001';
test.before(() => {
globalThis._replace = value => ({[replacement]: value});
});
test.after(() => {
delete globalThis._replace;
});
function fixture(){ function fixture(){
const roles={PLAYER:1,TRUSTED:2,ASSISTANT:3,GAMEMASTER:4}; const roles={PLAYER:1,TRUSTED:2,ASSISTANT:3,GAMEMASTER:4};
const constants={USER_ROLES:roles,USER_PERMISSIONS:Object.fromEntries([...ENABLE,...DISABLE].map(k=>[k,{requiredRoles:[4]}]))}; const constants={USER_ROLES:roles,USER_PERMISSIONS:Object.fromEntries([...ENABLE,...DISABLE].map(k=>[k,{requiredRoles:[4]}]))};
const users=new Map([...PLAYERS,'Jason','Gamemaster'].map((name,i)=>[name,{id:`u${i}`,name,role:name==='Austin'?2:name==='Jason'?3:name==='Gamemaster'?4:1}])); const users=new Map([...PLAYERS,'Jason','Gamemaster'].map((name,i)=>[name,{id:`u${String(i).padStart(15,'0')}`,name,role:name==='Austin'?2:name==='Jason'?3:name==='Gamemaster'?4:1}]));
const folders=new Map(), packs=new Map(), actors=new Map();let seq=0;const mutations=[]; const folders=new Map(), packs=new Map(), actors=new Map();let seq=0;const mutations=[];
const game={user:users.get('Gamemaster'),release:{generation:14},system:{id:'dnd5e'},world:{id:'the-phandelver'},users,folders,packs,actors,permissions:{...Object.fromEntries([...ENABLE,...DISABLE].map(k=>[k,[2,3,4]])),OTHER:[1,4]},settings:{get(ns,k){return ns===ID?true:game.permissions;},async set(ns,k,v){game.permissions=v;mutations.push(k);}}}; const game={user:users.get('Gamemaster'),release:{generation:14},system:{id:'dnd5e'},world:{id:'the-phandelver'},users,folders,packs,actors,permissions:{...Object.fromEntries([...ENABLE,...DISABLE].map(k=>[k,[2,3,4]])),OTHER:[1,4]},settings:{get(ns,k){return ns===ID?true:game.permissions;},async set(ns,k,v){game.permissions=v;mutations.push(k);}}};
const Folder={async create(data){const f={...data,id:`f${++seq}`,folder:folders.get(data.folder),toObject(){return {...data};}};folders.set(f.id,f);mutations.push('folder');return f;}}; const Folder={async create(data){const f={...data,id:`f${++seq}`,folder:folders.get(data.folder),toObject(){return {...data};}};folders.set(f.id,f);mutations.push('folder');return f;}};
for(const [,name] of ROWS){const actor={id:`a${++seq}`,name,folder:null,ownership:{default:2,old:3},system:{hp:55},toObject(){return {ownership:{...this.ownership}};},async update(p){this.folder=folders.get(p.folder);for(const [k,v] of Object.entries(p)){if(k.startsWith('ownership.-='))delete this.ownership[k.slice(12)];else if(k.startsWith('ownership.'))this.ownership[k.slice(10)]=v;}mutations.push('actor');}};actors.set(actor.id,actor);} for(const [,name] of ROWS){
const actor = {
id: `a${++seq}`,
name,
folder: null,
ownership: {default: 2, [formerOwnerId]: 3},
system: {hp: 55},
toObject() { return {ownership: {...this.ownership}}; },
async update(changes) {
assert.deepEqual(Object.keys(changes).sort(), ['folder', 'ownership']);
const nextOwnership = changes.ownership?.[replacement];
assert.ok(nextOwnership, 'Ownership must replace the complete map');
for (const [id, level] of Object.entries(nextOwnership)) {
assert.ok(id === 'default' || /^[a-zA-Z0-9]{16}$/.test(id));
assert.ok(Number.isInteger(level) && level >= 0 && level <= 3);
}
this.folder = folders.get(changes.folder);
this.ownership = {...nextOwnership};
mutations.push('actor');
return this;
}
};
actors.set(actor.id,actor);
}
const official={title:'Official',collection:'dnd5e.official',locked:true,ownership:{PLAYER:'OBSERVER'}};packs.set(official.collection,official); const official={title:'Official',collection:'dnd5e.official',locked:true,ownership:{PLAYER:'OBSERVER'}};packs.set(official.collection,official);
const Compendium={async createCompendium({label,name,type}){const p={title:label,collection:`world.${name}`,documentName:type,locked:true,ownership:{},folder:null,async configure(c){Object.assign(this,c);mutations.push('configure');},async setFolder(id){this.folder=folders.get(id);mutations.push('file');}};packs.set(p.collection,p);mutations.push('pack');return p;}}; const Compendium={async createCompendium({label,name,type}){const p={title:label,collection:`world.${name}`,documentName:type,locked:true,ownership:{},folder:null,async configure(c){Object.assign(this,c);mutations.push('configure');},async setFolder(id){this.folder=folders.get(id);mutations.push('file');}};packs.set(p.collection,p);mutations.push('pack');return p;}};
const dirs=new Set(['worlds/the-phandelver']); const dirs=new Set(['worlds/the-phandelver']);
@@ -16,6 +49,20 @@ function fixture(){
return {game,constants,api:{Folder,Compendium,Picker},official,dirs,mutations}; return {game,constants,api:{Folder,Compendium,Picker},official,dirs,mutations};
} }
test('preflight read-only; full apply; repeat makes zero mutations',async()=>{const f=fixture();const {game,constants,api,mutations}=f;const old=JSON.stringify(f.official);const active=await api.Folder.create({name:'Active Campaign',type:'Actor',folder:null});mutations.length=0;const plan=preflight(game,constants);assert.equal(mutations.length,0);await applyPlan(game,constants,api,plan,[]);assert.equal(lookup(game,'Actor',['Active Campaign']).id,active.id);assert.equal(game.packs.size,5);assert.equal(f.dirs.size,18);assert.equal(JSON.stringify(f.official),old);for(const row of plan.actors){assert.deepEqual(row.actor.ownership,row.ownership);assert.equal(row.actor.system.hp,55);}assert.deepEqual(game.permissions.OTHER,[1,4]);mutations.length=0;await applyPlan(game,constants,api,preflight(game,constants),[]);assert.deepEqual(mutations,[]);}); test('preflight read-only; full apply; repeat makes zero mutations',async()=>{const f=fixture();const {game,constants,api,mutations}=f;const old=JSON.stringify(f.official);const active=await api.Folder.create({name:'Active Campaign',type:'Actor',folder:null});mutations.length=0;const plan=preflight(game,constants);assert.equal(mutations.length,0);await applyPlan(game,constants,api,plan,[]);assert.equal(lookup(game,'Actor',['Active Campaign']).id,active.id);assert.equal(game.packs.size,5);assert.equal(f.dirs.size,18);assert.equal(JSON.stringify(f.official),old);for(const row of plan.actors){assert.deepEqual(row.actor.ownership,row.ownership);assert.equal(row.actor.system.hp,55);}assert.deepEqual(game.permissions.OTHER,[1,4]);mutations.length=0;await applyPlan(game,constants,api,preflight(game,constants),[]);assert.deepEqual(mutations,[]);});
test('named setup replaces former ownership and keeps the same actor in its new folder', async () => {
const {game,constants,api} = fixture();
const actor = [...game.actors.values()].find(entry => entry.name === 'Akupara Kurma');
const originalId = actor.id;
const austin = game.users.get('Austin');
const jason = game.users.get('Jason');
assert.equal(actor.ownership[formerOwnerId], 3);
await applyPlan(game, constants, api, preflight(game, constants), []);
assert.equal(game.actors.get(originalId), actor);
assert.equal(actor.folder, lookup(game, 'Actor', ['Active Campaign', 'Austin']));
assert.deepEqual(actor.ownership, {default: 0, [austin.id]: 3, [jason.id]: 3});
});
test('missing or duplicate actor blocks before writes',()=>{const f=fixture();const actor=[...f.game.actors.values()][0];f.game.actors.delete(actor.id);assert.throws(()=>preflight(f.game,f.constants),/Expected exactly one/);f.game.actors.set(actor.id,actor);f.game.actors.set('dupe',{...actor,id:'dupe'});assert.throws(()=>preflight(f.game,f.constants),/found 2/);assert.equal(f.mutations.length,0);}); test('missing or duplicate actor blocks before writes',()=>{const f=fixture();const actor=[...f.game.actors.values()][0];f.game.actors.delete(actor.id);assert.throws(()=>preflight(f.game,f.constants),/Expected exactly one/);f.game.actors.set(actor.id,actor);f.game.actors.set('dupe',{...actor,id:'dupe'});assert.throws(()=>preflight(f.game,f.constants),/found 2/);assert.equal(f.mutations.length,0);});
test('wrong user role, system or core version blocks',()=>{const f=fixture();f.game.users.get('Austin').role=1;assert.throws(()=>preflight(f.game,f.constants),/Austin/);f.game.users.get('Austin').role=2;f.game.release.generation=13;assert.throws(()=>preflight(f.game,f.constants),/v14/);f.game.release.generation=14;f.game.user=f.game.users.get('Jason');assert.throws(()=>preflight(f.game,f.constants),/Gamemaster/);}); test('wrong user role, system or core version blocks',()=>{const f=fixture();f.game.users.get('Austin').role=1;assert.throws(()=>preflight(f.game,f.constants),/Austin/);f.game.users.get('Austin').role=2;f.game.release.generation=13;assert.throws(()=>preflight(f.game,f.constants),/v14/);f.game.release.generation=14;f.game.user=f.game.users.get('Jason');assert.throws(()=>preflight(f.game,f.constants),/Gamemaster/);});
test('pack collisions block before writes',()=>{const f=fixture();f.game.packs.set('world.player-homebrew-items',{title:'Different',documentName:'Item'});assert.throws(()=>preflight(f.game,f.constants),/collision/);assert.equal(f.mutations.length,0);}); test('pack collisions block before writes',()=>{const f=fixture();f.game.packs.set('world.player-homebrew-items',{title:'Different',documentName:'Item'});assert.throws(()=>preflight(f.game,f.constants),/collision/);assert.equal(f.mutations.length,0);});