Skip to content

Commit f714cf0

Browse files
committed
fix(runtime): publish-drafts asks for an unknown package after the capability probe; fixtures install the packages they name
A host whose protocol cannot publish answers 501 whatever id it is asked about, as discard-drafts and the commit trail do. The runtime and rest fixtures that save into a package now install it first, as a boot or POST /packages does. Claude-Session: https://claude.ai/code/session_01FEkQ5nhhuhjVQJ8R3qK9UB Co-authored-by: Claude <noreply@anthropic.com>
1 parent 6f9228c commit f714cf0

16 files changed

Lines changed: 115 additions & 14 deletions

‎packages/rest/src/meta-delete-drop-storage-other-rows.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ async function boot(environmentId?: string) {
9898
engine.registry.registerObject(SysMetadataHistoryObject as any, TEST_PACKAGE_ID);
9999
engine.registry.registerObject(SysMetadataAuditObject as any, TEST_PACKAGE_ID);
100100
await engine.syncSchemas();
101+
// [#26708] The authored packages the saves below name are installed: a save
102+
// naming a package no installed package has is refused before it is written.
103+
for (const id of [P, Q]) engine.registry.installPackage({ id, name: id, version: '1.0.0' } as any, 'authored');
101104
// A real `single` install's Default Organization: the system writes below
102105
// derive it (ADR-0131 D9), as a fresh NOT NULL tenant column requires (D1).
103106
await installDefaultOrganization(engine);

‎packages/rest/src/meta-draft-head-package-inheritance.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,15 @@ async function boot(opts: { item?: { type: string; name: string }; permissions?:
113113
engine.registry.registerObject(SysMetadataHistoryObject as any, TEST_PACKAGE_ID);
114114
engine.registry.registerObject(SysMetadataAuditObject as any, TEST_PACKAGE_ID);
115115
await engine.syncSchemas();
116+
// [#26708] The packages the saves below name are installed, as authored
117+
// bases that bind this file's `task` object: a save naming a package no
118+
// installed package has is refused, and an installed package's write is
119+
// judged against its declared closure.
120+
for (const id of [PKG, 'com.probe.other', 'com.probe.q', 'com.probe.r']) {
121+
engine.registry.installPackage({
122+
id, name: id, version: '1.0.0', dependencies: { [TEST_PACKAGE_ID]: '*' },
123+
} as any, 'authored');
124+
}
116125

117126
const protocol = new ObjectStackProtocolImplementation(engine as any);
118127
const config = { api: { requireAuth: false }, metadata: { enableCache: false } };

‎packages/rest/src/meta-object-owd-gate.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ async function boot(opts: { channel?: MetadataAuthoringChannel; envWritableObjec
196196
objects: [SysMetadata, SysMetadataHistoryObject, SysMetadataAuditObject],
197197
});
198198
engine.registry.registerObject(PACKAGED_ACCOUNT as any, 'demo_pkg');
199+
// [#26708] The package the `?package=demo_pkg` door names is installed: a
200+
// save naming a package no installed package has is refused before the lint
201+
// door this file pins.
202+
engine.registry.installPackage({ id: 'demo_pkg', name: 'demo_pkg', version: '1.0.0' } as any, 'authored');
199203
await engine.syncSchemas();
200204

201205
const protocol = channel === undefined

‎packages/rest/src/meta-published-overlay.test.ts‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ import { MetadataManager } from '@objectstack/metadata';
4747
import { ObjectStackProtocolImplementation } from '@objectstack/metadata-protocol';
4848
import { RestServer } from './rest-server.js';
4949

50+
/**
51+
* [#26708] The packages this file's saves name, installed: a save naming a
52+
* package no installed package has is refused (`WRITABLE_PACKAGE_REQUIRED`)
53+
* before any gate this file pins is reached. Each answers a manifest that
54+
* declares no dependencies, as an authored base does.
55+
*/
56+
const INSTALLED_PACKAGES: ReadonlySet<string> = new Set(['app.projects']);
57+
const installedPackage = (id: string) => (INSTALLED_PACKAGES.has(id) ? { manifest: { id } } : undefined);
58+
59+
5060
const PUBLISHED = '/api/v1/meta/:type/:name/published';
5161

5262
interface Row {
@@ -144,7 +154,7 @@ function makeStubEngine(opts: { failSysMetadataReads?: Error } = {}) {
144154
registerItem: () => {},
145155
registerObject: () => {},
146156
getItem: () => undefined,
147-
getPackage: () => undefined,
157+
getPackage: installedPackage,
148158
},
149159
};
150160
return { engine, rows };
@@ -510,7 +520,7 @@ describe('[#21002] the published door follows the layered read for a shipped flo
510520
engine.registry = {
511521
registerItem: () => {},
512522
registerObject: () => {},
513-
getPackage: () => undefined,
523+
getPackage: installedPackage,
514524
getItem: (type: string, name: string) =>
515525
(type === 'flow' || type === 'flows') && name === SHIPPED ? loaderEntry : undefined,
516526
};
@@ -639,7 +649,7 @@ describe('[#21986] the published door serves a code-defined datasource\'s code d
639649
engine.registry = {
640650
registerItem: () => {},
641651
registerObject: () => {},
642-
getPackage: () => undefined,
652+
getPackage: installedPackage,
643653
getItem: () => undefined,
644654
getAllPackages: () => [{
645655
manifest: {

‎packages/rest/src/rest-meta-packaged-action-permission-refusal.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ function boot(environmentId: string | undefined = 'env_1') {
7373
registry.registerItem('action', { name, label: 'Approve', type: 'script', target: 'approve_fn' }, 'name', PACKAGE_ID);
7474
}
7575
registry.registerItem('permission', { name: PACKAGED_PERMISSION, label: 'Contributor', objects: {} }, 'name', PACKAGE_ID);
76+
// [#26708] The loaded package is installed too, as `registerApp` installs
77+
// it: a save naming a package no installed package has is refused before
78+
// the lock this file pins.
79+
registry.installPackage({ id: PACKAGE_ID, name: PACKAGE_ID, version: '1.0.0', type: 'app' } as never, 'code');
7680
const protocol = new ObjectStackProtocolImplementation(
7781
{ registry, findOne: async () => null, manifests: new Map([[PACKAGE_ID, {}]]) } as never,
7882
() => new Map(), environmentId,

‎packages/runtime/src/domains/meta-package-all-fold.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,14 @@ async function bootStore() {
103103
engine.registry.registerObject(SysMetadataHistoryObject as any, TEST_PACKAGE_ID);
104104
engine.registry.registerObject(SysMetadataAuditObject as any, TEST_PACKAGE_ID);
105105
await engine.syncSchemas();
106+
// [#26708] Both packages the seeds name are installed, as authored bases
107+
// that bind this file's `task` object: a save naming a package no installed
108+
// package has is refused before it is written.
109+
for (const id of [PROBE_PKG, OTHER_PKG]) {
110+
engine.registry.installPackage({
111+
id, name: id, version: '1.0.0', dependencies: { [TEST_PACKAGE_ID]: '*' },
112+
} as any, 'authored');
113+
}
106114
const protocol = new ObjectStackProtocolImplementation(engine as any);
107115
const seed = (type: string, name: string, item: unknown, packageId?: string) =>
108116
protocol.saveMetaItem({ type, name, item, ...(packageId ? { packageId } : {}) } as any);

‎packages/runtime/src/domains/meta-published-runtime-publish.test.ts‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ import { MetadataManager } from '@objectstack/metadata';
3838
import { ObjectStackProtocolImplementation } from '@objectstack/metadata-protocol';
3939
import { HttpDispatcher } from '../http-dispatcher.js';
4040

41+
/**
42+
* [#26708] The packages this file's saves name, installed: a save naming a
43+
* package no installed package has is refused (`WRITABLE_PACKAGE_REQUIRED`)
44+
* before any gate this file pins is reached. Each answers a manifest that
45+
* declares no dependencies, as an authored base does.
46+
*/
47+
const INSTALLED_PACKAGES: ReadonlySet<string> = new Set(['app.projects']);
48+
const installedPackage = (id: string) => (INSTALLED_PACKAGES.has(id) ? { manifest: { id } } : undefined);
49+
50+
4151
interface Row {
4252
id: string;
4353
type: string;
@@ -131,7 +141,7 @@ function makeStubEngine() {
131141
registerItem: () => {},
132142
registerObject: () => {},
133143
getItem: () => undefined,
134-
getPackage: () => undefined,
144+
getPackage: installedPackage,
135145
},
136146
};
137147
return { engine, rows };
@@ -360,7 +370,7 @@ describe('[#21002] the dispatcher published door follows the layered read for a
360370
engine.registry = {
361371
registerItem: () => {},
362372
registerObject: () => {},
363-
getPackage: () => undefined,
373+
getPackage: installedPackage,
364374
getItem: (type: string, name: string) =>
365375
(type === 'flow' || type === 'flows') && name === SHIPPED ? loaderEntry : undefined,
366376
};
@@ -491,7 +501,7 @@ describe('[#21986] the dispatcher published door serves a code-defined datasourc
491501
engine.registry = {
492502
registerItem: () => {},
493503
registerObject: () => {},
494-
getPackage: () => undefined,
504+
getPackage: installedPackage,
495505
getItem: () => undefined,
496506
getAllPackages: () => [{
497507
manifest: {

‎packages/runtime/src/domains/packages-seed-apply-org-scope.test.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ import { ObjectStackProtocolImplementation } from '@objectstack/metadata-protoco
8585
import { DEFAULT_METADATA_TYPE_REGISTRY } from '@objectstack/spec/kernel';
8686
import { HttpDispatcher } from '../http-dispatcher.js';
8787

88+
/**
89+
* [#26708] The packages this file's saves name, installed: a save naming a
90+
* package no installed package has is refused (`WRITABLE_PACKAGE_REQUIRED`)
91+
* before any gate this file pins is reached. Each answers a manifest that
92+
* declares no dependencies, as an authored base does.
93+
*/
94+
const INSTALLED_PACKAGES: ReadonlySet<string> = new Set(['com.workspace']);
95+
const installedPackage = (id: string) => (INSTALLED_PACKAGES.has(id) ? { manifest: { id } } : undefined);
96+
97+
8898
const ORG = 'org_acme';
8999
const PKG = 'com.workspace';
90100
const SEED = 'project_seed';
@@ -155,7 +165,7 @@ function makeEngine() {
155165
listItems: () => [],
156166
getItem: () => undefined,
157167
getObject: () => undefined,
158-
getPackage: () => undefined,
168+
getPackage: installedPackage,
159169
getArtifactItem: () => undefined,
160170
getAllPackages: () => [],
161171
isPackageDisabled: () => false,

‎packages/runtime/src/domains/packages-seed-apply-read-decorations.test.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,16 @@ import { SeedSchema } from '@objectstack/spec/data';
9494
import { SeedLoaderService } from '../seed-loader.js';
9595
import { HttpDispatcher } from '../http-dispatcher.js';
9696

97+
/**
98+
* [#26708] The packages this file's saves name, installed: a save naming a
99+
* package no installed package has is refused (`WRITABLE_PACKAGE_REQUIRED`)
100+
* before any gate this file pins is reached. Each answers a manifest that
101+
* declares no dependencies, as an authored base does.
102+
*/
103+
const INSTALLED_PACKAGES: ReadonlySet<string> = new Set(['com.workspace']);
104+
const installedPackage = (id: string) => (INSTALLED_PACKAGES.has(id) ? { manifest: { id } } : undefined);
105+
106+
97107
const PKG = 'com.workspace';
98108
const SEED = 'project_seed';
99109

@@ -168,7 +178,7 @@ function makeEngine() {
168178
listItems: () => [],
169179
getItem: () => undefined,
170180
getObject: () => undefined,
171-
getPackage: () => undefined,
181+
getPackage: installedPackage,
172182
getArtifactItem: () => undefined,
173183
getAllPackages: () => [],
174184
isPackageDisabled: () => false,

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,13 +1706,15 @@ export async function handlePackagesRequest(deps: DomainHandlerDeps, path: strin
17061706
// [ADR-0131 D12 items 7–8] Under a wall, the platform operator's.
17071707
const walled = await refuseWalledCatalogPackageWrite(deps, _context, `Publishing the drafts of package "${id}"`);
17081708
if (walled) return walled;
1709-
// [#26708] An id no installed package has is refused BEFORE
1710-
// anything is published — see `packageIsUnknown`.
1711-
if (packageIsUnknown(registry, id)) {
1712-
return { handled: true, response: deps.error(`Package '${id}' not found`, 404) };
1713-
}
17141709
const protocol = await resolveProtocol(deps, _context);
17151710
if (protocol && typeof protocol.publishPackageDrafts === 'function') {
1711+
// [#26708] An id no installed package has is refused BEFORE
1712+
// anything is published — see `packageIsUnknown`. After the
1713+
// capability probe, as its siblings: a host that cannot
1714+
// publish answers 501 whatever id it is asked about.
1715+
if (packageIsUnknown(registry, id)) {
1716+
return { handled: true, response: deps.error(`Package '${id}' not found`, 404) };
1717+
}
17161718
try {
17171719
const result = await protocol.publishPackageDrafts({
17181720
packageId: id,

0 commit comments

Comments
 (0)