Skip to content

Commit 6df6728

Browse files
committed
fix(sdk): keep surface budgets tight
1 parent 5eec215 commit 6df6728

2 files changed

Lines changed: 39 additions & 7 deletions

File tree

scripts/plugin-sdk-surface-report.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ let publicDeprecatedExportsByEntrypointBudget;
202202
try {
203203
budgets = {
204204
publicEntrypoints: readBudgetEnv("OPENCLAW_PLUGIN_SDK_MAX_PUBLIC_ENTRYPOINTS", 322),
205-
publicExports: readBudgetEnv("OPENCLAW_PLUGIN_SDK_MAX_PUBLIC_EXPORTS", 10411),
206-
publicFunctionExports: readBudgetEnv("OPENCLAW_PLUGIN_SDK_MAX_PUBLIC_FUNCTION_EXPORTS", 5251),
205+
publicExports: readBudgetEnv("OPENCLAW_PLUGIN_SDK_MAX_PUBLIC_EXPORTS", 10381),
206+
publicFunctionExports: readBudgetEnv("OPENCLAW_PLUGIN_SDK_MAX_PUBLIC_FUNCTION_EXPORTS", 5210),
207207
publicDeprecatedExports: readBudgetEnv(
208208
"OPENCLAW_PLUGIN_SDK_MAX_PUBLIC_DEPRECATED_EXPORTS",
209209
3247,

test/scripts/plugin-sdk-surface-report.test.ts

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Plugin Sdk Surface Report tests cover plugin sdk surface report script behavior.
22
import { spawnSync } from "node:child_process";
3+
import { readFileSync } from "node:fs";
34
import { describe, expect, it } from "vitest";
45

56
function runSurfaceReport(env: Record<string, string>) {
@@ -18,13 +19,32 @@ function readCurrentPublicFunctionExportCount() {
1819
expect(result.status).toBe(0);
1920
expect(result.stderr).toBe("");
2021

21-
const match = /public package SDK entrypoints:[\s\S]*?\n callable exports: (\d+)/u.exec(
22-
result.stdout,
22+
return parseCurrentPublicCounts(result.stdout).functionExports;
23+
}
24+
25+
function parseCurrentPublicCounts(stdout: string) {
26+
const match = /public package SDK entrypoints:[\s\S]*?\n exports: (\d+)\n callable exports: (\d+)/u
27+
.exec(stdout);
28+
if (match === null || match[1] === undefined || match[2] === undefined) {
29+
throw new Error("failed to read current public export counts");
30+
}
31+
return {
32+
exports: Number(match[1]),
33+
functionExports: Number(match[2]),
34+
};
35+
}
36+
37+
function readDefaultBudget(envName: string): number {
38+
const source = readFileSync("scripts/plugin-sdk-surface-report.mjs", "utf8");
39+
const match = new RegExp(
40+
`readBudgetEnv\\("${envName}",\\s*(\\d+)\\)`,
41+
"u",
2342
);
24-
if (match === null || match[1] === undefined) {
25-
throw new Error("failed to read current public function export count");
43+
const result = match.exec(source);
44+
if (result === null || result[1] === undefined) {
45+
throw new Error(`failed to read default budget for ${envName}`);
2646
}
27-
return Number(match[1]);
47+
return Number(result[1]);
2848
}
2949

3050
describe("plugin SDK surface report", () => {
@@ -95,6 +115,18 @@ describe("plugin SDK surface report", () => {
95115
expect(result.stderr).toBe("");
96116
});
97117

118+
it("keeps default public budgets tight to the current source surface", () => {
119+
const result = runSurfaceReport({});
120+
expect(result.status).toBe(0);
121+
expect(result.stderr).toBe("");
122+
123+
const counts = parseCurrentPublicCounts(result.stdout);
124+
expect(readDefaultBudget("OPENCLAW_PLUGIN_SDK_MAX_PUBLIC_EXPORTS")).toBe(counts.exports);
125+
expect(readDefaultBudget("OPENCLAW_PLUGIN_SDK_MAX_PUBLIC_FUNCTION_EXPORTS")).toBe(
126+
counts.functionExports,
127+
);
128+
});
129+
98130
it("keeps generated package declarations out of source surface counts", () => {
99131
const budget = readCurrentPublicFunctionExportCount();
100132
const result = runSurfaceReport({

0 commit comments

Comments
 (0)