mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-21 10:16:44 +00:00
fix: shorten managed npm generation paths (#97488)
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
// Covers managed plugin install path generation.
|
||||
import path from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
resolvePluginNpmGenerationProjectDir,
|
||||
resolvePluginNpmGenerationProjectDirPrefix,
|
||||
} from "./install-paths.js";
|
||||
|
||||
describe("managed npm plugin install paths", () => {
|
||||
it("keeps generation project names compact for nested Windows runtime binaries", () => {
|
||||
const packageName = "@openclaw/codex";
|
||||
const generationKey = [
|
||||
packageName,
|
||||
"2026.6.10",
|
||||
`${packageName}@2026.6.10`,
|
||||
"sha512-test-integrity",
|
||||
"codexshasum",
|
||||
].join("\n");
|
||||
const projectDir = resolvePluginNpmGenerationProjectDir({
|
||||
npmDir: String.raw`C:\Users\Administrator\.openclaw\npm`,
|
||||
packageName,
|
||||
generationKey,
|
||||
});
|
||||
const projectName = path.basename(projectDir);
|
||||
|
||||
expect(projectName).toMatch(
|
||||
/^openclaw-codex-[a-f0-9]{10}__openclaw-generation__g-[a-f0-9]{16}$/u,
|
||||
);
|
||||
expect(projectName.length).toBeLessThanOrEqual(66);
|
||||
|
||||
const nestedCodexBinaryPath = path.win32.join(
|
||||
String.raw`C:\Users\Administrator\.openclaw\npm\projects`,
|
||||
projectName,
|
||||
"node_modules",
|
||||
"@openclaw",
|
||||
"codex",
|
||||
"node_modules",
|
||||
"@openai",
|
||||
"codex-win32-x64",
|
||||
"vendor",
|
||||
"x86_64-pc-windows-msvc",
|
||||
"bin",
|
||||
"codex.exe",
|
||||
);
|
||||
expect(nestedCodexBinaryPath.length).toBeLessThan(260);
|
||||
});
|
||||
|
||||
it("keeps generation project names under the recoverable package prefix", () => {
|
||||
const packageName = "@openclaw/codex";
|
||||
const projectDir = resolvePluginNpmGenerationProjectDir({
|
||||
npmDir: "/tmp/openclaw/npm",
|
||||
packageName,
|
||||
generationKey: "codex-v2",
|
||||
});
|
||||
|
||||
expect(path.basename(projectDir)).toMatch(
|
||||
new RegExp(`^${resolvePluginNpmGenerationProjectDirPrefix(packageName)}`, "u"),
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,5 @@
|
||||
// Resolves plugin install paths for local and package sources.
|
||||
import { createHash } from "node:crypto";
|
||||
import path from "node:path";
|
||||
import {
|
||||
resolveSafeInstallDir,
|
||||
@@ -121,12 +122,19 @@ export function resolvePluginNpmProjectDir(params: {
|
||||
}
|
||||
|
||||
const PLUGIN_NPM_GENERATION_PROJECT_SEPARATOR = "__openclaw-generation__";
|
||||
const PLUGIN_NPM_GENERATION_KEY_HASH_CHARS = 16;
|
||||
|
||||
/** Resolves the managed npm artifact-generation project directory prefix for a package. */
|
||||
export function resolvePluginNpmGenerationProjectDirPrefix(packageName: string): string {
|
||||
return `${encodePluginNpmProjectDirName(packageName)}${PLUGIN_NPM_GENERATION_PROJECT_SEPARATOR}`;
|
||||
}
|
||||
|
||||
/** Encodes a package generation fingerprint into a compact project directory suffix. */
|
||||
export function encodePluginNpmGenerationKeyDirName(generationKey: string): string {
|
||||
const digest = createHash("sha256").update(generationKey).digest("hex");
|
||||
return `g-${digest.slice(0, PLUGIN_NPM_GENERATION_KEY_HASH_CHARS)}`;
|
||||
}
|
||||
|
||||
/** Resolves an artifact-generation-specific managed npm project directory. */
|
||||
export function resolvePluginNpmGenerationProjectDir(params: {
|
||||
packageName: string;
|
||||
@@ -135,7 +143,7 @@ export function resolvePluginNpmGenerationProjectDir(params: {
|
||||
}): string {
|
||||
return path.join(
|
||||
resolvePluginNpmProjectsDir(params.npmDir),
|
||||
`${resolvePluginNpmGenerationProjectDirPrefix(params.packageName)}${safePathSegmentHashed(
|
||||
`${resolvePluginNpmGenerationProjectDirPrefix(params.packageName)}${encodePluginNpmGenerationKeyDirName(
|
||||
params.generationKey,
|
||||
)}`,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user