feat: parser sortie apt-get -s full-upgrade -> AptPackage[]
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,11 @@
|
|||||||
|
Reading package lists...
|
||||||
|
Building dependency tree...
|
||||||
|
Reading state information...
|
||||||
|
Calculating upgrade...
|
||||||
|
The following packages will be upgraded:
|
||||||
|
libc6 pve-manager
|
||||||
|
Inst libc6 [2.31-13] (2.31-13+deb11u5 Debian:11.6/stable [amd64])
|
||||||
|
Inst pve-manager [8.4-1] (8.4-3 Proxmox VE:8.x [amd64])
|
||||||
|
Inst newpkg (1.0.0 Debian:11.6/stable [all])
|
||||||
|
Conf libc6 (2.31-13+deb11u5 Debian:11.6/stable [amd64])
|
||||||
|
Conf pve-manager (8.4-3 Proxmox VE:8.x [amd64])
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
// server/services/aptParse.test.ts
|
||||||
|
import { describe, it, expect } from "vitest";
|
||||||
|
import { readFileSync } from "node:fs";
|
||||||
|
import { fileURLToPath } from "node:url";
|
||||||
|
import { parseAptSimulate, parseRebootRequired } from "./aptParse.js";
|
||||||
|
|
||||||
|
const raw = readFileSync(fileURLToPath(new URL("./__fixtures__/apt-simulate.txt", import.meta.url)), "utf8");
|
||||||
|
|
||||||
|
describe("parseAptSimulate", () => {
|
||||||
|
it("extrait les paquets upgradables avec versions et origine", () => {
|
||||||
|
const pkgs = parseAptSimulate(raw);
|
||||||
|
expect(pkgs).toEqual([
|
||||||
|
{ name: "libc6", currentVersion: "2.31-13", targetVersion: "2.31-13+deb11u5", origin: "Debian:11.6/stable" },
|
||||||
|
{ name: "pve-manager", currentVersion: "8.4-1", targetVersion: "8.4-3", origin: "Proxmox VE:8.x" },
|
||||||
|
{ name: "newpkg", currentVersion: null, targetVersion: "1.0.0", origin: "Debian:11.6/stable" },
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("retourne un tableau vide quand aucun Inst", () => {
|
||||||
|
expect(parseAptSimulate("Reading package lists...\nDone")).toEqual([]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("parseRebootRequired", () => {
|
||||||
|
it("détecte le marqueur REBOOT_REQUIRED=1", () => {
|
||||||
|
expect(parseRebootRequired("REBOOT_REQUIRED=1")).toBe(true);
|
||||||
|
expect(parseRebootRequired("REBOOT_REQUIRED=0")).toBe(false);
|
||||||
|
expect(parseRebootRequired("rien")).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
// server/services/aptParse.ts
|
||||||
|
import type { AptPackage } from "@shared/types.js";
|
||||||
|
|
||||||
|
// Exemple de ligne:
|
||||||
|
// Inst pve-manager [8.4-1] (8.4-3 Proxmox VE:8.x [amd64])
|
||||||
|
// Inst newpkg (1.0.0 Debian:11.6/stable [all])
|
||||||
|
const INST_RE = /^Inst (\S+) (?:\[([^\]]+)\] )?\((\S+) (.+?) \[[^\]]+\]\)\s*$/;
|
||||||
|
|
||||||
|
export function parseAptSimulate(raw: string): AptPackage[] {
|
||||||
|
const out: AptPackage[] = [];
|
||||||
|
for (const line of raw.split("\n")) {
|
||||||
|
const m = INST_RE.exec(line.trimEnd());
|
||||||
|
if (!m) continue;
|
||||||
|
out.push({
|
||||||
|
name: m[1]!,
|
||||||
|
currentVersion: m[2] ?? null,
|
||||||
|
targetVersion: m[3]!,
|
||||||
|
origin: (m[4] ?? "").trim() || null,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function parseRebootRequired(raw: string): boolean {
|
||||||
|
return /REBOOT_REQUIRED=1/.test(raw);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user