Skip to content

Commit 98e6c22

Browse files
committed
wip(#29594): thread the installed-manifest lookup through every pair site; kernel verdict on the ensure door
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibzCo6pa7SSUFmosQD8
1 parent 3fe5f2a commit 98e6c22

42 files changed

Lines changed: 658 additions & 261 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎packages/cli/src/utils/override-declarations.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import { describe, expect, it } from 'vitest';
1515
import { judgeOverrideWrite } from '@objectstack/metadata-protocol';
1616
import { findOverrideDeclarationRefusals } from './override-declarations.js';
17+
import { installedManifestsOf } from '@objectstack/metadata-core';
1718

1819
const BASE = 'com.acme.crm';
1920
const PAIR = 'com.acme.crm.custom';
@@ -33,7 +34,7 @@ const base = pkg(BASE, [], {
3334
});
3435

3536
const judged = (type: string, name: string, packageId: string, item: unknown, dependencies: string[], shippers: string[]) => {
36-
const v = judgeOverrideWrite({ type, name, packageId, item }, { dependencies, shippers });
37+
const v = judgeOverrideWrite({ type, name, packageId, item }, { dependencies, shippers, installed: installedManifestsOf(undefined) });
3738
if (v.verdict !== 'refuse') throw new Error(`expected a refusal, got ${v.verdict}`);
3839
return v.message;
3940
};

‎packages/cli/src/utils/override-declarations.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
import { judgeOverrideWrite, overrideWriteItemsOf, type OverrideWriteItem } from '@objectstack/metadata-protocol';
4040
import { OverrideDeclarationSchema } from '@objectstack/spec/kernel';
41+
import type { InstalledManifestLookup } from '@objectstack/metadata-core';
4142

4243
import { artifactPackages } from './artifact-packages.js';
4344

@@ -56,6 +57,8 @@ export interface OverrideDeclarationRefusalRow {
5657

5758
interface WalkedPackage {
5859
id: string;
60+
/** The package's manifest as the artifact carries it. */
61+
manifest: Record<string, unknown> | undefined;
5962
dependencies: string[];
6063
items: OverrideWriteItem[];
6164
}
@@ -75,14 +78,15 @@ function packagesOf(parsed: Record<string, unknown>): WalkedPackage[] {
7578
if (entries.length > 0) {
7679
return entries.map(({ index, id, body }) => ({
7780
id,
81+
manifest: body,
7882
dependencies: dependencyIds(body),
7983
items: overrideWriteItemsOf(body, `packages[${index}].manifest.`),
8084
}));
8185
}
8286
const manifest = isRecord(parsed.manifest) ? parsed.manifest : undefined;
8387
const id = typeof manifest?.id === 'string' && manifest.id !== '' ? manifest.id : undefined;
8488
if (id === undefined) return [];
85-
return [{ id, dependencies: dependencyIds(manifest), items: overrideWriteItemsOf(parsed, '') }];
89+
return [{ id, manifest, dependencies: dependencyIds(manifest), items: overrideWriteItemsOf(parsed, '') }];
8690
}
8791

8892
/** `id`'s dependency closure, followed through the packages this artifact carries. */
@@ -107,6 +111,9 @@ export function findOverrideDeclarationRefusals(parsed: Record<string, unknown>)
107111
const packages = packagesOf(parsed);
108112
const byId = new Map(packages.map((p) => [p.id, p]));
109113
const shipped = new Map(packages.map((p) => [p.id, new Set(p.items.map((i) => `${i.type}\u0000${i.identity}`))]));
114+
// The manifests this artifact carries, as the pair lookup reads installed
115+
// ones: who may declare an override of a base is its App's pair.
116+
const installed: InstalledManifestLookup = (packageId) => byId.get(packageId)?.manifest;
110117
const rows: OverrideDeclarationRefusalRow[] = [];
111118
for (const pkg of packages) {
112119
const dependencies = closureOf(pkg.id, byId);
@@ -133,7 +140,7 @@ export function findOverrideDeclarationRefusals(parsed: Record<string, unknown>)
133140
(byId.get(baseId)?.items ?? []).filter((i) => i.type === walked.type).map((i) => i.item);
134141
const verdict = judgeOverrideWrite(
135142
{ type: walked.type, name: walked.name, packageId: pkg.id, item: walked.item },
136-
{ dependencies, shippers, baseItemOf, baseItemsOf },
143+
{ dependencies, shippers, baseItemOf, baseItemsOf, installed },
137144
);
138145
if (verdict.verdict !== 'refuse') continue;
139146
rows.push({ path: walked.path, code: 'NOT_OVERRIDABLE', rule: verdict.rule, packageId: pkg.id, message: verdict.message });

‎packages/cloud-connection/src/marketplace-install-local-override-gate.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import '@objectstack/runtime';
3232
import { judgeOverrideWrite } from '@objectstack/metadata-protocol';
3333
import { MarketplaceInstallLocalPlugin } from './marketplace-install-local-plugin.js';
3434
import { installerAuthService, withInstallerGrants } from './install-local-principal.fixtures.js';
35+
import { installedManifestsOf } from '@objectstack/metadata-core';
3536

3637
type Handler = (c: any) => Promise<any>;
3738

@@ -163,7 +164,7 @@ describe('install-local 2d — the override write gate at the managed install (A
163164
expect(res.payload?.error?.code).toBe('NOT_OVERRIDABLE');
164165
const verdict = judgeOverrideWrite(
165166
{ type: 'dashboard', name: 'crm_board', packageId: PARTNER, item },
166-
{ dependencies: [BASE], shippers: [BASE] },
167+
{ dependencies: [BASE], shippers: [BASE], installed: installedManifestsOf(undefined) },
167168
);
168169
expect(res.payload.error.details.refusals).toEqual([
169170
{ type: 'dashboard', name: 'crm_board', rule: 'undeclared_same_name', message: (verdict as any).message },

‎packages/cloud-connection/src/marketplace-install-local-plugin.ts‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,10 @@ import {
237237
fieldPatchTargetRefusals,
238238
fieldPatchTargetRefusalMessage,
239239
type FieldPatchTargetRefusal,
240+
// [ADR-0146 D3 · ruling record 6691022506] The installed manifests the
241+
// override gate's pair lookup reads.
242+
installedManifestsOf,
243+
type InstalledManifestLookup,
240244
} from '@objectstack/metadata-core';
241245
import { resolveCloudUrl } from './cloud-url.js';
242246
import { resolveMarketplacePublicBaseUrl } from './marketplace-public-url.js';
@@ -3803,7 +3807,7 @@ export class MarketplaceInstallLocalPlugin implements Plugin {
38033807
// each under its own id. A delivered package is in no registry yet: its
38043808
// dependencies and its items are read off the body, and it registers
38053809
// read-only, so it is a base a sibling's closure can hold.
3806-
const delivered = new Map<string, { dependencies: string[]; items: OverrideWriteItem[] }>();
3810+
const delivered = new Map<string, { manifest: unknown; dependencies: string[]; items: OverrideWriteItem[] }>();
38073811
const entries: Record<string, any>[] = Array.isArray(converted.packages)
38083812
? converted.packages
38093813
.map((entry: unknown) => (isPlainObject(entry) && isPlainObject(entry.manifest) ? entry.manifest : undefined))
@@ -3812,8 +3816,17 @@ export class MarketplaceInstallLocalPlugin implements Plugin {
38123816
for (const body of entries) {
38133817
const id = entries.length === 1 && !Array.isArray(converted.packages) ? manifestId : manifestIdOf(body);
38143818
if (typeof id !== 'string' || id === '') continue;
3815-
delivered.set(id, { dependencies: dependencyIdsOf(declaredPackageManifest(body)), items: overrideWriteItemsOf(body) });
3819+
const manifest = declaredPackageManifest(body);
3820+
delivered.set(id, { manifest, dependencies: dependencyIdsOf(manifest), items: overrideWriteItemsOf(body) });
38163821
}
3822+
// The manifests the pair lookup reads: a delivered package's own,
3823+
// else the installed one — who may declare an override of a base is
3824+
// its App's pair (`pairOf`).
3825+
const installedRegistry = installedManifestsOf(registry);
3826+
const manifestOf: InstalledManifestLookup = (id) => {
3827+
const local = delivered.get(id)?.manifest;
3828+
return isPlainObject(local) ? local : installedRegistry(id);
3829+
};
38173830
const dependenciesOf = (id: string): string[] => delivered.get(id)?.dependencies
38183831
?? dependencyIdsOf((registry.getPackage?.(id) as { manifest?: unknown } | undefined)?.manifest);
38193832
const closureOf = (id: string): string[] => {
@@ -3892,7 +3905,10 @@ export class MarketplaceInstallLocalPlugin implements Plugin {
38923905
}
38933906
const verdict = judgeOverrideWrite(
38943907
{ type: item.type, name: item.name, packageId, item: item.item },
3895-
{ dependencies: closure, shippers, baseItemOf: (base) => shipped.get(base), baseItemsOf: (base) => listed.get(base) ?? [] },
3908+
{
3909+
dependencies: closure, shippers, baseItemOf: (base) => shipped.get(base),
3910+
baseItemsOf: (base) => listed.get(base) ?? [], installed: manifestOf,
3911+
},
38963912
);
38973913
if (verdict.verdict === 'refuse') {
38983914
refusals.push({
@@ -3918,7 +3934,7 @@ export class MarketplaceInstallLocalPlugin implements Plugin {
39183934
if (holding === undefined) continue;
39193935
const verdict = judgeOverrideWrite(
39203936
{ type: item.type, name: item.name, packageId: dependent, item: holding },
3921-
{ dependencies: dependentClosure, shippers: [baseId] },
3937+
{ dependencies: dependentClosure, shippers: [baseId], installed: manifestOf },
39223938
);
39233939
if (verdict.verdict === 'refuse') {
39243940
collisions.push({ type: item.type, name: item.name, packageId: dependent, rule: verdict.rule, message: verdict.message });

‎packages/lint/src/validate-customization-namespace.ts‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
*
3434
* ## Not judged here
3535
*
36-
* - A package that is itself a pair (`customizationPackageId` answers
37-
* `base_is_customization_package`): a pair is never paired again, and its
36+
* - A package that is itself a pair (`isCustomizationPackage`, the one
37+
* spelling of "some base derives this id"): a pair is never paired again, and its
3838
* namespace is the pair namespace, longer than a base's by construction.
3939
* - The helper's other two refusals. A missing namespace is not this rule's
4040
* question, and a namespace the manifest grammar refuses for another reason
@@ -53,7 +53,7 @@ import {
5353
CUSTOMIZATION_NAMESPACE_SUFFIX,
5454
MAX_CUSTOMIZATION_BASE_NAMESPACE_LENGTH,
5555
customizationNamespace,
56-
customizationPackageId,
56+
isCustomizationPackage,
5757
} from '@objectstack/spec/kernel';
5858

5959
import type { AnyRec } from './page-walk.js';
@@ -105,8 +105,7 @@ export function validateCustomizationNamespace(stack: AnyRec): CustomizationName
105105
if (!isRec(stack)) return findings;
106106

107107
for (const { manifest, at } of deliveredManifests(stack)) {
108-
const pairId = customizationPackageId(manifest.id);
109-
if (!pairId.ok && pairId.reason === 'base_is_customization_package') continue;
108+
if (isCustomizationPackage(manifest.id)) continue;
110109

111110
const pairNamespace = customizationNamespace(manifest.namespace);
112111
if (pairNamespace.ok || pairNamespace.reason !== 'base_namespace_too_long') continue;

‎packages/metadata-core/src/customization-pair-lookup.test.ts‎

Lines changed: 70 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,43 @@
22

33
import { describe, expect, it } from 'vitest';
44
import { customizationPackageId, isCustomizationPairOf } from '@objectstack/spec/kernel';
5-
import { appOf, isPairOf, pairOf } from './customization-pair-lookup.js';
5+
import {
6+
appOf,
7+
installedManifestsOf,
8+
isPairOf,
9+
pairOf,
10+
type InstalledManifestLookup,
11+
} from './customization-pair-lookup.js';
612

713
/**
814
* The lookup answers exactly what the pure id rule answered for every package
915
* shape on `main` — an App, a module its artifact brings, a standalone
1016
* package, a `sys` kernel package, a manifest with no namespace — because
1117
* `appOf` is the identity until the ensure door resolves a member to its App.
1218
* Each row pins the literal pair, so a resolver that moves one package to
13-
* another App reds that row by name. The rows' `type`, `scope` and `namespace`
14-
* are read by nothing today: they are the App resolver's inputs when it lands.
19+
* another App reds that row by name. Every row is asked twice: with nothing
20+
* installed, and with all the rows installed — the module declaring its App
21+
* the way HotCRM's modules do — so the lookup the callers now hand in is
22+
* proven to move nothing while `appOf` stays the identity.
1523
*/
16-
const ROWS: ReadonlyArray<{ shape: string; manifest: { id: string; type?: string; scope?: string; namespace?: string }; pair: string }> = [
24+
const ROWS: ReadonlyArray<{
25+
shape: string;
26+
manifest: { id: string; type?: string; scope?: string; namespace?: string; dependencies?: Record<string, string> };
27+
pair: string;
28+
}> = [
1729
{
1830
shape: 'an App package',
1931
manifest: { id: 'app.objectstack.hotcrm', type: 'app', namespace: 'crm' },
2032
pair: 'app.objectstack.hotcrm.custom',
2133
},
2234
{
2335
shape: 'a module an App artifact brings (still its own pair today)',
24-
manifest: { id: 'app.objectstack.hotcrm.service', type: 'module', namespace: 'crm' },
36+
manifest: {
37+
id: 'app.objectstack.hotcrm.service',
38+
type: 'module',
39+
namespace: 'crm',
40+
dependencies: { 'app.objectstack.hotcrm': '^6.1.0' },
41+
},
2542
pair: 'app.objectstack.hotcrm.service.custom',
2643
},
2744
{
@@ -41,11 +58,43 @@ const ROWS: ReadonlyArray<{ shape: string; manifest: { id: string; type?: string
4158
},
4259
];
4360

61+
const NOTHING_INSTALLED = installedManifestsOf(undefined);
62+
const ALL_INSTALLED = installedManifestsOf({
63+
getPackage: (id: string) => {
64+
const row = ROWS.find((r) => r.manifest.id === id);
65+
return row ? { manifest: row.manifest } : undefined;
66+
},
67+
});
68+
const LOOKUPS: ReadonlyArray<{ installed: string; lookup: InstalledManifestLookup }> = [
69+
{ installed: 'nothing installed', lookup: NOTHING_INSTALLED },
70+
{ installed: 'every row installed', lookup: ALL_INSTALLED },
71+
];
72+
const ROWS_BY_LOOKUP = LOOKUPS.flatMap(({ installed, lookup }) => ROWS.map((row) => ({ ...row, installed, lookup })));
73+
74+
describe('installedManifestsOf — the registry read the lookup is', () => {
75+
it('reads the installed manifest by id, and nothing for an id not installed', () => {
76+
const service = ROWS[1]!.manifest;
77+
expect(ALL_INSTALLED(service.id)).toBe(service);
78+
expect(ALL_INSTALLED('com.example.absent')).toBeUndefined();
79+
});
80+
81+
it.each([
82+
{ source: 'no registry', registry: undefined },
83+
{ source: 'a null registry', registry: null },
84+
{ source: 'a registry with no getPackage', registry: {} },
85+
{ source: 'a package with no manifest', registry: { getPackage: () => ({}) } },
86+
{ source: 'a manifest that is not an object', registry: { getPackage: () => ({ manifest: 'app' }) } },
87+
{ source: 'a null manifest', registry: { getPackage: () => ({ manifest: null }) } },
88+
])('answers undefined for $source', ({ registry }) => {
89+
expect(installedManifestsOf(registry)('app.objectstack.hotcrm')).toBeUndefined();
90+
});
91+
});
92+
4493
describe('pairOf — the pair of a package, looked up through its App', () => {
45-
it.each(ROWS)('$shape: answers the old derivation, $pair', ({ manifest, pair }) => {
46-
expect(appOf(manifest.id)).toBe(manifest.id);
47-
expect(pairOf(manifest.id)).toEqual(customizationPackageId(manifest.id));
48-
expect(pairOf(manifest.id)).toEqual({ ok: true, value: pair });
94+
it.each(ROWS_BY_LOOKUP)('$shape, $installed: answers the old derivation, $pair', ({ manifest, pair, lookup }) => {
95+
expect(appOf(manifest.id, lookup)).toBe(manifest.id);
96+
expect(pairOf(manifest.id, lookup)).toEqual(customizationPackageId(manifest.id));
97+
expect(pairOf(manifest.id, lookup)).toEqual({ ok: true, value: pair });
4998
});
5099

51100
it.each([
@@ -55,24 +104,26 @@ describe('pairOf — the pair of a package, looked up through its App', () => {
55104
{ input: 'hotcrm.custom', reason: 'base_is_customization_package' },
56105
{ input: 'Com.Acme', reason: 'base_id_invalid' },
57106
])('refuses $input as the id rule does: $reason', ({ input, reason }) => {
58-
expect(pairOf(input)).toEqual(customizationPackageId(input));
59-
expect(pairOf(input)).toEqual({ ok: false, reason });
107+
for (const { lookup } of LOOKUPS) {
108+
expect(pairOf(input, lookup)).toEqual(customizationPackageId(input));
109+
expect(pairOf(input, lookup)).toEqual({ ok: false, reason });
110+
}
60111
});
61112
});
62113

63114
describe('isPairOf — is this THE pair of that package', () => {
64-
it.each(ROWS)('$shape: only $pair is its pair', ({ manifest, pair }) => {
115+
it.each(ROWS_BY_LOOKUP)('$shape, $installed: only $pair is its pair', ({ manifest, pair, lookup }) => {
65116
const candidates = [pair, manifest.id, `${pair}.custom`, 'app.objectstack.hotcrm.custom', 'partner.ext', null, undefined];
66117
for (const candidate of candidates) {
67-
expect(isPairOf(candidate, manifest.id)).toBe(isCustomizationPairOf(candidate, manifest.id));
118+
expect(isPairOf(candidate, manifest.id, lookup)).toBe(isCustomizationPairOf(candidate, manifest.id));
68119
}
69-
expect(isPairOf(pair, manifest.id)).toBe(true);
70-
expect(isPairOf(manifest.id, manifest.id)).toBe(false);
120+
expect(isPairOf(pair, manifest.id, lookup)).toBe(true);
121+
expect(isPairOf(manifest.id, manifest.id, lookup)).toBe(false);
71122
});
72123

73-
it('a pair has no pair, and a missing base has none', () => {
74-
expect(isPairOf('hotcrm.custom.custom', 'hotcrm.custom')).toBe(false);
75-
expect(isPairOf('.custom', '')).toBe(false);
76-
expect(isPairOf('x.custom', undefined)).toBe(false);
124+
it.each(LOOKUPS)('$installed: a pair has no pair, and a missing base has none', ({ lookup }) => {
125+
expect(isPairOf('hotcrm.custom.custom', 'hotcrm.custom', lookup)).toBe(false);
126+
expect(isPairOf('.custom', '', lookup)).toBe(false);
127+
expect(isPairOf('x.custom', undefined, lookup)).toBe(false);
77128
});
78129
});

0 commit comments

Comments
 (0)