feat: réducteur déterministe de lignes APT
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
// server/templates/aptReduce.test.ts
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { reduceAptLines } from "./aptReduce.js";
|
||||
|
||||
describe("reduceAptLines", () => {
|
||||
it("ne garde que les lignes utiles", () => {
|
||||
const raw = [
|
||||
"Reading package lists...",
|
||||
"Building dependency tree...",
|
||||
"Inst pve-manager [8.4-1] (8.4-3 Proxmox VE:8.x [amd64])",
|
||||
"blabla inutile",
|
||||
"Conf pve-manager (8.4-3 Proxmox VE:8.x [amd64])",
|
||||
"E: Could not get lock",
|
||||
"W: Some warning",
|
||||
"dpkg: warning: x",
|
||||
].join("\n");
|
||||
expect(reduceAptLines(raw)).toEqual([
|
||||
"Inst pve-manager [8.4-1] (8.4-3 Proxmox VE:8.x [amd64])",
|
||||
"Conf pve-manager (8.4-3 Proxmox VE:8.x [amd64])",
|
||||
"E: Could not get lock",
|
||||
"W: Some warning",
|
||||
"dpkg: warning: x",
|
||||
]);
|
||||
});
|
||||
|
||||
it("retourne un tableau vide si rien d'utile", () => {
|
||||
expect(reduceAptLines("Reading package lists...\nDone")).toEqual([]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
// server/templates/aptReduce.ts
|
||||
const PREFIXES = ["Inst ", "Conf ", "Remv ", "Err ", "E:", "W:", "dpkg:"];
|
||||
const CONTAINS = ["reboot-required", "REBOOT_REQUIRED"];
|
||||
|
||||
/** Garde uniquement les lignes informatives d'une sortie APT brute. */
|
||||
export function reduceAptLines(raw: string): string[] {
|
||||
return raw
|
||||
.split("\n")
|
||||
.map((l) => l.trimEnd())
|
||||
.filter((l) => PREFIXES.some((p) => l.startsWith(p)) || CONTAINS.some((c) => l.includes(c)));
|
||||
}
|
||||
Reference in New Issue
Block a user