feat: service machines (CRUD, test-connection, détection OS)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-05 04:03:51 +02:00
parent 0e8d5a9bcf
commit 3724326d81
2 changed files with 130 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
// server/services/machines.test.ts
import { describe, it, expect, vi } from "vitest";
// Mock all modules with side-effects at import time (DB, SSH, crypto)
vi.mock("../db/client.js", () => ({ db: {}, schema: { machines: {} } }));
vi.mock("../crypto/secrets.js", () => ({ encryptSecret: vi.fn(), decryptSecret: vi.fn() }));
vi.mock("../env.js", () => ({ env: { requireMasterKey: vi.fn(), reportsDir: "/tmp" } }));
vi.mock("../ssh/client.js", () => ({ runPlain: vi.fn() }));
import { parseOsRelease } from "./machines.js";
describe("parseOsRelease", () => {
it("détecte Debian", () => {
const r = parseOsRelease('ID=debian\nVERSION_ID="11"\nPRETTY_NAME="Debian 11"');
expect(r).toEqual({ family: "debian", version: "11" });
});
it("détecte Ubuntu", () => {
const r = parseOsRelease('ID=ubuntu\nVERSION_ID="22.04"');
expect(r).toEqual({ family: "ubuntu", version: "22.04" });
});
it("retombe sur unknown", () => {
expect(parseOsRelease("ID=arch").family).toBe("unknown");
});
});