@@ -27,14 +27,15 @@ let testCounter = 0; // Unique counter for each test run
2727const thisDir = dirname ( fileURLToPath ( import . meta. url ) ) ;
2828const projectRoot = join ( thisDir , ".." ) ;
2929const qmdScript = join ( projectRoot , "src" , "cli" , "qmd.ts" ) ;
30- // Resolve tsx binary from project's node_modules (not cwd-dependent)
31- const tsxBin = ( ( ) => {
32- const candidate = join ( projectRoot , "node_modules" , ".bin" , "tsx" ) ;
33- if ( existsSync ( candidate ) ) {
34- return candidate ;
35- }
36- return join ( process . cwd ( ) , "node_modules" , ".bin" , "tsx" ) ;
37- } ) ( ) ;
30+ const isBunRuntime = typeof ( globalThis as { Bun ?: unknown } ) . Bun !== "undefined" ;
31+ const tsxCli = join ( projectRoot , "node_modules" , "tsx" , "dist" , "cli.mjs" ) ;
32+ const qmdCommand = isBunRuntime
33+ ? { command : process . execPath , args : [ qmdScript ] }
34+ : { command : process . execPath , args : [ tsxCli , qmdScript ] } ;
35+
36+ function qmdRunnerArgs ( args : string [ ] ) : { command : string ; args : string [ ] } {
37+ return { command : qmdCommand . command , args : [ ...qmdCommand . args , ...args ] } ;
38+ }
3839
3940// Helper to run qmd command with test database
4041async function runQmd (
@@ -44,7 +45,8 @@ async function runQmd(
4445 const workingDir = options . cwd || fixturesDir ;
4546 const dbPath = options . dbPath || testDbPath ;
4647 const configDir = options . configDir || testConfigDir ;
47- const proc = spawn ( tsxBin , [ qmdScript , ...args ] , {
48+ const runner = qmdRunnerArgs ( args ) ;
49+ const proc = spawn ( runner . command , runner . args , {
4850 cwd : workingDir ,
4951 env : {
5052 ...process . env ,
@@ -252,23 +254,23 @@ describe("CLI Skills", () => {
252254 expect ( stderr ) . toBe ( "" ) ;
253255 expect ( exitCode ) . toBe ( 0 ) ;
254256 expect ( stdout ) . toContain ( "qmd" ) ;
255- expect ( stdout ) . toContain ( "Search markdown knowledge bases" ) ;
257+ expect ( stdout ) . toContain ( "Search local markdown knowledge bases" ) ;
256258 } ) ;
257259
258260 test ( "gets version-matched runtime skill content" , async ( ) => {
259261 const { stdout, stderr, exitCode } = await runQmd ( [ "skills" , "get" , "qmd" ] ) ;
260262 expect ( stderr ) . toBe ( "" ) ;
261263 expect ( exitCode ) . toBe ( 0 ) ;
262- expect ( stdout ) . toContain ( "# QMD - Quick Markdown Search " ) ;
263- expect ( stdout ) . toContain ( "## MCP: `query`" ) ;
264+ expect ( stdout ) . toContain ( "# QMD - Query Markdown Documents " ) ;
265+ expect ( stdout ) . toContain ( "## MCP Tool : `query`" ) ;
264266 expect ( stdout ) . not . toContain ( "This file is a discovery stub" ) ;
265267 } ) ;
266268
267269 test ( "gets runtime skill with supplementary references" , async ( ) => {
268270 const { stdout, stderr, exitCode } = await runQmd ( [ "skills" , "get" , "qmd" , "--full" ] ) ;
269271 expect ( stderr ) . toBe ( "" ) ;
270272 expect ( exitCode ) . toBe ( 0 ) ;
271- expect ( stdout ) . toContain ( "# QMD - Quick Markdown Search " ) ;
273+ expect ( stdout ) . toContain ( "# QMD - Query Markdown Documents " ) ;
272274 expect ( stdout ) . toContain ( "--- references/mcp-setup.md ---" ) ;
273275 expect ( stdout ) . toContain ( "# QMD MCP Server Setup" ) ;
274276 } ) ;
@@ -284,8 +286,8 @@ describe("CLI Skills", () => {
284286 const { stdout, stderr, exitCode } = await runQmd ( [ "skill" , "show" ] ) ;
285287 expect ( stderr ) . toBe ( "" ) ;
286288 expect ( exitCode ) . toBe ( 0 ) ;
287- expect ( stdout ) . toContain ( "# QMD - Quick Markdown Search " ) ;
288- expect ( stdout ) . toContain ( "## MCP: `query`" ) ;
289+ expect ( stdout ) . toContain ( "# QMD - Query Markdown Documents " ) ;
290+ expect ( stdout ) . toContain ( "## MCP Tool : `query`" ) ;
289291 expect ( stdout ) . not . toContain ( "This file is a discovery stub" ) ;
290292 } ) ;
291293
@@ -300,8 +302,8 @@ describe("CLI Skills", () => {
300302
301303 const installedSkillDir = join ( installDir , ".agents" , "skills" , "qmd" ) ;
302304 const installed = readFileSync ( join ( installedSkillDir , "SKILL.md" ) , "utf8" ) ;
303- expect ( installed ) . toContain ( "# QMD - Quick Markdown Search " ) ;
304- expect ( installed ) . toContain ( "## MCP: `query`" ) ;
305+ expect ( installed ) . toContain ( "# QMD - Query Markdown Documents " ) ;
306+ expect ( installed ) . toContain ( "## MCP Tool : `query`" ) ;
305307 expect ( installed ) . not . toContain ( "This file is a discovery stub" ) ;
306308 expect ( readFileSync ( join ( installedSkillDir , "references" , "mcp-setup.md" ) , "utf8" ) ) . toContain ( "# QMD MCP Server Setup" ) ;
307309 } ) ;
@@ -370,7 +372,7 @@ describe("CLI Skill Commands", () => {
370372 expect ( exitCode ) . toBe ( 0 ) ;
371373
372374 const skillDir = join ( projectDir , ".agents" , "skills" , "qmd" ) ;
373- expect ( readFileSync ( join ( skillDir , "SKILL.md" ) , "utf-8" ) ) . toContain ( "# QMD - Quick Markdown Search " ) ;
375+ expect ( readFileSync ( join ( skillDir , "SKILL.md" ) , "utf-8" ) ) . toContain ( "# QMD - Query Markdown Documents " ) ;
374376 expect ( existsSync ( join ( projectDir , ".claude" , "skills" , "qmd" ) ) ) . toBe ( false ) ;
375377 expect ( stdout ) . toContain ( `✓ Installed QMD skill to ${ skillDir } ` ) ;
376378 expect ( stdout ) . toContain ( "Tip: create a Claude symlink manually" ) ;
@@ -388,9 +390,9 @@ describe("CLI Skill Commands", () => {
388390 const skillDir = join ( fakeHome , ".agents" , "skills" , "qmd" ) ;
389391 const claudeLink = join ( fakeHome , ".claude" , "skills" , "qmd" ) ;
390392
391- expect ( readFileSync ( join ( skillDir , "SKILL.md" ) , "utf-8" ) ) . toContain ( "# QMD - Quick Markdown Search " ) ;
393+ expect ( readFileSync ( join ( skillDir , "SKILL.md" ) , "utf-8" ) ) . toContain ( "# QMD - Query Markdown Documents " ) ;
392394 expect ( lstatSync ( claudeLink ) . isSymbolicLink ( ) ) . toBe ( true ) ;
393- expect ( readFileSync ( join ( claudeLink , "SKILL.md" ) , "utf-8" ) ) . toContain ( "# QMD - Quick Markdown Search " ) ;
395+ expect ( readFileSync ( join ( claudeLink , "SKILL.md" ) , "utf-8" ) ) . toContain ( "# QMD - Query Markdown Documents " ) ;
394396 expect ( stdout ) . toContain ( `✓ Installed QMD skill to ${ skillDir } ` ) ;
395397 expect ( stdout ) . toContain ( `✓ Linked Claude skill at ${ claudeLink } ` ) ;
396398 } ) ;
@@ -408,7 +410,7 @@ describe("CLI Skill Commands", () => {
408410
409411 const skillDir = join ( fakeHome , ".agents" , "skills" , "qmd" ) ;
410412 expect ( lstatSync ( skillDir ) . isSymbolicLink ( ) ) . toBe ( false ) ;
411- expect ( readFileSync ( join ( skillDir , "SKILL.md" ) , "utf-8" ) ) . toContain ( "# QMD - Quick Markdown Search " ) ;
413+ expect ( readFileSync ( join ( skillDir , "SKILL.md" ) , "utf-8" ) ) . toContain ( "# QMD - Query Markdown Documents " ) ;
412414 expect ( stdout ) . toContain ( `✓ Claude already sees the skill via ${ join ( fakeHome , ".claude" , "skills" ) } ` ) ;
413415 } ) ;
414416
@@ -1580,7 +1582,8 @@ describe("mcp http daemon", () => {
15801582 port : number ,
15811583 options : { args ?: string [ ] ; env ?: Record < string , string > } = { } ,
15821584 ) : import ( "child_process" ) . ChildProcess {
1583- const proc = spawn ( tsxBin , [ qmdScript , ...( options . args ?? [ ] ) , "mcp" , "--http" , "--port" , String ( port ) ] , {
1585+ const runner = qmdRunnerArgs ( [ ...( options . args ?? [ ] ) , "mcp" , "--http" , "--port" , String ( port ) ] ) ;
1586+ const proc = spawn ( runner . command , runner . args , {
15841587 cwd : fixturesDir ,
15851588 env : {
15861589 ...process . env ,
0 commit comments