The best way to control Claude Code, Codex and more from any computer or phone

main
ts 74 lines 2.65 KB
Raw
1 import { assert, describe, it } from "@effect/vitest"
2 import { assertDefinitions, assertDiagnostic, name, namedType, parseOrThrow, str, stripLoc } from "./utils/ast.ts"
3
4 describe("Parser: executable documents", () => {
5 it("the shorthand is a query without a name", () => {
6 assertDefinitions("{ a }", [{
7 _tag: "OperationDefinition",
8 operation: "query",
9 variableDefinitions: [],
10 directives: [],
11 selectionSet: {
12 _tag: "SelectionSet",
13 selections: [{ _tag: "Field", name: name("a"), arguments: [], directives: [] }]
14 }
15 }])
16 })
17
18 it("locations are UTF-16 offsets into the body with an exclusive end", () => {
19 const document = parseOrThrow("{ a }")
20 assert.deepStrictEqual(document.loc, { start: 0, end: 5 })
21 const operation = document.definitions[0]!
22 assert(operation._tag === "OperationDefinition")
23 assert.deepStrictEqual(operation.selectionSet.selections[0]!.loc, { start: 2, end: 3 })
24 })
25
26 it("operations and variable definitions carry descriptions (September 2025 edition)", () => {
27 // Expectations are untyped until `Ast.ts` gains `description` on these nodes.
28 const definitions: unknown = stripLoc(parseOrThrow("\"op doc\" query Q(\"x doc\" $x: Int) { a }")).definitions
29 assert.deepStrictEqual(definitions, [{
30 _tag: "OperationDefinition",
31 description: str("op doc"),
32 operation: "query",
33 name: name("Q"),
34 variableDefinitions: [{
35 _tag: "VariableDefinition",
36 description: str("x doc"),
37 variable: { _tag: "Variable", name: name("x") },
38 type: namedType("Int"),
39 directives: []
40 }],
41 directives: [],
42 selectionSet: {
43 _tag: "SelectionSet",
44 selections: [{ _tag: "Field", name: name("a"), arguments: [], directives: [] }]
45 }
46 }])
47 })
48
49 describe("diagnostics", () => {
50 it("empty document", () => {
51 assertDiagnostic("", { line: 1, column: 1, message: "Unexpected <EOF>." })
52 })
53
54 it("description on the query shorthand", () => {
55 assertDiagnostic("\"docs\" { a }", {
56 line: 1,
57 column: 1,
58 message: "Unexpected description, descriptions are not supported on shorthand queries."
59 })
60 })
61
62 it("variable in selection position", () => {
63 assertDiagnostic("{ $v }", { line: 1, column: 3, message: "Expected Name, found \"$\"." })
64 })
65
66 it("fragment named on", () => {
67 assertDiagnostic("fragment on on T { a }", { line: 1, column: 10, message: "Unexpected Name \"on\"." })
68 })
69
70 it("fragment without a type condition", () => {
71 assertDiagnostic("fragment F { a }", { line: 1, column: 12, message: "Expected \"on\", found \"{\"." })
72 })
73 })
74 })