MCPcopy Index your code
hub / github.com/anomalyco/opencode / tmpdir

Function tmpdir

packages/opencode/test/fixture/fixture.ts:84–119  ·  view source on GitHub ↗
(options?: TmpDirOptions<T>)

Source from the content-addressed store, hash-verified

82 dispose?: (dir: string) => Promise<T>
83}
84export async function tmpdir<T>(options?: TmpDirOptions<T>) {
85 const dirpath = sanitizePath(path.join(os.tmpdir(), "opencode-test-" + Math.random().toString(36).slice(2)))
86 await fs.mkdir(dirpath, { recursive: true })
87 if (options?.git) {
88 await $`git init`.cwd(dirpath).quiet()
89 await $`git config core.fsmonitor false`.cwd(dirpath).quiet()
90 await $`git config commit.gpgsign false`.cwd(dirpath).quiet()
91 await $`git config user.email "test@opencode.test"`.cwd(dirpath).quiet()
92 await $`git config user.name "Test"`.cwd(dirpath).quiet()
93 await $`git commit --allow-empty -m "root commit ${dirpath}"`.cwd(dirpath).quiet()
94 }
95 if (options?.config) {
96 await Bun.write(
97 path.join(dirpath, "opencode.json"),
98 JSON.stringify({
99 $schema: "https://opencode.ai/config.json",
100 ...options.config,
101 }),
102 )
103 }
104 const realpath = sanitizePath(await fs.realpath(dirpath))
105 const extra = await options?.init?.(realpath)
106 const result = {
107 [Symbol.asyncDispose]: async () => {
108 try {
109 await options?.dispose?.(realpath)
110 } finally {
111 if (options?.git) await stop(realpath).catch(() => undefined)
112 await clean(realpath).catch(() => undefined)
113 }
114 },
115 path: realpath,
116 extra: extra as T,
117 }
118 return result
119}
120
121/** Effectful scoped tmpdir. Cleaned up when the scope closes. Make sure these stay in sync */
122export function tmpdirScoped<E = never, R = never>(options?: {

Callers 15

launch.test.tsFile · 0.90
client.test.tsFile · 0.90
install.test.tsFile · 0.90
fixture.test.tsFile · 0.90
scopedTmpdirFunction · 0.90
checkFunction · 0.90
thread.test.tsFile · 0.90

Calls 8

sanitizePathFunction · 0.85
quietMethod · 0.80
writeMethod · 0.80
stopFunction · 0.70
cleanFunction · 0.70
cwdMethod · 0.65
initMethod · 0.45
disposeMethod · 0.45

Tested by 7

scopedTmpdirFunction · 0.72
checkFunction · 0.72
loadFunction · 0.72
withTmpFunction · 0.72
tmpdirEffectFunction · 0.72
checkFunction · 0.72
tempFileFunction · 0.40