Skip to content

fix: make generate_handlers.js idempotent for untouched output - #44

Open
BhariGowda wants to merge 1 commit into
pashov:mainfrom
BhariGowda:fix/generate-handlers-stub-detection
Open

fix: make generate_handlers.js idempotent for untouched output#44
BhariGowda wants to merge 1 commit into
pashov:mainfrom
BhariGowda:fix/generate-handlers-stub-detection

Conversation

@BhariGowda

Copy link
Copy Markdown

isStubHandler() decided whether to protect a handler file from being overwritten by checking for the presence of any function keyword. But generate_handlers.js's own output always contains real function declarations (with // TODO: wire call placeholder bodies, by design) so the very first time it's run, then run again with zero edits, the second run reports "contains edits use --force to overwrite" even though nothing was ever touched.

Reproduced end-to-end with a synthetic Foundry project: generate once, re-run with no changes, no --force → incorrectly skipped every time.

Fix: compare the file on disk against what would be generated right now. If byte-identical, it's genuinely untouched and safe to overwrite this is what makes re-running the script after a selection change idempotent instead of permanently requiring --force. Falls back to the original "no function keyword" check to still correctly treat generate_suite.js's true empty shell as a stub.

Verified all four states: missing file (write), generate_suite.js's empty shell (write), untouched prior output with same inputs (write previously incorrectly skipped), and a genuine user edit (still correctly skipped and preserved).

isStubHandler() decided whether to protect a handler file from being
overwritten by checking for the presence of any 'function' keyword.
But generate_handlers.js's own output always contains real function
declarations (with '// TODO: wire call' placeholder bodies, by
design) - so the very first time it's run, then run again with zero
edits, the second run reports 'contains edits — use --force to
overwrite' even though nothing was ever touched.

Reproduced end-to-end with a synthetic Foundry project: generate once,
re-run with no changes, no --force -> incorrectly skipped every time.

Fix: compare the file on disk against what would be generated right
now. If byte-identical, it's genuinely untouched and safe to
overwrite - this is what makes re-running the script after a
selection change idempotent instead of permanently requiring --force.
Falls back to the original 'no function keyword' check to still
correctly treat generate_suite.js's true empty shell as a stub.

Verified all four states: missing file (write), generate_suite.js's
empty shell (write), untouched prior output with same inputs (write -
previously incorrectly skipped), and a genuine user edit (still
correctly skipped and preserved).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant