Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

fix(api): match ledger terms acceptance on gating version only (#5171)

Gaurav Chadha2a5af2267e73
diff --git a/apps/api/src/lib/exchange.test.ts b/apps/api/src/lib/exchange.test.ts
index b479c0020..6781ede9a 100644
--- a/apps/api/src/lib/exchange.test.ts
+++ b/apps/api/src/lib/exchange.test.ts
@@ -795,9 +795,20 @@ describe("Exchange terms acceptance", () => {
expect(access.allowed).toBe(true);
});
- it("does not accept a ledger entry for different terms text", async () => {
+ it("accepts a ledger entry for the gating version after a non-material text change", async () => {
ledgerAnswers([{ version: ACME_TERMS.version, textHash: "b".repeat(64) }]);
+ await expect(
+ getExchangeAccessForRequest({
+ ...PROFILE_REQUEST,
+ flags: { professionalProfileCompanyDataBeta: true },
+ }),
+ ).resolves.toMatchObject({ allowed: true });
+ });
+
+ it("does not accept a ledger entry for another terms version", async () => {
+ ledgerAnswers([{ version: "old", textHash: DIGEST }]);
+
await expect(
getExchangeAccessForRequest({
...PROFILE_REQUEST,
diff --git a/apps/api/src/services/alexandria/access.test.ts b/apps/api/src/services/alexandria/access.test.ts
index b1bfb20b0..e3a320b16 100644
--- a/apps/api/src/services/alexandria/access.test.ts
+++ b/apps/api/src/services/alexandria/access.test.ts
@@ -167,15 +167,6 @@ it.each([
"a".repeat(64),
false,
],
- [
- "disabled",
- "revoked_by_organization_admin",
- "2026-09-20T12:00:00Z",
- "2026-09-20T12:01:00Z",
- "2026-01",
- "b".repeat(64),
- false,
- ],
[
"disabled",
"revoked_by_organization_admin",
@@ -296,6 +287,46 @@ it.each([
},
);
+it("keeps an acceptance of the gating version across a non-material digest change", async () => {
+ const terms = requirement(true);
+ Object.assign(terms.body.providers[0].terms, { digest: "a".repeat(64) });
+ mocks.request.mockImplementation(async ({ path }) =>
+ path.includes("requirements")
+ ? terms
+ : {
+ status: 200,
+ body: {
+ providers: [
+ {
+ provider: "fred",
+ revoked: false,
+ version: "2026-01",
+ textHash: "b".repeat(64),
+ acceptedAt: "2026-09-20T12:01:00Z",
+ },
+ ],
+ },
+ },
+ );
+ expect(await authorizeProviders("team", calls, {}, "org")).toBeUndefined();
+ expect(
+ await authorizeProviders(
+ "team",
+ calls,
+ {
+ organizationDataSourceAccess: {
+ fred: {
+ status: "disabled",
+ disabledReason: "revoked_by_organization_admin",
+ disabledAt: "2026-09-20T12:00:00Z",
+ },
+ },
+ },
+ "org",
+ ),
+ ).toBeUndefined();
+});
+
it("does not discard other acceptances when a timestamp has an unexpected shape", async () => {
const terms = requirement(true);
Object.assign(terms.body.providers[0].terms, { digest: "a".repeat(64) });
diff --git a/apps/api/src/services/alexandria/terms.ts b/apps/api/src/services/alexandria/terms.ts
index 4c57e1d5b..b15afc60b 100644
--- a/apps/api/src/services/alexandria/terms.ts
+++ b/apps/api/src/services/alexandria/terms.ts
@@ -65,15 +65,13 @@ function timestamp(value: unknown): number {
return parsed.success ? Date.parse(parsed.data) : NaN;
}
+// Acceptance binds to the gating version, as the scrape gate and dashboard
+// compare it; a non-material revision changes the digest without invalidating it.
export function matchesAcceptance(
accepted: LedgerAcceptance | undefined,
- terms: { version: string; digest?: string },
+ terms: { version: string },
): boolean {
- return (
- terms.digest !== undefined &&
- accepted?.version === terms.version &&
- accepted.textHash === terms.digest
- );
+ return accepted?.version === terms.version;
}
// Whether the acceptance was recorded after `since`, e.g. an admin revocation