|
| 1 | +// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license. |
| 2 | + |
| 3 | +/** |
| 4 | + * ADR-0048 — end-to-end verification that the platform apps now live in their |
| 5 | + * own one-app packages and register under DISTINCT package ids. |
| 6 | + * |
| 7 | + * Boots a real ObjectQL engine, runs each app package's plugin `start()` against |
| 8 | + * a manifest service backed by `engine.registerApp` (exactly what the kernel |
| 9 | + * wires — see objectql plugin.ts: `register(m) => ql.registerApp(m)`), and |
| 10 | + * asserts each app resolves under `com.objectstack.{studio,setup,account}` and |
| 11 | + * that all three coexist (the multi-app-package ambiguity is gone). |
| 12 | + */ |
| 13 | + |
| 14 | +import { describe, it, expect, beforeEach } from 'vitest'; |
| 15 | +import { ObjectQL } from '@objectstack/objectql'; |
| 16 | +import { createStudioAppPlugin } from '@objectstack/studio'; |
| 17 | +import { createSetupAppPlugin } from '@objectstack/setup'; |
| 18 | +import { createAccountAppPlugin } from '@objectstack/account'; |
| 19 | + |
| 20 | +function makeCtx(engine: ObjectQL) { |
| 21 | + return { |
| 22 | + getService: (name: string) => |
| 23 | + name === 'manifest' ? { register: (m: any) => engine.registerApp(m) } : undefined, |
| 24 | + registerService: () => {}, |
| 25 | + getServices: () => new Map(), |
| 26 | + logger: { info: () => {}, warn: () => {}, error: () => {}, debug: () => {} }, |
| 27 | + hook: () => {}, |
| 28 | + } as any; |
| 29 | +} |
| 30 | + |
| 31 | +describe('ADR-0048 — platform apps as one-app packages', () => { |
| 32 | + let engine: ObjectQL; |
| 33 | + |
| 34 | + beforeEach(async () => { |
| 35 | + engine = new ObjectQL(); |
| 36 | + engine.registry.logLevel = 'silent'; |
| 37 | + const ctx = makeCtx(engine); |
| 38 | + for (const plugin of [createSetupAppPlugin(), createStudioAppPlugin(), createAccountAppPlugin()]) { |
| 39 | + await plugin.init?.(ctx); |
| 40 | + await plugin.start(ctx); |
| 41 | + } |
| 42 | + }); |
| 43 | + |
| 44 | + it('registers each app under its OWN package id', () => { |
| 45 | + expect(engine.registry.getItem<any>('app', 'studio', 'com.objectstack.studio')?._packageId).toBe( |
| 46 | + 'com.objectstack.studio', |
| 47 | + ); |
| 48 | + expect(engine.registry.getItem<any>('app', 'setup', 'com.objectstack.setup')?._packageId).toBe( |
| 49 | + 'com.objectstack.setup', |
| 50 | + ); |
| 51 | + expect(engine.registry.getItem<any>('app', 'account', 'com.objectstack.account')?._packageId).toBe( |
| 52 | + 'com.objectstack.account', |
| 53 | + ); |
| 54 | + }); |
| 55 | + |
| 56 | + it('all three apps coexist and resolve by name (getApp)', () => { |
| 57 | + expect(engine.registry.getApp('studio')?.name).toBe('studio'); |
| 58 | + expect(engine.registry.getApp('setup')?.name).toBe('setup'); |
| 59 | + expect(engine.registry.getApp('account')?.name).toBe('account'); |
| 60 | + }); |
| 61 | + |
| 62 | + it('each app package owns a distinct namespace (no install-gate conflict)', () => { |
| 63 | + expect(engine.registry.getNamespaceOwners('studio')).toEqual(['com.objectstack.studio']); |
| 64 | + expect(engine.registry.getNamespaceOwners('setup')).toEqual(['com.objectstack.setup']); |
| 65 | + expect(engine.registry.getNamespaceOwners('account')).toEqual(['com.objectstack.account']); |
| 66 | + }); |
| 67 | + |
| 68 | + it('records all three as installed packages', () => { |
| 69 | + const ids = engine.registry.getAllPackages().map((p: any) => p.manifest.id); |
| 70 | + expect(ids).toEqual( |
| 71 | + expect.arrayContaining([ |
| 72 | + 'com.objectstack.studio', |
| 73 | + 'com.objectstack.setup', |
| 74 | + 'com.objectstack.account', |
| 75 | + ]), |
| 76 | + ); |
| 77 | + }); |
| 78 | +}); |
0 commit comments