The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 06:00 UTC
| 1 | import { PrismaApiError } from "@alchemy.run/prisma/Client"; |
| 2 | import { describe, expect, it } from "@alchemy.run/test"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import * as Redacted from "effect/Redacted"; |
| 5 | import { Credentials } from "../../../prisma/src/internal/Credentials.ts"; |
| 6 | import { |
| 7 | getBuildLogsRequest, |
| 8 | getDeploymentLogsRequest, |
| 9 | } from "../../../prisma/src/internal/LogsClient.ts"; |
| 10 | |
| 11 | const provideEnv = Effect.provideService( |
| 12 | Credentials, |
| 13 | Effect.succeed({ apiToken: Redacted.make("test-token"), apiBaseUrl: "https://api.prisma.test" }), |
| 14 | ); |
| 15 | |
| 16 | describe("Prisma log request builders", { tags: ["unit", "provider:prisma", "local"] }, () => { |
| 17 | it.effect("builds authenticated deployment log stream requests", () => |
| 18 | Effect.gen(function* () { |
| 19 | const request = yield* getDeploymentLogsRequest("deployment-1", { |
| 20 | tail: 100, |
| 21 | fromStart: true, |
| 22 | cursor: "byte-42", |
| 23 | }); |
| 24 | expect(request.url).toBe( |
| 25 | "wss://api.prisma.test/v1/deployments/deployment-1/logs?tail=100&cursor=byte-42&from_start=true", |
| 26 | ); |
| 27 | expect(Redacted.value(request.headers.Authorization)).toBe("Bearer test-token"); |
| 28 | }).pipe(provideEnv), |
| 29 | ); |
| 30 | |
| 31 | it.effect("builds authenticated build log stream requests", () => |
| 32 | Effect.gen(function* () { |
| 33 | const request = yield* getBuildLogsRequest("build-1", { follow: true, cursor: "cursor-1" }); |
| 34 | expect(request.url).toBe( |
| 35 | "https://api.prisma.test/v1/builds/build-1/logs?follow=true&cursor=cursor-1", |
| 36 | ); |
| 37 | expect(Redacted.value(request.headers.Authorization)).toBe("Bearer test-token"); |
| 38 | expect(request.headers.Accept).toBe("application/x-ndjson"); |
| 39 | }).pipe(provideEnv), |
| 40 | ); |
| 41 | |
| 42 | it.effect("rejects path-confusing resource IDs before building a URL", () => |
| 43 | Effect.gen(function* () { |
| 44 | const deploymentLog = yield* getDeploymentLogsRequest("deployment-1/../../projects").pipe( |
| 45 | Effect.flip, |
| 46 | ); |
| 47 | const buildLog = yield* getBuildLogsRequest("build-1?token=leak").pipe(Effect.flip); |
| 48 | |
| 49 | for (const error of [deploymentLog, buildLog]) { |
| 50 | expect(error).toBeInstanceOf(PrismaApiError); |
| 51 | expect(error.message).toContain("invalid Prisma Management API"); |
| 52 | } |
| 53 | }).pipe(provideEnv), |
| 54 | ); |
| 55 | }); |