import-source-types.test.mjs
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd
feat(calendar): enforce agent context tiers in retrieval AP…
Human
minor
⚠ breaking
1 day ago
| 1 | /** |
| 2 | * Import source types: CLI/core reject unknown types; each known type reaches an importer. |
| 3 | */ |
| 4 | import { describe, it } 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 { IMPORT_SOURCE_TYPES } from '../lib/import-source-types.mjs'; |
| 10 | import { runImport } from '../lib/import.mjs'; |
| 11 | |
| 12 | const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
| 13 | const scratchVault = path.join(__dirname, 'fixtures', 'tmp-import-source-types-vault'); |
| 14 | |
| 15 | describe('import source types', () => { |
| 16 | it('pdf rejects empty input path', async () => { |
| 17 | await assert.rejects( |
| 18 | async () => { |
| 19 | await runImport('pdf', '', { vaultPath: scratchVault, dryRun: true }); |
| 20 | }, |
| 21 | /PDF path is required/ |
| 22 | ); |
| 23 | }); |
| 24 | |
| 25 | it('docx rejects empty input path', async () => { |
| 26 | await assert.rejects( |
| 27 | async () => { |
| 28 | await runImport('docx', '', { vaultPath: scratchVault, dryRun: true }); |
| 29 | }, |
| 30 | /DOCX path is required/ |
| 31 | ); |
| 32 | }); |
| 33 | |
| 34 | it('docx rejects non-docx extension', async () => { |
| 35 | const fake = path.join(scratchVault, 'not-word.txt'); |
| 36 | if (!fs.existsSync(scratchVault)) fs.mkdirSync(scratchVault, { recursive: true }); |
| 37 | fs.writeFileSync(fake, 'x', 'utf8'); |
| 38 | await assert.rejects( |
| 39 | async () => { |
| 40 | await runImport('docx', fake, { vaultPath: scratchVault, dryRun: true }); |
| 41 | }, |
| 42 | /DOCX import requires a \.docx file/ |
| 43 | ); |
| 44 | }); |
| 45 | |
| 46 | it('rejects unknown source type before loadConfig-sensitive work', async () => { |
| 47 | await assert.rejects( |
| 48 | () => runImport('typo-not-a-source', '/any/path', { vaultPath: scratchVault }), |
| 49 | /Unknown source type: typo-not-a-source/ |
| 50 | ); |
| 51 | }); |
| 52 | |
| 53 | it('each IMPORT_SOURCE_TYPES value is accepted by runImport (importer-specific error for bad input)', async () => { |
| 54 | if (!fs.existsSync(scratchVault)) fs.mkdirSync(scratchVault, { recursive: true }); |
| 55 | const missing = path.join(scratchVault, 'definitely-missing-input-xyz'); |
| 56 | for (const sourceType of IMPORT_SOURCE_TYPES) { |
| 57 | const badInput = sourceType === 'url' ? 'not-a-valid-url' : missing; |
| 58 | await assert.rejects( |
| 59 | async () => { |
| 60 | await runImport(sourceType, badInput, { vaultPath: scratchVault, dryRun: true }); |
| 61 | }, |
| 62 | (err) => { |
| 63 | assert( |
| 64 | err && typeof err.message === 'string', |
| 65 | `expected error for ${sourceType}` |
| 66 | ); |
| 67 | assert.ok( |
| 68 | !err.message.includes('Unknown source type'), |
| 69 | `${sourceType} should not fail as unknown type: ${err.message}` |
| 70 | ); |
| 71 | return true; |
| 72 | }, |
| 73 | `source type ${sourceType} should reach importer` |
| 74 | ); |
| 75 | } |
| 76 | }); |
| 77 | }); |
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