@@ -6,7 +6,7 @@ import { spawnSync } from "node:child_process";
66import fs from "node:fs" ;
77import path from "node:path" ;
88import ts from "typescript" ;
9- import { afterEach , beforeAll , describe , expect , it } from "vitest" ;
9+ import { afterEach , describe , expect , it } from "vitest" ;
1010import { publicPluginSdkEntrypoints } from "../../scripts/lib/plugin-sdk-entries.mts" ;
1111import { useAutoCleanupTempDirTracker } from "../../test/helpers/temp-dir.js" ;
1212import { formatPluginSdkApiTypeAlias } from "./api-baseline-declaration-print.js" ;
@@ -17,35 +17,38 @@ import {
1717 renderPluginSdkApiBaseline ,
1818 renderPluginSdkApiBaselineModules ,
1919 writeRenderedPluginSdkApiBaselineArtifacts ,
20+ type PluginSdkApiModule ,
2021 type PluginSdkApiBaselineRender ,
2122} from "./api-baseline.js" ;
2223
23- const TEST_ENTRYPOINTS = [
24- "agent-harness-runtime" ,
25- "approval-gateway-runtime" ,
26- "channel-policy" ,
27- "core" ,
28- "infra-runtime" ,
29- "plugin-entry" ,
30- "provider-auth" ,
31- "provider-catalog-live-runtime" ,
32- "provider-oauth-runtime" ,
33- "provider-selection-runtime" ,
34- "provider-web-search-config-contract" ,
35- "realtime-voice" ,
36- "session-catalog" ,
37- "sqlite-runtime-testing" ,
38- ] as const ;
39-
4024const tempDirs = useAutoCleanupTempDirTracker ( afterEach ) ;
4125
42- function contractContents ( rendered : PluginSdkApiBaselineRender ) : Record < string , string > {
43- return Object . fromEntries ( rendered . contractFiles . map ( ( file ) => [ file . fileName , file . content ] ) ) ;
26+ const SERIALIZATION_MODULES = [ "fixture-a" , "fixture-b" ] . map (
27+ ( entrypoint , index ) : PluginSdkApiModule => ( {
28+ category : null ,
29+ entrypoint,
30+ exports : [
31+ {
32+ closureHash : String ( index ) . repeat ( 64 ) ,
33+ declaration : `export type Fixture${ index } = string;` ,
34+ exportName : `Fixture${ index } ` ,
35+ kind : "type" ,
36+ source : { path : `src/plugin-sdk/${ entrypoint } .ts` } ,
37+ } ,
38+ ] ,
39+ importSpecifier : `openclaw/plugin-sdk/${ entrypoint } ` ,
40+ source : { path : `src/plugin-sdk/${ entrypoint } .ts` } ,
41+ } ) ,
42+ ) ;
43+ const rendered = renderPluginSdkApiBaselineModules ( SERIALIZATION_MODULES ) ;
44+
45+ function contractContents ( result : PluginSdkApiBaselineRender ) : Record < string , string > {
46+ return Object . fromEntries ( result . contractFiles . map ( ( file ) => [ file . fileName , file . content ] ) ) ;
4447}
4548
46- function writeContractFiles ( directory : string , rendered : PluginSdkApiBaselineRender ) : void {
49+ function writeContractFiles ( directory : string , result : PluginSdkApiBaselineRender ) : void {
4750 fs . mkdirSync ( directory , { recursive : true } ) ;
48- for ( const file of rendered . contractFiles ) {
51+ for ( const file of result . contractFiles ) {
4952 fs . writeFileSync ( path . join ( directory , file . fileName ) , file . content ) ;
5053 }
5154}
@@ -133,6 +136,11 @@ async function renderPrivateDeclarationFixture(params?: {
133136 "type FixtureOptions = { nested: FixtureOptionLeaf };" ,
134137 "type FixtureResult = { nested: FixtureResultLeaf };" ,
135138 "export declare function createFixture(options: FixtureOptions): FixtureResult;" ,
139+ "export class FixtureError extends Error {" ,
140+ " readonly status: number;" ,
141+ ' constructor(status: number) { super("fixture"); this.status = status; }' ,
142+ " getStatus() { return this.status; }" ,
143+ "}" ,
136144 ] . join ( "\n" ) ,
137145 ) ;
138146 fs . writeFileSync (
@@ -191,14 +199,6 @@ function createTupleAliasFixture(tuple: string, warmup: string, prewarm: boolean
191199}
192200
193201describe ( "Plugin SDK API baseline" , ( ) => {
194- let rendered : PluginSdkApiBaselineRender ;
195-
196- // Rendering builds a TS program across SDK entrypoints. Loaded CI runners can
197- // exceed the default hook budget; this work is compile-bound, not a hang.
198- beforeAll ( async ( ) => {
199- rendered = await renderPluginSdkApiBaseline ( { entrypoints : TEST_ENTRYPOINTS } ) ;
200- } , 300_000 ) ;
201-
202202 it ( "normalizes declaration import paths to repo-relative paths" , ( ) => {
203203 const repoRoot = process . cwd ( ) ;
204204 const modelCatalogPath = path . join ( repoRoot , "src" , "agents" , "agent-model-discovery" ) ;
@@ -286,78 +286,11 @@ describe("Plugin SDK API baseline", () => {
286286 ) ;
287287 } ) ;
288288
289- it ( "renders complete declarations for the canonical public entrypoint inventory" , ( ) => {
289+ it ( "uses the canonical public entrypoint inventory" , ( ) => {
290290 expect ( listPluginSdkApiBaselineEntrypoints ( ) ) . toEqual ( publicPluginSdkEntrypoints ) ;
291-
292- const findDeclaration = ( exportName : string ) =>
293- rendered . baseline . modules
294- . flatMap ( ( moduleSurface ) => moduleSurface . exports )
295- . find (
296- ( exportSurface ) =>
297- exportSurface . exportName === exportName && exportSurface . declaration !== null ,
298- ) ?. declaration ;
299-
300- expect ( rendered . baseline . modules . find ( ( entry ) => entry . entrypoint === "infra-runtime" ) ) . toEqual (
301- expect . objectContaining ( {
302- category : null ,
303- importSpecifier : "openclaw/plugin-sdk/infra-runtime" ,
304- } ) ,
305- ) ;
306- expect ( findDeclaration ( "OAuthProviderInterface" ) ) . toContain ( "readonly id: OAuthProviderId;" ) ;
307- expect ( findDeclaration ( "OAuthProviderInterface" ) ) . toContain (
308- "login(callbacks: OAuthLoginCallbacks): Promise<OAuthCredentials>;" ,
309- ) ;
310- expect ( findDeclaration ( "LiveModelCatalogHttpError" ) ) . toContain ( "readonly status: number;" ) ;
311- expect ( findDeclaration ( "LiveModelCatalogHttpError" ) ) . toContain (
312- "constructor(providerId: string, status: number);" ,
313- ) ;
314- expect ( findDeclaration ( "AgentHarnessPreflightError" ) ) . toContain ( 'readonly scope?: "harness";' ) ;
315- expect ( findDeclaration ( "AgentHarnessPreflightError" ) ) . toContain (
316- "constructor(message: string, options?: ErrorOptions & {" ,
317- ) ;
318- expect ( findDeclaration ( "AgentHarnessPreflightError" ) ) . toContain ( 'scope?: "harness";' ) ;
319- expect ( findDeclaration ( "AgentHarnessPreflightError" ) ) . not . toContain ( "harnessId" ) ;
320- expect ( findDeclaration ( "LiveModelCatalogHttpError" ) ) . not . toContain ( "super(" ) ;
321- expect ( findDeclaration ( "LiveModelRowProjection" ) ) . toContain (
322- "export type LiveModelRowProjection" ,
323- ) ;
324- expect ( findDeclaration ( "ApprovalResolveResult" ) ) . not . toContain ( "see source" ) ;
325- expect ( findDeclaration ( "RealtimeVoiceAgentConsultRuntime" ) ) . not . toContain ( "see source" ) ;
326- expect ( findDeclaration ( "createWebSearchProviderContractFields" ) ) . toContain (
327- "export function createWebSearchProviderContractFields(" ,
328- ) ;
329- expect ( findDeclaration ( "createWebSearchProviderContractFields" ) ) . not . toContain (
330- "createBaseWebSearchProviderContractFields" ,
331- ) ;
332- expect ( findDeclaration ( "OPENCLAW_VERSION" ) ) . toContain ( "export const OPENCLAW_VERSION:" ) ;
333- expect ( findDeclaration ( "SqliteTrajectoryRuntimeEventForTest" ) ) . toContain (
334- "export type SqliteTrajectoryRuntimeEventForTest =" ,
335- ) ;
336- expect (
337- rendered . baseline . modules
338- . flatMap ( ( moduleSurface ) => moduleSurface . exports )
339- . find ( ( exportSurface ) => exportSurface . exportName === "definePluginEntry" ) ?. closureHash ,
340- ) . toMatch ( / ^ [ a - f 0 - 9 ] { 64 } $ / u) ;
341- expect ( findDeclaration ( "definePluginEntry" ) ) . toContain ( "DefinePluginEntryOptions" ) ;
342- expect ( findDeclaration ( "definePluginEntry" ) ) . toContain ( "DefinedPluginEntry" ) ;
343- expect ( findDeclaration ( "ProviderSelection" ) ) . toContain (
344- "export type ProviderSelection<TProvider> =" ,
345- ) ;
346- expect ( findDeclaration ( "SessionCatalogEntrySummary" ) ) . toContain (
347- "export interface SessionCatalogEntrySummary" ,
348- ) ;
349- expect ( findDeclaration ( "SessionCatalogEntrySummary" ) ) . toContain ( "entry: SessionEntry;" ) ;
350- expect ( rendered . json ) . not . toContain ( '"line":' ) ;
351- expect ( rendered . json ) . toContain ( '"source": {' ) ;
352- const contract = rendered . contractFiles . map ( ( file ) => file . content ) . join ( "" ) ;
353- expect ( contract ) . not . toContain ( '"sourceLine":' ) ;
354- expect ( contract ) . not . toContain ( '"sourcePath":' ) ;
355- expect ( contract ) . toContain ( '"contentHash":"' ) ;
356- expect ( contract ) . not . toContain ( '"closureHash":"' ) ;
357- expect ( contract ) . not . toContain ( "// declaration closure:" ) ;
358291 } ) ;
359292
360- it ( "renders snapshots independently of entrypoint discovery order" , ( ) => {
293+ it ( "serializes modules independently of entrypoint discovery order" , ( ) => {
361294 const reverse = renderPluginSdkApiBaselineModules ( rendered . baseline . modules . toReversed ( ) ) ;
362295
363296 expect ( reverse . json ) . toBe ( rendered . json ) ;
@@ -432,6 +365,11 @@ describe("Plugin SDK API baseline", () => {
432365 expect . objectContaining ( { contentHash : expect . stringMatching ( / ^ [ a - f 0 - 9 ] { 64 } $ / u) } ) ,
433366 ] ) ,
434367 ) ;
368+ const contract = rendered . contractFiles . map ( ( file ) => file . content ) . join ( "" ) ;
369+ expect ( rendered . json ) . toContain ( '"source": {' ) ;
370+ expect ( contract ) . not . toContain ( '"sourceLine":' ) ;
371+ expect ( contract ) . not . toContain ( '"sourcePath":' ) ;
372+ expect ( contract ) . not . toContain ( '"closureHash":' ) ;
435373
436374 const mergeDir = tempDirs . make ( "openclaw-plugin-sdk-api-merge-" ) ;
437375 const contractDirectory = path . join ( mergeDir , "plugin-sdk-api-baseline" ) ;
@@ -476,8 +414,15 @@ describe("Plugin SDK API baseline", () => {
476414 it ( "renders byte-identical contract files deterministically" , async ( ) => {
477415 const firstRender = await renderPrivateDeclarationFixture ( ) ;
478416 const secondRender = await renderPrivateDeclarationFixture ( ) ;
417+ const fixtureError = firstRender . baseline . modules [ 0 ] ?. exports . find (
418+ ( exportSurface ) => exportSurface . exportName === "FixtureError" ,
419+ ) ?. declaration ;
479420
480421 expect ( secondRender . contractFiles ) . toEqual ( firstRender . contractFiles ) ;
422+ expect ( fixtureError ) . toContain ( "constructor(status: number);" ) ;
423+ expect ( fixtureError ) . toContain ( "getStatus(): number;" ) ;
424+ expect ( fixtureError ) . not . toContain ( "super(" ) ;
425+ expect ( fixtureError ) . not . toContain ( "return this.status" ) ;
481426 } ) ;
482427
483428 it ( "checks and repairs modified, missing, and stale contract records" , async ( ) => {
@@ -642,13 +587,16 @@ describe("Plugin SDK API baseline", () => {
642587 it ( "ignores unrelated declarations beside an aliased re-export" , async ( ) => {
643588 const render = ( extra = "" ) =>
644589 renderSourceFixture ( {
645- "fixture.ts" : 'export { internalLeaf as publicLeaf } from "./dep.js";\n' ,
646- "dep.ts" : `export type internalLeaf = { value: string }; \n${ extra } ` ,
590+ "fixture.ts" : 'export { internalFixture as publicFixture } from "./dep.js";\n' ,
591+ "dep.ts" : `export function internalFixture(value: string): string { return value; } \n${ extra } ` ,
647592 } ) ;
648593 const baseline = await render ( ) ;
649594 const unrelated = await render ( "export type Unrelated = { ignored: boolean };\n" ) ;
595+ const declaration = baseline . baseline . modules [ 0 ] ?. exports [ 0 ] ?. declaration ;
650596
651597 expect ( unrelated . contractFiles ) . toEqual ( baseline . contractFiles ) ;
598+ expect ( declaration ) . toContain ( "function publicFixture(" ) ;
599+ expect ( declaration ) . not . toContain ( "internalFixture" ) ;
652600 } ) ;
653601
654602 it ( "captures transitive private declaration changes deterministically" , async ( ) => {
0 commit comments