Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .changeset/34186-hosted-console-unserved-routes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
'@objectstack/service-settings': patch
'@objectstack/cloud-connection': patch
'@object-ui/app-shell': patch
---

fix(console): the console asks the deployment notice, install-local and a page's lookup targets only of a host that serves them

Clause-②: yes (widening)
Metadata-protocol: none

A hosted environment's console asked three routes its host does not serve, and each answered an error in the network log on every load.

- **The deployment notice.** `GET /api/v1/runtime/config` now serves `features.deploymentNotice`. It is true exactly when the deployment notice is composed on this host: `SettingsServicePlugin` registers the notice's door as the kernel service `settings.deployment-notice` when it mounts the settings routes with it, and `RuntimeConfigPlugin` reads that registration per request. A host that mounts the settings routes itself, with no door, answers `GET /api/settings/deployment/notice` with `503` and now reports `false`. The route table is the same on both hosts, so it cannot answer this. A host's `resolveFeatures` policy cannot override the key. The console's home and System Overview read the notice only when the key is true. A runtime that serves no key is older than this change and still serves the notice, so the console keeps reading it there; only an explicit `false` stops the read.
- **Install-local on the marketplace catalog.** The catalog's side load reads `GET /api/v1/marketplace/install-local` only when `features.installLocal` is true, the gate the package page already reads. A host without it no longer answers a `404` on every load and Refresh, and the catalog list draws as before.
- **A page's lookup targets.** In an app with no package, a page and an object's route asked each lookup target's definition by name, and a target the host does not register (`sys_business_unit` on the control plane's Members page) answered `404` on every open. The targets the route has not asked already are now asked first in one `GET /api/v1/meta/object?names=` read, which leaves an absent object out, and only the ones it serves are then read by name. A registered target still resolves as before. An app with a package reads its lookup targets as before.
140 changes: 140 additions & 0 deletions packages/cloud-connection/src/runtime-config-deployment-notice.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

/**
* `features.deploymentNotice` is an OBSERVATION of the composition
* (objectstack#34186).
*
* The Console's home asks `GET /api/settings/deployment/notice` of every
* administrator. `SettingsServicePlugin` serves it when it mounts the settings
* routes with its door; a hosted environment mounts the settings family itself
* with no door, and the same route answers `503` there. Both arms mount the
* route, so the route table cannot tell them apart: the door's registration
* (`DEPLOYMENT_NOTICE_SERVICE`) can, and this flag reads it per request.
*
* The fixtures boot the REAL settings plugin, so the service name this package
* spells and the one the settings package registers cannot drift apart with
* this suite still green.
*/

import { describe, it, expect } from 'vitest';
import { SettingsServicePlugin, registerSettingsRoutes } from '@objectstack/service-settings';
import { RuntimeConfigPlugin, type RuntimeConfigPluginConfig } from './runtime-config-plugin.js';

type Handler = (...args: any[]) => any;

/** A raw app shaped like the Hono instance `getRawApp()` returns, and the adapter verbs the settings routes mount through. */
function createHttp() {
const routes: Array<{ method: string; path: string }> = [];
const handlers = new Map<string, Handler>();
const record = (method: string) => (path: string, handler?: Handler) => {
routes.push({ method, path });
if (handler) handlers.set(`${method} ${path}`, handler);
};
const app = {
routes,
handlers,
get: record('GET'),
post: record('POST'),
put: record('PUT'),
delete: record('DELETE'),
patch: record('PATCH'),
head: record('HEAD'),
all: record('ALL'),
use: record('ALL'),
};
const server = { ...app, getRawApp: () => app, async listen() {}, async close() {} };
return { app, server };
}

/**
* Boot the settings plugin and the runtime config on one kernel-shaped context.
* `hostMountsRoutes`: the hosted shape, where the settings plugin mounts no
* routes and the host mounts the settings family itself, without a door.
*/
async function boot(opts: { hostMountsRoutes: boolean; runtimeConfig?: RuntimeConfigPluginConfig }) {
const { app, server } = createHttp();
const services: Record<string, unknown> = { 'http-server': server, 'http.server': server };
const hooks: Array<() => Promise<void>> = [];
const ctx: any = {
logger: { info() {}, warn() {}, error() {}, debug() {} },
registerService: (name: string, value: unknown) => {
if (name in services) throw new Error(`Service '${name}' already registered`);
services[name] = value;
},
getService: (name: string) => {
if (!(name in services)) throw new Error(`[Kernel] Service '${name}' not found`);
return services[name];
},
hook: (event: string, fn: () => Promise<void>) => {
if (event === 'kernel:ready') hooks.push(fn);
},
};
const settings = new SettingsServicePlugin({
manifests: [],
env: {},
actionHandlers: {},
...(opts.hostMountsRoutes ? { registerRoutes: false } : {}),
});
const runtimeConfig = new RuntimeConfigPlugin({ controlPlaneUrl: '', singleEnvironment: true, ...opts.runtimeConfig });
await settings.init(ctx);
await runtimeConfig.init(ctx);
await settings.start(ctx);
await runtimeConfig.start(ctx);
for (const hook of hooks) await hook();
if (opts.hostMountsRoutes) {
// The hosted shape: the settings family, mounted by the host, with no door.
registerSettingsRoutes(server as any, services.settings as any, {
contextFromRequest: () => ({ enforced: true, userId: 'usr_admin', permissions: ['setup.access', 'manage_platform_settings'] }),
});
}
return { app, services };
}

