Skip to content

Commit b527561

Browse files
author
DavidQ
committed
Fix Workspace V2 Session Library save semantics for new session IDs - PR_11_266
1 parent 35c7b82 commit b527561

3 files changed

Lines changed: 56 additions & 10 deletions

File tree

docs/dev/reports/PR_11_266_session_tools_closeout_bundle_report.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,26 @@ Workspace V2 only:
5757
## Full Samples Smoke Decision
5858
- Full samples smoke test was skipped.
5959
- Reason: changes are tightly scoped to Workspace V2 session UX/state handling and were covered by targeted runtime tests.
60+
61+
62+
## Continuation Fix (Session Library Save Behavior)
63+
- Adjusted Session Library action behavior so `Save Session` no longer requires the entered ID to pre-resolve to sessionStorage/recent history.
64+
- `Save Session` now creates a new saved entry when:
65+
- session ID is non-empty
66+
- session ID is not already saved
67+
- a valid current Workspace V2 payload is available (resolved from entered ID, recent/history, active session, or current payload)
68+
- `Overwrite Session`, `Load Session`, and `Delete Saved Session` continue to require existing saved library entries.
69+
- Updated status messages to clearly distinguish:
70+
- new ID save success
71+
- overwrite/load/delete existing entry requirements
72+
- missing/invalid active save source
73+
74+
### Additional Files Updated
75+
- tests/runtime/V2SessionLibraryActions.test.mjs
76+
77+
### Additional Validation
78+
1. `node --check tests/runtime/V2SessionLibraryActions.test.mjs`
79+
- PASS
80+
2. `node tests/runtime/V2SessionLibraryActions.test.mjs`
81+
- PASS
82+
- Results: `tmp/v2-session-library-actions-results.json`

tests/runtime/V2SessionLibraryActions.test.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function evaluateSaveAction(inputId, activePayload, library) {
4040
return { message: "Saved session already exists. Use Overwrite Session.", library: libraryMap };
4141
}
4242
libraryMap[sessionId] = activePayload;
43-
return { message: "Saved session created.", library: libraryMap };
43+
return { message: "Saved session created. New session ID is now available for Load, Overwrite, and Delete.", library: libraryMap };
4444
}
4545

4646
function evaluateOverwriteAction(inputId, activePayload, library) {
@@ -132,7 +132,7 @@ export function run() {
132132
"Enter a session ID before saving.",
133133
"No active Workspace V2 session is available to save.",
134134
"Saved session already exists. Use Overwrite Session.",
135-
"Saved session created.",
135+
"Saved session created. New session ID is now available for Load, Overwrite, and Delete.",
136136
"Enter a session ID before overwriting.",
137137
"No active Workspace V2 session is available to overwrite from.",
138138
"Saved session not found. Use Save Session to create it first.",
@@ -174,7 +174,7 @@ export function run() {
174174
if (emptyDelete.message !== "Enter a saved session ID before deleting.") failures.push("Delete empty input message mismatch.");
175175

176176
const saveCreated = evaluateSaveAction("saved-a", activePayload, {});
177-
if (saveCreated.message !== "Saved session created." || !Object.prototype.hasOwnProperty.call(saveCreated.library, "saved-a")) {
177+
if (saveCreated.message !== "Saved session created. New session ID is now available for Load, Overwrite, and Delete." || !Object.prototype.hasOwnProperty.call(saveCreated.library, "saved-a")) {
178178
failures.push("Save with valid active payload should create library entry.");
179179
}
180180

tools/workspace-v2/index.js

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,25 @@ class WorkspaceV2SessionProducer {
673673
return parsed.value;
674674
}
675675

676+
readSessionPayloadForSaveAction(sessionId) {
677+
const storagePayload = this.readSessionPayloadForLibraryWrite(sessionId);
678+
if (this.isValidSessionPayload(storagePayload)) {
679+
return storagePayload;
680+
}
681+
const recentPayload = this.readSessionPayloadFromRecentSessionId(sessionId);
682+
if (this.isValidSessionPayload(recentPayload)) {
683+
return recentPayload;
684+
}
685+
const activePayload = this.readActiveSessionPayloadForLibraryActions();
686+
if (this.isValidSessionPayload(activePayload)) {
687+
return activePayload;
688+
}
689+
if (this.isValidSessionPayload(this.currentSessionPayload)) {
690+
return this.currentSessionPayload;
691+
}
692+
return null;
693+
}
694+
676695
selectedMergedSessionId() {
677696
return typeof this.mergedSessionIdNode.value === "string" ? this.mergedSessionIdNode.value.trim() : "";
678697
}
@@ -2680,23 +2699,27 @@ class WorkspaceV2SessionProducer {
26802699
return;
26812700
}
26822701
const exists = Object.prototype.hasOwnProperty.call(library, sessionName);
2702+
if (overwriteExisting && !exists) {
2703+
this.setLibraryStatus("Saved session not found. Use Save Session to create it first.");
2704+
return;
2705+
}
26832706
if (!overwriteExisting && exists) {
26842707
this.setLibraryStatus("Saved session already exists. Use Overwrite Session.");
26852708
return;
26862709
}
2687-
const payloadForWrite = this.readSessionPayloadForLibraryWrite(sessionName);
2710+
const payloadForWrite = this.readSessionPayloadForSaveAction(sessionName);
26882711
if (!this.isValidSessionPayload(payloadForWrite)) {
2689-
this.setLibraryStatus("Session ID does not resolve to a valid Workspace V2 session.");
2690-
return;
2691-
}
2692-
if (overwriteExisting && !exists) {
2693-
this.setLibraryStatus("Saved session not found. Use Save Session to create it first.");
2712+
this.setLibraryStatus(overwriteExisting
2713+
? "No active Workspace V2 session is available to overwrite from."
2714+
: "No active Workspace V2 session is available to save.");
26942715
return;
26952716
}
26962717
library[sessionName] = payloadForWrite;
26972718
this.writeSessionLibrary(library);
26982719
this.renderSessionLibrary();
2699-
this.setLibraryStatus(overwriteExisting ? "Saved session overwritten." : "Saved session created.");
2720+
this.setLibraryStatus(overwriteExisting
2721+
? "Saved session overwritten."
2722+
: "Saved session created. New session ID is now available for Load, Overwrite, and Delete.");
27002723
}
27012724

27022725
loadNamedSession() {

0 commit comments

Comments
 (0)