attachment-store-stress.test.mjs
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf
mirror: GitHub Phase A durable MCP OAuth (#270)
Human
minor
⚠ breaking
10 days ago
| 1 | /** |
| 2 | * Tier 4 — STRESS: list cap at MAX_ATTACHMENT_SUMMARIES. |
| 3 | * |
| 4 | * @see docs/ATTACHMENT-STORE-CONTRACT-2F-b.md §9 |
| 5 | */ |
| 6 | import { describe, it, beforeEach, afterEach } from 'node:test'; |
| 7 | import assert from 'node:assert/strict'; |
| 8 | import fs from 'node:fs'; |
| 9 | import path from 'node:path'; |
| 10 | import { fileURLToPath } from 'node:url'; |
| 11 | import { listAttachments, MAX_ATTACHMENT_SUMMARIES } from '../lib/attachments/attachment-store.mjs'; |
| 12 | |
| 13 | const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
| 14 | const tmpRoot = path.join(__dirname, 'fixtures', 'tmp-attachment-stress'); |
| 15 | |
| 16 | describe('Attachment store — stress', () => { |
| 17 | const dataDir = path.join(tmpRoot, 'data'); |
| 18 | const vaultPath = path.join(tmpRoot, 'vault'); |
| 19 | const vaultId = 'default'; |
| 20 | |
| 21 | beforeEach(() => { |
| 22 | fs.rmSync(tmpRoot, { recursive: true, force: true }); |
| 23 | fs.mkdirSync(path.join(vaultPath, 'media'), { recursive: true }); |
| 24 | fs.mkdirSync(dataDir, { recursive: true }); |
| 25 | |
| 26 | for (let i = 0; i < MAX_ATTACHMENT_SUMMARIES + 5; i += 1) { |
| 27 | fs.writeFileSync(path.join(vaultPath, 'media', `file_${String(i).padStart(5, '0')}.png`), 'x'); |
| 28 | } |
| 29 | |
| 30 | fs.mkdirSync(path.join(vaultPath, 'notes'), { recursive: true }); |
| 31 | let body = ''; |
| 32 | for (let i = 0; i < 20; i += 1) { |
| 33 | body += `\n\n`; |
| 34 | } |
| 35 | fs.writeFileSync(path.join(vaultPath, 'notes', 'many-urls.md'), body); |
| 36 | }); |
| 37 | |
| 38 | afterEach(() => { |
| 39 | fs.rmSync(tmpRoot, { recursive: true, force: true }); |
| 40 | }); |
| 41 | |
| 42 | it('list returns capped rows with truncated:true when over limit', () => { |
| 43 | const result = listAttachments(dataDir, vaultPath, vaultId, { |
| 44 | filterScopes: new Set(['personal', 'project', 'org']), |
| 45 | effectiveScope: 'org', |
| 46 | limit: MAX_ATTACHMENT_SUMMARIES, |
| 47 | }); |
| 48 | assert.equal(result.attachments.length, MAX_ATTACHMENT_SUMMARIES); |
| 49 | assert.equal(result.truncated, true); |
| 50 | }); |
| 51 | |
| 52 | it('many notes × embedded URLs stays linear (completes under budget)', () => { |
| 53 | const t0 = performance.now(); |
| 54 | listAttachments(dataDir, vaultPath, vaultId, { |
| 55 | filterScopes: new Set(['personal', 'project', 'org']), |
| 56 | effectiveScope: 'org', |
| 57 | limit: MAX_ATTACHMENT_SUMMARIES, |
| 58 | }); |
| 59 | assert.ok(performance.now() - t0 < 5000); |
| 60 | }); |
| 61 | }); |
File History
1 commit
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf
mirror: GitHub Phase A durable MCP OAuth (#270)
Human
minor
⚠
10 days ago