@@ -7,6 +7,9 @@ import { Database } from "bun:sqlite";
77import { createSchema , generateId , hashContent } from "../src/schema" ;
88import { brainSearch } from "../src/search/unified" ;
99import plugin from "../src/four-opencode-brain" ;
10+ import { mkdtempSync } from "fs" ;
11+ import { tmpdir } from "os" ;
12+ import { join } from "path" ;
1013
1114let db : Database ;
1215
@@ -34,17 +37,23 @@ function tableExists(name: string): boolean {
3437
3538describe ( "brain_reindex — tool definition" , ( ) => {
3639 test ( "plugin exports brain_reindex tool" , async ( ) => {
37- const result = await plugin . server ( {
38- client : { } as any ,
39- project : "test" ,
40- directory : "/tmp" ,
41- $ : { } as any ,
42- } ) ;
43- expect ( result . tool ) . toHaveProperty ( "brain_reindex" ) ;
44- const tool = result . tool . brain_reindex ;
45- expect ( tool ) . toBeDefined ( ) ;
46- expect ( tool . description ) . toContain ( "Rebuild vec0 vector index" ) ;
47- expect ( tool . args ) . toEqual ( { } ) ;
40+ const originalHome = process . env . HOME ;
41+ process . env . HOME = mkdtempSync ( join ( tmpdir ( ) , "brain-test-" ) ) ;
42+ try {
43+ const result = await plugin . server ( {
44+ client : { } as any ,
45+ project : "test" ,
46+ directory : "/tmp" ,
47+ $ : { } as any ,
48+ } ) ;
49+ expect ( result . tool ) . toHaveProperty ( "brain_reindex" ) ;
50+ const tool = result . tool . brain_reindex ;
51+ expect ( tool ) . toBeDefined ( ) ;
52+ expect ( tool . description ) . toContain ( "Rebuild vec0 vector index" ) ;
53+ expect ( tool . args ) . toEqual ( { } ) ;
54+ } finally {
55+ process . env . HOME = originalHome ;
56+ }
4857 } ) ;
4958} ) ;
5059
0 commit comments