import { describe, it, expect, beforeEach, afterEach } from 'vitest'; import { mkdtempSync, rmSync, existsSync } from 'fs'; import { tmpdir } from 'os'; import { join } from 'path'; import { writeEntity, readEntity } from '../src/core/files.js'; describe('files', () => { let cwd: string; beforeEach(() => { cwd = mkdtempSync(join(tmpdir(), 'agenthub-')); }); afterEach(() => { rmSync(cwd, { recursive: true, force: true }); }); it('writes and reads a markdown entity', () => { const filePath = join(cwd, 'test.md'); const frontmatter = { id: 'TSK-0001', title: 'Test' }; const body = '# Test\n\nHello'; writeEntity(filePath, frontmatter, body); const result = readEntity(filePath); expect(result.frontmatter.id).toBe('TSK-0001'); expect(result.body.trim()).toBe('# Test\n\nHello'); expect(existsSync(filePath)).toBe(true); }); });