mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-21 10:16:44 +00:00
fix(install): isolate source postinstall state (#111514)
This commit is contained in:
@@ -823,10 +823,17 @@ export async function runPluginRegistryPostinstallMigration(params = {}) {
|
||||
const log = params.log ?? console;
|
||||
const packageRoot = params.packageRoot ?? DEFAULT_PACKAGE_ROOT;
|
||||
const env = params.env ?? process.env;
|
||||
const pathExists = params.existsSync ?? existsSync;
|
||||
|
||||
// Registry migration belongs to installed-package upgrades. Source checkouts
|
||||
// can contain stale dist from a different build and must not touch operator state.
|
||||
if (isSourceCheckoutRoot({ packageRoot, existsSync: pathExists })) {
|
||||
return { status: "skipped", reason: "source-checkout" };
|
||||
}
|
||||
|
||||
try {
|
||||
const migrationModule = await importInstalledDistModule(
|
||||
params,
|
||||
{ ...params, existsSync: pathExists },
|
||||
"dist/commands/doctor/shared/plugin-registry-migration.js",
|
||||
);
|
||||
if (!migrationModule) {
|
||||
|
||||
@@ -482,6 +482,37 @@ describe("bundled plugin postinstall", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("does not migrate operator plugin state from a source checkout", async () => {
|
||||
const packageRoot = "/source";
|
||||
const existingPaths = new Set([
|
||||
path.join(packageRoot, ".git"),
|
||||
path.join(packageRoot, "src"),
|
||||
path.join(packageRoot, "extensions"),
|
||||
path.join(
|
||||
packageRoot,
|
||||
"dist",
|
||||
"commands",
|
||||
"doctor",
|
||||
"shared",
|
||||
"plugin-registry-migration.js",
|
||||
),
|
||||
]);
|
||||
const importModule = vi.fn();
|
||||
|
||||
await expect(
|
||||
runPluginRegistryPostinstallMigration({
|
||||
packageRoot,
|
||||
existsSync: vi.fn((filePath: string) => existingPaths.has(filePath)),
|
||||
importModule,
|
||||
log: { log: vi.fn(), warn: vi.fn() },
|
||||
}),
|
||||
).resolves.toEqual({
|
||||
status: "skipped",
|
||||
reason: "source-checkout",
|
||||
});
|
||||
expect(importModule).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("keeps plugin registry postinstall migration non-fatal when dist entries are unavailable", async () => {
|
||||
const warn = vi.fn();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user