Skip to content

Commit cb35431

Browse files
author
DavidQ
committed
Verify Preview Generator SVG writes through workspace repo handle - PR_26130_006-preview-generator-handle-write-verification
1 parent 0223efe commit cb35431

8 files changed

Lines changed: 482 additions & 120 deletions

File tree

docs/dev/codex_commands.md

Lines changed: 38 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,41 @@
1-
# Codex Commands - PR_26130_004-workspace-return-tool-enable-regression
1+
# Codex Commands - PR_26130_006-preview-generator-handle-write-verification
22

33
```text
44
codex
55
66
Changes:
7-
Create PR_26130_004-workspace-return-tool-enable-regression.
7+
Create PR_26130_006-preview-generator-handle-write-verification.
88
Read docs/dev/PROJECT_INSTRUCTIONS.md first.
9-
Fix Workspace Manager V2 regression where returning from any tool leaves all workspace tools disabled/gray.
10-
On return from a tool, preserve the selected repo, selected game, live repo folder handle, active game binding, and enabled tool list.
11-
Do not treat normal return navigation as Cancel, Close, or lost file handle.
12-
Only disable tools when no valid opened game/toolState is active or when repo binding is actually missing.
13-
Add explicit log lines for return-from-tool state restoration: repo selected, game selected, source binding status, enabled tool count.
14-
Keep Save disabled only when no live writable file handle exists.
15-
Keep scope limited to Workspace Manager V2 return state and tool enablement regression.
9+
Fix Preview Generator V2 write verification so SVG writes are verified through the same live repo FileSystemDirectoryHandle provided by Workspace Manager V2.
10+
Do not treat absolute path string comparison against handle-relative path as a mismatch.
11+
Normalize path reporting into:
12+
- repo display label
13+
- repo root path string
14+
- handle root name
15+
- handle-relative output path
16+
- absolute display path
17+
After SVG write, verify by re-reading the handle target and logging:
18+
- file exists
19+
- file size
20+
- modified timestamp when available
21+
- content starts as SVG
22+
- output path
23+
- handle-relative path
24+
If Preview Generator cannot write through the Workspace Manager live repo handle, fail visibly and do not claim OK WRITE.
25+
Document whether the handle is passed from Workspace Manager or resolved from workspace.repo.reference/session runtime state.
26+
Keep scope limited to Preview Generator V2 handle/path/write verification.
1627
No unrelated files.
1728
No start_of_day changes.
1829
1930
Validation:
2031
Run npm run test:workspace-v2.
21-
Add/update Playwright test for opening a game, launching a tool, returning to workspace, and verifying tools remain enabled.
22-
Add/update Playwright test that Save state remains correct after return.
32+
Add/update Playwright coverage for Preview Generator V2 using Workspace Manager repo handle, SVG write verification, and no false OK WRITE when handle write/read verification fails.
2333
Do not run full samples smoke test; document skipped reason.
2434
2535
Required reports:
2636
Create docs/dev/reports/codex_review.diff.
2737
Create docs/dev/reports/codex_changed_files.txt.
28-
Create docs/dev/reports/PR_26130_004-workspace-return-tool-enable-regression.md.
38+
Create docs/dev/reports/PR_26130_006-preview-generator-handle-write-verification.md.
2939
Update docs/dev/codex_commands.md.
3040
Update docs/dev/commit_comment.txt.
3141
Produce required repo-structured ZIP under tmp/.
@@ -37,63 +47,48 @@ Produce required repo-structured ZIP under tmp/.
3747
Get-Content -Path "docs/dev/PROJECT_INSTRUCTIONS.md"
3848
Get-Content -Path ".codex/skills/repo-build/SKILL.md"
3949
git status --short --untracked-files=all
40-
rg -n "returnToWorkspaceButton|expectWorkspaceRestoreRequiresRepoRebind|rebindRestoredWorkspace|expectWorkspaceReturnRehydrated|activeToolStateRequiresRepoHandle|workspace.repo.reference|FileSystemDirectoryHandle|handle" tests/playwright/tools/WorkspaceManagerV2.spec.mjs tools/workspace-manager-v2/js tools/preview-generator-v2 tools/asset-manager-v2/js -g "*.js" -g "*.mjs"
41-
node --check tools/workspace-manager-v2/js/WorkspaceManagerV2App.js
42-
node --check tools/workspace-manager-v2/js/services/WorkspaceManagerV2ContextService.js
43-
node --check tools/asset-manager-v2/js/AssetManagerV2App.js
44-
node --check tools/asset-manager-v2/js/services/WorkspaceBridge.js
45-
node --check tools/palette-manager-v2/main.js
46-
node --check tools/preview-generator-v2/PreviewGeneratorV2ShellControl.js
47-
node --check tools/session-inspector-v2/js/SessionInspectorV2App.js
50+
Select-String -Path tools/preview-generator-v2/PreviewGeneratorV2App.js -Pattern "function hydrateWorkspaceRepoSession|function verifyWrittenPreview|function logWritePath|function writePreview|function absoluteOutputPathFromWrite|function handleOutputPathFromWrite|function hydrateWorkspaceLaunchContext" -Context 4,40
51+
Select-String -Path tools/preview-generator-v2/PreviewGeneratorV2RepoAccess.js -Pattern "createSessionRepoHandle|appendSessionWrite|WORKSPACE_REPO_WRITES_SESSION_KEY|class PreviewGeneratorV2RepoAccess" -Context 3,6
52+
Select-String -Path tests/playwright/tools/WorkspaceManagerV2.spec.mjs -Pattern "function installMockRepoPicker|function makeFileHandle|function makeDirectoryHandle|makeMockRepoHandle|__workspaceManagerV2RepoHandleCache" -Context 3,20
53+
node --check tools/preview-generator-v2/PreviewGeneratorV2RepoAccess.js
54+
node --check tools/preview-generator-v2/PreviewGeneratorV2App.js
4855
node --check tests/playwright/tools/WorkspaceManagerV2.spec.mjs
49-
npx playwright test tests/playwright/tools/WorkspaceManagerV2.spec.mjs --project=playwright --workers=1 --reporter=list -g "uses header lifecycle controls|keeps Preview Generator V2 repo writer|loads Gravity Well"
5056
npm run test:workspace-v2
57+
git diff -- tools/preview-generator-v2/PreviewGeneratorV2RepoAccess.js tools/preview-generator-v2/PreviewGeneratorV2App.js tests/playwright/tools/WorkspaceManagerV2.spec.mjs
5158
git diff --check
5259
git status --short --untracked-files=all
5360
git diff --stat
5461
```
5562

