mirror of
https://github.com/stablyai/orca.git
synced 2026-09-30 00:03:15 +00:00
* perf(git): bound git subprocess execution with an atomic admission scheduler Field traces (#16038, #11363) show Windows freeze storms driven by unbounded concurrent git children (12+ at once, 50-65s status convoys for 25+ minutes). Admit every main-process git child against atomic per-budget base+headroom counters (general / network / per-route), with reserved interactive capacity, ordering-only aging, close-bound permit release, a 120s fail-safe read timeout that feeds scheduler backoff, tier plumbing through every option carrier, and coalesced+jittered visibility pollers. Killswitch: ORCA_GIT_ADMISSION_DISABLED=1. Storm harness A/B: max concurrent children 65 -> 6, interactive p95 791ms -> 88ms; output-parity battery byte-identical with admission on vs off. * test(git): run the admission output-parity battery on every platform Parity needs real git, not the storm harness's PATH stub, so it must not share that file's POSIX gate - Windows is the platform where parity evidence matters. * fix(git): preserve interactive admission invariants * perf(git): keep admission queue drains linear * fix(git): close final admission gaps * perf(git): bound eligible route selection * fix(merge): remove unrelated stale snapshot changes * fix(git): preserve refresh lifecycle authority * test(git): align admission lifetime contracts * fix(git): harden admission across runtime paths * fix(git): restore freshness for bulk status reads * test(git): repoint delete-dialog source pins after admission plumbing The hydration effect now orders its targets through orderDeleteWorktreeStatusHydrationTargets and passes includeLineStats alongside the abort signal, so both literal anchors stopped matching. The invariants are unchanged and still pinned: dropping the signal, the main-worktree/folder filter, or getState-instead-of-subscribe each still reddens this test. * Fix git admission tier propagation and lock ordering Decode optional Git status tiers permissively and default runtime RPC status reads to the status lane while preserving renderer caller intent. Acquire the FETCH_HEAD mutex before atomic admission so same-repository fetch waiters hold no global or route permits. Preserve automatic pull-request refresh reasons, keep explicit hosted-review refreshes interactive, remove the dead candidate tier, and keep relay scheduling unchanged. Use tier-aware status lease keys because a shared lease cannot be safely promoted after its admission request is queued or granted. * test: align expectations with admission plumbing * refactor(child-process): move the process contract types to process-spec run-process.ts crossed its line cap after gaining the termination observer; the public types and defaults move out with re-exports so no caller changes. * chore: restore pnpm-lock.yaml to main (unintended local drift) --------- Co-authored-by: Merge Sim <sim@local>
236 lines
8.5 KiB
TypeScript
236 lines
8.5 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
const { coordinatorMocks, moduleMocks } = await vi.hoisted(async () => {
|
|
const moduleMocks = await import('./pr-refresh-coordinator-test-mocks')
|
|
return { coordinatorMocks: moduleMocks.createPRRefreshCoordinatorMocks(), moduleMocks }
|
|
})
|
|
|
|
vi.mock('electron', () => moduleMocks.electronModuleMock(coordinatorMocks))
|
|
vi.mock('./client', () => moduleMocks.clientModuleMock(coordinatorMocks))
|
|
vi.mock('./github-api-repository', () =>
|
|
moduleMocks.githubApiRepositoryModuleMock(coordinatorMocks)
|
|
)
|
|
vi.mock('./rate-limit', () => moduleMocks.rateLimitModuleMock(coordinatorMocks))
|
|
vi.mock('../ipc/ui', () => moduleMocks.ipcUiModuleMock(coordinatorMocks))
|
|
|
|
import { makeCandidate, makePR } from './pr-refresh-coordinator-test-harness'
|
|
|
|
const { sendMock, sendToTrustedUIRendererMock, getAllWebContentsMock, getPRForBranchOutcomeMock } =
|
|
coordinatorMocks
|
|
|
|
describe('pr-refresh-coordinator', () => {
|
|
beforeEach(() => {
|
|
moduleMocks.resetPRRefreshCoordinatorMocks(coordinatorMocks)
|
|
})
|
|
|
|
afterEach(() => {
|
|
vi.useRealTimers()
|
|
})
|
|
|
|
it('preserves the coordinator public module API', async () => {
|
|
const coordinator = await import('./pr-refresh-coordinator')
|
|
|
|
expect(Object.keys(coordinator).sort()).toEqual([
|
|
'_getPRRefreshAliasCountForTests',
|
|
'_getPRRefreshErrorBackoffCountForTests',
|
|
'_getPRRefreshQueueSizeForTests',
|
|
'_getVisiblePRRefreshWindowCountForTests',
|
|
'clearVisiblePRRefreshWindow',
|
|
'enqueuePRRefresh',
|
|
'pruneWorktreePRRefreshAliases',
|
|
'refreshPRNow',
|
|
'reportVisiblePRRefreshCandidates',
|
|
'setPRRefreshOutcomeObserver'
|
|
])
|
|
})
|
|
|
|
it('ignores a stale visibility generation before it can replace queued work', async () => {
|
|
const { reportVisiblePRRefreshCandidates } = await import('./pr-refresh-coordinator')
|
|
getPRForBranchOutcomeMock.mockResolvedValue({ kind: 'no-pr', fetchedAt: Date.now() })
|
|
|
|
reportVisiblePRRefreshCandidates(
|
|
[makeCandidate({ branch: 'feature/current', cacheKey: '/repo::feature/current' })],
|
|
2,
|
|
1
|
|
)
|
|
reportVisiblePRRefreshCandidates(
|
|
[makeCandidate({ branch: 'feature/stale', cacheKey: '/repo::feature/stale' })],
|
|
1,
|
|
1
|
|
)
|
|
await vi.advanceTimersByTimeAsync(0)
|
|
|
|
expect(getPRForBranchOutcomeMock).toHaveBeenCalledOnce()
|
|
expect(getPRForBranchOutcomeMock.mock.calls[0]?.[1]).toBe('feature/current')
|
|
})
|
|
|
|
it('sends each refresh event once without broadcasting to 100 browser guests', async () => {
|
|
const guestSends = Array.from({ length: 100 }, () => vi.fn())
|
|
getAllWebContentsMock.mockReturnValue(
|
|
guestSends.map((send, index) => ({
|
|
id: index + 100,
|
|
isDestroyed: () => false,
|
|
send
|
|
}))
|
|
)
|
|
const { enqueuePRRefresh } = await import('./pr-refresh-coordinator')
|
|
|
|
enqueuePRRefresh(makeCandidate({ isBare: true }), 'manual')
|
|
|
|
expect(sendToTrustedUIRendererMock).toHaveBeenCalledOnce()
|
|
expect(sendToTrustedUIRendererMock).toHaveBeenCalledWith(
|
|
'gh:prRefreshEvent',
|
|
expect.objectContaining({ status: 'skipped', skippedReason: 'bare' })
|
|
)
|
|
expect(sendMock).toHaveBeenCalledOnce()
|
|
expect(getAllWebContentsMock).not.toHaveBeenCalled()
|
|
expect(guestSends.reduce((total, send) => total + send.mock.calls.length, 0)).toBe(0)
|
|
})
|
|
|
|
it('forwards the candidate worktree head into the branch lookup options', async () => {
|
|
const { reportVisiblePRRefreshCandidates } = await import('./pr-refresh-coordinator')
|
|
getPRForBranchOutcomeMock.mockResolvedValueOnce({
|
|
kind: 'no-pr',
|
|
fetchedAt: Date.now()
|
|
})
|
|
|
|
reportVisiblePRRefreshCandidates([makeCandidate({ currentHeadOid: 'worktree-head-oid' })], 1, 1)
|
|
await vi.runOnlyPendingTimersAsync()
|
|
|
|
// Why: without the head, a panel-supplied fallback number preserves a
|
|
// merged PR head-blind after the branch moves on to new work.
|
|
expect(getPRForBranchOutcomeMock).toHaveBeenCalledWith(
|
|
'/repo',
|
|
'feature/test',
|
|
null,
|
|
null,
|
|
null,
|
|
expect.objectContaining({ currentHeadOid: 'worktree-head-oid' })
|
|
)
|
|
})
|
|
|
|
it('copies the candidate worktree head onto broadcast aliases', async () => {
|
|
const { reportVisiblePRRefreshCandidates } = await import('./pr-refresh-coordinator')
|
|
getPRForBranchOutcomeMock.mockResolvedValueOnce({
|
|
kind: 'found',
|
|
pr: makePR({ state: 'merged' }),
|
|
fetchedAt: Date.now()
|
|
})
|
|
|
|
reportVisiblePRRefreshCandidates([makeCandidate({ currentHeadOid: 'worktree-head-oid' })], 1, 1)
|
|
await vi.runOnlyPendingTimersAsync()
|
|
|
|
// Why: the renderer clear of a diverged merged linked PR is head-scoped, so
|
|
// the broadcast alias must carry the request-time head it was probed against.
|
|
const outcomeEvent = sendMock.mock.calls
|
|
.map(([, event]) => event)
|
|
.find((event) => event.outcome)
|
|
expect(outcomeEvent?.aliases[0]?.currentHeadOid).toBe('worktree-head-oid')
|
|
})
|
|
|
|
it('includes request start time on manual refresh events', async () => {
|
|
const { refreshPRNow } = await import('./pr-refresh-coordinator')
|
|
getPRForBranchOutcomeMock.mockResolvedValueOnce({
|
|
kind: 'found',
|
|
pr: makePR({ checksStatus: 'success' }),
|
|
fetchedAt: Date.now() + 5
|
|
})
|
|
|
|
await refreshPRNow(makeCandidate())
|
|
|
|
const events = sendMock.mock.calls.map(([, event]) => event)
|
|
const inFlight = events.find((event) => event.status === 'in-flight')
|
|
const outcome = events.find((event) => event.outcome)
|
|
expect(inFlight?.requestStartedAt).toBe(1_000)
|
|
expect(outcome?.requestStartedAt).toBe(1_000)
|
|
expect(outcome?.sequence).toBe(inFlight?.sequence)
|
|
})
|
|
|
|
it('keeps each manual outcome on its request sequence when completions race', async () => {
|
|
const { refreshPRNow } = await import('./pr-refresh-coordinator')
|
|
let resolveFirst!: (outcome: ReturnType<typeof makePR>) => void
|
|
let resolveSecond!: (outcome: ReturnType<typeof makePR>) => void
|
|
const first = new Promise<ReturnType<typeof makePR>>((resolve) => {
|
|
resolveFirst = resolve
|
|
})
|
|
const second = new Promise<ReturnType<typeof makePR>>((resolve) => {
|
|
resolveSecond = resolve
|
|
})
|
|
getPRForBranchOutcomeMock
|
|
.mockImplementationOnce(async () => ({
|
|
kind: 'found',
|
|
pr: await first,
|
|
fetchedAt: Date.now()
|
|
}))
|
|
.mockImplementationOnce(async () => ({
|
|
kind: 'found',
|
|
pr: await second,
|
|
fetchedAt: Date.now()
|
|
}))
|
|
|
|
const firstRefresh = refreshPRNow(makeCandidate())
|
|
const secondRefresh = refreshPRNow(makeCandidate())
|
|
await vi.advanceTimersByTimeAsync(0)
|
|
resolveSecond(makePR({ number: 22 }))
|
|
await secondRefresh
|
|
resolveFirst(makePR({ number: 11 }))
|
|
await firstRefresh
|
|
|
|
const events = sendMock.mock.calls.map(([, event]) => event)
|
|
const inFlight = events.filter((event) => event.status === 'in-flight')
|
|
const outcomes = events.filter((event) => event.outcome)
|
|
const firstOutcome = outcomes.find((event) => event.outcome.pr?.number === 11)
|
|
const secondOutcome = outcomes.find((event) => event.outcome.pr?.number === 22)
|
|
expect(firstOutcome?.sequence).toBe(inFlight[0]?.sequence)
|
|
expect(secondOutcome?.sequence).toBe(inFlight[1]?.sequence)
|
|
expect(firstOutcome?.sequence).toBeLessThan(secondOutcome?.sequence)
|
|
})
|
|
|
|
it('accepts merged fallback PRs for visible fallback refreshes', async () => {
|
|
const { refreshPRNow } = await import('./pr-refresh-coordinator')
|
|
getPRForBranchOutcomeMock.mockResolvedValueOnce({
|
|
kind: 'found',
|
|
pr: makePR({ state: 'merged' }),
|
|
fetchedAt: Date.now()
|
|
})
|
|
|
|
await refreshPRNow(
|
|
makeCandidate({
|
|
fallbackPRNumber: 12,
|
|
fallbackPRSource: 'pr-cache'
|
|
})
|
|
)
|
|
|
|
expect(getPRForBranchOutcomeMock).toHaveBeenCalledWith(
|
|
'/repo',
|
|
'feature/test',
|
|
null,
|
|
null,
|
|
12,
|
|
{
|
|
acceptMergedFallbackPR: true,
|
|
localGitExecOptions: { admissionTier: 'interactive' }
|
|
}
|
|
)
|
|
})
|
|
|
|
it('preserves an automatic fallback reason and keeps its git work background', async () => {
|
|
const { refreshPRNow } = await import('./pr-refresh-coordinator')
|
|
getPRForBranchOutcomeMock.mockResolvedValueOnce({ kind: 'no-pr', fetchedAt: Date.now() })
|
|
|
|
await refreshPRNow(makeCandidate(), 'swr')
|
|
|
|
expect(getPRForBranchOutcomeMock).toHaveBeenCalledWith(
|
|
'/repo',
|
|
'feature/test',
|
|
null,
|
|
null,
|
|
null,
|
|
{ localGitExecOptions: { admissionTier: 'background' } }
|
|
)
|
|
expect(sendMock.mock.calls.map(([, event]) => event.reason)).toEqual(
|
|
expect.arrayContaining(['swr'])
|
|
)
|
|
})
|
|
})
|