+21

![opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com>](/assets/img/avatar_default.png)



![opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>](/assets/img/avatar_default.png)



James Long
Brendan Allan
Kit Langton
opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
Affan Ali
affanali2k3
Frank
opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com>
𝓛𝓲𝓽𝓽𝓵𝓮 𝓕𝓻𝓪𝓷𝓴
Aiden Cline
Jay V
Dax Raad
Aarav Sareen
OpeOginni
Luke Parker
Ben Guthrie
Dax
Filip
Max Anderson
Brendan Allan
Jack
Shoubhit Dash
Dustin Deus
starptech
Aiden Cline
usrnk1
Jay
runvip
opencode
Julian Coy
Vladimir Glafirov
8c94e9005f
Co-authored-by: Brendan Allan <14191578+Brendonovich@users.noreply.github.com> Co-authored-by: Kit Langton <kit.langton@gmail.com> Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> Co-authored-by: Affan Ali <93028901+affanali2k3@users.noreply.github.com> Co-authored-by: affanali2k3 <affanalikhanxx@gmail.com> Co-authored-by: Frank <frank@anoma.ly> Co-authored-by: opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com> Co-authored-by: 𝓛𝓲𝓽𝓽𝓵𝓮 𝓕𝓻𝓪𝓷𝓴 <little-frank@opencord.local> Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Co-authored-by: Jay V <air@live.ca> Co-authored-by: Dax Raad <d@ironbay.co> Co-authored-by: Aarav Sareen <96787824+arvsrn@users.noreply.github.com> Co-authored-by: OpeOginni <107570612+OpeOginni@users.noreply.github.com> Co-authored-by: Luke Parker <10430890+Hona@users.noreply.github.com> Co-authored-by: Ben Guthrie <benjee.012@gmail.com> Co-authored-by: Dax <mail@thdxr.com> Co-authored-by: Filip <34747899+neriousy@users.noreply.github.com> Co-authored-by: Max Anderson <max.a.anderson95@gmail.com> Co-authored-by: Brendan Allan <git@brendonovich.dev> Co-authored-by: Jack <jack@anoma.ly> Co-authored-by: Shoubhit Dash <shoubhit2005@gmail.com> Co-authored-by: Dustin Deus <deusdustin@gmail.com> Co-authored-by: starptech <starptech@starptechs-MBP.fritz.box> Co-authored-by: Aiden Cline <aidenpcline@gmail.com> Co-authored-by: usrnk1 <7547651+usrnk1@users.noreply.github.com> Co-authored-by: Jay <53023+jayair@users.noreply.github.com> Co-authored-by: runvip <164729189+runvip@users.noreply.github.com> Co-authored-by: opencode <opencode@sst.dev> Co-authored-by: Julian Coy <julian@ex-machina.co> Co-authored-by: Vladimir Glafirov <vglafirov@gitlab.com>
129 lines
4.6 KiB
TypeScript
129 lines
4.6 KiB
TypeScript
import { $ } from "bun"
|
|
import { describe, expect } from "bun:test"
|
|
import * as fs from "fs/promises"
|
|
import path from "path"
|
|
import { LayerNode } from "@opencode-ai/core/effect/layer-node"
|
|
import { Effect } from "effect"
|
|
import { InstanceBootstrap } from "../../src/project/bootstrap"
|
|
import { InstanceStore } from "../../src/project/instance-store"
|
|
import { Worktree } from "../../src/worktree"
|
|
import { TestInstance } from "../fixture/fixture"
|
|
import { testEffect } from "../lib/effect"
|
|
|
|
const it = testEffect(LayerNode.compile(Worktree.node, [[InstanceStore.bootstrapNode, InstanceBootstrap.node]]))
|
|
const wintest = process.platform === "win32" ? it.instance : it.instance.skip
|
|
|
|
describe("Worktree.remove", () => {
|
|
it.instance(
|
|
"continues when git remove exits non-zero after detaching",
|
|
() =>
|
|
Effect.gen(function* () {
|
|
const root = (yield* TestInstance).directory
|
|
const svc = yield* Worktree.Service
|
|
const name = `remove-regression-${Date.now().toString(36)}`
|
|
const branch = `opencode/${name}`
|
|
const dir = path.join(root, "..", name)
|
|
|
|
yield* Effect.promise(() => $`git worktree add --no-checkout -b ${branch} ${dir}`.cwd(root).quiet())
|
|
yield* Effect.promise(() => $`git reset --hard`.cwd(dir).quiet())
|
|
|
|
const real = (yield* Effect.promise(() => $`which git`.quiet().text())).trim()
|
|
expect(real).toBeTruthy()
|
|
|
|
const bin = path.join(root, "bin")
|
|
const shim = path.join(bin, "git")
|
|
yield* Effect.promise(() => fs.mkdir(bin, { recursive: true }))
|
|
yield* Effect.promise(() =>
|
|
Bun.write(
|
|
shim,
|
|
[
|
|
"#!/bin/bash",
|
|
`REAL_GIT=${JSON.stringify(real)}`,
|
|
'if [ "$1" = "worktree" ] && [ "$2" = "remove" ]; then',
|
|
' "$REAL_GIT" "$@" >/dev/null 2>&1',
|
|
' echo "fatal: failed to remove worktree: Directory not empty" >&2',
|
|
" exit 1",
|
|
"fi",
|
|
'exec "$REAL_GIT" "$@"',
|
|
].join("\n"),
|
|
),
|
|
)
|
|
yield* Effect.promise(() => fs.chmod(shim, 0o755))
|
|
|
|
const prev = yield* Effect.acquireRelease(
|
|
Effect.sync(() => {
|
|
const prev = process.env.PATH ?? ""
|
|
process.env.PATH = `${bin}${path.delimiter}${prev}`
|
|
return prev
|
|
}),
|
|
(prev) =>
|
|
Effect.sync(() => {
|
|
process.env.PATH = prev
|
|
}),
|
|
)
|
|
void prev
|
|
|
|
const ok = yield* svc.remove({ directory: dir })
|
|
|
|
expect(ok).toBe(true)
|
|
expect(
|
|
yield* Effect.promise(() =>
|
|
fs
|
|
.stat(dir)
|
|
.then(() => true)
|
|
.catch(() => false),
|
|
),
|
|
).toBe(false)
|
|
|
|
const list = yield* Effect.promise(() => $`git worktree list --porcelain`.cwd(root).quiet().text())
|
|
expect(list).not.toContain(`worktree ${dir}`)
|
|
|
|
const ref = yield* Effect.promise(() =>
|
|
$`git show-ref --verify --quiet refs/heads/${branch}`.cwd(root).quiet().nothrow(),
|
|
)
|
|
expect(ref.exitCode).not.toBe(0)
|
|
}),
|
|
{ git: true },
|
|
)
|
|
|
|
wintest(
|
|
"stops fsmonitor before removing a worktree",
|
|
() =>
|
|
Effect.gen(function* () {
|
|
const root = (yield* TestInstance).directory
|
|
const svc = yield* Worktree.Service
|
|
const name = `remove-fsmonitor-${Date.now().toString(36)}`
|
|
const branch = `opencode/${name}`
|
|
const dir = path.join(root, "..", name)
|
|
|
|
yield* Effect.promise(() => $`git worktree add --no-checkout -b ${branch} ${dir}`.cwd(root).quiet())
|
|
yield* Effect.promise(() => $`git reset --hard`.cwd(dir).quiet())
|
|
yield* Effect.promise(() => $`git config core.fsmonitor true`.cwd(dir).quiet())
|
|
yield* Effect.promise(() => $`git fsmonitor--daemon stop`.cwd(dir).quiet().nothrow())
|
|
yield* Effect.promise(() => Bun.write(path.join(dir, "tracked.txt"), "next\n"))
|
|
yield* Effect.promise(() => $`git diff`.cwd(dir).quiet())
|
|
|
|
const before = yield* Effect.promise(() => $`git fsmonitor--daemon status`.cwd(dir).quiet().nothrow())
|
|
expect(before.exitCode).toBe(0)
|
|
|
|
const ok = yield* svc.remove({ directory: dir })
|
|
|
|
expect(ok).toBe(true)
|
|
expect(
|
|
yield* Effect.promise(() =>
|
|
fs
|
|
.stat(dir)
|
|
.then(() => true)
|
|
.catch(() => false),
|
|
),
|
|
).toBe(false)
|
|
|
|
const ref = yield* Effect.promise(() =>
|
|
$`git show-ref --verify --quiet refs/heads/${branch}`.cwd(root).quiet().nothrow(),
|
|
)
|
|
expect(ref.exitCode).not.toBe(0)
|
|
}),
|
|
{ git: true },
|
|
)
|
|
})
|