init.test.ts
This file
Path
apps/cli/test/local/init.test.ts
906 lines · 26.1 KiB · TypeScript
Last changed by
Merge build/comments-cli-protocol-checks into mainoscabrielbefore adoptionc86204f
History of this fileTake 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–6why, one step back1import { NodeServices } from "@effect/platform-node";2import { describe, expect, it } from "@effect/vitest";3import { Brand } from "@repo/brand";4import { Client, Contracts } from "@repo/protocol/contracts";5import type { InitProject } from "@repo/protocol/contracts";6import { Envelope } from "@repo/protocol/envelope";Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 7why, one step back7import { Handle, LandedSha, ProjectName } from "@repo/protocol/ids";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 8–19why, one step back8import { ProjectExists } from "@repo/protocol/refusal";9import type { ImportFailed } from "@repo/protocol/refusal";10import { asTester, unanswered } from "@repo/protocol/testing";11import { git, gitOk } from "@repo/testkit/git";12import {13 Cause,14 Effect,15 Exit,16 FileSystem,17 Layer,18 Option,19 Path,Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 20why, one step back20 Redacted,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 21–29why, one step back21 Ref,22 Runtime,23 Schema,24} from "effect";25import { CliOutput } from "effect/cli";26import { ChildProcess, ChildProcessSpawner } from "effect/process";27import { RpcTest } from "effect/rpc";28import { TestConsole } from "effect/testing";29Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 30why, one step back30import { Credentials } from "../../src/credentials.ts";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 31–35why, one step back31import { projectFile } from "../../src/local/project-file.ts";32import { program } from "../../src/main.ts";33import { OutputPlain } from "../../src/output.ts";34import { SignedOut } from "../signed-out.ts";35Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
lines 36–45why, one step back36const signedInAs = (handle: string) =>37 Layer.mock(Credentials)({38 current: Effect.succeedSome({39 handle: Handle.make(handle),40 token: Redacted.make("a-token-0123456789"),41 url: "https://platform.example.test",42 }),43 forHost: () => Effect.succeedNone,44 });45Merge 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 46–103why, one step back46const CONFIG = `${Brand.configDir}/project.ts`;4748const scripts = {49 lint: "oxlint",50 test: "vitest run",51 typecheck: "tsc --noEmit",52};5354const ci = [55 "on: push",56 "jobs:",57 " test:",58 " runs-on: ubuntu-latest",59 " steps:",60 " - uses: actions/checkout@v4",61 " - run: bun install --frozen-lockfile",62 " - run: bun run test",63 "",64].join("\n");6566const proposal = projectFile(67 {68 checks: Object.fromEntries(69 new Map([70 ["unit", "bun run test"],71 ["lint", "bun run lint"],72 ["types", "bun run typecheck"],73 ])74 ),75 setup: "bun install --frozen-lockfile",76 test: "vitest run {path}",77 },78 [79 "setup from .github/workflows/ci.yml",80 "test from package.json",81 "checks.unit from .github/workflows/ci.yml",82 "checks.lint from package.json",83 "checks.types from package.json",84 ]85);8687const aMachine = Effect.gen(function* () {88 const fs = yield* FileSystem.FileSystem;89 const path = yield* Path.Path;90 const home = yield* fs.realPath(yield* fs.makeTempDirectoryScoped());91 const repo = yield* fs.realPath(yield* fs.makeTempDirectoryScoped());92 const bare = yield* fs.realPath(yield* fs.makeTempDirectoryScoped());93 const gitconfig = path.join(home, ".gitconfig");9495 yield* fs.writeFileString(96 gitconfig,97 "[user]\n\tname = Maintainer\n\temail = maintainer@example.com\n"98 );99100 yield* gitOk(repo, "init", "--quiet", "--initial-branch=work");101102 yield* fs.writeFileString(103 path.join(repo, "package.json"),Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 104why, one step back104 JSON.stringify({ name: "oscabriel/demo", scripts }, null, 2)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 105–180why, one step back105 );106107 yield* fs.makeDirectory(path.join(repo, ".github", "workflows"), {108 recursive: true,109 });110111 yield* fs.writeFileString(path.join(repo, ".github/workflows/ci.yml"), ci);112 yield* gitOk(repo, "add", "-A");113 yield* gitOk(repo, "commit", "--quiet", "--message", "Start");114 yield* gitOk(bare, "init", "--quiet", "--bare");115116 return { bare, gitconfig, home, remote: `file://${bare}`, repo };117});118119type Machine = Effect.Success<typeof aMachine>;120121const startedIn = (machine: Machine) =>122 Layer.effect(ChildProcessSpawner.ChildProcessSpawner)(123 Effect.gen(function* () {124 const real = yield* ChildProcessSpawner.ChildProcessSpawner;125 const path = yield* Path.Path;126127 const env = {128 GIT_CONFIG_GLOBAL: machine.gitconfig,129 GIT_CONFIG_NOSYSTEM: "1",130 GIT_TERMINAL_PROMPT: "0",131 HOME: machine.home,132 LC_ALL: "C",133 XDG_CONFIG_HOME: path.join(machine.home, ".config"),134 };135136 return ChildProcessSpawner.make((command) =>137 real.spawn(138 ChildProcess.isStandardCommand(command)139 ? ChildProcess.make(command.command, command.args, {140 ...command.options,141 cwd: path.resolve(machine.repo, command.options.cwd ?? "."),142 env: { ...command.options.env, ...env },143 extendEnv: true,144 })145 : command146 )147 );148 })149 ).pipe(Layer.provide(NodeServices.layer));150151const aPlatform = (152 reply: Effect.Effect<153 typeof InitProject.successSchema.Type,154 ProjectExists | ImportFailed155 >156) =>157 Effect.map(Ref.make<readonly unknown[]>([]), (calls) => ({158 calls: Ref.get(calls),159 layer: Layer.effect(Client)(RpcTest.makeClient(Contracts)).pipe(160 Layer.provide([161 Layer.mergeAll(162 unanswered,163 Contracts.toLayerHandler("initProject", (payload) =>164 Effect.andThen(165 Ref.update(calls, (all) => [...all, payload]),166 reply167 )168 )169 ),170 asTester,171 ])172 ),173 }));174175const exitCodeOf = (exit: Exit.Exit<unknown, unknown>) =>176 Exit.isSuccess(exit) ? 0 : Runtime.getErrorExitCode(Cause.squash(exit.cause));177178const cli = (179 machine: Machine,180 platform: Layer.Layer<Client>,Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
lines 181–182why, one step back181 argv: readonly string[],182 credentials: Layer.Layer<Credentials> = SignedOutMerge 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 183–201why, one step back183) =>184 Effect.gen(function* () {185 const exit = yield* Effect.exit(program(argv));186187 return {188 code: exitCodeOf(exit),189 err: (yield* TestConsole.errorLines).flatMap((chunk) =>190 String(chunk).split("\n")191 ),192 out: (yield* TestConsole.logLines).map(String),193 };194 }).pipe(195 Effect.provide(196 Layer.mergeAll(197 NodeServices.layer,198 TestConsole.layer,199 CliOutput.layer(CliOutput.defaultFormatter({ colors: false })),200 OutputPlain,201 platform,Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 202why, one step back202 credentials,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 203–245why, one step back203 startedIn(machine)204 )205 )206 );207208const decodeEnvelope = Schema.decodeEffect(209 Schema.fromJsonString(Envelope(Schema.Unknown))210);211212const envelopeOf = (out: readonly string[]) =>213 Effect.gen(function* () {214 expect(out).toHaveLength(1);215216 return yield* decodeEnvelope(out[0] ?? "");217 });218219const state = (machine: Machine) =>220 Effect.gen(function* () {221 const fs = yield* FileSystem.FileSystem;222 const path = yield* Path.Path;223 const file = path.join(machine.repo, CONFIG);224225 return {226 branch: yield* gitOk(machine.repo, "branch", "--show-current"),227 commits: Number(228 yield* gitOk(machine.repo, "rev-list", "--count", "HEAD")229 ),230 config: (yield* fs.exists(file))231 ? Option.some(yield* fs.readFileString(file))232 : Option.none(),233 head: yield* gitOk(machine.repo, "rev-parse", "HEAD"),234 platformMain: (yield* git(235 machine.bare,236 "rev-parse",237 "--verify",238 "--quiet",239 "main"240 )).stdout.trim(),241 remotes: yield* gitOk(machine.repo, "remote"),242 };243 });244245const created = (machine: Machine) =>Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
lines 246–249why, one step back246 Effect.succeed({247 project: ProjectName.make("oscabriel/demo"),248 remote: machine.remote,249 });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 250–269why, one step back250251describe(`${Brand.cli} init in an existing repo`, () => {252 it.live(253 "writes the proposed config, commits it alone, makes the project, adds the remote and pushes HEAD to main",254 () =>255 Effect.gen(function* () {256 const fs = yield* FileSystem.FileSystem;257 const path = yield* Path.Path;258 const machine = yield* aMachine;259260 // Work in progress the maintainer has staged: init must leave it be.261 yield* fs.writeFileString(path.join(machine.repo, "notes.md"), "wip\n");262 yield* gitOk(machine.repo, "add", "notes.md");263264 const before = yield* state(machine);265 const platform = yield* aPlatform(created(machine));266267 const ran = yield* cli(machine, platform.layer, [268 "init",269 "--project",Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 270why, one step back270 "oscabriel/demo",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 271–279why, one step back271 "--yes",272 "--json",273 ]);274275 expect(ran.code).toBe(0);276 expect(yield* envelopeOf(ran.out)).toStrictEqual({277 command: "init",278 data: {279 files: [CONFIG],Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 280why, one step back280 project: "oscabriel/demo",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 281–286why, one step back281 pushed: true,282 remote: machine.remote,283 },284 ok: true,285 v: 1,286 });Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
lines 287–289why, one step back287 expect(yield* platform.calls).toStrictEqual([288 { project: "oscabriel/demo" },289 ]);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 290–335why, one step back290291 const after = yield* state(machine);292293 expect({294 branch: after.branch,295 commits: after.commits - before.commits,296 config: after.config,297 files: yield* gitOk(298 machine.repo,299 "show",300 "--name-only",301 "--format=",302 "HEAD"303 ),304 platformMain: after.platformMain,305 remote: yield* gitOk(machine.repo, "remote", "get-url", Brand.slug),306 remotes: after.remotes,307 staged: yield* gitOk(machine.repo, "diff", "--cached", "--name-only"),308 }).toStrictEqual({309 branch: "work",310 commits: 1,311 config: Option.some(proposal),312 files: CONFIG,313 platformMain: after.head,314 remote: machine.remote,315 remotes: Brand.slug,316 staged: "notes.md",317 });318 expect(319 yield* gitOk(machine.repo, "log", "-1", "--format=%s")320 ).toContain(CONFIG);321 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),322 { timeout: 30_000 }323 );324325 it.live(326 "without --yes exits 2 with a line naming --yes, and writes, calls and adds nothing",327 () =>328 Effect.gen(function* () {329 const machine = yield* aMachine;330 const before = yield* state(machine);331 const platform = yield* aPlatform(created(machine));332333 const ran = yield* cli(machine, platform.layer, [334 "init",335 "--project",Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 336why, one step back336 "oscabriel/demo",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 337–360why, one step back337 ]);338339 expect(ran.code).toBe(2);340 expect(ran.err.filter((line) => line.includes("--yes"))).toHaveLength(341 1342 );343 expect(ran.out).toStrictEqual([]);344 expect(yield* platform.calls).toStrictEqual([]);345 expect(yield* state(machine)).toStrictEqual(before);346 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),347 { timeout: 30_000 }348 );349350 it.live(351 "with --dry-run prints the file, the payload and the git commands it would run, and does none of it",352 () =>353 Effect.gen(function* () {354 const machine = yield* aMachine;355 const before = yield* state(machine);356 const platform = yield* aPlatform(created(machine));357358 const ran = yield* cli(machine, platform.layer, [359 "init",360 "--project",Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 361why, one step back361 "oscabriel/demo",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 362–427why, one step back362 "--dry-run",363 "--json",364 ]);365366 expect(ran.code).toBe(0);367368 const envelope = yield* envelopeOf(ran.out);369370 const Plan = Schema.Struct({371 command: Schema.Literal("init"),372 data: Schema.Struct({373 dryRun: Schema.Literal(true),374 payload: Schema.Struct({375 files: Schema.Array(376 Schema.Struct({ content: Schema.String, path: Schema.String })377 ),378 git: Schema.Array(Schema.Array(Schema.String)),379 payload: Schema.Unknown,380 }),381 }),382 ok: Schema.Literal(true),383 });384385 const { payload: plan } = (yield* Schema.decodeUnknownEffect(Plan)(386 envelope387 )).data;388389 expect(plan).toStrictEqual({390 files: [{ content: proposal, path: CONFIG }],391 git: [392 ["git", "add", "--", CONFIG],393 [394 "git",395 "commit",396 "--quiet",397 "--message",398 expect.stringContaining(CONFIG),399 "--",400 CONFIG,401 ],402 ["git", "remote", "add", Brand.slug, expect.any(String)],403 [404 "git",405 "config",406 "--global",407 "--replace-all",408 expect.stringMatching(/^credential\..+\.helper$/u),409 "",410 ],411 [412 "git",413 "config",414 "--global",415 "--add",416 expect.stringMatching(/^credential\..+\.helper$/u),417 Brand.slug,418 ],419 [420 "git",421 "config",422 "--global",423 expect.stringMatching(/^credential\..+\.useHttpPath$/u),424 "true",425 ],426 ["git", "push", Brand.slug, "HEAD:main"],427 ],Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 428why, one step back428 payload: { project: "oscabriel/demo" },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 429–457why, one step back429 });430 expect({431 calls: yield* platform.calls,432 state: yield* state(machine),433 }).toStrictEqual({ calls: [], state: before });434 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),435 { timeout: 30_000 }436 );437438 it.live(439 "keeps a config the repo already has, says so, and does the rest",440 () =>441 Effect.gen(function* () {442 const fs = yield* FileSystem.FileSystem;443 const path = yield* Path.Path;444 const machine = yield* aMachine;445 const mine = "// the maintainer's own\nexport default {};\n";446447 yield* fs.makeDirectory(path.join(machine.repo, Brand.configDir));448 yield* fs.writeFileString(path.join(machine.repo, CONFIG), mine);449 yield* gitOk(machine.repo, "add", "-A");450 yield* gitOk(machine.repo, "commit", "--quiet", "--message", "Config");451452 const before = yield* state(machine);453 const platform = yield* aPlatform(created(machine));454455 const ran = yield* cli(machine, platform.layer, [456 "init",457 "--project",Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 458why, one step back458 "oscabriel/demo",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 459–472why, one step back459 "--yes",460 "--json",461 ]);462463 expect(ran.code).toBe(0);464 expect(465 ran.err.filter(466 (line) => line.includes(CONFIG) && line.includes("kept")467 )468 ).toHaveLength(1);469 expect(yield* envelopeOf(ran.out)).toStrictEqual({470 command: "init",471 data: {472 files: [],Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 473why, one step back473 project: "oscabriel/demo",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 474–514why, one step back474 pushed: true,475 remote: machine.remote,476 },477 ok: true,478 v: 1,479 });480481 const after = yield* state(machine);482483 expect({484 config: after.config,485 head: after.head,486 platformMain: after.platformMain,487 }).toStrictEqual({488 config: Option.some(mine),489 head: before.head,490 platformMain: before.head,491 });492 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),493 { timeout: 30_000 }494 );495496 it.live(497 "commits a config the work tree has and HEAD lacks, as it is, so a rerun after a failed commit pushes it",498 () =>499 Effect.gen(function* () {500 const fs = yield* FileSystem.FileSystem;501 const path = yield* Path.Path;502 const machine = yield* aMachine;503 const mine = "// the maintainer's own\nexport default {};\n";504505 // What a run whose commit failed (no user.name yet, a hook) leaves.506 yield* fs.makeDirectory(path.join(machine.repo, Brand.configDir));507 yield* fs.writeFileString(path.join(machine.repo, CONFIG), mine);508 yield* gitOk(machine.repo, "add", "--", CONFIG);509510 const platform = yield* aPlatform(created(machine));511512 const ran = yield* cli(machine, platform.layer, [513 "init",514 "--project",Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 515why, one step back515 "oscabriel/demo",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 516–524why, one step back516 "--yes",517 "--json",518 ]);519520 expect(ran.code).toBe(0);521 expect(yield* envelopeOf(ran.out)).toStrictEqual({522 command: "init",523 data: {524 files: [CONFIG],Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 525why, one step back525 project: "oscabriel/demo",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 526–547why, one step back526 pushed: true,527 remote: machine.remote,528 },529 ok: true,530 v: 1,531 });532 expect({533 committed: yield* gitOk(534 machine.repo,535 "show",536 "--name-only",537 "--format=",538 "HEAD"539 ),540 onPlatform: (yield* git(machine.bare, "show", `main:${CONFIG}`))541 .stdout,542 }).toStrictEqual({ committed: CONFIG, onPlatform: mine });543 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),544 { timeout: 30_000 }545 );546547 it.live(Merge cli/exit-codes into mainoscabrielbefore adoptionc19a862
line 548why, one step back548 "prints ProjectExists once and exits 65, pushing nothing",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 549–553why, one step back549 () =>550 Effect.gen(function* () {551 const machine = yield* aMachine;552553 const platform = yield* aPlatform(Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
lines 554–556why, one step back554 Effect.fail(555 new ProjectExists({ project: ProjectName.make("oscabriel/demo") })556 )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 557–561why, one step back557 );558559 const ran = yield* cli(machine, platform.layer, [560 "init",561 "--project",Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 562why, one step back562 "oscabriel/demo",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 563–565why, one step back563 "--yes",564 ]);565Merge cli/exit-codes into mainoscabrielbefore adoptionc19a862
line 566why, one step back566 expect(ran.code).toBe(65);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 567–568why, one step back567 expect(568 ran.err.filter((line) =>Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 569why, one step back569 line.includes("a project named oscabriel/demo already exists")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 570–572why, one step back570 )571 ).toHaveLength(1);572 expect(ran.out).toStrictEqual([]);Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
lines 573–575why, one step back573 expect(yield* platform.calls).toStrictEqual([574 { project: "oscabriel/demo" },575 ]);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 576–595why, one step back576577 const after = yield* state(machine);578579 expect({580 platformMain: after.platformMain,581 remotes: after.remotes,582 }).toStrictEqual({ platformMain: "", remotes: "" });583 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),584 { timeout: 30_000 }585 );586587 it.live(588 "sets up git's credential helper for an https platform, prints what it changed, and with --no-push pushes nothing",589 () =>590 Effect.gen(function* () {591 const machine = yield* aMachine;592 const platformUrl = "https://platform.example.test";593 const gateway = `${platformUrl}/demo.git`;594595 const platform = yield* aPlatform(Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
lines 596–599why, one step back596 Effect.succeed({597 project: ProjectName.make("oscabriel/demo"),598 remote: gateway,599 })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 600–604why, one step back600 );601602 const ran = yield* cli(machine, platform.layer, [603 "init",604 "--project",Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 605why, one step back605 "oscabriel/demo",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 606–615why, one step back606 "--yes",607 "--no-push",608 "--json",609 ]);610611 expect(ran.code).toBe(0);612 expect(yield* envelopeOf(ran.out)).toStrictEqual({613 command: "init",614 data: {615 files: [CONFIG],Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 616why, one step back616 project: "oscabriel/demo",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 617–674why, one step back617 pushed: false,618 remote: gateway,619 },620 ok: true,621 v: 1,622 });623624 const helpers = yield* git(625 machine.repo,626 "config",627 "--file",628 machine.gitconfig,629 "--get-all",630 `credential.${platformUrl}.helper`631 );632633 expect({634 helpers: helpers.stdout.trimEnd().split("\n"),635 platformMain: (yield* state(machine)).platformMain,636 printed: ran.err.filter((line) =>637 line.includes(`credential.${platformUrl}.helper`)638 ).length,639 useHttpPath: yield* gitOk(640 machine.repo,641 "config",642 "--file",643 machine.gitconfig,644 `credential.${platformUrl}.useHttpPath`645 ),646 }).toStrictEqual({647 // An empty helper first drops any general one, then the CLI's.648 helpers: ["", Brand.slug],649 platformMain: "",650 printed: 2,651 useHttpPath: "true",652 });653 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),654 { timeout: 30_000 }655 );656});657658describe(`${Brand.cli} init --import`, () => {659 it.live(660 "asks the platform to import the public repo, touches nothing here, and prints the clone command",661 () =>662 Effect.gen(function* () {663 const machine = yield* aMachine;664 const before = yield* state(machine);665 const url = "https://example.test/acme/widgets.git";666 const gateway = "https://platform.example.test/widgets.git";667668 const landed = LandedSha.make(669 "4444444444444444444444444444444444444444"670 );671672 const platform = yield* aPlatform(673 Effect.succeed({674 landed,Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 675why, one step back675 project: ProjectName.make("oscabriel/widgets"),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 676–683why, one step back676 remote: gateway,677 })678 );679680 const ran = yield* cli(machine, platform.layer, [681 "init",682 "--import",683 url,Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
lines 684–685why, one step back684 "--project",685 "oscabriel/widgets",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 686–693why, one step back686 "--branch",687 "trunk",688 "--yes",689 "--json",690 ]);691692 expect(ran.code).toBe(0);693 expect(yield* platform.calls).toStrictEqual([Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 694why, one step back694 { import: { branch: "trunk", url }, project: "oscabriel/widgets" },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 695–701why, one step back695 ]);696 expect(yield* envelopeOf(ran.out)).toStrictEqual({697 command: "init",698 data: {699 clone: `git clone ${gateway}`,700 files: [],701 landed,Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 702why, one step back702 project: "oscabriel/widgets",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 703–731why, one step back703 pushed: false,704 remote: gateway,705 },706 ok: true,707 v: 1,708 });709 expect(yield* state(machine)).toStrictEqual(before);710 expect(711 (yield* git(712 machine.repo,713 "config",714 "--file",715 machine.gitconfig,716 "--list"717 )).stdout718 ).not.toContain("credential");719 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),720 { timeout: 30_000 }721 );722723 it.live(724 "prints the clone command for a person too",725 () =>726 Effect.gen(function* () {727 const machine = yield* aMachine;728 const gateway = "https://platform.example.test/widgets.git";729730 const platform = yield* aPlatform(731 Effect.succeed({Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 732why, one step back732 project: ProjectName.make("oscabriel/widgets"),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 733–740why, one step back733 remote: gateway,734 })735 );736737 const ran = yield* cli(machine, platform.layer, [738 "init",739 "--import",740 "https://example.test/acme/widgets.git",Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
lines 741–742why, one step back741 "--project",742 "oscabriel/widgets",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 743–768why, one step back743 "--yes",744 ]);745746 expect(ran.code).toBe(0);747 expect(ran.out.join("\n")).toContain(`git clone ${gateway}`);748 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),749 { timeout: 30_000 }750 );751752 it.live.each([753 "http://example.test/acme/widgets.git",754 "git@example.test:acme/widgets.git",755 "file:///srv/widgets.git",756 ])(757 "refuses %s before any call: a usage error, exit 2",758 (url) =>759 Effect.gen(function* () {760 const machine = yield* aMachine;761 const platform = yield* aPlatform(created(machine));762763 const ran = yield* cli(machine, platform.layer, [764 "init",765 "--project",766 "widgets",767 "--import",768 url,Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
lines 769–770why, one step back769 "--project",770 "oscabriel/widgets",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 771–813why, one step back771 "--yes",772 ]);773774 expect(ran.code).toBe(2);775 expect(776 ran.err.filter((line) => line.includes("https://"))777 ).toHaveLength(1);778 expect(yield* platform.calls).toStrictEqual([]);779 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),780 { timeout: 30_000 }781 );782783 it.live.each([784 {785 flags: [786 "--import",787 "https://example.test/acme/widgets.git",788 "--branch",789 "",790 ],791 names: "--branch",792 },793 { flags: ["--branch", "trunk"], names: "--import" },794 ])(795 "refuses $flags before any call, naming $names: a usage error, exit 2",796 ({ flags, names }) =>797 Effect.gen(function* () {798 const machine = yield* aMachine;799 const before = yield* state(machine);800 const platform = yield* aPlatform(created(machine));801802 const ran = yield* cli(machine, platform.layer, [803 "init",804 ...flags,805 "--yes",806 ]);807808 expect({809 calls: yield* platform.calls,810 code: ran.code,811 lines: ran.err.filter((line) => line.includes(names)).length,812 state: yield* state(machine),813 }).toStrictEqual({ calls: [], code: 2, lines: 1, state: before });Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
lines 814–902why, one step back814 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),815 { timeout: 30_000 }816 );817});818819const decodeCalls = Schema.decodeUnknownEffect(820 Schema.Array(Schema.Struct({ project: Schema.String }))821);822823const importSends = (handle: string, url: string, flags: readonly string[]) =>824 Effect.gen(function* () {825 const machine = yield* aMachine;826827 const platform = yield* aPlatform(828 Effect.succeed({829 project: ProjectName.make("bob/foo"),830 remote: "https://platform.example.test/bob/foo.git",831 })832 );833834 yield* cli(835 machine,836 platform.layer,837 ["init", "--import", url, ...flags, "--yes", "--json"],838 signedInAs(handle)839 );840841 const calls = yield* decodeCalls(yield* platform.calls);842843 return calls.map(({ project }) => project);844 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer));845846describe(`${Brand.cli} init's project name`, () => {847 it.live(848 "gives a bare --project the profile's handle, even on an import from a known host",849 () =>850 Effect.gen(function* () {851 const sent = yield* importSends(852 "Bob",853 "https://github.com/pallets/click",854 ["--project", "foo"]855 );856857 expect(sent).toStrictEqual(["bob/foo"]);858 }),859 { timeout: 30_000 }860 );861862 it.live(863 "names an import from a known host by its source path, and any other by the handle",864 () =>865 Effect.gen(function* () {866 const known = yield* importSends(867 "bob",868 "https://github.com/Pallets/click.git",869 []870 );871872 const other = yield* importSends(873 "bob",874 "https://example.test/acme/widgets.git",875 []876 );877878 expect(known).toStrictEqual(["github.com/pallets/click"]);879 expect(other).toStrictEqual(["bob/widgets"]);880 }),881 { timeout: 30_000 }882 );883884 it.live(885 "refuses a bare --project with no handle known, a usage error naming the full form",886 () =>887 Effect.gen(function* () {888 const machine = yield* aMachine;889 const platform = yield* aPlatform(created(machine));890891 const ran = yield* cli(machine, platform.layer, [892 "init",893 "--import",894 "https://github.com/pallets/click",895 "--project",896 "foo",897 "--yes",898 ]);899900 expect(ran.code).toBe(2);901 expect(ran.err.join("\n")).toContain("<owner>/<name>");902 expect(yield* platform.calls).toStrictEqual([]);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 903–906why, one step back903 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),904 { timeout: 30_000 }905 );906});