Files
anomalyco_opencode/packages/opencode/test/util/log.test.ts
T
Dax Raad 705f792e87 core: move Global module to @opencode-ai/core for centralized path management
Move the Global module from packages/opencode/src/global to packages/core/src/global
to provide a unified location for managing XDG directories and application paths.
This eliminates duplicate path definitions across packages and ensures consistent
access to data, config, cache, state, log, and bin directories throughout the codebase.
2026-04-25 13:52:32 -04:00

45 lines
1.1 KiB
TypeScript

import { afterEach, expect, test } from "bun:test"
import fs from "fs/promises"
import path from "path"
import { Global } from "@opencode-ai/core/global"
import { Log } from "../../src/util"
import { tmpdir } from "../fixture/fixture"
const log = Global.Path.log
afterEach(() => {
Global.Path.log = log
})
async function files(dir: string) {
let last = ""
let same = 0
for (let i = 0; i < 50; i++) {
const list = (await fs.readdir(dir)).sort()
const next = JSON.stringify(list)
same = next === last ? same + 1 : 0
if (same >= 2 && list.length === 11) return list
last = next
await Bun.sleep(10)
}
return (await fs.readdir(dir)).sort()
}
test("init cleanup keeps the newest timestamped logs", async () => {
await using tmp = await tmpdir()
Global.Path.log = tmp.path
const list = Array.from({ length: 12 }, (_, i) => `2000-01-${String(i + 1).padStart(2, "0")}T000000.log`)
await Promise.all(list.map((file) => fs.writeFile(path.join(tmp.path, file), file)))
await Log.init({ print: false, dev: false })
const next = await files(tmp.path)
expect(next).not.toContain(list[0]!)
expect(next).toContain(list.at(-1)!)
})