Skip to content

Commit a4db1d2

Browse files
TheodoreSpeaksclaude
authored andcommitted
fix(cli): make the generated v2 API a fixed point of the formatter
The pre-commit hook rewrote the generated file immediately after it was committed, so `check:cli-api` then failed in CI reporting contract drift that had not happened — the only difference was quote style. The biome.json exclusion added alongside it does not help: lint-staged runs `biome check --write` on explicit paths, which bypasses `files.includes`. It implied protection it never provided, so it is removed. The generator now pipes its output through `biome format --stdin-file-path` instead, making the emitted file conformant by construction. The hook has nothing left to change, and the check compares like with like. A formatter failure throws rather than emitting unformatted output, since falling back silently would reopen the same loop. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EsThUPqZXjwuuyRjBbmVkj
1 parent 21ffeb4 commit a4db1d2

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

biome.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
"!**/.venv",
3434
"!**/uploads",
3535
"!**/apps/sim/lib/execution/sandbox/bundles/*.cjs",
36-
"!**/packages/sim-cli/src/generated",
3736
"!**/test-results",
3837
"!**/playwright-report"
3938
]

scripts/generate-v2-cli-api.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
* bun run scripts/generate-v2-cli-api.ts --check-openapi
2828
*/
2929

30+
import { spawnSync } from 'node:child_process'
3031
import { readFileSync, writeFileSync } from 'node:fs'
3132
import path from 'node:path'
3233
import { z } from 'zod'
@@ -290,6 +291,35 @@ function checkOpenApi(operations: Operation[]): string[] {
290291
return problems
291292
}
292293

294+
/**
295+
* Runs the emitted source through Biome so the generated file is a fixed point
296+
* of the repo's formatter.
297+
*
298+
* Without this the file is rewritten on the way into a commit: lint-staged runs
299+
* `biome check --write` on explicit paths, which bypasses the `files.includes`
300+
* exclusion in biome.json. The result was a generated file that no longer
301+
* matched its generator, so `--check` failed in CI complaining about contract
302+
* drift that had not happened. Formatting here means the hook has nothing left
303+
* to change.
304+
*/
305+
function format(source: string): string {
306+
const result = spawnSync(
307+
path.join(ROOT, 'node_modules/.bin/biome'),
308+
['format', `--stdin-file-path=${OUTPUT}`],
309+
{ input: source, encoding: 'utf8' }
310+
)
311+
312+
if (result.status !== 0 || !result.stdout) {
313+
// Fail loudly: silently emitting unformatted output would reintroduce the
314+
// exact hook-rewrites-generated-file loop this exists to close.
315+
throw new Error(
316+
`biome failed to format the generated output (status ${result.status}): ${result.stderr ?? ''}`
317+
)
318+
}
319+
320+
return result.stdout
321+
}
322+
293323
async function main() {
294324
const args = new Set(process.argv.slice(2))
295325
const operations = await collectOperations()
@@ -308,7 +338,7 @@ async function main() {
308338
return
309339
}
310340

311-
const generated = render(operations)
341+
const generated = format(render(operations))
312342

313343
if (args.has('--check')) {
314344
let current = ''

0 commit comments

Comments
 (0)