fix(plugin-sdk): validate checks apiVersion and the manifest rules exactly as an install does

The SDK accepted any number as apiVersion while the host refuses anything
but a positive integer no newer than its plugin API, a false green for an
author. The manifest patterns, sets and caps now live in the host's
protocol/manifest-rules.ts, and gen-plugin-facts writes them and
PLUGIN_API_VERSION into the SDK, so check:plugin-facts covers them. One
manifest corpus is judged by both validators in a server test (the SDK may
only be stricter, case by case), and a typecheck test holds the SDK's plugin
API types to the host child's copy, which gains rawBodyBase64.
This commit is contained in:
Maurice
2026-10-10 15:20:42 +02:00
parent 15db688586
commit 81ec7dd28d
18 changed files with 949 additions and 146 deletions
+245
View File
@@ -0,0 +1,245 @@
/**
* One corpus of manifests, judged by both validators: the SDK's `validateManifest`
* (what `trek-plugin validate` says) and the host's `parseManifest` with
* `requireTrek` (what an install says). `test/manifest-corpus.test.ts` runs the SDK
* over it here; `server/tests/unit/plugins/manifest-parity.test.ts` runs both and
* fails on any case where they disagree with the verdicts below.
*
* The verdict that must never happen is the SDK accepting what the host refuses: a
* false green lets an author cut a release the registry then rejects. The SDK may be
* stricter than the host on purpose (a declaration the host installs but never
* uses); each such case carries `sdk` and the reason in `why`.
*
* Plain data, no imports: the server test reaches this file by a relative path.
*/
export type Verdict = 'accept' | 'reject';
export interface ManifestCase {
name: string;
manifest: Record<string, unknown>;
/** What an install answers. */
host: Verdict;
/** What `validate` answers, when it differs from the host (only ever stricter). */
sdk?: Verdict;
/** Why the SDK is stricter here. Required with `sdk`. */
why?: string;
}
const base = {
id: 'demo-plugin',
name: 'Demo',
version: '1.0.0',
type: 'integration',
trek: '>=4.0.0 <5.0.0',
};
const tool = (name: string) => ({ name, description: 'Looks something up.' });
const poi = { id: 'trails', label: 'Trails', icon: 'Footprints', color: '#22aa66' };
export const MANIFEST_CORPUS: ManifestCase[] = [
{ name: 'the minimal manifest', manifest: { ...base }, host: 'accept' },
{ name: 'not an object', manifest: null as unknown as Record<string, unknown>, host: 'reject' },
// apiVersion: a positive integer no newer than the host's plugin API
{ name: 'apiVersion 1', manifest: { ...base, apiVersion: 1 }, host: 'accept' },
{ name: 'apiVersion 0', manifest: { ...base, apiVersion: 0 }, host: 'reject' },
{ name: 'apiVersion -1', manifest: { ...base, apiVersion: -1 }, host: 'reject' },
{ name: 'apiVersion 1.5', manifest: { ...base, apiVersion: 1.5 }, host: 'reject' },
{ name: 'apiVersion as a string', manifest: { ...base, apiVersion: '1' }, host: 'reject' },
{ name: 'apiVersion null', manifest: { ...base, apiVersion: null }, host: 'reject' },
{ name: 'apiVersion newer than the host', manifest: { ...base, apiVersion: 2 }, host: 'reject' },
// id, version, type, trek
{ name: 'id too short', manifest: { ...base, id: 'ab' }, host: 'reject' },
{ name: 'id with capitals', manifest: { ...base, id: 'Demo-plugin' }, host: 'reject' },
{ name: 'reserved id', manifest: { ...base, id: 'registry' }, host: 'reject' },
{ name: 'missing name', manifest: { ...base, name: '' }, host: 'reject' },
{ name: 'version without patch', manifest: { ...base, version: '1.0' }, host: 'reject' },
{ name: 'prerelease version', manifest: { ...base, version: '1.0.0-beta.1' }, host: 'accept' },
{ name: 'version with build metadata', manifest: { ...base, version: '1.0.0+build' }, host: 'reject' },
{ name: 'unknown type', manifest: { ...base, type: 'theme' }, host: 'reject' },
{ name: 'trip-page type', manifest: { ...base, type: 'trip-page' }, host: 'accept' },
{ name: 'missing trek range', manifest: { ...base, trek: undefined }, host: 'reject' },
{ name: 'unsatisfiable trek range', manifest: { ...base, trek: '>=5.0.0 <4.0.0' }, host: 'reject' },
{ name: 'trek range that is not semver', manifest: { ...base, trek: 'latest' }, host: 'reject' },
{ name: 'native modules', manifest: { ...base, nativeModules: true }, host: 'reject' },
// permissions and egress
{ name: 'a known permission', manifest: { ...base, permissions: ['db:read:trips'] }, host: 'accept' },
{ name: 'an unknown permission', manifest: { ...base, permissions: ['db:read:everything'] }, host: 'reject' },
{
name: 'outbound host with its egress',
manifest: { ...base, permissions: ['http:outbound:api.example.com'], egress: ['api.example.com'] },
host: 'accept',
},
{
name: 'outbound to a whole TLD',
manifest: { ...base, permissions: ['http:outbound:*.com'], egress: ['*.com'] },
host: 'reject',
},
{ name: 'outbound without egress', manifest: { ...base, permissions: ['http:outbound'] }, host: 'reject' },
{
name: 'operator egress without hosts',
manifest: { ...base, permissions: ['http:outbound'], operatorEgress: true },
host: 'accept',
},
{ name: 'operator egress not a boolean', manifest: { ...base, operatorEgress: 'yes' }, host: 'reject' },
{ name: 'operator egress without outbound', manifest: { ...base, operatorEgress: true }, host: 'reject' },
{
name: 'bare wildcard egress',
manifest: { ...base, permissions: ['http:outbound'], egress: ['*'] },
host: 'reject',
},
{
name: 'egress host with a scheme',
manifest: { ...base, permissions: ['http:outbound'], egress: ['https://api.example.com'] },
host: 'reject',
},
// capabilities
{ name: 'hero widget', manifest: { ...base, type: 'widget', capabilities: { widget: { slot: 'hero' } } }, host: 'accept' },
{ name: 'unknown widget slot', manifest: { ...base, capabilities: { widget: { slot: 'footer' } } }, host: 'reject' },
{ name: 'trip page replacing collab', manifest: { ...base, capabilities: { tripPage: { replaces: ['collab'] } } }, host: 'accept' },
{ name: 'trip page replacing the plan', manifest: { ...base, capabilities: { tripPage: { replaces: ['plan'] } } }, host: 'reject' },
{ name: 'trip page at position 50', manifest: { ...base, capabilities: { tripPage: { position: 50 } } }, host: 'accept' },
{ name: 'trip page at position 51', manifest: { ...base, capabilities: { tripPage: { position: 51 } } }, host: 'reject' },
{ name: 'settingsUi not a boolean', manifest: { ...base, capabilities: { settingsUi: 'yes' } }, host: 'reject' },
{
name: 'route profiles with their grant',
manifest: { ...base, permissions: ['hook:route-provider'], capabilities: { routeProfiles: [{ id: 'bike', label: 'Bike' }] } },
host: 'accept',
},
{
name: 'four route profiles',
manifest: {
...base,
permissions: ['hook:route-provider'],
capabilities: { routeProfiles: ['a', 'b', 'c', 'd'].map((id) => ({ id, label: id })) },
},
host: 'reject',
},
{
name: 'route profile id with capitals',
manifest: { ...base, permissions: ['hook:route-provider'], capabilities: { routeProfiles: [{ id: 'Bike', label: 'Bike' }] } },
host: 'reject',
},
{
name: 'route profiles without their grant',
manifest: { ...base, capabilities: { routeProfiles: [{ id: 'bike', label: 'Bike' }] } },
host: 'accept',
sdk: 'reject',
why: 'the host installs the declaration but never offers the profiles without hook:route-provider',
},
{
name: 'notification channel with its grant',
manifest: {
...base,
permissions: ['hook:notification-channel'],
capabilities: { notificationChannel: { events: ['trip_invite'] } },
},
host: 'accept',
},
{
name: 'notification channel for an admin-only event',
manifest: {
...base,
permissions: ['hook:notification-channel'],
capabilities: { notificationChannel: { events: ['version_available'] } },
},
host: 'reject',
},
{
name: 'notification channel without its grant',
manifest: { ...base, capabilities: { notificationChannel: { events: ['trip_invite'] } } },
host: 'accept',
sdk: 'reject',
why: 'the host installs the declaration but never delivers to it without hook:notification-channel',
},
{
name: 'MCP tools with their grant',
manifest: { ...base, permissions: ['mcp:tools'], capabilities: { mcpTools: [tool('lookup')] } },
host: 'accept',
},
{
name: 'MCP tools without their grant',
manifest: { ...base, capabilities: { mcpTools: [tool('lookup')] } },
host: 'reject',
},
{
name: 'MCP tool name with a dash',
manifest: { ...base, permissions: ['mcp:tools'], capabilities: { mcpTools: [tool('look-up')] } },
host: 'reject',
},
{
name: 'nine MCP tools',
manifest: {
...base,
permissions: ['mcp:tools'],
capabilities: { mcpTools: Array.from({ length: 9 }, (_, i) => tool(`tool_${i}`)) },
},
host: 'reject',
},
{
name: 'MCP tool without a description',
manifest: { ...base, permissions: ['mcp:tools'], capabilities: { mcpTools: [{ name: 'lookup' }] } },
host: 'reject',
},
{
name: 'POI categories with their grant',
manifest: { ...base, permissions: ['hook:poi-category-provider'], capabilities: { poiCategories: [poi] } },
host: 'accept',
},
{
name: 'POI category with an unknown icon',
manifest: {
...base,
permissions: ['hook:poi-category-provider'],
capabilities: { poiCategories: [{ ...poi, icon: 'NotAnIcon' }] },
},
host: 'reject',
},
{
name: 'POI categories without their grant',
manifest: { ...base, capabilities: { poiCategories: [poi] } },
host: 'accept',
sdk: 'reject',
why: 'the host installs the declaration but never shows the chips without hook:poi-category-provider',
},
{ name: 'provided names', manifest: { ...base, capabilities: { provides: ['rate.updated'] } }, host: 'accept' },
{ name: 'provided name starting with a digit', manifest: { ...base, capabilities: { provides: ['1rate'] } }, host: 'reject' },
// settings and actions
{ name: 'a dotted settings key', manifest: { ...base, settings: [{ key: 'api.key' }] }, host: 'accept' },
{ name: 'a prototype settings key', manifest: { ...base, settings: [{ key: '__proto__' }] }, host: 'reject' },
{ name: 'settings options not a list', manifest: { ...base, settings: [{ key: 'mode', options: 'a,b' }] }, host: 'reject' },
{ name: 'settings option without a value', manifest: { ...base, settings: [{ key: 'mode', options: [{ value: '' }] }] }, host: 'reject' },
{ name: 'string settings options', manifest: { ...base, settings: [{ key: 'mode', options: ['a', 'b'] }] }, host: 'accept' },
{ name: 'an action', manifest: { ...base, actions: [{ key: 'test', label: 'Test' }] }, host: 'accept' },
{
name: 'nine actions',
manifest: { ...base, actions: Array.from({ length: 9 }, (_, i) => ({ key: `a${i}` })) },
host: 'reject',
},
{ name: 'duplicate actions', manifest: { ...base, actions: [{ key: 'test' }, { key: 'test' }] }, host: 'reject' },
{ name: 'action with an unknown scope', manifest: { ...base, actions: [{ key: 'test', scope: 'admin' }] }, host: 'reject' },
// dependencies
{ name: 'a required addon', manifest: { ...base, requiredAddons: ['llm_parsing'] }, host: 'accept' },
{ name: 'a malformed addon id', manifest: { ...base, requiredAddons: ['LLM'] }, host: 'reject' },
{
name: 'a plugin dependency',
manifest: { ...base, pluginDependencies: [{ id: 'other-plugin', version: '^1.0.0' }] },
host: 'accept',
},
{
name: 'a dependency on itself',
manifest: { ...base, pluginDependencies: [{ id: 'demo-plugin', version: '^1.0.0' }] },
host: 'reject',
},
{
name: 'a dependency with a junk range',
manifest: { ...base, pluginDependencies: [{ id: 'other-plugin', version: 'whenever' }] },
host: 'reject',
},
];
+32
View File
@@ -0,0 +1,32 @@
/**
* test/host-types.test-d.ts holds the SDK's plugin API to the host child's copy, name by
* name. This makes sure it names every one: an export both files declare and the type
* test does not list would drift unchecked. Skips outside the monorepo, like the other
* host parity tests.
*/
import { describe, expect, it } from 'vitest';
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const here = path.dirname(fileURLToPath(import.meta.url));
const hostFile = path.resolve(here, '../../server/src/nest/plugins/runtime/plugin-sdk.ts');
const sdkFile = path.resolve(here, '../src/index.ts');
const typeTest = path.resolve(here, 'host-types.test-d.ts');
const exportsOf = (file: string): Set<string> =>
new Set(
[...fs.readFileSync(file, 'utf8').matchAll(/^export (?:declare )?(?:interface|type|const|function|class|enum) (\w+)/gm)].map(
(m) => m[1],
),
);
describe.skipIf(!fs.existsSync(hostFile))('host type parity covers every shared name', () => {
it('lists each type both sides export', () => {
const host = exportsOf(hostFile);
const shared = [...exportsOf(sdkFile)].filter((name) => host.has(name) && name !== 'definePlugin').sort();
const listed = new Set([...fs.readFileSync(typeTest, 'utf8').matchAll(/expectTypeOf<(?:keyof )?Sdk\.(\w+)>/g)].map((m) => m[1]));
expect(shared.length).toBeGreaterThan(40);
expect(shared.filter((name) => !listed.has(name))).toEqual([]);
});
});
+116
View File
@@ -0,0 +1,116 @@
/**
* Type parity between the SDK's plugin API (src/index.ts) and the copy the host's plugin
* child runs on (server/src/nest/plugins/runtime/plugin-sdk.ts). Both declare the same
* names; vitest's typecheck mode compiles this file (vitest.config.ts enables it only
* inside the monorepo, where the host file exists).
*
* Two kinds of name:
* - the plain shapes (requests, results, contributions) are the same type on both sides;
* - the shapes that carry a `ctx` are refined in the SDK: its PluginContext types the
* entity results (`Trip`, `Place`, …) and some requests where the host's child says
* `unknown`, so those are held to the same members (a method or field on one side
* only is the drift this catches, as `rawBodyBase64` was), not to one type.
*
* test/host-types-names.test.ts checks every name both files export is listed here.
*/
import { expectTypeOf, test } from 'vitest';
import type * as Sdk from '../src/index.js';
import type * as Host from '../../server/src/nest/plugins/runtime/plugin-sdk.js';
test('the plain shapes are one type on both sides', () => {
expectTypeOf<Sdk.PluginResponse>().toEqualTypeOf<Host.PluginResponse>();
expectTypeOf<Sdk.Photo>().toEqualTypeOf<Host.Photo>();
expectTypeOf<Sdk.NotificationMessage>().toEqualTypeOf<Host.NotificationMessage>();
expectTypeOf<Sdk.PluginActionResult>().toEqualTypeOf<Host.PluginActionResult>();
expectTypeOf<Sdk.CalendarEvent>().toEqualTypeOf<Host.CalendarEvent>();
expectTypeOf<Sdk.PlaceDetailItem>().toEqualTypeOf<Host.PlaceDetailItem>();
expectTypeOf<Sdk.SearchResultPlace>().toEqualTypeOf<Host.SearchResultPlace>();
expectTypeOf<Sdk.SearchRequest>().toEqualTypeOf<Host.SearchRequest>();
expectTypeOf<Sdk.TripWarning>().toEqualTypeOf<Host.TripWarning>();
expectTypeOf<Sdk.ContributionTone>().toEqualTypeOf<Host.ContributionTone>();
expectTypeOf<Sdk.TableColumnContribution>().toEqualTypeOf<Host.TableColumnContribution>();
expectTypeOf<Sdk.TableActionContribution>().toEqualTypeOf<Host.TableActionContribution>();
expectTypeOf<Sdk.TableContribution>().toEqualTypeOf<Host.TableContribution>();
expectTypeOf<Sdk.MapMarkerContribution>().toEqualTypeOf<Host.MapMarkerContribution>();
expectTypeOf<Sdk.MapLayerFeature>().toEqualTypeOf<Host.MapLayerFeature>();
expectTypeOf<Sdk.MapLayerContribution>().toEqualTypeOf<Host.MapLayerContribution>();
expectTypeOf<Sdk.RouteWaypoint>().toEqualTypeOf<Host.RouteWaypoint>();
expectTypeOf<Sdk.RouteRequest>().toEqualTypeOf<Host.RouteRequest>();
expectTypeOf<Sdk.RouteLeg>().toEqualTypeOf<Host.RouteLeg>();
expectTypeOf<Sdk.RouteViaPoint>().toEqualTypeOf<Host.RouteViaPoint>();
expectTypeOf<Sdk.RouteProviderResult>().toEqualTypeOf<Host.RouteProviderResult>();
expectTypeOf<Sdk.DayScheduleContribution>().toEqualTypeOf<Host.DayScheduleContribution>();
expectTypeOf<Sdk.DayTintContribution>().toEqualTypeOf<Host.DayTintContribution>();
expectTypeOf<Sdk.PdfSection>().toEqualTypeOf<Host.PdfSection>();
expectTypeOf<Sdk.AtlasLayerCountry>().toEqualTypeOf<Host.AtlasLayerCountry>();
expectTypeOf<Sdk.AtlasLayer>().toEqualTypeOf<Host.AtlasLayer>();
expectTypeOf<Sdk.TripCardContribution>().toEqualTypeOf<Host.TripCardContribution>();
expectTypeOf<Sdk.JournalEntryRow>().toEqualTypeOf<Host.JournalEntryRow>();
expectTypeOf<Sdk.PluginRequest>().toEqualTypeOf<Host.PluginRequest>();
});
test('the shapes that carry a ctx have the same members on both sides', () => {
expectTypeOf<keyof Sdk.PluginContext>().toEqualTypeOf<keyof Host.PluginContext>();
expectTypeOf<keyof Sdk.PluginRoute>().toEqualTypeOf<keyof Host.PluginRoute>();
expectTypeOf<keyof Sdk.PluginJob>().toEqualTypeOf<keyof Host.PluginJob>();
expectTypeOf<keyof Sdk.PhotoProvider>().toEqualTypeOf<keyof Host.PhotoProvider>();
expectTypeOf<keyof Sdk.NotificationChannel>().toEqualTypeOf<keyof Host.NotificationChannel>();
expectTypeOf<keyof Sdk.CalendarSource>().toEqualTypeOf<keyof Host.CalendarSource>();
expectTypeOf<keyof Sdk.PlaceDetailProvider>().toEqualTypeOf<keyof Host.PlaceDetailProvider>();
expectTypeOf<keyof Sdk.SearchProvider>().toEqualTypeOf<keyof Host.SearchProvider>();
expectTypeOf<keyof Sdk.PoiCategoryProvider>().toEqualTypeOf<keyof Host.PoiCategoryProvider>();
expectTypeOf<keyof Sdk.WarningProvider>().toEqualTypeOf<keyof Host.WarningProvider>();
expectTypeOf<keyof Sdk.TableContributor>().toEqualTypeOf<keyof Host.TableContributor>();
expectTypeOf<keyof Sdk.MapMarkerProvider>().toEqualTypeOf<keyof Host.MapMarkerProvider>();
expectTypeOf<keyof Sdk.MapLayerProvider>().toEqualTypeOf<keyof Host.MapLayerProvider>();
expectTypeOf<keyof Sdk.RouteProvider>().toEqualTypeOf<keyof Host.RouteProvider>();
expectTypeOf<keyof Sdk.DayScheduleProvider>().toEqualTypeOf<keyof Host.DayScheduleProvider>();
expectTypeOf<keyof Sdk.DayTintProvider>().toEqualTypeOf<keyof Host.DayTintProvider>();
expectTypeOf<keyof Sdk.PdfSectionProvider>().toEqualTypeOf<keyof Host.PdfSectionProvider>();
expectTypeOf<keyof Sdk.AtlasLayerProvider>().toEqualTypeOf<keyof Host.AtlasLayerProvider>();
expectTypeOf<keyof Sdk.TripCardProvider>().toEqualTypeOf<keyof Host.TripCardProvider>();
expectTypeOf<keyof Sdk.JournalEntryProvider>().toEqualTypeOf<keyof Host.JournalEntryProvider>();
expectTypeOf<keyof Sdk.PluginEventSubscription>().toEqualTypeOf<keyof Host.PluginEventSubscription>();
expectTypeOf<keyof Sdk.PluginExport>().toEqualTypeOf<keyof Host.PluginExport>();
expectTypeOf<keyof Sdk.PluginSubscription>().toEqualTypeOf<keyof Host.PluginSubscription>();
expectTypeOf<keyof Sdk.McpToolProvider>().toEqualTypeOf<keyof Host.McpToolProvider>();
expectTypeOf<keyof Sdk.PluginDefinition>().toEqualTypeOf<keyof Host.PluginDefinition>();
});
test('every ctx namespace offers the same methods on both sides', () => {
type Members<T> = T extends (...args: never[]) => unknown ? never : keyof T;
expectTypeOf<Members<Sdk.PluginContext['id']>>().toEqualTypeOf<Members<Host.PluginContext['id']>>();
expectTypeOf<Members<Sdk.PluginContext['config']>>().toEqualTypeOf<Members<Host.PluginContext['config']>>();
expectTypeOf<Members<Sdk.PluginContext['settings']>>().toEqualTypeOf<Members<Host.PluginContext['settings']>>();
expectTypeOf<Members<Sdk.PluginContext['db']>>().toEqualTypeOf<Members<Host.PluginContext['db']>>();
expectTypeOf<Members<Sdk.PluginContext['trips']>>().toEqualTypeOf<Members<Host.PluginContext['trips']>>();
expectTypeOf<Members<Sdk.PluginContext['reservations']>>().toEqualTypeOf<Members<Host.PluginContext['reservations']>>();
expectTypeOf<Members<Sdk.PluginContext['accommodations']>>().toEqualTypeOf<Members<Host.PluginContext['accommodations']>>();
expectTypeOf<Members<Sdk.PluginContext['packing']>>().toEqualTypeOf<Members<Host.PluginContext['packing']>>();
expectTypeOf<Members<Sdk.PluginContext['files']>>().toEqualTypeOf<Members<Host.PluginContext['files']>>();
expectTypeOf<Members<Sdk.PluginContext['collab']>>().toEqualTypeOf<Members<Host.PluginContext['collab']>>();
expectTypeOf<Members<Sdk.PluginContext['notify']>>().toEqualTypeOf<Members<Host.PluginContext['notify']>>();
expectTypeOf<Members<Sdk.PluginContext['ai']>>().toEqualTypeOf<Members<Host.PluginContext['ai']>>();
expectTypeOf<Members<Sdk.PluginContext['oauth']>>().toEqualTypeOf<Members<Host.PluginContext['oauth']>>();
expectTypeOf<Members<Sdk.PluginContext['scheduler']>>().toEqualTypeOf<Members<Host.PluginContext['scheduler']>>();
expectTypeOf<Members<Sdk.PluginContext['weather']>>().toEqualTypeOf<Members<Host.PluginContext['weather']>>();
expectTypeOf<Members<Sdk.PluginContext['rates']>>().toEqualTypeOf<Members<Host.PluginContext['rates']>>();
expectTypeOf<Members<Sdk.PluginContext['categories']>>().toEqualTypeOf<Members<Host.PluginContext['categories']>>();
expectTypeOf<Members<Sdk.PluginContext['tags']>>().toEqualTypeOf<Members<Host.PluginContext['tags']>>();
expectTypeOf<Members<Sdk.PluginContext['todos']>>().toEqualTypeOf<Members<Host.PluginContext['todos']>>();
expectTypeOf<Members<Sdk.PluginContext['journal']>>().toEqualTypeOf<Members<Host.PluginContext['journal']>>();
expectTypeOf<Members<Sdk.PluginContext['atlas']>>().toEqualTypeOf<Members<Host.PluginContext['atlas']>>();
expectTypeOf<Members<Sdk.PluginContext['vacay']>>().toEqualTypeOf<Members<Host.PluginContext['vacay']>>();
expectTypeOf<Members<Sdk.PluginContext['collections']>>().toEqualTypeOf<Members<Host.PluginContext['collections']>>();
expectTypeOf<Members<Sdk.PluginContext['daynotes']>>().toEqualTypeOf<Members<Host.PluginContext['daynotes']>>();
expectTypeOf<Members<Sdk.PluginContext['costs']>>().toEqualTypeOf<Members<Host.PluginContext['costs']>>();
expectTypeOf<Members<Sdk.PluginContext['places']>>().toEqualTypeOf<Members<Host.PluginContext['places']>>();
expectTypeOf<Members<Sdk.PluginContext['days']>>().toEqualTypeOf<Members<Host.PluginContext['days']>>();
expectTypeOf<Members<Sdk.PluginContext['itinerary']>>().toEqualTypeOf<Members<Host.PluginContext['itinerary']>>();
expectTypeOf<Members<Sdk.PluginContext['meta']>>().toEqualTypeOf<Members<Host.PluginContext['meta']>>();
expectTypeOf<Members<Sdk.PluginContext['users']>>().toEqualTypeOf<Members<Host.PluginContext['users']>>();
expectTypeOf<Members<Sdk.PluginContext['ws']>>().toEqualTypeOf<Members<Host.PluginContext['ws']>>();
expectTypeOf<Members<Sdk.PluginContext['log']>>().toEqualTypeOf<Members<Host.PluginContext['log']>>();
expectTypeOf<Members<Sdk.PluginContext['plugins']>>().toEqualTypeOf<Members<Host.PluginContext['plugins']>>();
expectTypeOf<Members<Sdk.PluginContext['events']>>().toEqualTypeOf<Members<Host.PluginContext['events']>>();
});
+45
View File
@@ -0,0 +1,45 @@
/**
* The SDK half of the manifest parity corpus (test/fixtures/manifest-corpus.ts). It
* runs standalone; the server's manifest-parity test runs the same corpus through
* the host's loader as well, so the two cannot drift apart unseen.
*/
import { describe, expect, it } from 'vitest';
import { validateManifest } from '../src/manifest.js';
import { PLUGIN_API_VERSION } from '../src/index.js';
import { MANIFEST_CORPUS } from './fixtures/manifest-corpus.js';
describe('manifest corpus — validate', () => {
it.each(MANIFEST_CORPUS)('$name', ({ manifest, host, sdk }) => {
const result = validateManifest(manifest);
expect(result.ok ? 'accept' : 'reject', result.errors.join('; ')).toBe(sdk ?? host);
});
it('marks every stricter-than-host case as one, with its reason', () => {
for (const c of MANIFEST_CORPUS) {
if (c.sdk === undefined) continue;
expect(c.sdk, `${c.name}: the SDK may only ever be stricter than the host`).toBe('reject');
expect(c.host, c.name).toBe('accept');
expect(c.why, `${c.name} needs a reason`).toBeTruthy();
}
});
});
describe('apiVersion', () => {
const base = { id: 'demo-plugin', name: 'Demo', version: '1.0.0', type: 'integration', trek: '>=4.0.0 <5.0.0' };
it.each([0, -1, 1.5, '1', null])('refuses %p, which is not a positive integer', (apiVersion) => {
expect(validateManifest({ ...base, apiVersion }).errors).toContain('apiVersion must be a positive integer');
});
it('refuses a version newer than the plugin API TREK implements', () => {
const next = PLUGIN_API_VERSION + 1;
expect(validateManifest({ ...base, apiVersion: next }).errors).toEqual([
`apiVersion ${next} is newer than the plugin API TREK implements (v${PLUGIN_API_VERSION})`,
]);
});
it('keeps an accepted version and defaults a missing one to 1', () => {
expect(validateManifest({ ...base, apiVersion: PLUGIN_API_VERSION }).manifest?.apiVersion).toBe(PLUGIN_API_VERSION);
expect(validateManifest(base).manifest?.apiVersion).toBe(1);
});
});
+5 -3
View File
@@ -99,13 +99,15 @@ describe.skipIf(!inMonorepo)('core event catalog', () => {
});
describe.skipIf(!inMonorepo)('settings-field attribute parity', () => {
it("SETTING_FIELD_KEYS matches the host's install/manifest.ts", () => {
it("SETTING_FIELD_KEYS matches the host's protocol/manifest-rules.ts", () => {
// The `manifest.settings-known-keys` check warns on an attribute the host would
// silently drop, so the list must be the host's — compared whole, both ways round.
const theirsFile = path.resolve(here, '../../server/src/nest/plugins/install/manifest.ts');
// It is generated into host-facts.ts now (check:plugin-facts); this reads the source
// as well so a standalone run of this suite catches a stale artefact.
const theirsFile = path.resolve(here, '../../server/src/nest/plugins/protocol/manifest-rules.ts');
const src = fs.readFileSync(theirsFile, 'utf8');
const block = src.match(/export const SETTING_FIELD_KEYS = \[([\s\S]*?)\] as const/);
expect(block, 'SETTING_FIELD_KEYS not found in install/manifest.ts').toBeTruthy();
expect(block, 'SETTING_FIELD_KEYS not found in protocol/manifest-rules.ts').toBeTruthy();
const theirs = [...block![1].matchAll(/'([^']+)'/g)].map((m) => m[1]);
expect([...SETTING_FIELD_KEYS]).toEqual(theirs);
});