/** Ask the mounted `/api/v1/runtime/config` handler for its payload. */
async function readConfig(app: ReturnType<typeof createHttp>['app']): Promise<any> {
const handler = app.handlers.get('GET /api/v1/runtime/config');
if (typeof handler !== 'function') throw new Error('runtime/config was never mounted');
return handler({ req: { header: () => undefined }, json: (body: any) => body });
}

/** Ask the notice route as an administrator, the way the Console does, and return the status it answers. */
async function askNotice(app: ReturnType<typeof createHttp>['app']): Promise<number> {
const handler = app.handlers.get('GET /api/settings/deployment/notice');
if (typeof handler !== 'function') throw new Error('the notice route was never mounted');
let status = 200;
const res: any = {
status(code: number) { status = code; return res; },
json() { return res; },
send() { return res; },
header() { return res; },
};
await handler({ params: {}, query: {}, headers: {}, method: 'GET', path: '/api/settings/deployment/notice' }, res);
return status;
}

describe('features.deploymentNotice — observed from the composition (objectstack#34186)', () => {
it("reports true where SettingsServicePlugin mounted the routes with its door", async () => {
const { app } = await boot({ hostMountsRoutes: false });
expect((await readConfig(app)).features.deploymentNotice).toBe(true);
});

it('reports false for a host that mounts the settings routes without a door, whose notice answers 503', async () => {
const { app } = await boot({ hostMountsRoutes: true });
// Both arms mount the route: this one answers it 503.
expect(await askNotice(app)).toBe(503);
expect((await readConfig(app)).features.deploymentNotice).toBe(false);
});

it("a host's feature policy can neither claim the notice nor withhold it", async () => {
const claimed = await boot({
hostMountsRoutes: true,
runtimeConfig: { resolveFeatures: () => ({ deploymentNotice: true }) },
});
expect((await readConfig(claimed.app)).features.deploymentNotice).toBe(false);
const withheld = await boot({
hostMountsRoutes: false,
runtimeConfig: { resolveFeatures: () => ({ deploymentNotice: false }) },
});
expect((await readConfig(withheld.app)).features.deploymentNotice).toBe(true);
});
});
34 changes: 33 additions & 1 deletion packages/cloud-connection/src/runtime-config-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* mapStyleUrl?: string, // the deployment's default map style (OS_CONSOLE_MAP_STYLE_URL) — absent unless set (#26001)
* singleEnvironment: boolean,
* defaultOrgId?, defaultEnvironmentId?, // multi-tenant, per-hostname
* features: { installLocal, marketplace, aiStudio, autoPublishAiBuilds, ... },
* features: { installLocal, marketplace, deploymentNotice, aiStudio, autoPublishAiBuilds, ... },
* branding: { productName, productShortName, stage?, logoUrl, faviconUrl, brandColor, pwaDescription, pwaThemeColor },
* telemetry: { errorReporting?: { dsn, sendDefaultPii, environment?, tracesSampleRate, replaysOnErrorSampleRate } }
* }
Expand Down Expand Up @@ -552,6 +552,34 @@ function someRoutePattern(rawApp: unknown, matches: (pattern: string) => boolean
});
}

/**
* The kernel service the settings plugin registers its deployment-notice door
* under when it mounts the settings routes with one (`@objectstack/service-settings`
* `DEPLOYMENT_NOTICE_SERVICE`). Spelled here rather than imported, as the
* marketplace prefixes above are: this package does not depend on the settings
* one. The coupling is pinned by test, which mounts the REAL settings plugin.
*/
const DEPLOYMENT_NOTICE_SERVICE = 'settings.deployment-notice';

/**
* Does this host serve the deployment notice (`GET /api/settings/deployment/notice`)?
*
* Observed, never declared, and read per request: the settings plugin
* registers its door when it mounts the routes at `kernel:ready`. A host that
* mounts the settings routes itself, with no door, answers that route `503`,
* and its route table is the same as a host that serves it, so the route
* table cannot answer this; the door's registration can. The Console asks the
* notice only where this is true (an older runtime that serves no key keeps
* asking, as it always has).
*/
function hasDeploymentNoticeDoor(ctx: PluginContext): boolean {
try {
return ctx.getService<unknown>(DEPLOYMENT_NOTICE_SERVICE) != null;
} catch {
return false;
}
}


