@minniexcode/codex-switch 0.0.4 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/README.md +35 -97
  2. package/dist/app/add-provider.js +40 -3
  3. package/dist/app/edit-provider.js +76 -3
  4. package/dist/app/export-providers.js +2 -2
  5. package/dist/app/get-current-profile.js +1 -1
  6. package/dist/app/get-status.js +10 -3
  7. package/dist/app/import-providers.js +47 -3
  8. package/dist/app/list-backups.js +1 -1
  9. package/dist/app/list-config-profiles.js +30 -0
  10. package/dist/app/list-providers.js +1 -1
  11. package/dist/app/remove-provider.js +35 -3
  12. package/dist/app/rollback-backup.js +1 -1
  13. package/dist/app/rollback-latest.js +1 -1
  14. package/dist/app/run-doctor.js +44 -26
  15. package/dist/app/run-mutation.js +2 -2
  16. package/dist/app/setup-codex.js +37 -20
  17. package/dist/app/show-config.js +34 -0
  18. package/dist/app/show-provider.js +1 -1
  19. package/dist/app/switch-provider.js +8 -5
  20. package/dist/cli/add-interactive.js +7 -106
  21. package/dist/cli/args.js +5 -126
  22. package/dist/cli/help.js +5 -276
  23. package/dist/cli/interactive.js +16 -171
  24. package/dist/cli/output.js +23 -1
  25. package/dist/cli/prompt.js +3 -108
  26. package/dist/cli.js +10 -315
  27. package/dist/commands/args.js +132 -0
  28. package/dist/commands/dispatch.js +16 -0
  29. package/dist/commands/handlers.js +391 -0
  30. package/dist/commands/help.js +119 -0
  31. package/dist/commands/registry.js +291 -0
  32. package/dist/commands/types.js +2 -0
  33. package/dist/domain/config.js +548 -39
  34. package/dist/infra/backup-repo.js +8 -208
  35. package/dist/infra/codex-cli.js +8 -113
  36. package/dist/infra/codex-discovery.js +3 -41
  37. package/dist/infra/codex-paths.js +5 -69
  38. package/dist/infra/config-repo.js +161 -9
  39. package/dist/infra/fs-utils.js +7 -95
  40. package/dist/infra/lock-repo.js +3 -97
  41. package/dist/infra/providers-repo.js +7 -96
  42. package/dist/interaction/add-interactive.js +108 -0
  43. package/dist/interaction/interactive.js +216 -0
  44. package/dist/interaction/prompt.js +110 -0
  45. package/dist/runtime/codex-cli.js +130 -0
  46. package/dist/runtime/codex-probe.js +50 -0
  47. package/dist/runtime/types.js +2 -0
  48. package/dist/storage/backup-repo.js +210 -0
  49. package/dist/storage/codex-paths.js +71 -0
  50. package/dist/storage/config-repo.js +208 -0
  51. package/dist/storage/fs-utils.js +97 -0
  52. package/dist/storage/lock-repo.js +99 -0
  53. package/dist/storage/providers-repo.js +98 -0
  54. package/docs/Design/codex-switch-v0.0.5-design.md +932 -0
  55. package/docs/Design/codex-switch-v0.0.6-design.md +708 -0
  56. package/docs/PRD/codex-switch-prd-v0.0.5-to-v0.1.0.md +340 -0
  57. package/docs/PRD/codex-switch-prd-v0.1.0.md +215 -291
  58. package/docs/PRD/codex-switch-prd.md +1 -1
  59. package/docs/cli-usage.md +2 -1
  60. package/docs/codex-switch-technical-architecture.md +73 -4
  61. package/docs/test-report-0.0.5.md +163 -0
  62. package/docs/testing.md +131 -0
  63. package/package.json +1 -1
  64. /package/docs/{codex-switch-v0.0.4-design.md → Design/codex-switch-v0.0.4-design.md} +0 -0
@@ -130,6 +130,13 @@ Infrastructure 层
130
130
 
