mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-27 21:07:01 -06:00
abf0ef6513
* fix(cua-computer): prove Linux X11 live vertical * test(computer-use): authenticate isolated Linux rig * fix(gateway): refresh computer use after node approval * refactor(cua-computer): resolve the plugin manifest by static import * fix(gateway): break plugin runtime import cycle * fix(computer-use): bind live rig to committed helpers
144 lines
4.7 KiB
TypeScript
144 lines
4.7 KiB
TypeScript
import { createHash } from "node:crypto";
|
|
import fs from "node:fs";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import { afterEach, describe, expect, it } from "vitest";
|
|
import { inspectCuaDriverArtifacts } from "./driver-artifact-verification.js";
|
|
|
|
const temporaryDirectories: string[] = [];
|
|
|
|
function writeJson(pathname: string, value: unknown): void {
|
|
fs.writeFileSync(pathname, `${JSON.stringify(value)}\n`, "utf8");
|
|
}
|
|
|
|
function createArtifactFixture(
|
|
options: {
|
|
platformKey?: "linux-x64-gnu" | "win32-x64-msvc";
|
|
sdkVersion?: string;
|
|
platformVersion?: string;
|
|
omitPlatformPackage?: boolean;
|
|
expectedDigest?: string;
|
|
} = {},
|
|
) {
|
|
const root = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-cua-artifacts-"));
|
|
temporaryDirectories.push(root);
|
|
const platformKey = options.platformKey ?? "linux-x64-gnu";
|
|
const acceptedVersion = "0.19.3";
|
|
const nativeFile = platformKey.startsWith("linux")
|
|
? "libcua_driver_sdk.so"
|
|
: "cua_driver_sdk.dll";
|
|
const nativeContents = "accepted native artifact";
|
|
const expectedDigest =
|
|
options.expectedDigest ?? createHash("sha256").update(nativeContents).digest("hex");
|
|
const sdkManifestPath = path.join(root, "sdk-package.json");
|
|
const platformPackageName = `@trycua/cua-driver-${platformKey}`;
|
|
const platformDir = path.join(root, "platform");
|
|
const platformManifestPath = path.join(platformDir, "package.json");
|
|
|
|
fs.mkdirSync(platformDir);
|
|
const pluginManifest = {
|
|
dependencies: { "@trycua/cua-driver": acceptedVersion },
|
|
cuaDriverArtifacts: { [platformKey]: { files: { [nativeFile]: expectedDigest } } },
|
|
};
|
|
writeJson(sdkManifestPath, {
|
|
name: "@trycua/cua-driver",
|
|
version: options.sdkVersion ?? acceptedVersion,
|
|
});
|
|
writeJson(platformManifestPath, {
|
|
name: platformPackageName,
|
|
version: options.platformVersion ?? acceptedVersion,
|
|
});
|
|
fs.writeFileSync(path.join(platformDir, nativeFile), nativeContents);
|
|
|
|
const packages = new Map<string, string>([["@trycua/cua-driver", sdkManifestPath]]);
|
|
if (!options.omitPlatformPackage) {
|
|
packages.set(platformPackageName, platformManifestPath);
|
|
}
|
|
return {
|
|
pluginManifest,
|
|
resolvePackageJson: (packageName: string) => packages.get(packageName),
|
|
};
|
|
}
|
|
|
|
afterEach(() => {
|
|
for (const directory of temporaryDirectories.splice(0)) {
|
|
fs.rmSync(directory, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
describe("CUA Driver artifact verification", () => {
|
|
it("accepts the pinned SDK and native file digest", () => {
|
|
const fixture = createArtifactFixture();
|
|
|
|
expect(
|
|
inspectCuaDriverArtifacts({
|
|
platform: "linux",
|
|
arch: "x64",
|
|
linuxLibc: "gnu",
|
|
...fixture,
|
|
}),
|
|
).toEqual({
|
|
ok: true,
|
|
applicable: true,
|
|
version: "0.19.3",
|
|
platformPackage: "@trycua/cua-driver-linux-x64-gnu",
|
|
});
|
|
});
|
|
|
|
it("reports an actionable typed diagnostic when the native package is absent", () => {
|
|
const fixture = createArtifactFixture({ omitPlatformPackage: true });
|
|
|
|
const result = inspectCuaDriverArtifacts({
|
|
platform: "linux",
|
|
arch: "x64",
|
|
linuxLibc: "gnu",
|
|
...fixture,
|
|
});
|
|
|
|
expect(result).toMatchObject({ ok: false, code: "COMPUTER_DRIVER_PACKAGE_MISSING" });
|
|
expect(result.ok ? "" : result.diagnostic).toContain("Reinstall OpenClaw on this node host");
|
|
});
|
|
|
|
it("refuses SDK and platform package version skew", () => {
|
|
const fixture = createArtifactFixture({ platformVersion: "0.19.2" });
|
|
|
|
const result = inspectCuaDriverArtifacts({
|
|
platform: "linux",
|
|
arch: "x64",
|
|
linuxLibc: "gnu",
|
|
...fixture,
|
|
});
|
|
|
|
expect(result).toMatchObject({ ok: false, code: "COMPUTER_DRIVER_VERSION_MISMATCH" });
|
|
expect(result.ok ? "" : result.diagnostic).toContain("resolved @trycua/cua-driver@0.19.3");
|
|
});
|
|
|
|
it("refuses a native file that does not match the accepted digest", () => {
|
|
const fixture = createArtifactFixture({ expectedDigest: "0".repeat(64) });
|
|
|
|
const result = inspectCuaDriverArtifacts({
|
|
platform: "linux",
|
|
arch: "x64",
|
|
linuxLibc: "gnu",
|
|
...fixture,
|
|
});
|
|
|
|
expect(result).toMatchObject({ ok: false, code: "COMPUTER_DRIVER_DIGEST_MISMATCH" });
|
|
expect(result.ok ? "" : result.diagnostic).toContain("do not run or replace");
|
|
});
|
|
|
|
it("rejects Linux hosts without a published glibc package", () => {
|
|
const fixture = createArtifactFixture();
|
|
|
|
const result = inspectCuaDriverArtifacts({
|
|
platform: "linux",
|
|
arch: "x64",
|
|
linuxLibc: "musl",
|
|
...fixture,
|
|
});
|
|
|
|
expect(result).toMatchObject({ ok: false, code: "COMPUTER_DRIVER_PLATFORM_UNSUPPORTED" });
|
|
expect(result.ok ? "" : result.diagnostic).toContain("glibc-based Linux");
|
|
});
|
|
});
|