Diffinery

codician/diffinerypublic

Open-source, agent-first GitHub and GitHub Actions alternative that runs on your own Cloudflare account: git hosting, pull requests, code review and drop-in GitHub Actions YAML on Workers, Durable Objects, R2 and Containers.

25 lines · 1.2 KBRaw History
1import { describe, expect, it } from "vitest";
2import { parse } from "graphql";
3import { measure } from "../../src/http/graphql.js";
4import { randomAlnum } from "../../src/lib/util.js";
5
6describe("GraphQL limits", () => {
7 it("counts fields and depth with fragments expanded where they're spread", () => {
8 const doc = parse(`fragment pr on PullRequest { number title commits(last: 1) { nodes { commit { oid } } } }
9 query { a: repository(owner: "o", name: "r") { p1: pullRequest(number: 1) { ...pr } p2: pullRequest(number: 2) { ...pr } } }`);
10 // repository + 2 × (pullRequest + number + title + commits + nodes + commit + oid)
11 expect(measure(doc)).toEqual({ fields: 15, depth: 6 });
12 });
13
14 it("doesn't loop on a fragment that spreads itself", () => {
15 const doc = parse(`fragment f on Repository { id parent { ...f } } query { repository(owner: "o", name: "r") { ...f } }`);
16 expect(measure(doc).fields).toBe(3);
17 });
18});
19
20describe("randomAlnum", () => {
21 it("draws letters and digits only, at the asked length", () => {
22 for (const n of [1, 40, 200]) expect(randomAlnum(n)).toMatch(new RegExp(`^[A-Za-z0-9]{${n}}$`));
23 expect(new Set(Array.from({ length: 20 }, () => randomAlnum(40))).size).toBe(20);
24 });
25});