chore: fix test to have deterministic testing (#1401)

This commit is contained in:
Yordis Prieto
2025-07-29 18:54:22 -04:00
committed by GitHub
parent 7e9ac35666
commit 4c34b69ae6
5 changed files with 20 additions and 18 deletions

View File

@@ -0,0 +1 @@
// Test fixture for ListTool

View File

@@ -0,0 +1 @@
// Test fixture for ListTool

View File

@@ -0,0 +1 @@
// Test fixture for ListTool

View File

@@ -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`] = ` exports[`tool.ls basic 1`] = `
"- /home/thdxr/dev/projects/sst/opencode/js/example/ "packages/opencode/test/fixtures/example/
- home/ broken.ts
- thdxr/ cli.ts
- dev/ ink.tsx
- projects/
- sst/
- opencode/
- js/
- example/
- ink.tsx
- broken.ts
- cli.ts
" "
`; `;

View File

@@ -2,6 +2,7 @@ import { describe, expect, test } from "bun:test"
import { App } from "../../src/app/app" import { App } from "../../src/app/app"
import { GlobTool } from "../../src/tool/glob" import { GlobTool } from "../../src/tool/glob"
import { ListTool } from "../../src/tool/ls" import { ListTool } from "../../src/tool/ls"
import path from "path"
const ctx = { const ctx = {
sessionID: "test", sessionID: "test",
@@ -12,9 +13,12 @@ const ctx = {
const glob = await GlobTool.init() const glob = await GlobTool.init()
const list = await ListTool.init() const list = await ListTool.init()
const projectRoot = path.join(__dirname, "../..")
const fixturePath = path.join(__dirname, "../fixtures/example")
describe("tool.glob", () => { describe("tool.glob", () => {
test("truncate", async () => { test("truncate", async () => {
await App.provide({ cwd: process.cwd() }, async () => { await App.provide({ cwd: projectRoot }, async () => {
let result = await glob.execute( let result = await glob.execute(
{ {
pattern: "../../node_modules/**/*", pattern: "../../node_modules/**/*",
@@ -26,7 +30,7 @@ describe("tool.glob", () => {
}) })
}) })
test("basic", async () => { test("basic", async () => {
await App.provide({ cwd: process.cwd() }, async () => { await App.provide({ cwd: projectRoot }, async () => {
let result = await glob.execute( let result = await glob.execute(
{ {
pattern: "*.json", pattern: "*.json",
@@ -44,9 +48,12 @@ describe("tool.glob", () => {
describe("tool.ls", () => { describe("tool.ls", () => {
test("basic", async () => { test("basic", async () => {
const result = await App.provide({ cwd: process.cwd() }, async () => { const result = await App.provide({ cwd: projectRoot }, async () => {
return await list.execute({ path: "./example", ignore: [".git"] }, ctx) 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()
}) })
}) })