cli.test.ts 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. /**
  2. * CLI Integration Tests
  3. *
  4. * Tests all qmd CLI commands using a temporary test database via INDEX_PATH.
  5. * These tests spawn actual qmd processes to verify end-to-end functionality.
  6. */
  7. import { describe, test, expect, beforeAll, afterAll, beforeEach } from "bun:test";
  8. import { mkdtemp, rm, writeFile, mkdir } from "fs/promises";
  9. import { tmpdir } from "os";
  10. import { join } from "path";
  11. // Test fixtures directory and database path
  12. let testDir: string;
  13. let testDbPath: string;
  14. let fixturesDir: string;
  15. let testCounter = 0; // Unique counter for each test run
  16. // Get the directory where this test file lives (same as qmd.ts)
  17. const qmdDir = import.meta.dir;
  18. const qmdScript = join(qmdDir, "qmd.ts");
  19. // Helper to run qmd command with test database
  20. async function runQmd(
  21. args: string[],
  22. options: { cwd?: string; env?: Record<string, string>; dbPath?: string } = {}
  23. ): Promise<{ stdout: string; stderr: string; exitCode: number }> {
  24. const workingDir = options.cwd || fixturesDir;
  25. const dbPath = options.dbPath || testDbPath;
  26. const proc = Bun.spawn(["bun", qmdScript, ...args], {
  27. cwd: workingDir,
  28. env: {
  29. ...process.env,
  30. INDEX_PATH: dbPath,
  31. PWD: workingDir, // Must explicitly set PWD since getPwd() checks this
  32. ...options.env,
  33. },
  34. stdout: "pipe",
  35. stderr: "pipe",
  36. });
  37. const stdout = await new Response(proc.stdout).text();
  38. const stderr = await new Response(proc.stderr).text();
  39. const exitCode = await proc.exited;
  40. return { stdout, stderr, exitCode };
  41. }
  42. // Get a fresh database path for isolated tests
  43. function getFreshDbPath(): string {
  44. testCounter++;
  45. return join(testDir, `test-${testCounter}.sqlite`);
  46. }
  47. // Setup test fixtures
  48. beforeAll(async () => {
  49. // Create temp directory structure
  50. testDir = await mkdtemp(join(tmpdir(), "qmd-test-"));
  51. testDbPath = join(testDir, "test.sqlite");
  52. fixturesDir = join(testDir, "fixtures");
  53. await mkdir(fixturesDir, { recursive: true });
  54. await mkdir(join(fixturesDir, "notes"), { recursive: true });
  55. await mkdir(join(fixturesDir, "docs"), { recursive: true });
  56. // Create test markdown files
  57. await writeFile(
  58. join(fixturesDir, "README.md"),
  59. `# Test Project
  60. This is a test project for QMD CLI testing.
  61. ## Features
  62. - Full-text search with BM25
  63. - Vector similarity search
  64. - Hybrid search with reranking
  65. `
  66. );
  67. await writeFile(
  68. join(fixturesDir, "notes", "meeting.md"),
  69. `# Team Meeting Notes
  70. Date: 2024-01-15
  71. ## Attendees
  72. - Alice
  73. - Bob
  74. - Charlie
  75. ## Discussion Topics
  76. - Project timeline review
  77. - Resource allocation
  78. - Technical debt prioritization
  79. ## Action Items
  80. 1. Alice to update documentation
  81. 2. Bob to fix authentication bug
  82. 3. Charlie to review pull requests
  83. `
  84. );
  85. await writeFile(
  86. join(fixturesDir, "notes", "ideas.md"),
  87. `# Product Ideas
  88. ## Feature Requests
  89. - Dark mode support
  90. - Keyboard shortcuts
  91. - Export to PDF
  92. ## Technical Improvements
  93. - Improve search performance
  94. - Add caching layer
  95. - Optimize database queries
  96. `
  97. );
  98. await writeFile(
  99. join(fixturesDir, "docs", "api.md"),
  100. `# API Documentation
  101. ## Endpoints
  102. ### GET /search
  103. Search for documents.
  104. Parameters:
  105. - q: Search query (required)
  106. - limit: Max results (default: 10)
  107. ### GET /document/:id
  108. Retrieve a specific document.
  109. ### POST /index
  110. Index new documents.
  111. `
  112. );
  113. });
  114. // Cleanup after all tests
  115. afterAll(async () => {
  116. if (testDir) {
  117. await rm(testDir, { recursive: true, force: true });
  118. }
  119. });
  120. describe("CLI Help", () => {
  121. test("shows help with --help flag", async () => {
  122. const { stdout, exitCode } = await runQmd(["--help"]);
  123. expect(exitCode).toBe(0);
  124. expect(stdout).toContain("Usage:");
  125. expect(stdout).toContain("qmd collection add");
  126. expect(stdout).toContain("qmd search");
  127. });
  128. test("shows help with no arguments", async () => {
  129. const { stdout, exitCode } = await runQmd([]);
  130. expect(exitCode).toBe(1);
  131. expect(stdout).toContain("Usage:");
  132. });
  133. });
  134. describe("CLI Add Command", () => {
  135. test("adds files from current directory", async () => {
  136. const { stdout, exitCode } = await runQmd(["collection", "add", "."]);
  137. expect(exitCode).toBe(0);
  138. expect(stdout).toContain("Collection:");
  139. expect(stdout).toContain("Indexed:");
  140. });
  141. test("adds files with custom glob pattern", async () => {
  142. const { stdout, exitCode } = await runQmd(["collection", "add", ".", "--mask", "notes/*.md"]);
  143. expect(exitCode).toBe(0);
  144. expect(stdout).toContain("Collection:");
  145. // Should find meeting.md and ideas.md in notes/
  146. expect(stdout).toContain("notes/*.md");
  147. });
  148. test("can recreate collection with remove and add", async () => {
  149. // First add
  150. await runQmd(["collection", "add", "."]);
  151. // Remove it
  152. await runQmd(["collection", "remove", "fixtures"]);
  153. // Re-add
  154. const { stdout, exitCode } = await runQmd(["collection", "add", "."]);
  155. expect(exitCode).toBe(0);
  156. expect(stdout).toContain("Collection 'fixtures' created successfully");
  157. });
  158. });
  159. describe("CLI Status Command", () => {
  160. beforeEach(async () => {
  161. // Ensure we have indexed files
  162. await runQmd(["collection", "add", "."]);
  163. });
  164. test("shows index status", async () => {
  165. const { stdout, exitCode } = await runQmd(["status"]);
  166. expect(exitCode).toBe(0);
  167. // Should show collection info
  168. expect(stdout).toContain("Collection");
  169. });
  170. });
  171. describe("CLI Search Command", () => {
  172. beforeEach(async () => {
  173. // Ensure we have indexed files
  174. await runQmd(["collection", "add", "."]);
  175. });
  176. test("searches for documents with BM25", async () => {
  177. const { stdout, exitCode } = await runQmd(["search", "meeting"]);
  178. expect(exitCode).toBe(0);
  179. // Should find meeting.md
  180. expect(stdout.toLowerCase()).toContain("meeting");
  181. });
  182. test("searches with limit option", async () => {
  183. const { stdout, exitCode } = await runQmd(["search", "-n", "1", "test"]);
  184. expect(exitCode).toBe(0);
  185. });
  186. test("searches with all results option", async () => {
  187. const { stdout, exitCode } = await runQmd(["search", "--all", "the"]);
  188. expect(exitCode).toBe(0);
  189. });
  190. test("returns no results message for non-matching query", async () => {
  191. const { stdout, exitCode } = await runQmd(["search", "xyznonexistent123"]);
  192. expect(exitCode).toBe(0);
  193. expect(stdout).toContain("No results");
  194. });
  195. test("requires query argument", async () => {
  196. const { stdout, stderr, exitCode } = await runQmd(["search"]);
  197. expect(exitCode).toBe(1);
  198. // Error message goes to stderr
  199. expect(stderr).toContain("Usage:");
  200. });
  201. });
  202. describe("CLI Get Command", () => {
  203. beforeEach(async () => {
  204. // Ensure we have indexed files
  205. await runQmd(["collection", "add", "."]);
  206. });
  207. test("retrieves document content by path", async () => {
  208. const { stdout, exitCode } = await runQmd(["get", "README.md"]);
  209. expect(exitCode).toBe(0);
  210. expect(stdout).toContain("Test Project");
  211. });
  212. test("retrieves document from subdirectory", async () => {
  213. const { stdout, exitCode } = await runQmd(["get", "notes/meeting.md"]);
  214. expect(exitCode).toBe(0);
  215. expect(stdout).toContain("Team Meeting");
  216. });
  217. test("handles non-existent file", async () => {
  218. const { stdout, exitCode } = await runQmd(["get", "nonexistent.md"]);
  219. // Should indicate file not found
  220. expect(exitCode).toBe(1);
  221. });
  222. });
  223. describe("CLI Multi-Get Command", () => {
  224. beforeEach(async () => {
  225. // Ensure we have indexed files
  226. await runQmd(["collection", "add", "."]);
  227. });
  228. test("retrieves multiple documents by pattern", async () => {
  229. const { stdout, exitCode } = await runQmd(["multi-get", "notes/*.md"]);
  230. expect(exitCode).toBe(0);
  231. // Should contain content from both notes files
  232. expect(stdout).toContain("Meeting");
  233. expect(stdout).toContain("Ideas");
  234. });
  235. test("retrieves documents by comma-separated paths", async () => {
  236. const { stdout, exitCode } = await runQmd([
  237. "multi-get",
  238. "README.md,notes/meeting.md",
  239. ]);
  240. expect(exitCode).toBe(0);
  241. expect(stdout).toContain("Test Project");
  242. expect(stdout).toContain("Team Meeting");
  243. });
  244. });
  245. describe("CLI Update Command", () => {
  246. let localDbPath: string;
  247. beforeEach(async () => {
  248. // Use a fresh database for this test suite
  249. localDbPath = getFreshDbPath();
  250. // Ensure we have indexed files
  251. await runQmd(["collection", "add", "."], { dbPath: localDbPath });
  252. });
  253. test("updates all collections", async () => {
  254. const { stdout, exitCode } = await runQmd(["update"], { dbPath: localDbPath });
  255. expect(exitCode).toBe(0);
  256. expect(stdout).toContain("Updating");
  257. });
  258. });
  259. describe("CLI Add-Context Command", () => {
  260. beforeEach(async () => {
  261. // Ensure we have indexed files
  262. await runQmd(["collection", "add", "."]);
  263. });
  264. test("adds context to a path", async () => {
  265. const { stdout, exitCode } = await runQmd([
  266. "add-context",
  267. "notes",
  268. "Personal notes and meeting logs",
  269. ]);
  270. expect(exitCode).toBe(0);
  271. });
  272. test("requires path and text arguments", async () => {
  273. const { stderr, exitCode } = await runQmd(["add-context"]);
  274. expect(exitCode).toBe(1);
  275. // Error message goes to stderr
  276. expect(stderr).toContain("Usage:");
  277. });
  278. });
  279. describe("CLI Cleanup Command", () => {
  280. beforeEach(async () => {
  281. // Ensure we have indexed files
  282. await runQmd(["collection", "add", "."]);
  283. });
  284. test("cleans up orphaned entries", async () => {
  285. const { stdout, exitCode } = await runQmd(["cleanup"]);
  286. expect(exitCode).toBe(0);
  287. });
  288. });
  289. describe("CLI Error Handling", () => {
  290. test("handles unknown command", async () => {
  291. const { stderr, exitCode } = await runQmd(["unknowncommand"]);
  292. expect(exitCode).toBe(1);
  293. // Should indicate unknown command
  294. expect(stderr).toContain("Unknown command");
  295. });
  296. test("uses INDEX_PATH environment variable", async () => {
  297. // Verify the test DB path is being used by creating a separate index
  298. const customDbPath = join(testDir, "custom.sqlite");
  299. const { exitCode } = await runQmd(["collection", "add", "."], {
  300. env: { INDEX_PATH: customDbPath },
  301. });
  302. expect(exitCode).toBe(0);
  303. // The custom database should exist
  304. const file = Bun.file(customDbPath);
  305. expect(await file.exists()).toBe(true);
  306. });
  307. });
  308. describe("CLI Output Formats", () => {
  309. beforeEach(async () => {
  310. await runQmd(["collection", "add", "."]);
  311. });
  312. test("search with --json flag outputs JSON", async () => {
  313. const { stdout, exitCode } = await runQmd(["search", "--json", "test"]);
  314. expect(exitCode).toBe(0);
  315. // Should be valid JSON
  316. const parsed = JSON.parse(stdout);
  317. expect(Array.isArray(parsed)).toBe(true);
  318. });
  319. test("search with --files flag outputs file paths", async () => {
  320. const { stdout, exitCode } = await runQmd(["search", "--files", "meeting"]);
  321. expect(exitCode).toBe(0);
  322. expect(stdout).toContain(".md");
  323. });
  324. test("search output includes snippets by default", async () => {
  325. const { stdout, exitCode } = await runQmd(["search", "API"]);
  326. expect(exitCode).toBe(0);
  327. // If results found, should have snippet content
  328. if (!stdout.includes("No results")) {
  329. expect(stdout.toLowerCase()).toContain("api");
  330. }
  331. });
  332. });
  333. describe("CLI Search with Collection Filter", () => {
  334. let localDbPath: string;
  335. beforeEach(async () => {
  336. // Use a fresh database for this test suite
  337. localDbPath = getFreshDbPath();
  338. // Create multiple collections
  339. await runQmd(["collection", "add", ".", "--mask", "notes/*.md"], { dbPath: localDbPath });
  340. await runQmd(["collection", "add", ".", "--mask", "docs/*.md"], { dbPath: localDbPath });
  341. });
  342. test("filters search by collection name", async () => {
  343. const { stdout, exitCode } = await runQmd([
  344. "search",
  345. "-c",
  346. "notes",
  347. "meeting",
  348. ], { dbPath: localDbPath });
  349. expect(exitCode).toBe(0);
  350. // Should find results from notes collection
  351. expect(stdout.toLowerCase()).toContain("meeting");
  352. });
  353. });
  354. describe("CLI Context Management", () => {
  355. let localDbPath: string;
  356. beforeEach(async () => {
  357. // Use a fresh database for this test suite
  358. localDbPath = getFreshDbPath();
  359. // Index some files first
  360. await runQmd(["collection", "add", "."], { dbPath: localDbPath });
  361. });
  362. test("add global context with /", async () => {
  363. const { stdout, exitCode } = await runQmd([
  364. "context",
  365. "add",
  366. "/",
  367. "Global system context",
  368. ], { dbPath: localDbPath });
  369. expect(exitCode).toBe(0);
  370. expect(stdout).toContain("✓ Added global context");
  371. expect(stdout).toContain("Global system context");
  372. });
  373. test("list contexts", async () => {
  374. // Add a global context first
  375. await runQmd([
  376. "context",
  377. "add",
  378. "/",
  379. "Test context",
  380. ], { dbPath: localDbPath });
  381. const { stdout, exitCode } = await runQmd([
  382. "context",
  383. "list",
  384. ], { dbPath: localDbPath });
  385. expect(exitCode).toBe(0);
  386. expect(stdout).toContain("Configured Contexts");
  387. expect(stdout).toContain("Test context");
  388. });
  389. test("add context to virtual path", async () => {
  390. // Collection name should be "fixtures" (basename of the fixtures directory)
  391. const { stdout, exitCode } = await runQmd([
  392. "context",
  393. "add",
  394. "qmd://fixtures/notes",
  395. "Context for notes subdirectory",
  396. ], { dbPath: localDbPath });
  397. expect(exitCode).toBe(0);
  398. expect(stdout).toContain("✓ Added context for: qmd://fixtures/notes");
  399. });
  400. test("remove global context", async () => {
  401. // Add a global context first
  402. await runQmd([
  403. "context",
  404. "add",
  405. "/",
  406. "Global context to remove",
  407. ], { dbPath: localDbPath });
  408. const { stdout, exitCode } = await runQmd([
  409. "context",
  410. "rm",
  411. "/",
  412. ], { dbPath: localDbPath });
  413. expect(exitCode).toBe(0);
  414. expect(stdout).toContain("✓ Removed");
  415. });
  416. test("remove virtual path context", async () => {
  417. // Add a context first
  418. await runQmd([
  419. "context",
  420. "add",
  421. "qmd://fixtures/notes",
  422. "Context to remove",
  423. ], { dbPath: localDbPath });
  424. const { stdout, exitCode } = await runQmd([
  425. "context",
  426. "rm",
  427. "qmd://fixtures/notes",
  428. ], { dbPath: localDbPath });
  429. expect(exitCode).toBe(0);
  430. expect(stdout).toContain("✓ Removed context for: qmd://fixtures/notes");
  431. });
  432. test("fails to remove non-existent context", async () => {
  433. const { stdout, stderr, exitCode } = await runQmd([
  434. "context",
  435. "rm",
  436. "qmd://nonexistent/path",
  437. ], { dbPath: localDbPath });
  438. expect(exitCode).toBe(1);
  439. expect(stderr || stdout).toContain("not found");
  440. });
  441. });
  442. describe("CLI ls Command", () => {
  443. let localDbPath: string;
  444. beforeEach(async () => {
  445. // Use a fresh database for this test suite
  446. localDbPath = getFreshDbPath();
  447. // Index some files first
  448. await runQmd(["collection", "add", "."], { dbPath: localDbPath });
  449. });
  450. test("lists all collections", async () => {
  451. const { stdout, exitCode } = await runQmd(["ls"], { dbPath: localDbPath });
  452. expect(exitCode).toBe(0);
  453. expect(stdout).toContain("Collections:");
  454. expect(stdout).toContain("qmd://fixtures/");
  455. });
  456. test("lists files in a collection", async () => {
  457. const { stdout, exitCode } = await runQmd(["ls", "fixtures"], { dbPath: localDbPath });
  458. expect(exitCode).toBe(0);
  459. expect(stdout).toContain("qmd://fixtures/README.md");
  460. expect(stdout).toContain("qmd://fixtures/notes/meeting.md");
  461. });
  462. test("lists files with path prefix", async () => {
  463. const { stdout, exitCode } = await runQmd(["ls", "fixtures/notes"], { dbPath: localDbPath });
  464. expect(exitCode).toBe(0);
  465. expect(stdout).toContain("qmd://fixtures/notes/meeting.md");
  466. expect(stdout).toContain("qmd://fixtures/notes/ideas.md");
  467. // Should not include files outside the prefix
  468. expect(stdout).not.toContain("qmd://fixtures/README.md");
  469. });
  470. test("lists files with virtual path", async () => {
  471. const { stdout, exitCode } = await runQmd(["ls", "qmd://fixtures/docs"], { dbPath: localDbPath });
  472. expect(exitCode).toBe(0);
  473. expect(stdout).toContain("qmd://fixtures/docs/api.md");
  474. });
  475. test("handles non-existent collection", async () => {
  476. const { stderr, exitCode } = await runQmd(["ls", "nonexistent"], { dbPath: localDbPath });
  477. expect(exitCode).toBe(1);
  478. expect(stderr).toContain("Collection not found");
  479. });
  480. });
  481. describe("CLI Collection Commands", () => {
  482. let localDbPath: string;
  483. beforeEach(async () => {
  484. // Use a fresh database for this test suite
  485. localDbPath = getFreshDbPath();
  486. // Index some files first to create a collection
  487. await runQmd(["collection", "add", "."], { dbPath: localDbPath });
  488. });
  489. test("lists collections", async () => {
  490. const { stdout, exitCode } = await runQmd(["collection", "list"], { dbPath: localDbPath });
  491. expect(exitCode).toBe(0);
  492. expect(stdout).toContain("Collections");
  493. expect(stdout).toContain("fixtures");
  494. expect(stdout).toContain("Path:");
  495. expect(stdout).toContain("Pattern:");
  496. expect(stdout).toContain("Files:");
  497. });
  498. test("removes a collection", async () => {
  499. // First verify the collection exists
  500. const { stdout: listBefore } = await runQmd(["collection", "list"], { dbPath: localDbPath });
  501. expect(listBefore).toContain("fixtures");
  502. // Remove it
  503. const { stdout, exitCode } = await runQmd(["collection", "remove", "fixtures"], { dbPath: localDbPath });
  504. expect(exitCode).toBe(0);
  505. expect(stdout).toContain("✓ Removed collection 'fixtures'");
  506. expect(stdout).toContain("Deleted");
  507. // Verify it's gone
  508. const { stdout: listAfter } = await runQmd(["collection", "list"], { dbPath: localDbPath });
  509. expect(listAfter).not.toContain("fixtures");
  510. });
  511. test("handles removing non-existent collection", async () => {
  512. const { stderr, exitCode } = await runQmd(["collection", "remove", "nonexistent"], { dbPath: localDbPath });
  513. expect(exitCode).toBe(1);
  514. expect(stderr).toContain("Collection not found");
  515. });
  516. test("handles missing remove argument", async () => {
  517. const { stderr, exitCode } = await runQmd(["collection", "remove"], { dbPath: localDbPath });
  518. expect(exitCode).toBe(1);
  519. expect(stderr).toContain("Usage:");
  520. });
  521. test("handles unknown subcommand", async () => {
  522. const { stderr, exitCode } = await runQmd(["collection", "invalid"], { dbPath: localDbPath });
  523. expect(exitCode).toBe(1);
  524. expect(stderr).toContain("Unknown subcommand");
  525. });
  526. test("renames a collection", async () => {
  527. // First verify the collection exists
  528. const { stdout: listBefore } = await runQmd(["collection", "list"], { dbPath: localDbPath });
  529. expect(listBefore).toMatch(/^fixtures$/m); // Collection name on its own line
  530. // Rename it
  531. const { stdout, exitCode } = await runQmd(["collection", "rename", "fixtures", "my-fixtures"], { dbPath: localDbPath });
  532. expect(exitCode).toBe(0);
  533. expect(stdout).toContain("✓ Renamed collection 'fixtures' to 'my-fixtures'");
  534. expect(stdout).toContain("qmd://fixtures/");
  535. expect(stdout).toContain("qmd://my-fixtures/");
  536. // Verify the new name exists and old name is gone
  537. const { stdout: listAfter } = await runQmd(["collection", "list"], { dbPath: localDbPath });
  538. expect(listAfter).toMatch(/^my-fixtures$/m); // Collection name on its own line
  539. expect(listAfter).not.toMatch(/^fixtures$/m); // Old name should not appear as collection name
  540. });
  541. test("handles renaming non-existent collection", async () => {
  542. const { stderr, exitCode } = await runQmd(["collection", "rename", "nonexistent", "newname"], { dbPath: localDbPath });
  543. expect(exitCode).toBe(1);
  544. expect(stderr).toContain("Collection not found");
  545. });
  546. test("handles renaming to existing collection name", async () => {
  547. // Create a second collection in a temp directory
  548. const tempDir = await mkdtemp(join(tmpdir(), "qmd-second-"));
  549. await writeFile(join(tempDir, "test.md"), "# Test");
  550. const addResult = await runQmd(["collection", "add", tempDir, "--name", "second"], { dbPath: localDbPath });
  551. if (addResult.exitCode !== 0) {
  552. console.error("Failed to add second collection:", addResult.stderr);
  553. }
  554. expect(addResult.exitCode).toBe(0);
  555. // Verify both collections exist
  556. const { stdout: listBoth } = await runQmd(["collection", "list"], { dbPath: localDbPath });
  557. expect(listBoth).toMatch(/^fixtures$/m);
  558. expect(listBoth).toMatch(/^second$/m);
  559. // Try to rename fixtures to second (which already exists)
  560. const { stderr, exitCode } = await runQmd(["collection", "rename", "fixtures", "second"], { dbPath: localDbPath });
  561. expect(exitCode).toBe(1);
  562. expect(stderr).toContain("Collection name already exists");
  563. });
  564. test("handles missing rename arguments", async () => {
  565. const { stderr: stderr1, exitCode: exitCode1 } = await runQmd(["collection", "rename"], { dbPath: localDbPath });
  566. expect(exitCode1).toBe(1);
  567. expect(stderr1).toContain("Usage:");
  568. const { stderr: stderr2, exitCode: exitCode2 } = await runQmd(["collection", "rename", "fixtures"], { dbPath: localDbPath });
  569. expect(exitCode2).toBe(1);
  570. expect(stderr2).toContain("Usage:");
  571. });
  572. });