Files
Mind-o-Mat/tests/determinism.test.ts
T
Jannik f2e8e59baf
CI / test (push) Canceled after 0s
CI / webapp (push) Canceled after 0s
v2.0.2: Watcher-Mode + Watch-Bug-Fix + Lint-Setup + Audit-Fix
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)
2026-09-05 12:29:48 +02:00

96 lines
2.8 KiB
TypeScript

// Deterministik-Test: zwei Indexer-Laeufe ergeben byte-identische Outputs
// Phase 1.5
import { describe, it, expect } from 'vitest';
import { execSync } from 'node:child_process';
import { readFileSync, mkdtempSync, writeFileSync, mkdirSync, rmSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
const TOOL_PATH = 'C:/GitHub/Mind-o-Mat';
const CLI = `node ${TOOL_PATH}/bin/mindomat.mjs`;
function createTestVault(): string {
const dir = mkdtempSync(join(tmpdir(), 'mindomat-determinism-'));
// 12 Ordner
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(dir, d), { recursive: true });
}
// 3 Test-Notizen mit deterministischen Wikilinks
writeFileSync(join(dir, '00_Inbox', '2026-01-01_A.md'), `---
title: A
created: 2026-01-01
---
# A
Verweist auf [[B]] und [[C]].
`);
writeFileSync(join(dir, '00_Inbox', '2026-01-02_B.md'), `---
title: B
created: 2026-01-02
---
# B
Verweist auf [[A]].
`);
writeFileSync(join(dir, '00_Inbox', '2026-01-03_C.md'), `---
title: C
created: 2026-01-03
---
# C
Kein Link.
`);
return dir;
}
describe('Indexer Determinismus', () => {
it('zwei Laeufe ergeben byte-identische Outputs', () => {
const vault = createTestVault();
try {
// Erster Lauf
execSync(`${CLI} index --vault "${vault}" --no-interactive`, { stdio: 'pipe' });
const l1 = readFileSync(join(vault, 'landkarte.json'), 'utf-8');
const i1sys = readFileSync(join(vault, '99_System', 'Index.md'), 'utf-8');
const i1wiki = readFileSync(join(vault, '10_Wiki', 'Index.md'), 'utf-8');
// Zweiter Lauf
execSync(`${CLI} index --vault "${vault}" --no-interactive`, { stdio: 'pipe' });
const l2 = readFileSync(join(vault, 'landkarte.json'), 'utf-8');
const i2sys = readFileSync(join(vault, '99_System', 'Index.md'), 'utf-8');
const i2wiki = readFileSync(join(vault, '10_Wiki', 'Index.md'), 'utf-8');
expect(l2).toBe(l1);
expect(i2sys).toBe(i1sys);
expect(i2wiki).toBe(i1wiki);
} finally {
rmSync(vault, { recursive: true, force: true });
}
});
it('landkarte.json enthaelt alle Notizen + Edges', () => {
const vault = createTestVault();
try {
execSync(`${CLI} index --vault "${vault}" --no-interactive`, { stdio: 'pipe' });
const landkarte = JSON.parse(readFileSync(join(vault, 'landkarte.json'), 'utf-8'));
expect(landkarte.nodes.length).toBe(3);
// A->B, A->C, B->A = 3 Edges
expect(landkarte.edges.length).toBe(3);
} finally {
rmSync(vault, { recursive: true, force: true });
}
});
});