|
40 | 40 | * answered before (#25366; its full matrix lives in |
41 | 41 | * `marketplace-install-local-catalog-name-collision.test.ts`); |
42 | 42 | * - CONTROL, the same package declaring a flow name nobody holds: `200`, |
43 | | - * `hotLoaded: true`, registered and ledgered. |
| 43 | + * `hotLoaded: true`, registered and ledgered; |
| 44 | + * - #31392, the namespace sibling: a fresh install and an upgrade declaring |
| 45 | + * the namespace the holder owns, with no dependency on it, answer the same |
| 46 | + * `422` with the registry's namespace sentence, nothing registered or |
| 47 | + * ledgered. Measured before the fix: `200`, `hotLoaded: false`, ledgered. |
| 48 | + * The `objectql` service hands the door the engine's `manifests`, so the |
| 49 | + * holder this door installed reads as a code package (step 1f's writable |
| 50 | + * base refusal is not this one). |
44 | 51 | * |
45 | 52 | * A register failure that is NOT a registry refusal keeps #22695's lenient |
46 | 53 | * answer; `marketplace-install-local-hot-loaded.test.ts` pins that. |
@@ -154,6 +161,10 @@ async function bootPlugin() { |
154 | 161 | objectql: withInstallerGrants({ |
155 | 162 | convertPackageBodyForward: (body: unknown) => ql.convertPackageBodyForward(body), |
156 | 163 | registry: ql.registry, |
| 164 | + // [#31392] The engine's registered code packages, read live, so a |
| 165 | + // package this door installed reads as code and not as a writable |
| 166 | + // base (`isWritablePackage`), as on the real `objectql` service. |
| 167 | + get manifests() { return (ql as unknown as { manifests: Map<string, unknown> }).manifests; }, |
157 | 168 | syncSchemas: async () => undefined, |
158 | 169 | }), |
159 | 170 | }; |
@@ -298,3 +309,57 @@ describe('install-local cloud branch refuses a package declaring a bare name ano |
298 | 309 | expectHolderFlowKept(ql); |
299 | 310 | }); |
300 | 311 | }); |
| 312 | + |
| 313 | +describe('install-local cloud branch refuses a package whose namespace another package owns, before any write (#31392)', () => { |
| 314 | + const versions = { |
| 315 | + // The holder's namespace (`dispatch`), under another id, with no dependency on it. |
| 316 | + 'v1-ns-held': packageVersion(INCOMING_ID, '1.0.0', [FREE_FLOW], { namespace: 'dispatch' }), |
| 317 | + 'v1-free': packageVersion(INCOMING_ID, '1.0.0', [FREE_FLOW]), |
| 318 | + 'v2-ns-held': packageVersion(INCOMING_ID, '2.0.0', [FREE_FLOW], { namespace: 'dispatch' }), |
| 319 | + }; |
| 320 | + |
| 321 | + function expectNamespaceRefusal(res: any) { |
| 322 | + expect(res.status, JSON.stringify(res.payload)).toBe(422); |
| 323 | + expect(BaseResponseSchema.safeParse(res.payload).success).toBe(true); |
| 324 | + expect(envelopeViolations(res.payload)).toEqual([]); |
| 325 | + expect(ApiErrorSchema.safeParse(res.payload.error).success).toBe(true); |
| 326 | + expect(res.payload.success).toBe(false); |
| 327 | + expect(res.payload.error.code).toBe('PLUGIN_REGISTER_FAILED'); |
| 328 | + // The registry's own sentence: the namespace, its owner, and the package it stopped. |
| 329 | + expect(res.payload.error.message).toContain(`namespace "dispatch" is already owned by package "${HOLDER_ID}"`); |
| 330 | + expect(res.payload.error.message).toContain(`package "${INCOMING_ID}" cannot be installed alongside it`); |
| 331 | + } |
| 332 | + |
| 333 | + it('a fresh install is refused: 422 naming the namespace and its owner, nothing registered or ledgered', async () => { |
| 334 | + serveVersions(versions); |
| 335 | + const { ql, installFromCloud, installHolder } = await bootPlugin(); |
| 336 | + await installHolder(); |
| 337 | + const before = ledger(); |
| 338 | + |
| 339 | + const res = await installFromCloud('v1-ns-held'); |
| 340 | + |
| 341 | + expectNamespaceRefusal(res); |
| 342 | + expect(res.payload.data).toBeUndefined(); |
| 343 | + expect(ql.registry.getPackage(INCOMING_ID)).toBeUndefined(); |
| 344 | + expect(ledger()).toEqual(before); |
| 345 | + expect(ledger().incoming).toBeNull(); |
| 346 | + expectHolderFlowKept(ql); |
| 347 | + }); |
| 348 | + |
| 349 | + it('an upgrade into the held namespace is refused: 422, the installed version still registered and ledgered', async () => { |
| 350 | + serveVersions(versions); |
| 351 | + const { ql, installFromCloud, installHolder } = await bootPlugin(); |
| 352 | + await installHolder(); |
| 353 | + const first = await installFromCloud('v1-free'); |
| 354 | + expect(first.status, JSON.stringify(first.payload)).toBe(200); |
| 355 | + const before = ledger(); |
| 356 | + |
| 357 | + const res = await installFromCloud('v2-ns-held'); |
| 358 | + |
| 359 | + expectNamespaceRefusal(res); |
| 360 | + expect(ql.registry.getPackage(INCOMING_ID)?.manifest?.version).toBe('1.0.0'); |
| 361 | + expect(ledger()).toEqual(before); |
| 362 | + expect(ledger().incoming?.version).toBe('1.0.0'); |
| 363 | + expectHolderFlowKept(ql); |
| 364 | + }); |
| 365 | +}); |
0 commit comments