






















@@ -14,39 +14,57 @@ function runSurfaceReport(env: Record<string, string>) {
1414});
1515}
161617-function readCurrentPublicFunctionExportCount() {
17+type PublicSurfaceCounts = {
18+callableExports: number;
19+exports: number;
20+wildcardReexports: number;
21+};
22+23+function readDefaultPublicSurfaceBudgets(): PublicSurfaceCounts {
24+const source = readFileSync("scripts/plugin-sdk-surface-report.mjs", "utf8");
25+const readFallback = (budgetKey: string) => {
26+const match = new RegExp(
27+`${budgetKey}:\\s*readBudgetEnv\\(\\s*"[^"]+",\\s*(\\d+)`,
28+"u",
29+).exec(source);
30+if (match === null || match[1] === undefined) {
31+throw new Error(`failed to read default ${budgetKey} budget`);
32+}
33+return Number(match[1]);
34+};
35+return {
36+exports: readFallback("publicExports"),
37+callableExports: readFallback("publicFunctionExports"),
38+wildcardReexports: readFallback("publicWildcardReexports"),
39+};
40+}
41+42+function readCurrentPublicSurfaceCounts(): PublicSurfaceCounts {
1843const result = runSurfaceReport({});
1944expect(result.status).toBe(0);
2045expect(result.stderr).toBe("");
214622-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");
47+const totalsMatch =
48+/public package SDK entrypoints:[\s\S]*?\n exports: (\d+)\n callable exports: (\d+)/u.exec(
49+result.stdout,
50+);
51+const wildcardsMatch = /public wildcard reexports: (\d+)/u.exec(result.stdout);
52+if (
53+totalsMatch === null ||
54+totalsMatch[1] === undefined ||
55+totalsMatch[2] === undefined ||
56+wildcardsMatch === null ||
57+wildcardsMatch[1] === undefined
58+) {
59+throw new Error("failed to read current public surface counts");
3060}
3161return {
32-exports: Number(match[1]),
33-functionExports: Number(match[2]),
62+exports: Number(totalsMatch[1]),
63+callableExports: Number(totalsMatch[2]),
64+wildcardReexports: Number(wildcardsMatch[1]),
3465};
3566}
366737-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",
42-);
43-const result = match.exec(source);
44-if (result === null || result[1] === undefined) {
45-throw new Error(`failed to read default budget for ${envName}`);
46-}
47-return Number(result[1]);
48-}
49-5068describe("plugin SDK surface report", () => {
5169it("rejects unknown CLI options before collecting SDK stats", () => {
5270const result = spawnSync(
@@ -115,20 +133,12 @@ describe("plugin SDK surface report", () => {
115133expect(result.stderr).toBe("");
116134});
117135118-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-);
136+it("keeps default public surface budgets pinned to current source counts", () => {
137+expect(readDefaultPublicSurfaceBudgets()).toEqual(readCurrentPublicSurfaceCounts());
128138});
129139130140it("keeps generated package declarations out of source surface counts", () => {
131-const budget = readCurrentPublicFunctionExportCount();
141+const budget = readCurrentPublicSurfaceCounts().callableExports;
132142const result = runSurfaceReport({
133143OPENCLAW_PLUGIN_SDK_MAX_PUBLIC_FUNCTION_EXPORTS: String(budget - 1),
134144});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。