|
| 1 | +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. |
| 2 | + |
| 3 | +/** |
| 4 | + * #8343 — the air-gapped install surface must not be gated on the control |
| 5 | + * plane it is designed not to need. |
| 6 | + * |
| 7 | + * The defect, measured on a customer's self-hosted objectos-ee 4.0.5-rc.1 with |
| 8 | + * `OS_CLOUD_URL=off` (the value that image's own compose file documents for a |
| 9 | + * fully self-hosted box): `GET` and `POST /api/v1/marketplace/install-local` |
| 10 | + * both 404, with no other package-install surface in the served OpenAPI. The |
| 11 | + * deployment could not install a package by any route — while its |
| 12 | + * `/api/v1/runtime/config` advertised `features.installLocal: true`. |
| 13 | + * |
| 14 | + * Why the whole wiring block sat behind ONE flag: it mounts a control-plane |
| 15 | + * client (browse proxy, cloud-connection, runtime-config) AND the local |
| 16 | + * install surface, and only the former needs a URL. `handleInstall`'s |
| 17 | + * inline-manifest branch reads no URL at all, which is exactly what makes |
| 18 | + * `os package install ./dist/objectstack.json` the documented offline path. |
| 19 | + * |
| 20 | + * These tests pin the SPLIT, in both directions — a fix that merely mounts |
| 21 | + * more would be indistinguishable here from one that stopped honouring `off`: |
| 22 | + * |
| 23 | + * - explicitly-disabled cloud mounts the offline surface and NOTHING that |
| 24 | + * dials out, |
| 25 | + * - a resolved cloud URL still mounts the full set (no capability lost), |
| 26 | + * - a runtime host kernel still mounts NEITHER (the cloud distribution wires |
| 27 | + * its own — the guard that was checked first and is easy to disturb), |
| 28 | + * - a host config that wires its own install-local is left alone. |
| 29 | + */ |
| 30 | + |
| 31 | +import { describe, expect, it } from 'vitest'; |
| 32 | +import Serve from '../src/commands/serve.js'; |
| 33 | + |
| 34 | +/** Minimal stand-in for a loaded plugin: what the resolver actually reads. */ |
| 35 | +function plugin(name: string, ctorName: string): { name: string } { |
| 36 | + const Ctor = { [ctorName]: class { name: string; constructor(n: string) { this.name = n; } } }[ctorName]!; |
| 37 | + return new Ctor(name) as { name: string }; |
| 38 | +} |
| 39 | + |
| 40 | +/** The host-kernel signal the cloud distribution is detected by. */ |
| 41 | +const OBJECTOS_ENVIRONMENT = plugin( |
| 42 | + 'com.objectstack.runtime.objectos-environment', |
| 43 | + 'ObjectOSEnvironmentPlugin', |
| 44 | +); |
| 45 | + |
| 46 | +const INSTALL_LOCAL = plugin( |
| 47 | + 'com.objectstack.runtime.marketplace-install-local', |
| 48 | + 'MarketplaceInstallLocalPlugin', |
| 49 | +); |
| 50 | + |
| 51 | +describe('#8343: install-local mounts on a runtime with the cloud switched off', () => { |
| 52 | + it('THE REGRESSION — `OS_CLOUD_URL=off` still mounts the offline install surface', () => { |
| 53 | + // resolveCloudUrl() maps every disable sentinel to '' — that empty string |
| 54 | + // is what reaches this decision, and it used to mean "mount nothing". |
| 55 | + const wiring = Serve.planMarketplaceWiring({ |
| 56 | + isRuntimeHostKernel: false, |
| 57 | + marketplaceUrl: '', |
| 58 | + plugins: [], |
| 59 | + }); |
| 60 | + |
| 61 | + expect( |
| 62 | + wiring.offlineInstallLocal, |
| 63 | + 'a self-hosted box with no control plane is the deployment that most needs the offline install path', |
| 64 | + ).toBe(true); |
| 65 | + }); |
| 66 | + |
| 67 | + it('and mounts NOTHING that talks to a control plane', () => { |
| 68 | + // The other half of the fix. `off` still has to mean off: the browse |
| 69 | + // proxy, the cloud-connection surface and the pushed runtime-config are |
| 70 | + // all control-plane clients and must stay unmounted. |
| 71 | + const wiring = Serve.planMarketplaceWiring({ |
| 72 | + isRuntimeHostKernel: false, |
| 73 | + marketplaceUrl: '', |
| 74 | + plugins: [], |
| 75 | + }); |
| 76 | + |
| 77 | + expect(wiring.cloudSurfaces).toBe(false); |
| 78 | + }); |
| 79 | + |
| 80 | + it('a resolved cloud URL still mounts the full set — nothing was traded away', () => { |
| 81 | + // The regression a narrowed rule invites: mounting only the offline half |
| 82 | + // everywhere would pass the two tests above while silently deleting |
| 83 | + // marketplace browse from every connected runtime. |
| 84 | + const wiring = Serve.planMarketplaceWiring({ |
| 85 | + isRuntimeHostKernel: false, |
| 86 | + marketplaceUrl: 'https://cloud.objectos.ai', |
| 87 | + plugins: [], |
| 88 | + }); |
| 89 | + |
| 90 | + expect(wiring.cloudSurfaces).toBe(true); |
| 91 | + // The cloud arm already carries its own install-local, so the offline arm |
| 92 | + // must not fire on top of it. |
| 93 | + expect(wiring.offlineInstallLocal).toBe(false); |
| 94 | + }); |
| 95 | + |
| 96 | + it('vanilla `objectstack dev` is UNCHANGED — it never reached the offline arm', () => { |
| 97 | + // Worth pinning because the reading that makes this change look expensive |
| 98 | + // is "unconditional mounting adds a Setup nav entry to every plain dev |
| 99 | + // app". It does not: with OS_CLOUD_URL unset, resolveCloudUrl() returns |
| 100 | + // the public DEFAULT_CLOUD_URL, so a plain dev app takes the CLOUD arm — |
| 101 | + // and has mounted install-local (and its "Installed Apps" nav) all along. |
| 102 | + // Only runs that explicitly opted out see any difference at all. |
| 103 | + const wiring = Serve.planMarketplaceWiring({ |
| 104 | + isRuntimeHostKernel: false, |
| 105 | + marketplaceUrl: 'https://cloud.objectos.ai', // what an unset env resolves to |
| 106 | + plugins: [], |
| 107 | + }); |
| 108 | + |
| 109 | + expect(wiring.cloudSurfaces).toBe(true); |
| 110 | + expect(wiring.offlineInstallLocal).toBe(false); |
| 111 | + }); |
| 112 | + |
| 113 | + it('a runtime host kernel mounts NEITHER arm, cloud off or on', () => { |
| 114 | + // The guard that is checked FIRST and is the easy casualty of editing this |
| 115 | + // block: the cloud distribution (objectos-stack) wires its own marketplace |
| 116 | + // on the host kernel, so auto-wiring here double-mounts. Pinned for both |
| 117 | + // URL states, because the offline arm is a new path through this branch. |
| 118 | + for (const marketplaceUrl of ['', 'https://cloud.objectos.ai']) { |
| 119 | + const wiring = Serve.planMarketplaceWiring({ |
| 120 | + isRuntimeHostKernel: true, |
| 121 | + marketplaceUrl, |
| 122 | + plugins: [OBJECTOS_ENVIRONMENT], |
| 123 | + }); |
| 124 | + |
| 125 | + expect(wiring.cloudSurfaces, `cloudSurfaces for url='${marketplaceUrl}'`).toBe(false); |
| 126 | + expect(wiring.offlineInstallLocal, `offlineInstallLocal for url='${marketplaceUrl}'`).toBe(false); |
| 127 | + } |
| 128 | + }); |
| 129 | + |
| 130 | + it('a host that wires its OWN install-local keeps it', () => { |
| 131 | + // `kernel.use` keys plugins by name, so an unguarded mount would REPLACE a |
| 132 | + // host's own instance. That is not a redundant-mount tidy-up: a host may |
| 133 | + // have constructed one with an explicit control-plane URL while |
| 134 | + // OS_CLOUD_URL says `off`, and the replacement — pinned to `off` — would |
| 135 | + // silently drop that host's catalog capability. |
| 136 | + const wiring = Serve.planMarketplaceWiring({ |
| 137 | + isRuntimeHostKernel: false, |
| 138 | + marketplaceUrl: '', |
| 139 | + plugins: [INSTALL_LOCAL], |
| 140 | + }); |
| 141 | + |
| 142 | + expect(wiring.offlineInstallLocal).toBe(false); |
| 143 | + }); |
| 144 | +}); |
| 145 | + |
| 146 | +describe('#8343: the identities the offline arm matches on are the real ones', () => { |
| 147 | + it('matches the plugin by registered name AND by class name', () => { |
| 148 | + expect(Serve.providesCapability([INSTALL_LOCAL], Serve.INSTALL_LOCAL_IDENTITIES)).toBe(true); |
| 149 | + expect( |
| 150 | + Serve.providesCapability( |
| 151 | + [plugin('some.other.plugin', 'MarketplaceInstallLocalPlugin')], |
| 152 | + Serve.INSTALL_LOCAL_IDENTITIES, |
| 153 | + ), |
| 154 | + ).toBe(true); |
| 155 | + }); |
| 156 | + |
| 157 | + it('drift check — the identities still match the plugin the CLI actually mounts', async () => { |
| 158 | + // Same discipline as serve-capability-identity.test.ts: a registry of |
| 159 | + // identities that has drifted from the class it names fails OPEN (nothing |
| 160 | + // matches -> the guard never fires -> the host's instance gets replaced), |
| 161 | + // and nothing else in the suite would notice. |
| 162 | + const { MarketplaceInstallLocalPlugin } = await import('@objectstack/cloud-connection'); |
| 163 | + const real = new MarketplaceInstallLocalPlugin({ controlPlaneUrl: 'off' }); |
| 164 | + |
| 165 | + expect(Serve.INSTALL_LOCAL_IDENTITIES).toContain(real.name); |
| 166 | + expect(Serve.INSTALL_LOCAL_IDENTITIES).toContain(MarketplaceInstallLocalPlugin.name); |
| 167 | + expect(Serve.providesCapability([real], Serve.INSTALL_LOCAL_IDENTITIES)).toBe(true); |
| 168 | + }); |
| 169 | +}); |
| 170 | + |
| 171 | +describe('#8343: why the offline mount passes `off` and never an empty string', () => { |
| 172 | + it('an empty controlPlaneUrl resolves to the PUBLIC cloud, `off` resolves to none', async () => { |
| 173 | + // The trap behind the call site's literal. The plugin re-resolves whatever |
| 174 | + // it is constructed with through resolveCloudUrl(), which treats '' as |
| 175 | + // "unset" and substitutes DEFAULT_CLOUD_URL. Handing it the '' that the |
| 176 | + // wiring block already has in `marketplaceUrl` would therefore point an |
| 177 | + // air-gapped runtime's catalog branch at cloud.objectos.ai — the exact |
| 178 | + // opposite of what `off` requested, and invisible until a box with no |
| 179 | + // egress hangs on an install. |
| 180 | + const { resolveCloudUrl, DEFAULT_CLOUD_URL } = await import('@objectstack/cloud-connection'); |
| 181 | + |
| 182 | + expect(resolveCloudUrl(''), "'' means 'unset', NOT 'disabled'").toBe(DEFAULT_CLOUD_URL); |
| 183 | + |
| 184 | + // The call site's actual value, not a restatement of it — this goes red if |
| 185 | + // anyone "simplifies" the constant to the empty marketplaceUrl in scope. |
| 186 | + expect( |
| 187 | + resolveCloudUrl(Serve.OFFLINE_CONTROL_PLANE), |
| 188 | + 'the value the offline mount is constructed with must resolve to NO cloud', |
| 189 | + ).toBe(''); |
| 190 | + }); |
| 191 | +}); |
0 commit comments