Files
orca/tests/e2e/terminal-split-activation-latency-artifact.unit.test.ts
Neil c558d7e083 Activate terminal splits before inherited CWD resolution (#17601)
* perf(terminal): activate splits before cwd resolution

* test(terminal): prove split focus before cwd publish

* fix(terminal): release stale split cwd fence

* test(terminal): add visible split activation latency benchmark

* docs(reliability): clarify split benchmark provenance

* fix: preserve deferred split handoffs across remounts

* fix: fence late deferred split closes

* docs(reliability): record exact split benchmark runs

* test(reliability): fail benchmark on artifact write errors

* test(reliability): attribute split activation phases

* docs(reliability): record schema-v2 split benchmark

* refactor(terminal): collapse duplicated split-handoff and write-queue paths

- Drop the discardDeferredSplitPaneHandoff alias for its identical clear twin.
- Fold the deferred-cwd resolve/reject settle handlers into one applier.
- Extract settlePaneCwdDeferredSpawn for the repeated read-clear-write pattern.
- Share one head-index FIFO primitive between the ordinary and reply queues.

* fix(terminal): stop retaining a promise reaction per acknowledged write

Racing every accepted write against one queue-lifetime cancel promise kept a
reaction record alive until that promise settled: 200k acknowledged writes
retained 88.6MB, now 0.1MB. Give each in-flight write its own cancel, and
split the shared FIFO primitive into its own module.

Also sanitize the split-latency benchmark report at its single serialization
point so shared artifacts no longer carry the machine-local repo path or
unbounded cleanup error text.

* fix(terminal): settle deferred split input when the spawn is abandoned

An abandoned deferred spawn returns before transport.connect(), so nothing
drained the pre-connect buffer: sendInputAccepted's promise never settled and
a paste into that pane hung forever. Clear the buffer on the abandon fence.

Also re-derive the pre-connect retention cap from the clipboard-paste ceiling
rather than the 16MB single-write ceiling; it is held twice per pane across up
to 64 deferred splits, so 5.59M code units guarded the wrong thing.

* fix(terminal): release the deferred cwd fence on a rejected reattach

A daemon createOrAttach can turn an apparent fresh spawn into a reattach; when
that reattach is refused the spawn ends with deferredSplitSpawn/pendingCwd
still set, permanently arming the pre-bind detach refusal. The release no-ops
when a PTY did bind, so it only fires where the fence would otherwise leak.

The stale-generation return above is deliberately left alone: a newer connect
already owns the pane there, and the fence is not generation-scoped.
2026-08-31 16:45:36 -07:00

75 lines
2.7 KiB
TypeScript

import { existsSync, mkdtempSync, readFileSync, rmSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { afterEach, describe, expect, it } from 'vitest'
import {
sanitizeTerminalSplitLatencyReport,
writeTerminalSplitLatencyArtifact
} from './terminal-split-activation-latency-artifact'
const temporaryDirectories: string[] = []
afterEach(() => {
while (temporaryDirectories.length > 0) {
const directory = temporaryDirectories.pop()
if (directory) {
rmSync(directory, { recursive: true, force: true })
}
}
})
describe('writeTerminalSplitLatencyArtifact', () => {
it('writes the report body to the requested path', () => {
const directory = mkdtempSync(join(tmpdir(), 'orca-split-latency-artifact-'))
temporaryDirectories.push(directory)
const outputPath = join(directory, 'report.json')
const body = '{"status":"passed"}\n'
writeTerminalSplitLatencyArtifact(outputPath, body)
expect(existsSync(outputPath)).toBe(true)
expect(readFileSync(outputPath, 'utf8')).toBe(body)
})
it('throws when the report path cannot be written', () => {
const directory = mkdtempSync(join(tmpdir(), 'orca-split-latency-artifact-'))
temporaryDirectories.push(directory)
const outputPath = join(directory, 'missing-parent', 'report.json')
expect(() => writeTerminalSplitLatencyArtifact(outputPath, '{}')).toThrow(
`[terminal-split-activation-latency] unable to write ${outputPath}`
)
})
})
describe('sanitizeTerminalSplitLatencyReport', () => {
it('replaces the machine-local test repo path', () => {
expect(
sanitizeTerminalSplitLatencyReport({ testRepoPath: '/var/folders/ab/T/orca-seeded-repo' })
.testRepoPath
).toBe('<test-repo>')
})
it('redacts absolute paths and bounds free-form cleanup text', () => {
const sanitized = sanitizeTerminalSplitLatencyReport({
abortReason: 'ENOENT: /Users/someone/secret/dir missing',
measuredSamples: [{ shortcutToFocusMs: 12, cleanupError: `x /tmp/a ${'y'.repeat(500)}` }]
})
expect(sanitized.abortReason).toBe('ENOENT: <path> missing')
const [sample] = sanitized.measuredSamples as { cleanupError: string }[]
expect(sample?.cleanupError).not.toContain('/tmp/a')
expect(sample?.cleanupError.length).toBeLessThanOrEqual(200)
})
it('keeps timing fields and non-string cleanup values intact', () => {
const sanitized = sanitizeTerminalSplitLatencyReport({
headlineMs: { shortcutToFocusP50: 12 },
measuredSamples: [{ shortcutToFocusMs: 12, cleanupError: null }]
})
expect(sanitized.headlineMs).toEqual({ shortcutToFocusP50: 12 })
expect(sanitized.measuredSamples).toEqual([{ shortcutToFocusMs: 12, cleanupError: null }])
})
})