Skip to content

Commit d17be32

Browse files
committed
fix(runtime): the uninstall door and the verb's guard answer one refusal, in its uninstall form
The DELETE arm asks packageUninstallDependentRulesRefusal instead of an inline scan; the guard passes { operation: 'uninstall' } to the builder, and the in-process pin holds the uninstall sentence. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ihL2c1rk1PGZ51s32cxZt
1 parent fffe4d6 commit d17be32

2 files changed

Lines changed: 26 additions & 13 deletions

File tree

‎packages/runtime/src/domains/packages-disable-module-extension-fields.test.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,6 +1439,7 @@ describe('[#31232] the in-process uninstall verb refuses while an enabled packag
14391439
const expectedMessage = () => runtime.formatPackageDisableDependents(
14401440
`Package '${TIERS}' cannot be uninstalled`,
14411441
runtime.readPackageDisableDependents(booted!.engine.registry, TIERS),
1442+
{ operation: 'uninstall' },
14421443
);
14431444

14441445
it('the verb answers 409 with the doors\' code and sentence under an uninstall lead, having read and moved nothing', async () => {
@@ -1457,8 +1458,12 @@ describe('[#31232] the in-process uninstall verb refuses while an enabled packag
14571458
expect({ status: refused.status, code: refused.code }).toEqual({ status: 409, code: CODE });
14581459
expect(refused.message).toBe(expectedMessage());
14591460
expect(refused.message).toBe(packageUninstallDependentRulesRefusal(engine.registry, TIERS)?.message);
1460-
expect(String(refused.message)).toMatch(new RegExp(`^Package '${TIERS.replace(/\./g, '\\.')}' cannot be uninstalled: an active validation rule reads a field it adds through objectExtensions`));
1461-
expect(String(refused.message)).toContain(`${READER} · ${ACCOUNT} · ${RULE} (reads ${TIER})`);
1461+
// The uninstall form: what the uninstall would do, and the remedy that keeps the field served.
1462+
expect(refused.message).toBe(
1463+
`Package '${TIERS}' cannot be uninstalled: an active validation rule reads a field it adds through objectExtensions, `
1464+
+ `which the uninstall would withdraw — ${READER} · ${ACCOUNT} · ${RULE} (reads ${TIER}). Switch off or change that rule first, `
1465+
+ 'or keep the package installed.',
1466+
);
14621467

14631468
// Nothing read, nothing moved: no stored row read or deleted, no
14641469
// registry withdrawal, no cleanup; the package and its field stay

‎packages/runtime/src/domains/packages.ts‎

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -936,9 +936,11 @@ const DEPENDENT_RULES_GUARD_REGISTERED = new WeakSet<object>();
936936
* validation rule of another enabled package reads a field the package adds
937937
* through `objectExtensions`: the disable door's verdict
938938
* ({@link readDisableDependentRules}) and sentence
939-
* ({@link disableDependentRulesMessage}) under an uninstall lead, as the wire
940-
* pair `409` `PACKAGE_DISABLE_RESTRICTED_BY_VALIDATION_RULE`. `undefined` when
941-
* no rule depends. Pure over `registry`.
939+
* ({@link disableDependentRulesMessage}, in its uninstall form) under an
940+
* uninstall lead, as the wire pair `409`
941+
* `PACKAGE_DISABLE_RESTRICTED_BY_VALIDATION_RULE`. `undefined` when no rule
942+
* depends. Pure over `registry`. The one refusal both the uninstall verb's
943+
* guard and `DELETE /packages/:id` answer.
942944
*/
943945
export function packageUninstallDependentRulesRefusal(
944946
registry: unknown,
@@ -949,7 +951,7 @@ export function packageUninstallDependentRulesRefusal(
949951
return {
950952
code: PACKAGE_DISABLE_RESTRICTED_BY_VALIDATION_RULE.code,
951953
status: PACKAGE_DISABLE_RESTRICTED_BY_VALIDATION_RULE.status,
952-
message: disableDependentRulesMessage(`Package '${packageId}' cannot be uninstalled`, dependents),
954+
message: disableDependentRulesMessage(`Package '${packageId}' cannot be uninstalled`, dependents, { operation: 'uninstall' }),
953955
};
954956
}
955957

@@ -3854,15 +3856,21 @@ export async function handlePackagesRequest(deps: DomainHandlerDeps, path: strin
38543856
// and the environment's state exactly as they were. A package
38553857
// already disabled withholds its fields already: the verdict is
38563858
// empty and the uninstall proceeds as before.
3857-
const dependents = readDisableDependentRules(registry, id);
3858-
if (dependents.length > 0) {
3859+
//
3860+
// [#31232] Through {@link packageUninstallDependentRulesRefusal},
3861+
// the ONE refusal the uninstall verb's guard answers too
3862+
// (`ensureDependentRulesUninstallGuard`), so this door and every
3863+
// in-process caller of `deletePackage` answer the same code and
3864+
// the same words. Asked here as well, before the protocol is
3865+
// resolved, because a host whose protocol has no `deletePackage`,
3866+
// or that registered no guard, uninstalls through the registry
3867+
// below; with a guard registered, this answer comes first and the
3868+
// verb's guard is not reached on this path.
3869+
const dependentRefusal = packageUninstallDependentRulesRefusal(registry, id);
3870+
if (dependentRefusal) {
38593871
return {
38603872
handled: true,
3861-
response: deps.error(
3862-
disableDependentRulesMessage(`Package '${id}' cannot be uninstalled`, dependents, { operation: 'uninstall' }),
3863-
PACKAGE_DISABLE_RESTRICTED_BY_VALIDATION_RULE.status,
3864-
{ code: PACKAGE_DISABLE_RESTRICTED_BY_VALIDATION_RULE.code },
3865-
),
3873+
response: deps.error(dependentRefusal.message, dependentRefusal.status, { code: dependentRefusal.code }),
38663874
};
38673875
}
38683876
const protocol = await resolveProtocol(deps, _context);

0 commit comments

Comments
 (0)