Repository navigation
feat: improve how cli shows transactions receipts - #250
Conversation
… receipts - Add stdout/stderr flags to ReceiptParams and handling in ReceiptAction - Print consensus_data.leader_receipt[0].genvm_result.stdout/stderr when requested - Keep default behavior to print full receipt when no flags are provided - Update success messages for clarity
- Expose new flags for selective output - Preserve default behavior without flags
…ss messages - Add tests for stdout-only, stderr-only, and both flags - Adjust structure to consensus_data.leader_receipt[0].genvm_result - Verify updated succeedSpinner messages
- Verify options forwarded to ReceiptAction.receipt - Add tests for both flags and individually
WalkthroughAdds --stdout and --stderr flags to the transactions receipt command, threads them through ReceiptOptions/ReceiptParams, and updates ReceiptAction.receipt to conditionally print only stdout, only stderr, or both from the transaction receipt. Extends tests to cover flag parsing and output behavior. No other commands changed. Changes
Sequence Diagram(s)sequenceDiagram
participant U as User
participant CLI as transactions receipt
participant RA as ReceiptAction
participant RPC as Chain RPC
participant OUT as Output/Spinner
U->>CLI: receipt <txId> [--stdout] [--stderr]
CLI->>RA: receipt({ txId, status, retries, interval, rpc, stdout?, stderr? })
RA->>RPC: waitForTransactionReceipt(txId, { status, retries, interval, rpc })
RPC-->>RA: receipt { ... genvm_result: { stdout, stderr } ... }
alt stdout or stderr flagged
RA->>OUT: print selected field(s)
RA-->>CLI: return
else no flags
RA->>OUT: print full receipt
end
CLI-->>U: display output
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/commands/transactions/receipt.ts (1)
21-34: Fix type-safety: validateTransactionStatus expects string but caller passes string | TransactionStatus.
This can fail type-checking and is easy to harden.Use a union-safe call:
- let validatedStatus = this.validateTransactionStatus(status); + const validatedStatus = + typeof status === "string" ? this.validateTransactionStatus(status) : status;Optionally, also widen the helper’s signature to accept
string | TransactionStatusand early-return when already valid.Also applies to: 50-54
🧹 Nitpick comments (6)
src/commands/transactions/receipt.ts (1)
63-82: Stream-only output logic works; tighten edge handling and reduce repetition.
- If either stream is absent, you’ll print
undefined. Consider explicit fallbacks or a clearer message.- Minor DRY: compute message/payload once, then single succeedSpinner/return.
Apply this small refactor:
- // If specific output flags are provided, print only those fields - if (stdout || stderr) { - const stdoutValue = (result as any)?.consensus_data?.leader_receipt[0]?.genvm_result?.stdout; - const stderrValue = (result as any)?.consensus_data?.leader_receipt[0]?.genvm_result?.stderr; - - if (stdout && stderr) { - this.succeedSpinner("Transaction stdout and stderr", { stdout: stdoutValue, stderr: stderrValue }); - return; - } - - if (stdout) { - this.succeedSpinner("Transaction stdout retrieved successfully", stdoutValue); - return; - } - - if (stderr) { - this.succeedSpinner("Transaction stderr retrieved successfully", stderrValue); - return; - } - } + // If specific output flags are provided, print only those fields + if (stdout || stderr) { + const receipt = (result as any)?.consensus_data?.leader_receipt?.[0]?.genvm_result ?? {}; + const stdoutValue = receipt.stdout ?? ""; + const stderrValue = receipt.stderr ?? ""; + + const both = stdout && stderr; + const msg = both + ? "Transaction stdout and stderr" + : stdout + ? "Transaction stdout retrieved successfully" + : "Transaction stderr retrieved successfully"; + const payload = both ? { stdout: stdoutValue, stderr: stderrValue } : (stdout ? stdoutValue : stderrValue); + this.succeedSpinner(msg, payload); + return; + }src/commands/transactions/index.ts (1)
21-22: LGTM: new flags exposed.
Consider clarifying in the help text that flags can be combined.- .option("--stdout", "Print only stdout from the receipt") - .option("--stderr", "Print only stderr from the receipt") + .option("--stdout", "Print stdout from the receipt (can be combined with --stderr)") + .option("--stderr", "Print stderr from the receipt (can be combined with --stdout)")tests/commands/receipt.test.ts (1)
109-141: LGTM: CLI parses new flags correctly.
Optional: add one case combining flags with custom options to ensure no regression in parsing precedence.tests/actions/receipt.test.ts (3)
173-200: Assert no extra default-print call when using --stdout.
Strengthen test by verifying only one success call.expect(receiptAction["succeedSpinner"]).toHaveBeenCalledWith( "Transaction stdout retrieved successfully", "program stdout", ); + expect(receiptAction["succeedSpinner"]).toHaveBeenCalledTimes(1);
202-229: Assert no extra default-print call when using --stderr.
Same rationale as above.expect(receiptAction["succeedSpinner"]).toHaveBeenCalledWith( "Transaction stderr retrieved successfully", "program stderr", ); + expect(receiptAction["succeedSpinner"]).toHaveBeenCalledTimes(1);
231-259: Assert no extra default-print call when using both flags; add missing-field case.
- Ensure only one success call here as well.
- Consider an additional test where stdout/stderr are missing to confirm graceful handling (after code change above).
expect(receiptAction["succeedSpinner"]).toHaveBeenCalledWith( "Transaction stdout and stderr", { stdout: "program stdout", stderr: "program stderr" }, ); + expect(receiptAction["succeedSpinner"]).toHaveBeenCalledTimes(1);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (4)
src/commands/transactions/index.ts(1 hunks)src/commands/transactions/receipt.ts(3 hunks)tests/actions/receipt.test.ts(1 hunks)tests/commands/receipt.test.ts(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
tests/actions/receipt.test.ts (1)
src/commands/transactions/receipt.ts (1)
ReceiptParams(4-12)
tests/commands/receipt.test.ts (1)
src/commands/transactions/receipt.ts (1)
ReceiptAction(16-90)
🔇 Additional comments (2)
src/commands/transactions/receipt.ts (2)
10-11: LGTM: typed flags added to params.
Matches CLI surface; no issues.
42-44: LGTM: flags threaded into action.
Parameters are passed through correctly.
Summary
Adds
--stdoutand--stderroptions to thereceiptcommand, allowing users to print only the program’s stdout or stderr (or both) from a transaction’s receipt. Default behavior remains unchanged and prints the full receipt object.Changes
🚀 New Features
--stdoutand--stderrflags forgenlayer receipt <txId>🔧 Implementation Details
stdout/stderroptions and print:result.consensus_data.leader_receipt[0].genvm_result.stdoutresult.consensus_data.leader_receipt[0].genvm_result.stderr--stdoutand--stderrin thereceiptcommand📁 File Structure
🏗️ Command Architecture
genlayer receipt <txId>--status <status>(default: FINALIZED)--retries <retries>(default: 100)--interval <ms>(default: 5000)--rpc <rpcUrl>--stdout(print only stdout)--stderr(print only stderr)BaseActionspinner and logging conventions🧪 Testing
Action Tests (
tests/actions/receipt.test.ts):Command Tests (
tests/commands/receipt.test.ts):--stdout,--stderr, and both flags together🔧 Usage
✨ Code Quality
BaseActionand spinner usageReceiptParamsandReceiptOptions🔗 Dependencies
BaseActionand existinggenlayer-jsclient initialization🛡️ Backward Compatibility
📚 Documentation Updates
Add notes for
--stdoutand--stderrto thereceiptcommand in README (follow-up doc tweak)Implemented PR description for the new
receiptflags and tests.Summary by CodeRabbit
New Features
Tests