5663
## Validation
5764

58-
`npm run test:workspace-v2` passed: 22 passed.
59-
60-
Focused rerun for the return-regression slices passed: 3 passed.
65+
`npm run test:workspace-v2` passed: 23 passed.
6166

6267
Syntax checks passed for:
6368

64-
- `tools/workspace-manager-v2/js/WorkspaceManagerV2App.js`
65-
- `tools/workspace-manager-v2/js/services/WorkspaceManagerV2ContextService.js`
66-
- `tools/asset-manager-v2/js/AssetManagerV2App.js`
67-
- `tools/asset-manager-v2/js/services/WorkspaceBridge.js`
68-
- `tools/palette-manager-v2/main.js`
69-
- `tools/preview-generator-v2/PreviewGeneratorV2ShellControl.js`
70-
- `tools/session-inspector-v2/js/SessionInspectorV2App.js`
69+
- `tools/preview-generator-v2/PreviewGeneratorV2RepoAccess.js`
70+
- `tools/preview-generator-v2/PreviewGeneratorV2App.js`
7171
- `tests/playwright/tools/WorkspaceManagerV2.spec.mjs`
7272

7373
`git diff --check` passed.
7474

75-
Full samples smoke test skipped because this PR is limited to Workspace Manager V2 return state/tool enablement and does not modify shared sample loading, sample manifests, or broad sample runtime behavior.
75+
Full samples smoke test skipped because this PR is limited to Preview Generator V2 handle/path/write verification and does not modify shared sample loading, sample manifests, or broad sample runtime behavior.
7676

7777
## Playwright Impact
7878

7979
Playwright impacted: Yes.
8080

81-
Workspace Manager V2 Playwright now validates opening a game, launching workspace tools, returning to Workspace Manager V2, keeping workspace tools enabled, preserving repo/game/source binding, and preserving clean/dirty Save and Close button state after return.
81+
Workspace Manager V2 Playwright now validates Preview Generator V2 restoring the live Workspace Manager repo handle, writing `preview.svg` through that handle, logging read-back verification details, and failing without `OK WRITE` when handle read-back verification fails.
8282

83-
Expected pass behavior: normal Return to Workspace restores the active repo, game, source binding, enabled tool count, and refreshed dirty toolState data without requiring Pick Repo Folder.
83+
Expected pass behavior: Preview Generator V2 writes and verifies `preview.svg` through the live repo handle, reports handle-relative and absolute display paths separately, and logs file exists/size/modified/SVG-start metadata.
8484

85-
Expected fail behavior: tests fail if return navigation drops the live repo handle, grays out tools, enables Save without a live binding, disables Save while dirty after a valid return, or omits the return-state log lines.
85+
Expected fail behavior: tests fail if Preview Generator V2 falls back to session-only writes, logs a false path mismatch for absolute-vs-handle-relative paths, claims `OK WRITE` after read-back verification fails, or cannot restore the Workspace Manager V2 live repo handle.
8686

