chore: tech debt sweep — #96, #97, #98, #99, #102#109
Conversation
Extract worker state creation, map registration, and DB registration into a private registerWorker method, reducing spawn() from ~99 to ~65 lines. Includes UNIQUE violation rollback logic (Edge Case J).
Add two guard helpers to services.ts that eliminate repeated if-not-ok/if-null guard blocks across CLI commands. Refactors status.ts (2 sites), logs.ts (3 sites), and schedule.ts (8 sites).
Simplifier refinements: withReadOnlyContext and withServices now use exitOnError internally, exitOnNull gains configurable stopMsg, status.ts findAll branch uses exitOnError, schedule.ts functions get explicit return types.
Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant CLI as CLI Command<br/>(logs / status / schedule)
participant SVC as services.ts<br/>(exitOnError / exitOnNull)
participant REPO as Repository
participant UI as ui.*
participant PROC as process
CLI->>SVC: withReadOnlyContext(s) / withServices(s)
SVC->>SVC: exitOnError(createReadOnlyContext(), s, prefix)
alt result.ok == false
SVC->>UI: ui.error(prefix + message)
SVC->>PROC: process.exit(1)
else result.ok == true
SVC-->>CLI: ctx / services (unwrapped T)
end
CLI->>REPO: findById / findAll / etc.
CLI->>SVC: exitOnError(result, s, prefix)
alt result.ok == false
SVC->>UI: ui.error(prefix + message)
SVC->>PROC: process.exit(1)
else result.ok == true
SVC-->>CLI: value: T
end
opt value may be null
CLI->>SVC: exitOnNull(value, s, msg)
alt value == null
SVC->>UI: s.stop(stopMsg)
SVC->>UI: ui.error(msg)
SVC->>PROC: process.exit(1)
else value != null
SVC-->>CLI: value: T (narrowed, non-null)
end
end
CLI->>UI: ui.success / ui.info / ui.note
CLI->>PROC: process.exit(0)
Last reviewed commit: "style(cli): dogfood ..." |
| process.exit(1); | ||
| } | ||
| const task = exitOnError(taskResult, s, 'Failed to get task logs'); | ||
| exitOnNull(task, s, `Failed to get task logs: ${taskNotFound(taskId).message}`); |
There was a problem hiding this comment.
Discarded return value of
exitOnNull
The narrowed, non-null Task returned by exitOnNull is discarded here. After this line, task is still typed Task | null (from the exitOnError call above). This differs from the pattern in status.ts where the result is always captured:
const found = exitOnError(result, s, 'Failed to get task status');
const task = exitOnNull(found, s, `Failed to get task status: ...`);Since the task value isn't used beyond this existence check, consider clarifying intent — for example, by using a clearer variable name like _existingTask or adding a comment:
| exitOnNull(task, s, `Failed to get task logs: ${taskNotFound(taskId).message}`); | |
| exitOnNull(task, s, `Failed to get task logs: ${taskNotFound(taskId).message}`); // guard: validate task exists |
Or capture the narrowed value for consistency (even if unused):
const _task = exitOnNull(task, s, `Failed to get task logs: ${taskNotFound(taskId).message}`);This makes it clear that the call is solely an existence guard and not a logic oversight.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Summary
Post-v0.6.0 tech debt cleanup. Closes 5 issues; 3 were already resolved, 2 required code changes.
registerWorker()fromspawn()— reduces method from ~99 to ~65 linesexitOnError/exitOnNullCLI helpers — eliminates 13 repeated guard blocks acrossstatus.ts,logs.ts,schedule.ts(net -41 lines)Also updated #31 tech debt backlog: marked 3 stale/fixed entries, updated open count from 14 → 4.
Closes #96, closes #97, closes #98, closes #99, closes #102
Test plan
npm run build— clean typechecknpm run test:implementations— 314 tests pass (covers tech-debt: EventDrivenWorkerPool.spawn() at 99 lines — extract post-spawn setup #98)npm run test:cli— 157 tests pass (covers Extract exitOnError CLI helper to reduce boilerplate #102)npx biome check— clean