|
1 | 1 | // Plugin Sdk Surface Report tests cover plugin sdk surface report script behavior. |
2 | 2 | import { spawnSync } from "node:child_process"; |
3 | | -import { readFileSync } from "node:fs"; |
4 | 3 | import { describe, expect, it } from "vitest"; |
5 | 4 | |
6 | 5 | function runSurfaceReport(env: Record<string, string>) { |
@@ -14,14 +13,16 @@ function runSurfaceReport(env: Record<string, string>) {
|
14 | 13 | }); |
15 | 14 | } |
16 | 15 | |
17 | | -function readDefaultPublicFunctionExportBudget() { |
18 | | -const source = readFileSync("scripts/plugin-sdk-surface-report.mjs", "utf8"); |
19 | | -const match = |
20 | | -/publicFunctionExports:\s*readBudgetEnv\("OPENCLAW_PLUGIN_SDK_MAX_PUBLIC_FUNCTION_EXPORTS",\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 = /public package SDK entrypoints:[\s\S]*?\n callable exports: (\d+)/u.exec( |
| 22 | +result.stdout, |
| 23 | +); |
23 | 24 | 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"); |
25 | 26 | } |
26 | 27 | return Number(match[1]); |
27 | 28 | } |
@@ -95,7 +96,7 @@ describe("plugin SDK surface report", () => {
|
95 | 96 | }); |
96 | 97 | |
97 | 98 | it("keeps generated package declarations out of source surface counts", () => { |
98 | | -const budget = readDefaultPublicFunctionExportBudget(); |
| 99 | +const budget = readCurrentPublicFunctionExportCount(); |
99 | 100 | const result = runSurfaceReport({ |
100 | 101 | OPENCLAW_PLUGIN_SDK_MAX_PUBLIC_FUNCTION_EXPORTS: String(budget - 1), |
101 | 102 | }); |
|