@@ -1541,64 +1541,115 @@ test('[P1] home hero example presets update the composer input for prototype and
15411541} ) ;
15421542
15431543test ( '[P1] live dashboard preset sends the active workspace name to plugin apply' , async ( { page } ) => {
1544+ const personalWorkspace = {
1545+ workspaceId : 'ws-personal' ,
1546+ workspaceName : 'Personal Workspace' ,
1547+ workspaceType : 'personal' ,
1548+ workspaceMemberId : 'wm-personal' ,
1549+ role : 'owner' ,
1550+ memberStatus : 'active' ,
1551+ lifecycleState : 'active' ,
1552+ } as const ;
1553+ const teamWorkspace = {
1554+ workspaceId : 'ws-qa' ,
1555+ workspaceName : 'QA Team' ,
1556+ workspaceType : 'team' ,
1557+ workspaceMemberId : 'wm-qa' ,
1558+ role : 'member' ,
1559+ memberStatus : 'active' ,
1560+ lifecycleState : 'active' ,
1561+ } as const ;
1562+ const workspaceContext = (
1563+ selected : typeof personalWorkspace | typeof teamWorkspace ,
1564+ includeWorkspaceName = false ,
1565+ ) => ( {
1566+ workspaceId : selected . workspaceId ,
1567+ workspaceType : selected . workspaceType ,
1568+ workspaceMemberId : selected . workspaceMemberId ,
1569+ role : selected . role ,
1570+ memberStatus : 'active' as const ,
1571+ lifecycleState : 'active' as const ,
1572+ billingState : 'active' as const ,
1573+ planId : selected . workspaceType === 'team' ? 'team' : null ,
1574+ providerMode : 'platform_credits' as const ,
1575+ seatSummary : {
1576+ seatLimit : 10 ,
1577+ usedSeats : 1 ,
1578+ availableSeats : 9 ,
1579+ isSeatFull : false ,
1580+ } ,
1581+ permissions : {
1582+ canInviteMembers : false ,
1583+ canManageMembers : false ,
1584+ canManageBilling : false ,
1585+ canManageAutoRecharge : false ,
1586+ canShareProjects : true ,
1587+ canWriteSyncedFiles : true ,
1588+ canViewWorkspaceSettings : true ,
1589+ canManageSharedResources : false ,
1590+ } ,
1591+ ...( includeWorkspaceName ? { workspaceName : selected . workspaceName } : { } ) ,
1592+ } ) ;
15441593 await page . route ( '**/api/workspace/directory' , async ( route ) => {
15451594 await route . fulfill ( {
15461595 json : {
1547- items : [ {
1548- workspaceId : 'ws-qa' ,
1549- workspaceName : 'QA Team' ,
1550- workspaceType : 'team' ,
1551- workspaceMemberId : 'wm-qa' ,
1552- role : 'member' ,
1553- memberStatus : 'active' ,
1554- lifecycleState : 'active' ,
1555- } ] ,
1596+ items : [ personalWorkspace , teamWorkspace ] ,
15561597 activeWorkspaceId : null ,
15571598 } ,
15581599 } ) ;
15591600 } ) ;
15601601 await page . route ( '**/api/workspace/context' , async ( route ) => {
1602+ const workspaceId = route . request ( ) . headers ( ) [ 'x-od-workspace-id' ] ;
1603+ const selected = workspaceId === teamWorkspace . workspaceId
1604+ ? teamWorkspace
1605+ : personalWorkspace ;
15611606 await route . fulfill ( {
15621607 json : {
1563- context : {
1564- workspaceId : 'ws-qa' ,
1565- workspaceType : 'team' ,
1566- workspaceMemberId : 'wm-qa' ,
1567- role : 'member' ,
1568- memberStatus : 'active' ,
1569- lifecycleState : 'active' ,
1570- billingState : 'active' ,
1571- planId : 'team' ,
1572- providerMode : 'platform_credits' ,
1573- seatSummary : {
1574- seatLimit : 10 ,
1575- usedSeats : 1 ,
1576- availableSeats : 9 ,
1577- isSeatFull : false ,
1578- } ,
1579- permissions : {
1580- canInviteMembers : false ,
1581- canManageMembers : false ,
1582- canManageBilling : false ,
1583- canManageAutoRecharge : false ,
1584- canShareProjects : true ,
1585- canWriteSyncedFiles : true ,
1586- canViewWorkspaceSettings : true ,
1587- canManageSharedResources : false ,
1588- } ,
1589- } ,
1608+ context : workspaceContext ( selected ) ,
1609+ } ,
1610+ } ) ;
1611+ } ) ;
1612+ await page . route ( '**/api/workspace/active' , async ( route ) => {
1613+ if ( route . request ( ) . method ( ) !== 'PUT' ) {
1614+ await route . fallback ( ) ;
1615+ return ;
1616+ }
1617+ const body = route . request ( ) . postDataJSON ( ) as {
1618+ workspaceId ?: unknown ;
1619+ workspaceMemberId ?: unknown ;
1620+ } ;
1621+ const selected = [ personalWorkspace , teamWorkspace ] . find (
1622+ ( item ) =>
1623+ item . workspaceId === body . workspaceId
1624+ && item . workspaceMemberId === body . workspaceMemberId ,
1625+ ) ;
1626+ if ( ! selected ) {
1627+ await route . fulfill ( { status : 400 , json : { error : 'exact_workspace_scope_required' } } ) ;
1628+ return ;
1629+ }
1630+ await route . fulfill ( {
1631+ json : {
1632+ activeWorkspaceId : selected . workspaceId ,
1633+ context : workspaceContext ( selected , true ) ,
15901634 } ,
15911635 } ) ;
15921636 } ) ;
15931637
15941638 await gotoEntryHome ( page ) ;
15951639 await page . getByTestId ( 'workspace-home-rail-toggle' ) . click ( ) ;
1596- await expect ( page . getByText ( 'QA Team' , { exact : true } ) ) . toBeVisible ( ) ;
1640+ await expect ( page . getByTestId ( 'workspace-switcher' ) ) . toContainText ( 'Personal Workspace' ) ;
15971641
15981642 await pickHomeTemplate ( page , 'live-artifact' ) ;
15991643 await usePreset ( page , 'example-live-dashboard' ) ;
16001644 await expect ( page . getByTestId ( 'home-hero-submit' ) ) . toBeEnabled ( ) ;
16011645
1646+ // The preset is already bound to Personal. Switching the request-local tab
1647+ // context must replace that context-owned input and invalidate the old apply
1648+ // snapshot before Send — no account-level active Workspace participates.
1649+ await page . getByTestId ( 'workspace-switcher' ) . click ( ) ;
1650+ await page . getByRole ( 'menuitem' , { name : 'QA Team' } ) . click ( ) ;
1651+ await expect ( page . getByTestId ( 'workspace-switcher' ) ) . toContainText ( 'QA Team' ) ;
1652+
16021653 const applyRequestPromise = page . waitForRequest ( ( request ) =>
16031654 request . method ( ) === 'POST'
16041655 && request . url ( ) . includes ( '/api/plugins/example-live-dashboard/apply' ) ,
0 commit comments