fix: reduce GitHub quota use with sharing enabled (#11888)
Co-authored-by: Julius Marminge <[email protected]>
This commit is contained in:
1 parent
b84f63bb13
commit
f4600d77dd
20 files changed
+1020
-273
No files matched your search
@@ -3,6 +3,7 @@ import * as Effect from "effect/Effect";
|
||||
import * as TestClock from "effect/testing/TestClock";
|
||||
|
||||
import * as GitHubGraphQlBudget from "./githubGraphQlBudget.ts";
|
||||
import { CredentialScope } from "./SourceControlRateLimit.ts";
|
||||
|
||||
const RESET_AT = "2026-08-13T14:00:00.000Z";
|
||||
const NEXT_RESET_AT = "2026-08-13T15:00:00.000Z";
|
||||
@@ -71,6 +72,23 @@ describe("GitHub GraphQL budget", () => {
|
||||
}).pipe(Effect.provide(GitHubGraphQlBudget.layer)),
|
||||
);
|
||||
|
||||
it.effect("isolates query reservations and observations by credential", () =>
|
||||
Effect.gen(function* () {
|
||||
yield* TestClock.setTime(BEFORE_RESET);
|
||||
const budget = yield* GitHubGraphQlBudget.GitHubGraphQlBudget;
|
||||
const query = budget.query("github.com", "query { viewer { login } }");
|
||||
yield* budget
|
||||
.observe("github.com", rateLimit(0))
|
||||
.pipe(Effect.provideService(CredentialScope, "first"));
|
||||
yield* budget
|
||||
.observe("github.com", rateLimit(5000))
|
||||
.pipe(Effect.provideService(CredentialScope, "second"));
|
||||
yield* query.pipe(Effect.provideService(CredentialScope, "second"));
|
||||
const error = yield* query.pipe(Effect.provideService(CredentialScope, "first"), Effect.flip);
|
||||
expect(error.retryAt).toBe(Date.parse(RESET_AT));
|
||||
}).pipe(Effect.provide(GitHubGraphQlBudget.layer)),
|
||||
);
|
||||
|
||||
it.effect("keeps the lower remaining value from out-of-order responses", () =>
|
||||
Effect.gen(function* () {
|
||||
yield* TestClock.setTime(BEFORE_RESET);
|
||||
@@ -181,6 +199,19 @@ describe("GitHub GraphQL budget", () => {
|
||||
}).pipe(Effect.provide(GitHubGraphQlBudget.layer)),
|
||||
);
|
||||
|
||||
it.effect("stops interactive reads when the reserve is exhausted", () =>
|
||||
Effect.gen(function* () {
|
||||
yield* TestClock.setTime(BEFORE_RESET);
|
||||
const budget = yield* GitHubGraphQlBudget.GitHubGraphQlBudget;
|
||||
yield* budget.observe("github.com", rateLimit(1, 5000, RESET_AT, 1));
|
||||
yield* budget.query("github.com", "query { viewer { login } }", { allowReserve: true });
|
||||
const error = yield* budget
|
||||
.query("github.com", "query { viewer { login } }", { allowReserve: true })
|
||||
.pipe(Effect.flip);
|
||||
expect(error.retryAt).toBe(Date.parse(RESET_AT));
|
||||
}).pipe(Effect.provide(GitHubGraphQlBudget.layer)),
|
||||
);
|
||||
|
||||
it.effect("ignores malformed or partial rate metadata", () =>
|
||||
Effect.gen(function* () {
|
||||
yield* TestClock.setTime(BEFORE_RESET);
|
||||
|
||||
Reference in new issue
Block a user