131
131
  这意味着未来即使引入 GUI / MCP / HTTP 适配层,核心同步目标仍然是 runtime files,而不是把 runtime files 本身当成长期管理数据库。
132
132
 
133
+ `0.0.6` 的实现边界还需要区分“逻辑主层”和“兼容层”:
134
+
135
+ - 逻辑主层已经迁移到 `src/commands/`、`src/interaction/`、`src/storage/`、`src/runtime/`
136
+ - `src/cli/` 和 `src/infra/` 当前主要承担兼容 re-export 与入口收敛职责
137
+ - 这意味着 `0.0.6` 的完成标准是“边界和契约已经统一”,而不是“所有旧路径文件都物理删除”
138
+ - 后续版本可以在兼容窗口结束后继续删除旧 facade,但这不属于 `0.0.6` 的必须交付范围
139
+
133
140
  ### 3.3 模块依赖图
134
141
 
135
142
  当前代码依赖关系可以抽象为:
@@ -194,10 +201,14 @@ argv
194
201
  ```text
195
202
  src/
196
203
  cli.ts
204
+ commands/
205
+ interaction/
197
206
  app/
198
207
  cli/
199
208
  domain/
209
+ runtime/
200
210
  infra/
211
+ storage/
201
212
 
202
213
  tests/
203
214
  app.spec.js
@@ -220,7 +231,65 @@ scripts/
220
231
 
221
232
  它不直接做文件读写,不直接写业务逻辑,也不直接实现备份或校验规则。
222
233
 
223
- ### 4.2 `src/cli/`
234
+ ### 4.2 `src/commands/`
235
+
236
+ 这一层是 `0.0.6` 新增的命令表面层,负责把“公开 CLI 形态”收敛为单一 registry。
237
+
238
+ 它承担的职责是:
239
+
240
+ - 定义每个命令的公开 token 形态,例如 `config show`、`config list-profiles`、`backups list`
241
+ - 统一保存 `summary`、`usage`、`details`、`examples`
242
+ - 绑定 command handler,供 dispatch 直接执行
243
+ - 让 help、解析和 dispatch 共享同一份事实源
244
+
245
+ 它不负责:
246
+
247
+ - 具体文件读写
248
+ - prompt 交互细节
249
+ - human output 渲染
250
+
251
+ ### 4.3 `src/interaction/`
252
+
253
+ 这一层是 `0.0.6` 中显式抽出的交互层,负责所有 CLI 级 prompt 组合逻辑。
254
+
255
+ 它承担的职责是:
256
+
257
+ - 判断哪些路径允许交互
258
+ - 组合 provider 选择、确认、rollback 预览等交互动作
259
+ - 组织 add/edit/setup 中的渐进式输入收集
260
+
261
+ 它不负责:
262
+
263
+ - 业务状态变更
264
+ - 文件系统写入
265
+ - 运行时探测
266
+
267
+ `setup` 是这一层边界最强的命令之一。在 `0.0.6` 中,它的 adopt profile 选择和 provider 详情输入仍然是交互式 contract,因此非交互路径会显式失败,而不是隐式进入空输入分支。
268
+
269
+ ### 4.4 `src/storage/`
270
+
271
+ 这一层是 `0.0.6` 的文件和状态访问层,负责把以前分散在 `infra/` 的能力收口成稳定存储边界。
272
+
273
+ 它承担的职责是:
274
+
275
+ - `config.toml` / `providers.json` / backup manifest / lock file 的读写
276
+ - Codex home 目录路径展开
277
+ - 原子写入、备份、回滚、锁定
278
+
279
+ `src/infra/` 在当前版本主要保留兼容 re-export,以便逐步迁移,不再作为新的业务入口继续扩张。
280
+
281
+ ### 4.5 `src/runtime/`
282
+
283
+ 这一层是 `0.0.6` 新增的运行时边界,负责本地 Codex CLI 的外部依赖探测和登录调用。
284
+
285
+ 它承担的职责是:
286
+
287
+ - Codex 可用性检查
288
+ - Codex 版本检查
289
+ - Codex login 调用
290
+ - 未来可扩展为第三方 runtime adapter 的能力边界
291
+
292
+ ### 4.6 `src/cli/`
224
293
 
225
294
  #### `src/cli/args.ts`
226
295
 
@@ -272,7 +341,7 @@ scripts/
272
341
 
273
342
  这两个纯渲染入口的作用是让 CLI 层本身也能被测试,而不依赖真实子进程。
274
343
 
275
- ### 4.3 `src/app/`
344
+ ### 4.7 `src/app/`
276
345
 
277
346
  这一层是应用服务 / 用例编排层。每个文件基本对应一个命令或一个用例:
278
347
 
@@ -301,7 +370,7 @@ scripts/
301
370
  - `stdout` / `stderr` 怎么写
302
371
  - argv 怎么解析
303
372
 
304
- ### 4.4 `src/domain/`
373
+ ### 4.8 `src/domain/`
305
374
 
306
375
  #### `errors.ts`
307
376
 
@@ -463,7 +532,7 @@ scripts/
463
532
  - 用于 `codex login --with-api-key`
464
533
  - `baseUrl`
465
534
  - 选填
466
- - 当前版本只存储,不回写 `config.toml`
535
+ - 当前版本只存储在 `providers.json`;`config show` 中展示的 runtime `baseUrl` 由 `model_provider -> model_providers.*.base_url` 解析
467
536
  - `note`
468
537
  - 选填
469
538
  - 面向人类和 AI 的说明字段
@@ -0,0 +1,163 @@
1
+ # Test Report: 0.0.5
2
+
3
+ Date: 2026-05-13
4
+
5
+ ## Environment
6
+
7
+ - Platform: Windows (`win32`)
8
+ - Node.js: `v24.11.1`
9
+ - npm: `11.13.0`
10
+ - Workspace: `C:\Users\A200477427\Developers\Github\codex-switch`
11
+
12
+ ## Commands Run
13
+
14
+ ```bash
15
+ npm run build
16
+ npm test
17
+ ```
18
+
19
+ ## Overall Result
20
+
21
+ - Build: PASS
22
+ - Test suites: 5/5 PASS
23
+
24
+ Suite results:
25
+
26
+ - `domain`: PASS
27
+ - `app`: PASS
28
+ - `cli`: PASS
29
+ - `dev-sandbox`: PASS
30
+ - `e2e`: PASS
31
+
32
+ ## Coverage Added In This Pass
33
+
34
+ New test assets:
35
+
36
+ - `tests/dev-sandbox.spec.js`
37
+ - `tests/e2e.spec.js`
38
+ - `docs/testing.md`
39
+
40
+ Updated wiring:
41
+
42
+ - `tests/helpers.js`
43
+ - `tests/run-tests.js`
44
+
45
+ ## Detailed Results
46
+
47
+ ### 1. Domain Suite
48
+
49
+ Status: PASS
50
+
51
+ Focus:
52
+
53
+ - config patch planning
54
+ - managed profile view generation
55
+ - provider normalization and masking
56
+ - runtime drift helpers
57
+ - backup list helpers
58
+
59
+ ### 2. App Suite
60
+
61
+ Status: PASS
62
+
63
+ Focus:
64
+
65
+ - list/current/status
66
+ - add/edit/show/remove
67
+ - import/export
68
+ - switch/login/rollback
69
+ - setup
70
+ - doctor
71
+ - lock conflict and rollback behavior
72
+
73
+ ### 3. CLI Suite
74
+
75
+ Status: PASS
76
+
77
+ Focus:
78
+
79
+ - arg parsing
80
+ - help rendering
81
+ - JSON success/failure envelopes
82
+ - interactive add/edit/remove/import/export/rollback/setup flows
83
+ - config commands
84
+
85
+ ### 4. Dev Sandbox Suite
86
+
87
+ Status: PASS
88
+
89
+ Fixture:
90
+
91
+ - `dev-codex/local-sandbox`
92
+
93
+ Validated with the built CLI command dispatcher against the real development fixture:
94
+
95
+ - `list --json`
96
+ - `current --json`
97
+ - `status --json`
98
+ - `config show --json`
99
+ - `backups list --json`
100
+ - `doctor --json`
101
+
102
+ Observed state during test:
103
+
104
+ - active profile: `packycode`
105
+ - managed providers: `freemodel`, `packycode`
106
+ - status issues: `0`
107
+ - backups found: `>= 1`
108
+
109
+ ### 5. End-to-End Suite
110
+
111
+ Status: PASS
112
+
113
+ Fixture strategy:
114
+
115
+ - copy `dev-codex/local-sandbox` into a temp directory
116
+ - run write commands against the temp copy
117
+ - keep the repository fixture unchanged
118
+
119
+ Validated flows:
120
+
121
+ - `switch freemodel` updates active profile and refreshes `auth.json`
122
+ - `rollback` restores `config.toml` and `auth.json`
123
+ - `add` creates a provider in `providers.json`
124
+ - `edit` updates note and tags
125
+ - `remove --force` deletes a non-active provider
126
+ - `add --create-profile` creates a managed profile section in `config.toml` when a same-named `[model_providers.*]` runtime section already exists
127
+ - destructive removal of the active provider fails with `PROFILE_IN_USE`
128
+ - `import --merge` replaces overlapping providers and keeps merged state valid
129
+ - `export` writes a valid providers file
130
+ - `backups list` skips corrupt backup folders with warnings
131
+ - `rollback missing-backup` fails with `BACKUP_NOT_FOUND`
132
+ - corrupt `backups/latest.json` fails with `ROLLBACK_FAILED`
133
+ - `setup` adopt flow works through CLI dispatch with mocked Codex CLI availability
134
+
135
+ Validated mixed workflows:
136
+
137
+ - `add -> switch -> edit -> show -> config show -> export -> rollback`
138
+ - `import --merge -> switch --no-login -> remove -> doctor -> backups list -> rollback <backup-id>`
139
+
140
+ ## Release Confidence
141
+
142
+ Current confidence for `0.0.5`: medium-high.
143
+
144
+ Why:
145
+
146
+ - core read and write workflows now have automated coverage
147
+ - the development fixture is exercised directly by the built CLI
148
+ - backup/rollback behavior is covered by both existing and new tests
149
+
150
+ ## Residual Risks
151
+
152
+ - `setup` is not yet covered as a true subprocess end-to-end command because it depends on interactive adopt input and external `codex` availability
153
+ - `rollback-latest` still has no direct dedicated test case even though `rollback` coverage is strong
154
+ - `README.md` still shows version `0.0.4` in the documentation text and should be updated separately
155
+
156
+ ## Recommended Pre-Release Checklist
157
+
158
+ Before the next publish:
159
+
160
+ - run `npm test`
161
+ - run a manual smoke check of `node dist/cli.js --help`
162
+ - run one real local `switch --no-login` against a temp `--codex-dir`
163
+ - update user-facing docs if the package version changes
@@ -0,0 +1,131 @@
1
+ # Testing Guide
2
+
3
+ `codex-switch` now has four test layers:
4
+
5
+ - `tests/domain.spec.js`: pure domain/unit coverage
6
+ - `tests/app.spec.js`: file-backed application integration coverage
7
+ - `tests/cli.spec.js`: CLI dispatch and prompt simulation coverage
8
+ - `tests/dev-sandbox.spec.js`: real `node dist/cli.js` read-only smoke tests against `dev-codex/local-sandbox`
9
+ - `tests/e2e.spec.js`: write-command regression tests against temporary copies of `dev-codex/local-sandbox`
10
+
11
+ ## Commands
12
+
13
+ Build the CLI:
14
+
15
+ ```bash
16
+ npm run build
17
+ ```
18
+
19
+ Run the full suite:
20
+
21
+ ```bash
22
+ npm test
23
+ ```
24
+
25
+ Run a single suite manually:
26
+
27
+ ```bash
28
+ node -e "require('./tests/dev-sandbox.spec').run()"
29
+ node -e "require('./tests/e2e.spec').run()"
30
+ ```
31
+
32
+ ## Development Fixture
33
+
34
+ The repository fixture lives at:
35
+
36
+ ```text
37
+ dev-codex/local-sandbox/
38
+ ```
39
+
40
+ It is used in two different ways:
41
+
42
+ - read-only dispatcher tests point at it directly
43
+ - mutation tests copy it into a temporary directory before running writes
44
+
45
+ Do not point destructive automation directly at `dev-codex/local-sandbox` unless you intentionally want to update the fixture.
46
+
47
+ ## Read-Only Smoke Tests
48
+
49
+ `tests/dev-sandbox.spec.js` verifies the built CLI against the real development fixture.
50
+
51
+ Covered commands:
52
+
53
+ - `list --json`
54
+ - `current --json`
55
+ - `status --json`
56
+ - `config show --json`
57
+ - `backups list --json`
58
+ - `doctor --json`
59
+
60
+ These tests check two execution styles:
61
+
62
+ - development default resolution with `NODE_ENV=development`
63
+ - explicit `--codex-dir dev-codex/local-sandbox`
64
+
65
+ This is the fastest way to validate that `0.0.x` builds still read the repo sandbox correctly.
66
+
67
+ ## Mutation Regression Tests
68
+
69
+ `tests/e2e.spec.js` uses `fs.cpSync()` to clone `dev-codex/local-sandbox` into a temp directory, then exercises the real CLI command dispatcher against the copy.
70
+
71
+ Covered write scenarios:
72
+
73
+ - `switch` with login and backup creation
74
+ - `rollback` restoring `config.toml` and `auth.json`
75
+ - `add`, `edit`, `remove`
76
+ - `add --create-profile`
77
+ - blocking destructive remove of the active profile provider
78
+ - `import --merge`
79
+ - `export`
80
+ - `backups list` with corrupt backup entries
81
+ - `rollback <missing-id>`
82
+ - corrupt `backups/latest.json`
83
+
84
+ It also includes mixed workflow scenarios where multiple commands operate on the same sandbox copy end-to-end, for example:
85
+
86
+ - `add -> switch -> edit -> show -> config show -> export -> rollback`
87
+ - `import --merge -> switch --no-login -> remove -> doctor -> backups list -> rollback <backup-id>`
88
+
89
+ The setup flow is covered with `executeCommand()` plus mocked Codex CLI checks because `setup` currently depends on external `codex --version` availability and interactive adopt input.
90
+
91
+ ## Fixture Rules
92
+
93
+ - Prefer `--codex-dir <temp-copy>` for all write tests.
94
+ - Prefer `--json` when assertions need stable output.
95
+ - Treat `show --json` output as sensitive because it includes unmasked API keys.
96
+ - If a test needs `codex login` or `codex --version`, prefer mocking the spawn layer.
97
+ - Keep fixture assertions focused on stable data such as provider names, active profile, backup count, and typed error codes.
98
+
99
+ ## Reporting Template
100
+
101
+ Use this template for release checks:
102
+
103
+ ```text
104
+ Version under test: 0.0.x
105
+ Build: PASS/FAIL
106
+ Suite results:
107
+ - domain: PASS/FAIL
108
+ - app: PASS/FAIL
109
+ - cli: PASS/FAIL
110
+ - dev-sandbox: PASS/FAIL
111
+ - e2e: PASS/FAIL
112
+
113
+ Read-only smoke checks:
114
+ - list/current/status/config/backups/doctor
115
+
116
+ Mutation checks:
117
+ - switch/rollback/add/edit/remove/import/export/setup
118
+
119
+ Open risks:
120
+ - <risk 1>
121
+ - <risk 2>
122
+ ```
123
+
124
+ ## Current Gaps
125
+
126
+ Known areas that still deserve more coverage:
127
+
128
+ - true subprocess coverage for `setup`
129
+ - explicit tests for `rollback-latest`
130
+ - more backup corruption cases inside historical manifests
131
+ - README and release docs should stay in sync with the package version
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@minniexcode/codex-switch",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "Local-first CLI for managing and switching Codex provider/profile configuration.",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",