File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { $ } from "bun"
2- import { realpathSync } from "fs"
2+ import * as fs from "fs/promises "
33import os from "os"
44import path from "path"
55
6+ // Strip null bytes from paths (defensive fix for CI environment issues)
7+ function sanitizePath ( p : string ) : string {
8+ return p . replace ( / \0 / g, "" )
9+ }
10+
611type TmpDirOptions < T > = {
712 git ?: boolean
813 init ?: ( dir : string ) => Promise < T >
914 dispose ?: ( dir : string ) => Promise < T >
1015}
1116export async function tmpdir < T > ( options ?: TmpDirOptions < T > ) {
12- const dirpath = path . join ( os . tmpdir ( ) , "opencode-test-" + Math . random ( ) . toString ( 36 ) . slice ( 2 ) )
13- await $ ` mkdir -p ${ dirpath } ` . quiet ( )
17+ const dirpath = sanitizePath ( path . join ( os . tmpdir ( ) , "opencode-test-" + Math . random ( ) . toString ( 36 ) . slice ( 2 ) ) )
18+ await fs . mkdir ( dirpath , { recursive : true } )
1419 if ( options ?. git ) {
1520 await $ `git init` . cwd ( dirpath ) . quiet ( )
1621 await $ `git commit --allow-empty -m "root commit ${ dirpath } "` . cwd ( dirpath ) . quiet ( )
1722 }
1823 const extra = await options ?. init ?.( dirpath )
24+ const realpath = sanitizePath ( await fs . realpath ( dirpath ) )
1925 const result = {
2026 [ Symbol . asyncDispose ] : async ( ) => {
2127 await options ?. dispose ?.( dirpath )
22- await $ `rm -rf ${ dirpath } ` . quiet ( )
28+ await fs . rm ( dirpath , { recursive : true , force : true } )
2329 } ,
24- path : realpathSync ( dirpath ) ,
30+ path : realpath ,
2531 extra : extra as T ,
2632 }
2733 return result
Original file line number Diff line number Diff line change 22// xdg-basedir reads env vars at import time, so we must set these first
33import os from "os"
44import path from "path"
5+ import fs from "fs/promises"
56
6- const testDataDir = path . join ( os . tmpdir ( ) , "opencode-test-data-" + process . pid )
7- process . env [ "XDG_DATA_HOME" ] = testDataDir
8- process . env [ "XDG_CACHE_HOME" ] = path . join ( testDataDir , "cache" )
9- process . env [ "XDG_CONFIG_HOME" ] = path . join ( testDataDir , "config" )
10- process . env [ "XDG_STATE_HOME" ] = path . join ( testDataDir , "state" )
7+ const dir = path . join ( os . tmpdir ( ) , "opencode-test-data-" + process . pid )
8+ await fs . mkdir ( dir , { recursive : true } )
9+ process . env [ "XDG_DATA_HOME" ] = path . join ( dir , "data" )
10+ process . env [ "XDG_CACHE_HOME" ] = path . join ( dir , "cache" )
11+ process . env [ "XDG_CONFIG_HOME" ] = path . join ( dir , "config" )
12+ process . env [ "XDG_STATE_HOME" ] = path . join ( dir , "state" )
1113
1214// Clear provider env vars to ensure clean test state
1315delete process . env [ "ANTHROPIC_API_KEY" ]
You can’t perform that action at this time.
0 commit comments