|
1 | | -import { test, expect, beforeAll, afterAll } from "bun:test"; |
2 | | -import { expandImports, hasImports, toCanonicalPath } from "./imports"; |
| 1 | +import { test, expect, beforeAll, afterAll, describe } from "bun:test"; |
| 2 | +import { expandImports, hasImports, toCanonicalPath, isMarkdownFileCommand } from "./imports"; |
3 | 3 | import { mkdtemp, rm, symlink } from "node:fs/promises"; |
4 | 4 | import { tmpdir } from "node:os"; |
5 | 5 | import { join } from "node:path"; |
@@ -422,3 +422,63 @@ test("expandImports runs bun commands in invocationCwd", async () => { |
422 | 422 | expect(result).toContain("bun-invocation-dir"); |
423 | 423 | expect(result).not.toContain("bun-agent-dir"); |
424 | 424 | }); |
| 425 | + |
| 426 | +// Auto-run .md files with ma tests |
| 427 | +describe("isMarkdownFileCommand", () => { |
| 428 | + test("detects simple .md file", () => { |
| 429 | + expect(isMarkdownFileCommand("foo.md")).toBe(true); |
| 430 | + }); |
| 431 | + |
| 432 | + test("detects relative path .md file", () => { |
| 433 | + expect(isMarkdownFileCommand("./foo.md")).toBe(true); |
| 434 | + expect(isMarkdownFileCommand("../foo.md")).toBe(true); |
| 435 | + }); |
| 436 | + |
| 437 | + test("detects home path .md file", () => { |
| 438 | + expect(isMarkdownFileCommand("~/foo.md")).toBe(true); |
| 439 | + expect(isMarkdownFileCommand("~/.ma/foo.md")).toBe(true); |
| 440 | + }); |
| 441 | + |
| 442 | + test("detects absolute path .md file", () => { |
| 443 | + expect(isMarkdownFileCommand("/path/to/foo.md")).toBe(true); |
| 444 | + }); |
| 445 | + |
| 446 | + test("detects compound .md file names", () => { |
| 447 | + expect(isMarkdownFileCommand("foo.claude.md")).toBe(true); |
| 448 | + expect(isMarkdownFileCommand("task.i.claude.md")).toBe(true); |
| 449 | + }); |
| 450 | + |
| 451 | + test("detects .md file with arguments", () => { |
| 452 | + expect(isMarkdownFileCommand("foo.md arg1 arg2")).toBe(true); |
| 453 | + expect(isMarkdownFileCommand("./task.claude.md --verbose")).toBe(true); |
| 454 | + }); |
| 455 | + |
| 456 | + test("does NOT match non-.md files", () => { |
| 457 | + expect(isMarkdownFileCommand("foo.txt")).toBe(false); |
| 458 | + expect(isMarkdownFileCommand("foo.js")).toBe(false); |
| 459 | + expect(isMarkdownFileCommand("echo hello")).toBe(false); |
| 460 | + expect(isMarkdownFileCommand("ls -la")).toBe(false); |
| 461 | + }); |
| 462 | + |
| 463 | + test("does NOT match commands containing .md elsewhere", () => { |
| 464 | + expect(isMarkdownFileCommand("echo foo.md")).toBe(false); |
| 465 | + expect(isMarkdownFileCommand("cat foo.md")).toBe(false); |
| 466 | + expect(isMarkdownFileCommand("grep pattern foo.md")).toBe(false); |
| 467 | + }); |
| 468 | + |
| 469 | + test("does NOT match .md in the middle of command", () => { |
| 470 | + expect(isMarkdownFileCommand("cp foo.md bar.md")).toBe(false); |
| 471 | + }); |
| 472 | +}); |
| 473 | + |
| 474 | +test("expandImports does not affect non-.md commands", async () => { |
| 475 | + const content = "!`echo 'not an md file'`"; |
| 476 | + const result = await expandImports(content, testDir); |
| 477 | + expect(result).toContain("not an md file"); |
| 478 | +}); |
| 479 | + |
| 480 | +test("expandImports preserves normal shell commands", async () => { |
| 481 | + const content = "!`echo hello.txt`"; |
| 482 | + const result = await expandImports(content, testDir); |
| 483 | + expect(result).toContain("hello.txt"); |
| 484 | +}); |
0 commit comments