import { describe, it, expect, beforeEach, afterEach } from 'vitest'; import { GitOpsService } from '../src/services/gitops.service.js'; import os from 'os'; import path from 'path'; import fs from 'fs/promises'; describe('GitOpsService', () => { let gitops: GitOpsService; let testRepoDir: string; beforeEach(async () => { testRepoDir = path.join(os.tmpdir(), `naxos-gitops-test-${Date.now()}-${Math.random().toString(36).slice(2)}`); gitops = new GitOpsService(testRepoDir); await gitops.init(); }); afterEach(async () => { try { await fs.rm(testRepoDir, { recursive: true, force: true }); } catch {} }); it('should initialize and produce valid GitOps status', async () => { const status = await gitops.getStatus(); expect(status.enabled).toBe(true); expect(status.branch).toBe('main'); expect(status.lastCommitSha).toBeDefined(); }); it('should translate declarative configuration into valid NixOS module code', async () => { const nixCode = await gitops.renderNixOSModule(); expect(nixCode).toContain('services.naxos.storage'); expect(nixCode).toContain('services.naxos.shares.samba'); expect(nixCode).toContain('importExistingPools'); expect(nixCode).toContain('tank'); }); it('should create commits on state changes', async () => { const res = await gitops.updateConfig( { core: { hostname: 'naxos-test', timezone: 'UTC' }, }, 'feat(test): updated hostname' ); expect(res.commitSha).toBeDefined(); expect(res.commitSha.length).toBeGreaterThan(10); const commits = await gitops.getCommits(5); expect(commits[0].message).toBe('feat(test): updated hostname'); }); });