@minniexcode/codex-switch 0.0.8 → 0.0.9

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.
@@ -0,0 +1,367 @@
1
+ # `0.0.9` Bridge Automated Testing Guide
2
+
3
+ This document defines the automated test strategy for the `0.0.9` Copilot bridge release.
4
+
5
+ ## Goal
6
+
7
+ The release must prove that the managed Copilot bridge can:
8
+
9
+ - resolve the correct provider target
10
+ - start, stop, and report status through the public CLI surface
11
+ - reuse one healthy instance for the same provider
12
+ - replace an existing managed instance for a different provider
13
+ - recover from preferred-port conflicts using another 5-digit port
14
+ - persist recovered ports into `providers.json` and `config.toml`
15
+ - clean up newly started workers when persistence fails
16
+ - surface stale runtime-state diagnostics through `status` and `doctor`
17
+
18
+ ## Test Layers
19
+
20
+ Bridge coverage is intentionally split across four layers.
21
+
22
+ ### 1. Runtime Layer
23
+
24
+ File: `tests/runtime.spec.js`
25
+
26
+ Use this layer for low-level worker/runtime behaviors:
27
+
28
+ - bridge HTTP health endpoint behavior
29
+ - worker fallback defaults
30
+ - port conflict recovery
31
+ - single-instance replacement at the runtime-state layer
32
+ - direct `probeCopilotBridgeRuntime()` status behavior
33
+
34
+ ### 2. Workflow Layer
35
+
36
+ File: `tests/workflows.spec.js`
37
+
38
+ Use this layer for app use cases and filesystem side effects:
39
+
40
+ - `startBridge`
41
+ - `stopBridge`
42
+ - `statusBridge`
43
+ - `switchProvider`
44
+ - `runDoctor`
45
+ - persistence and rollback behavior
46
+
47
+ ### 3. Command Layer
48
+
49
+ File: `tests/commands.spec.js`
50
+
51
+ Use this layer for registry, argument parsing, and dispatch wiring:
52
+
53
+ - nested command parsing
54
+ - help text
55
+ - `executeCommand()` dispatch for `bridge start|stop|status`
56
+ - mismatch-guard and unresolved-target error contracts
57
+
58
+ ### 4. Built CLI Layer
59
+
60
+ File: `tests/cli-e2e.spec.js`
61
+
62
+ Use this layer only for a small number of user-visible end-to-end checks:
63
+
64
+ - `bridge start --json`
65
+ - `bridge status --json`
66
+ - `bridge stop --json`
67
+ - stable JSON error envelopes for bridge failures
68
+
69
+ ## Shared Fixtures And Helpers
70
+
71
+ ### Existing helpers
72
+
73
+ - `tests/helpers.js`
74
+ - `makeSandboxCopy()`
75
+ - `makeEmptyCodexDir()`
76
+ - `runBuiltCli()`
77
+ - `runJsonCli()`
78
+ - `tests/workflows.spec.js`
79
+ - `makeFixture()`
80
+ - `withCodexAvailable()`
81
+ - `withFakeCopilotSdk()`
82
+ - `getFreePort()`
83
+ - `requestJson()`
84
+ - `tests/commands.spec.js`
85
+ - `makeTempCodexDir()`
86
+ - `writeBridgeFixture()`
87
+ - `withFakeCopilotSdk()`
88
+
89
+ ### Environment hooks
90
+
91
+ Mock bridge-oriented tests should continue to use:
92
+
93
+ - `CODEX_SWITCH_COPILOT_RUNTIME_DIR`
94
+ - `CODEX_SWITCH_RUNTIME_STATE_DIR`
95
+
96
+ These keep SDK loading and runtime-state persistence isolated inside temporary directories.
97
+
98
+ ## Required Automated Coverage
99
+
100
+ ### Runtime tests
101
+
102
+ Required scenarios:
103
+
104
+ - healthy in-process bridge serves `/healthz`
105
+ - worker fallback port remains `41415`
106
+ - `ensureCopilotBridge()` reuses a healthy worker for the same provider
107
+ - `ensureCopilotBridge()` replaces a different managed provider instance
108
+ - `ensureCopilotBridge()` recovers from preferred-port conflicts
109
+ - `ensureCopilotBridge()` reports startup failures with `BRIDGE_START_FAILED`
110
+
111
+ Recommended additions when extending runtime coverage:
112
+
113
+ - `probeCopilotBridgeRuntime()` with missing state
114
+ - `probeCopilotBridgeRuntime()` with stale state and no active Copilot provider
115
+ - `probeCopilotBridgeRuntime()` with base URL mismatch
116
+ - `probeCopilotBridgeRuntime()` with failed healthcheck
117
+
118
+ ### Workflow tests
119
+
120
+ Required scenarios:
121
+
122
+ - explicit `bridge start|status|stop`
123
+ - `bridge stop` idempotency without runtime state
124
+ - recovered-port persistence into `providers.json` and `config.toml`
125
+ - cleanup when recovered-port persistence fails for a newly started worker
126
+ - cleanup when recovered-port persistence fails after replacing a previous worker
127
+ - providers rollback when config projection update fails
128
+ - stale runtime-state surfaced by `status` and `doctor` while a direct provider is active
129
+ - `switchProvider()` keeps bridge cleanup semantics on failure
130
+
131
+ Recommended additions when extending workflow coverage:
132
+
133
+ - active-provider bridge target resolution without explicit provider argument
134
+ - sole Copilot provider resolution without explicit provider argument
135
+ - explicit mismatch guard for `bridge stop`
136
+ - explicit mismatch guard for `bridge status`
137
+ - `BRIDGE_TARGET_UNRESOLVED` for non-interactive multi-provider ambiguity
138
+
139
+ ### Command tests
140
+
141
+ Required scenarios:
142
+
143
+ - nested `bridge` command parsing
144
+ - bridge help text rendering
145
+ - `executeCommand()` dispatches `bridge start|status|stop`
146
+
147
+ Recommended additions when extending command coverage:
148
+
149
+ - `executeCommand()` mismatch guard for `bridge stop`
150
+ - `executeCommand()` mismatch guard for `bridge status`
151
+ - `executeCommand()` unresolved target failures
152
+
153
+ ### Built CLI tests
154
+
155
+ Required scenarios:
156
+
157
+ - `bridge start|status|stop` through the built CLI entrypoint
158
+ - read-command JSON envelope remains stable while `doctor` now may report multiple issue codes
159
+
160
+ Recommended additions when extending CLI coverage:
161
+
162
+ - `bridge status` stale runtime-state envelope
163
+ - `bridge start` unresolved-target envelope
164
+
165
+ ## Fast Execution Order
166
+
167
+ When time is limited, implement and verify tests in this order:
168
+
169
+ 1. `tests/commands.spec.js`
170
+ 2. `tests/workflows.spec.js`
171
+ 3. `tests/cli-e2e.spec.js`
172
+ 4. `tests/runtime.spec.js`
173
+
174
+ This order catches the highest-value regressions first:
175
+
176
+ - wiring regressions
177
+ - persistence/cleanup regressions
178
+ - user-visible CLI regressions
179
+ - low-level runtime regressions
180
+
181
+ ## Running The Suite
182
+
183
+ Build and run all tests:
184
+
185
+ ```bash
186
+ npm test
187
+ ```
188
+
189
+ This runs:
190
+
191
+ ```bash
192
+ npm run build
193
+ node tests/run-tests.js
194
+ ```
195
+
196
+ ## Release Gate For `0.0.9`
197
+
198
+ Treat bridge automation as release-ready only when all of the following are true:
199
+
200
+ - `commands`, `runtime`, `workflows`, and `cli-e2e` all pass
201
+ - `bridge start|stop|status` are covered at both app and CLI layers
202
+ - single-instance reuse and replacement are covered
203
+ - recovered-port persistence and cleanup failure paths are covered
204
+ - stale runtime-state diagnostics are covered in both `status` and `doctor`
205
+
206
+ ## Remaining Manual Smoke Checks
207
+
208
+ Automated coverage does not replace a final real-environment smoke pass.
209
+
210
+ Before shipping, still run a logged-in Copilot smoke check for:
211
+
212
+ - real `bridge start`
213
+ - real `bridge status`
214
+ - one real request through `/v1/chat/completions`
215
+ - real `bridge stop`
216
+ - real `switch <copilot-provider>` reuse/replacement behavior
217
+
218
+ ## Minimal Manual Smoke Checklist
219
+
220
+ Use this short checklist after the automated suite passes and after you have logged into Copilot in the real target environment.
221
+
222
+ ### Preconditions
223
+
224
+ - run from the repository root
225
+ - use the real Codex directory you intend to validate
226
+ - ensure the target Copilot provider already exists in `providers.json`
227
+ - ensure the optional Copilot SDK is installed
228
+ - ensure you are logged into Copilot before starting the live smoke pass
229
+
230
+ Suggested placeholder values:
231
+
232
+ - `<CODEX_DIR>`: your real Codex directory
233
+ - `<COPILOT_PROVIDER>`: the Copilot-backed provider name you want to validate
234
+
235
+ ### 1. Confirm the automated gate is still green
236
+
237
+ ```bash
238
+ npm test
239
+ ```
240
+
241
+ Expected result:
242
+
243
+ - build succeeds
244
+ - all automated suites pass
245
+
246
+ ### 2. Start the real managed bridge
247
+
248
+ ```bash
249
+ node dist/cli.js bridge start <COPILOT_PROVIDER> --json --codex-dir <CODEX_DIR>
250
+ ```
251
+
252
+ Expected result:
253
+
254
+ - command exits successfully
255
+ - JSON payload reports the requested provider
256
+ - payload includes `host`, `port`, and `baseUrl`
257
+ - `reused` is `false` on the first successful start unless a healthy matching bridge is already running
258
+
259
+ ### 3. Confirm bridge status
260
+
261
+ ```bash
262
+ node dist/cli.js bridge status <COPILOT_PROVIDER> --json --codex-dir <CODEX_DIR>
263
+ ```
264
+
265
+ Expected result:
266
+
267
+ - command exits successfully
268
+ - `health.ok` is `true`
269
+ - `active` is `true`
270
+ - `matches` is `true`
271
+
272
+ ### 4. Send one real request through the bridge
273
+
274
+ Use the `baseUrl` and API key from the selected provider record. Replace `<BRIDGE_BASE_URL>` and `<BRIDGE_API_KEY>` with real values from your environment.
275
+
276
+ ```bash
277
+ curl -sS <BRIDGE_BASE_URL>/chat/completions \
278
+ -H "Content-Type: application/json" \
279
+ -H "Authorization: Bearer <BRIDGE_API_KEY>" \
280
+ -d "{\"model\":\"gpt-4o-mini\",\"messages\":[{\"role\":\"user\",\"content\":\"Reply with the single word OK.\"}]}"
281
+ ```
282
+
283
+ Expected result:
284
+
285
+ - HTTP request succeeds
286
+ - response contains a completion payload
287
+ - model output proves the request reached the live bridge successfully
288
+
289
+ If your shell or environment prefers the OpenAI-style path, validate the same request against:
290
+
291
+ ```text
292
+ <BRIDGE_BASE_URL>/chat/completions
293
+ ```
294
+
295
+ ### 5. Verify same-provider reuse
296
+
297
+ Run the start command again:
298
+
299
+ ```bash
300
+ node dist/cli.js bridge start <COPILOT_PROVIDER> --json --codex-dir <CODEX_DIR>
301
+ ```
302
+
303
+ Expected result:
304
+
305
+ - command exits successfully
306
+ - `reused` is `true`
307
+ - reported `port` remains stable
308
+
309
+ ### 6. Verify switch reuse or replacement behavior
310
+
311
+ Run a real switch into the Copilot provider:
312
+
313
+ ```bash
314
+ node dist/cli.js switch <COPILOT_PROVIDER> --json --codex-dir <CODEX_DIR>
315
+ ```
316
+
317
+ Expected result:
318
+
319
+ - command exits successfully
320
+ - provider/profile switch succeeds
321
+ - if the same healthy bridge is already running, it is reused
322
+ - if another managed bridge instance was active, it is replaced cleanly
323
+
324
+ If you have a second Copilot provider available, also validate explicit replacement:
325
+
326
+ ```bash
327
+ node dist/cli.js bridge start <SECOND_COPILOT_PROVIDER> --json --codex-dir <CODEX_DIR>
328
+ ```
329
+
330
+ Expected result:
331
+
332
+ - previous managed instance is replaced
333
+ - status for the new provider is healthy
334
+ - no stale runtime-state mismatch is left behind
335
+
336
+ ### 7. Stop the managed bridge
337
+
338
+ ```bash
339
+ node dist/cli.js bridge stop <COPILOT_PROVIDER> --json --codex-dir <CODEX_DIR>
340
+ ```
341
+
342
+ Expected result:
343
+
344
+ - command exits successfully
345
+ - payload reports `stopped: true`
346
+
347
+ ### 8. Confirm shutdown state
348
+
349
+ ```bash
350
+ node dist/cli.js bridge status <COPILOT_PROVIDER> --json --codex-dir <CODEX_DIR>
351
+ ```
352
+
353
+ Expected result:
354
+
355
+ - command may either report inactive bridge health or a missing runtime state, depending on the exact environment state
356
+ - it must not falsely report a healthy active managed bridge after stop
357
+
358
+ ### Manual Pass Criteria
359
+
360
+ Treat the live smoke pass as complete only when all of the following are true:
361
+
362
+ - `bridge start` succeeds in a logged-in real environment
363
+ - `bridge status` reports a healthy active bridge
364
+ - one real request succeeds through the bridge
365
+ - repeated `bridge start` reuses the same healthy instance
366
+ - `switch <copilot-provider>` preserves expected reuse/replacement behavior
367
+ - `bridge stop` shuts the managed instance down cleanly
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@minniexcode/codex-switch",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "description": "Local-first CLI for managing and switching Codex provider/profile configuration.",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",
File without changes