Files
orca/src/relay/workspace-session-handler.test.ts
T
NeilandOrca 46646d7ff1 chore(lint): upgrade oxlint to 1.71 + enable 7 new rules (autofixed backlog) (#6841)
* chore(lint): upgrade oxlint to 1.71 and enable 7 new rules

Upgrade oxlint 1.67.0 -> 1.71.0 (1.72 was blocked by the repo's 3-day
minimum-release-age supply-chain guard; nothing here needs it). The
bump is a no-op on the existing config.

Enable 3 error rules (backlog autofixed to zero in this commit) and
4 warn rules (surface signal without gating CI):

error (autofixed, behavior-preserving):
- unicorn/prefer-node-protocol        (~1531 sites: bare builtin -> node:)
- typescript/no-import-type-side-effects (~36: all-inline-type -> import type)
- unicorn/no-array-reverse            (19: copy-then-reverse -> toReversed)

warn (real signal, current fires are test-only/correct):
- unicorn/no-array-fill-with-reference-type  (aliasing footgun guard)
- typescript/no-unsafe-function-type         (bans bare Function type)
- unicorn/prefer-array-flat-map              (map().flat() -> flatMap())
- unicorn/prefer-regexp-test                 (.match() in bool ctx -> .test())

mobile/.oxlintrc.json extends root, so it inherits all 7; the autofix
ran from root and covered mobile/ too.

Verification (all green): oxlint 0 errors (root+mobile+aux configs),
oxfmt clean, typecheck (node+cli+web), vitest 22795 passed / 0 failed,
builds (electron-vite + web + cli) succeed. node: rewrites confirmed to
skip embedded SSH/CLI string payloads (AST-only); all toReversed sites
verified to operate on fresh copies or write-once locals.

* chore(lint): bump mobile oxlint to 1.71 so inherited rules parse

mobile/ is a standalone pnpm project pinning its own oxlint@1.67, which
lacks unicorn/no-array-fill-with-reference-type (needs >=1.70). Since
mobile/.oxlintrc.json extends the root config, mobile CI's 'cd mobile &&
oxlint' failed to parse the new rule. Bump mobile to match root (1.71).

Verified in mobile/: oxlint 0 errors, oxfmt --check clean, tsc --noEmit
pass, vitest 978 passed / 0 failed.

Co-authored-by: Orca <help@stably.ai>

---------

Co-authored-by: Orca <help@stably.ai>
2026-06-29 22:38:29 -07:00

143 lines
4.0 KiB
TypeScript

import { mkdtempSync, rmSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
import { RelayDispatcher } from './dispatcher'
import { WorkspaceSessionHandler } from './workspace-session-handler'
import { encodeJsonRpcFrame, MessageType, type JsonRpcRequest } from './protocol'
function decodeJsonFrames(written: Buffer[]): unknown[] {
return written
.filter((buf) => buf[0] === MessageType.Regular)
.map((buf) => {
const len = buf.readUInt32BE(9)
return JSON.parse(buf.subarray(13, 13 + len).toString('utf-8')) as unknown
})
}
async function sendRequest(
dispatcher: RelayDispatcher,
method: string,
params: Record<string, unknown>,
id: number
): Promise<void> {
const req: JsonRpcRequest = {
jsonrpc: '2.0',
id,
method,
params
}
dispatcher.feed(encodeJsonRpcFrame(req, id, 0))
await Promise.resolve()
}
describe('WorkspaceSessionHandler', () => {
let baseDir: string
let dispatcher: RelayDispatcher
let written: Buffer[]
beforeEach(() => {
baseDir = mkdtempSync(join(tmpdir(), 'orca-workspace-session-'))
written = []
dispatcher = new RelayDispatcher((data) => {
written.push(Buffer.from(data))
})
new WorkspaceSessionHandler(dispatcher, baseDir)
})
afterEach(() => {
dispatcher.dispose()
rmSync(baseDir, { recursive: true, force: true })
})
it('stores snapshots atomically and rejects stale revisions', async () => {
const session = {
activeWorktreePath: '/repo/worktree',
activeTabId: 'tab-1',
tabsByWorktreePath: {
'/repo/worktree': [{ id: 'tab-1', title: 'Terminal', worktreePath: '/repo/worktree' }]
},
terminalLayoutsByTabId: {}
}
await sendRequest(
dispatcher,
'workspace.patch',
{
namespace: 'ssh target/path',
baseRevision: 0,
clientId: 'client-a',
patch: { kind: 'replace-session', session }
},
1
)
const frames = decodeJsonFrames(written)
const response = frames.find((frame) => (frame as { id?: number }).id === 1) as {
result: { ok: boolean; snapshot: { revision: number; session: unknown } }
}
expect(response.result.ok).toBe(true)
expect(response.result.snapshot.revision).toBe(1)
expect(response.result.snapshot.session).toEqual(session)
expect(
frames.some((frame) => (frame as { method?: string }).method === 'workspace.changed')
).toBe(true)
written = []
await sendRequest(
dispatcher,
'workspace.patch',
{
namespace: 'ssh target/path',
baseRevision: 0,
clientId: 'client-b',
patch: { kind: 'replace-session', session: { ...session, activeTabId: 'tab-2' } }
},
2
)
const staleResponse = decodeJsonFrames(written).find(
(frame) => (frame as { id?: number }).id === 2
) as { result: { ok: boolean; reason: string; snapshot: { revision: number } } }
expect(staleResponse.result.ok).toBe(false)
expect(staleResponse.result.reason).toBe('stale-revision')
expect(staleResponse.result.snapshot.revision).toBe(1)
})
it('tracks presence per namespace', async () => {
await sendRequest(
dispatcher,
'workspace.presence',
{
namespace: 'team',
clientId: 'client-a',
clientName: ' Laptop A '
},
1
)
await sendRequest(
dispatcher,
'workspace.presence',
{
namespace: 'team',
clientId: 'client-b',
clientName: 'Laptop B'
},
2
)
const response = decodeJsonFrames(written).find(
(frame) => (frame as { id?: number }).id === 2
) as {
result: { clients: { clientId: string; name: string }[] }
}
expect(response.result.clients.map((client) => client.clientId).sort()).toEqual([
'client-a',
'client-b'
])
expect(response.result.clients.find((client) => client.clientId === 'client-a')?.name).toBe(
'Laptop A'
)
})
})