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, 04:45 UTC
| 1 | import { assert, it } from "@effect/vitest"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as Layer from "effect/Layer"; |
| 4 | |
| 5 | import * as NodeCrypto from "@effect/platform-node/NodeCrypto"; |
| 6 | import * as NodeServices from "@effect/platform-node/NodeServices"; |
| 7 | import * as FileSystem from "effect/FileSystem"; |
| 8 | |
| 9 | import * as ServerConfig from "../config.ts"; |
| 10 | import * as VcsProcess from "../vcs/VcsProcess.ts"; |
| 11 | import * as GitManager from "./GitManager.ts"; |
| 12 | import * as GitWorkflowService from "./GitWorkflowService.ts"; |
| 13 | import * as GitVcsDriver from "../vcs/GitVcsDriver.ts"; |
| 14 | import * as VcsDriverRegistry from "../vcs/VcsDriverRegistry.ts"; |
| 15 | |
| 16 | it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))("GitWorkflowService", (it) => { |
| 17 | it.effect("finds a name among the refs of every namespace", () => |
| 18 | Effect.gen(function* () { |
| 19 | const fileSystem = yield* FileSystem.FileSystem; |
| 20 | const cwd = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-ref-named-" }); |
| 21 | const workflow = yield* GitWorkflowService.GitWorkflowService; |
| 22 | const driver = yield* GitVcsDriver.GitVcsDriver; |
| 23 | for (const args of [ |
| 24 | ["init", "-b", "main"], |
| 25 | ["-c", "user.email=t@t", "-c", "user.name=t", "commit", "--allow-empty", "-m", "init"], |
| 26 | ["update-ref", "refs/remotes/upstream/feature/topic", "HEAD"], |
| 27 | ["symbolic-ref", "refs/remotes/origin/alias", "refs/heads/main"], |
| 28 | ["update-ref", "refs/mirror/origin/mirrored", "HEAD"], |
| 29 | ]) { |
| 30 | yield* driver.execute({ operation: "test.setupRepo", cwd, args }); |
| 31 | } |
| 32 | const found = yield* Effect.forEach( |
| 33 | ["main", "feature/topic", "alias", "mirrored", "t3/renamed", "feature/*"], |
| 34 | (refName) => workflow.hasRefNamed({ cwd, refName }), |
| 35 | ); |
| 36 | assert.deepEqual(found, [true, true, true, true, false, false]); |
| 37 | }).pipe( |
| 38 | Effect.scoped, |
| 39 | Effect.provide( |
| 40 | GitWorkflowService.layer.pipe( |
| 41 | Layer.provide( |
| 42 | Layer.mock(VcsDriverRegistry.VcsDriverRegistry)({ |
| 43 | resolve: () => Effect.succeed({ kind: "git" } as VcsDriverRegistry.VcsDriverHandle), |
| 44 | }), |
| 45 | ), |
| 46 | Layer.provide(Layer.mock(GitManager.GitManager)({})), |
| 47 | Layer.provideMerge(GitVcsDriver.layer), |
| 48 | Layer.provideMerge(VcsProcess.layer), |
| 49 | Layer.provideMerge( |
| 50 | ServerConfig.layerTest(process.cwd(), { prefix: "t3-ref-named-" }).pipe( |
| 51 | Layer.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)), |
| 52 | ), |
| 53 | ), |
| 54 | Layer.provideMerge(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)), |
| 55 | ), |
| 56 | ), |
| 57 | ), |
| 58 | ); |
| 59 | |
| 60 | it.effect("reads no HEAD path from a removed worktree without spawning Git", () => |
| 61 | Effect.gen(function* () { |
| 62 | const fileSystem = yield* FileSystem.FileSystem; |
| 63 | const parent = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-removed-wt-" }); |
| 64 | const removed = `${parent}/removed`; |
| 65 | const workflow = yield* GitWorkflowService.GitWorkflowService; |
| 66 | assert.strictEqual(yield* workflow.headPath(removed), null); |
| 67 | }).pipe( |
| 68 | Effect.scoped, |
| 69 | Effect.provide( |
| 70 | GitWorkflowService.layer.pipe( |
| 71 | Layer.provide(Layer.mock(VcsDriverRegistry.VcsDriverRegistry)({})), |
| 72 | Layer.provide(Layer.mock(GitManager.GitManager)({})), |
| 73 | Layer.provide( |
| 74 | Layer.mock(GitVcsDriver.GitVcsDriver)({ |
| 75 | execute: (input) => Effect.die(`spawned Git in ${input.cwd}`), |
| 76 | }), |
| 77 | ), |
| 78 | ), |
| 79 | ), |
| 80 | ), |
| 81 | ); |
| 82 | }); |