Standardise output for missing or optional fields#248
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughThis PR standardises how missing or optional fields are displayed across the CLI: instead of showing placeholder strings like Changes
Review Notes
|
There was a problem hiding this comment.
Review Summary
| File | Status | Issues |
|---|---|---|
| test/e2e/auth/basic-auth.test.ts | 1 issue | Missing required userEmail in 3 calls |
| src/commands/accounts/current.ts | 1 issue | Inconsistent null fallback in JSON path |
| src/services/interactive-helper.ts | Minor | Old configs show undefined in prompt |
| All other changed files | OK | — |
test/e2e/auth/basic-auth.test.ts
Bug: 3 storeAccount calls missing the now-required userEmail field
The ConfigManager interface and TomlConfigManager implementation were changed to require userEmail in accountInfo, but these e2e tests were not updated:
- Line ~226: storeAccount("token", "platform-test", { accountId: ..., accountName: ... })
- Line ~242: storeAccount("token", "lineending-test", { accountId: ..., accountName: ... })
- Line ~270: storeAccount("isolated-token", "isolated-account", { accountId: ..., accountName: ... })
These are TypeScript errors under the project's strict config. They aren't caught by pnpm test:unit because vitest uses esbuild to transpile (no type checking), but tsc -p tsconfig.test.json --noEmit would fail. Same fix pattern as the unit tests in this PR — just add userEmail: "..." to each call.
src/commands/accounts/current.ts:127
Inconsistency: user: { email: currentAccount.userEmail || null } in cached JSON path
In the error/catch path, JSON output still uses the || null fallback, meaning old configs emit "email": null instead of omitting the key. Inconsistent with the stated goal of omitting fields with no value. Fix: conditionally spread the user key.
src/services/interactive-helper.ts:63
Minor: old configs will show undefined in the account selection prompt
AccountConfig.userEmail is now typed as required, but existing user configs stored before this change won't have it. The interactive account picker would display "(undefined, undefined)" for those users instead of "(Unknown, Unknown)". Not a crash, but noticeably confusing UX for users who have not re-logged-in. Not caught by CI since the interactive prompt path is not exercised in tests.
Overall: The approach is sound. The e2e test TypeScript gap should be fixed before merge; the other two are smaller but worth addressing.
1ab18ea to
377327e
Compare
|
@claude your test issue you flagged was valid - fixed. The others weren't... userEmail has been stored since the initial implementation so I've removed the deadend fallback instead |
There was a problem hiding this comment.
Review: Standardise output for missing or optional fields
Clean, well-scoped PR. The intent is correct and the approach is consistent. A few things worth considering.
src/commands/accounts/current.ts — conditional guard removed (backward compat)
Before, the cached-account block in the catch path was guarded so it was hidden when both fields were absent:
if (currentAccount.accountName || currentAccount.accountId) {
this.log(`${formatLabel("Account (cached)")} ...`)
}
After: unconditional. The TOML config is loaded with parse(content) as unknown as AblyConfig, so TypeScript won't catch missing fields at runtime. A user with a manually-edited or pre-login config could see "undefined (undefined)" instead of nothing.
The login command has always stored these fields (login.ts:182), so this is low risk in practice. Just worth noting as an explicit tradeoff — if desired, a runtime guard on load would eliminate the exposure.
accounts/current.ts catch block — JSON schema change
user.email was previously explicitly null when missing; it will now be absent from the JSON envelope entirely. Consistent with the PR's goal, but callers checking for "email": null would be silently broken.
push/channels/list.ts — final fallback removed
- const id = sub.deviceId || sub.clientId || "unknown";
+ const id = sub.deviceId || sub.clientId;
Both fields are likely optional in the SDK types. If both are absent, output would show "client: undefined". Very low real-world risk but the original fallback cost nothing.
Everything else: LGTM
The SDK types for PresenceMessage.clientId, SpaceMember.clientId/connectionId, and Chat Message.clientId are non-optional strings (TypeScript build would fail otherwise), so removing the || "fallback" guards is correct. The AccountConfig typing changes and storeAccount signature updates match actual usage. Test updates are accurate and complete.
src/commands/auth/issue-jwt-token.ts
Outdated
| this.log(`Key ID: ${keyId}`); | ||
| this.log(`Client ID: ${clientId || "None"}`); | ||
| if (clientId) { | ||
| this.log(`Client ID: ${clientId}`); |
There was a problem hiding this comment.
This should re-use formatClientId
There was a problem hiding this comment.
not the intention of this PR... but have addressed in the last commit 9683748
9cf3926 to
f22cca6
Compare
|
Found few inconsistencies
|
…batch-publish These three commands called rest.request() without checking statusCode, silently swallowing API errors (4xx/5xx) since the Ably SDK returns HTTP errors as part of the response rather than throwing: - channels occupancy get: returned all-zero metrics on error - spaces occupancy get: returned all-zero metrics on error - push batch-publish: reported success on error Add statusCode !== 200 guard with CommandError.fromHttpResponse() to all three, matching the pattern established by the other fixes in this PR. Add corresponding test coverage for HTTP error responses.
Add required userEmail field to 3 storeAccount calls in basic-auth e2e tests to fix TypeScript type errors. Remove unnecessary || null fallback for userEmail in accounts/current cached JSON path since the field is always present.
377327e to
9687ee6
Compare
targeting #236... tests on CI will run once this targets main (once the other PR is in)
Intent
The changes standardize how missing or optional fields are displayed across the CLI: instead of showing inconsistent placeholders like "None", "N/A", or "Unknown", we omit the field entirely from both human and JSON output when it has no value. As part of this, AccountConfig fields that were never actually optional are now typed as required, eliminating their fallback strings at the source.
Summary
accountId,accountName, anduserEmailrequired inAccountConfiginterface (they are always populated duringably login)storeAccount()signature to requireaccountInfowith required fields, matching actual usageclientIdin JSON output (issue-ably-token, issue-jwt-token) so the key is absent rather thannullstoreAccount()Test plan
pnpm test:unitpassespnpm exec eslint .cleannull/"Unknown"