Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions config/scripts/check-focus-read-ratchet.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,7 @@ const ADVICE =
"Route by the resource's owner. Only a creation flow with no source row may use defaultCreationHost."

export function isScannedPath(rel) {
return (
/\.(ts|tsx)$/.test(rel) &&
!/\.(test|spec)(?:-fixture)?\.tsx?$/.test(rel)
)
return /\.(ts|tsx)$/.test(rel) && !/\.(test|spec)(?:-fixture)?\.tsx?$/.test(rel)
}

// One read and one discovery per root per run; `--prune` then `main` reuse them.
Expand Down
4 changes: 3 additions & 1 deletion src/main/ipc/pty-launch-parity.test-fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ export function startParityLanes(
// A folder's contained repo is saved too, so the host can borrow its runtime if it would.
const repo =
scopeRepo ??
(args.workspace.repoPath ? launchScope({ kind: 'repo', path: args.workspace.repoPath }).repo : null)
(args.workspace.repoPath
? launchScope({ kind: 'repo', path: args.workspace.repoPath }).repo
: null)
const store = {
getSettings: () => settings,
getProjects: () => [
Expand Down
137 changes: 75 additions & 62 deletions src/main/ipc/worktrees-canonical-ssh-listing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,71 +147,84 @@ describe.each([
})
})

it.each(['git', 'folder'] as const)('projects exact known SSH %s endpoints without building foreign repos', async (kind) => {
const { repo, store } = fixture({ connectionId: 'host-a' })
const parentInstance = '11111111-2222-3333-4444-555555555555'
const parentPath = `/remote/parent::workspace:${parentInstance}`
const parentRepo = hydrateRepo(
{ ...repo, id: 'parent-repo', kind, path: kind === 'folder' ? '/remote/parent' : parentPath, displayName: 'parent' },
new Map()
)
const childId = 'repo::/remote/repository'
const parentId = `parent-repo::${parentPath}`
const metaById: Record<string, WorktreeMeta> = {
[childId]: mergeWorktreeMetaForWrite(undefined, {
hostId: 'ssh:host-a',
instanceId: 'child-instance',
projectId: 'child-project'
}),
[parentId]: mergeWorktreeMetaForWrite(undefined, {
hostId: 'ssh:host-a',
instanceId: parentInstance,
projectId: 'parent-project'
it.each(['git', 'folder'] as const)(
'projects exact known SSH %s endpoints without building foreign repos',
async (kind) => {
const { repo, store } = fixture({ connectionId: 'host-a' })
const parentInstance = '11111111-2222-3333-4444-555555555555'
const parentPath = `/remote/parent::workspace:${parentInstance}`
const parentRepo = hydrateRepo(
{
...repo,
id: 'parent-repo',
kind,
path: kind === 'folder' ? '/remote/parent' : parentPath,
displayName: 'parent'
},
new Map()
)
const childId = 'repo::/remote/repository'
const parentId = `parent-repo::${parentPath}`
const metaById: Record<string, WorktreeMeta> = {
[childId]: mergeWorktreeMetaForWrite(undefined, {
hostId: 'ssh:host-a',
instanceId: 'child-instance',
projectId: 'child-project'
}),
[parentId]: mergeWorktreeMetaForWrite(undefined, {
hostId: 'ssh:host-a',
instanceId: parentInstance,
projectId: 'parent-project'
})
}
if (kind === 'folder') {
metaById[parentId].instanceId = undefined
}
store.setWorktreeMeta.mockImplementation((id: string, updates: Partial<WorktreeMeta>) => {
const meta = mergeWorktreeMetaForWrite(metaById[id], updates)
metaById[id] = meta
return meta
})
}
if (kind === 'folder') {
metaById[parentId].instanceId = undefined
}
store.setWorktreeMeta.mockImplementation((id: string, updates: Partial<WorktreeMeta>) => {
const meta = mergeWorktreeMetaForWrite(metaById[id], updates)
metaById[id] = meta
return meta
})
Object.assign(store, {
getRepos: () => [repo, parentRepo],
getAllWorktreeMeta: () => metaById,
getWorktreeMeta: (id: string) => metaById[id],
getAllWorktreeLineage: () => ({
[childId]: {
worktreeId: childId,
worktreeInstanceId: 'child-instance',
parentWorktreeId: parentId,
parentWorktreeInstanceId: parentInstance,
origin: 'cli',
capture: { source: 'explicit-cli-flag', confidence: 'explicit' },
createdAt: 1
}
Object.assign(store, {
getRepos: () => [repo, parentRepo],
getAllWorktreeMeta: () => metaById,
getWorktreeMeta: (id: string) => metaById[id],
getAllWorktreeLineage: () => ({
[childId]: {
worktreeId: childId,
worktreeInstanceId: 'child-instance',
parentWorktreeId: parentId,
parentWorktreeInstanceId: parentInstance,
origin: 'cli',
capture: { source: 'explicit-cli-flag', confidence: 'explicit' },
createdAt: 1
}
})
})
})

const child = await invoke('known')
expect(child).toMatchObject({
status: 'complete',
result: { worktrees: [expect.objectContaining({ id: childId, parentWorktreeId: parentId })] }
})
expect(store.setWorktreeMeta).not.toHaveBeenCalledWith(parentId, expect.anything())
const parent = mocks.handlers.get('worktrees:listKnownForExecutionHost')!(null, {
repoId: parentRepo.id,
executionHostId: 'ssh:host-a'
})
expect(parent).toMatchObject({
status: 'complete',
result: { worktrees: [
...(kind === 'folder' ? [expect.objectContaining({ id: 'parent-repo::/remote/parent' })] : []),
expect.objectContaining({ id: parentId, childWorktreeIds: [childId] })
] }
})
})
const child = await invoke('known')
expect(child).toMatchObject({
status: 'complete',
result: { worktrees: [expect.objectContaining({ id: childId, parentWorktreeId: parentId })] }
})
expect(store.setWorktreeMeta).not.toHaveBeenCalledWith(parentId, expect.anything())
const parent = mocks.handlers.get('worktrees:listKnownForExecutionHost')!(null, {
repoId: parentRepo.id,
executionHostId: 'ssh:host-a'
})
expect(parent).toMatchObject({
status: 'complete',
result: {
worktrees: [
...(kind === 'folder'
? [expect.objectContaining({ id: 'parent-repo::/remote/parent' })]
: []),
expect.objectContaining({ id: parentId, childWorktreeIds: [childId] })
]
}
})
}
)

it.each([undefined, 'nested'])(
'keeps runtime rows out of local cache and root registration: %s',
Expand Down
1 change: 1 addition & 0 deletions src/main/runtime/rpc/methods/terminal/stream-schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const TerminalMultiplexSubscribeFrame = TerminalHandle.extend({
ackOutputSourceRanges: z.literal(1).optional(),
desktopViewportClaims: z.literal(1).optional(),
outputPause: z.literal(1).optional(),
outputPauseDropNotice: z.literal(1).optional(),
writeUnavailable: z.literal(1).optional(),
inputAck: z.literal(1).optional()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
encodeTerminalStreamText
} from '../../../../../shared/terminal-stream-protocol'
import { appendAckPendingOutput } from './terminal-stream-replay'
import { notePausedOutputDropped } from './terminal-multiplex-paused-output-drop'
import {
isMultiplexStreamAttached,
type TerminalMultiplexConnection
Expand Down Expand Up @@ -121,7 +122,11 @@ export function installMultiplexFrameDelivery(state: TerminalMultiplexConnection
stream: TerminalMultiplexStream,
chunk: TerminalOutputFrameChunk
): void => {
if (!isMultiplexStreamAttached(state, stream) || stream.outputPaused) {
if (!isMultiplexStreamAttached(state, stream)) {
return
}
if (stream.outputPaused) {
notePausedOutputDropped(state, stream)
return
}
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export async function publishMultiplexInitialSnapshot(
...((stream.supportsOutputPause || stream.inputSessionId !== null) && {
capabilities: {
...(stream.supportsOutputPause ? { outputPause: 1 as const } : {}),
...(stream.supportsOutputPauseDropNotice ? { outputPauseDropNotice: 1 as const } : {}),
...(stream.inputSessionId !== null ? { inputAck: 1 as const } : {})
}
}),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { TerminalStreamOpcode } from '../../../../../shared/terminal-stream-protocol'
import type { TerminalMultiplexConnection } from './terminal-multiplex-connection'
import type { TerminalMultiplexStream } from './terminal-stream-types'

/** Tells a negotiated client that this pause discarded output, so its reveal must restore. */
export function notePausedOutputDropped(
state: Pick<TerminalMultiplexConnection, 'sendFrame'>,
stream: TerminalMultiplexStream
): void {
if (!stream.supportsOutputPauseDropNotice || stream.pausedOutputDropNoticeSent) {
return
}
// Why mark before send: a failed send means the link is going down, and resubscribe repaints anyway.
stream.pausedOutputDropNoticeSent = true
state.sendFrame(stream.streamId, TerminalStreamOpcode.PausedOutputDropped)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
serializeBudgetedRequestedSnapshot
} from './terminal-snapshot-publication'
import { updateViewportForClient } from './terminal-viewport-update'
import { notePausedOutputDropped } from './terminal-multiplex-paused-output-drop'
import {
isMultiplexStreamAttached,
type MultiplexSnapshotRequest,
Expand Down Expand Up @@ -80,10 +81,17 @@ export function installMultiplexSlotFrames(state: TerminalMultiplexConnection):
}
stream.outputPaused = payload.paused
if (stream.outputPaused) {
stream.pausedOutputDropNoticeSent = false
const discardsQueuedOutput =
stream.ackPendingOutput.length > 0 || stream.ackPendingOutputOverflowed
// Why: batched bytes flush into the paused gate, which reports them as dropped.
stream.outputBatcher.flush()
stream.ackPendingOutput = []
stream.ackPendingOutputBytes = 0
stream.ackPendingOutputOverflowed = false
if (discardsQueuedOutput) {
notePausedOutputDropped(state, stream)
}
}
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { TERMINAL_MULTIPLEX_ACK_STREAM_INITIAL_WINDOW_BYTES } from '../../../../
import { createTerminalOutputBatcher } from './terminal-output-batcher'
import { appendPendingMultiplexOutput } from './terminal-stream-replay'
import { updateViewportForClient } from './terminal-viewport-update'
import { notePausedOutputDropped } from './terminal-multiplex-paused-output-drop'
import {
isMultiplexStreamAttached,
type MultiplexSubscribeRequest,
Expand All @@ -33,6 +34,9 @@ export async function initializeMultiplexStream(
ackInFlightBytes: 0,
ackWindowBytes: TERMINAL_MULTIPLEX_ACK_STREAM_INITIAL_WINDOW_BYTES,
supportsOutputPause: request.capabilities?.outputPause === 1,
supportsOutputPauseDropNotice:
request.capabilities?.outputPause === 1 && request.capabilities.outputPauseDropNotice === 1,
pausedOutputDropNoticeSent: false,
supportsWriteUnavailable: request.capabilities?.writeUnavailable === 1,
inputSessionId: request.capabilities?.inputAck === 1 ? (request.inputSessionId ?? null) : null,
outputPaused: false,
Expand Down Expand Up @@ -84,6 +88,7 @@ export async function initializeMultiplexStream(
return
}
if (stream.outputPaused) {
notePausedOutputDropped(state, stream)
return
}
if (stream.buffering) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ export type TerminalMultiplexStream = {
ackInFlightBytes: number
ackWindowBytes: number
supportsOutputPause: boolean
// Why: lets the client skip the reveal snapshot when a pause discarded nothing.
supportsOutputPauseDropNotice: boolean
pausedOutputDropNoticeSent: boolean
supportsWriteUnavailable: boolean
// Set only when the client negotiated `inputAck`; sequenced Input frames are then deduped and acked.
inputSessionId: string | null
Expand Down
112 changes: 112 additions & 0 deletions src/main/runtime/rpc/terminal-multiplex-paused-output-drop.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import './unused-default-rpc-methods.test-fixture'
import { describe, expect, it, vi } from 'vitest'
import type { RuntimeTerminalDataMeta } from '../orca-runtime'
import {
TerminalStreamOpcode,
decodeTerminalStreamFrame,
encodeTerminalStreamFrame,
encodeTerminalStreamJson
} from '../../../shared/terminal-stream-protocol'
import { startDesktopMultiplexSubscribe } from './terminal-multiplex-test-harness'

async function subscribePausable(capabilities: Record<string, 1>) {
const listeners: ((data: string, meta?: RuntimeTerminalDataMeta) => void)[] = []
const harness = startDesktopMultiplexSubscribe({
subscribeToTerminalData: vi.fn((_ptyId, listener) => {
listeners.push(listener)
return vi.fn()
})
})
await vi.waitFor(() => expect(harness.handlers.has(0)).toBe(true))
harness.handlers.get(0)?.(
decodeTerminalStreamFrame(
encodeTerminalStreamFrame({
opcode: TerminalStreamOpcode.Subscribe,
streamId: 0,
seq: 1,
payload: encodeTerminalStreamJson({
streamId: 1,
terminal: 'terminal-1',
client: { id: 'desktop-1', type: 'desktop' },
capabilities
})
})
)!
)
const subscribedEvent = () =>
harness.messages
.map((message) => JSON.parse(message).result)
.find((event) => event?.type === 'subscribed' && event.streamId === 1)
await vi.waitFor(() => expect(subscribedEvent()).toBeDefined())
let seq = 0
let frameSeq = 10
const setPaused = (paused: boolean): void =>
harness.handlers.get(1)?.(
decodeTerminalStreamFrame(
encodeTerminalStreamFrame({
opcode: TerminalStreamOpcode.SetOutputPaused,
streamId: 1,
seq: frameSeq++,
payload: encodeTerminalStreamJson({ paused })
})
)!
)
const emitOutput = (text: string): void => {
seq += text.length
listeners[0]?.(text, { seq, rawLength: text.length })
}
const dropNotices = (): number =>
harness.binaryFrames.filter(
(bytes) =>
decodeTerminalStreamFrame(bytes)?.opcode === TerminalStreamOpcode.PausedOutputDropped
).length
const close = async (): Promise<void> => {
harness.registry.cleanupSubscription('terminal-multiplex:conn-desktop-first-paint')
await harness.dispatchPromise
}
return { subscribed: subscribedEvent(), setPaused, emitOutput, dropNotices, close }
}

describe('terminal multiplex paused-output drop notice', () => {
it('announces a pause only when it actually discarded output', async () => {
const host = await subscribePausable({ ackOutput: 1, outputPause: 1, outputPauseDropNotice: 1 })
expect(host.subscribed.capabilities).toMatchObject({ outputPause: 1, outputPauseDropNotice: 1 })

host.setPaused(true)
host.setPaused(false)
expect(host.dropNotices()).toBe(0)

host.setPaused(true)
host.emitOutput('hidden-1')
host.emitOutput('hidden-2')
expect(host.dropNotices()).toBe(1)
host.setPaused(false)
host.emitOutput('visible')
expect(host.dropNotices()).toBe(1)

// Each pause reports independently.
host.setPaused(true)
host.emitOutput('hidden-3')
expect(host.dropNotices()).toBe(2)
await host.close()
})

it('announces output still batched when the pause lands', async () => {
const host = await subscribePausable({ ackOutput: 1, outputPause: 1, outputPauseDropNotice: 1 })
host.emitOutput('batched-before-pause')
host.setPaused(true)
expect(host.dropNotices()).toBe(1)
await host.close()
})

it('never sends the frame to a client that did not negotiate it', async () => {
const host = await subscribePausable({ ackOutput: 1, outputPause: 1 })
expect(host.subscribed.capabilities?.outputPauseDropNotice).toBeUndefined()

host.setPaused(true)
host.emitOutput('hidden')
host.setPaused(false)
expect(host.dropNotices()).toBe(0)
await host.close()
})
})
Loading
Loading