mirror of
https://github.com/moltbot/moltbot.git
synced 2026-05-13 23:56:07 +00:00
test: fix postpublish verifier sidecar handling
This commit is contained in:
@@ -78,8 +78,9 @@ export function collectInstalledPackageErrors(params: {
|
||||
packageRoot: string;
|
||||
}): string[] {
|
||||
const errors: string[] = [];
|
||||
const installedVersion = normalizeInstalledBinaryVersion(params.installedVersion);
|
||||
|
||||
if (params.installedVersion !== params.expectedVersion) {
|
||||
if (installedVersion !== params.expectedVersion) {
|
||||
errors.push(
|
||||
`installed package version mismatch: expected ${params.expectedVersion}, found ${params.installedVersion || "<missing>"}.`,
|
||||
);
|
||||
@@ -96,6 +97,12 @@ export function collectInstalledPackageErrors(params: {
|
||||
return errors;
|
||||
}
|
||||
|
||||
export function normalizeInstalledBinaryVersion(output: string): string {
|
||||
const trimmed = output.trim();
|
||||
const versionMatch = /\b\d{4}\.\d{1,2}\.\d{1,2}(?:-\d+|-beta\.\d+)?\b/u.exec(trimmed);
|
||||
return versionMatch?.[0] ?? trimmed;
|
||||
}
|
||||
|
||||
export function resolveInstalledBinaryPath(prefixDir: string, platform = process.platform): string {
|
||||
return platform === "win32"
|
||||
? join(prefixDir, "openclaw.cmd")
|
||||
@@ -109,6 +116,25 @@ function collectRuntimeDependencySpecs(packageJson: InstalledPackageJson): Map<s
|
||||
]);
|
||||
}
|
||||
|
||||
function collectExpectedBundledExtensionPackageIds(
|
||||
sourceExtensionsDir = join(process.cwd(), "extensions"),
|
||||
): ReadonlySet<string> | null {
|
||||
if (!existsSync(sourceExtensionsDir)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const ids = new Set<string>();
|
||||
for (const entry of readdirSync(sourceExtensionsDir, { withFileTypes: true })) {
|
||||
if (!entry.isDirectory()) {
|
||||
continue;
|
||||
}
|
||||
if (existsSync(join(sourceExtensionsDir, entry.name, "package.json"))) {
|
||||
ids.add(entry.name);
|
||||
}
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
function readBundledExtensionPackageJsons(packageRoot: string): {
|
||||
manifests: InstalledBundledExtensionManifestRecord[];
|
||||
errors: string[];
|
||||
@@ -120,6 +146,7 @@ function readBundledExtensionPackageJsons(packageRoot: string): {
|
||||
|
||||
const manifests: InstalledBundledExtensionManifestRecord[] = [];
|
||||
const errors: string[] = [];
|
||||
const expectedPackageIds = collectExpectedBundledExtensionPackageIds();
|
||||
|
||||
for (const entry of readdirSync(extensionsDir, { withFileTypes: true })) {
|
||||
if (!entry.isDirectory()) {
|
||||
@@ -129,7 +156,9 @@ function readBundledExtensionPackageJsons(packageRoot: string): {
|
||||
const extensionDirPath = join(extensionsDir, entry.name);
|
||||
const packageJsonPath = join(extensionsDir, entry.name, "package.json");
|
||||
if (!existsSync(packageJsonPath)) {
|
||||
errors.push(`installed bundled extension manifest missing: ${packageJsonPath}.`);
|
||||
if (expectedPackageIds === null || expectedPackageIds.has(entry.name)) {
|
||||
errors.push(`installed bundled extension manifest missing: ${packageJsonPath}.`);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -281,7 +310,7 @@ function verifyScenario(version: string, scenario: PublishedInstallScenario): vo
|
||||
});
|
||||
const installedBinaryVersion = readInstalledBinaryVersion(prefixDir, workingDir);
|
||||
|
||||
if (installedBinaryVersion !== scenario.expectedVersion) {
|
||||
if (normalizeInstalledBinaryVersion(installedBinaryVersion) !== scenario.expectedVersion) {
|
||||
errors.push(
|
||||
`installed openclaw binary version mismatch: expected ${scenario.expectedVersion}, found ${installedBinaryVersion || "<missing>"}.`,
|
||||
);
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
buildPublishedInstallScenarios,
|
||||
collectInstalledMirroredRootDependencyManifestErrors,
|
||||
collectInstalledPackageErrors,
|
||||
normalizeInstalledBinaryVersion,
|
||||
resolveInstalledBinaryPath,
|
||||
} from "../scripts/openclaw-npm-postpublish-verify.ts";
|
||||
import { BUNDLED_RUNTIME_SIDECAR_PATHS } from "../src/plugins/runtime-sidecar-paths.ts";
|
||||
@@ -60,6 +61,15 @@ describe("collectInstalledPackageErrors", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("normalizeInstalledBinaryVersion", () => {
|
||||
it("accepts decorated CLI version output", () => {
|
||||
expect(normalizeInstalledBinaryVersion("OpenClaw 2026.4.8 (9ece252)")).toBe("2026.4.8");
|
||||
expect(normalizeInstalledBinaryVersion("OpenClaw 2026.4.8-beta.1 (9ece252)")).toBe(
|
||||
"2026.4.8-beta.1",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveInstalledBinaryPath", () => {
|
||||
it("uses the Unix global bin path on non-Windows platforms", () => {
|
||||
expect(resolveInstalledBinaryPath("/tmp/openclaw-prefix", "darwin")).toBe(
|
||||
@@ -209,6 +219,24 @@ describe("collectInstalledMirroredRootDependencyManifestErrors", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("skips manifest-only sidecar directories without package.json", () => {
|
||||
const packageRoot = makeInstalledPackageRoot();
|
||||
|
||||
try {
|
||||
writePackageFile(packageRoot, "package.json", {
|
||||
version: "2026.4.9",
|
||||
dependencies: {},
|
||||
});
|
||||
writePackageFile(packageRoot, "dist/extensions/device-pair/openclaw.plugin.json", {
|
||||
id: "device-pair",
|
||||
});
|
||||
|
||||
expect(collectInstalledMirroredRootDependencyManifestErrors(packageRoot)).toEqual([]);
|
||||
} finally {
|
||||
rmSync(packageRoot, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it("rejects bundled extension manifests that are not regular files", () => {
|
||||
const packageRoot = makeInstalledPackageRoot();
|
||||
const outsideManifestRoot = makeInstalledPackageRoot();
|
||||
|
||||
Reference in New Issue
Block a user