Skip to content

Commit c27d477

Browse files
committed
fix: uninstall refusal reads the pair named for the package; pin appOf's kernel scopes
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ihL2dM9PvPPB9BMVdhf2R
1 parent 7467e2e commit c27d477

3 files changed

Lines changed: 87 additions & 12 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* [#29594, ADR-0146 D3 as amended] `@objectstack/metadata-core`'s `appOf`
5+
* keeps its own copy of the kernel scopes — that package sits below this one
6+
* and cannot import {@link READ_ONLY_PACKAGE_SCOPES}. This pin holds the two
7+
* equal from the side that can see both: a package of every read-only scope
8+
* is its own App reading (the kernel is not customizable this version, ruling
9+
* record 6691217245), even when it declares an App; a package of any other
10+
* scope declaring one App reads that App.
11+
*/
12+
import { describe, expect, it } from 'vitest';
13+
import { appOf, type InstalledManifestLookup } from '@objectstack/metadata-core';
14+
import { READ_ONLY_PACKAGE_SCOPES } from './package-writability.js';
15+
16+
const APP = 'com.acme.app';
17+
18+
function installedWith(id: string, scope: string): InstalledManifestLookup {
19+
const manifests: Record<string, Record<string, unknown>> = {
20+
[APP]: { id: APP, type: 'app', namespace: 'acme' },
21+
[id]: { id, type: 'module', namespace: 'acme', scope, dependencies: { [APP]: '^1' } },
22+
};
23+
return (packageId) => manifests[packageId] as never;
24+
}
25+
26+
describe('[#29594] appOf\'s kernel scopes are READ_ONLY_PACKAGE_SCOPES', () => {
27+
it('a package of every read-only scope is its own unit, even when it declares an App', () => {
28+
expect(READ_ONLY_PACKAGE_SCOPES.length).toBeGreaterThan(0);
29+
for (const scope of READ_ONLY_PACKAGE_SCOPES) {
30+
expect(appOf('com.acme.kernelish', installedWith('com.acme.kernelish', scope)), scope).toBe('com.acme.kernelish');
31+
}
32+
});
33+
34+
it('a package of a writable scope declaring one App reads that App', () => {
35+
for (const scope of ['project', 'environment', 'platform']) {
36+
if (READ_ONLY_PACKAGE_SCOPES.includes(scope)) continue;
37+
expect(appOf('com.acme.member', installedWith('com.acme.member', scope)), scope).toBe(APP);
38+
}
39+
});
40+
});

‎packages/objectql/src/registry-assert-package-uninstallable.test.ts‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,3 +280,39 @@ describe('#28408 (ADR-0146 D3) a base whose paired customization package is inst
280280
expect(forced.getObject('account')).toBeUndefined();
281281
});
282282
});
283+
284+
describe('[#29594] ADR-0146 D3 (as amended): the App is the unit — a member is not refused for the App\'s pair', () => {
285+
const APP = 'app.objectstack.hotcrm';
286+
const MODULE = 'app.objectstack.hotcrm.service';
287+
const APP_PAIR = 'app.objectstack.hotcrm.custom';
288+
const LEGACY_PAIR = 'app.objectstack.hotcrm.service.custom';
289+
290+
function hotcrm(opts: { legacy?: boolean } = {}) {
291+
const r = new SchemaRegistry({ multiTenant: false });
292+
(r as any).logLevel = 'silent';
293+
r.installPackage({ id: APP, name: 'HotCRM', version: '6.0.0', type: 'app', namespace: 'crm', dependencies: { [MODULE]: '^6' } } as any, 'marketplace');
294+
r.installPackage({ id: MODULE, name: 'HotCRM Service', version: '6.0.0', type: 'module', namespace: 'crm', dependencies: { [APP]: '^6' } } as any, 'marketplace');
295+
r.registerObject({ name: 'service_case', fields: {} } as any, MODULE, 'crm', 'own');
296+
r.installPackage({ id: APP_PAIR, name: 'HotCRM (custom)', version: '0.1.0', type: 'module', namespace: 'crm_custom', dependencies: { [APP]: '^6' } } as any, 'authored');
297+
if (opts.legacy) {
298+
r.installPackage({ id: LEGACY_PAIR, name: 'HotCRM Service (custom)', version: '0.1.0', type: 'module', namespace: 'crm_svc_custom', dependencies: { [MODULE]: '^6' } } as any, 'authored');
299+
}
300+
return r;
301+
}
302+
303+
it('the App is refused naming the App\'s pair; a member module is not', () => {
304+
const r = hotcrm();
305+
expect(thrownBy(() => r.assertPackageUninstallable(APP)).customizationPackageId).toBe(APP_PAIR);
306+
expect(() => r.assertPackageUninstallable(MODULE)).not.toThrow();
307+
});
308+
309+
it('a member that still has the pair an earlier version created for it is refused naming that pair (merge question 12)', () => {
310+
const r = hotcrm({ legacy: true });
311+
const err = thrownBy(() => r.assertPackageUninstallable(MODULE));
312+
expect({ code: err.code, status: err.status, pair: err.customizationPackageId }).toEqual({
313+
code: 'RESOURCE_CONFLICT',
314+
status: 409,
315+
pair: LEGACY_PAIR,
316+
});
317+
});
318+
});