8787
## Coverage
8888

89-
Playwright V8 coverage report generated by `npm run test:workspace-v2`:
89+
Playwright V8 coverage report generated by `npm run test:workspace-v2` noted changed Preview Generator V2 runtime coverage, including:
9090

91-
- `(63%) tools/asset-manager-v2/js/AssetManagerV2App.js - executed lines 643/643; executed functions 36/57`
92-
- `(76%) tools/preview-generator-v2/PreviewGeneratorV2ShellControl.js - executed lines 166/166; executed functions 13/17`
93-
- `(83%) tools/palette-manager-v2/main.js - executed lines 227/227; executed functions 15/18`
94-
- `(87%) tools/workspace-manager-v2/js/WorkspaceManagerV2App.js - executed lines 710/710; executed functions 39/45`
95-
- `(90%) tools/workspace-manager-v2/js/services/WorkspaceManagerV2ContextService.js - executed lines 1458/1458; executed functions 136/151`
96-
- `(93%) tools/asset-manager-v2/js/services/WorkspaceBridge.js - executed lines 305/305; executed functions 25/27`
97-
- `(93%) tools/session-inspector-v2/js/SessionInspectorV2App.js - executed lines 309/309; executed functions 41/44`
91+
- `(88%) tools/preview-generator-v2/PreviewGeneratorV2App.js - changed JS file with browser V8 coverage`
92+
- `(28%) tools/preview-generator-v2/PreviewGeneratorV2RepoAccess.js - advisory low coverage; restore/cache helpers are exercised through browser launch flows but branch coverage remains low`
9893

9994
`tests/playwright/tools/WorkspaceManagerV2.spec.mjs` is a changed test file and is not collected as browser runtime coverage.

docs/dev/commit_comment.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Preserve Workspace Manager V2 tool enablement after tool return - PR_26130_004-workspace-return-tool-enable-regression
1+
Fix Preview Generator V2 live handle write verification - PR_26130_006-preview-generator-handle-write-verification
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# PR_26130_006-preview-generator-handle-write-verification
2+
3+
## Summary
4+
5+
- Preview Generator V2 workspace launch now restores the live Workspace Manager V2 repo `FileSystemDirectoryHandle` instead of creating a session-backed synthetic repo writer.
6+
- `preview.svg` writes are verified by re-reading the live handle target before `OK WRITE` is logged.
7+
- Write logs now separate repo display label, repo root path string, handle root name, handle-relative output path, and absolute display path.
8+
- SVG write verification logs file existence, file size, modified timestamp when available, SVG-start detection, output path, and handle-relative path.
9+
- Absolute display paths are no longer compared directly against handle-relative paths, removing the false path mismatch warning.
10+
11+
## Scope
12+
13+
Changed only Preview Generator V2 live repo handle restoration/path/write verification and Workspace Manager V2 Playwright coverage for that behavior.
14+
15+
No `start_of_day` files were modified.
16+
17+
## Handle Source
18+
19+
The live handle is resolved from Workspace Manager V2 runtime state, not passed through or serialized inside toolState JSON.
20+
21+
Preview Generator V2 reads `workspace.repo.reference`, then restores the matching live repo handle from the Workspace Manager V2 repo handle cache:
22+
23+
- Test/runtime hook: `window.__workspaceManagerV2RepoHandleCache.restore({ reference })`
24+
- Browser fallback: IndexedDB cache `workspace-manager-v2-repo-handles` / `repo-handles` / `active-repo-handle`
25+
26+
`manifest.repoPath` is used for repo root path string and absolute display path reporting. It is not used as the write authority and is not compared as if it were handle-relative.
27+
28+
If no live Workspace Manager V2 repo handle can be restored, Preview Generator V2 logs the exact restore failure and required recovery action, leaves generation disabled, and does not claim `OK WRITE`.
29+
30+
## Validation
31+
32+
- `node --check tools/preview-generator-v2/PreviewGeneratorV2RepoAccess.js`
33+
- `node --check tools/preview-generator-v2/PreviewGeneratorV2App.js`
34+
- `node --check tests/playwright/tools/WorkspaceManagerV2.spec.mjs`
35+
- `npm run test:workspace-v2`: 23 passed
36+
- `git diff --check`: passed
37+
38+
Full samples smoke test was skipped because this PR is limited to Preview Generator V2 handle/path/write verification and does not modify shared sample loading, sample manifests, or broad sample runtime behavior.
39+
40+
## Playwright Coverage
41+
42+
Playwright impacted: Yes.
43+
44+
Validated behavior:
45+
46+
- Preview Generator V2 restores the Workspace Manager V2 live repo handle through `workspace.repo.reference` plus the runtime handle cache.
47+
- `preview.svg` writes are performed through the live handle and verified by read-back before `OK WRITE`.
48+
- Write logs include normalized path fields and SVG verification metadata.
49+
- Handle-relative output paths are not treated as mismatches against absolute display paths.
50+
- A forced read-back verification failure logs `FAIL`, records `Failed: 1`, and never logs `OK WRITE`.
51+
52+
Expected fail behavior: tests fail if Preview Generator V2 silently falls back to session-only writes, logs `OK WRITE` before successful read-back verification, or resurrects the absolute-vs-handle-relative mismatch warning.
53+
54+
## Coverage Notes
55+
56+
Runtime JavaScript coverage from `npm run test:workspace-v2` included changed Preview Generator V2 files:
57+
58+
- `(88%) tools/preview-generator-v2/PreviewGeneratorV2App.js - changed JS file with browser V8 coverage`
59+
- `(28%) tools/preview-generator-v2/PreviewGeneratorV2RepoAccess.js - advisory low coverage; cache restore branches include browser API and failure-path guards`
60+
61+
`tests/playwright/tools/WorkspaceManagerV2.spec.mjs` is a changed test file and is not collected as browser runtime coverage.
62+
63+
## Manual Test
64+
65+
1. Open Workspace Manager V2.
66+
2. Pick the repo folder and open Asteroids.
67+
3. Launch Preview Generator V2 from the Workspace Manager V2 tool tiles.
68+
4. Generate the workspace preview.
69+
5. Expected: status log shows live handle restoration, write read-back verification, normalized path fields, and `OK WRITE Asteroids`.
70+
6. Expected: no absolute path versus handle-relative path mismatch warning appears.
71+
72+
Out of scope: full sample smoke validation. Sample smoke remains skipped until a dedicated sample/runtime validation phase.
73+
74+
## Changed Files
75+
76+
- `docs/dev/codex_commands.md`
77+
- `docs/dev/commit_comment.txt`
78+
- `docs/dev/reports/PR_26130_006-preview-generator-handle-write-verification.md`
79+
- `tests/playwright/tools/WorkspaceManagerV2.spec.mjs`
80+
- `tools/preview-generator-v2/PreviewGeneratorV2App.js`
81+
- `tools/preview-generator-v2/PreviewGeneratorV2RepoAccess.js`

