Phase 6 (Bonus): Watcher-Mode (--watch): - src/cli/ingest.ts: --watch Flag parsed - watchInbox(): chokidar-basiert (robuster als node:fs.watch auf Windows) Debounce 1s, awaitWriteFinish, ignoreInitial, filter Verarbeitet/Problemfaelle Auf Ctrl+C wird sauber beendet - Bug-Fix: 'return' bei files.length===0 war vor dem Watch-Block -> bei leerer Inbox mit --watch startet Watcher trotzdem ESLint + Prettier: - .eslintrc.cjs (deprecated eslintrc-Format, USE_FLAT_CONFIG=false) - .prettierrc mit Standard-Format - package.json scripts: lint, format, format:check - Lint-Fehler in Tests gefixt (try/catch, unused imports) npm audit fix --force: - esbuild 0.24.2 -> neuere Version (via Vite-Update) - vite, vitest auf v5 (breaking change akzeptiert) - 5 vulnerabilities -> 0 Verifiziert: - 50/50 Tests gruen - Watcher E2E: Notiz in 00_Inbox/ waehrend --watch -> Wiki erstellt, verarbeitet - Lint: 0 Fehler (nur Deprecation-Warnung fuer eslintrc-Format) Dependencies: chokidar (neu)
115 lines
3.1 KiB
TypeScript
115 lines
3.1 KiB
TypeScript
// Unit-Tests für 1.2 Vault-Pfad-Discovery
|
|
// Phase 1.2 Test
|
|
|
|
import { describe, it, expect } from 'vitest';
|
|
import { resolveVaultPath, assertVaultExists, VaultPathError } from '../src/vault-path.js';
|
|
import { mkdtempSync, rmSync } from 'node:fs';
|
|
import { tmpdir } from 'node:os';
|
|
import { join } from 'node:path';
|
|
|
|
describe('resolveVaultPath', () => {
|
|
const cwd = process.cwd();
|
|
|
|
it('liest --vault <pfad> aus CLI-Args', () => {
|
|
const result = resolveVaultPath({
|
|
args: ['--vault', 'C:\\foo'],
|
|
env: {},
|
|
cwd,
|
|
});
|
|
expect(result.path).toBe('C:\\foo');
|
|
expect(result.source).toBe('cli');
|
|
});
|
|
|
|
it('liest -v <pfad> Kurzform', () => {
|
|
const result = resolveVaultPath({
|
|
args: ['-v', 'C:\\bar'],
|
|
env: {},
|
|
cwd,
|
|
});
|
|
expect(result.path).toBe('C:\\bar');
|
|
expect(result.source).toBe('cli');
|
|
});
|
|
|
|
it('liest --vault=<pfad> Gleichheits-Form', () => {
|
|
const result = resolveVaultPath({
|
|
args: ['--vault=C:\\baz'],
|
|
env: {},
|
|
cwd,
|
|
});
|
|
expect(result.path).toBe('C:\\baz');
|
|
expect(result.source).toBe('cli');
|
|
});
|
|
|
|
it('faellt zurück auf MINDOMAT_VAULT_PATH, wenn keine CLI-Arg', () => {
|
|
const result = resolveVaultPath({
|
|
args: [],
|
|
env: { MINDOMAT_VAULT_PATH: 'C:\\env-vault' },
|
|
cwd,
|
|
});
|
|
expect(result.path).toBe('C:\\env-vault');
|
|
expect(result.source).toBe('env');
|
|
});
|
|
|
|
it('CLI-Arg ueberschreibt Env-Var', () => {
|
|
const result = resolveVaultPath({
|
|
args: ['--vault', 'C:\\cli-wins'],
|
|
env: { MINDOMAT_VAULT_PATH: 'C:\\env-loses' },
|
|
cwd,
|
|
});
|
|
expect(result.path).toBe('C:\\cli-wins');
|
|
expect(result.source).toBe('cli');
|
|
});
|
|
|
|
it('wirft VaultPathError MISSING, wenn weder CLI noch Env', () => {
|
|
expect(() => resolveVaultPath({
|
|
args: [],
|
|
env: {},
|
|
cwd,
|
|
})).toThrow(VaultPathError);
|
|
try {
|
|
resolveVaultPath({ args: [], env: {}, cwd });
|
|
} catch (err) {
|
|
expect(err).toBeInstanceOf(VaultPathError);
|
|
expect((err as VaultPathError).code).toBe('MISSING');
|
|
}
|
|
});
|
|
|
|
it('wirft VaultPathError MISSING, wenn Env-Var leer', () => {
|
|
expect(() => resolveVaultPath({
|
|
args: [],
|
|
env: { MINDOMAT_VAULT_PATH: ' ' },
|
|
cwd,
|
|
})).toThrow(VaultPathError);
|
|
});
|
|
|
|
it('loest relative Pfade gegen cwd auf', () => {
|
|
const result = resolveVaultPath({
|
|
args: ['--vault', 'relativ'],
|
|
env: {},
|
|
cwd: 'C:\\base',
|
|
});
|
|
// Windows-spezifisch: join mit Backslashes
|
|
expect(result.path).toMatch(/relativ/);
|
|
expect(result.path).toMatch(/C:\\base/);
|
|
});
|
|
});
|
|
|
|
describe('assertVaultExists', () => {
|
|
let tmpDir: string;
|
|
|
|
it('laesst existierende Verzeichnisse durch', () => {
|
|
tmpDir = mkdtempSync(join(tmpdir(), 'mindomat-test-'));
|
|
expect(() => assertVaultExists(tmpDir)).not.toThrow();
|
|
rmSync(tmpDir, { recursive: true, force: true });
|
|
});
|
|
|
|
it('wirft NOT_FOUND fuer nicht existierende Pfade', () => {
|
|
try {
|
|
assertVaultExists('C:\\gibt-es-nicht\\garantiert\\nicht');
|
|
} catch (err) {
|
|
expect(err).toBeInstanceOf(VaultPathError);
|
|
expect((err as VaultPathError).code).toBe('NOT_FOUND');
|
|
}
|
|
});
|
|
});
|