mirror of
https://github.com/stablyai/orca.git
synced 2026-09-23 16:02:24 +00:00
* Revert "fix terminal attribution shim removal edge cases (#14187)"
This reverts 585dd6d3a9. Re-landed in the next commit without the host capability gate. Nothing shipped with it, so no migration constraint.
* rm git shim: neutralize stale wrappers without a host gate
Re-lands the cleanup half of #14187: pass-through tombstones for retained wrapper paths, env/PATH scrubbing at every spawn owner, and the retired setting drop.
Only writes tombstones when the legacy directory already exists, so a clean install no longer has it created. Leaves out the terminal.attribution-removed.v1 capability gate: the tombstone neutralizes each host locally, so refusing terminal create/split against older hosts denied service without adding cleanup.
* rm git shim: surface neutralization failures and fix rollback marker
Readiness review follow-ups: warn on each failed attempt and on give-up (was silent and undiagnosable); write a VERSION marker distinct from the retired shim's '7' so a rolled-back build rewrites its own wrappers; clear a captured ORCA_REAL_* path that no longer exists so the cmd wrapper's where.exe fallback can run; stop a locked temp file masking the real error. Adds retry-exhaustion coverage.
* rm git shim: pin the cmd fallback order and correct the give-up count
Round-2 review follow-ups: string-pin that a stale ORCA_REAL_* is cleared before the where.exe fallback, and count the initial attempt in the give-up warning so it agrees with the per-attempt line.
* rm git shim: keep the split-failure toast
The revert took a toast that #14187 added alongside the gate but which stands on its own: without it a failed remote split only reaches the console and the pane silently never appears. Also pins attempt ordinals in the retry-exhaustion test.
152 lines
5.6 KiB
TypeScript
152 lines
5.6 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest'
|
|
import type { RuntimeRpcResponse } from './runtime-rpc-envelope'
|
|
import {
|
|
closeSharedControlLogicalSubscription,
|
|
createSharedControlSubscription,
|
|
handleSharedControlLogicalResponse,
|
|
replaySharedControlSubscriptions
|
|
} from './remote-runtime-shared-control-subscriptions'
|
|
import type { SharedControlLogicalSubscription } from './remote-runtime-shared-control-types'
|
|
|
|
function makeSubscriptions(): {
|
|
subscriptions: Map<string, SharedControlLogicalSubscription<unknown>>
|
|
subscription: SharedControlLogicalSubscription<unknown>
|
|
} {
|
|
const subscriptions = new Map<string, SharedControlLogicalSubscription<unknown>>()
|
|
const subscription = createSharedControlSubscription({
|
|
requestId: 'req-1',
|
|
method: 'runtime.clientEvents.subscribe',
|
|
params: null,
|
|
retainedParamsBytes: 0,
|
|
callbacks: { onResponse: vi.fn(), onError: vi.fn() }
|
|
})
|
|
subscriptions.set(subscription.requestId, subscription)
|
|
return { subscriptions, subscription }
|
|
}
|
|
|
|
function okResponse(subscriptionId: string): RuntimeRpcResponse<unknown> {
|
|
return {
|
|
ok: true,
|
|
id: 'req-1',
|
|
result: { subscriptionId }
|
|
} as unknown as RuntimeRpcResponse<unknown>
|
|
}
|
|
|
|
describe('closeSharedControlLogicalSubscription — replay-window leak', () => {
|
|
it('sends the unsubscribe when closed after an established subscribe replay completes', () => {
|
|
const { subscriptions, subscription } = makeSubscriptions()
|
|
// First establishment: server assigned a concrete subscription id.
|
|
subscription.sent = true
|
|
subscription.remoteSubscriptionId = 'server-sub-1'
|
|
|
|
const request = vi.fn()
|
|
closeSharedControlLogicalSubscription({ subscriptions, subscription, request })
|
|
|
|
// Established subscription cleans up immediately by its known id.
|
|
expect(request).toHaveBeenCalledWith('runtime.clientEvents.unsubscribe', {
|
|
subscriptionId: 'server-sub-1'
|
|
})
|
|
expect(subscriptions.size).toBe(0)
|
|
})
|
|
|
|
it('does NOT leak a server subscription when close races the replay resubscribe window', () => {
|
|
const { subscriptions, subscription } = makeSubscriptions()
|
|
// Subscription was previously established on the server.
|
|
subscription.sent = true
|
|
subscription.remoteSubscriptionId = 'server-sub-1'
|
|
|
|
// Reconnect replay: sent flips false and the old id is cleared right before
|
|
// the resubscribe frame goes out. The server WILL assign a fresh id.
|
|
const sent: SharedControlLogicalSubscription<unknown>[] = []
|
|
replaySharedControlSubscriptions({
|
|
subscriptions,
|
|
send: (s) => {
|
|
sent.push(s)
|
|
},
|
|
tagReplayedResponses: true
|
|
})
|
|
expect(subscription.sent).toBe(false)
|
|
expect(subscription.remoteSubscriptionId).toBeNull()
|
|
|
|
// close() arrives during the window: no remoteSubscriptionId yet, so a
|
|
// naive close finishes locally and never unsubscribes — leaking the server
|
|
// subscription that the in-flight resubscribe is about to create.
|
|
const request = vi.fn()
|
|
closeSharedControlLogicalSubscription({ subscriptions, subscription, request })
|
|
|
|
// The close must be deferred, not finished with no cleanup.
|
|
expect(subscriptions.size).toBe(1)
|
|
expect(request).not.toHaveBeenCalled()
|
|
|
|
// When the resubscribe's ready response arrives with the new server id, the
|
|
// deferred close fires the unsubscribe and only then finishes.
|
|
handleSharedControlLogicalResponse({
|
|
subscriptions,
|
|
subscription,
|
|
response: okResponse('server-sub-2'),
|
|
request
|
|
})
|
|
|
|
expect(request).toHaveBeenCalledWith('runtime.clientEvents.unsubscribe', {
|
|
subscriptionId: 'server-sub-2'
|
|
})
|
|
expect(subscriptions.size).toBe(0)
|
|
})
|
|
|
|
it('finishes locally without an unsubscribe for a never-sent subscription', () => {
|
|
const { subscriptions, subscription } = makeSubscriptions()
|
|
// Brand new: never sent, no server subscription exists.
|
|
const request = vi.fn()
|
|
closeSharedControlLogicalSubscription({ subscriptions, subscription, request })
|
|
|
|
expect(request).not.toHaveBeenCalled()
|
|
expect(subscriptions.size).toBe(0)
|
|
})
|
|
|
|
it('finishes a deferred close locally when replay returns an error', () => {
|
|
const { subscriptions, subscription } = makeSubscriptions()
|
|
subscription.sent = true
|
|
subscription.remoteSubscriptionId = 'server-sub-1'
|
|
replaySharedControlSubscriptions({ subscriptions, send: vi.fn(), tagReplayedResponses: true })
|
|
|
|
const request = vi.fn()
|
|
closeSharedControlLogicalSubscription({ subscriptions, subscription, request })
|
|
handleSharedControlLogicalResponse({
|
|
subscriptions,
|
|
subscription,
|
|
response: {
|
|
ok: false,
|
|
id: 'req-1',
|
|
error: { code: 'replay_failed', message: 'replay failed' }
|
|
} as RuntimeRpcResponse<unknown>,
|
|
request
|
|
})
|
|
|
|
expect(request).not.toHaveBeenCalled()
|
|
expect(subscriptions.size).toBe(0)
|
|
})
|
|
|
|
it('does not leave a later close waiting after replay already failed', () => {
|
|
const { subscriptions, subscription } = makeSubscriptions()
|
|
subscription.sent = true
|
|
subscription.remoteSubscriptionId = 'server-sub-1'
|
|
replaySharedControlSubscriptions({ subscriptions, send: vi.fn(), tagReplayedResponses: true })
|
|
|
|
handleSharedControlLogicalResponse({
|
|
subscriptions,
|
|
subscription,
|
|
response: {
|
|
ok: false,
|
|
id: 'req-1',
|
|
error: { code: 'replay_failed', message: 'replay failed' }
|
|
} as RuntimeRpcResponse<unknown>,
|
|
request: vi.fn()
|
|
})
|
|
|
|
const request = vi.fn()
|
|
closeSharedControlLogicalSubscription({ subscriptions, subscription, request })
|
|
expect(request).not.toHaveBeenCalled()
|
|
expect(subscriptions.size).toBe(0)
|
|
})
|
|
})
|