Skip to content
Myr

check-runner-sandbox.ts

This file

Path

apps/platform/src/adapters/check-runner-sandbox.ts

103 lines · 2.9 KiB · TypeScript

Last changed by

Merge build/comments-platform into mainoscabrielbefore adoptionddf09e8

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–38why, one step back
1import { RepoHost } from "@repo/artifacts/repo-host";
2import { CheckRunner } from "@repo/checks/check-runner";3import type { CheckJob, CheckRun } from "@repo/checks/check-runner";4import { CheckExit, CheckWire } from "@repo/checks/check-runner/wire";5import type {6 BundleExit,7 BundleWire,8 ComposeExit,9 ComposeWire,10 LandExit,11 LandWire,12 MergeExit,13 MergeWire,14} from "@repo/project/lander/wire";15import type { HeldBackResult } from "@repo/protocol/domain/answer";16import { VerifierBlocked } from "@repo/protocol/refusal";17import { Array, Effect, Layer } from "effect";1819import { sandboxJob, withRemote } from "./sandbox-credentials.ts";2021export interface SandboxBinding {22 readonly check: (23 wire: typeof CheckWire.Encoded24 ) => Promise<typeof CheckExit.Encoded>;25 readonly merge: (26 wire: typeof MergeWire.Encoded27 ) => Promise<typeof MergeExit.Encoded>;28 readonly land: (29 wire: typeof LandWire.Encoded30 ) => Promise<typeof LandExit.Encoded>;31 readonly compose: (32 wire: typeof ComposeWire.Encoded33 ) => Promise<typeof ComposeExit.Encoded>;34 readonly bundleRules: (35 wire: typeof BundleWire.Encoded36 ) => Promise<typeof BundleExit.Encoded>;37}38

Merge build/comments-platform into mainoscabrielbefore adoptionddf09e8

line 39why, one step back
39// Bits that answer some other job are the platform's trouble, never a result an answer earned.

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 40–103why, one step back
40const answersJob = (job: CheckJob, bits: readonly HeldBackResult[]) => {
41 const suite = job.heldBack;4243 if (suite === undefined) {44 return bits.length === 0;45 }4647 const areas = Array.dedupe(suite.areas);4849 return (50 bits.length === areas.length &&51 areas.every((area, index) => {52 const each = bits[index];53 const total = suite.runs.filter((run) => run.area === area).length;5455 return (56 each !== undefined &&57 each.area === area &&58 each.suite === suite.suite &&59 each.total === total &&60 each.passed >= 0 &&61 each.passed <= total62 );63 })64 );65};6667const heldTo = (job: CheckJob) => (ran: CheckRun) =>68 answersJob(job, ran.heldBack)69 ? Effect.succeed(ran)70 : Effect.logError("sandbox job blocked").pipe(71 Effect.annotateLogs({72 failure: "held-back bits do not answer the job",73 method: "check",74 }),75 Effect.andThen(Effect.fail(new VerifierBlocked({})))76 );7778export const CheckRunnerSandbox = (79 sandbox: SandboxBinding80): Layer.Layer<CheckRunner, never, RepoHost> =>81 Layer.effect(82 CheckRunner,83 Effect.gen(function* () {84 const host = yield* RepoHost;8586 return CheckRunner.of({87 run: (job) =>88 withRemote("check", { repo: job.repo, scope: "read" }, (clone) =>89 sandboxJob({90 exit: CheckExit,91 job: { clone, job },92 method: "check",93 remotes: [clone],94 send: (wire) => sandbox.check(wire),95 wire: CheckWire,96 })97 ).pipe(98 Effect.flatMap(heldTo(job)),99 Effect.provideService(RepoHost, host)100 ),101 });102 })103 );