‎packages/objectql/src/registry.ts‎

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ import { SystemFieldName, scalarOverridesPackagedBase } from '@objectstack/spec/
5656
import { resolveTenancyPosture, resolveSearchPinyinEnabled } from '@objectstack/types';
5757
import { postureEnforcesWall } from '@objectstack/spec/security';
5858
import { provisionSearchCompanion, SEARCH_COMPANION_FIELD } from './search-companion.js';
59-
import { ObjectStackManifest, ManifestSchema, InstalledPackage, InstalledPackageSchema, InstalledPackageSourceSchema, type InstalledPackageSource, checkFieldCompleteness } from '@objectstack/spec/kernel';
59+
import { ObjectStackManifest, ManifestSchema, InstalledPackage, InstalledPackageSchema, InstalledPackageSourceSchema, type InstalledPackageSource, checkFieldCompleteness, customizationBasePackageId } from '@objectstack/spec/kernel';
6060
import { DEFAULT_FLOW_FUNCTION_EFFECT } from '@objectstack/spec/automation';
6161
import { AppSchema, ActionSchema } from '@objectstack/spec/ui';
6262
import { applyProtection } from '@objectstack/spec/shared';
@@ -3336,7 +3336,7 @@ const EXTENDED_OBJECTS_LISTED = 5;
33363336
* so one answer is the whole way out rather than the first step of several.
33373337
*
33383338
* [#28408, ADR-0146 D3] …and the uninstall refusal of a base whose paired
3339-
* customization package is installed and stands on it: the App's pair of an
3339+
* customization package is installed and named for it: the App's pair of an
33403340
* App, or the per-package pair an earlier version created for a package
33413341
* ({@link pairsOf}), held by this registry. That package
33423342
* holds every customization of the base, so uninstalling the base under it
@@ -7353,9 +7353,9 @@ export class SchemaRegistry {
73537353
* package is refused exactly when the first such object exists.
73547354
*
73557355
* [#28408, ADR-0146 D3] It also refuses while this registry holds the
7356-
* package's paired customization package that declares `packageId` — one
7357-
* of the ids {@link pairsOf} looks up for it (the App's pair stands on the
7358-
* App, not on a member) — so the pair is
7356+
* package's paired customization package named for `packageId` — one
7357+
* of the ids {@link pairsOf} looks up for it (the App's pair is named for
7358+
* the App, not for a member) — so the pair is
73597359
* found by id alone, whichever door created or installed it. The same
73607360
* refusal, carrying both causes when both hold. Uninstalling the pair itself
73617361
* asks nothing of this kind: a `.custom` id derives no pair of its own. An
@@ -7386,15 +7386,14 @@ export class SchemaRegistry {
73867386
extended.push({ objectName: fqn, extenders: otherExtenders.map(c => String(c.packageId)) });
73877387
}
73887388
}
7389-
// [ADR-0146 D3 · merge questions 11, 12] The installed pair that stands
7390-
// on this package: the App's pair when this is the App (a member's
7389+
// [ADR-0146 D3 · merge questions 11, 12] The installed pair named for
7390+
// this package: the App's pair when this is the App (a member's
73917391
// uninstall keeps and marks its overrides in the App's pair, and is not
73927392
// refused for it), or the per-package pair an earlier version created
7393-
// for this package — each declares the package it stands on.
7394-
const installedPair = pairsOf(packageId, installedManifestsOf(this)).find((id) => {
7395-
const dependencies = (this.getPackage(id)?.manifest as { dependencies?: unknown } | undefined)?.dependencies;
7396-
return typeof dependencies === 'object' && dependencies !== null && Object.prototype.hasOwnProperty.call(dependencies, packageId);
7397-
});
7393+
// for this package.
7394+
const installedPair = pairsOf(packageId, installedManifestsOf(this)).find(
7395+
(id) => customizationBasePackageId(id) === packageId && this.getPackage(id) !== undefined,
7396+
);
73987397
if (extended.length > 0 || installedPair !== undefined) {
73997398
throw new PackageUninstallExtendedError(packageId, extended, installedPair);
74007399
}

0 commit comments

Comments
 (0)