Fix core migrate binary to call programmatic migration API#13
Merged
Conversation
## Summary
Fix the published `atomicmemory-core` binary so that `atomicmemory-core migrate` works correctly for npm installs. Previously the `migrate` command imported the standalone migration CLI, which reparsed `process.argv` and treated the command word `migrate` as a migration option, breaking the documented workflow.
## Changes
- `bin.ts`: Route the `migrate` command through `migration-api.migrate()` directly instead of importing the standalone `migrate.js` CLI.
- `bin.ts`: Export `runCommand` and `parseCliArgs` so the dispatch logic is testable without spawning a subprocess.
- `bin.test.ts`: Add CLI dispatch regression test that guards against `migrate.js` being re-imported and verifies the programmatic API receives the call.
- `CHANGELOG.md`: Document the fix and the new behavior.
## Why
The standalone `migrate.js` module re-reads `process.argv` when imported, so invoking `atomicmemory-core migrate` caused the string `"migrate"` to be reparsed as a migration option rather than the command name. The programmatic `migration-api.migrate()` function accepts no argv and applies migrations directly, which is the correct path for a CLI dispatch layer.
## Validation
- New `bin.test.ts` confirms `parseCliArgs` strips the command word correctly and that `runCommand('migrate')` calls `migration-api.migrate()` exactly once without ever importing `migrate.js`.
- The mock guard in the test (`throw new Error(...)`) ensures the regression cannot silently reappear.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix the published
atomicmemory-corebinary so thatatomicmemory-core migrateworks correctly for npm installs. Previously themigratecommand imported the standalone migration CLI, which reparsedprocess.argvand treated the command wordmigrateas a migration option, breaking the documented workflow.Changes
bin.ts: Route themigratecommand throughmigration-api.migrate()directly instead of importing the standalonemigrate.jsCLI.bin.ts: ExportrunCommandandparseCliArgsso the dispatch logic is testable without spawning a subprocess.bin.test.ts: Add CLI dispatch regression test that guards againstmigrate.jsbeing re-imported and verifies the programmatic API receives the call.CHANGELOG.md: Document the fix and the new behavior.Why
The standalone
migrate.jsmodule re-readsprocess.argvwhen imported, so invokingatomicmemory-core migratecaused the string"migrate"to be reparsed as a migration option rather than the command name. The programmaticmigration-api.migrate()function accepts no argv and applies migrations directly, which is the correct path for a CLI dispatch layer.Validation
bin.test.tsconfirmsparseCliArgsstrips the command word correctly and thatrunCommand('migrate')callsmigration-api.migrate()exactly once without ever importingmigrate.js.throw new Error(...)) ensures the regression cannot silently reappear.