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)
101 lines
3.0 KiB
TypeScript
101 lines
3.0 KiB
TypeScript
// E2E-Test fuer Ingest mit Mock-Modus
|
|
// Phase 2.3
|
|
|
|
import { describe, it, expect, afterEach } from 'vitest';
|
|
import { execSync } from 'node:child_process';
|
|
import { mkdtempSync, writeFileSync, mkdirSync, readFileSync, existsSync, rmSync, copyFileSync, readdirSync } from 'node:fs';
|
|
import { tmpdir } from 'node:os';
|
|
import { join } from 'node:path';
|
|
|
|
const TOOL = 'C:/GitHub/Mind-o-Mat';
|
|
const CLI = `node ${TOOL}/bin/mindomat.mjs`;
|
|
|
|
function setupTestVault(): string {
|
|
const vault = mkdtempSync(join(tmpdir(), 'mindomat-ingest-e2e-'));
|
|
const dirs = [
|
|
'00_Inbox', '00_Inbox/Verarbeitet', '00_Inbox/Problemfaelle',
|
|
'01_Daily', '10_Wiki', '10_Wiki/Seiten',
|
|
'20_Projekte', '90_Templates',
|
|
'99_System', '99_System/Skripte', '99_System/Logs', '99_System/Cache',
|
|
];
|
|
for (const d of dirs) {
|
|
mkdirSync(join(vault, d), { recursive: true });
|
|
}
|
|
|
|
// Konfig
|
|
writeFileSync(join(vault, '99_System', 'Konfig.md'),
|
|
`---
|
|
veraltet_schwellwert_monate: 12
|
|
ki_provider: minimax
|
|
ki_modell: MiniMax-M3
|
|
ki_api_url: https://api.minimaxi.chat/v1
|
|
ki_api_key_env: MINIMAX_API_KEY
|
|
---
|
|
`);
|
|
|
|
// Schema
|
|
copyFileSync(join(TOOL, 'src/templates/_Schema.md'), join(vault, '10_Wiki/_Schema.md'));
|
|
|
|
return vault;
|
|
}
|
|
|
|
describe('Ingest E2E mit --mock', () => {
|
|
const vaults: string[] = [];
|
|
|
|
afterEach(() => {
|
|
for (const v of vaults) {
|
|
rmSync(v, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
it('erstellt Wiki-Seite aus Inbox-Notiz', () => {
|
|
const vault = setupTestVault();
|
|
vaults.push(vault);
|
|
|
|
const today = new Date().toISOString().slice(0, 10);
|
|
writeFileSync(join(vault, '00_Inbox', `${today}_Kaffee_Ritual.md`),
|
|
`---
|
|
title: Kaffee_Ritual
|
|
created: ${today}
|
|
tags: [Gewohnheit]
|
|
---
|
|
|
|
# Kaffee Ritual
|
|
|
|
Jeden Morgen Kaffee, schwarz, aus der Handmuehle.
|
|
`);
|
|
|
|
execSync(`${CLI} ingest --vault "${vault}" --mock`, { stdio: 'pipe' });
|
|
|
|
// Wiki wurde erstellt
|
|
const wikiPath = join(vault, '10_Wiki', 'Seiten', `${today}_Kaffee_Ritual.md`);
|
|
expect(existsSync(wikiPath)).toBe(true);
|
|
|
|
// Frontmatter pruefen
|
|
const wiki = readFileSync(wikiPath, 'utf-8');
|
|
expect(wiki).toContain('type: wiki');
|
|
expect(wiki).toContain('status: aktuell');
|
|
expect(wiki).toContain('konflikt_hart: false');
|
|
expect(wiki).toContain('konflikt_wert: false');
|
|
expect(wiki).toContain('konflikt_logisch: false');
|
|
expect(wiki).toContain(`"[[${today}_Kaffee_Ritual]]"`);
|
|
|
|
// Original wurde nach Verarbeitet/ verschoben
|
|
const verarbeitetDir = join(vault, '00_Inbox', 'Verarbeitet', today);
|
|
expect(existsSync(join(verarbeitetDir, `${today}_Kaffee_Ritual.md`))).toBe(true);
|
|
expect(existsSync(join(vault, '00_Inbox', `${today}_Kaffee_Ritual.md`))).toBe(false);
|
|
});
|
|
|
|
it('Inbox ist leer nach Ingest', () => {
|
|
const vault = setupTestVault();
|
|
vaults.push(vault);
|
|
|
|
execSync(`${CLI} ingest --vault "${vault}" --mock`, { stdio: 'pipe' });
|
|
|
|
// Inbox hat nur die Original-Dateien nicht mehr
|
|
const inbox = readdirSync(join(vault, '00_Inbox'));
|
|
const notes = inbox.filter((f) => f.endsWith('.md'));
|
|
expect(notes).toEqual([]);
|
|
});
|
|
});
|