Skip to content

Open-source, local-first AI agent for real work.

3.1 KB
Raw Blame
import assert from "node:assert/strict";
import { mkdtemp, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import test from "node:test";
import {
	parseDebContents,
	parseDebFields,
	parseRpmFields,
	readExpectedVersion,
	verifyLinuxPackageInspection,
} from "./verify-linux-packages.mjs";

const paths = [
	"/opt/Vetta/Vetta",
	"/opt/Vetta/resources/package-type",
	"/usr/share/applications/vetta.desktop",
	"/usr/share/icons/hicolor/512x512/apps/Vetta.png",
	"/usr/share/mime/packages/Vetta.xml",
];
const expectedVersion = "1.2.3";
const deb = { name: "vetta", version: expectedVersion, arch: "amd64", paths };
const rpm = { name: "vetta", version: expectedVersion, arch: "x86_64", paths };

test("Linux package inspection accepts matching Debian and RPM packages", () => {
	assert.doesNotThrow(() => verifyLinuxPackageInspection({ expectedVersion, deb, rpm }));
});

test("Linux package inspection rejects a wrong Debian version", () => {
	assert.throws(
		() => verifyLinuxPackageInspection({ expectedVersion, deb: { ...deb, version: "1.2.2" }, rpm }),
		/Debian version 1\.2\.2 does not match 1\.2\.3/,
	);
});

test("Linux package inspection rejects a Debian package without its MIME definition", () => {
	const mimePath = "/usr/share/mime/packages/Vetta.xml";
	const incompleteDeb = { ...deb, paths: paths.filter((path) => path !== mimePath) };
	assert.throws(() => verifyLinuxPackageInspection({ expectedVersion, deb: incompleteDeb, rpm }), {
		message: `[verify-linux-packages] Debian package is missing ${mimePath}`,
	});
});

for (const [requiredName, wrongCase, expectedError] of [
	["vetta.desktop", "Vetta.desktop", /RPM package is missing \/usr\/share\/applications\/vetta\.desktop/],
	["Vetta.png", "vetta.png", /RPM package has no Vetta hicolor icon/],
]) {
	test(`Linux package inspection rejects an RPM with ${wrongCase} instead of ${requiredName}`, () => {
		const renamedRpm = { ...rpm, paths: paths.map((path) => path.replace(requiredName, wrongCase)) };
		assert.throws(() => verifyLinuxPackageInspection({ expectedVersion, deb, rpm: renamedRpm }), expectedError);
	});
}

test("package command output parsers normalize Debian and RPM metadata", () => {
	assert.deepEqual(
		parseDebFields("Package: vetta\nVersion: 1.2.3\nArchitecture: amd64\nDescription: Vetta\n"),
		{ name: "vetta", version: "1.2.3", arch: "amd64" },
	);
	assert.deepEqual(parseRpmFields("vetta\n1.2.3\nx86_64\n"), {
		name: "vetta",
		version: "1.2.3",
		arch: "x86_64",
	});
	assert.deepEqual(
		parseDebContents(
			"-rwxr-xr-x root/root 123 2026-01-01 00:00 ./opt/Vetta/Vetta\n" +
				"lrwxrwxrwx root/root 0 2026-01-01 00:00 ./usr/bin/vetta -> /opt/Vetta/Vetta\n",
		),
		["/opt/Vetta/Vetta", "/usr/bin/vetta"],
	);
});

test("native package verification uses the release manifest version", async () => {
	const releaseDir = await mkdtemp(join(tmpdir(), "vetta-linux-packages-"));
	try {
		await writeFile(join(releaseDir, "latest-linux.yml"), "version: 9.8.7\n");
		assert.equal(await readExpectedVersion(releaseDir), "9.8.7");
	} finally {
		await rm(releaseDir, { recursive: true, force: true });
	}
});