/**
* Did this deployment declare that it has no control plane? (#10805)
Expand Down Expand Up @@ -1196,6 +1224,10 @@ export class RuntimeConfigPlugin implements Plugin {
marketplace: hasMarketplaceBrowseMount(rawApp),
// aiStudio + autoPublishAiBuilds + any distribution keys.
...features,
// Observed from the composition, and after the host's
// keys so no policy hook can claim a notice the host
// does not serve, nor withhold one it does.
deploymentNotice: hasDeploymentNoticeDoor(ctx),
},
// Read per request (#24766): a Branding save shows on the
// next load, with no restart.
Expand Down
12 changes: 12 additions & 0 deletions packages/services/service-settings/src/deployment-notice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ const BOOT_FINDINGS_CHANNEL_ENV = 'OS_INTERNAL_DEPLOYMENT_FINDINGS';
/** The capability that reads the notice and hides it — the infrastructure namespaces' gate. */
export const DEPLOYMENT_NOTICE_CAPABILITY = 'manage_platform_settings';

/**
* The kernel service a composition that serves the notice registers its door
* under, at the moment `SettingsServicePlugin` mounts the routes with it. Its
* presence is the composition fact `GET /api/v1/runtime/config` reports as
* `features.deploymentNotice` (`@objectstack/cloud-connection`
* `RuntimeConfigPlugin`), so the Console asks the notice only of a host that
* serves it. A host that mounts the settings routes itself, with no door,
* registers nothing, and its routes answer `503`: the route table is the same
* on both arms, so only this registration tells them apart.
*/
export const DEPLOYMENT_NOTICE_SERVICE = 'settings.deployment-notice';

