♻️ Refactor commands to use functional modules directly#133
Conversation
Code Review: Functional Refactor of CommandsThis PR successfully migrates commands from the service container pattern to direct functional imports. The refactoring improves code clarity and reduces indirection. However, there are several important issues to address. Critical Issues1. Code Duplication: createServerManager FunctionLocation: src/commands/run.js:40-84 and src/commands/tdd.js The createServerManager function is duplicated across both run.js and tdd.js. This violates DRY principles and creates maintenance burden. If the server manager interface changes, you'll need to update both files identically. Recommendation: Extract createServerManager to src/server-manager/index.js as an exported helper, then import it in both commands. 2. Circular Dependency Risk in createTokenStoreLocation: src/auth/index.js:46-70 The late-import pattern using dynamic import() to avoid circular dependencies is a code smell. Since you're already re-exporting the token functions at the top of the file (lines 11-15), just use them directly. This would be simpler, synchronous, and eliminate the circular dependency concern. Medium Priority Issues3. Inconsistent Error Handling in CleanupLocation: src/commands/run.js:111-149 and src/commands/tdd.js:53-64 The cleanup functions silently swallow all errors with empty catch blocks. At minimum, log errors in verbose mode for debugging. 4. Missing Null Check in run.js CleanupLocation: src/commands/run.js:129-144 The finalize build logic checks if (buildId && config) but doesn't validate that serverManager is available, even though it's used in the deps object. 5. Process Signal Handler CleanupLocation: src/commands/run.js:158-159 Signal handlers are registered but never removed, which could cause memory leaks in long-running processes or test suites. What's Good
Testing ConcernsThe PR description shows manual testing is incomplete. Before merging, ensure all manual tests pass, especially:
SummaryThis is a solid refactoring moving in the right direction. Main concerns:
Recommendation: Request changes for items 1 and 2, then approve after fixes and manual testing completion. |
Commands now import from functional modules instead of createServices():
- API: import { createApiClient, getBuild } from '../api/index.js'
- Auth: import { createAuthClient, whoami } from '../auth/index.js'
- Test runner: import { runTests } from '../test-runner/index.js'
Added createTokenStore() helper to auth module for commands.
Commands create lightweight inline objects for serverManager/buildManager
instead of using class instances.
b340169 to
b11b71b
Compare
Removes duplication between run.js and tdd.js by moving the createServerManager factory to server-manager/index.js where it belongs with the other server management functions.
The dynamic import was defensive code for a circular dependency that doesn't exist. global-config.js only imports from node: modules and output.js - it has no dependency on auth/.
a8dd071 to
a50b567
Compare
## Summary **Deleted thin wrapper classes** (only used by createServices): - `api-service.js`, `auth-service.js`, `config-service.js`, `project-service.js` - `tdd-service.js` re-export (now imports from `tdd/` directly) - `BuildManager` class (kept pure functions) - `html-report-generator.js` and `report-generator/` assets **Simplified `createServices()`** to only create: - `testRunner` (EventEmitter for plugin API) - `serverManager` (plugin API) **Added:** - `report-generator/` module with functional operations - Test helpers in `tests/helpers/` ## Stats - **Net deletion:** ~700 lines from services layer - Services layer reduced from 783 → 681 lines ## Migration path (future) The `testRunner` and `serverManager` classes remain for plugin API backwards compatibility. Future work: - Document deprecation, recommend plugins use functional modules - Remove class wrappers in next major version ## Test plan - [x] All 56 test files pass (1086 tests) - [ ] CI passes - [ ] Plugin API still works --- **Part 3 of 3** for functional decomposition refactor (VIZ-128) Depends on #133
Summary
createServices()import { createApiClient, getBuild } from '../api/index.js'import { createAuthClient, whoami } from '../auth/index.js'import { runTests } from '../test-runner/index.js'createTokenStore()helper to auth module for commandsTest plan
vizzly run,vizzly tdd,vizzly uploadcommands workPart 2 of 3 for functional decomposition refactor (VIZ-128)
Depends on #132