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
10 changes: 10 additions & 0 deletions .changeset/38972-serve-host-mounted-cloud-capabilities.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@objectstack/cli': patch
---

fix(cli): `os serve` no longer tells the operator to remove a cloud capability the host mounted itself

Clause-②: no
Metadata-protocol: none

An enterprise host that mounts the provider of a packageless cloud token in its own `plugins[]` (for example `AiSeatPlugin` for `ai-seat`, `AiGovernancePlugin` for `governance`) and serves an app declaring that token in `requires` used to get a start-up warning saying the token "is provided only by a cloud runtime and has no open-edition provider … Remove it from `requires`", while the same boot ran the provider. `os serve` now recognises those providers in `plugins[]` by their exact plugin name or class name (`CLOUD_TIER_PROVIDER_IDENTITIES`, covering `ai-seat`, `governance`, `audit-compliance` and `access-policy-console`) and prints the warning only for a declared token nothing mounts. The boot itself is unchanged, and `os validate` / `os verify` read the same as before.
13 changes: 10 additions & 3 deletions packages/cli/src/commands/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ import {
type SeedSettlementSnapshot,
type SeedSuppressionReason,
} from '@objectstack/spec/contracts';
import { judgeDeclaredCapabilities, missingProviderMessage } from '../utils/capability-preflight.js';
import {
hostMountsCloudTierProvider,
judgeDeclaredCapabilities,
missingProviderMessage,
} from '../utils/capability-preflight.js';
import { composeSeedSettledMessage } from '../utils/seed-settled-message.js';
// The deployment's product name, for `AuthPlugin` — the same resolver the email
// capability's template context reads (`resolveEmailCapabilityArg`), so the two
Expand Down Expand Up @@ -5547,12 +5551,15 @@ export default class Serve extends Command {
// before any request, in the sentence
// `os validate` and `os verify` print for the same token, and only when
// nothing in `plugins[]` provides it. A warning, never a refusal: the
// boot is unchanged.
// boot is unchanged. A packageless cloud token whose provider the host
// mounted itself (an enterprise host's `AiSeatPlugin`) is mounted, not
// missing: the judgement below cannot see that, so it is filtered here.
const unmountedKnownTokens = [...declaredRequires].filter(
(cap) =>
!CAPABILITY_PROVIDERS[cap] &&
!Object.prototype.hasOwnProperty.call(Serve.CAPABILITY_TO_TIER, cap) &&
PLATFORM_CAPABILITY_TOKENS.includes(cap),
PLATFORM_CAPABILITY_TOKENS.includes(cap) &&
!hostMountsCloudTierProvider(cap, plugins),
);
if (unmountedKnownTokens.length > 0) {
const judged = await judgeDeclaredCapabilities({
Expand Down
37 changes: 37 additions & 0 deletions packages/cli/src/utils/capability-preflight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,43 @@ export async function preflightProviderWiring(opts: {
return found;
}

// ── Cloud-tier providers a host mounts itself ───────────────────────────────

/**
* The plugin identities that provide a packageless `cloud` token, for the
* runtime that mounts its provider in its OWN `plugins[]`.
*
* A `cloud` row with `package: null` (`PLATFORM_CAPABILITY_PROVIDERS`) has no
* package to resolve and no exports to match, so nothing in the registry says
* which plugin provides it. A cloud runtime's loader mounts it from `requires`,
* but an enterprise host (cloud's objectos-ee composition) mounts the provider
* itself, and `os serve` then boots it like any other `plugins[]` entry. Without
* these identities `serve` read every such token as unmounted and told the
* operator to remove a capability the same boot was running.
*
* Matched EXACTLY (`providesCapability`, `@objectstack/core`): the registered
* plugin `name` and the exported class name, read from the provider's source
* in `@objectstack/security-enterprise` (cloud repository), the same pair each
* cloud loader row names. Every key is pinned to a packageless cloud registry
* row in `capability-preflight.test.ts`, so a row cannot outlive its token.
*/
export const CLOUD_TIER_PROVIDER_IDENTITIES: Readonly<Record<string, readonly string[]>> = Object.freeze({
'ai-seat': ['com.objectstack.security.ai-seat', 'AiSeatPlugin'],
governance: ['com.objectstack.security.ai-governance', 'AiGovernancePlugin'],
'audit-compliance': ['com.objectstack.security.audit-compliance', 'AuditCompliancePlugin'],
'access-policy-console': ['com.objectstack.security.access-policy-console', 'AccessPolicyConsolePlugin'],
});

/**
* True when `plugins` already holds the provider of the cloud-tier `token`
* (see {@link CLOUD_TIER_PROVIDER_IDENTITIES}). Always false for a token with
* no row, so every other token is judged exactly as before.
*/
export function hostMountsCloudTierProvider(token: string, plugins: unknown): boolean {
if (!Object.prototype.hasOwnProperty.call(CLOUD_TIER_PROVIDER_IDENTITIES, token)) return false;
return providesCapability(Array.isArray(plugins) ? plugins : [], CLOUD_TIER_PROVIDER_IDENTITIES[token]);
}

/** One capability advisory as `os validate --json` and `os verify --json` carry it. */
export interface CapabilityAdvisory {
readonly token: string;
Expand Down
61 changes: 61 additions & 0 deletions packages/cli/test/capability-preflight.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { describe, expect, it } from 'vitest';
import {
CLOUD_TIER_PROVIDER_IDENTITIES,
ENTERPRISE_ABSENCE_CONSEQUENCE,
ENTERPRISE_ABSENCE_RUNTIME_NOTICE,
enterpriseAbsenceConsequence,
hostMountsCloudTierProvider,
judgeDeclaredCapabilities,
preflightDeclaredCapabilities,
preflightProviderWiring,
Expand Down Expand Up @@ -423,3 +425,62 @@ describe('the enterprise consequence sentence', () => {
}
});
});

// An enterprise host mounts a packageless cloud token's provider in its own
// `plugins[]`; `os serve` must then not tell the operator to remove the token.
// The fixtures carry the provider's registered name and class name, as the
// host's instances do; nothing else about them is read.
class AiSeatPlugin {
name = 'com.objectstack.security.ai-seat';
async init() {}
}
class AiGovernancePlugin {
name = 'com.objectstack.security.ai-governance';
async init() {}
}

describe('hostMountsCloudTierProvider — a cloud-tier provider the host mounted itself', () => {
it('every row keys a packageless cloud-edition registry token, and the measured two are there', () => {
const keys = Object.keys(CLOUD_TIER_PROVIDER_IDENTITIES);
expect(keys).toEqual(expect.arrayContaining(['ai-seat', 'governance']));
for (const token of keys) {
const row = PLATFORM_CAPABILITY_PROVIDERS[token];
expect(row, token).toBeDefined();
expect(row.edition, token).toBe('cloud');
expect(row.package, token).toBeNull();
expect(CLOUD_TIER_PROVIDER_IDENTITIES[token].length, token).toBeGreaterThan(0);
}
});

it('the host mounted both providers ⇒ both tokens are provided', () => {
const plugins = [new AiSeatPlugin(), new AiGovernancePlugin()];
expect(hostMountsCloudTierProvider('ai-seat', plugins)).toBe(true);
expect(hostMountsCloudTierProvider('governance', plugins)).toBe(true);
});

it('matched by the registered name alone, or by the class name alone', () => {
expect(hostMountsCloudTierProvider('ai-seat', [{ name: 'com.objectstack.security.ai-seat' }])).toBe(true);
class AiGovernancePluginRenamed extends AiGovernancePlugin {}
expect(hostMountsCloudTierProvider('governance', [new AiGovernancePluginRenamed()])).toBe(true);
});

it('CONTROL: a token whose provider the host did not mount is still unprovided', () => {
const plugins = [new AiSeatPlugin()];
expect(hostMountsCloudTierProvider('governance', plugins)).toBe(false);
expect(hostMountsCloudTierProvider('audit-compliance', plugins)).toBe(false);
expect(hostMountsCloudTierProvider('ai-seat', [])).toBe(false);
expect(hostMountsCloudTierProvider('ai-seat', undefined)).toBe(false);
});

it('CONTROL: identity is exact — a consumer named after the token provides nothing', () => {
expect(hostMountsCloudTierProvider('governance', [{ name: 'com.objectstack.security.ai-governance-report' }])).toBe(false);
expect(hostMountsCloudTierProvider('ai-seat', [{ name: 'ai-seat' }])).toBe(false);
});

it('CONTROL: a token with no row is never provided this way, whatever is mounted', () => {
const plugins = [new AiSeatPlugin(), new AiGovernancePlugin()];
for (const token of ['ai', 'ai-studio', 'hierarchy-security', 'automation']) {
expect(hostMountsCloudTierProvider(token, plugins), token).toBe(false);
}
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

/**
* `os serve` does not tell the operator to remove a packageless cloud token
* whose provider the HOST mounted in its own `plugins[]` — asserted over the
* real `os serve` process.
*
* ## The defect
*
* An enterprise host (cloud's objectos-ee composition) mounts `AiSeatPlugin`
* and `AiGovernancePlugin` itself, and the app it serves declares
* `requires: ['governance', 'ai-seat']`. The start-up line for declared tokens
* nothing here mounts read those two as unmounted, because a cloud row with
* `package: null` gives the judgement nothing to match, and printed
* `Capability "governance" is provided only by a cloud runtime and has no
* open-edition provider … Remove "governance" from \`requires\`` while the same
* boot's plugin table listed both providers.
*
* ## What is pinned, in one boot
*
* - the two tokens whose providers the config mounts (fixtures carrying the
* providers' registered names and class names) get no start-up line;
* - CONTROL, same boot: `audit-compliance`, declared with no provider
* mounted, still gets the line, so the start-up check itself still runs.
*
* The identity table and its per-token cases are unit-level, in
* `capability-preflight.test.ts`; this file pins the WIRING, that `serve`
* hands the judgement the host's own `plugins[]`.
*/

import { afterAll, beforeAll, describe, expect, it } from 'vitest';
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { runServe, type ServeRun } from './helpers/serve-process.js';
import { defineStackSourceFromLiteral, linkSpec } from './helpers/define-stack-fixture.js';

/** The start-up line's opening, for one packageless cloud token. */
const unmountedLine = (token: string) =>
`Capability "${token}" is provided only by a cloud runtime and has no open-edition provider`;

const FIXTURE_PLUGINS = `
class AiSeatPlugin {
name = 'com.objectstack.security.ai-seat';
version = '0.0.0';
async init() {}
async start() {}
}
class AiGovernancePlugin {
name = 'com.objectstack.security.ai-governance';
version = '0.0.0';
async init() {}
async start() {}
}
`;

const STACK = `{
manifest: { id: 'com.example.hostmountedcloud', namespace: 'hmc', version: '1.0.0', name: 'Host Mounted Cloud', type: 'app' },
requires: ['governance', 'ai-seat', 'audit-compliance'],
plugins: [new AiSeatPlugin(), new AiGovernancePlugin()],
objects: [
{ name: 'hmc_note', label: 'Note', pluralLabel: 'Notes', fields: { title: { type: 'text', label: 'Title' } } },
],
}`;

let dir = '';
let run: ServeRun;

beforeAll(async () => {
dir = mkdtempSync(join(tmpdir(), 'os-host-mounted-cloud-'));
writeFileSync(join(dir, 'package.json'), JSON.stringify({ name: 'host-mounted-cloud-fixture', private: true, type: 'module' }));
const source = defineStackSourceFromLiteral(STACK);
writeFileSync(join(dir, 'objectstack.config.ts'), source.replace('\n\nexport default', `\n${FIXTURE_PLUGINS}\nexport default`));
linkSpec(dir);
run = await runServe(dir, [], { waitFor: /Press Ctrl\+C to stop/, timeoutMs: 90_000 });
}, 120_000);

afterAll(() => {
if (dir) rmSync(dir, { recursive: true, force: true });
});

describe('os serve: a cloud token whose provider the host mounted is not reported as unmounted', () => {
it('the boot reached its ready banner', () => {
expect(run.port, `${run.stdout}\n${run.stderr}`).toBeTypeOf('number');
});

it('governance and ai-seat, both mounted by the config: no start-up line', () => {
const out = `${run.stdout}\n${run.stderr}`;
expect(out).not.toContain(unmountedLine('governance'));
expect(out).not.toContain(unmountedLine('ai-seat'));
});

it('CONTROL: audit-compliance, declared and mounted by nothing, still gets the line', () => {
const out = `${run.stdout}\n${run.stderr}`;
expect(out).toContain(unmountedLine('audit-compliance'));
expect(out).toContain('Remove "audit-compliance" from `requires`');
});
});
Loading