| @@ -4,7 +4,7 @@ · 3 unmodified lines |
| 4 | // single org. | 4 | // single org. |
| 5 | | 5 | |
| 6 | import { describe, expect, it } from "@effect/vitest"; | 6 | import { describe, expect, it } from "@effect/vitest"; |
| 7 | import { Effect } from "effect"; | 7 | import { Effect, Result, Schema } from "effect"; |
| 8 | import http from "node:http"; | 8 | import http from "node:http"; |
| 9 | import { readFileSync } from "node:fs"; | 9 | import { readFileSync } from "node:fs"; |
| 10 | import type { AddressInfo } from "node:net"; | 10 | import type { AddressInfo } from "node:net"; |
| @@ -173,6 +173,11 @@ const GRAPHQL_INTROSPECTION_RESPONSE = { · 162 unmodified lines |
| 173 | }, | 173 | }, |
| 174 | }; | 174 | }; |
| 175 | | 175 | |
| | 176 | const GraphqlRequestSchema = Schema.Struct({ |
| | 177 | query: Schema.optional(Schema.String), |
| | 178 | variables: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)), |
| | 179 | }); |
| | 180 | |
| 176 | const startGraphqlServer = () => { | 181 | const startGraphqlServer = () => { |
| 177 | const requests: Array<{ readonly query: string; readonly variables: unknown }> = []; | 182 | const requests: Array<{ readonly query: string; readonly variables: unknown }> = []; |
| 178 | const server = http.createServer(async (req, res) => { | 183 | const server = http.createServer(async (req, res) => { |
| @@ -182,10 +187,9 @@ const startGraphqlServer = () => { · 3 unmodified lines |
| 182 | return; | 187 | return; |
| 183 | } | 188 | } |
| 184 | | 189 | |
| 185 | const parsed = JSON.parse(await readBody(req)) as { | 190 | const parsed = await Schema.decodeUnknownPromise(Schema.fromJsonString(GraphqlRequestSchema))( |
| 186 | readonly query?: string; | 191 | await readBody(req), |
| 187 | readonly variables?: Record<string, unknown>; | 192 | ); |
| 188 | }; | | |
| 189 | const query = parsed.query ?? ""; | 193 | const query = parsed.query ?? ""; |
| 190 | requests.push({ query, variables: parsed.variables ?? null }); | 194 | requests.push({ query, variables: parsed.variables ?? null }); |
| 191 | | 195 | |
| @@ -411,9 +415,8 @@ describe("sources api (HTTP)", () => { · 219 unmodified lines |
| 411 | }), | 415 | }), |
| 412 | ); | 416 | ); |
| 413 | | 417 | |
| 414 | if (execution.status !== "completed") { | 418 | expect(execution.status).toBe("completed"); |
| 415 | throw new Error(`Expected completed execution, got ${execution.status}`); | 419 | if (execution.status !== "completed") return; |
| 416 | } | | |
| 417 | expect(execution.isError).toBe(false); | 420 | expect(execution.isError).toBe(false); |
| 418 | expect(execution.structured).toMatchObject({ | 421 | expect(execution.structured).toMatchObject({ |
| 419 | status: "completed", | 422 | status: "completed", |
| @@ -448,7 +451,7 @@ describe("sources api (HTTP)", () => { · 28 unmodified lines |
| 448 | }) | 451 | }) |
| 449 | .pipe(Effect.result), | 452 | .pipe(Effect.result), |
| 450 | ); | 453 | ); |
| 451 | expect(addResult._tag).toBe("Failure"); | 454 | expect(Result.isFailure(addResult)).toBe(true); |
| 452 | | 455 | |
| 453 | const fetched = yield* asOrg(org, (client) => | 456 | const fetched = yield* asOrg(org, (client) => |
| 454 | client.mcp.getSource({ params: { scopeId, namespace } }), | 457 | client.mcp.getSource({ params: { scopeId, namespace } }), |
| @@ -518,9 +521,8 @@ describe("sources api (HTTP)", () => { · 63 unmodified lines |
| 518 | }), | 521 | }), |
| 519 | ); | 522 | ); |
| 520 | | 523 | |
| 521 | if (execution.status !== "completed") { | 524 | expect(execution.status).toBe("completed"); |
| 522 | throw new Error(`Expected completed execution, got ${execution.status}`); | 525 | if (execution.status !== "completed") return; |
| 523 | } | | |
| 524 | expect(execution.isError).toBe(false); | 526 | expect(execution.isError).toBe(false); |
| 525 | expect(execution.structured).toMatchObject({ | 527 | expect(execution.structured).toMatchObject({ |
| 526 | status: "completed", | 528 | status: "completed", |
| @@ -587,9 +589,8 @@ describe("sources api (HTTP)", () => { · 60 unmodified lines |
| 587 | }), | 589 | }), |
| 588 | ); | 590 | ); |
| 589 | | 591 | |
| 590 | if (execution.status !== "completed") { | 592 | expect(execution.status).toBe("completed"); |
| 591 | throw new Error(`Expected completed execution, got ${execution.status}`); | 593 | if (execution.status !== "completed") return; |
| 592 | } | | |
| 593 | expect(execution.isError).toBe(false); | 594 | expect(execution.isError).toBe(false); |
| 594 | expect(execution.structured).toMatchObject({ | 595 | expect(execution.structured).toMatchObject({ |
| 595 | status: "completed", | 596 | status: "completed", |
| @@ -635,7 +636,7 @@ describe("sources api (HTTP)", () => { · 39 unmodified lines |
| 635 | .remove({ params: { scopeId: ScopeId.make(org), sourceId: ghost } }) | 636 | .remove({ params: { scopeId: ScopeId.make(org), sourceId: ghost } }) |
| 636 | .pipe(Effect.result), | 637 | .pipe(Effect.result), |
| 637 | ); | 638 | ); |
| 638 | expect(result._tag).toBe("Success"); | 639 | expect(Result.isSuccess(result)).toBe(true); |
| 639 | }), | 640 | }), |
| 640 | ); | 641 | ); |
| 641 | | 642 | |
| @@ -651,7 +652,7 @@ describe("sources api (HTTP)", () => { · 9 unmodified lines |
| 651 | .remove({ params: { scopeId: ScopeId.make(org), sourceId: "openapi" } }) | 652 | .remove({ params: { scopeId: ScopeId.make(org), sourceId: "openapi" } }) |
| 652 | .pipe(Effect.result), | 653 | .pipe(Effect.result), |
| 653 | ); | 654 | ); |
| 654 | expect(result._tag).toBe("Failure"); | 655 | expect(Result.isFailure(result)).toBe(true); |
| 655 | }), | 656 | }), |
| 656 | ); | 657 | ); |
| 657 | | 658 | |