Skip to content

Commit ad8a371

Browse files
committed
Fix QMD CI test runtime assumptions
1 parent 028e8fc commit ad8a371

4 files changed

Lines changed: 41 additions & 28 deletions

File tree

test/cli.test.ts

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@ let testCounter = 0; // Unique counter for each test run
2727
const thisDir = dirname(fileURLToPath(import.meta.url));
2828
const projectRoot = join(thisDir, "..");
2929
const 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
4041
async 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,

test/local-config.test.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ import { tmpdir } from "node:os";
55
import { afterEach, describe, expect, test } from "vitest";
66
import { findLocalConfigPath, getLocalDbPath } from "../src/collections.js";
77

8+
function cliCommandArgs(command: string): { bin: string; args: string[] } {
9+
const cliPath = join(process.cwd(), "src/cli/qmd.ts");
10+
if (process.versions.bun) {
11+
return { bin: process.execPath, args: [cliPath, command] };
12+
}
13+
return {
14+
bin: process.execPath,
15+
args: [join(process.cwd(), "node_modules/tsx/dist/cli.mjs"), cliPath, command],
16+
};
17+
}
18+
819
const roots: string[] = [];
920

1021
function tempProject(): string {
@@ -59,9 +70,8 @@ describe("local .qmd project config", () => {
5970
writeFileSync(join(root, ".qmd", "index.yaml"), `collections:\n docs:\n path: ${JSON.stringify(join(root, "docs"))}\n pattern: "**/*.md"\n context:\n /: Local test docs\nmodels:\n embed: local-embed-model\n rerank: local-rerank-model\n generate: local-generate-model\n`);
6071

6172
const home = join(root, "home");
62-
const tsxBin = join(process.cwd(), "node_modules", ".bin", "tsx");
63-
const runner = existsSync(tsxBin) ? tsxBin : "bun";
64-
const output = execFileSync(runner, [join(process.cwd(), "src/cli/qmd.ts"), "status"], {
73+
const { bin, args } = cliCommandArgs("status");
74+
const output = execFileSync(bin, args, {
6575
cwd: root,
6676
encoding: "utf-8",
6777
env: {

test/mcp.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ function seedTestData(db: Database): void {
186186
for (let i = 0; i < 768; i++) embedding[i] = Math.random();
187187

188188
for (const doc of docs.slice(0, 4)) { // Skip large file for embeddings
189-
db.prepare(`INSERT INTO content_vectors (hash, seq, pos, model, embedded_at) VALUES (?, 0, 0, 'embeddinggemma', ?)`).run(doc.hash, now);
189+
db.prepare(`INSERT INTO content_vectors (hash, seq, pos, model, embedded_at) VALUES (?, 0, 0, ?, ?)`).run(doc.hash, DEFAULT_EMBED_MODEL, now);
190190
db.prepare(`INSERT INTO vectors_vec (hash_seq, embedding) VALUES (?, ?)`).run(`${doc.hash}_0`, embedding);
191191
}
192192
}

test/package.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ describe("package grammar distribution", () => {
2020
expect(pkg.files, "published package files").toContain("scripts/check-package-grammars.mjs");
2121
expect(pkg.files, "published package files").toContain("skills/");
2222
const qmdSkill = readFileSync(new URL("skills/qmd/SKILL.md", root), "utf8");
23-
expect(qmdSkill).toContain("# QMD - Quick Markdown Search");
24-
expect(qmdSkill).toContain("## MCP: `query`");
23+
expect(qmdSkill).toContain("# QMD - Query Markdown Documents");
24+
expect(qmdSkill).toContain("## MCP Tool: `query`");
2525
expect(qmdSkill).not.toContain("This file is a discovery stub");
2626

2727
const scriptPath = join(root.pathname, "scripts", "check-package-grammars.mjs");

0 commit comments

Comments
 (0)