-
Notifications
You must be signed in to change notification settings - Fork 14
refactor(server): effectify instance root json handlers #1031
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
packages/opencode/test/server/instance-root-routes.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import { $ } from "bun" | ||
| import { afterEach, describe, expect, test } from "bun:test" | ||
| import fs from "fs/promises" | ||
| import path from "path" | ||
| import { Instance } from "../../src/project/instance" | ||
| import { Server } from "../../src/server/server" | ||
| import { resetDatabase } from "../fixture/db" | ||
| import { tmpdir } from "../fixture/fixture" | ||
|
|
||
| afterEach(async () => { | ||
| await Instance.disposeAll() | ||
| await resetDatabase() | ||
| }) | ||
|
|
||
| describe("instance root routes", () => { | ||
| test("returns path and metadata JSON through the route runtime", async () => { | ||
| await using tmp = await tmpdir({ git: true }) | ||
| const app = Server.Default().app | ||
| const headers = { "x-opencode-directory": tmp.path } | ||
|
|
||
| const pathResponse = await app.request("/path", { headers }) | ||
| expect(pathResponse.status).toBe(200) | ||
| expect(await pathResponse.json()).toMatchObject({ directory: tmp.path, worktree: tmp.path }) | ||
|
|
||
| for (const route of ["/agent", "/skill", "/command", "/lsp", "/formatter"]) { | ||
| const response = await app.request(route, { headers }) | ||
| expect(response.status, route).toBe(200) | ||
| expect(await response.json(), route).toBeArray() | ||
| } | ||
| }) | ||
|
|
||
| test("returns VCS JSON through the route runtime", async () => { | ||
| await using tmp = await tmpdir({ git: true }) | ||
| const app = Server.Default().app | ||
| const headers = { "x-opencode-directory": tmp.path } | ||
|
|
||
| await fs.writeFile(path.join(tmp.path, "tracked.txt"), "original\n", "utf-8") | ||
| await $`git add tracked.txt`.cwd(tmp.path).quiet() | ||
| await $`git commit --no-gpg-sign -m "add file"`.cwd(tmp.path).quiet() | ||
| await fs.writeFile(path.join(tmp.path, "tracked.txt"), "changed\n", "utf-8") | ||
|
|
||
| const info = await app.request("/vcs", { headers }) | ||
| expect(info.status).toBe(200) | ||
| expect(await info.json()).toMatchObject({ branch: expect.any(String) }) | ||
|
|
||
| const diff = await app.request("/vcs/diff?mode=git", { headers }) | ||
| expect(diff.status).toBe(200) | ||
| expect(await diff.json()).toEqual([ | ||
| expect.objectContaining({ file: "tracked.txt", additions: 1, deletions: 1, status: "modified" }), | ||
| ]) | ||
|
|
||
| const status = await app.request("/vcs/status", { headers }) | ||
| expect(status.status).toBe(200) | ||
| expect(await status.json()).toEqual([{ file: "tracked.txt", additions: 1, deletions: 1, status: "modified" }]) | ||
| }) | ||
|
|
||
| test("disposes the current instance through the route runtime", async () => { | ||
| await using tmp = await tmpdir({ git: true }) | ||
| const response = await Server.Default().app.request("/instance/dispose", { | ||
| method: "POST", | ||
| headers: { "x-opencode-directory": tmp.path }, | ||
| }) | ||
|
|
||
| expect(response.status).toBe(200) | ||
| expect(await response.json()).toBe(true) | ||
| }) | ||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.