diff --git a/src/main/runtime/rpc/methods/workspace-layout-apply.test.ts b/src/main/runtime/rpc/methods/workspace-layout-apply.test.ts index 62c9feea3a0..724c3e64443 100644 --- a/src/main/runtime/rpc/methods/workspace-layout-apply.test.ts +++ b/src/main/runtime/rpc/methods/workspace-layout-apply.test.ts @@ -9,8 +9,12 @@ import { MOBILE_RPC_METHOD_ALLOWLIST } from '../../runtime-rpc/runtime-rpc-mobil import { OrcaRuntimeService } from '../../orca-runtime' import { eraseRpcMethods, isStreamingMethod, type RpcContext } from '../core' import { LAYOUT_APPLY_METHODS } from './workspace-layout' +import { ALL_RPC_METHODS } from './index' import { partialRuntimeStore, type PartialRuntimeStore } from '../../runtime-store-partial-fixture' +// Pin a window-owned build even under `ORCA_LAYOUT_OWNER=main`, so the default registry omits layout commands. +vi.mock('../../../../shared/layout-owner-switch', () => ({ ORCA_LAYOUT_OWNER_IS_MAIN: false })) + const frozen = vi.hoisted(() => ({ workspaces: new Set() })) vi.mock( '../../../persistence/moving-wsl-projects/wsl-move-scope-guard', @@ -29,15 +33,6 @@ const SPLIT = { direction: 'vertical' } as const -async function registeredMethods(layoutOwnerIsMain: boolean) { - vi.resetModules() - vi.doMock('../../../../shared/layout-owner-switch', () => ({ - ORCA_LAYOUT_OWNER_IS_MAIN: layoutOwnerIsMain - })) - const { ALL_RPC_METHODS } = await import('./index') - return eraseRpcMethods(ALL_RPC_METHODS) -} - function sessionListing(tabId: string): WorkspaceSessionState { return { activeRepoId: null, @@ -84,21 +79,22 @@ function runtimeHolding(hostId: ExecutionHostId) { afterEach(() => { frozen.workspaces.clear() - vi.doUnmock('../../../../shared/layout-owner-switch') - vi.resetModules() }) describe('layout.apply', () => { - it('is not registered in a window-owned build, and never advertised or open to phones', async () => { - const methods = await registeredMethods(false) - - expect(methods.some((method) => method.name === 'layout.apply')).toBe(false) + it('is not registered in a window-owned build, and never advertised or open to phones', () => { + const names = ALL_RPC_METHODS.map((method) => method.name) + for (const name of ['layout.apply', 'layout.reopenHeldPanes', 'layout.reportView']) { + expect(names, name).not.toContain(name) + } expect(RUNTIME_CAPABILITIES.some((capability) => capability.startsWith('layout'))).toBe(false) expect(MOBILE_RPC_METHOD_ALLOWLIST.has('layout.apply')).toBe(false) }) - it('is registered in a layout-owner build; a split keeps only a valid window pane id', async () => { - const apply = (await registeredMethods(true)).find((method) => method.name === 'layout.apply') + it('keeps only a valid window pane id on a split', async () => { + const apply = eraseRpcMethods(LAYOUT_APPLY_METHODS).find( + (method) => method.name === 'layout.apply' + ) if (!apply || isStreamingMethod(apply)) { throw new Error('layout.apply is not a request method') } @@ -450,7 +446,9 @@ describe('layout.apply', () => { }) it('takes an open into a new split under the window’s group id, on every open kind', async () => { - const apply = (await registeredMethods(true)).find((method) => method.name === 'layout.apply') + const apply = eraseRpcMethods(LAYOUT_APPLY_METHODS).find( + (method) => method.name === 'layout.apply' + ) const parse = (command: Record) => apply?.params?.safeParse({ command }) const split = { besideGroupId: 'g1', direction: 'right' } const opens = [ diff --git a/src/main/runtime/rpc/methods/workspace-layout-paired-desktop.test.ts b/src/main/runtime/rpc/methods/workspace-layout-paired-desktop.test.ts index 2790e429fc9..0dfc7c786bf 100644 --- a/src/main/runtime/rpc/methods/workspace-layout-paired-desktop.test.ts +++ b/src/main/runtime/rpc/methods/workspace-layout-paired-desktop.test.ts @@ -28,17 +28,10 @@ vi.mock('../../../../shared/layout-owner-switch', () => ({ } })) -// Rebuild the registry under this environment switch. -async function switchedBuild(layoutOwnerIsMain: boolean) { - layoutOwner.isMain = layoutOwnerIsMain - vi.resetModules() - const [{ OrcaRuntimeService }, { RpcDispatcher }, { ALL_RPC_METHODS }] = await Promise.all([ - import('../../orca-runtime'), - import('../dispatcher'), - import('./index') - ]) - return { OrcaRuntimeService, RpcDispatcher, ALL_RPC_METHODS } -} +// Loaded once as a layout-owner build; window-owned registration is covered in workspace-layout-apply.test.ts. +import { OrcaRuntimeService } from '../../orca-runtime' +import { RpcDispatcher } from '../dispatcher' +import { ALL_RPC_METHODS } from './index' const Frame = z.object({ type: z.string(), subscriptionId: z.string().optional() }) const StreamReply = z.object({ ok: z.literal(true), result: Frame }) @@ -56,23 +49,20 @@ afterEach(() => { }) describe('the layout intents capability', () => { - it('is advertised only by a layout-owner build', async () => { - const on = await switchedBuild(true) - expect(new on.OrcaRuntimeService().getStatus().capabilities).toEqual( + it('is advertised only by a layout-owner build', () => { + expect(new OrcaRuntimeService().getStatus().capabilities).toEqual( expect.arrayContaining([ LAYOUT_INTENTS_RUNTIME_CAPABILITY, LAYOUT_REOPEN_HELD_PANES_CAPABILITY ]) ) - const off = await switchedBuild(false) - const offCapabilities = new off.OrcaRuntimeService().getStatus().capabilities + layoutOwner.isMain = false + const offCapabilities = new OrcaRuntimeService().getStatus().capabilities expect(offCapabilities).not.toContain(LAYOUT_INTENTS_RUNTIME_CAPABILITY) expect(offCapabilities).not.toContain(LAYOUT_REOPEN_HELD_PANES_CAPABILITY) - expect(off.ALL_RPC_METHODS.map((method) => method.name)).not.toContain('layout.reopenHeldPanes') }) - it('comes with the layout methods registered', async () => { - const { ALL_RPC_METHODS } = await switchedBuild(true) + it('comes with the layout methods registered', () => { const registered = new Set(ALL_RPC_METHODS.map((method) => method.name)) for (const method of LAYOUT_METHODS) { expect(registered.has(method), method).toBe(true) @@ -88,7 +78,6 @@ describe('layout methods on a layout-owner server', () => { ['layout.reopenHeldPanes', 'invalid_argument'], ['layout.reportView', 'invalid_argument'] ] as const)('admits a paired desktop and refuses a phone: %s', async (method, nextCheck) => { - const { OrcaRuntimeService, RpcDispatcher } = await switchedBuild(true) const dispatcher = new RpcDispatcher({ runtime: new OrcaRuntimeService() }) const asDesktop = await dispatcher.dispatch(request(method, { bad: 1 }), { callerScope: PAIRED_DESKTOP @@ -99,7 +88,6 @@ describe('layout methods on a layout-owner server', () => { }) it('streams a snapshot to a paired desktop', async () => { - const { OrcaRuntimeService, RpcDispatcher } = await switchedBuild(true) const runtime = new OrcaRuntimeService() const dispatcher = new RpcDispatcher({ runtime }) const frames: z.infer[] = [] @@ -128,7 +116,6 @@ describe('layout.reportView', () => { } it("records the desktop's groups under its connection", async () => { - const { OrcaRuntimeService, RpcDispatcher } = await switchedBuild(true) const runtime = new OrcaRuntimeService() const reported = vi.spyOn(runtime, 'reportClientView') const dispatcher = new RpcDispatcher({ runtime }) @@ -141,7 +128,6 @@ describe('layout.reportView', () => { }) it('passes a refresh on as one', async () => { - const { OrcaRuntimeService, RpcDispatcher } = await switchedBuild(true) const runtime = new OrcaRuntimeService() const reported = vi.spyOn(runtime, 'reportClientView') const reply = await new RpcDispatcher({ runtime }).dispatch( @@ -153,7 +139,6 @@ describe('layout.reportView', () => { }) it('refuses a caller with no connection to tie the report to', async () => { - const { OrcaRuntimeService, RpcDispatcher } = await switchedBuild(true) const runtime = new OrcaRuntimeService() const reported = vi.spyOn(runtime, 'reportClientView') const reply = await new RpcDispatcher({ runtime }).dispatch( @@ -171,7 +156,6 @@ describe('layout.reportView', () => { [{ activeGroupByWorkspace: ['g1'] }], [{ activeGroupByWorkspace: {}, refresh: false }] ])('refuses params it cannot read: %j', async (params) => { - const { OrcaRuntimeService, RpcDispatcher } = await switchedBuild(true) const runtime = new OrcaRuntimeService() const reported = vi.spyOn(runtime, 'reportClientView') const reply = await new RpcDispatcher({ runtime }).dispatch( @@ -181,11 +165,6 @@ describe('layout.reportView', () => { expect(errorCode(reply)).toBe('invalid_argument') expect(reported).not.toHaveBeenCalled() }) - - it('is not registered by a window-owned build', async () => { - const { ALL_RPC_METHODS } = await switchedBuild(false) - expect(ALL_RPC_METHODS.map((method) => method.name)).not.toContain('layout.reportView') - }) }) describe('an older desktop on a layout-owner server', () => { @@ -228,7 +207,6 @@ describe('an older desktop on a layout-owner server', () => { /** A windowless (serve) host: no notifier, its tabs already published. */ async function headlessServer() { - const { OrcaRuntimeService, RpcDispatcher } = await switchedBuild(true) class HeadlessServer extends OrcaRuntimeService { seed(): void { this.storeMobileSessionSnapshot(WT, published())