Skip to content

Commit 8f56596

Browse files
committed
fix(objectql): record a versioned app's in-place stamp, and refuse a nested plugin's stamp before the parent registers
The app paths read the stamp before stampPackage, the order the collection and seed loops keep, so the registration-written exemption holds for a versioned registration too. registerApp's pre-pass walks manifest.plugins[] (objects and plugin-as-app), so a nested plugin's foreign stamp is refused before anything of the parent body registers. The changeset states the upgrade behaviour. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5pevHhCDHNc3eWbkAg
1 parent 7e796f0 commit 8f56596

4 files changed

Lines changed: 69 additions & 25 deletions

File tree

‎.changeset/28697-object-app-owner-stamp-refused.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Metadata-protocol: narrowed (an object's or app's `_packageId`, declared by `Met
2222
**BREAKING** accept-set narrowing at package registration and the build door (`@objectstack/objectql`, `@objectstack/metadata`, `@objectstack/spec`), shipped as `minor`.
2323

2424
- **Before.** An installed manifest `com.acme.app` whose `apps[0]` carried `_packageId: 'com.acme.host'` registered the app filed under the host. `GET /api/v1/meta/app?package=com.acme.host` listed it, `?package=com.acme.app` listed nothing, and disabling `com.acme.app` kept serving the app while its objects answered 404. An object's body stamp was kept on its definition.
25-
- **Now.** The registration throws before anything of the package registers. Through `POST /api/v1/marketplace/install-local`, an inline install answers `422 PLUGIN_REGISTER_FAILED` with that message and persists nothing. `defineStack` / `os validate` report the same stamp as an issue at `objects.N._packageId` or `apps.N._packageId`.
25+
- **Now.** The registration throws before anything of the package registers. Through `POST /api/v1/marketplace/install-local`, an inline install answers `422 PLUGIN_REGISTER_FAILED` with that message and persists nothing. `defineStack` / `os validate` report the same stamp as an issue at `objects.N._packageId` or `apps.N._packageId`. On upgrade, a config boot whose stack carries such a stamp fails to start with the judge's message, and a package installed earlier that carries one is not loaded at the next start and is reported at `error`.
2626
- **Unchanged.** An absent `_packageId`, or one equal to the registering package, registers as before. An app object that an earlier registration stamped in place, such as a module constant handed to a second registration, registers as it always has. `objectExtensions` are not judged.
2727
- **Who sees it.** Only someone who hand-writes `_packageId` on an object or app naming another package. No build, export or install writes one.
2828

‎packages/objectql/src/engine-package-registration.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@
3939
* never copied. Nothing re-exports them from the package entry, so the
4040
* published surface does not move. [#28697] Two more follow the same rule:
4141
* `packageBodyObjectAndAppOwnerStampRefusal` and `registerAppNotingStamp`
42-
* (`registerApp` and `registerPlugin`).
42+
* (`registerApp` and `registerPlugin`); the plugin-as-app now reaches
43+
* `stampPackage` through `registerAppNotingStamp`, so this module no longer
44+
* imports `stampPackage` itself.
4345
*
4446
* That import is a run-time module cycle (`engine.ts` imports this module,
4547
* this module imports `engine.ts`). Nothing here runs at module evaluation,
@@ -56,7 +58,6 @@ import {
5658
packageBodyObjectAndAppOwnerStampRefusal,
5759
registerAppNotingStamp,
5860
stampObjectPackage,
59-
stampPackage,
6061
} from './engine.js';
6162
import type { ObjectQL } from './engine.js';
6263

@@ -191,7 +192,7 @@ export function registerPlugin(
191192
if (plugin.name && plugin.navigation) {
192193
try {
193194
const resolved = pluginNamespace ? this.resolveNavObjectNames(plugin, pluginNamespace) : plugin;
194-
registerAppNotingStamp(this._registry, stampPackage(resolved, ownerId, parentVersion), ownerId);
195+
registerAppNotingStamp(this._registry, resolved, ownerId, parentVersion);
195196
this.logger.debug('Registered plugin-as-app', { app: plugin.name, from: pluginName });
196197
} catch (err: any) {
197198
this.logger.warn('Failed to register plugin as app', { pluginName, error: err.message });

‎packages/objectql/src/engine.ts‎

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4987,15 +4987,23 @@ export function packageBodyObjectAndAppOwnerStampRefusal(
49874987
}
49884988

49894989
/**
4990-
* [#28697] Register an app object through the registry's app verb, recording
4991-
* the stamp the registration writes onto the caller's own object
4992-
* ({@link noteRegistrationStamp}): `registerItem` stamps the object in place,
4993-
* so a module constant handed to a second registration arrives wearing the
4994-
* first one's stamp, which no body wrote.
4990+
* [#28697] Stamp an app object ({@link stampPackage}) and register it through
4991+
* the registry's app verb, recording the stamp the registration writes onto
4992+
* the caller's own object ({@link noteRegistrationStamp}): `stampPackage` (with
4993+
* a version) and `registerItem` (without one) stamp the object in place, so a
4994+
* module constant handed to a second registration arrives wearing the first
4995+
* one's stamp, which no body wrote. The stamp before is read BEFORE
4996+
* `stampPackage`, the order the collection and seed loops keep, so a versioned
4997+
* registration is recorded too.
49954998
*/
4996-
export function registerAppNotingStamp(registry: SchemaRegistry, app: any, ownerId: string): void {
4999+
export function registerAppNotingStamp(
5000+
registry: SchemaRegistry,
5001+
app: any,
5002+
ownerId: string,
5003+
ownerVersion: string | undefined,
5004+
): void {
49975005
const stampBefore = (app as { _packageId?: unknown } | null | undefined)?._packageId;
4998-
registry.registerApp(app, ownerId);
5006+
registry.registerApp(stampPackage(app, ownerId, ownerVersion), ownerId);
49995007
noteRegistrationStamp(app, stampBefore);
50005008
}
50015009

@@ -9028,6 +9036,20 @@ export class ObjectQL implements IObjectQLEngine {
90289036
selfAsApp: Boolean(manifest.name && manifest.navigation && !manifest.apps?.length),
90299037
});
90309038
if (refusal) throw refusal;
9039+
// …and each nested plugin's objects and plugin-as-app (step 7, which
9040+
// registers them under this package after everything above), so a
9041+
// nested plugin's stamp is refused before this body registers too.
9042+
// `registerPlugin` asks the same of the plugin it is handed.
9043+
if (Array.isArray(manifest.plugins)) {
9044+
for (const plugin of manifest.plugins) {
9045+
if (!plugin || typeof plugin !== 'object') continue;
9046+
const nested = packageBodyObjectAndAppOwnerStampRefusal(plugin, id, {
9047+
apps: false,
9048+
selfAsApp: Boolean(plugin.name && plugin.navigation),
9049+
});
9050+
if (nested) throw nested;
9051+
}
9052+
}
90319053
}
90329054
this.invalidateSummaryIndex(); // new objects may add/change summary fields
90339055
this.logger.debug('Registering package manifest', { id, namespace });
@@ -9113,7 +9135,7 @@ export class ObjectQL implements IObjectQLEngine {
91139135
const appName = app.name || app.id;
91149136
if (appName) {
91159137
const resolved = namespace ? this.resolveNavObjectNames(app, namespace) : app;
9116-
registerAppNotingStamp(this._registry, stampPackage(resolved, id, version), id);
9138+
registerAppNotingStamp(this._registry, resolved, id, version);
91179139
this.logger.debug('Registered App', { app: appName, from: id });
91189140
}
91199141
}
@@ -9123,7 +9145,7 @@ export class ObjectQL implements IObjectQLEngine {
91239145
// This handles the case where the manifest IS the app definition (legacy/simple packages)
91249146
if (manifest.name && manifest.navigation && !manifest.apps?.length) {
91259147
const resolved = namespace ? this.resolveNavObjectNames(manifest, namespace) : manifest;
9126-
registerAppNotingStamp(this._registry, stampPackage(resolved, id, version), id);
9148+
registerAppNotingStamp(this._registry, resolved, id, version);
91279149
this.logger.debug('Registered manifest-as-app', { app: manifest.name, from: id });
91289150
}
91299151

‎packages/objectql/src/package-object-app-owner-stamp.test.ts‎

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,32 @@ describe('[#28697] registerApp refuses an app or object whose body `_packageId`
9595
expectRefused(register({ id: PKG, name: 'probe', objects: { probe_thing: unnamed }, apps: [app()] }), 'object', 'probe_thing');
9696
});
9797

98-
it('a nested plugin\'s object and plugin-as-app, judged against the parent package', () => {
99-
const r1 = register({ id: PKG, name: 'probe', plugins: [{ name: 'nested', objects: [object(HOST)] }] });
98+
it('a nested plugin\'s object and plugin-as-app, judged against the parent package before the PARENT registers anything', () => {
99+
// The parent carries an object and an app of its own, both unstamped:
100+
// the nested plugin's stamp is refused before either is registered.
101+
const parent = { id: PKG, name: 'probe', version: '1.0.0', objects: [object(undefined, 'parent_thing')], apps: [app(undefined, 'parent_app')] };
102+
const r1 = register({ ...parent, plugins: [{ name: 'nested', objects: [object(HOST)] }] });
100103
expect(r1.error).toMatchObject({ code: 'VALIDATION_ERROR', status: 400 });
101104
expect(r1.error.message).toContain("from object 'probe_thing'");
105+
expect(r1.pkg, 'refused before the parent\'s package record is written').toBeUndefined();
102106
expect(r1.objects).not.toContain('probe_thing');
103-
const r2 = register({ id: PKG, name: 'probe', plugins: [{ ...app(HOST, 'nested_app') }] });
107+
expect(r1.objects).not.toContain('parent_thing');
108+
expect(r1.apps).toEqual([]);
109+
const r2 = register({ ...parent, plugins: [{ ...app(HOST, 'nested_app') }] });
104110
expect(r2.error).toMatchObject({ code: 'VALIDATION_ERROR', status: 400 });
105111
expect(r2.error.message).toContain("from app 'nested_app'");
112+
expect(r2.pkg).toBeUndefined();
113+
expect(r2.objects).not.toContain('parent_thing');
106114
expect(r2.apps).toEqual([]);
107115
});
108116

117+
it('CONTROL: a nested plugin whose object and plugin-as-app stamp nothing registers under the parent', () => {
118+
const r = register({ id: PKG, name: 'probe', version: '1.0.0', plugins: [{ ...app(undefined, 'nested_app'), objects: [object()] }] });
119+
expect(r.error).toBeUndefined();
120+
expect(r.objects).toContain('probe_thing');
121+
expect(r.apps).toEqual([{ name: 'nested_app', _packageId: PKG }]);
122+
});
123+
109124
it('`null` and the empty string are stamps too', () => {
110125
for (const stamp of [null, '']) {
111126
const r = register({ id: PKG, name: 'probe', apps: [app(stamp)] });
@@ -124,15 +139,21 @@ describe('[#28697] registerApp refuses an app or object whose body `_packageId`
124139
});
125140

126141
it('CONTROL: one app object, stamped in place by a first registration, registers again under its own package and under another', () => {
127-
const shared = app();
128-
new ObjectQL().registerApp({ id: HOST, name: 'host', apps: [shared] } as any);
129-
expect((shared as { _packageId?: unknown })._packageId, 'the first registration stamped the caller\'s app').toBe(HOST);
130-
expect(register({ id: HOST, name: 'host', apps: [shared] }).error).toBeUndefined();
131-
// A module constant handed on: no body wrote that stamp.
132-
expect(register({ id: PKG, name: 'probe', apps: [shared] }).error).toBeUndefined();
133-
// The same bytes ARRIVING as a body are the body's own stamp.
134-
const arrived = register({ id: PKG, name: 'probe', apps: [JSON.parse(JSON.stringify(shared))] });
135-
expect(arrived.error).toMatchObject({ code: 'VALIDATION_ERROR', status: 400 });
142+
// Versioned and version-less registrations stamp the caller's app at
143+
// different points (`stampPackage` with a version, `registerItem`
144+
// without one); both stamps are the registration's, never a body's.
145+
for (const version of ['1.0.0', undefined]) {
146+
const label = `version ${String(version)}`;
147+
const shared = app();
148+
new ObjectQL().registerApp({ id: HOST, name: 'host', version, apps: [shared] } as any);
149+
expect((shared as { _packageId?: unknown })._packageId, `${label}: the first registration stamped the caller's app`).toBe(HOST);
150+
expect(register({ id: HOST, name: 'host', version, apps: [shared] }).error, label).toBeUndefined();
151+
// A module constant handed on: no body wrote that stamp.
152+
expect(register({ id: PKG, name: 'probe', version, apps: [shared] }).error, label).toBeUndefined();
153+
// The same bytes ARRIVING as a body are the body's own stamp.
154+
const arrived = register({ id: PKG, name: 'probe', version, apps: [JSON.parse(JSON.stringify(shared))] });
155+
expect(arrived.error, label).toMatchObject({ code: 'VALIDATION_ERROR', status: 400 });
156+
}
136157
});
137158
});
138159

0 commit comments

Comments
 (0)