mirror of
https://github.com/stablyai/orca.git
synced 2026-10-05 00:02:33 +00:00
Deletes 101 test files and trims 112 more, all matching documented junk patterns: exact source/import/string greps, copied inventories and export lists, duplicate invocations of a contract another test already owns, typeof-shape checks TypeScript already enforces, and self-comparisons. The largest group read a production `.ts` file and asserted on its text — for example a TaskPage test that required the source to contain `selectedRepos.find((r) => r.id === newIssueRepoId) ?? selectedRepos[0] ?? null`. Any behavior-preserving rename broke it; no behavior change ever did. Production-side follow-through: exports that only these tests imported are de-exported or deleted, stale comments pointing at removed censuses are dropped, and the reliability-gate registry, `cloud/package.json` test lists, and orphaned source-reading helpers are updated so nothing references a deleted file. Two files kept their real coverage and lost only the census scaffolding: `agent-status-producer-census.test.ts` now drives all five producers end to end instead of grepping the source tree, and `config-toml-trust-stale-writes` replaces an export-list parity check.
185 lines
6.8 KiB
JavaScript
185 lines
6.8 KiB
JavaScript
import { describe, expect, it, vi } from 'vitest'
|
|
import { parseArgs } from '../../tests/tools/win-crash-survival-e2e/cli-args.mjs'
|
|
import { buildCrashAssertions } from '../../tests/tools/win-crash-survival-e2e/crash-assertions.mjs'
|
|
import { scanPwshFailFast } from '../../tests/tools/win-crash-survival-e2e/crash-step.mjs'
|
|
import { selectScopedDaemon } from '../../tests/tools/win-crash-survival-e2e/daemon-identity.mjs'
|
|
import {
|
|
reattachSentinelMatches,
|
|
selectCreatedTabId
|
|
} from '../../tests/tools/win-crash-survival-e2e/reattach-proof.mjs'
|
|
import { quotePowerShellLiteral } from '../../tests/tools/win-update-e2e/powershell-runner.mjs'
|
|
import { closeApp, resolveElectronMainPid } from '../../tests/tools/win-update-e2e/app-driver.mjs'
|
|
import { isPidAlive } from '../../tests/tools/win-update-e2e/daemon-processes.mjs'
|
|
|
|
describe('win-crash-survival-e2e proof contracts', () => {
|
|
it('requires the full survival oracle, including daemon identity and reattach', () => {
|
|
const base = {
|
|
profile: 'survival',
|
|
mainDied: true,
|
|
daemonAliveAfterCrash: true,
|
|
shellAliveAfterCrash: true,
|
|
failFastEvents: [],
|
|
preDaemonPid: 101,
|
|
postDaemonPid: 101,
|
|
postDaemonAlive: true,
|
|
reattachProven: true
|
|
}
|
|
expect(buildCrashAssertions(base).every((entry) => entry.pass)).toBe(true)
|
|
expect(
|
|
buildCrashAssertions({ ...base, postDaemonPid: 202 }).find((entry) =>
|
|
entry.name.startsWith('relaunch adopts')
|
|
)?.pass
|
|
).toBe(false)
|
|
expect(
|
|
buildCrashAssertions({ ...base, reattachProven: false }).find((entry) =>
|
|
entry.name.startsWith('reattached UI')
|
|
)?.pass
|
|
).toBe(false)
|
|
})
|
|
|
|
it('fails closed when the Windows event log query fails', () => {
|
|
let command = ''
|
|
expect(() =>
|
|
scanPwshFailFast(1234, (received) => {
|
|
command = received
|
|
return { code: 1, stdout: '', stderr: 'access denied', error: null }
|
|
})
|
|
).toThrow('pwsh-failfast scan failed (exit 1): access denied')
|
|
expect(command).toContain('-ErrorAction Stop')
|
|
expect(command).toContain('NoMatchingEventsFound*')
|
|
})
|
|
|
|
it('accepts an empty event result only from the serialized evidence envelope', () => {
|
|
expect(
|
|
scanPwshFailFast(1234, () => ({
|
|
code: 0,
|
|
stdout: '{"events":[]}',
|
|
stderr: '',
|
|
error: null
|
|
}))
|
|
).toEqual({ events: [] })
|
|
expect(() =>
|
|
scanPwshFailFast(1234, () => ({ code: 0, stdout: '', stderr: '', error: null }))
|
|
).toThrow('pwsh-failfast scan returned no JSON output')
|
|
expect(() =>
|
|
scanPwshFailFast(1234, () => ({ code: 0, stdout: '{}', stderr: '', error: null }))
|
|
).toThrow('without an events envelope')
|
|
})
|
|
|
|
it('fails closed when PID liveness evidence is unavailable', () => {
|
|
expect(isPidAlive(42, () => ({ code: 0, stdout: 'alive\n', stderr: '', error: null }))).toBe(
|
|
true
|
|
)
|
|
expect(isPidAlive(42, () => ({ code: 0, stdout: 'dead\n', stderr: '', error: null }))).toBe(
|
|
false
|
|
)
|
|
expect(() =>
|
|
isPidAlive(42, () => ({ code: 1, stdout: '', stderr: 'access denied', error: null }))
|
|
).toThrow('PID liveness probe failed (exit 1): access denied')
|
|
expect(() => isPidAlive(42, () => ({ code: 0, stdout: '', stderr: '', error: null }))).toThrow(
|
|
'PID liveness probe returned an invalid state'
|
|
)
|
|
})
|
|
|
|
it('uses the scoped live process as daemon authority', () => {
|
|
expect(
|
|
selectScopedDaemon(
|
|
[{ pid: 42, appVersion: '1.2.3' }],
|
|
[{ pid: 42, commandLine: 'daemon-entry.js --socket scoped' }]
|
|
)
|
|
).toEqual({ pid: 42, appVersion: '1.2.3' })
|
|
expect(() =>
|
|
selectScopedDaemon(
|
|
[{ pid: 41, appVersion: 'stale' }],
|
|
[{ pid: 42, commandLine: 'daemon-entry.js --socket scoped' }]
|
|
)
|
|
).toThrow('daemon PID file does not match scoped live daemon 42')
|
|
expect(() => selectScopedDaemon([], [])).toThrow('expected exactly one')
|
|
expect(() => selectScopedDaemon([], [{ pid: 1 }, { pid: 2 }])).toThrow('expected exactly one')
|
|
})
|
|
|
|
it('rejects CLI typos and duplicate value flags before launching', () => {
|
|
const baseArgs = ['--expect', 'survival', '--exe-path', process.execPath]
|
|
expect(parseArgs(baseArgs).errors).toEqual([])
|
|
expect(parseArgs([...baseArgs, '--exe-pathh', process.execPath]).errors).toContain(
|
|
'Unknown argument: --exe-pathh'
|
|
)
|
|
expect(parseArgs([...baseArgs, '--expect', 'orphaned']).errors).toContain(
|
|
'Duplicate argument: --expect'
|
|
)
|
|
})
|
|
|
|
it('quotes apostrophes in generated PowerShell path literals', () => {
|
|
expect(quotePowerShellLiteral("C:\\Users\\O'Brien\\shell.pid")).toBe(
|
|
"'C:\\Users\\O''Brien\\shell.pid'"
|
|
)
|
|
})
|
|
|
|
it('targets exactly the terminal tab created before the crash', () => {
|
|
expect(selectCreatedTabId(['agent-tab'], ['agent-tab', 'terminal-tab'])).toBe('terminal-tab')
|
|
expect(() => selectCreatedTabId(['agent-tab'], ['agent-tab'])).toThrow(
|
|
'expected exactly one created terminal tab, found 0'
|
|
)
|
|
expect(() => selectCreatedTabId([], ['first', 'second'])).toThrow(
|
|
'expected exactly one created terminal tab, found 2'
|
|
)
|
|
})
|
|
|
|
it('requires both the per-shell canary and exact survivor pid', () => {
|
|
expect(reattachSentinelMatches('1660|canary\r\n', 'canary', 1660)).toBe(true)
|
|
expect(reattachSentinelMatches('1770|canary', 'canary', 1660)).toBe(false)
|
|
expect(reattachSentinelMatches('1660|other', 'canary', 1660)).toBe(false)
|
|
expect(reattachSentinelMatches('1660|canary|extra', 'canary', 1660)).toBe(false)
|
|
})
|
|
|
|
it('resolves the real packaged main but permits fallback cleanup', async () => {
|
|
expect(
|
|
await resolveElectronMainPid({
|
|
evaluate: async () => 222,
|
|
process: () => ({ pid: 111 })
|
|
})
|
|
).toBe(222)
|
|
const unavailableApp = {
|
|
evaluate: async () => {
|
|
throw new Error('main unavailable')
|
|
},
|
|
process: () => ({ pid: 111 })
|
|
}
|
|
expect(
|
|
await resolveElectronMainPid(unavailableApp, { allowLauncherFallback: false })
|
|
).toBeNull()
|
|
expect(await resolveElectronMainPid(unavailableApp)).toBe(111)
|
|
})
|
|
|
|
it('bounds main PID resolution when the Electron connection is wedged', async () => {
|
|
vi.useFakeTimers()
|
|
try {
|
|
const result = resolveElectronMainPid(
|
|
{
|
|
evaluate: () => new Promise(() => {}),
|
|
process: () => ({ pid: 333 })
|
|
},
|
|
{ timeoutMs: 20 }
|
|
)
|
|
await vi.advanceTimersByTimeAsync(20)
|
|
await expect(result).resolves.toBe(333)
|
|
} finally {
|
|
vi.useRealTimers()
|
|
}
|
|
})
|
|
|
|
it('releases the close deadline after a successful app close', async () => {
|
|
vi.useFakeTimers()
|
|
try {
|
|
await closeApp({
|
|
evaluate: async () => 444,
|
|
process: () => ({ pid: 333 }),
|
|
close: async () => {}
|
|
})
|
|
expect(vi.getTimerCount()).toBe(0)
|
|
} finally {
|
|
vi.useRealTimers()
|
|
}
|
|
})
|
|
})
|