held-back.ts
This file
Path
apps/platform/src/workflows/answer/held-back.ts
124 lines · 3.9 KiB · TypeScript
Last changed by
Merge build/comments-platform into mainoscabrielbefore adoptionddf09e8
History of this fileTake it
The walk stopped after 200 commits: lines older than 678c8b8 point at it.
Merge build/comments-platform into mainoscabrielbefore adoptionddf09e8
lines 1–2why, one step back1// The layer's files are read by the platform, so no layer route or token reaches the2// sandbox.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 3–124why, one step back3import { CheckAt, CheckRunner } from "@repo/checks/check-runner";4import { patchId } from "@repo/git/patch-id";5import { runBlockOf } from "@repo/project/answer-runs";6import type { AnswerRun } from "@repo/project/answer-runs";7import { noRunEnv } from "@repo/project/env-port";8import { LandingState } from "@repo/project/landing";9import { Projects } from "@repo/project/projects";10import type { HeldBackJob } from "@repo/project/visibility-port";11import { HeldBackResult } from "@repo/protocol/domain/answer";12import { PatchId, SuiteRoot } from "@repo/protocol/ids";13import type { ProjectName, RequestId, TreeSha } from "@repo/protocol/ids";14import { Refusal } from "@repo/protocol/refusal";15import { Effect, Option, Schema } from "effect";1617import { StepRunner } from "../step.ts";1819export const HeldBackRun = Schema.TaggedUnion({20 Blocked: { attempt: Schema.Int },21 Judged: {22 patchId: PatchId,23 refusals: Schema.Array(Refusal),24 results: Schema.Array(HeldBackResult),25 suite: SuiteRoot,26 },27 Unsealed: {},28});2930export type HeldBackRun = typeof HeldBackRun.Type;3132export type Judged = Extract<HeldBackRun, { readonly _tag: "Judged" }>;3334export const unsealed: HeldBackRun = HeldBackRun.cases.Unsealed.make({});3536const areaBits = (input: {37 readonly earlier: Option.Option<Judged>;38 readonly job: HeldBackJob;39 readonly patch: PatchId;40 readonly run: AnswerRun;41 readonly tree: TreeSha;42}) =>43 Option.match(44 Option.filter(45 input.earlier,46 ({ patchId: patched, suite }) =>47 patched === input.patch && suite === input.job.suite48 ),49 {50 onNone: () =>51 Effect.flatMap(runBlockOf(input.run), (block) =>52 CheckRunner.use((runner) =>53 runner.run({54 ...(input.run.env ?? noRunEnv),55 at: CheckAt.cases.Tree.make({ tree: input.tree }),56 heldBack: input.job,57 lanes: [],58 project: input.run.state.request.project,59 repo: input.run.state.request.fork,60 run: block,61 })62 )63 ).pipe(Effect.map(({ heldBack }) => heldBack)),64 onSome: ({ results }) => Effect.succeed(results),65 }66 );6768export const heldBack = (69 params: { readonly project: ProjectName; readonly requestId: RequestId },70 tree: TreeSha,71 attempt: number,72 earlier: Option.Option<Judged>73): Effect.Effect<HeldBackRun, never, CheckRunner | Projects | StepRunner> =>74 Effect.flatMap(StepRunner, ({ step }) =>75 step(76 `held-back#${attempt}`,77 HeldBackRun,78 Effect.gen(function* () {79 const api = yield* Projects.use((projects) =>80 projects.get(params.project)81 ).pipe(Effect.orDie);8283 const run = yield* api.answer(params.requestId);8485 const checking = Option.flatMap(run, (found) =>86 LandingState.guards.Checking(found.state) && found.state.tree === tree87 ? Option.some({ found, state: found.state })88 : Option.none()89 );9091 if (Option.isNone(checking)) {92 return unsealed;93 }9495 const { found, state } = checking.value;96 const job = yield* api.heldBackJob(params.requestId);9798 if (Option.isNone(job)) {99 return unsealed;100 }101102 const patch = yield* patchId(state.changes);103104 const results = yield* areaBits({105 earlier,106 job: job.value,107 patch,108 run: found,109 tree,110 }).pipe(Effect.option);111112 if (Option.isNone(results)) {113 return HeldBackRun.cases.Blocked.make({ attempt: state.attempt });114 }115116 return HeldBackRun.cases.Judged.make({117 patchId: patch,118 refusals: yield* api.recordHeldBack(params.requestId, results.value),119 results: results.value,120 suite: job.value.suite,121 });122 })123 )124 );