summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYordis Prieto <[email protected]>2025-07-29 18:54:22 -0400
committerGitHub <[email protected]>2025-07-29 17:54:22 -0500
commit4c34b69ae64bf0a04f532d88ea9296ccb2790475 (patch)
treec22e51df7fe595f6a8f24635065f8ab4dff56898
parent7e9ac3566601bc7ec97cdba1dddeff10a93ba50a (diff)
downloadopencode-4c34b69ae64bf0a04f532d88ea9296ccb2790475.tar.gz
opencode-4c34b69ae64bf0a04f532d88ea9296ccb2790475.zip
chore: fix test to have deterministic testing (#1401)
-rw-r--r--packages/opencode/test/fixtures/example/broken.ts1
-rw-r--r--packages/opencode/test/fixtures/example/cli.ts1
-rw-r--r--packages/opencode/test/fixtures/example/ink.tsx1
-rw-r--r--packages/opencode/test/tool/__snapshots__/tool.test.ts.snap18
-rw-r--r--packages/opencode/test/tool/tool.test.ts17
5 files changed, 20 insertions, 18 deletions
diff --git a/packages/opencode/test/fixtures/example/broken.ts b/packages/opencode/test/fixtures/example/broken.ts
new file mode 100644
index 000000000..c60848fca
--- /dev/null
+++ b/packages/opencode/test/fixtures/example/broken.ts
@@ -0,0 +1 @@
+// Test fixture for ListTool
diff --git a/packages/opencode/test/fixtures/example/cli.ts b/packages/opencode/test/fixtures/example/cli.ts
new file mode 100644
index 000000000..c60848fca
--- /dev/null
+++ b/packages/opencode/test/fixtures/example/cli.ts
@@ -0,0 +1 @@
+// Test fixture for ListTool
diff --git a/packages/opencode/test/fixtures/example/ink.tsx b/packages/opencode/test/fixtures/example/ink.tsx
new file mode 100644
index 000000000..c60848fca
--- /dev/null
+++ b/packages/opencode/test/fixtures/example/ink.tsx
@@ -0,0 +1 @@
+// Test fixture for ListTool
diff --git a/packages/opencode/test/tool/__snapshots__/tool.test.ts.snap b/packages/opencode/test/tool/__snapshots__/tool.test.ts.snap
index 12669e387..53c671956 100644
--- a/packages/opencode/test/tool/__snapshots__/tool.test.ts.snap
+++ b/packages/opencode/test/tool/__snapshots__/tool.test.ts.snap
@@ -1,17 +1,9 @@
-// Bun Snapshot v1, https://goo.gl/fbAQLP
+// Bun Snapshot v1, https://bun.sh/docs/test/snapshots
exports[`tool.ls basic 1`] = `
-"- /home/thdxr/dev/projects/sst/opencode/js/example/
- - home/
- - thdxr/
- - dev/
- - projects/
- - sst/
- - opencode/
- - js/
- - example/
- - ink.tsx
- - broken.ts
- - cli.ts
+"packages/opencode/test/fixtures/example/
+ broken.ts
+ cli.ts
+ ink.tsx
"
`;
diff --git a/packages/opencode/test/tool/tool.test.ts b/packages/opencode/test/tool/tool.test.ts
index 7fb1c73c3..f1ed318bf 100644
--- a/packages/opencode/test/tool/tool.test.ts
+++ b/packages/opencode/test/tool/tool.test.ts
@@ -2,6 +2,7 @@ import { describe, expect, test } from "bun:test"
import { App } from "../../src/app/app"
import { GlobTool } from "../../src/tool/glob"
import { ListTool } from "../../src/tool/ls"
+import path from "path"
const ctx = {
sessionID: "test",
@@ -12,9 +13,12 @@ const ctx = {
const glob = await GlobTool.init()
const list = await ListTool.init()
+const projectRoot = path.join(__dirname, "../..")
+const fixturePath = path.join(__dirname, "../fixtures/example")
+
describe("tool.glob", () => {
test("truncate", async () => {
- await App.provide({ cwd: process.cwd() }, async () => {
+ await App.provide({ cwd: projectRoot }, async () => {
let result = await glob.execute(
{
pattern: "../../node_modules/**/*",
@@ -26,7 +30,7 @@ describe("tool.glob", () => {
})
})
test("basic", async () => {
- await App.provide({ cwd: process.cwd() }, async () => {
+ await App.provide({ cwd: projectRoot }, async () => {
let result = await glob.execute(
{
pattern: "*.json",
@@ -44,9 +48,12 @@ describe("tool.glob", () => {
describe("tool.ls", () => {
test("basic", async () => {
- const result = await App.provide({ cwd: process.cwd() }, async () => {
- return await list.execute({ path: "./example", ignore: [".git"] }, ctx)
+ const result = await App.provide({ cwd: projectRoot }, async () => {
+ return await list.execute({ path: fixturePath, ignore: [".git"] }, ctx)
})
- expect(result.output).toMatchSnapshot()
+
+ // Normalize absolute path to relative for consistent snapshots
+ const normalizedOutput = result.output.replace(fixturePath, "packages/opencode/test/fixtures/example")
+ expect(normalizedOutput).toMatchSnapshot()
})
})