feat(mothership): format generated function code#5742
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview The workflow engine tracks block IDs whenever a New Dependencies: Reviewed by Cursor Bugbot for commit 58209d5. Bugbot is set up for automated code reviews on this repo. Configure here. |
Greptile SummaryThis PR formats Function block code after workflow operations resolve the final block state. The main changes are:
Confidence Score: 4/5The Python async formatting path and server packaging for Prettier need fixes before merging.
apps/sim/lib/workflows/blocks/format-function-code.ts and apps/sim/next.config.ts Important Files Changed
Reviews (1): Last reviewed commit: "feat(mothership): format generated funct..." | Re-trigger Greptile |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit a5e1c3d. Configure here.
- Preserve Sim references adjacent to right-shift operators - Add regression coverage for signed and unsigned shifts Note: pre-existing type-check failures in audit exports and linked workspace dependencies were not addressed by this PR.
Not addressing these two summary-level concerns because they do not reproduce against the current head:
The formatter remains fail-open in either path, and the current focused suite passes all 103 tests. |

Summary
Mothership-created JavaScript and Python Function blocks now arrive formatted and readable instead of being persisted as dense single-line source. Formatting runs after workflow operations resolve the final block identity and language, preserves Sim workflow and environment references, and fails open so invalid or unverifiable source remains unchanged while the mothership receives a sanitized formatting result.
This uses Prettier for JavaScript and Ruff's WebAssembly formatter for Python, keeping formatting deterministic and independent of how the mothership writes its tool-call strings.
Formatted output is accepted only when Sim references remain identical and ordered, JavaScript has an equivalent Babel syntax tree, and a second formatting pass is byte-stable. Parenthesized environment expressions retain grouping through raw resolver substitution, including comment-bearing expressions; otherwise the original Function source is kept.
The safety suite exercises broad JavaScript and Python syntax corpora, formatting idempotence, exact workflow/environment-reference restoration, real placeholder-token collisions, high-cardinality reference sets, invalid-source fail-open behavior, real VariableResolver integration, JavaScript runtime equivalence, and independent CPython AST and runtime equivalence.
Type of Change
Testing
DATABASE_URL=postgres://postgres:postgres@localhost:5432/sim bunx vitest run lib/workflows/blocks/format-function-code.test.ts lib/workflows/blocks/format-function-code.safety.test.ts lib/workflows/blocks/format-function-code.validation.test.ts lib/workflows/blocks/format-function-code.integration.test.ts lib/copilot/tools/server/workflow/edit-workflow/function-code-formatting.test.tsfromapps/sim- 110 tests passed.DATABASE_URL=postgres://postgres:postgres@localhost:5432/sim bun test apps/sim/lib/copilot/tools/server/workflow/edit-workflow/operations.test.ts- 14 tests passed with 45 expectations; 124 relevant tests passed in total.bunx biome checkacross the six formatter implementation/test files - passed.bun run check:utils- passed with no banned patterns.bun run check:api-validation- passed with all 964 API routes Zod-backed and no baseline drift.bun build apps/sim/lib/workflows/blocks/format-function-code.ts --target=node --outdir /tmp/sim-function-formatter-bundle --external @wasm-fmt/ruff_fmt/node- passed with Prettier's Babel parser bundled.bun run --cwd apps/sim type-check- the authored formatter files emitted no errors; the isolated worktree still surfaces unrelated linked-dependency drift for two audit constants,recordAuditBatch, and@google-cloud/storage. CI should validate from a fresh dependency install.Reviewers should focus on parenthesized environment-expression protection, Sim-reference ordering, the JavaScript AST normalization boundary, the independent CPython oracle, and Ruff WebAssembly tracing for standalone Next deployments.
Post-deploy monitoring and validation: for 24 hours after deployment, the Workflow/Mothership owner should watch
edit_workflowerror rate and latency and search logs forFunction code formatting failed open, grouped by language and block ID. Healthy behavior is stable edit latency/error rate with warnings limited to genuinely invalid source; a sustained warning increase, latency regression, or any behavior-changing formatted Function should trigger rollback of this change while fail-open keeps original source intact.Checklist
Screenshots/Videos
Not applicable - this changes server-side workflow code normalization and has no new visual surface.