mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-04-25 18:14:58 +00:00
chore: fix test
This commit is contained in:
@@ -50,7 +50,7 @@ const cacheDir = path.join(dir, "cache", "opencode")
|
|||||||
await fs.mkdir(cacheDir, { recursive: true })
|
await fs.mkdir(cacheDir, { recursive: true })
|
||||||
await fs.writeFile(path.join(cacheDir, "version"), "14")
|
await fs.writeFile(path.join(cacheDir, "version"), "14")
|
||||||
|
|
||||||
// Clear provider env vars to ensure clean test state
|
// Clear provider and server auth env vars to ensure clean test state
|
||||||
delete process.env["ANTHROPIC_API_KEY"]
|
delete process.env["ANTHROPIC_API_KEY"]
|
||||||
delete process.env["OPENAI_API_KEY"]
|
delete process.env["OPENAI_API_KEY"]
|
||||||
delete process.env["GOOGLE_API_KEY"]
|
delete process.env["GOOGLE_API_KEY"]
|
||||||
@@ -70,6 +70,8 @@ delete process.env["DEEPSEEK_API_KEY"]
|
|||||||
delete process.env["FIREWORKS_API_KEY"]
|
delete process.env["FIREWORKS_API_KEY"]
|
||||||
delete process.env["CEREBRAS_API_KEY"]
|
delete process.env["CEREBRAS_API_KEY"]
|
||||||
delete process.env["SAMBANOVA_API_KEY"]
|
delete process.env["SAMBANOVA_API_KEY"]
|
||||||
|
delete process.env["OPENCODE_SERVER_PASSWORD"]
|
||||||
|
delete process.env["OPENCODE_SERVER_USERNAME"]
|
||||||
|
|
||||||
// Now safe to import from src/
|
// Now safe to import from src/
|
||||||
const { Log } = await import("../src/util/log")
|
const { Log } = await import("../src/util/log")
|
||||||
|
|||||||
@@ -73,8 +73,8 @@ describe("project.initGit endpoint", () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
test("does not reload again when the project is already git", async () => {
|
test("does not reload when the project is already git", async () => {
|
||||||
await using tmp = await tmpdir()
|
await using tmp = await tmpdir({ git: true })
|
||||||
const app = Server.App()
|
const app = Server.App()
|
||||||
const seen: { directory?: string; payload: { type: string } }[] = []
|
const seen: { directory?: string; payload: { type: string } }[] = []
|
||||||
const fn = (evt: { directory?: string; payload: { type: string } }) => {
|
const fn = (evt: { directory?: string; payload: { type: string } }) => {
|
||||||
@@ -85,36 +85,32 @@ describe("project.initGit endpoint", () => {
|
|||||||
GlobalBus.on("event", fn)
|
GlobalBus.on("event", fn)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const first = await app.request("/project/git/init", {
|
const init = await app.request("/project/git/init", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"x-opencode-directory": tmp.path,
|
"x-opencode-directory": tmp.path,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
expect(first.status).toBe(200)
|
expect(init.status).toBe(200)
|
||||||
const before = seen.filter(
|
expect(await init.json()).toMatchObject({
|
||||||
(evt) => evt.directory === tmp.path && evt.payload.type === "server.instance.disposed",
|
|
||||||
).length
|
|
||||||
expect(reloadSpy).toHaveBeenCalledTimes(1)
|
|
||||||
|
|
||||||
const second = await app.request("/project/git/init", {
|
|
||||||
method: "POST",
|
|
||||||
headers: {
|
|
||||||
"x-opencode-directory": tmp.path,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
expect(second.status).toBe(200)
|
|
||||||
expect(await second.json()).toMatchObject({
|
|
||||||
id: "global",
|
|
||||||
vcs: "git",
|
vcs: "git",
|
||||||
worktree: tmp.path,
|
worktree: tmp.path,
|
||||||
})
|
})
|
||||||
|
expect(
|
||||||
|
seen.filter((evt) => evt.directory === tmp.path && evt.payload.type === "server.instance.disposed").length,
|
||||||
|
).toBe(0)
|
||||||
|
expect(reloadSpy).toHaveBeenCalledTimes(0)
|
||||||
|
|
||||||
const after = seen.filter(
|
const current = await app.request("/project/current", {
|
||||||
(evt) => evt.directory === tmp.path && evt.payload.type === "server.instance.disposed",
|
headers: {
|
||||||
).length
|
"x-opencode-directory": tmp.path,
|
||||||
expect(after).toBe(before)
|
},
|
||||||
expect(reloadSpy).toHaveBeenCalledTimes(1)
|
})
|
||||||
|
expect(current.status).toBe(200)
|
||||||
|
expect(await current.json()).toMatchObject({
|
||||||
|
vcs: "git",
|
||||||
|
worktree: tmp.path,
|
||||||
|
})
|
||||||
} finally {
|
} finally {
|
||||||
reloadSpy.mockRestore()
|
reloadSpy.mockRestore()
|
||||||
GlobalBus.off("event", fn)
|
GlobalBus.off("event", fn)
|
||||||
|
|||||||
Reference in New Issue
Block a user