Skip to content

Commit 60f69d0

Browse files
author
Vladimir Rogojin
committed
fix(cli)(sphere-sdk#282): route wallet use confirmation to STDERR
Residual #2 of the §D `manual-test-full-recovery.sh` ALL GREEN campaign. The `sphere wallet use <name>` subcommand printed its confirmation lines ✓ Switched to wallet profile: <name> Nametag: <tag> L1 Addr: <alpha1...> via `console.log` (stdout). The harness captures `sphere balance > file` snapshots; some snapshot blocks bracket the `wallet use` invocation outside the redirect (peer2: `sphere wallet use alice ; sphere balance > file`), others inside a subshell (peer1: `( … sphere wallet use alice && sphere balance ) > file`). The two flows yield different captured-stdout content for the same logical operation, so the resulting peer1-vs-peer2 diff failed assertion even though both wallets had identical balances. Fix: route the entire confirmation block (success and `(wallet not initialized in this profile)` fallback) through `console.error`. Errors (usage hint, profile-not-found) were already on stderr, so this brings the success path in line with them. Behaviour for human operators is unchanged — terminal sessions still see the banner; only `>` / `|` stdout pipelines are now unaffected by it. Side-benefit: any future shell tooling that pipes `sphere wallet use <name> | …` no longer has to filter the banner out of the consumed stream. Tests * `test/integration/cli-wallet-profile.integration.test.ts` — the "`wallet use alice` switches the active profile" assertion now expects the banner on `r.stderr` (with a negative match on `r.stdout`) per the new contract. * Full integration suite: 25 / 25 passed. * Full default unit suite: 119 / 119 passed. Refs sphere-sdk#282
1 parent e73ddb7 commit 60f69d0

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

src/legacy/legacy-cli.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1982,19 +1982,29 @@ async function main(): Promise<void> {
19821982
}
19831983

19841984
if (switchToProfile(profileName)) {
1985-
console.log(`✓ Switched to wallet profile: ${profileName}`);
1985+
// Issue sphere-sdk#282 Residual #2 — confirmation output
1986+
// goes to STDERR so that pipelines capturing the NEXT
1987+
// command's stdout (e.g. `sphere wallet use alice &&
1988+
// sphere balance > file`) don't accidentally include the
1989+
// wallet-use banner in the captured snapshot. Without
1990+
// this, the same logical command sequence produces
1991+
// different captured-stdout content depending on whether
1992+
// the harness redirects the `wallet use` invocation
1993+
// separately or groups it in a subshell — see the
1994+
// peer1-vs-peer2 asymmetry in `manual-test-full-recovery.sh`.
1995+
console.error(`✓ Switched to wallet profile: ${profileName}`);
19861996

19871997
// Show wallet status
19881998
try {
19891999
const sphere = await getSphere();
19902000
const identity = sphere.identity;
19912001
if (identity) {
1992-
console.log(` Nametag: ${identity.nametag || '(not set)'}`);
1993-
console.log(` L1 Addr: ${identity.l1Address}`);
2002+
console.error(` Nametag: ${identity.nametag || '(not set)'}`);
2003+
console.error(` L1 Addr: ${identity.l1Address}`);
19942004
}
19952005
await closeSphere();
19962006
} catch {
1997-
console.log(' (wallet not initialized in this profile)');
2007+
console.error(' (wallet not initialized in this profile)');
19982008
}
19992009
} else {
20002010
console.error(`Profile "${profileName}" not found.`);

test/integration/cli-wallet-profile.integration.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,11 @@ describe('sphere-cli — wallet profile CRUD lifecycle (offline)', () => {
230230
it('`wallet use alice` switches the active profile', () => {
231231
const r = runSphere(env, ['wallet', 'use', 'alice'], { timeoutMs: 15_000 });
232232
expect(r.status).toBe(0);
233-
expect(r.stdout).toMatch(/Switched to wallet profile:\s*alice/);
233+
// sphere-sdk#282 Residual #2 — confirmation lives on STDERR so
234+
// downstream `sphere wallet use … && sphere balance > file` shell
235+
// pipelines don't fold the banner into the captured snapshot.
236+
expect(r.stderr).toMatch(/Switched to wallet profile:\s*alice/);
237+
expect(r.stdout).not.toMatch(/Switched to wallet profile/);
234238

235239
// Verify by re-reading current.
236240
const current = runSphere(env, ['wallet', 'current'], { timeoutMs: 15_000 });

0 commit comments

Comments
 (0)