Skip to content

feat: support temp_script_refs in wmill dev for local relative imports#9554

Draft
hugocasa wants to merge 2 commits into
mainfrom
hugo/win-2038-support-temp_script_refs-in-wmill-dev-for-local-relative
Draft

feat: support temp_script_refs in wmill dev for local relative imports#9554
hugocasa wants to merge 2 commits into
mainfrom
hugo/win-2038-support-temp_script_refs-in-wmill-dev-for-local-relative

Conversation

@hugocasa

@hugocasa hugocasa commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes WIN-2038.

When using wmill dev, previews of scripts/flows with relative imports to scripts that haven't been deployed yet (or have local edits) failed or used stale deployed code, because the dev page's runScriptPreview / runFlowPreview calls didn't include temp_script_refs. This was already supported in wmill script preview, wmill flow preview, and wmill app dev via buildPreviewTempScriptRefs().

This PR computes the refs at wmill dev startup (mirroring the wmill app dev snapshot pattern), sends them through the WebSocket → browser chain, and plumbs them into the preview API calls.

Design note: unlike wmill app dev, the previewed item in wmill dev can change at runtime (path picker / loadWmPath), so there is no single anchor node to filter refs by. Instead a new { kind: "all" } target on buildPreviewTempScriptRefs returns the refs for all locally-diverged scripts (uploaded once at startup), and the same map rides on every preview run. This is a superset of the per-target map for any node, and the backend only looks up the imports it actually needs, so extra entries are inert. It also means imports added live in the dev page editor still resolve, as long as the target script existed at startup.

Known limitation (same as wmill app dev): the refs are a startup snapshot — restart wmill dev to pick up later edits to imported workspace scripts. This is surfaced in the startup log line.

Changes

  • cli/src/utils/dependency_tree.ts: new getAllTempScriptRefs() returning path → contentHash for every uploaded node.
  • cli/src/commands/generate-metadata/generate-metadata.ts: buildPreviewTempScriptRefs accepts { kind: "all" } (no anchor node; tree-wide refs).
  • cli/src/commands/dev/dev.ts: computes the refs once at startup (graceful degradation on older backends without /raw_temp), adds temp_script_refs to LastEditScript / LastEditFlow and to all four WS message construction sites (loadPaths / loadWmPath × script / flow).
  • frontend/src/lib/components/Dev.svelte: stores the refs from WS messages; passes them on script Test runs; exposes them to the flow editor tree via a new optional devTempScriptRefs getter on FlowEditorContext. Flow refs are deliberately kept outside the flow object so the flow.yaml round-trip back to the CLI is never polluted.
  • frontend/src/lib/components/flows/types.ts: optional devTempScriptRefs on FlowEditorContext (only set by the dev page; regular flow editor unaffected).
  • frontend/src/lib/components/JobLoader.svelte: runPreview takes optional tempScriptRefstemp_script_refs in the request body.
  • frontend/src/lib/components/flows/utils.svelte.ts + FlowPreviewContent.svelte: whole-flow / up-to previews pass the refs to JobService.runFlowPreview.
  • frontend/src/lib/components/ModuleTest.svelte: single-step (rawscript) tests in the dev page pass the refs too.
  • cli/test/dependency_tree_unit.test.ts: unit tests for getAllTempScriptRefs (all-uploaded, partial, superset-of-per-node semantics).

Test plan

  • CLI unit tests: UNIT_ONLY=1 bun test test/*_unit* — 856 pass (includes 3 new tests).
  • bunx tsc --noEmit in cli/ — no new errors (pre-existing errors untouched).
  • npm run check in frontend/ — 0 errors.
  • Manual end-to-end (local backend + frontend): created a workspace folder with f/devtest/lib.ts (never deployed) and f/devtest/main.ts importing ./lib.ts; ran wmill dev → startup logs Resolved 2 locally-edited script(s) for preview relative imports; script Test on the dev page returns hello from LOCAL lib, world and the /jobs/run/preview request body contains temp_script_refs.
  • Manual flow preview: flow with an inline script importing ../lib.ts — Test flow succeeds with hello from LOCAL lib, flowworld; /jobs/run/preview_flow body contains temp_script_refs; the flow.yaml written back by the dev round-trip contains no temp_script_refs key.
  • Against an older backend without /raw_temp: wmill dev prints the yellow fallback warning and previews still run against deployed versions (not exercised locally — degradation path is the existing shared buildPreviewTempScriptRefs catch).

Screenshots

Script preview on the dev page resolving a relative import from a never-deployed local script:

script-preview-local-import

Flow preview with an inline script importing the same local lib:

flow-preview-local-import

🤖 Generated with Claude Code


Summary by cubic

Adds temp_script_refs to wmill dev so script and flow previews resolve relative imports from local, not-yet-deployed files. Fixes WIN-2038 to eliminate stale code in dev previews.

  • New Features
    • Compute refs once at wmill dev startup using buildPreviewTempScriptRefs({ kind: "all" }), send via WS, and include in all preview runs (scripts, flows, module tests).
    • CLI: add getAllTempScriptRefs; include refs in LastEditScript/LastEditFlow and WS messages; graceful fallback on older backends without /raw_temp.
    • Frontend: store refs in the dev page and pass them to JobService.runPreview/runFlowPreview; expose devTempScriptRefs in FlowEditorContext without touching flow.yaml.
    • Tests: unit tests for getAllTempScriptRefs.
    • Limitation: refs are a startup snapshot; restart wmill dev to pick up later edits to imported workspace scripts.

Written for commit d9213b0. Summary will update on new commits.

Review in cubic

hugocasa and others added 2 commits June 12, 2026 14:40
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying windmill with  Cloudflare Pages  Cloudflare Pages

Latest commit: d9213b0
Status: ✅  Deploy successful!
Preview URL: https://feda0d79.windmill.pages.dev
Branch Preview URL: https://hugo-win-2038-support-temp-s.windmill.pages.dev

View logs

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