import-source-types.test.mjs
77 lines 2.7 KB
Raw
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf mirror: GitHub Phase A durable MCP OAuth (#270) Human minor ⚠ breaking 11 days 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 4 commits
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf mirror: GitHub Phase A durable MCP OAuth (#270) Human minor 11 days ago
sha256:d8c648b20a4d53b2673c5c082ee7edfa7b2fc9b11080832da1f38807b6bf940b fix(7C-L1b): route hosted delegation proposals through cani… Human minor 31 days ago
sha256:2827ba9e7632a4b141c50caf1e8f7d77abbc3515be20e7465f2bccb0ac4edf91 fix: repair endpoint now sets has_active_subscription when … Human minor 51 days ago