Migrate activity and upload to pure command runners#92
Conversation
65cfe4e to
2b8bbb3
Compare
arthyn
left a comment
There was a problem hiding this comment.
I understand the gist of this PR which is basically make all of this more testable. I don't understand why we'd keep the standalone scripts we convert though, since this is intended to always be run from main.ts. Also I'm not a huge fan of having to create a deps bundles in the runtime file (esp not if it means defining command specific helpers there). could we maybe just have something like import * as api from '@tloncorp/api' and then pass that api object to each command to use?
Yeah, I agree we need a better solution on imports. Maybe we should switch over to node-style moduleResolution, but that's probably best for another PR. For now, the activity command gets its local types from the @tloncorp/api function return types instead of just copying the shapes. |
Summary
This PR introduces a testable command-runner pattern and migrates
activityanduploadas pilot commands.The goal is to stop growing the legacy import-side-effect CLI shape, where command modules read globals, call
process.exit(), and are difficult to test without subprocesses. The new pattern keeps command logic in purerun(args, deps): Promise<number>modules, with command-specific runtime deps wired through the top-level CLI.This is PR 1 of 3 for this phase.
What Changed
activityintoscripts/commands/activity.tswith injected auth, activity API calls, and output formatting.uploadintoscripts/commands/upload.tswith injected stdin, filesystem, fetch, Blob creation, and upload API operations.scripts/main.tsso top-leveltlon activity ...andtlon upload ...dispatch through explicit command runners instead of import-time side effects.process,console,fetch, or directfsimports.activityandupload, including URL upload failure modes and stable command-error output.Scope Notes
activityandupload.uploadis included as the IO-heavy pilot because it proves the dependency-injection shape for stdin, filesystem, fetch, Blob construction, and upload API behavior.activityis included as the read-only pilot because it proves side-effect import removal and API/output injection.Tests
Validated locally:
bun test scripts/commands/activity.test.ts scripts/commands/upload.test.ts scripts/commands/command-contract.test.ts npm run typecheck npm run test:unit npm run test:integration npm run build:smoke npm run check git diff --check