Skip to content

refactor(workers): consolidate the command family onto shared helpers - #6431

Draft
johnstonmatt wants to merge 7 commits into
FUNC-848/workers-deploy-wait-flagfrom
workers-family-cleanup
Draft

refactor(workers): consolidate the command family onto shared helpers#6431
johnstonmatt wants to merge 7 commits into
FUNC-848/workers-deploy-wait-flagfrom
workers-family-cleanup

Conversation

@johnstonmatt

@johnstonmatt johnstonmatt commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Pure refactor of the workers command family, one consolidation per commit, stacked on #6371. The duplication it removes was hiding a handful of bugs, fixed here as a side effect:

  • legacyWorkersRun owns the shared command scaffold — service acquisition, ref resolution and suffix, and the two finalizers — with the ordering written once. Four handlers resolved the ref above both finalizers, so an unlinked non-interactive run failed before the telemetry flush was installed and wrote no post-run event.
  • legacyEmitWorkersPayload makes the "emit a structured payload" decision once, and legacyWorkersRendersText names the "renders human text" condition. Both fix the same precedence bug across ten hand-written call sites: -o pretty --output-format json asks for text but was treated as a machine run.
  • legacyWorkersCommand, with legacyWorkersPushCommand and legacyWorkersStatusCommand for the two recurring suggestions, replaces the supabase experimental workers literal in roughly thirty call sites. A unit test pins the spelling, since these strings get copy-pasted out of a terminal.
  • legacyWorkerNotDeployed builds the sentence that is identical in three commands and takes the way out that is not: status and logs point at push, delete deliberately points at list.
  • workers logs: the follow loop's two always-paired Refs become one FollowCursor, and the paging walk moves to drainSince, so the poll body reads as its three steps — read the cursor, drain the window, emit what is new.
  • workers push: the sixty-line source check lifts out of deployOneWorker into assertDeployableSource, leaving the deploy readable as its steps.

Also trims comments that explained a change rather than the code. Rationale about what used to be wrong, and how many callers had it wrong, lives in these commit messages rather than in a docblock every later reader pays for.

Five handlers opened with the same three service acquisitions, the same ref
resolution and suffix, and closed with the same two finalizers. The ordering is
the whole point of that block and is easy to get subtly wrong: four of them
resolved the ref above both finalizers, so an unlinked non-interactive checkout
failed before `telemetryState.flush` was installed and wrote no post-run event.

`legacyWorkersRun` owns the ordering once. Telemetry wraps the resolution;
the linked-project cache stays under the ref, having nothing to write without
one. `logs` already had the fix and now shares the same path.
The machine-output check, the structured emission and the fall-through to text
were written out in all five handlers. Four of them branched on `output.format`
alone, which ignores `-o`'s priority over `--output-format` — so
`-o pretty --output-format json` emitted JSON from a run that had asked for
text.

`legacyEmitWorkersPayload` makes the decision once, keeping the existing
"returns whether it emitted" contract so callers still skip their text
rendering the same way. The precedence is pinned in one place rather than once
per command.
`supabase experimental workers` was a literal in roughly thirty call sites. The
move under `experimental` had to rewrite every one, and two follow-up commits
exist because some were missed or left pointing at a command that no longer
existed.

`legacyWorkersCommand` owns the path, with `legacyWorkersPushCommand` and
`legacyWorkersStatusCommand` for the two suggestions that recur. A unit test
pins the exact spelling, since these strings are copy-pasted out of a terminal.
Three commands raised `WorkerNotDeployedError` with a byte-identical detail and
their own suggestion. `legacyWorkerNotDeployed` owns the sentence that is the
same everywhere and takes the way out that is not: `status` and `logs` point at
`push`, while `delete` deliberately points at `list`.
Five more call sites — push's progress lines and per-worker output, delete's
confirmation guard, new's prompt gate — each spelled out `output.format` plus
`machineOutput` by hand, and each got the precedence wrong the same way:
`-o pretty --output-format json` asks for text but was treated as a machine
run.

`legacyWorkersRendersText` answers it once. `push` threads that instead of
`machineOutput`, and `new` now emits through the shared payload helper.
`pollOnce` was a 60-line closure doing three jobs, and carried two `Ref`s that
were only ever read and written together — one cursor split in half, where
advancing the timestamp without recording the ids replays the overlap.

`FollowCursor` is that one value, and the paging walk moves to `drainSince`, so
the poll body reads as its three steps: read the cursor, drain the window, emit
what is new.

Trims the comments here and in the helpers this pass added. Rationale that
belongs to a change rather than to the code — what used to be wrong, and how
many callers had it wrong — lives in the commit that made it, not in a docblock
the next reader pays for.
`deployOneWorker` opened with a sixty-line bare block — the author's own marker
that it was a separate job. `assertDeployableSource` is that job: does this path
hold something worth deploying. What is left reads as its steps — describe,
check the source, resolve the spec, package, upload, deploy, report.

Costs a few lines in parameter plumbing and buys a function that can be read,
and tested, without the deploy around it.
@johnstonmatt
johnstonmatt changed the base branch from develop to FUNC-848/workers-deploy-wait-flag September 2, 2026 01:37
@johnstonmatt johnstonmatt changed the title refactor(workers): consolidate command family scaffolding and add logs refactor(workers): unify output, add logs command, make push async Sep 2, 2026
@johnstonmatt johnstonmatt changed the title refactor(workers): unify output, add logs command, make push async refactor(workers): consolidate the command family onto shared helpers Sep 2, 2026
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