mirror of
https://github.com/stablyai/orca.git
synced 2026-11-18 11:54:46 +00:00
test: remove low-value boundary and coordination tests (#43466)
Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
# This is a RATCHET: counts may only go DOWN. Run `pnpm lint:ast-grep:flaky-tests` to list them.
|
||||
# Prune after a fix: pnpm check:flaky-test-pattern-ratchet --prune
|
||||
4 test-no-in-test-import-actual:src/main/bitbucket/credential-store.test.ts
|
||||
1 test-no-in-test-import-actual:src/main/bitbucket/status-no-decrypt.test.ts
|
||||
4 test-no-in-test-import-actual:src/main/daemon/endpoint/publication/testing/daemon-endpoint-publish.test.ts
|
||||
1 test-no-in-test-import-actual:src/main/daemon/history/storage/testing/terminal-history-permissions.test.ts
|
||||
1 test-no-in-test-import-actual:src/main/git/command-runner/process-capture/spawned-command-tree-kill.test.ts
|
||||
|
||||
@@ -568,7 +568,6 @@
|
||||
"src/main/automations/service-precheck.test.ts": 2057,
|
||||
"src/main/automations/automation-service.test.ts": 2970,
|
||||
"src/main/bitbucket/credential-store.test.ts": 245,
|
||||
"src/main/bitbucket/status-no-decrypt.test.ts": 256,
|
||||
"src/main/browser/agent-browser/observation/agent-browser-action-effects.test.ts": 487,
|
||||
"src/main/browser/agent-browser/command-queue/agent-browser-bridge-host-revocation.test.ts": 1017,
|
||||
"src/main/browser/agent-browser/command-queue/agent-browser-bridge-javascript-dialog.test.ts": 358,
|
||||
@@ -1028,7 +1027,6 @@
|
||||
"src/main/daemon/permissions/testing/daemon-folder-access-mismatch.test.ts": 220,
|
||||
"src/main/daemon/permissions/testing/daemon-folder-access-probe-script.test.ts": 198,
|
||||
"src/main/daemon/permissions/testing/daemon-folder-access-reset.test.ts": 226,
|
||||
"src/main/daemon/health/testing/daemon-health-socket-cleanup.test.ts": 135,
|
||||
"src/main/daemon/health/testing/daemon-health.test.ts": 4438,
|
||||
"src/main/daemon/executable-host/windows/testing/daemon-host-current-version-reclaim.test.ts": 350,
|
||||
"src/main/daemon/executable-host/windows/testing/daemon-host-entry-layout.test.ts": 204,
|
||||
@@ -2049,7 +2047,6 @@
|
||||
"src/main/runtime/browser-host/leases/browser-host-lease-registry.test.ts": 184,
|
||||
"src/main/runtime/browser-host/reconciliation/browser-host-page-reconciliation-preconditions.test.ts": 129,
|
||||
"src/main/runtime/browser/network/browser-network-tunnel-paired-runtime.integration.test.ts": 5293,
|
||||
"src/main/runtime/browser/screencast/browser-screencast-renderer-throttle-lease.test.ts": 5665,
|
||||
"src/main/runtime/browser/tabs/browser-session-tab-selection-snapshot.test.ts": 45,
|
||||
"src/main/runtime/browser/screencast/browser-screencasts.test.ts": 632,
|
||||
"src/main/runtime/terminal/agent-teams/claude-agent-teams-service.test.ts": 115,
|
||||
@@ -2618,7 +2615,6 @@
|
||||
"src/main/runtime/terminal/layout/agent-generated-tab-titles.test.ts": 5572,
|
||||
"src/main/runtime/terminal/lifecycle/main-pane-liveness.test.ts": 4871,
|
||||
"src/main/runtime/terminal/lifecycle/ssh-exit-code-pane-outcome.test.ts": 4334,
|
||||
"src/main/runtime/terminal/query/terminal-identity-read-context.test.ts": 5310,
|
||||
"src/main/runtime/terminal/stop/exact-terminal-stop-liveness.test.ts": 4321,
|
||||
"src/main/runtime/terminal/stop/terminal-update-admission.test.ts": 48,
|
||||
"src/main/runtime/terminal/surface/terminal-surface-replies-main.test.ts": 4324,
|
||||
@@ -4487,7 +4483,6 @@
|
||||
"tests/e2e/structured-agent-session-launch-admission.unit.test.ts": 4762,
|
||||
"tests/e2e/structured-attention-headless-delivery.unit.test.ts": 328,
|
||||
"tests/e2e/terminal-perf-presentation.unit.test.ts": 60,
|
||||
"tests/e2e/worktree-status-warning.unit.test.ts": 2331,
|
||||
"tests/tools/omp-close-lifecycle.test.mjs": 403,
|
||||
"tests/tools/omp-config-root-relay-shell.test.mjs": 297,
|
||||
"tests/tools/relay-bench/phone-e2ee-desktop-parity.test.mjs": 111,
|
||||
|
||||
@@ -1,142 +0,0 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { agentJournalItemKey } from '../../shared/agent-session/journal/agent-session-journal-item-key'
|
||||
import type { OrcaRuntimeService } from '../runtime/orca-runtime'
|
||||
import { buildProfileStateCutoverFixture } from '../persistence/profile-state-cutover-fixture'
|
||||
import { observeAutomationChatRun } from './observation/runtime-chat-run-observer'
|
||||
import type { StructuredAgentSessionHost } from '../native-chat/agent-session-wire/host/structured-agent-session-host'
|
||||
import { createQueuedMessageTestRig } from '../native-chat/agent-session-wire/host/testing/structured-agent-session-queued-message-rig.test-fixture'
|
||||
import { eventually } from '../native-chat/agent-session-wire/host/testing/structured-agent-session-queued-message-rig-provider.test-fixture'
|
||||
import {
|
||||
HOST_TEST_SESSION,
|
||||
HOST_TEST_THREAD,
|
||||
hostTestMessage
|
||||
} from '../native-chat/agent-session-wire/host/testing/structured-agent-session-host-test-data.test-fixture'
|
||||
import { AGENT_JOURNAL_THREAD_SCOPE } from '../../shared/agent-session/journal/agent-session-journal-types'
|
||||
import { automationRunOperationId } from './launch/automation-run-operation'
|
||||
|
||||
const mocks = vi.hoisted(() => {
|
||||
const hostState: { actualHost: StructuredAgentSessionHost | null } = { actualHost: null }
|
||||
return {
|
||||
...hostState,
|
||||
host: {
|
||||
automationRun: vi.fn(),
|
||||
observeConversationPublications: vi.fn(),
|
||||
queuedSendAnswer: vi.fn(async () => null)
|
||||
}
|
||||
}
|
||||
})
|
||||
vi.mock('../native-chat/agent-session-wire/host/structured-agent-session-registry', () => ({
|
||||
getStructuredAgentSessionHost: () => mocks.actualHost ?? mocks.host
|
||||
}))
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
mocks.actualHost = null
|
||||
})
|
||||
afterEach(() => {
|
||||
vi.useRealTimers()
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
describe('real host queue publication', () => {
|
||||
it('follows a queued run through handover and returns its exact output', async () => {
|
||||
const rig = await createQueuedMessageTestRig({ restartable: true })
|
||||
mocks.actualHost = rig.host
|
||||
const controller = new AbortController()
|
||||
try {
|
||||
const working = await rig.workingSend()
|
||||
const journal = rig.host.collaboratorsForTests().sessions.get(HOST_TEST_SESSION)!.journal
|
||||
const run = {
|
||||
...buildProfileStateCutoverFixture('/fixture').automationRuns[0],
|
||||
// ast-grep-ignore: test-no-wall-clock -- Match the observer's expiry clock.
|
||||
createdAt: Date.now(),
|
||||
// ast-grep-ignore: test-no-wall-clock -- Match the observer's expiry clock.
|
||||
dispatchedAt: Date.now(),
|
||||
sessionKind: 'chat' as const,
|
||||
chatSessionId: HOST_TEST_SESSION
|
||||
}
|
||||
const q = automationRunOperationId(run, 'reuse-send')
|
||||
const fields = {
|
||||
body: hostTestMessage('automation behind human backlog'),
|
||||
delivery: 'queue-if-active' as const
|
||||
}
|
||||
expect(
|
||||
await rig.host.send(
|
||||
{ callerKey: 'client-1' },
|
||||
{
|
||||
...fields,
|
||||
envelope: rig.envelope(fields, 'agentSession.send', q)
|
||||
}
|
||||
)
|
||||
).toMatchObject({ ok: true, value: { queued: { messageId: q, state: 'waiting' } } })
|
||||
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: only runtime initialization and receipt lookup are scripted; the host owns delivery and observation.
|
||||
const runtime = {
|
||||
ensureStructuredAgentSessionHost: async () => {},
|
||||
openAgentSessionRecordStore: async () => ({
|
||||
getOperationRow: (_caller: string, id: string) =>
|
||||
id === q
|
||||
? { outcome: { status: 'succeeded', sessionId: HOST_TEST_SESSION } }
|
||||
: undefined,
|
||||
getConversation: () => ({ provider: 'codex', location: { workspaceId: 'workspace-1' } })
|
||||
})
|
||||
} as unknown as OrcaRuntimeService
|
||||
const pending = observeAutomationChatRun(runtime, run, controller.signal)
|
||||
void pending.catch(() => {})
|
||||
await rig.settleAccepted(working, 'human')
|
||||
let sink = rig.providerEvents()
|
||||
sink.appendItem(
|
||||
{ provider: 'codex', threadId: HOST_TEST_THREAD, turnId: 'turn-human', ordinal: 1 },
|
||||
{ kind: 'turn', turnId: 'turn-human', state: 'completed', outcome: 'success' },
|
||||
{ turnScope: AGENT_JOURNAL_THREAD_SCOPE, lifecycle: true }
|
||||
)
|
||||
sink.publish({ lifecycle: true })
|
||||
expect(await sink.written?.()).toEqual({ ok: true })
|
||||
await rig.host.flushStreamedEvents(HOST_TEST_SESSION)
|
||||
const sent = await vi.waitFor(() => rig.handoffId(q), { timeout: 10_000 })
|
||||
expect(sent).not.toBe(q)
|
||||
await eventually(async () =>
|
||||
expect((await journal.reads.submission(sent))?.handedOverAt).toBeDefined()
|
||||
)
|
||||
await rig.settleAccepted(sent, 'automation')
|
||||
const accepted = await journal.reads.submission(sent)
|
||||
sink = rig.providerEvents()
|
||||
const ownId = {
|
||||
provider: 'codex' as const,
|
||||
threadId: HOST_TEST_THREAD,
|
||||
turnId: 'turn-automation',
|
||||
ordinal: 1
|
||||
}
|
||||
sink.appendItem(
|
||||
ownId,
|
||||
{
|
||||
kind: 'turn',
|
||||
turnId: 'turn-automation',
|
||||
userItemId: accepted!.providerItemId!,
|
||||
state: 'completed',
|
||||
outcome: 'success'
|
||||
},
|
||||
{ turnScope: AGENT_JOURNAL_THREAD_SCOPE, lifecycle: true }
|
||||
)
|
||||
sink.appendItem(
|
||||
{ ...ownId, ordinal: 2 },
|
||||
{
|
||||
kind: 'message',
|
||||
role: 'assistant',
|
||||
blocks: [{ type: 'text', text: 'Exact automation output' }]
|
||||
},
|
||||
{ turnScope: { kind: 'turn', turnItemId: agentJournalItemKey(ownId) } }
|
||||
)
|
||||
sink.publish({ lifecycle: true })
|
||||
expect(await sink.written?.()).toEqual({ ok: true })
|
||||
await rig.host.flushStreamedEvents(HOST_TEST_SESSION)
|
||||
expect(await pending).toMatchObject({
|
||||
status: 'completed',
|
||||
outputSnapshot: { content: 'Exact automation output' }
|
||||
})
|
||||
expect(rig.dispatch).toHaveBeenCalledTimes(2)
|
||||
} finally {
|
||||
controller.abort()
|
||||
mocks.actualHost = null
|
||||
await rig.dispose()
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -1,103 +0,0 @@
|
||||
import { mkdtempSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import type * as Os from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
const decryptSpy = vi.fn((value: Buffer) => value.toString('utf-8'))
|
||||
const OLD_ENV = process.env
|
||||
const OLD_FETCH = globalThis.fetch
|
||||
let tempHome = ''
|
||||
|
||||
vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({
|
||||
...(await importOriginal<Record<string, unknown>>()),
|
||||
gitExecFileAsync: vi.fn()
|
||||
}))
|
||||
|
||||
async function loadModules() {
|
||||
vi.resetModules()
|
||||
const { setSecretStore } = await import('../../shared/secure-storage/secret-store')
|
||||
setSecretStore({
|
||||
isEncryptionAvailable: () => true,
|
||||
encryptString: (value) => Buffer.from(value),
|
||||
decryptString: decryptSpy,
|
||||
describeProtectionGap: () => null
|
||||
})
|
||||
vi.doMock('node:os', async () => {
|
||||
const actual = await vi.importActual<typeof Os>('node:os')
|
||||
return { ...actual, homedir: () => tempHome }
|
||||
})
|
||||
vi.doMock('./repository-ref', () => ({
|
||||
getBitbucketRepoRef: async () => ({ workspace: 'acme', repoSlug: 'app' })
|
||||
}))
|
||||
const store = await import('./credential-store')
|
||||
const client = await import('./client')
|
||||
const connection = await import('./credential-connection')
|
||||
return { store, client, connection }
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
process.env = { ...OLD_ENV }
|
||||
for (const key of [
|
||||
'ORCA_BITBUCKET_ACCESS_TOKEN',
|
||||
'ORCA_BITBUCKET_EMAIL',
|
||||
'ORCA_BITBUCKET_API_TOKEN',
|
||||
'ORCA_BITBUCKET_API_BASE_URL'
|
||||
]) {
|
||||
delete process.env[key]
|
||||
}
|
||||
tempHome = mkdtempSync(join(tmpdir(), 'orca-bb-nodecrypt-'))
|
||||
decryptSpy.mockClear()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
process.env = OLD_ENV
|
||||
globalThis.fetch = OLD_FETCH
|
||||
})
|
||||
|
||||
const STORED_BASIC_CREDENTIAL = {
|
||||
authMode: 'basic',
|
||||
email: 'ada@example.com',
|
||||
baseUrl: null,
|
||||
account: 'ada',
|
||||
accessToken: null,
|
||||
apiToken: 'secret-token'
|
||||
} as const
|
||||
|
||||
describe('Bitbucket status reads never decrypt the stored secret', () => {
|
||||
it('renders connected state from plaintext metadata without touching the keychain', async () => {
|
||||
const { store, client, connection } = await loadModules()
|
||||
const fetchSpy = vi.fn()
|
||||
globalThis.fetch = fetchSpy as unknown as typeof fetch
|
||||
store.saveBitbucketCredential(STORED_BASIC_CREDENTIAL)
|
||||
|
||||
// Clear memory only to simulate relaunch with the credential still on disk.
|
||||
store._resetBitbucketCredentialCache()
|
||||
decryptSpy.mockClear()
|
||||
|
||||
const auth = await client.getBitbucketAuthStatus()
|
||||
const status = connection.getBitbucketConnectionStatus()
|
||||
|
||||
expect(auth).toEqual({ configured: true, authenticated: true, account: 'ada' })
|
||||
expect(status).toMatchObject({ source: 'stored', account: 'ada', authMode: 'basic' })
|
||||
expect(decryptSpy).not.toHaveBeenCalled()
|
||||
expect(fetchSpy).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('revalidates a stored credential once its secret is already warm in memory', async () => {
|
||||
const { store, client } = await loadModules()
|
||||
store.saveBitbucketCredential(STORED_BASIC_CREDENTIAL)
|
||||
decryptSpy.mockClear()
|
||||
|
||||
const fetchSpy = vi.fn(async () => new Response(null, { status: 401 }))
|
||||
globalThis.fetch = fetchSpy as unknown as typeof fetch
|
||||
|
||||
await expect(client.getBitbucketAuthStatus()).resolves.toEqual({
|
||||
configured: true,
|
||||
authenticated: false,
|
||||
account: 'ada'
|
||||
})
|
||||
expect(fetchSpy).toHaveBeenCalledTimes(1)
|
||||
expect(decryptSpy).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
@@ -1,69 +0,0 @@
|
||||
import { EventEmitter } from 'node:events'
|
||||
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
const { netConnectMock } = vi.hoisted(() => ({
|
||||
netConnectMock: vi.fn()
|
||||
}))
|
||||
|
||||
vi.mock('net', () => ({ connect: netConnectMock }))
|
||||
|
||||
import { healthCheckDaemon } from '../daemon-health'
|
||||
import { killStaleDaemon } from '../../launch/daemon-stale-kill'
|
||||
|
||||
class FakeSocket extends EventEmitter {
|
||||
destroy = vi.fn()
|
||||
write = vi.fn()
|
||||
}
|
||||
|
||||
describe('daemon health socket listener cleanup', () => {
|
||||
let dir: string
|
||||
let socketPath: string
|
||||
let tokenPath: string
|
||||
|
||||
beforeEach(() => {
|
||||
dir = mkdtempSync(join(tmpdir(), 'daemon-health-socket-cleanup-'))
|
||||
socketPath = join(dir, 'daemon.sock')
|
||||
tokenPath = join(dir, 'daemon.token')
|
||||
writeFileSync(socketPath, '')
|
||||
writeFileSync(tokenPath, 'token')
|
||||
netConnectMock.mockReset()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
vi.useRealTimers()
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
})
|
||||
|
||||
it('removes health-check socket listeners after a timeout', async () => {
|
||||
vi.useFakeTimers()
|
||||
const socket = new FakeSocket()
|
||||
netConnectMock.mockReturnValueOnce(socket)
|
||||
|
||||
const result = healthCheckDaemon(socketPath, tokenPath)
|
||||
await vi.advanceTimersByTimeAsync(3_000)
|
||||
|
||||
await expect(result).resolves.toBe(false)
|
||||
expect(socket.listenerCount('connect')).toBe(0)
|
||||
expect(socket.listenerCount('error')).toBe(0)
|
||||
expect(socket.listenerCount('data')).toBe(0)
|
||||
expect(socket.destroy).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('removes stale-socket probe listeners after a timeout', async () => {
|
||||
vi.useFakeTimers()
|
||||
const socket = new FakeSocket()
|
||||
netConnectMock.mockReturnValueOnce(socket)
|
||||
|
||||
const result = killStaleDaemon(dir, socketPath, tokenPath)
|
||||
await vi.advanceTimersByTimeAsync(500)
|
||||
|
||||
// The publisher re-probes before replacing, so an unknown launcher hint can allow a fork.
|
||||
await expect(result).resolves.toEqual({ killed: false, liveOwnerSurvived: false })
|
||||
expect(socket.listenerCount('connect')).toBe(0)
|
||||
expect(socket.listenerCount('error')).toBe(0)
|
||||
expect(socket.destroy).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
})
|
||||
@@ -50,25 +50,4 @@ describe('runCoalescedProbe', () => {
|
||||
await expect(joinedRequest).resolves.toBe('new')
|
||||
expect(probes).toEqual(new Map())
|
||||
})
|
||||
|
||||
it('removes a settled probe only when it still owns the key', async () => {
|
||||
const probes: CoalescedProbes<string> = new Map()
|
||||
const first = deferred<string>()
|
||||
const second = deferred<string>()
|
||||
const createProbe = vi
|
||||
.fn<() => Promise<string>>()
|
||||
.mockReturnValueOnce(first.promise)
|
||||
.mockReturnValueOnce(second.promise)
|
||||
|
||||
const firstRequest = runCoalescedProbe(probes, 'repo', createProbe, 1)
|
||||
vi.advanceTimersByTime(2)
|
||||
const secondRequest = runCoalescedProbe(probes, 'repo', createProbe, 1)
|
||||
|
||||
first.reject(new Error('old probe failed'))
|
||||
await expect(firstRequest).rejects.toThrow('old probe failed')
|
||||
expect(probes.get('repo')?.promise).toBe(second.promise)
|
||||
|
||||
second.resolve('new')
|
||||
await expect(secondRequest).resolves.toBe('new')
|
||||
})
|
||||
})
|
||||
|
||||
-127
@@ -1,127 +0,0 @@
|
||||
/** Hidden host compositors must keep drawing while remote streams need guest frames. */
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import type { BrowserScreencastOptions } from '../../../browser/cdp/screencast/browser-screencast-stream-types'
|
||||
import { createScreencastHarness } from './browser-screencast-subscriber-test-harness'
|
||||
import { RuntimeBrowserCommands } from '../commands/browser-commands'
|
||||
import { createSinglePageBrowserCommandsHost } from '../client-pages/single-page-browser-commands-host-test-double'
|
||||
|
||||
const { webContentsFromId, startBrowserScreencast } = vi.hoisted(() => ({
|
||||
webContentsFromId: vi.fn(),
|
||||
startBrowserScreencast: vi.fn()
|
||||
}))
|
||||
|
||||
vi.mock('electron', () => ({
|
||||
ipcMain: { on: vi.fn(), removeListener: vi.fn(), handle: vi.fn(), removeHandler: vi.fn() },
|
||||
webContents: { fromId: webContentsFromId }
|
||||
}))
|
||||
vi.mock('../../../browser/cdp/screencast/browser-screencast-stream', () => ({
|
||||
startBrowserScreencast
|
||||
}))
|
||||
|
||||
type PageStream = { options: BrowserScreencastOptions; close: () => void }
|
||||
|
||||
function createRig() {
|
||||
const { runtime } = createScreencastHarness()
|
||||
const setBackgroundThrottling = vi.fn()
|
||||
const window = {
|
||||
webContents: {
|
||||
isDestroyed: () => false,
|
||||
setBackgroundThrottling,
|
||||
capturePage: vi.fn(async () => null)
|
||||
}
|
||||
}
|
||||
const guestCalls: unknown[] = []
|
||||
const guest = {
|
||||
destroyed: false,
|
||||
isDestroyed: () => guest.destroyed,
|
||||
isLoading: () => false,
|
||||
setBackgroundThrottling: (allowed: boolean) => guestCalls.push(allowed),
|
||||
capturePage: async (rect: unknown, opts: unknown) => {
|
||||
guestCalls.push({ capture: rect, opts })
|
||||
return null
|
||||
}
|
||||
}
|
||||
webContentsFromId.mockReturnValue(guest)
|
||||
Object.assign(runtime, {
|
||||
browserCommands: new RuntimeBrowserCommands(createSinglePageBrowserCommandsHost(window))
|
||||
})
|
||||
const pageStreams: PageStream[] = []
|
||||
// Model asynchronous teardown: stopping does not close the held stream yet.
|
||||
const stopControl = { hold: false }
|
||||
startBrowserScreencast.mockImplementation(
|
||||
async (_guest: unknown, options: BrowserScreencastOptions) => {
|
||||
let close!: () => void
|
||||
const done = new Promise<void>((resolve) => {
|
||||
close = resolve
|
||||
})
|
||||
pageStreams.push({ options, close })
|
||||
return {
|
||||
stop: () => {
|
||||
if (!stopControl.hold) {
|
||||
close()
|
||||
}
|
||||
},
|
||||
done,
|
||||
updateViewport: vi.fn(async () => {}),
|
||||
updateFrameBudget: vi.fn(async () => {})
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
const subscribe = (connectionId: string, signal?: AbortSignal) => {
|
||||
const emit = vi.fn()
|
||||
const done = runtime.browserScreencast(
|
||||
{ worktree: 'id:wt-1', page: 'page-1', format: 'jpeg' },
|
||||
{ connectionId, clientKind: 'mobile', sendBinary: vi.fn(() => true), signal, emit }
|
||||
)
|
||||
const ready = async (): Promise<string> => {
|
||||
await vi.waitFor(() =>
|
||||
expect(emit).toHaveBeenCalledWith(expect.objectContaining({ type: 'ready' }))
|
||||
)
|
||||
return emit.mock.calls.find(([event]) => event.type === 'ready')?.[0].subscriptionId
|
||||
}
|
||||
const eventTypes = (): string[] => emit.mock.calls.map(([event]) => event.type)
|
||||
return { done, ready, eventTypes }
|
||||
}
|
||||
|
||||
return {
|
||||
runtime,
|
||||
subscribe,
|
||||
pageStreams,
|
||||
stopControl,
|
||||
throttleCalls: () => setBackgroundThrottling.mock.calls.map(([allowed]) => allowed),
|
||||
guest,
|
||||
guestCalls
|
||||
}
|
||||
}
|
||||
|
||||
describe('remote browser screencast renderer throttle lease', () => {
|
||||
beforeEach(() => {
|
||||
webContentsFromId.mockReset()
|
||||
webContentsFromId.mockReturnValue({ isDestroyed: () => false })
|
||||
startBrowserScreencast.mockReset()
|
||||
})
|
||||
|
||||
// Unsubscribe, disconnect, ghost eviction and page close all settle through done.
|
||||
|
||||
it('starts a fresh stream for a viewer that joins while the errored one tears down', async () => {
|
||||
const rig = createRig()
|
||||
const phone = rig.subscribe('conn-phone')
|
||||
await phone.ready()
|
||||
rig.stopControl.hold = true
|
||||
|
||||
rig.pageStreams[0].options.onError?.('Browser stream timed out.')
|
||||
const guestLookups = webContentsFromId.mock.calls.length
|
||||
const tablet = rig.subscribe('conn-tablet')
|
||||
await vi.waitFor(() =>
|
||||
expect(webContentsFromId.mock.calls.length).toBeGreaterThan(guestLookups)
|
||||
)
|
||||
await new Promise((resolve) => setImmediate(resolve))
|
||||
rig.pageStreams[0].close()
|
||||
await tablet.ready()
|
||||
|
||||
expect(startBrowserScreencast).toHaveBeenCalledTimes(2)
|
||||
expect(tablet.eventTypes()).toEqual(['ready'])
|
||||
await phone.done
|
||||
})
|
||||
})
|
||||
@@ -89,35 +89,4 @@ describe('TerminalFocusNavigationCoalescer', () => {
|
||||
await expect(first).resolves.toEqual({ id: 'a', navigated: false })
|
||||
await expect(latest).resolves.toEqual({ id: 'b', navigated: true })
|
||||
})
|
||||
|
||||
it('propagates run failures without stranding the queue', async () => {
|
||||
const coalescer = new TerminalFocusNavigationCoalescer<string>()
|
||||
const aGate = deferred<void>()
|
||||
let aStarted = false
|
||||
|
||||
const pA = coalescer.run({
|
||||
key: 'term_a',
|
||||
run: async () => {
|
||||
aStarted = true
|
||||
await aGate.promise
|
||||
throw new Error('boom')
|
||||
},
|
||||
resolveSuperseded: () => 'super-a'
|
||||
})
|
||||
await vi.waitFor(() => {
|
||||
expect(aStarted).toBe(true)
|
||||
})
|
||||
|
||||
const pB = coalescer.run({
|
||||
key: 'term_b',
|
||||
run: async () => 'full-b',
|
||||
resolveSuperseded: () => 'super-b'
|
||||
})
|
||||
|
||||
aGate.resolve()
|
||||
// A is obsolete when it fails after B enqueued — settles as superseded, not boom.
|
||||
await expect(pA).resolves.toBe('super-a')
|
||||
await expect(pB).resolves.toBe('full-b')
|
||||
expect(coalescer.getState().running).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
import { identityFixture as fixture, PANE } from './terminal-identity.test-fixture'
|
||||
import '../../orchestration/db/contract-constants'
|
||||
import '../../orchestration/db/messages/mailbox-routing-page'
|
||||
import '../../orchestration/db/dispatch-row-writer'
|
||||
import '../../orchestration/db/attempt-outcome-projection'
|
||||
import { expect, it, vi } from 'vitest'
|
||||
import '../../orca-runtime-tests/runtime-test-module-registration.spec'
|
||||
import '../../rpc/methods/orchestration/runs/runs'
|
||||
import '../../rpc/methods/orchestration/runs/run-scope'
|
||||
import '../../../../shared/agent-session/identity/orca-session-address'
|
||||
import '../../../../shared/agent-session/identity/orca-session-address-test-fixture'
|
||||
|
||||
it('invalidates actual SSH-held facts on register and finally-release with equal and conflicting claims', async () => {
|
||||
const f = fixture()
|
||||
const wake = vi.fn()
|
||||
const stop = f.owner.crewChanges.subscribe(wake)
|
||||
const terminal = { handle: 'term_ssh', paneKey: PANE, processIncarnation: 'remote-process' }
|
||||
const first = f.runtime.registerOrchestrationCompatibilitySshAttachment('target', 'one', terminal)
|
||||
const equal = f.runtime.registerOrchestrationCompatibilitySshAttachment('target', 'two', terminal)
|
||||
expect(wake).toHaveBeenCalledTimes(2)
|
||||
expect(f.runtime.getTerminalPaneKey(terminal.handle)).toBe(PANE)
|
||||
const ctx = f.runtime.createTerminalIdentityReadContext()
|
||||
expect(f.owner.getOrchestrationCompatibilitySshTerminal(terminal.handle, ctx)).toEqual(terminal)
|
||||
expect(f.runtime.getTerminalProcessIncarnation(terminal.handle, ctx)).toBe('remote-process')
|
||||
const conflict = f.runtime.registerOrchestrationCompatibilitySshAttachment(
|
||||
'other-target',
|
||||
'three',
|
||||
terminal
|
||||
)
|
||||
try {
|
||||
// A changed source owns a fresh finite context; the old context is never retained as authority.
|
||||
expect(
|
||||
f.owner.getOrchestrationCompatibilitySshTerminal(
|
||||
terminal.handle,
|
||||
f.runtime.createTerminalIdentityReadContext()
|
||||
)
|
||||
).toBeUndefined()
|
||||
expect(f.runtime.getTerminalPaneKey(terminal.handle)).toBeNull()
|
||||
await Promise.resolve()
|
||||
} finally {
|
||||
f.runtime.releaseOrchestrationCompatibilitySshAttachment(conflict.attachmentId)
|
||||
}
|
||||
expect(f.runtime.getTerminalPaneKey(terminal.handle)).toBe(PANE)
|
||||
f.runtime.releaseOrchestrationCompatibilitySshAttachment(first.attachmentId)
|
||||
expect(f.runtime.getTerminalPaneKey(terminal.handle)).toBe(PANE)
|
||||
f.runtime.releaseOrchestrationCompatibilitySshAttachment(equal.attachmentId)
|
||||
expect(f.runtime.getTerminalPaneKey(terminal.handle)).toBeNull()
|
||||
expect(wake).toHaveBeenCalledTimes(6)
|
||||
f.runtime.releaseOrchestrationCompatibilitySshAttachment(equal.attachmentId)
|
||||
expect(wake).toHaveBeenCalledTimes(6)
|
||||
stop()
|
||||
})
|
||||
@@ -35,27 +35,4 @@ describe('describeWorkerMessage', () => {
|
||||
expect(describeWorkerMessage(rows)).toMatchObject({ items: 1, bytes: 1001 })
|
||||
expect(Map.prototype.entries.call(rows).next().done).toBe(false)
|
||||
})
|
||||
|
||||
it('stays bounded on cyclic, deep and huge payloads', () => {
|
||||
// Wide and self-referential: each object is read once and keys share one budget.
|
||||
const cyclic: Record<string, unknown> = { type: 'loop' }
|
||||
for (let key = 0; key < 10_000; key += 1) {
|
||||
cyclic[`k${key}`] = cyclic
|
||||
}
|
||||
expect(describeWorkerMessage(cyclic)).toMatchObject({ kind: 'loop', items: 10_001 })
|
||||
|
||||
let deep: Record<string, unknown> = { leaf: true }
|
||||
for (let level = 0; level < 100_000; level += 1) {
|
||||
deep = { next: deep }
|
||||
}
|
||||
const deepShape = describeWorkerMessage(deep)
|
||||
expect(deepShape.truncated).toBe(true)
|
||||
expect(deepShape.depth).toBe(2048)
|
||||
|
||||
const huge = describeWorkerMessage({
|
||||
type: 'page',
|
||||
rows: Array.from({ length: 5_000_000 }, () => 1)
|
||||
})
|
||||
expect(huge).toMatchObject({ kind: 'page', items: 5_000_000, truncated: true })
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,168 +0,0 @@
|
||||
import type * as childProcess from 'node:child_process'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import { RpcDispatcher } from '../../src/main/runtime/rpc/dispatcher'
|
||||
import type { OrcaRuntimeService } from '../../src/main/runtime/orca-runtime'
|
||||
import { WORKTREE_METHODS } from '../../src/main/runtime/rpc/methods/workspaces/worktree'
|
||||
import type { WorkspaceStatusDefinition } from '../../src/shared/worktree/types'
|
||||
import { DEFAULT_WORKSPACE_STATUSES } from '../../src/shared/workspace/status/workspace-status-defaults'
|
||||
import { getWorkspaceStatus } from '../../src/shared/workspace/status/workspace-statuses'
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
callMock: vi.fn(),
|
||||
runtimeClientConstructorMock: vi.fn(),
|
||||
serveOrcaAppMock: vi.fn(),
|
||||
getDefaultUserDataPathMock: vi.fn(() => '/tmp/orca-user-data'),
|
||||
addEnvironmentFromPairingCodeMock: vi.fn(),
|
||||
listEnvironmentsMock: vi.fn(),
|
||||
spawnMock: vi.fn()
|
||||
}))
|
||||
|
||||
vi.mock('../../src/cli/runtime/client', async () => {
|
||||
const { createRuntimeClientModuleMock } = await import('../../src/cli/index-test-harness.js')
|
||||
return createRuntimeClientModuleMock(mocks)
|
||||
})
|
||||
|
||||
vi.mock('../../src/cli/runtime/launch', async (importOriginal) => ({
|
||||
...(await importOriginal<Record<string, unknown>>()),
|
||||
serveOrcaApp: mocks.serveOrcaAppMock
|
||||
}))
|
||||
|
||||
vi.mock('../../src/cli/runtime/profile/metadata', async (importOriginal) => ({
|
||||
...(await importOriginal<Record<string, unknown>>()),
|
||||
getDefaultUserDataPath: mocks.getDefaultUserDataPathMock
|
||||
}))
|
||||
vi.mock('../../src/cli/runtime/pairing/environments', () => ({
|
||||
addEnvironmentFromPairingCode: mocks.addEnvironmentFromPairingCodeMock,
|
||||
removeEnvironment: vi.fn(),
|
||||
resolveEnvironment: vi.fn()
|
||||
}))
|
||||
|
||||
vi.mock('../../src/shared/remote-runtime/host-store/runtime-environment-store', () => ({
|
||||
listEnvironments: mocks.listEnvironmentsMock
|
||||
}))
|
||||
vi.mock('child_process', async (importOriginal) => {
|
||||
const original = await importOriginal<typeof childProcess>()
|
||||
const { createChildProcessModuleMock } = await import('../../src/cli/index-test-harness.js')
|
||||
return { ...original, ...(await createChildProcessModuleMock(mocks.spawnMock)) }
|
||||
})
|
||||
|
||||
import { main } from '../../src/cli/index'
|
||||
import { buildWorktree } from '../../src/cli/runtime/fixtures/runtime-rpc-fixtures'
|
||||
import { useWorktreeAwarenessEnvironment } from '../../src/cli/index-test-harness'
|
||||
|
||||
const CUSTOM_STATUSES: WorkspaceStatusDefinition[] = [
|
||||
{ id: 'ready', label: 'Ready', color: 'neutral', icon: 'circle' },
|
||||
{ id: 'shipped', label: 'Shipped', color: 'emerald', icon: 'circle-check' }
|
||||
]
|
||||
|
||||
function fixture(
|
||||
options: {
|
||||
statuses?: readonly WorkspaceStatusDefinition[]
|
||||
failRead?: boolean
|
||||
hostId?: string
|
||||
} = {}
|
||||
) {
|
||||
const stored = {
|
||||
...buildWorktree('/tmp/repo/child', 'feature/child'),
|
||||
hostId: options.hostId ?? 'local',
|
||||
workspaceStatus: 'in-progress'
|
||||
}
|
||||
const getUIState = vi.fn(() => {
|
||||
if (options.failRead) {
|
||||
throw new Error('runtime_unavailable')
|
||||
}
|
||||
return { workspaceStatuses: options.statuses }
|
||||
})
|
||||
const updateManagedWorktreeMeta = vi.fn(async (_selector, updates) => {
|
||||
if (updates.workspaceStatus !== undefined) {
|
||||
stored.workspaceStatus = updates.workspaceStatus
|
||||
}
|
||||
return stored
|
||||
})
|
||||
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: the explicit registry only calls these runtime methods; all data is in memory.
|
||||
const runtime = {
|
||||
getRuntimeId: () => 'owner-runtime',
|
||||
getUIState,
|
||||
updateManagedWorktreeMeta
|
||||
} as unknown as OrcaRuntimeService
|
||||
const dispatcher = new RpcDispatcher({ runtime, methods: WORKTREE_METHODS })
|
||||
mocks.callMock.mockImplementation(async (method, params) => {
|
||||
expect(method).toBe('worktree.set')
|
||||
return dispatcher.dispatch({ id: 'fixture', authToken: 'tok', method, params })
|
||||
})
|
||||
const log = vi.spyOn(console, 'log').mockImplementation(() => {})
|
||||
const error = vi.spyOn(console, 'error').mockImplementation(() => {})
|
||||
return { stored, getUIState, updateManagedWorktreeMeta, log, error }
|
||||
}
|
||||
|
||||
async function setStatus(status: string | undefined, json: boolean) {
|
||||
await main(
|
||||
[
|
||||
'worktree',
|
||||
'set',
|
||||
'--worktree',
|
||||
'id:repo::/tmp/repo/child',
|
||||
...(status === undefined
|
||||
? ['--comment', 'unchanged status']
|
||||
: ['--workspace-status', status]),
|
||||
...(json ? ['--json'] : [])
|
||||
],
|
||||
'/tmp/repo'
|
||||
)
|
||||
}
|
||||
|
||||
describe('workspace status warnings through CLI and owning RPC handler', () => {
|
||||
useWorktreeAwarenessEnvironment(mocks)
|
||||
|
||||
it.each([false, true])('warns about the default fallback with json=%s', async (json) => {
|
||||
const { stored, log, error } = fixture()
|
||||
await setStatus('done', json)
|
||||
expect(stored.workspaceStatus).toBe('done')
|
||||
expect(getWorkspaceStatus(stored, DEFAULT_WORKSPACE_STATUSES)).toBe('in-progress')
|
||||
const warning = {
|
||||
code: 'UNKNOWN_WORKSPACE_STATUS',
|
||||
message: expect.stringContaining('Unknown workspace status "done"'),
|
||||
details: {
|
||||
requestedId: 'done',
|
||||
effectiveId: 'in-progress',
|
||||
validIds: ['todo', 'in-progress', 'in-review', 'completed']
|
||||
}
|
||||
}
|
||||
const output = log.mock.calls.flat().join('\n')
|
||||
if (json) {
|
||||
expect(JSON.parse(output)).toMatchObject({
|
||||
ok: true,
|
||||
result: { worktree: { workspaceStatus: 'done' }, warnings: [warning] }
|
||||
})
|
||||
expect(output).toContain('In progress')
|
||||
expect(error).not.toHaveBeenCalled()
|
||||
} else {
|
||||
expect(error).toHaveBeenCalledWith(expect.stringContaining('Unknown workspace status "done"'))
|
||||
const text = error.mock.calls.flat().join('\n')
|
||||
expect(text).toContain('In progress')
|
||||
expect(text).toContain('todo, in-progress, in-review, completed')
|
||||
}
|
||||
})
|
||||
|
||||
it.each(['ssh:build-box', 'runtime:paired-owner'])(
|
||||
'uses %s owner columns for unknown ids',
|
||||
async (hostId) => {
|
||||
const { stored, log } = fixture({ statuses: CUSTOM_STATUSES, hostId })
|
||||
await setStatus('done', true)
|
||||
expect(getWorkspaceStatus(stored, CUSTOM_STATUSES)).toBe('ready')
|
||||
expect(JSON.parse(log.mock.calls.flat().join('\n'))).toMatchObject({
|
||||
ok: true,
|
||||
result: {
|
||||
warnings: [
|
||||
{
|
||||
details: { requestedId: 'done', effectiveId: 'ready', validIds: ['ready', 'shipped'] }
|
||||
}
|
||||
]
|
||||
}
|
||||
})
|
||||
expect(log.mock.calls.flat().join('\n')).toContain('Ready')
|
||||
expect(mocks.callMock).toHaveBeenCalledTimes(1)
|
||||
}
|
||||
)
|
||||
})
|
||||
Reference in New Issue
Block a user