Skip to content
Myr

env-shape.test.ts

This file

Path

packages/visibility/test/env-shape.test.ts

110 lines · 3.4 KiB · TypeScript

Last changed by

Merge build/comments-packages-rest into mainoscabrielbefore adoption38cd503

History of this file

Take it

The walk stopped after 200 commits: lines older than 678c8b8 point at it.

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 1–16why, one step back
1import { describe, expect, it } from "@effect/vitest";
2import { EnvSchemaView } from "@repo/protocol/domain/env";3import { LandedSha, ProjectName } from "@repo/protocol/ids";4import { Effect, Option, Schema } from "effect";56import { EnvSchemaParser } from "../src/env-schema.ts";7import { EnvSchemaParserEnvSpec } from "../src/env-schema/env-spec.ts";8import { EnvSchemaParserMemory } from "../src/env-schema/memory.ts";9import {10 envSchemaViewOf,11 isSensitive,12 proxyOf,13 requiredOf,14} from "../src/env-shape.ts";15import { fixtures, parsedByFile, refused } from "./fixtures/env/cases.ts";16

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

line 17why, one step back
17const project = ProjectName.make("oscabriel/datekit");

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 18–41why, one step back
18
19const at = LandedSha.make("a1".repeat(20));2021const parsers = [22 ["the /memory fake", EnvSchemaParserMemory(parsedByFile)],23 ["the /env-spec adapter", EnvSchemaParserEnvSpec],24] as const;2526describe.each(parsers)("the env shape, read through %s", (_, layer) => {27 it.effect.each(fixtures)("$title", ({ file, text, view }) =>28 Effect.gen(function* () {29 const parser = yield* EnvSchemaParser;30 const parsed = yield* parser.parse(file, text);31 const shown = envSchemaViewOf({ at, file, parsed, project });3233 expect(yield* Schema.encodeEffect(EnvSchemaView)(shown)).toStrictEqual({34 ...view,35 at,36 file,37 project,38 });39 }).pipe(Effect.provide(layer))40 );41

Drop the private build plan's citations from the code, and fail verify if one comes backoscabrielbefore adoptiona29cef6

line 42why, one step back
42 // An import from outside the repo is never followed, so the

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 43–110why, one step back
43 // schema that names one is refused whole.
44 it.effect.each(refused)("refuses $title", ({ file, reason, text }) =>45 Effect.gen(function* () {46 const parser = yield* EnvSchemaParser;47 const unreadable = yield* Effect.flip(parser.parse(file, text));4849 expect(unreadable._tag).toBe("EnvSchemaUnreadable");50 expect(unreadable.file).toBe(file);51 expect(unreadable.reason).toBe(reason);52 }).pipe(Effect.provide(layer))53 );54});5556// The pure readers where varlock would refuse the schema or only the57// environment decides: they fail safe, never toward showing or sending a58// value.59describe("the env shape's readers", () => {60 const host = {61 fn: "ref",62 named: [],63 positional: ["UPLOAD_HOST"],64 text: "ref(UPLOAD_HOST)",65 };6667 const proxiedTo = {68 decorators: [69 {70 name: "proxy",71 value: { named: [{ key: "domain", value: host }], positional: [] },72 },73 ],74 key: "UPLOAD_TOKEN",75 };7677 it("send a value to no host the environment names, and keep its item sensitive", () => {78 expect(proxyOf(proxiedTo)).toStrictEqual(Option.none());79 expect(80 isSensitive(proxiedTo, [{ name: "defaultSensitive", value: false }])81 ).toBeTruthy();82 });8384 it("read @proxy=passthrough as no rule", () => {85 const passthrough = {86 decorators: [{ name: "proxy", value: "passthrough" }],87 key: "LEGACY_TOKEN",88 };8990 expect(proxyOf(passthrough)).toStrictEqual(Option.none());91 expect(92 isSensitive(passthrough, [{ name: "defaultSensitive", value: false }])93 ).toBeFalsy();94 });9596 it("count a header default only the environment decides as sensitive, and as depends", () => {97 const item = { decorators: [], key: "API_KEY", value: "x" };9899 const header = [100 {101 name: "defaultRequired",102 value: { ...host, fn: "forEnv", text: "forEnv(prod)" },103 },104 { name: "defaultSensitive", value: "maybe" },105 ];106107 expect(requiredOf(item, header)).toBe("depends");108 expect(isSensitive(item, header)).toBeTruthy();109 });110});