Skip to content

Commit 58b9a1c

Browse files
committed
test(env): cover ratchet growth and boundary; document surface budgets
1 parent c516441 commit 58b9a1c

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

docs/ci.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,22 @@ The changed-target PR plan reduces the common Node test burst from 14 Blacksmith
207207

208208
Canonical-repo CI keeps Blacksmith as the default runner path for normal push and pull-request runs. `workflow_dispatch` and non-canonical repository runs use GitHub-hosted runners, but normal canonical runs do not currently probe Blacksmith queue health or automatically fall back to GitHub-hosted labels when Blacksmith is unavailable.
209209

210+
## Surface ratchets
211+
212+
Two shrink-only budgets guard the configuration surface. Both fail CI on growth
213+
until the budget file is consciously updated in the same PR, and both demand a
214+
ratchet-down when cleanup lowers the real count.
215+
216+
- `config/env-var-count-budget.txt` caps the number of distinct `OPENCLAW_*`
217+
names in production source under `src/`, `packages/`, and `extensions/`
218+
(tests and QA Lab excluded). Checked by `node scripts/check-env-var-count.mjs`.
219+
Removing env vars: lower the number in the same PR. Adding one is a
220+
config-surface decision — justify it in the PR body.
221+
- `docs/.generated/config-baseline.counts.json` caps the per-kind
222+
(core/channel/plugin) `openclaw.json` schema entry counts. Checked by
223+
`pnpm config:docs:check`; regenerate with `pnpm config:docs:gen` after any
224+
schema change.
225+
210226
## Local equivalents
211227

212228
```bash

test/scripts/check-env-var-count.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,45 @@ describe("check-env-var-count", () => {
7373
expect(() => main(["--base", "missing"], root)).toThrow(/Could not resolve/u);
7474
});
7575

76+
it("rejects growth above the budget", () => {
77+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-env-count-grow-"));
78+
tempDirs.push(root);
79+
fs.mkdirSync(path.join(root, "config"), { recursive: true });
80+
fs.mkdirSync(path.join(root, "src"), { recursive: true });
81+
fs.writeFileSync(path.join(root, "config/env-var-count-budget.txt"), "1\n");
82+
fs.writeFileSync(
83+
path.join(root, "src/runtime.ts"),
84+
"process.env.OPENCLAW_ONE; process.env.OPENCLAW_TWO;\n",
85+
);
86+
execFileSync("git", ["init"], { cwd: root, stdio: "ignore" });
87+
execFileSync("git", ["add", "."], { cwd: root, stdio: "ignore" });
88+
execFileSync(
89+
"git",
90+
["-c", "user.name=OpenClaw", "-c", "[email protected]", "commit", "-m", "base"],
91+
{ cwd: root, stdio: "ignore" },
92+
);
93+
94+
expect(() => main(["--base", "HEAD"], root)).toThrow(/exceeds budget|over budget/u);
95+
});
96+
97+
it("passes when the count exactly matches the budget", () => {
98+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-env-count-exact-"));
99+
tempDirs.push(root);
100+
fs.mkdirSync(path.join(root, "config"), { recursive: true });
101+
fs.mkdirSync(path.join(root, "src"), { recursive: true });
102+
fs.writeFileSync(path.join(root, "config/env-var-count-budget.txt"), "1\n");
103+
fs.writeFileSync(path.join(root, "src/runtime.ts"), "process.env.OPENCLAW_ONLY;\n");
104+
execFileSync("git", ["init"], { cwd: root, stdio: "ignore" });
105+
execFileSync("git", ["add", "."], { cwd: root, stdio: "ignore" });
106+
execFileSync(
107+
"git",
108+
["-c", "user.name=OpenClaw", "-c", "[email protected]", "commit", "-m", "base"],
109+
{ cwd: root, stdio: "ignore" },
110+
);
111+
112+
expect(() => main(["--base", "HEAD"], root)).not.toThrow();
113+
});
114+
76115
it("rejects stale headroom after the count shrinks", () => {
77116
const root = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-env-count-tight-"));
78117
tempDirs.push(root);

0 commit comments

Comments
 (0)