attachment-fixture.mjs
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf
mirror: GitHub Phase A durable MCP OAuth (#270)
Human
minor
⚠ breaking
10 days ago
| 1 | /** |
| 2 | * Shared temp vault fixtures for attachment store tests. |
| 3 | */ |
| 4 | import fs from 'node:fs'; |
| 5 | import path from 'node:path'; |
| 6 | import { deriveAttachmentId, normalizeUrlForId } from '../../lib/attachments/attachment-store.mjs'; |
| 7 | |
| 8 | /** Valid Mist blob id per SPEC §2.4 / MIST_ID_RE. */ |
| 9 | export const FIXTURE_MIST_ID = '3J98t1WpEZ73'; |
| 10 | |
| 11 | /** |
| 12 | * @param {string} tmpRoot |
| 13 | * @returns {{ vaultPath: string, dataDir: string, vaultId: string, fileId: string, mistId: string, urlId: string }} |
| 14 | */ |
| 15 | export function buildAttachmentFixtureVault(tmpRoot) { |
| 16 | const vaultPath = path.join(tmpRoot, 'vault'); |
| 17 | const dataDir = path.join(tmpRoot, 'data'); |
| 18 | fs.mkdirSync(dataDir, { recursive: true }); |
| 19 | fs.mkdirSync(path.join(vaultPath, 'media'), { recursive: true }); |
| 20 | fs.mkdirSync(path.join(vaultPath, 'notes'), { recursive: true }); |
| 21 | fs.mkdirSync(path.join(vaultPath, 'projects', 'demo'), { recursive: true }); |
| 22 | |
| 23 | fs.writeFileSync(path.join(vaultPath, 'media', 'sample.png'), Buffer.from('89504e470d0a1a0a', 'hex')); |
| 24 | |
| 25 | fs.writeFileSync( |
| 26 | path.join(vaultPath, 'notes', 'mist-note.md'), |
| 27 | `--- |
| 28 | title: Mist Note |
| 29 | attachments: |
| 30 | - ${FIXTURE_MIST_ID} |
| 31 | --- |
| 32 | # Body |
| 33 | `, |
| 34 | ); |
| 35 | |
| 36 | fs.writeFileSync( |
| 37 | path.join(vaultPath, 'notes', 'url-note.md'), |
| 38 | `# URL Note |
| 39 | |
| 40 |  |
| 41 | `, |
| 42 | ); |
| 43 | |
| 44 | fs.writeFileSync( |
| 45 | path.join(vaultPath, 'projects', 'demo', 'project-photo.md'), |
| 46 | `--- |
| 47 | scope: project |
| 48 | --- |
| 49 | Project note with  |
| 50 | `, |
| 51 | ); |
| 52 | |
| 53 | const fileId = deriveAttachmentId('file', 'file:media/sample.png'); |
| 54 | const mistId = deriveAttachmentId('mist', `mist:${FIXTURE_MIST_ID}`); |
| 55 | const urlId = deriveAttachmentId( |
| 56 | 'url', |
| 57 | `url:notes/url-note.md|${normalizeUrlForId('https://cdn.example.com/assets/diagram.png')}`, |
| 58 | ); |
| 59 | |
| 60 | return { vaultPath, dataDir, vaultId: 'default', fileId, mistId, urlId }; |
| 61 | } |
File History
1 commit
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf
mirror: GitHub Phase A durable MCP OAuth (#270)
Human
minor
⚠
10 days ago