Skip to content

Commit 597d204

Browse files
heskewclaude
andcommitted
test: restore process.argv in the suite that overrides CONFIRM_DOWNGRADE
Per review: fix the leaking fixture at its source instead of compensating in upgradePrompt.test.js — hdbInfoController.test.js now saves/restores process.argv around its override, and the compensation filter is removed. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FNbH9xnNHcd7V1a58ho2CJ
1 parent 6ca79ef commit 597d204

3 files changed

Lines changed: 9 additions & 10 deletions

File tree

DESIGN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ To match v4: `OpenDBIObject` sets `randomAccessStructure = isPrimary`, and `Reco
3030

3131
- The prompt's answer can be supplied non-interactively via `CONFIRM_DOWNGRADE` — env var or `--CONFIRM_DOWNGRADE` CLI arg; argv wins (`assignCMDENVVariables`). With no override and no TTY on stdin, the prompt throws instead of blocking on stdin forever (#2046 — services/CI hung with nothing in the log; the mismatch is also logged to hdb.log now).
3232
- Upgrades never prompt (see the rationale comment in `bin/upgrade.js`); only the downgrade direction confirms. `upgradeCertsPrompt()` on the 4.x upgrade path still has the block-on-stdin hazard.
33-
- Test-suite gotcha: `unitTests/dataLayer/hdbInfoController.test.js` pushes `--CONFIRM_DOWNGRADE yes` into `process.argv` in a `before()` without cleanup, so it leaks into every later test file in the mocha process; tests that exercise the prompt must scrub argv first (see `unitTests/upgrade/upgradePrompt.test.js`).
33+
- Test-suite gotcha: a suite that supplies the override via `process.argv` affects every later test file in the same mocha process — save and restore `process.argv` in `before`/`after` (see `unitTests/dataLayer/hdbInfoController.test.js`).
3434

3535
## getFromSource() timing: promise resolves before commit runs
3636

unitTests/dataLayer/hdbInfoController.test.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,18 @@ describe.skip('Test hdbInfoController module ', function () {
219219
insert_stub.resolves();
220220
});
221221

222+
let originalArgv;
223+
222224
before(() => {
223225
version_stub = sandbox.stub(packageJson, 'version').get(() => '4.0.0');
224226
hasUpgradesRequired_stub = sandbox.stub(directiveManager, 'hasUpgradesRequired').returns(true);
225227
sandbox.stub().returns();
226-
process.argv.push('--CONFIRM_DOWNGRADE', 'yes');
228+
originalArgv = process.argv;
229+
process.argv = [...process.argv, '--CONFIRM_DOWNGRADE', 'yes'];
230+
});
231+
232+
after(() => {
233+
process.argv = originalArgv;
227234
});
228235

229236
it('getVersionUpdateInfo nominal test', async () => {

unitTests/upgrade/upgradePrompt.test.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,16 @@ describe('forceDowngradePrompt — non-interactive starts', () => {
1414
const upgradeObj = new UpgradeObject('5.2.0', '5.1.22');
1515
let originalIsTTY;
1616
let originalEnv;
17-
let originalArgv;
1817

1918
beforeEach(() => {
2019
originalIsTTY = process.stdin.isTTY;
2120
originalEnv = process.env.CONFIRM_DOWNGRADE;
22-
originalArgv = process.argv;
2321
process.stdin.isTTY = false;
2422
delete process.env.CONFIRM_DOWNGRADE;
25-
// Other test files push --CONFIRM_DOWNGRADE into argv without cleanup; scrub the flag and
26-
// its value so these tests control the override.
27-
process.argv = process.argv.filter(
28-
(arg, i, argv) => arg !== '--CONFIRM_DOWNGRADE' && argv[i - 1] !== '--CONFIRM_DOWNGRADE'
29-
);
3023
});
3124

3225
afterEach(() => {
3326
process.stdin.isTTY = originalIsTTY;
34-
process.argv = originalArgv;
3527
if (originalEnv === undefined) delete process.env.CONFIRM_DOWNGRADE;
3628
else process.env.CONFIRM_DOWNGRADE = originalEnv;
3729
});

0 commit comments

Comments
 (0)