/** One thing a production deployment keeps on its own disk because nobody set it. */
export type DeploymentFindingId =
| 'database_local_file'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
storedSecretReaderOverEngine,
} from './local-crypto-provider.js';
import { buildConfigChangeAuditSink } from './config-change-audit.js';
import { buildDeploymentNoticeDoor } from './deployment-notice.js';
import { buildDeploymentNoticeDoor, DEPLOYMENT_NOTICE_SERVICE } from './deployment-notice.js';
import { registerLocalizationCurrencyLock, type CurrencyUsageEngine } from './localization-currency-lock.js';
import { registerLocalizationLocaleOptions, type LocaleListService } from './localization-locale-options.js';
import { USER_OBJECT, assertUserReferenceResolves, registeredLabel } from './actor-reference.js';
Expand Down Expand Up @@ -564,6 +564,10 @@ export class SettingsServicePlugin implements Plugin {
contextFromRequest: verifiedContextFromRequest,
deploymentNotice,
});
// The door is composed on this host: say so where the runtime config
// reads it (`features.deploymentNotice`), so the Console asks the
// notice of this host and of no host without it.
ctx.registerService(DEPLOYMENT_NOTICE_SERVICE, deploymentNotice);
ctx.logger?.info?.(
'SettingsServicePlugin: REST routes registered at ' + (this.opts.basePath ?? '/api/settings'),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ vi.mock('@object-ui/react', async (importOriginal) => ({
useMutationInvalidationBridge: () => {},
}));

// `AppContent` reaches a dynamic `import('@objectstack/lint')` (through
// `ConsoleLayout` → `DraftPreviewBar`, statically): pay its load at collection,
// never inside a case's clocked window (`check:test-source-alias`).
import '@objectstack/lint';
import { AppContent } from '../AppContent';
import { MetadataProvider } from '../../providers/MetadataProvider';
import { useActionModal } from '../../hooks/useActionModal';
Expand Down Expand Up @@ -133,7 +137,14 @@ function makeAdapter() {
},
getClient: () => ({
meta: {
getItems: (type: string, options?: { packageId?: string }) => {
getItems: (type: string, options?: { packageId?: string; names?: readonly string[] }) => {
// objectstack#34188 — the `?names=` read answers the asked names it
// holds and leaves an absent one out, as the list door does.
if (options?.names) {
server.calls.push(`${type}?names=${options.names.join(',')}`);
const named: any[] = type === 'object' ? OBJECTS.filter((o: any) => options.names!.includes(o.name)) : [];
return Promise.resolve({ type, items: structuredClone(named) });
}
server.calls.push(options?.packageId ? `${type}?package=${options.packageId}` : type);
const all = type === 'object' ? OBJECTS : type === 'app' ? server.apps : [];
const items = options?.packageId ? all.filter((o: any) => o._packageId === options.packageId) : all;
Expand Down Expand Up @@ -239,7 +250,8 @@ describe('one console open asks for the app\'s objects, not the whole registry (
await waitFor(() => expect(screen.getByTestId('object-view')).toHaveTextContent('sys_user'));

expect(objectCalls()).not.toContain('object');
expect(objectCalls().some((c) => c.startsWith('object?'))).toBe(false);
// objectstack#34188 — the one list-shaped read is the lookup target's presence, by name.
expect(objectCalls().filter((c) => c.startsWith('object?'))).toEqual(['object?names=sys_user']);
expect(objectCalls()).toEqual(expect.arrayContaining(['object/crm_account', 'object/sys_user']));
expect(screen.getByTestId('object-view')).toHaveTextContent('crm_account');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ vi.mock('@object-ui/react', async (importOriginal) => {
};
});

// `AppContent` reaches a dynamic `import('@objectstack/lint')` (through
// `ConsoleLayout` → `DraftPreviewBar`, statically): pay its load at collection,
// never inside a case's clocked window (`check:test-source-alias`).
import '@objectstack/lint';
import { AppContent } from '../AppContent';
import { MetadataProvider, useMetadata } from '../../providers/MetadataProvider';

Expand Down Expand Up @@ -169,7 +173,14 @@ function makeAdapter() {
},
getClient: () => ({
meta: {
getItems: (type: string, options?: { packageId?: string }) => {
getItems: (type: string, options?: { packageId?: string; names?: readonly string[] }) => {
// objectstack#34188 — the `?names=` read answers the asked names it
// holds and leaves an absent one out, as the list door does.
if (options?.names) {
server.calls.push(`${type}?names=${options.names.join(',')}`);
const named: any[] = type === 'object' ? OBJECTS.filter((o: any) => options.names!.includes(o.name)) : [];
return Promise.resolve({ type, items: structuredClone(named) });
}
server.calls.push(options?.packageId ? `${type}?package=${options.packageId}` : type);
const all: Doc[] =
type === 'object' ? OBJECTS : type === 'view' ? VIEWS : type === 'page' ? PAGES : type === 'app' ? [NOTES_APP, CRM_APP] : [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,14 @@ function makeAdapter() {
},
getClient: () => ({
meta: {
getItems: (type: string, options?: { packageId?: string }) => {
getItems: (type: string, options?: { packageId?: string; names?: readonly string[] }) => {
// objectstack#34188 — the `?names=` read answers the asked names it
// holds and leaves an absent one out, as the list door does.
if (options?.names) {
server.calls.push(`${type}?names=${options.names.join(',')}`);
const named: any[] = type === 'object' ? server.objects.filter((o: any) => options.names!.includes(o.name)) : [];
return Promise.resolve({ type, items: structuredClone(named) });
}
server.calls.push(options?.packageId ? `${type}?package=${options.packageId}` : type);
const all: Doc[] =
type === 'object' ? server.objects : type === 'app' ? [OPS_APP, REQUIRES_APP, CRM_APP] : type === 'page' ? server.pages : [];
Expand Down Expand Up @@ -321,7 +328,7 @@ describe('a package-less app’s record route with no declared record page reads

expect(objectCalls()).not.toContain('object');
// Every bundled object is answered from the bundle; the lookup target outside it is asked by name.
expect(objectCalls()).toEqual(['object/sys_user']);
expect(objectCalls()).toEqual(['object?names=sys_user', 'object/sys_user']);
expect(sorted((screen.getByTestId('record-view').textContent ?? '').split(','))).toEqual(
sorted(['crm_account', 'crm_activity', 'crm_contact', 'crm_lead', 'crm_opportunity', 'sys_user']),
);
Expand Down Expand Up @@ -360,7 +367,7 @@ describe('a package-less app’s record route with no declared record page reads
land();
await waitFor(() => expect(screen.getByTestId('record-view')).toHaveTextContent('crm_activity'));
await settle();
expect(objectCalls()).toEqual(['object/sys_user']);
expect(objectCalls()).toEqual(['object?names=sys_user', 'object/sys_user']);
});
});

Expand Down Expand Up @@ -566,7 +573,7 @@ describe('a tracked object’s record route asks sys_audit_log by name (objectst

expect(firstRender()).toContain('sys_audit_log');
expect(objectCalls()).not.toContain('object');
expect(sorted(objectCalls())).toEqual(sorted(['object/sys_user', 'object/sys_audit_log']));
expect(sorted(objectCalls())).toEqual(sorted(['object?names=sys_user', 'object/sys_user', 'object/sys_audit_log']));
expect(drawnRelated()).toEqual(registryRelated('crm_account'));
});

Expand Down
Loading
Loading