mirror of
https://github.com/stablyai/orca.git
synced 2026-10-02 16:02:15 +00:00
* fix(github): load PR diffs for Enterprise remotes * fix(github): encode PR content paths by segment * Fix PR review actions failing on GitHub Enterprise remotes - Threads GitHub host identity (not just owner/repo) through the client, work-item-details, issues, and RPC layers so gh commands target the correct Enterprise server instead of silently falling back to github.com - Adds a shared github-api-repository helper to resolve/host-qualify repo identity consistently across REST, GraphQL, and CLI shorthand calls - Scopes the gh rate-limit breaker and singleton rate-limit snapshot by host/runtime so a github.com block or probe can't affect GHES or WSL - Coalesces concurrent host-auth probes and paginates PR file fetching beyond 100 results - Propagates `host` through renderer PR caches, checks-panel keys, and preload IPC types so Enterprise and github.com data never collide * Route gh host qualification through runner options instead of argv sniff Move GHES/GH_HOST resolution from parsing --hostname/--repo out of gh argv to an explicit options.host passed through ghExecFileAsync, since SSH-backed repos spawn gh with no cwd and argv sniffing couldn't reliably detect the target host. The runner now injects --hostname and qualifies --repo/-R at spawn time from options.host, and rate-limit scoping/guards use the same explicit host instead of inferring it. Also adds a shared githubRepoIdentityKey helper to keep cache/store keys consistent with the new host-aware repository identity. * Fix gh CLI GHES host pinning and rate-limit scope leaks - Pin `--host` on every gh call site so a process-level GH_HOST can't silently redirect requests, and qualify `-R`/`-R=` repo shorthand alongside the existing `--repo=` handling. - Check the target scope for an active rate-limit block before each WSL/native or host fallback retry, not just on the initial attempt, so a blocked scope can't be hit again through a fallback path. - Compute idempotency once per call instead of re-deriving it after fallback reassigns args. * Fix GitHub Enterprise host identity loss across PR/work-item paths - Thread `host` through mobile PR RPC params, IPC work-item lookups, and RPC schemas so GHES identity survives the renderer/mobile/main boundary instead of silently falling back to a same-named github.com repo. - Qualify `--repo`/`-R` args for github.com too (not just GHES), since gh resolves bare shorthand against a process-level GH_HOST that can redirect pinned github.com commands. - Cache `getOriginGitHubApiRepository` to avoid a per-call uncached `git remote get-url` round trip on connection-backed repos. - Add a local-fork fallback in `getWorkItemDetails` so PRs living on a base repo (not visible via the origin slug) still resolve via cwd. - Centralize the github.com-vs-GHES host predicate in `isDefaultGitHubHost` so cache keys, quota scoping, and identity checks can't drift out of sync. * Make repository identity host-aware across all GitHub surfaces Generalize the auth-gated enterprise resolver to any remote and build a cached hosted-identity family (origin/issue/candidates/source) on top of it, then migrate every github.com-only consumer: Tasks listing/counting, branch-to-PR discovery, push targets, fork upstream, issue operations, Projects, web links, avatars, and PR-link facts. Scope the rate-limit breaker probe per runtime:host and classify WSL UNC cwds correctly. Co-authored-by: Orca <help@stably.ai> * Fix expected slug to include host field in GitHub PR link test Updates the smart-source paste-intent test fixture to match the repository slug shape that now carries a `host` field, keeping GHES host identity intact through the paste-intent parsing path. * Surface per-host gh auth state for GitHub Enterprise diagnoseGhAuth accepts the host a surface needs credentials for, scopes the account/scope diagnosis to that host, and reports whether gh has any login there; GhAuthErrorHelp renders host-qualified login/refresh commands so an unauthenticated GHES host stops masquerading as a github.com scope problem. Also fixes the mobile paste-intent expectation for host-carrying parsed links. Co-authored-by: Orca <help@stably.ai> * Bound GHES identity caches and preserve non-default ports in host identity Cap the origin-repo and host-auth caches like ownerRepoCache; keep ports from remote/link URLs so GHES on a non-default port is a distinct identity; make positional github.com slugs explicit against GH_HOST; compare work-item sources by host-aware identity key; bail cwd-less branch lookups when no repository candidate resolved; thread host through the renderer work-item slug lookup. Co-authored-by: Orca <help@stably.ai> * Thread GitHub host through issue detail requests Incorporates ghes-issue-host-support (ed6bb96ef): one hosted issue repository identity is resolved before the details fan-out so comments, timeline, participants, and mention lookups cannot drift across hosts, with SSH guards so unresolved issue/PR repositories never fall through to gh's default host. Co-authored-by: Orca <help@stably.ai> * Scope remaining GitHub rate-limit accounting * Resolve typed PR lookups across hosted repository candidates getWorkItem's PR path probes upstream-then-origin hosted candidates instead of origin alone, so fork checkouts resolve the base repo's PR with the right host; issue detail resolution reuses the up-front hosted identity and keeps the SSH unresolved-host guards. Co-authored-by: Orca <help@stably.ai> * Refactor GitHub repository execution setup * Carry host on smart-submit link intents Co-authored-by: Orca <help@stably.ai> * Carry the project host on GitHub item dialog origins Co-authored-by: Orca <help@stably.ai> * Keep GHES web ports but drop SSH transport ports in host identity Supersedes PR #9118 on this branch: http(s) remote ports identify the Enterprise web/API endpoint and are preserved, while ssh/git transport ports (including ssh.github.com:443) never leak into gh's host identity. Replaces the ssh.github.com:443 special case with the structural protocol split and ports the PR's parsing test suite. Co-authored-by: Orca <help@stably.ai> * Support GitHub Enterprise diffs and mutations with host-scoped caches Parse GitHub host identity from work-item URLs and carry it through PR/issue mutations, labels, and assignments. Bound rate-limit and scope-probe caches (1024 and 512 entries) to prevent unbounded growth when interacting with multiple GHES instances. Normalize repository identity keys to include host so github.com and GHES slugs don't collide in cache and equality checks. * Support GitHub Enterprise diffs and mutations with host-scoped caches - Carry host identity through PR mutations and reads so fork PRs on different GHES instances don't collide in cache or state tracking. - Validate host authentication before routing requests to unconfigured Enterprise servers; ambient credentials must never reach untrusted hosts. - Scope rate-limit guards and spend tracking per host so GHES quota stays independent from github.com quota. - Respect explicit --hostname arguments in gh CLI calls ahead of GH_HOST or ambient defaults, so breaker state follows the actual request target. - Detect implicit WSL runtimes from UNC paths for consistent host auth and execution-options scoping across mobile and desktop clients. * Support GitHub Enterprise work-item diffs with host-scoped execution Enterprise PRs must use their selected host consistently across diff, comments, and file-content loads. Validate repository slugs before authenticated execution to prevent path-injection via renderer overrides. Scope project browsing cache and rate-limit tracking by host to prevent cross-host pollution. Use parsed URLs as authoritative over ambient hosts for project resolution. * Support GitHub Enterprise work-item diffs with host-scoped execution Preserve host identity on PR/issue work items throughout the mutation and diff pipeline so Enterprise instances (including ported endpoints like github.acme.test:8443) can execute mutations without ambiguity. Rate-limit gh commands by the pre-qualified --repo host, cache auth state per ported host, and surface Enterprise hosts in project metadata and error messages. * fix(review): drop dead rateLimitGuard/noteRateLimitSpend re-export Both callers (project-view.ts, mutations.ts) moved to the host-scoped repositoryRateLimitGuard/noteRepositoryRateLimitSpend; the bucket-only re-export in internals.ts had zero importers left. Co-authored-by: Orca <help@stably.ai> * fix(ci): split Enterprise host work-item tests under max-lines Move GHES/SSH host-routing cases out of work-item-details.test.ts so the suite stays within the 800-line test max-lines budget. * test(github): align mocks with host-scoped repository resolution - Route origin repository resolution through getOwnerRepoForRemote, not getOwnerRepo, to match production path - Pin github.com host on origin results so host-less fixtures pass host gate in resolveGitHubApiRepository - Add generation-based invalidation to prevent stale slug-cache writes from in-flight resolutions - Fix ref-sync race in ProjectPicker: use useLayoutEffect so committed tree owns browse cache key - Defer handledCrossRepoUrlRef assignment in SmartWorkspaceNameField until resolution succeeds - Update Enterprise host routing: found work items must not silently fall back to default host when unresolved - Normalize GHES avatar URLs: accept explicit port 443 as canonical form, not a fallback trigger --------- Co-authored-by: Jinjing <6427696+AmethystLiang@users.noreply.github.com> Co-authored-by: Orca <help@stably.ai>
367 lines
13 KiB
TypeScript
367 lines
13 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
const { ghExecFileAsyncMock } = vi.hoisted(() => ({
|
|
ghExecFileAsyncMock: vi.fn()
|
|
}))
|
|
|
|
vi.mock('../git/runner', () => ({
|
|
ghExecFileAsync: ghExecFileAsyncMock
|
|
}))
|
|
|
|
vi.mock('./gh-utils', () => ({
|
|
acquire: vi.fn(),
|
|
release: vi.fn()
|
|
}))
|
|
|
|
import {
|
|
getRateLimit,
|
|
rateLimitGuard,
|
|
noteRateLimitSpend,
|
|
spendsSharedGitHubComQuota,
|
|
repositoryRateLimitGuard,
|
|
noteRepositoryRateLimitSpend,
|
|
_resetRateLimitCache
|
|
} from './rate-limit'
|
|
import {
|
|
clearGhRateLimitBlock,
|
|
getGhRateLimitBlockedUntilMs,
|
|
notifyGhPrimaryRateLimit,
|
|
type GhRateLimitBucket
|
|
} from '../git/gh-rate-limit-breaker'
|
|
|
|
const PAYLOAD = JSON.stringify({
|
|
resources: {
|
|
core: { limit: 5000, remaining: 4200, reset: 1_700_000_000 },
|
|
search: { limit: 30, remaining: 28, reset: 1_700_000_000 },
|
|
graphql: { limit: 5000, remaining: 4900, reset: 1_700_000_000 }
|
|
}
|
|
})
|
|
|
|
describe('getRateLimit', () => {
|
|
beforeEach(() => {
|
|
vi.useFakeTimers()
|
|
vi.setSystemTime(1_000)
|
|
ghExecFileAsyncMock.mockReset()
|
|
_resetRateLimitCache()
|
|
})
|
|
|
|
afterEach(() => {
|
|
vi.useRealTimers()
|
|
})
|
|
|
|
it('parses bucket counts from gh api rate_limit', async () => {
|
|
ghExecFileAsyncMock.mockResolvedValue({ stdout: PAYLOAD })
|
|
|
|
const result = await getRateLimit()
|
|
|
|
expect(result).toEqual({
|
|
ok: true,
|
|
snapshot: {
|
|
core: { limit: 5000, remaining: 4200, resetAt: 1_700_000_000 },
|
|
search: { limit: 30, remaining: 28, resetAt: 1_700_000_000 },
|
|
graphql: { limit: 5000, remaining: 4900, resetAt: 1_700_000_000 },
|
|
fetchedAt: 1_000
|
|
}
|
|
})
|
|
// The runner injects --hostname at spawn from the `host` option, so the
|
|
// probe passes bare argv and pins the host to github.com through options.
|
|
expect(ghExecFileAsyncMock).toHaveBeenCalledWith(['api', 'rate_limit'], {
|
|
encoding: 'utf-8',
|
|
host: 'github.com'
|
|
})
|
|
})
|
|
|
|
it('caches a failed probe for the TTL instead of re-spawning gh', async () => {
|
|
// Why: refreshes fail open past a probe failure, so without a negative cache
|
|
// an auth or transport failure would spawn the same doomed gh call repeatedly.
|
|
ghExecFileAsyncMock.mockRejectedValue(new Error('HTTP 404: Rate limiting is not enabled.'))
|
|
|
|
const first = await getRateLimit()
|
|
const second = await getRateLimit()
|
|
|
|
expect(first).toEqual({ ok: false, error: 'HTTP 404: Rate limiting is not enabled.' })
|
|
expect(second).toEqual(first)
|
|
expect(ghExecFileAsyncMock).toHaveBeenCalledTimes(1)
|
|
})
|
|
|
|
it('re-probes after the failure TTL elapses and recovers on success', async () => {
|
|
ghExecFileAsyncMock.mockRejectedValueOnce(new Error('boom'))
|
|
ghExecFileAsyncMock.mockResolvedValue({ stdout: PAYLOAD })
|
|
|
|
expect((await getRateLimit()).ok).toBe(false)
|
|
expect((await getRateLimit()).ok).toBe(false)
|
|
expect(ghExecFileAsyncMock).toHaveBeenCalledTimes(1)
|
|
|
|
vi.setSystemTime(1_000 + 30_000)
|
|
|
|
expect((await getRateLimit()).ok).toBe(true)
|
|
expect(ghExecFileAsyncMock).toHaveBeenCalledTimes(2)
|
|
})
|
|
|
|
it('bypasses the failure cache when forced', async () => {
|
|
ghExecFileAsyncMock.mockRejectedValueOnce(new Error('boom'))
|
|
ghExecFileAsyncMock.mockResolvedValue({ stdout: PAYLOAD })
|
|
|
|
expect((await getRateLimit()).ok).toBe(false)
|
|
expect((await getRateLimit({ force: true })).ok).toBe(true)
|
|
expect(ghExecFileAsyncMock).toHaveBeenCalledTimes(2)
|
|
})
|
|
})
|
|
|
|
describe('rateLimitGuard', () => {
|
|
beforeEach(() => {
|
|
vi.useFakeTimers()
|
|
vi.setSystemTime(1_000)
|
|
ghExecFileAsyncMock.mockReset()
|
|
_resetRateLimitCache()
|
|
})
|
|
|
|
afterEach(() => {
|
|
vi.useRealTimers()
|
|
})
|
|
|
|
async function cacheExhaustedSnapshot(resetEpochSeconds: number): Promise<void> {
|
|
ghExecFileAsyncMock.mockResolvedValueOnce({
|
|
stdout: JSON.stringify({
|
|
resources: {
|
|
core: { limit: 5000, remaining: 3, reset: resetEpochSeconds },
|
|
search: { limit: 30, remaining: 28, reset: resetEpochSeconds },
|
|
graphql: { limit: 5000, remaining: 4900, reset: resetEpochSeconds }
|
|
}
|
|
})
|
|
})
|
|
expect((await getRateLimit()).ok).toBe(true)
|
|
}
|
|
|
|
it('blocks below the floor while resetAt is in the future', async () => {
|
|
await cacheExhaustedSnapshot(61)
|
|
|
|
expect(rateLimitGuard('core')).toEqual({
|
|
blocked: true,
|
|
remaining: 3,
|
|
limit: 5000,
|
|
resetAt: 61
|
|
})
|
|
})
|
|
|
|
it('fails open once the blocking bucket resetAt has elapsed', async () => {
|
|
// Why: probes can fail indefinitely (sleep past resetAt, network blip), so
|
|
// a stale exhausted snapshot must not block once GitHub has already reset
|
|
// the budget — a past-due pause would spin the coordinator drain loop.
|
|
await cacheExhaustedSnapshot(61)
|
|
|
|
vi.setSystemTime(61_000)
|
|
|
|
expect(rateLimitGuard('core')).toEqual({ blocked: false })
|
|
})
|
|
})
|
|
|
|
// Why: only default github.com traffic on the native runtime shares this
|
|
// snapshot's budget. GHES hosts and WSL distros run against separate quotas,
|
|
// so the shared guard must bypass them entirely.
|
|
describe('shared-quota host scoping', () => {
|
|
beforeEach(() => {
|
|
vi.useFakeTimers()
|
|
vi.setSystemTime(1_000)
|
|
ghExecFileAsyncMock.mockReset()
|
|
_resetRateLimitCache()
|
|
})
|
|
|
|
afterEach(() => {
|
|
vi.useRealTimers()
|
|
})
|
|
|
|
async function cacheExhaustedSnapshot(resetEpochSeconds: number): Promise<void> {
|
|
ghExecFileAsyncMock.mockResolvedValueOnce({
|
|
stdout: JSON.stringify({
|
|
resources: {
|
|
core: { limit: 5000, remaining: 3, reset: resetEpochSeconds },
|
|
search: { limit: 30, remaining: 28, reset: resetEpochSeconds },
|
|
graphql: { limit: 5000, remaining: 4900, reset: resetEpochSeconds }
|
|
}
|
|
})
|
|
})
|
|
expect((await getRateLimit()).ok).toBe(true)
|
|
}
|
|
|
|
it('treats github.com / no host on the native runtime as sharing the budget', () => {
|
|
expect(spendsSharedGitHubComQuota(undefined)).toBe(true)
|
|
expect(spendsSharedGitHubComQuota(null)).toBe(true)
|
|
expect(spendsSharedGitHubComQuota({ host: 'github.com' })).toBe(true)
|
|
expect(spendsSharedGitHubComQuota({ host: 'GitHub.com' })).toBe(true)
|
|
})
|
|
|
|
it('excludes GHES hosts and WSL runtimes from the shared budget', () => {
|
|
expect(spendsSharedGitHubComQuota({ host: 'github.acme-corp.com' })).toBe(false)
|
|
expect(spendsSharedGitHubComQuota({ host: 'github.com' }, { wslDistro: 'Ubuntu' })).toBe(false)
|
|
expect(spendsSharedGitHubComQuota(undefined, { wslDistro: 'Ubuntu' })).toBe(false)
|
|
})
|
|
|
|
it('treats a WSL UNC cwd as non-shared even without an explicit wslDistro', () => {
|
|
// Why: the runner derives the WSL distro from a \\wsl.localhost\... cwd, so
|
|
// gh runs inside WSL and spends that distro's quota — not the native one.
|
|
expect(
|
|
spendsSharedGitHubComQuota(
|
|
{ host: 'github.com' },
|
|
{ cwd: '\\\\wsl.localhost\\Ubuntu\\home\\me\\repo' }
|
|
)
|
|
).toBe(false)
|
|
expect(
|
|
spendsSharedGitHubComQuota(
|
|
{ host: 'github.com' },
|
|
{ cwd: '\\\\wsl$\\Ubuntu\\home\\me\\repo' }
|
|
)
|
|
).toBe(false)
|
|
// Regular Windows/POSIX cwds keep sharing the native github.com budget.
|
|
expect(spendsSharedGitHubComQuota({ host: 'github.com' }, { cwd: 'C:\\repos\\a' })).toBe(true)
|
|
expect(spendsSharedGitHubComQuota({ host: 'github.com' }, { cwd: '/Users/me/repo' })).toBe(true)
|
|
})
|
|
|
|
it('bypasses the guard and spend for a WSL UNC cwd', async () => {
|
|
await cacheExhaustedSnapshot(61)
|
|
|
|
const cwd = '\\\\wsl.localhost\\Ubuntu\\home\\me\\repo'
|
|
expect(repositoryRateLimitGuard({ host: 'github.com' }, 'core', { cwd })).toEqual({
|
|
blocked: false
|
|
})
|
|
|
|
noteRepositoryRateLimitSpend({ host: 'github.com' }, 'core', 1, { cwd })
|
|
const guard = rateLimitGuard('core')
|
|
expect(guard.blocked && guard.remaining).toBe(3)
|
|
})
|
|
|
|
it('applies the shared guard for github.com but bypasses non-shared scopes', async () => {
|
|
await cacheExhaustedSnapshot(61)
|
|
|
|
expect(repositoryRateLimitGuard({ host: 'github.com' }, 'core')).toEqual({
|
|
blocked: true,
|
|
remaining: 3,
|
|
limit: 5000,
|
|
resetAt: 61
|
|
})
|
|
expect(repositoryRateLimitGuard({ host: 'github.acme-corp.com' }, 'core')).toEqual({
|
|
blocked: false
|
|
})
|
|
expect(
|
|
repositoryRateLimitGuard({ host: 'github.com' }, 'core', { wslDistro: 'Ubuntu' })
|
|
).toEqual({ blocked: false })
|
|
})
|
|
|
|
it('debits shared-budget spend but no-ops for non-shared scopes', async () => {
|
|
await cacheExhaustedSnapshot(61)
|
|
|
|
noteRepositoryRateLimitSpend({ host: 'github.acme-corp.com' }, 'core')
|
|
const afterEnterprise = rateLimitGuard('core')
|
|
expect(afterEnterprise.blocked && afterEnterprise.remaining).toBe(3)
|
|
|
|
noteRepositoryRateLimitSpend({ host: 'github.com' }, 'core')
|
|
const afterShared = rateLimitGuard('core')
|
|
expect(afterShared.blocked && afterShared.remaining).toBe(2)
|
|
})
|
|
|
|
it('matches noteRateLimitSpend when the scope is shared github.com', async () => {
|
|
await cacheExhaustedSnapshot(61)
|
|
noteRateLimitSpend('core')
|
|
const guard = rateLimitGuard('core')
|
|
expect(guard.blocked && guard.remaining).toBe(2)
|
|
})
|
|
})
|
|
|
|
// Why: the breaker's reset probe must query the tripping scope's runtime/host
|
|
// (WSL distro, GHES host), record into that scope only, and never touch the
|
|
// shared native-github.com snapshot.
|
|
describe('scope-aware breaker reset probe', () => {
|
|
const WSL_SCOPE = 'wsl:ubuntu:github.com'
|
|
const GHES_SCOPE = 'native:github.acme-corp.com'
|
|
const ALL_BUCKETS: GhRateLimitBucket[] = ['core', 'search', 'graphql']
|
|
|
|
beforeEach(() => {
|
|
vi.useFakeTimers()
|
|
vi.setSystemTime(1_000)
|
|
ghExecFileAsyncMock.mockReset()
|
|
_resetRateLimitCache()
|
|
})
|
|
|
|
afterEach(() => {
|
|
// Clear per-scope breaker state without unregistering the module-load
|
|
// probe (which _resetGhRateLimitBreaker would drop for later tests).
|
|
for (const scope of [WSL_SCOPE, GHES_SCOPE]) {
|
|
for (const bucket of ALL_BUCKETS) {
|
|
clearGhRateLimitBlock(bucket, scope)
|
|
}
|
|
}
|
|
vi.useRealTimers()
|
|
})
|
|
|
|
async function flushProbe(): Promise<void> {
|
|
for (let i = 0; i < 20; i++) {
|
|
await Promise.resolve()
|
|
}
|
|
}
|
|
|
|
it('refines a WSL-scope trip via a probe matching that scope', async () => {
|
|
// resetAt 601s > the 5-minute fallback so the refinement is observable.
|
|
ghExecFileAsyncMock.mockResolvedValue({
|
|
stdout: JSON.stringify({
|
|
resources: {
|
|
core: { limit: 5000, remaining: 0, reset: 601 },
|
|
search: { limit: 30, remaining: 20, reset: 601 },
|
|
graphql: { limit: 5000, remaining: 100, reset: 601 }
|
|
}
|
|
})
|
|
})
|
|
|
|
notifyGhPrimaryRateLimit('core', WSL_SCOPE)
|
|
// Single-flight: a concurrent second trip must not spawn a second probe.
|
|
notifyGhPrimaryRateLimit('core', WSL_SCOPE)
|
|
await flushProbe()
|
|
|
|
expect(ghExecFileAsyncMock).toHaveBeenCalledTimes(1)
|
|
expect(ghExecFileAsyncMock).toHaveBeenCalledWith(['api', 'rate_limit'], {
|
|
encoding: 'utf-8',
|
|
host: 'github.com',
|
|
wslDistro: 'ubuntu'
|
|
})
|
|
// The exhausted core bucket is refined to the real reset for THAT scope.
|
|
expect(getGhRateLimitBlockedUntilMs('core', 1_000, WSL_SCOPE)).toBe(601_000)
|
|
// Non-exhausted buckets in the same scope stay clear.
|
|
expect(getGhRateLimitBlockedUntilMs('search', 1_000, WSL_SCOPE)).toBeNull()
|
|
// The shared native-github.com snapshot was not written: the guard has no
|
|
// cached data and fails open.
|
|
expect(rateLimitGuard('core')).toEqual({ blocked: false })
|
|
expect(getGhRateLimitBlockedUntilMs('core', 1_000)).toBeNull()
|
|
})
|
|
|
|
it('fails open on a GHES probe failure and negative-caches the scope', async () => {
|
|
ghExecFileAsyncMock.mockRejectedValue(new Error('HTTP 404: Rate limiting is not enabled.'))
|
|
|
|
notifyGhPrimaryRateLimit('core', GHES_SCOPE)
|
|
await flushProbe()
|
|
// A second trip inside the failure TTL must not spawn another probe.
|
|
notifyGhPrimaryRateLimit('core', GHES_SCOPE)
|
|
await flushProbe()
|
|
|
|
expect(ghExecFileAsyncMock).toHaveBeenCalledTimes(1)
|
|
// Fail open: the blunt fallback block stands (5 minutes from trip time).
|
|
expect(getGhRateLimitBlockedUntilMs('core', 1_000, GHES_SCOPE)).toBe(301_000)
|
|
|
|
// Past the TTL the scope is probed again (and can recover on success).
|
|
vi.setSystemTime(1_000 + 30_000)
|
|
ghExecFileAsyncMock.mockResolvedValue({
|
|
stdout: JSON.stringify({
|
|
resources: { core: { limit: 5000, remaining: 4999, reset: 700 } }
|
|
})
|
|
})
|
|
notifyGhPrimaryRateLimit('core', GHES_SCOPE)
|
|
await flushProbe()
|
|
|
|
expect(ghExecFileAsyncMock).toHaveBeenCalledTimes(2)
|
|
expect(ghExecFileAsyncMock).toHaveBeenLastCalledWith(['api', 'rate_limit'], {
|
|
encoding: 'utf-8',
|
|
host: 'github.acme-corp.com'
|
|
})
|
|
// Budget is actually available in that scope — the block is cleared.
|
|
expect(getGhRateLimitBlockedUntilMs('core', 31_000, GHES_SCOPE)).toBeNull()
|
|
})
|
|
})
|