import-markdown.test.mjs
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd
feat(calendar): enforce agent context tiers in retrieval AP…
Human
minor
⚠ breaking
1 day ago
| 1 | /** |
| 2 | * Markdown importer tests: importMarkdown with file and folder, dryRun, project/tags. |
| 3 | */ |
| 4 | import { describe, it, before, after } from 'node:test'; |
| 5 | import assert from 'node:assert'; |
| 6 | import path from 'path'; |
| 7 | import fs from 'fs'; |
| 8 | import { fileURLToPath } from 'url'; |
| 9 | import { importMarkdown } from '../lib/importers/markdown.mjs'; |
| 10 | import { readNote } from '../lib/vault.mjs'; |
| 11 | |
| 12 | const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
| 13 | const fixtureMd = path.join(__dirname, 'fixtures', 'markdown-import', 'simple.md'); |
| 14 | const testVault = path.join(__dirname, 'fixtures', 'tmp-import-vault'); |
| 15 | |
| 16 | describe('importMarkdown', () => { |
| 17 | before(() => { |
| 18 | if (fs.existsSync(testVault)) fs.rmSync(testVault, { recursive: true }); |
| 19 | fs.mkdirSync(testVault, { recursive: true }); |
| 20 | }); |
| 21 | |
| 22 | after(() => { |
| 23 | if (fs.existsSync(testVault)) { |
| 24 | try { |
| 25 | fs.rmSync(testVault, { recursive: true }); |
| 26 | } catch (_) {} |
| 27 | } |
| 28 | }); |
| 29 | |
| 30 | it('imports a single file and returns imported paths', async () => { |
| 31 | const ctx = { |
| 32 | vaultPath: testVault, |
| 33 | outputBase: 'imports/md', |
| 34 | project: null, |
| 35 | tags: [], |
| 36 | dryRun: false, |
| 37 | }; |
| 38 | const result = await importMarkdown(fixtureMd, ctx); |
| 39 | assert(Array.isArray(result.imported)); |
| 40 | assert.strictEqual(result.count, 1); |
| 41 | assert(result.imported[0].path.includes('simple.md')); |
| 42 | const note = readNote(testVault, result.imported[0].path); |
| 43 | assert(note.body.includes('Imported note')); |
| 44 | assert(note.frontmatter?.source === 'markdown'); |
| 45 | assert(note.frontmatter?.date); |
| 46 | }); |
| 47 | |
| 48 | it('dryRun does not write files', async () => { |
| 49 | const ctx = { |
| 50 | vaultPath: testVault, |
| 51 | outputBase: 'imports/dry', |
| 52 | project: null, |
| 53 | tags: [], |
| 54 | dryRun: true, |
| 55 | }; |
| 56 | const result = await importMarkdown(fixtureMd, ctx); |
| 57 | assert.strictEqual(result.count, 1); |
| 58 | const outPath = path.join(testVault, 'imports/dry/simple.md'); |
| 59 | assert(!fs.existsSync(outPath)); |
| 60 | }); |
| 61 | |
| 62 | it('merges project and tags when provided', async () => { |
| 63 | const ctx = { |
| 64 | vaultPath: testVault, |
| 65 | outputBase: 'imports/tagged', |
| 66 | project: 'myproject', |
| 67 | tags: ['imported', 'test'], |
| 68 | dryRun: false, |
| 69 | }; |
| 70 | const result = await importMarkdown(fixtureMd, ctx); |
| 71 | assert.strictEqual(result.count, 1); |
| 72 | const note = readNote(testVault, result.imported[0].path); |
| 73 | assert.strictEqual(note.project, 'myproject'); |
| 74 | assert(Array.isArray(note.tags)); |
| 75 | assert(note.tags.includes('imported')); |
| 76 | assert(note.tags.includes('test')); |
| 77 | }); |
| 78 | |
| 79 | it('throws when input path does not exist', async () => { |
| 80 | const ctx = { |
| 81 | vaultPath: testVault, |
| 82 | outputBase: 'imports', |
| 83 | project: null, |
| 84 | tags: [], |
| 85 | dryRun: false, |
| 86 | }; |
| 87 | await assert.rejects( |
| 88 | () => importMarkdown(path.join(__dirname, 'fixtures', 'nonexistent.md'), ctx), |
| 89 | /Input not found/ |
| 90 | ); |
| 91 | }); |
| 92 | |
| 93 | it('discovers .markdown and case variants of .md when importing a folder (ZIP extract parity)', async () => { |
| 94 | const srcDir = path.join(testVault, 'src-mixed-md-ext'); |
| 95 | fs.mkdirSync(path.join(srcDir, 'nested'), { recursive: true }); |
| 96 | fs.writeFileSync(path.join(srcDir, 'nested', 'Note.MD'), '# From upper\n', 'utf8'); |
| 97 | fs.writeFileSync(path.join(srcDir, 'readme.markdown'), '# Readme markdown ext\n', 'utf8'); |
| 98 | const ctx = { |
| 99 | vaultPath: testVault, |
| 100 | outputBase: 'imports/mixed-ext', |
| 101 | project: null, |
| 102 | tags: [], |
| 103 | dryRun: false, |
| 104 | }; |
| 105 | const result = await importMarkdown(srcDir, ctx); |
| 106 | assert.strictEqual(result.count, 2); |
| 107 | const basenames = result.imported.map((x) => path.basename(x.path)).sort(); |
| 108 | assert.deepStrictEqual(basenames, ['Note.MD', 'readme.markdown']); |
| 109 | }); |
| 110 | }); |
File History
2 commits
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd
feat(calendar): enforce agent context tiers in retrieval AP…
Human
minor
⚠
1 day ago
sha256:9103f98c89257ed2b01c237cea895dabb3e85ea337dccb1161c175e4422355b6
docs: accept Calendar Events v0 spec with Phase 0 security …
Human
1 day ago