hub-bulk-metadata.test.mjs
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd
feat(calendar): enforce agent context tiers in retrieval AP…
Human
minor
⚠ breaking
2 days ago
| 1 | /** |
| 2 | * Bulk delete/rename by project slug (Node Hub helpers). |
| 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 { writeNote } from '../lib/write.mjs'; |
| 10 | import { readNote } from '../lib/vault.mjs'; |
| 11 | import { deleteNotesByProjectSlug, renameProjectSlugInVault } from '../lib/hub-bulk-metadata.mjs'; |
| 12 | |
| 13 | const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
| 14 | const testVault = path.join(__dirname, 'fixtures', 'tmp-bulk-meta-vault'); |
| 15 | |
| 16 | describe('hub-bulk-metadata', () => { |
| 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('deleteNotesByProjectSlug removes notes matching project frontmatter', () => { |
| 31 | writeNote(testVault, 'inbox/a.md', { body: 'a', frontmatter: { project: 'acme', title: 'A' } }); |
| 32 | writeNote(testVault, 'inbox/b.md', { body: 'b', frontmatter: { project: 'other', title: 'B' } }); |
| 33 | const { deleted, paths } = deleteNotesByProjectSlug(testVault, 'acme'); |
| 34 | assert.strictEqual(deleted, 1); |
| 35 | assert.strictEqual(paths.length, 1); |
| 36 | assert(paths.includes('inbox/a.md')); |
| 37 | assert.throws(() => readNote(testVault, 'inbox/a.md'), /not found/); |
| 38 | const kept = readNote(testVault, 'inbox/b.md'); |
| 39 | assert.strictEqual(kept.body.trim(), 'b'); |
| 40 | }); |
| 41 | |
| 42 | it('renameProjectSlugInVault updates frontmatter project slug', () => { |
| 43 | writeNote(testVault, 'inbox/r1.md', { body: 'x', frontmatter: { project: 'oldp', title: 'T' } }); |
| 44 | writeNote(testVault, 'inbox/r2.md', { body: 'y', frontmatter: { project: 'oldp' } }); |
| 45 | const { updated, paths } = renameProjectSlugInVault(testVault, 'oldp', 'newp'); |
| 46 | assert.strictEqual(updated, 2); |
| 47 | assert.strictEqual(paths.length, 2); |
| 48 | const n1 = readNote(testVault, 'inbox/r1.md'); |
| 49 | assert.strictEqual(n1.project, 'newp'); |
| 50 | const n2 = readNote(testVault, 'inbox/r2.md'); |
| 51 | assert.strictEqual(n2.project, 'newp'); |
| 52 | }); |
| 53 | |
| 54 | it('deleteNotesByProjectSlug throws when project empty', () => { |
| 55 | assert.throws(() => deleteNotesByProjectSlug(testVault, ' '), /project slug required/); |
| 56 | }); |
| 57 | |
| 58 | it('deleteNotesByProjectSlug matches path-inferred project under projects/<slug>/', () => { |
| 59 | writeNote(testVault, 'projects/pathonly/inbox/z.md', { body: 'z', frontmatter: { title: 'Z' } }); |
| 60 | const { deleted, paths } = deleteNotesByProjectSlug(testVault, 'pathonly'); |
| 61 | assert.strictEqual(deleted, 1); |
| 62 | assert(paths.includes('projects/pathonly/inbox/z.md')); |
| 63 | }); |
| 64 | }); |
File History
2 commits
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd
feat(calendar): enforce agent context tiers in retrieval AP…
Human
minor
⚠
2 days ago
sha256:9103f98c89257ed2b01c237cea895dabb3e85ea337dccb1161c175e4422355b6
docs: accept Calendar Events v0 spec with Phase 0 security …
Human
2 days ago