fix(install): isolate source postinstall state (#111514)

This commit is contained in:
Peter Steinberger
2026-07-19 12:14:21 -07:00
committed by GitHub
parent 1ddb6f1bbb
commit 5ec3b2dab4
2 changed files with 39 additions and 1 deletions
+8 -1
View File
@@ -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();