From ed3cb91cd4b226b03a90a389525abcf081bd8102 Mon Sep 17 00:00:00 2001 From: Gilles Soulier Date: Fri, 5 Jun 2026 04:05:23 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20g=C3=A9n=C3=A9ration=20de=20rapport=20M?= =?UTF-8?q?arkdown=20d'ex=C3=A9cution?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.8 --- server/services/report.test.ts | 22 ++++++++++++++++++++++ server/services/report.ts | 25 +++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 server/services/report.test.ts create mode 100644 server/services/report.ts diff --git a/server/services/report.test.ts b/server/services/report.test.ts new file mode 100644 index 0000000..9b3b9c5 --- /dev/null +++ b/server/services/report.test.ts @@ -0,0 +1,22 @@ +// server/services/report.test.ts +import { describe, it, expect } from "vitest"; +import { buildReportMarkdown } from "./report.js"; +import type { ExecutionResult } from "@shared/types.js"; + +const exec: ExecutionResult = { + executionId: "exec_1", machineId: "m1", startedAt: "2026-06-04T12:00:00Z", + finishedAt: "2026-06-04T12:05:00Z", mode: "manual", action: "apt_full_upgrade", + status: "ok", rebootRequiredAfterRun: true, + importantLogLines: ["Inst libc6 [2.31-13] (2.31-13+deb11u5 Debian [amd64])"], + rawLogRef: "reports/m1/exec_1.log", reportRef: "reports/m1/exec_1.md", +}; + +describe("buildReportMarkdown", () => { + it("contient l'en-tête, le statut et les lignes importantes", () => { + const md = buildReportMarkdown(exec, "deb-01"); + expect(md).toContain("# Rapport d'exécution — deb-01"); + expect(md).toContain("apt_full_upgrade"); + expect(md).toContain("Redémarrage requis : oui"); + expect(md).toContain("Inst libc6"); + }); +}); diff --git a/server/services/report.ts b/server/services/report.ts new file mode 100644 index 0000000..4f397fe --- /dev/null +++ b/server/services/report.ts @@ -0,0 +1,25 @@ +// server/services/report.ts +import type { ExecutionResult } from "@shared/types.js"; + +export function buildReportMarkdown(exec: ExecutionResult, machineName: string): string { + const lines = exec.importantLogLines.map((l) => ` ${l}`).join("\n"); + return `# Rapport d'exécution — ${machineName} + +- Exécution : ${exec.executionId} +- Action : ${exec.action} +- Statut : ${exec.status} +- Début : ${exec.startedAt} +- Fin : ${exec.finishedAt} +- Redémarrage requis : ${exec.rebootRequiredAfterRun ? "oui" : "non"} + +## Lignes importantes + +\`\`\` +${lines || " (aucune)"} +\`\`\` + +## Log brut + +Référence : \`${exec.rawLogRef}\` +`; +}