fix(plugins): normalize registry migration env flags · openclaw/openclaw@73caceb
vincentkoc
·
2026-04-26
·
via Recent Commits to openclaw:main
File tree
src/commands/doctor/shared
| Original file line number | Diff line number | Diff line change |
|---|
@@ -117,6 +117,11 @@ const BAILEYS_MEDIA_ONCE_IMPORT_RE = /import\s+\{\s*once\s*\}\s+from\s+['"]event
|
117 | 117 | const BAILEYS_MEDIA_ASYNC_CONTEXT_RE = |
118 | 118 | /async\s+function\s+encryptedStream|encryptedStream\s*=\s*async/u; |
119 | 119 | |
| 120 | +function hasEnvFlag(env, key) { |
| 121 | +const value = env?.[key]?.trim().toLowerCase(); |
| 122 | +return Boolean(value && value !== "0" && value !== "false" && value !== "no"); |
| 123 | +} |
| 124 | + |
120 | 125 | function readJson(filePath) { |
121 | 126 | return JSON.parse(readFileSync(filePath, "utf8")); |
122 | 127 | } |
@@ -666,7 +671,7 @@ export async function runPluginRegistryPostinstallMigration(params = {}) {
|
666 | 671 | const packageRoot = params.packageRoot ?? DEFAULT_PACKAGE_ROOT; |
667 | 672 | const env = params.env ?? process.env; |
668 | 673 | |
669 | | -if (env[DISABLE_PLUGIN_REGISTRY_MIGRATION_ENV]?.trim()) { |
| 674 | +if (hasEnvFlag(env, DISABLE_PLUGIN_REGISTRY_MIGRATION_ENV)) { |
670 | 675 | return { status: "disabled", migrated: false, reason: "disabled-env" }; |
671 | 676 | } |
672 | 677 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -12,6 +12,7 @@ import {
|
12 | 12 | makeTrackedTempDir, |
13 | 13 | } from "../../../plugins/test-helpers/fs-fixtures.js"; |
14 | 14 | import { |
| 15 | +DISABLE_PLUGIN_REGISTRY_MIGRATION_ENV, |
15 | 16 | FORCE_PLUGIN_REGISTRY_MIGRATION_ENV, |
16 | 17 | migratePluginRegistryForInstall, |
17 | 18 | preflightPluginRegistryInstallMigration, |
@@ -268,4 +269,23 @@ describe("plugin registry install migration", () => {
|
268 | 269 | ], |
269 | 270 | }); |
270 | 271 | }); |
| 272 | + |
| 273 | +it("treats falsey env flag strings as unset", async () => { |
| 274 | +const stateDir = makeTempDir(); |
| 275 | +await writePersistedInstalledPluginIndex(createCurrentIndex(), { stateDir }); |
| 276 | + |
| 277 | +expect( |
| 278 | +preflightPluginRegistryInstallMigration({ |
| 279 | + stateDir, |
| 280 | +env: hermeticEnv({ |
| 281 | +[DISABLE_PLUGIN_REGISTRY_MIGRATION_ENV]: "0", |
| 282 | +[FORCE_PLUGIN_REGISTRY_MIGRATION_ENV]: "false", |
| 283 | +}), |
| 284 | +}), |
| 285 | +).toMatchObject({ |
| 286 | +action: "skip-existing", |
| 287 | +force: false, |
| 288 | +deprecationWarnings: [], |
| 289 | +}); |
| 290 | +}); |
271 | 291 | }); |
| Original file line number | Diff line number | Diff line change |
|---|
@@ -57,7 +57,8 @@ export type PluginRegistryInstallMigrationParams = LoadInstalledPluginIndexParam
|
57 | 57 | }; |
58 | 58 | |
59 | 59 | function hasEnvFlag(env: NodeJS.ProcessEnv | undefined, key: string): boolean { |
60 | | -return Boolean(env?.[key]?.trim()); |
| 60 | +const value = env?.[key]?.trim().toLowerCase(); |
| 61 | +return Boolean(value && value !== "0" && value !== "false" && value !== "no"); |
61 | 62 | } |
62 | 63 | |
63 | 64 | function forceDeprecationWarning(): string { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -349,6 +349,33 @@ describe("bundled plugin postinstall", () => {
|
349 | 349 | expect(importModule).not.toHaveBeenCalled(); |
350 | 350 | }); |
351 | 351 | |
| 352 | +it("does not disable plugin registry migration for falsey env flag strings", async () => { |
| 353 | +const migratePluginRegistryForInstall = vi.fn(async () => ({ |
| 354 | +status: "skip-existing", |
| 355 | +migrated: false, |
| 356 | +preflight: {}, |
| 357 | +})); |
| 358 | +const importModule = vi.fn(async () => ({ migratePluginRegistryForInstall })); |
| 359 | + |
| 360 | +await expect( |
| 361 | +runPluginRegistryPostinstallMigration({ |
| 362 | +packageRoot: "/pkg", |
| 363 | +env: { OPENCLAW_DISABLE_PLUGIN_REGISTRY_MIGRATION: "0" }, |
| 364 | +existsSync: vi.fn(() => true), |
| 365 | + importModule, |
| 366 | +log: { log: vi.fn(), warn: vi.fn() }, |
| 367 | +}), |
| 368 | +).resolves.toMatchObject({ |
| 369 | +status: "skip-existing", |
| 370 | +migrated: false, |
| 371 | +}); |
| 372 | +expect(importModule).toHaveBeenCalledOnce(); |
| 373 | +expect(migratePluginRegistryForInstall).toHaveBeenCalledWith({ |
| 374 | +env: { OPENCLAW_DISABLE_PLUGIN_REGISTRY_MIGRATION: "0" }, |
| 375 | +packageRoot: "/pkg", |
| 376 | +}); |
| 377 | +}); |
| 378 | + |
352 | 379 | it("prunes stale dist files from packaged installs", async () => { |
353 | 380 | const packageRoot = await createTempDirAsync("openclaw-packaged-install-"); |
354 | 381 | const currentFile = path.join(packageRoot, "dist", "channel-BOa4MfoC.js"); |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。