games/Asteroids/assets/images/preview.svg

Lines changed: 1 addition & 1 deletion
Loading

games/Asteroids/game.manifest.json

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,57 +36,62 @@
3636
{
3737
"symbol": "!",
3838
"hex": "#020617",
39-
"name": "Space Black"
39+
"name": "Space Black",
40+
"source": "manifest"
4041
},
4142
{
4243
"symbol": "#",
4344
"hex": "#FFFFFF",
44-
"name": "Vector White"
45+
"name": "Vector White",
46+
"source": "manifest"
4547
},
4648
{
4749
"symbol": "$",
4850
"hex": "#CBD5E1",
49-
"name": "Asteroid Gray"
51+
"name": "Asteroid Gray",
52+
"source": "manifest"
5053
},
5154
{
5255
"symbol": "%",
5356
"hex": "#DBEAFE",
54-
"name": "Saucer Glow"
57+
"name": "Saucer Glow",
58+
"source": "manifest"
5559
},
5660
{
5761
"symbol": "&",
5862
"hex": "#94A3B8",
59-
"name": "HUD Muted"
60-
},
61-
{
62-
"symbol": "(",
63-
"hex": "#FBBF24",
64-
"name": "Accent Amber"
63+
"name": "HUD Muted",
64+
"source": "manifest"
6565
},
6666
{
6767
"symbol": ")",
6868
"hex": "#F87171",
69-
"name": "Warning Red"
69+
"name": "Warning Red",
70+
"source": "manifest"
7071
},
7172
{
7273
"symbol": "*",
7374
"hex": "#78B7FF",
74-
"name": "HUD Blue"
75+
"name": "HUD Blue",
76+
"source": "manifest"
7577
},
7678
{
7779
"symbol": "+",
7880
"hex": "#FFBE64",
79-
"name": "HUD Gold"
81+
"name": "HUD Gold",
82+
"source": "manifest"
8083
},
8184
{
8285
"symbol": "0",
8386
"hex": "#05070D",
84-
"name": "HUD Color 1"
87+
"name": "HUD Color 1",
88+
"source": "manifest"
8589
},
8690
{
8791
"symbol": "1",
8892
"hex": "#DCE8FF",
89-
"name": "HUD Color 2"
93+
"name": "HUD Color 2",
94+
"source": "manifest"
9095
}
9196
]
9297
},

0 commit comments

Comments
 (0)