mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-04-02 15:13:46 +00:00
ignore: revert 3 commits that broke dev branch (#18260)
This commit is contained in:
@@ -10,48 +10,45 @@ import { ProjectID } from "../../src/project/schema"
|
||||
|
||||
Log.init({ print: false })
|
||||
|
||||
const gitModule = await import("../../src/git")
|
||||
const originalGit = gitModule.Git.run
|
||||
const gitModule = await import("../../src/util/git")
|
||||
const originalGit = gitModule.git
|
||||
|
||||
type Mode = "none" | "rev-list-fail" | "top-fail" | "common-dir-fail"
|
||||
let mode: Mode = "none"
|
||||
|
||||
mock.module("../../src/git", () => ({
|
||||
Git: {
|
||||
...gitModule.Git,
|
||||
run: (args: string[], opts: { cwd: string; env?: Record<string, string> }) => {
|
||||
const cmd = ["git", ...args].join(" ")
|
||||
if (
|
||||
mode === "rev-list-fail" &&
|
||||
cmd.includes("git rev-list") &&
|
||||
cmd.includes("--max-parents=0") &&
|
||||
cmd.includes("HEAD")
|
||||
) {
|
||||
return Promise.resolve({
|
||||
exitCode: 128,
|
||||
text: () => "",
|
||||
stdout: Buffer.from(""),
|
||||
stderr: Buffer.from("fatal"),
|
||||
})
|
||||
}
|
||||
if (mode === "top-fail" && cmd.includes("git rev-parse") && cmd.includes("--show-toplevel")) {
|
||||
return Promise.resolve({
|
||||
exitCode: 128,
|
||||
text: () => "",
|
||||
stdout: Buffer.from(""),
|
||||
stderr: Buffer.from("fatal"),
|
||||
})
|
||||
}
|
||||
if (mode === "common-dir-fail" && cmd.includes("git rev-parse") && cmd.includes("--git-common-dir")) {
|
||||
return Promise.resolve({
|
||||
exitCode: 128,
|
||||
text: () => "",
|
||||
stdout: Buffer.from(""),
|
||||
stderr: Buffer.from("fatal"),
|
||||
})
|
||||
}
|
||||
return originalGit(args, opts)
|
||||
},
|
||||
mock.module("../../src/util/git", () => ({
|
||||
git: (args: string[], opts: { cwd: string; env?: Record<string, string> }) => {
|
||||
const cmd = ["git", ...args].join(" ")
|
||||
if (
|
||||
mode === "rev-list-fail" &&
|
||||
cmd.includes("git rev-list") &&
|
||||
cmd.includes("--max-parents=0") &&
|
||||
cmd.includes("HEAD")
|
||||
) {
|
||||
return Promise.resolve({
|
||||
exitCode: 128,
|
||||
text: () => Promise.resolve(""),
|
||||
stdout: Buffer.from(""),
|
||||
stderr: Buffer.from("fatal"),
|
||||
})
|
||||
}
|
||||
if (mode === "top-fail" && cmd.includes("git rev-parse") && cmd.includes("--show-toplevel")) {
|
||||
return Promise.resolve({
|
||||
exitCode: 128,
|
||||
text: () => Promise.resolve(""),
|
||||
stdout: Buffer.from(""),
|
||||
stderr: Buffer.from("fatal"),
|
||||
})
|
||||
}
|
||||
if (mode === "common-dir-fail" && cmd.includes("git rev-parse") && cmd.includes("--git-common-dir")) {
|
||||
return Promise.resolve({
|
||||
exitCode: 128,
|
||||
text: () => Promise.resolve(""),
|
||||
stdout: Buffer.from(""),
|
||||
stderr: Buffer.from("fatal"),
|
||||
})
|
||||
}
|
||||
return originalGit(args, opts)
|
||||
},
|
||||
}))
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ function withVcs(
|
||||
) {
|
||||
return withServices(
|
||||
directory,
|
||||
Layer.merge(FileWatcher.layer, Vcs.defaultLayer),
|
||||
Layer.merge(FileWatcher.layer, Vcs.layer),
|
||||
async (rt) => {
|
||||
await rt.runPromise(FileWatcher.Service.use(() => Effect.void))
|
||||
await rt.runPromise(Vcs.Service.use(() => Effect.void))
|
||||
@@ -34,15 +34,7 @@ function withVcs(
|
||||
)
|
||||
}
|
||||
|
||||
function withVcsOnly(
|
||||
directory: string,
|
||||
body: (rt: ManagedRuntime.ManagedRuntime<Vcs.Service, never>) => Promise<void>,
|
||||
) {
|
||||
return withServices(directory, Vcs.defaultLayer, body)
|
||||
}
|
||||
|
||||
type BranchEvent = { directory?: string; payload: { type: string; properties: { branch?: string } } }
|
||||
const weird = process.platform === "win32" ? "space file.txt" : "tab\tfile.txt"
|
||||
|
||||
/** Wait for a Vcs.Event.BranchUpdated event on GlobalBus, with retry polling as fallback */
|
||||
function nextBranchUpdate(directory: string, timeout = 10_000) {
|
||||
@@ -129,104 +121,3 @@ describeVcs("Vcs", () => {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("Vcs diff", () => {
|
||||
afterEach(() => Instance.disposeAll())
|
||||
|
||||
test("defaultBranch() falls back to main", async () => {
|
||||
await using tmp = await tmpdir({ git: true })
|
||||
await $`git branch -M main`.cwd(tmp.path).quiet()
|
||||
|
||||
await withVcsOnly(tmp.path, async (rt) => {
|
||||
const branch = await rt.runPromise(Vcs.Service.use((s) => s.defaultBranch()))
|
||||
expect(branch).toBe("main")
|
||||
})
|
||||
})
|
||||
|
||||
test("defaultBranch() uses init.defaultBranch when available", async () => {
|
||||
await using tmp = await tmpdir({ git: true })
|
||||
await $`git branch -M trunk`.cwd(tmp.path).quiet()
|
||||
await $`git config init.defaultBranch trunk`.cwd(tmp.path).quiet()
|
||||
|
||||
await withVcsOnly(tmp.path, async (rt) => {
|
||||
const branch = await rt.runPromise(Vcs.Service.use((s) => s.defaultBranch()))
|
||||
expect(branch).toBe("trunk")
|
||||
})
|
||||
})
|
||||
|
||||
test("detects current branch from the active worktree", async () => {
|
||||
await using tmp = await tmpdir({ git: true })
|
||||
await using wt = await tmpdir()
|
||||
await $`git branch -M main`.cwd(tmp.path).quiet()
|
||||
const dir = path.join(wt.path, "feature")
|
||||
await $`git worktree add -b feature/test ${dir} HEAD`.cwd(tmp.path).quiet()
|
||||
|
||||
await withVcsOnly(dir, async (rt) => {
|
||||
const [branch, base] = await Promise.all([
|
||||
rt.runPromise(Vcs.Service.use((s) => s.branch())),
|
||||
rt.runPromise(Vcs.Service.use((s) => s.defaultBranch())),
|
||||
])
|
||||
expect(branch).toBe("feature/test")
|
||||
expect(base).toBe("main")
|
||||
})
|
||||
})
|
||||
|
||||
test("diff('git') returns uncommitted changes", async () => {
|
||||
await using tmp = await tmpdir({ git: true })
|
||||
await fs.writeFile(path.join(tmp.path, "file.txt"), "original\n", "utf-8")
|
||||
await $`git add .`.cwd(tmp.path).quiet()
|
||||
await $`git commit --no-gpg-sign -m "add file"`.cwd(tmp.path).quiet()
|
||||
await fs.writeFile(path.join(tmp.path, "file.txt"), "changed\n", "utf-8")
|
||||
|
||||
await withVcsOnly(tmp.path, async (rt) => {
|
||||
const diff = await rt.runPromise(Vcs.Service.use((s) => s.diff("git")))
|
||||
expect(diff).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
file: "file.txt",
|
||||
status: "modified",
|
||||
}),
|
||||
]),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
test("diff('git') handles special filenames", async () => {
|
||||
await using tmp = await tmpdir({ git: true })
|
||||
const file = weird
|
||||
await fs.writeFile(path.join(tmp.path, file), "hello\n", "utf-8")
|
||||
|
||||
await withVcsOnly(tmp.path, async (rt) => {
|
||||
const diff = await rt.runPromise(Vcs.Service.use((s) => s.diff("git")))
|
||||
expect(diff).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
file,
|
||||
status: "added",
|
||||
}),
|
||||
]),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
test("diff('branch') returns changes against default branch", async () => {
|
||||
await using tmp = await tmpdir({ git: true })
|
||||
await $`git branch -M main`.cwd(tmp.path).quiet()
|
||||
await $`git checkout -b feature/test`.cwd(tmp.path).quiet()
|
||||
await fs.writeFile(path.join(tmp.path, "branch.txt"), "hello\n", "utf-8")
|
||||
await $`git add .`.cwd(tmp.path).quiet()
|
||||
await $`git commit --no-gpg-sign -m "branch file"`.cwd(tmp.path).quiet()
|
||||
|
||||
await withVcsOnly(tmp.path, async (rt) => {
|
||||
const diff = await rt.runPromise(Vcs.Service.use((s) => s.diff("branch")))
|
||||
expect(diff).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
file: "branch.txt",
|
||||
status: "added",
|
||||
}),
|
||||
]),
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user