mirror of
https://github.com/stablyai/orca.git
synced 2026-09-25 16:02:38 +00:00
* refactor(tests): split oversized test files off the max-lines suppression list Every `*.test.ts`/`*.spec.ts` that carried an `eslint/oxlint-disable max-lines` directive is now split into focused, behavior-scoped suites that fit the 800-line test budget, with shared setup extracted into co-located `*-test-harness.ts` / `*-test-fixtures.ts` modules (300-line budget). 83 files became ~930; the largest output is 797 effective lines. `orca-runtime.test.ts` is intentionally untouched. Test bodies were moved by scripted line-range slicing rather than retyped, so assertions are byte-identical. The only permitted body edits were mechanical rebinding where a shared value moved into a harness (e.g. `tmpHome` -> `homes.tmpHome`). Registries that enumerate test files were updated in lockstep: - config/max-lines-baseline.txt: pruned 341 -> 258 entries (all 83 removed). - config/reliability-gates.jsonc: 33 gates repointed at the split files, with assertionRefs split per file where a gate's coverage now spans several. - .github/workflows/pr.yml: the real-zsh lane now lists the 4 split files that actually exercise zsh, so they keep running in the dedicated shell lane. Also renamed agent-hooks `server-test-fixtures.ts` to `server.test-fixtures.ts` so the global-fetch call-site audit keeps skipping it, and added `.js` extensions to the CLI suites' dynamic harness imports (node16 resolution) to unbreak `build:cli`. Verification: full suite 52,449 passing vs 52,448 at baseline with zero assertions lost; `pnpm lint`, `pnpm typecheck`, and `pnpm build:cli` all exit 0; the terminal-pane e2e spec runs 31/31 headless. * refactor(tests): split hook-idle arbitration suite that oxfmt pushed over budget The pre-commit oxfmt pass reflowed pty-connection-hook-idle-arbitration.test.ts to 811 effective lines, 11 over the test budget. Split the hook-completion side effect and replacement-agent veto cases into their own suite; both files now sit well under the cap and the 15 tests are unchanged. * test: port upstream test changes into the split files after rebase Rebasing onto main surfaced 27 tests that main had added to files this branch deleted, plus edits to tests that had already moved. Taking the deletion side of those modify/delete conflicts would have dropped that coverage silently, so each upstream change is ported into the split file that now owns the behavior — for example main's six orchestration mailbox tests land across orchestration-runs, -send, and -check. Also repoints `orchestration.notification-mailbox-consistency`, a gate main added after this branch's gate remap, at those same three split files, and re-prunes the max-lines baseline against main's (257 entries). Verified: all 27 upstream test titles present; full suite 52,761 passing with the only diff vs baseline being 12 tests main itself removed and 3 that moved from skipped to passing; lint and typecheck exit 0. * fix(test): flush pending continuations before tearing down terminal test globals CI shard 5/16 failed on both Node 24 and 26 with `ReferenceError: window is not defined` from pty-connection.ts, surfacing through pty-connection-daemon-snapshot-replay.test.ts. The reattach/settle chains `await` a real promise and then touch `window.api`. Under fake timers those continuations cannot run, so they only become schedulable once restoreTerminalTestGlobals() switches back to real timers — which previously happened immediately before `delete globalThis.window`, so a late continuation threw and failed the whole file. Flush async ticks in that window instead. This is latent in the source rather than new: the pre-split 25k-line file kept running other tests after these, which gave the chains time to settle before teardown. Splitting the file moved teardown directly behind them. * fix(test): keep an inert window after terminal test teardown instead of deleting it The async-tick flush was not enough: the reattach/settle chain can resolve after teardown regardless of how long we drain, so CI shard 5/16 still failed with `ReferenceError: window is not defined` from pty-connection.ts. A real renderer never loses `window`, so deleting it was the artificial part. Swap in an inert proxy whose properties resolve to callables and whose calls resolve to undefined, making a late `window.api.pty.*` call a harmless no-op. The next test replaces it wholesale via installTerminalTestGlobals(), and no test asserts that `window` is absent.
214 lines
7.9 KiB
TypeScript
214 lines
7.9 KiB
TypeScript
import { mkdir, readFile, readlink, symlink, writeFile } from 'node:fs/promises'
|
|
import { tmpdir } from 'node:os'
|
|
import { join } from 'node:path'
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
const execFileMock = vi.hoisted(() => vi.fn())
|
|
|
|
vi.mock('electron', () => ({
|
|
app: {
|
|
isPackaged: false,
|
|
getPath: () => tmpdir(),
|
|
getAppPath: () => tmpdir()
|
|
}
|
|
}))
|
|
|
|
vi.mock('node:child_process', () => ({
|
|
execFile: execFileMock
|
|
}))
|
|
|
|
import { CliInstaller } from './cli-installer'
|
|
import { createPackagedMacLauncher, makeFixture } from './cli-installer-test-fixtures'
|
|
|
|
describe('CliInstaller', () => {
|
|
beforeEach(() => {
|
|
execFileMock.mockReset()
|
|
})
|
|
|
|
afterEach(() => {
|
|
vi.useRealTimers()
|
|
vi.restoreAllMocks()
|
|
})
|
|
|
|
// Why: this test creates a Unix symlink to /tmp/not-orca, which only applies on macOS/Linux.
|
|
it.skipIf(process.platform === 'win32')(
|
|
'refuses to replace an unknown symlink at the command path',
|
|
async () => {
|
|
const fixture = await makeFixture()
|
|
const installPath = join(fixture.root, 'bin', 'orca')
|
|
const existingTarget = '/tmp/not-orca'
|
|
await mkdir(join(fixture.root, 'bin'), { recursive: true })
|
|
await symlink(existingTarget, installPath)
|
|
|
|
const installer = new CliInstaller({
|
|
platform: 'darwin',
|
|
isPackaged: false,
|
|
userDataPath: fixture.userDataPath,
|
|
execPath: '/Applications/Orca.app/Contents/MacOS/Orca',
|
|
appPath: fixture.appPath,
|
|
commandPathOverride: installPath
|
|
})
|
|
|
|
await expect(installer.getStatus()).resolves.toMatchObject({
|
|
state: 'conflict',
|
|
supported: true
|
|
})
|
|
await expect(installer.install()).rejects.toThrow('Refusing to replace non-Orca command')
|
|
await expect(readlink(installPath)).resolves.toBe(existingTarget)
|
|
}
|
|
)
|
|
|
|
// Why: packaged app moves can leave a symlink to an older Orca-owned launcher;
|
|
// those are safe to refresh, unlike arbitrary user symlinks.
|
|
it.skipIf(process.platform === 'win32')(
|
|
'replaces stale packaged Orca launcher symlinks',
|
|
async () => {
|
|
const fixture = await makeFixture()
|
|
const commandDir = join(fixture.root, 'bin')
|
|
const installPath = join(commandDir, 'orca')
|
|
const resourcesPath = join(fixture.root, 'Current.app', 'Contents', 'Resources')
|
|
const launcherPath = join(resourcesPath, 'bin', 'orca')
|
|
const oldLauncherPath = join(fixture.root, 'Old.app', 'Contents', 'Resources', 'bin', 'orca')
|
|
await mkdir(commandDir, { recursive: true })
|
|
await mkdir(join(resourcesPath, 'bin'), { recursive: true })
|
|
await writeFile(launcherPath, '#!/usr/bin/env bash\n', 'utf8')
|
|
await symlink(oldLauncherPath, installPath)
|
|
|
|
const installer = new CliInstaller({
|
|
platform: 'darwin',
|
|
isPackaged: true,
|
|
resourcesPath,
|
|
commandPathOverride: installPath,
|
|
processPathEnv: commandDir
|
|
})
|
|
|
|
await expect(installer.getStatus()).resolves.toMatchObject({
|
|
state: 'stale',
|
|
currentTarget: oldLauncherPath
|
|
})
|
|
await expect(installer.install()).resolves.toMatchObject({ state: 'installed' })
|
|
await expect(readlink(installPath)).resolves.toBe(launcherPath)
|
|
}
|
|
)
|
|
|
|
// Why: old dev/package experiments wrote a generated Orca launcher file
|
|
// directly into /usr/local/bin/orca. That broke profiling because Settings
|
|
// treated the regular file as a hard conflict and would not self-heal it.
|
|
it.skipIf(process.platform === 'win32')(
|
|
'replaces stale generated Unix launcher files',
|
|
async () => {
|
|
const fixture = await makeFixture()
|
|
const commandDir = join(fixture.root, 'bin')
|
|
const installPath = join(commandDir, 'orca')
|
|
const resourcesPath = join(fixture.root, 'Current.app', 'Contents', 'Resources')
|
|
const launcherPath = join(resourcesPath, 'bin', 'orca')
|
|
const oldCliPath = join(fixture.root, 'OldWorktree', 'out', 'cli', 'index.js')
|
|
await mkdir(commandDir, { recursive: true })
|
|
await mkdir(join(resourcesPath, 'bin'), { recursive: true })
|
|
await writeFile(launcherPath, '#!/usr/bin/env bash\n', 'utf8')
|
|
await writeFile(
|
|
installPath,
|
|
[
|
|
'#!/usr/bin/env bash',
|
|
'set -euo pipefail',
|
|
"ELECTRON='/tmp/Old.app/Contents/MacOS/Electron'",
|
|
`CLI='${oldCliPath}'`,
|
|
'export ORCA_NODE_OPTIONS="${NODE_OPTIONS-}"',
|
|
'export ORCA_NODE_REPL_EXTERNAL_MODULE="${NODE_REPL_EXTERNAL_MODULE-}"',
|
|
'unset NODE_OPTIONS',
|
|
'unset NODE_REPL_EXTERNAL_MODULE',
|
|
'ELECTRON_RUN_AS_NODE=1 "$ELECTRON" "$CLI" "$@"',
|
|
''
|
|
].join('\n'),
|
|
'utf8'
|
|
)
|
|
|
|
const installer = new CliInstaller({
|
|
platform: 'darwin',
|
|
isPackaged: true,
|
|
resourcesPath,
|
|
commandPathOverride: installPath,
|
|
processPathEnv: commandDir
|
|
})
|
|
|
|
await expect(installer.getStatus()).resolves.toMatchObject({
|
|
state: 'stale',
|
|
currentTarget: oldCliPath
|
|
})
|
|
await expect(installer.install()).resolves.toMatchObject({ state: 'installed' })
|
|
await expect(readlink(installPath)).resolves.toBe(launcherPath)
|
|
}
|
|
)
|
|
|
|
it.skipIf(process.platform === 'win32')(
|
|
'keeps arbitrary regular files at the command path as conflicts',
|
|
async () => {
|
|
const fixture = await makeFixture()
|
|
const commandDir = join(fixture.root, 'bin')
|
|
const installPath = join(commandDir, 'orca')
|
|
const resourcesPath = await createPackagedMacLauncher(fixture.root)
|
|
await mkdir(commandDir, { recursive: true })
|
|
await writeFile(
|
|
installPath,
|
|
'#!/usr/bin/env bash\nELECTRON_RUN_AS_NODE=1 /tmp/not-orca "$@"\n',
|
|
'utf8'
|
|
)
|
|
|
|
const installer = new CliInstaller({
|
|
platform: 'darwin',
|
|
isPackaged: true,
|
|
resourcesPath,
|
|
commandPathOverride: installPath,
|
|
processPathEnv: commandDir
|
|
})
|
|
|
|
await expect(installer.getStatus()).resolves.toMatchObject({
|
|
state: 'conflict',
|
|
currentTarget: null
|
|
})
|
|
await expect(installer.install()).rejects.toThrow('Refusing to replace non-Orca command')
|
|
await expect(readFile(installPath, 'utf8')).resolves.toContain('/tmp/not-orca')
|
|
}
|
|
)
|
|
|
|
// Why: a dev build can temporarily own the public command on developer
|
|
// machines; packaged Orca should treat that as stale, not a hard conflict.
|
|
it.skipIf(process.platform === 'win32')(
|
|
'replaces stale sibling dev launcher symlinks from packaged installs',
|
|
async () => {
|
|
const fixture = await makeFixture()
|
|
for (const devLauncherName of ['orca', 'orca-dev']) {
|
|
const caseRoot = join(fixture.root, devLauncherName)
|
|
const commandDir = join(caseRoot, 'bin')
|
|
const installPath = join(commandDir, 'orca')
|
|
const userDataPath = join(caseRoot, 'orca')
|
|
const resourcesPath = join(caseRoot, 'Current.app', 'Contents', 'Resources')
|
|
const launcherPath = join(resourcesPath, 'bin', 'orca')
|
|
const devLauncherPath = join(`${userDataPath}-dev`, 'cli', 'bin', devLauncherName)
|
|
await mkdir(commandDir, { recursive: true })
|
|
await mkdir(join(resourcesPath, 'bin'), { recursive: true })
|
|
await mkdir(join(`${userDataPath}-dev`, 'cli', 'bin'), { recursive: true })
|
|
await writeFile(launcherPath, '#!/usr/bin/env bash\n', 'utf8')
|
|
await writeFile(devLauncherPath, '#!/usr/bin/env bash\n', 'utf8')
|
|
await symlink(devLauncherPath, installPath)
|
|
|
|
const installer = new CliInstaller({
|
|
platform: 'darwin',
|
|
isPackaged: true,
|
|
userDataPath,
|
|
resourcesPath,
|
|
commandPathOverride: installPath,
|
|
processPathEnv: commandDir
|
|
})
|
|
|
|
await expect(installer.getStatus()).resolves.toMatchObject({
|
|
state: 'stale',
|
|
currentTarget: devLauncherPath
|
|
})
|
|
await expect(installer.install()).resolves.toMatchObject({ state: 'installed' })
|
|
await expect(readlink(installPath)).resolves.toBe(launcherPath)
|
|
}
|
|
}
|
|
)
|
|
})
|