@@ -147,6 +147,16 @@ async function expectWorkspaceToolsDisabled(page) {
147147 expect ( await page . locator ( "#workspaceToolTiles [data-workspace-tool-id]" ) . evaluateAll ( ( tiles ) => tiles . every ( ( tile ) => tile . disabled ) ) ) . toBe ( true ) ;
148148}
149149
150+ async function expectWorkspaceReturnRehydrated ( page , { gameId = "Asteroids" , repoName = "HTML-JavaScript-Gaming" } = { } ) {
151+ await expect ( page . locator ( "#repoSelectedValue" ) ) . toHaveText ( repoName ) ;
152+ await expect ( page . locator ( "#activeGameSelect" ) ) . toHaveValue ( gameId ) ;
153+ await expect ( page . locator ( "#exportManifestButton" ) ) . toBeEnabled ( ) ;
154+ await expect ( page . locator ( '[data-workspace-tool-id="asset-manager-v2"]' ) ) . toBeEnabled ( ) ;
155+ await expect ( page . locator ( '[data-workspace-tool-id="palette-manager-v2"]' ) ) . toBeEnabled ( ) ;
156+ await expect ( page . locator ( '[data-workspace-tool-id="preview-generator-v2"]' ) ) . toBeEnabled ( ) ;
157+ await expect ( page . locator ( '[data-workspace-tool-id="session-inspector-v2"]' ) ) . toBeEnabled ( ) ;
158+ }
159+
150160async function readWorkspaceSessionHydration ( page ) {
151161 return await page . evaluate ( ( ) => {
152162 const parseJson = ( key ) => {
@@ -1662,10 +1672,12 @@ test.describe("Workspace Manager V2 bootstrap", () => {
16621672 expect ( JSON . stringify ( storedContext ) ) . not . toMatch ( / s a m p l e s \/ / i) ;
16631673 await page . locator ( "#returnToWorkspaceButton" ) . click ( ) ;
16641674 await expect ( page ) . toHaveURL ( / w o r k s p a c e - m a n a g e r - v 2 \/ i n d e x \. h t m l \? h o s t C o n t e x t I d = w o r k s p a c e - m a n a g e r - v 2 - / ) ;
1675+ await expectWorkspaceReturnRehydrated ( page ) ;
16651676 await expect ( page . locator ( "#activeGameSelect" ) ) . toHaveValue ( "Asteroids" ) ;
16661677 await expect ( page . locator ( "#activeAssetRegistrySummary" ) ) . toHaveCount ( 0 ) ;
16671678 await expect ( page . locator ( '[data-workspace-tool-id="asset-manager-v2"]' ) ) . toBeEnabled ( ) ;
16681679 await expect ( page . locator ( "#exportManifestButton" ) ) . toBeEnabled ( ) ;
1680+ await expect ( page . locator ( "#statusLog" ) ) . toHaveValue ( / O K R e s t o r e d r e p o d e s t i n a t i o n f r o m w o r k s p a c e \. r e p o \. r e f e r e n c e f o r H T M L - J a v a S c r i p t - G a m i n g \. / ) ;
16691681 await expect ( page . locator ( "#statusLog" ) ) . toHaveValue ( / O K R e s t o r e d A s t e r o i d s w o r k s p a c e f r o m s e s s i o n c o n t e x t w o r k s p a c e - m a n a g e r - v 2 - / ) ;
16701682
16711683 await page . locator ( '[data-workspace-tool-id="palette-manager-v2"]' ) . click ( ) ;
@@ -1679,6 +1691,8 @@ test.describe("Workspace Manager V2 bootstrap", () => {
16791691 await expect ( page . locator ( "#paletteStatus" ) ) . toHaveText ( "Loaded active workspace palette Asteroids Palette." ) ;
16801692 await page . locator ( "#returnToWorkspaceButton" ) . click ( ) ;
16811693 await expect ( page ) . toHaveURL ( / w o r k s p a c e - m a n a g e r - v 2 \/ i n d e x \. h t m l \? h o s t C o n t e x t I d = w o r k s p a c e - m a n a g e r - v 2 - / ) ;
1694+ await expectWorkspaceReturnRehydrated ( page ) ;
1695+ await expect ( page . locator ( "#statusLog" ) ) . toHaveValue ( / O K R e s t o r e d r e p o d e s t i n a t i o n f r o m w o r k s p a c e \. r e p o \. r e f e r e n c e f o r H T M L - J a v a S c r i p t - G a m i n g \. / ) ;
16821696 await expect ( previewTile ) . toBeEnabled ( ) ;
16831697 await expect ( previewTile ) . toContainText ( "Schema-valid manifest" ) ;
16841698 await page . locator ( '[data-workspace-tool-id="preview-generator-v2"]' ) . click ( ) ;
@@ -1740,6 +1754,8 @@ test.describe("Workspace Manager V2 bootstrap", () => {
17401754 expect ( previewWrites [ 0 ] . contents ) . not . toContain ( "Capture timeout" ) ;
17411755 await page . locator ( "#returnToWorkspaceButton" ) . click ( ) ;
17421756 await expect ( page ) . toHaveURL ( / w o r k s p a c e - m a n a g e r - v 2 \/ i n d e x \. h t m l \? h o s t C o n t e x t I d = w o r k s p a c e - m a n a g e r - v 2 - / ) ;
1757+ await expectWorkspaceReturnRehydrated ( page ) ;
1758+ await expect ( page . locator ( "#statusLog" ) ) . toHaveValue ( / O K R e s t o r e d r e p o d e s t i n a t i o n f r o m w o r k s p a c e \. r e p o \. r e f e r e n c e f o r H T M L - J a v a S c r i p t - G a m i n g \. / ) ;
17431759 expect ( pageErrors ) . toEqual ( [ ] ) ;
17441760 } finally {
17451761 await coverageReporter . stop ( page ) ;
@@ -1790,6 +1806,50 @@ test.describe("Workspace Manager V2 bootstrap", () => {
17901806 }
17911807 } ) ;
17921808
1809+ test ( "blocks Workspace Manager V2 return restore when repo session reference is missing or invalid" , async ( { page } ) => {
1810+ const pageErrors = [ ] ;
1811+ const hostContextId = "workspace-manager-v2-missing-return-repo-reference" ;
1812+ const gameManifest = JSON . parse ( await readFile ( "games/Asteroids/game.manifest.json" , "utf8" ) ) ;
1813+ const manifest = gameManifest . game . workspace ;
1814+ await page . addInitScript ( ( { contextId, workspaceManifest } ) => {
1815+ window . sessionStorage . setItem ( contextId , JSON . stringify ( workspaceManifest ) ) ;
1816+ } , { contextId : hostContextId , workspaceManifest : manifest } ) ;
1817+ const server = await openWorkspaceManagerV2 ( page , `?hostContextId=${ hostContextId } ` ) ;
1818+
1819+ page . on ( "pageerror" , ( error ) => {
1820+ pageErrors . push ( error . message ) ;
1821+ } ) ;
1822+
1823+ try {
1824+ await expect ( page . locator ( "#repoSelectedValue" ) ) . toHaveText ( "not selected" ) ;
1825+ await expect ( page . locator ( "#activeGameSelect" ) ) . toBeDisabled ( ) ;
1826+ await expect ( page . locator ( "#activeGameSelect option" ) ) . toHaveCount ( 0 ) ;
1827+ await expect ( page . locator ( "#exportManifestButton" ) ) . toBeDisabled ( ) ;
1828+ await expect ( page . locator ( "#workspaceContextOutput" ) ) . toHaveValue ( "{}" ) ;
1829+ await expectWorkspaceToolsDisabled ( page ) ;
1830+ await expect ( page . locator ( "#activeGameSummary" ) ) . toHaveText ( "workspace.repo.reference was not found in sessionStorage. Pick Repo Folder to reselect repo before launching tools." ) ;
1831+ await expect ( page . locator ( "#statusLog" ) ) . toHaveValue ( / F A I L W o r k s p a c e r e s t o r e f a i l e d : w o r k s p a c e \. r e p o \. r e f e r e n c e w a s n o t f o u n d i n s e s s i o n S t o r a g e \. P i c k R e p o F o l d e r t o r e s e l e c t r e p o b e f o r e l a u n c h i n g t o o l s \. / ) ;
1832+ expect ( await readWorkspaceSessionHydration ( page ) ) . toMatchObject ( {
1833+ repoReference : null ,
1834+ toolKeys : [ ]
1835+ } ) ;
1836+
1837+ await page . evaluate ( ( { contextId, workspaceManifest } ) => {
1838+ window . sessionStorage . setItem ( contextId , JSON . stringify ( workspaceManifest ) ) ;
1839+ window . sessionStorage . setItem ( "workspace.repo.reference" , "not-json" ) ;
1840+ } , { contextId : hostContextId , workspaceManifest : manifest } ) ;
1841+ await page . goto ( `${ server . baseUrl } /tools/workspace-manager-v2/index.html?hostContextId=${ hostContextId } ` , { waitUntil : "networkidle" } ) ;
1842+ await expect ( page . locator ( "#repoSelectedValue" ) ) . toHaveText ( "not selected" ) ;
1843+ await expect ( page . locator ( "#activeGameSelect" ) ) . toBeDisabled ( ) ;
1844+ await expectWorkspaceToolsDisabled ( page ) ;
1845+ await expect ( page . locator ( "#statusLog" ) ) . toHaveValue ( / F A I L W o r k s p a c e r e s t o r e f a i l e d : w o r k s p a c e \. r e p o \. r e f e r e n c e c o n t a i n s i n v a l i d J S O N : / ) ;
1846+ expect ( pageErrors ) . toEqual ( [ ] ) ;
1847+ } finally {
1848+ await coverageReporter . stop ( page ) ;
1849+ await server . close ( ) ;
1850+ }
1851+ } ) ;
1852+
17931853 test ( "opens Preview Generator V2 workspace launch with actionable missing repo session status" , async ( { page } ) => {
17941854 const server = await startRepoServer ( ) ;
17951855 const pageErrors = [ ] ;
0 commit comments