11// Plugin Sdk Surface Report tests cover plugin sdk surface report script behavior.
22import { spawnSync } from "node:child_process" ;
3- import { readFileSync } from "node:fs" ;
43import { describe , expect , it } from "vitest" ;
54
65function runSurfaceReport ( env : Record < string , string > ) {
@@ -14,14 +13,16 @@ function runSurfaceReport(env: Record<string, string>) {
1413 } ) ;
1514}
1615
17- function readDefaultPublicFunctionExportBudget ( ) {
18- const source = readFileSync ( "scripts/plugin-sdk-surface-report.mjs" , "utf8" ) ;
19- const match =
20- / p u b l i c F u n c t i o n E x p o r t s : \s * r e a d B u d g e t E n v \( " O P E N C L A W _ P L U G I N _ S D K _ M A X _ P U B L I C _ F U N C T I O N _ E X P O R T S " , \s * ( \d + ) \) / u. exec (
21- source ,
22- ) ;
16+ function readCurrentPublicFunctionExportCount ( ) {
17+ const result = runSurfaceReport ( { } ) ;
18+ expect ( result . status ) . toBe ( 0 ) ;
19+ expect ( result . stderr ) . toBe ( "" ) ;
20+
21+ const match = / p u b l i c p a c k a g e S D K e n t r y p o i n t s : [ \s \S ] * ?\n c a l l a b l e e x p o r t s : ( \d + ) / u. exec (
22+ result . stdout ,
23+ ) ;
2324 if ( match === null || match [ 1 ] === undefined ) {
24- throw new Error ( "failed to read default public function export budget " ) ;
25+ throw new Error ( "failed to read current public function export count " ) ;
2526 }
2627 return Number ( match [ 1 ] ) ;
2728}
@@ -95,7 +96,7 @@ describe("plugin SDK surface report", () => {
9596 } ) ;
9697
9798 it ( "keeps generated package declarations out of source surface counts" , ( ) => {
98- const budget = readDefaultPublicFunctionExportBudget ( ) ;
99+ const budget = readCurrentPublicFunctionExportCount ( ) ;
99100 const result = runSurfaceReport ( {
100101 OPENCLAW_PLUGIN_SDK_MAX_PUBLIC_FUNCTION_EXPORTS : String ( budget - 1 ) ,
101102 } ) ;
0 commit comments