mirror of
https://github.com/stablyai/orca.git
synced 2026-11-05 03:27:44 +00:00
* test: remove mock echoes and duplicate contracts that only reading finds
Two veins in one wave, both requiring the production path to be read rather than
pattern-matched.
Mock echoes (36 strongest candidates reviewed, 2 real): the flagged shape —
literals shared between a mock factory and an expect matcher — is almost always
a test feeding an input and asserting a transform. The two genuine echoes are in
`pty-management.test.ts`, where the handler returns
`getDaemonFolderAccessMismatch(identity)` verbatim, so asserting the mock's own
`evidence('allowed')` object and its `null` proved only the mock. One case's own
comment conceded the handler makes no decision. The branch-exercising cases in
that file stay.
Semantic sweep of 80 files no detector flagged, 27 junk cases removed. What it
found has no mechanical signature:
- a handler that is literally `() => getComputerUsePermissionStatus()`, so
`resolves.toBe(result)` guarded nothing;
- "does not mutate a stale registration off Linux" whose refusal came from a
DIFFERENT guard — `cli.ts` has no platform check, and the test's own mock made
`resolveAppImageRuntimeIdentity` return null, which a sibling case already owns;
- "keeps probing a host that is still retained" asserting a no-op, because
`retainScopes` only cancels queued probes and stores no state;
- two cases comparing against `referenceAllowedRoots`, a verbatim copy of the
pre-change algorithm kept in the test file — expected values produced by the
thing under test. The third such case stays: it calls the old algorithm to
COUNT its work (100_000 containment checks vs 100), a real bound on the
authorization hot path;
- a remote-folder refusal that came from the fake provider's own rejection
message rather than any Orca guard;
- "advertises each capability once", where a duplicate entry is inert in
production because membership is `includes`;
- an Antigravity `scaffold self-check` built on a hand-typed five-line screen —
the exact fixture shape docs/reference/antigravity-readiness-evidence.md blames
for five failed detector attempts — whose banner had already drifted to
`Antigravity CLI 1.0.3` against a real captured `1.2.0`. The raw-capture
provenance guard and the transcript checklist ratchet in that file stay.
No production file is touched and no test file is deleted.
* test: retire duplicate daemon and filesystem cases the sweep found
Continues the semantic sweep into src/main/ipc filesystem handlers and
src/main/daemon. 16 cases removed across 13 files; no production file touched.
The recurring shape is a case that reaches the same branch as its sibling by a
different-looking route:
- `parseArgs` is a flag-scanning loop, so "handles flags in any order" asserts the
identical result object as the in-order case, and "throws with no args" lands on
the same `Usage:` throw the two missing-flag cases already reach;
- an ENOENT case with "no code at all" and its sibling with a numeric transport
code both fall through to the same `ENOENT_MESSAGE.test` branch;
- "establishes connection with hello handshake" and "receives stream events" are
strict subsets of cases that require two matching authenticated sockets and a
frame split inside a multibyte character.
Two were vacuous rather than duplicated: a fixture self-comparison asserting
`String.normalize` gives different NFC and NFD spellings, and a
`not.toThrow` batch case whose 200k events are truncated by
`MAX_BATCHED_WATCHER_EVENTS = 5_000` long before the argument spread it was
written to exercise.
One whole-file deletion was reversed: `freebuff-detection.test.ts` looked like a
table restatement, but the sibling detection test covers only dependency ordering
and platform gating, not freebuff/codebuff independence — and those two names
share a suffix, so it is the only guard against one shadowing the other.
188 lines
5.3 KiB
TypeScript
188 lines
5.3 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest'
|
|
import {
|
|
CHECKPOINT_SESSION_QUEUE_MAX_PENDING,
|
|
CheckpointSessionQueue
|
|
} from './daemon-checkpoint-session-queue'
|
|
|
|
function deferred<T>(): {
|
|
promise: Promise<T>
|
|
resolve: (value: T) => void
|
|
reject: (error: unknown) => void
|
|
} {
|
|
let resolve!: (value: T) => void
|
|
let reject!: (error: unknown) => void
|
|
const promise = new Promise<T>((res, rej) => {
|
|
resolve = res
|
|
reject = rej
|
|
})
|
|
return { promise, reject, resolve }
|
|
}
|
|
|
|
describe('CheckpointSessionQueue', () => {
|
|
it('serializes operations for one session', async () => {
|
|
const queue = new CheckpointSessionQueue()
|
|
const order: string[] = []
|
|
const first = deferred<void>()
|
|
|
|
const a = queue.run('s', async () => {
|
|
order.push('a:start')
|
|
await first.promise
|
|
order.push('a:end')
|
|
})
|
|
const b = queue.run('s', async () => {
|
|
order.push('b:start')
|
|
})
|
|
|
|
await vi.waitFor(() => expect(order).toEqual(['a:start']))
|
|
first.resolve()
|
|
await Promise.all([a, b])
|
|
expect(order).toEqual(['a:start', 'a:end', 'b:start'])
|
|
})
|
|
|
|
it('does not make one session wait on another', async () => {
|
|
const queue = new CheckpointSessionQueue()
|
|
const stalled = deferred<void>()
|
|
let stalledEntered = false
|
|
|
|
void queue
|
|
.run('stalled', async () => {
|
|
stalledEntered = true
|
|
await stalled.promise
|
|
})
|
|
.catch(() => {})
|
|
|
|
const healthy = await queue.run('healthy', async () => 'ran')
|
|
|
|
// Why assert entry: a stall that never started would prove nothing about isolation.
|
|
expect(stalledEntered).toBe(true)
|
|
expect(healthy).toBe('ran')
|
|
stalled.resolve()
|
|
})
|
|
|
|
it('resolves the fallback when the deadline fires and still runs the operation', async () => {
|
|
const queue = new CheckpointSessionQueue()
|
|
const stalled = deferred<void>()
|
|
let completed = false
|
|
const onDeadlineFired = vi.fn()
|
|
|
|
const outcome = await queue.runWithDeadline(
|
|
'stalled',
|
|
async () => {
|
|
await stalled.promise
|
|
completed = true
|
|
return 'durable'
|
|
},
|
|
5,
|
|
'live',
|
|
{ onDeadline: onDeadlineFired }
|
|
)
|
|
|
|
expect(outcome).toBe('live')
|
|
expect(onDeadlineFired).toHaveBeenCalledOnce()
|
|
// Why: abandoning the wait must not abandon the write, or a reattach deadline
|
|
// would drop durable history instead of merely delaying it.
|
|
expect(completed).toBe(false)
|
|
stalled.resolve()
|
|
await vi.waitFor(() => expect(completed).toBe(true))
|
|
})
|
|
|
|
it('propagates operation failures instead of reporting a deadline', async () => {
|
|
const queue = new CheckpointSessionQueue()
|
|
const onDeadlineFired = vi.fn()
|
|
|
|
await expect(
|
|
queue.runWithDeadline(
|
|
'failed',
|
|
async () => {
|
|
throw new Error('daemon unavailable')
|
|
},
|
|
50,
|
|
'timed-out',
|
|
{ onDeadline: onDeadlineFired }
|
|
)
|
|
).rejects.toThrow('daemon unavailable')
|
|
expect(onDeadlineFired).not.toHaveBeenCalled()
|
|
})
|
|
|
|
it('reports an operation rejection that arrives after the deadline', async () => {
|
|
const queue = new CheckpointSessionQueue()
|
|
const stalled = deferred<void>()
|
|
const onAbandonedRejection = vi.fn()
|
|
|
|
await expect(
|
|
queue.runWithDeadline<void | 'timed-out'>(
|
|
'failed-late',
|
|
async () => await stalled.promise,
|
|
5,
|
|
'timed-out',
|
|
{ onAbandonedRejection }
|
|
)
|
|
).resolves.toBe('timed-out')
|
|
|
|
stalled.reject(new Error('late failure'))
|
|
await vi.waitFor(() =>
|
|
expect(onAbandonedRejection).toHaveBeenCalledWith(
|
|
expect.objectContaining({ message: 'late failure' })
|
|
)
|
|
)
|
|
})
|
|
|
|
it('keeps a later waiter behind an abandoned operation', async () => {
|
|
const queue = new CheckpointSessionQueue()
|
|
const stalled = deferred<void>()
|
|
const order: string[] = []
|
|
|
|
expect(
|
|
await queue.runWithDeadline<'ran' | 'timed-out'>(
|
|
's',
|
|
async () => {
|
|
order.push('stalled:start')
|
|
await stalled.promise
|
|
order.push('stalled:end')
|
|
return 'ran'
|
|
},
|
|
5,
|
|
'timed-out'
|
|
)
|
|
).toBe('timed-out')
|
|
|
|
const later = queue.run('s', async () => {
|
|
order.push('later')
|
|
})
|
|
await vi.waitFor(() => expect(order).toEqual(['stalled:start']))
|
|
stalled.resolve()
|
|
await later
|
|
expect(order).toEqual(['stalled:start', 'stalled:end', 'later'])
|
|
})
|
|
|
|
it('reports saturation once the queue bound is reached and clears it after draining', async () => {
|
|
const queue = new CheckpointSessionQueue()
|
|
const blocker = deferred<void>()
|
|
const pending: Promise<void>[] = []
|
|
|
|
for (let index = 0; index < CHECKPOINT_SESSION_QUEUE_MAX_PENDING; index += 1) {
|
|
expect(queue.isSaturated('s')).toBe(false)
|
|
pending.push(queue.run('s', async () => await blocker.promise))
|
|
}
|
|
|
|
expect(queue.isSaturated('s')).toBe(true)
|
|
expect(queue.isSaturated('other')).toBe(false)
|
|
|
|
blocker.resolve()
|
|
await Promise.all(pending)
|
|
expect(queue.isSaturated('s')).toBe(false)
|
|
})
|
|
|
|
it('does not strand a session after an operation rejects', async () => {
|
|
const queue = new CheckpointSessionQueue()
|
|
await expect(
|
|
queue.run('s', async () => {
|
|
throw new Error('checkpoint failed')
|
|
})
|
|
).rejects.toThrow('checkpoint failed')
|
|
|
|
expect(queue.isSaturated('s')).toBe(false)
|
|
expect(await queue.run('s', async () => 'next')).toBe('next')
|
|
})
|
|
})
|