|
1 | 1 | import * as Schema from "@effect/schema/Schema" |
| 2 | +import * as ParseResult from "@effect/schema/ParseResult" |
2 | 3 | import { describe, expect, it } from "@effect/vitest" |
3 | 4 | import { createClient } from "@prover-coder-ai/docker-git-openapi" |
4 | 5 | import type { ApiTransportValue } from "@prover-coder-ai/docker-git-openapi" |
5 | | -import { Effect } from "effect" |
| 6 | +import { Effect, Either } from "effect" |
6 | 7 | import * as fc from "fast-check" |
7 | 8 |
|
8 | 9 | type CapturedRequest = { |
@@ -39,6 +40,25 @@ const createMockFetch = ( |
39 | 40 | return Effect.runPromise(Effect.succeed(response)) |
40 | 41 | } |
41 | 42 |
|
| 43 | +/** |
| 44 | + * Runs a fast-check synchronous property inside the Effect test runtime. |
| 45 | + * |
| 46 | + * @param property - Finite pure property over OpenAPI boundary values. |
| 47 | + * @returns Effect that fails when fast-check finds a counterexample. |
| 48 | + * |
| 49 | + * @pure false - executes property samples. |
| 50 | + * @effect Effect.sync, fc.assert. |
| 51 | + * @invariant success proves every sampled case preserved the asserted pure invariant. |
| 52 | + * @precondition property predicate is synchronous and total. |
| 53 | + * @postcondition counterexamples are surfaced through the Effect error channel. |
| 54 | + * @complexity O(r * c) where r is numRuns and c is one predicate cost. |
| 55 | + * @throws Never. |
| 56 | + */ |
| 57 | +const assertOpenApiClientSyncProperty = <PropertyArgs>(property: fc.IProperty<PropertyArgs>) => |
| 58 | + Effect.sync(() => { |
| 59 | + fc.assert(property, { numRuns: 25 }) |
| 60 | + }) |
| 61 | + |
42 | 62 | /** |
43 | 63 | * Runs a fast-check async property inside the Effect test runtime. |
44 | 64 | * |
@@ -91,6 +111,16 @@ describe("docker-git OpenAPI Effect client", () => { |
91 | 111 | expect(new URL(requests[0]?.url ?? "").searchParams.has("_")).toBe(true) |
92 | 112 | })) |
93 | 113 |
|
| 114 | + it.effect("property: schema decoding preserves JSON null transport values", () => |
| 115 | + assertOpenApiClientSyncProperty( |
| 116 | + fc.property(fc.constant(null), (value) => |
| 117 | + Either.match(ParseResult.decodeUnknownEither(Schema.Null)(value), { |
| 118 | + onLeft: () => false, |
| 119 | + onRight: (decoded) => decoded === null |
| 120 | + }) |
| 121 | + ) |
| 122 | + )) |
| 123 | + |
94 | 124 | it.effect("property: GET requests always include no-cache transport invariants", () => |
95 | 125 | assertOpenApiClientProperty( |
96 | 126 | fc.asyncProperty( |
|
0 commit comments