Skip to content

fix: add structured debug logging to silent catch blocks in update-check#229

Open
iamyhe wants to merge 2 commits into
TestSprite:mainfrom
iamyhe:main
Open

fix: add structured debug logging to silent catch blocks in update-check#229
iamyhe wants to merge 2 commits into
TestSprite:mainfrom
iamyhe:main

Conversation

@iamyhe

@iamyhe iamyhe commented Jul 9, 2026

Copy link
Copy Markdown

What does this PR do?

This PR adds structured debug logging to the silent catch blocks in the update-check module to improve maintainability and troubleshooting.

Key Highlights:

  • Extracted isDebugLoggingEnabled helper for cleaner logic.
  • Injected argv dependency to follow the project's dependency-injection pattern and improve testability.
  • Fixed double newline formatting in debug diagnostic outputs.

Type of change

  • Bug fix / Refactor (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that changes existing behavior)

Summary by CodeRabbit

  • New Features

    • Added optional debug logging for cache read and write failures when running with debug or verbose output enabled.
    • Error messages can now be sent to a configured error output stream, or the default system error stream.
  • Bug Fixes

    • Improved visibility into update-check cache issues while preserving the existing behavior of not throwing or rejecting on failures.

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

This PR adds optional debug logging to the update-notifier cache logic in src/lib/update-check.ts. A new helper checks process.argv for --debug or --verbose flags; when enabled, cache read/parse and cache write failures emit debug messages to stderr while preserving the existing silent-failure behavior. A module doc comment was also reformatted.

Changes

Update-check debug logging

Layer / File(s) Summary
Debug logging helper and cache error handling
src/lib/update-check.ts
Adds isDebugLoggingEnabled helper checking --debug/--verbose argv flags; readUpdateCheckCache and writeUpdateCheckCache catch blocks now log errors to stderr when enabled, while still swallowing errors and returning stale/no-op results.
Header comment reformat
src/lib/update-check.ts
Reformats indentation of the maybeNotifyUpdate documentation block with no logic changes.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Possibly related issues

Possibly related PRs

Suggested reviewers: ruili-testsprite, zeshi-du

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding debug logging to silent catch blocks in update-check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/lib/update-check.ts (1)

120-123: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

argv default parameter never actually gets injected — DI intent unfulfilled.

isDebugLoggingEnabled accepts an argv parameter for testability, but both call sites (Line 136, Line 154) invoke it with no arguments, so it always falls back to reading the real process.argv. Unlike every other dependency in this module (env, now, readFile, stderr, etc., all resolved via resolveUpdateCheckDeps/ResolvedUpdateCheckDeps), argv isn't threaded through the deps object, so tests can't exercise the debug-logging branch without mutating the global process.argv. This directly contradicts the PR's own stated goal of "injecting argv as a dependency ... to improve testability."

♻️ Suggested fix: thread argv through the deps object
-function isDebugLoggingEnabled(argv: string[] = process.argv): boolean {
-  return argv.includes('--debug') || argv.includes('--verbose');
-}
+function isDebugLoggingEnabled(resolved: ResolvedUpdateCheckDeps): boolean {
+  return resolved.argv.includes('--debug') || resolved.argv.includes('--verbose');
+}

Add argv: string[] to UpdateCheckDeps/ResolvedUpdateCheckDeps (defaulting to process.argv in resolveUpdateCheckDeps), then call isDebugLoggingEnabled(resolved) at both call sites.

Also applies to: 136-136, 154-154

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/lib/update-check.ts` around lines 120 - 123, Thread argv through the
dependency injection path in update-check.ts: add argv to UpdateCheckDeps and
ResolvedUpdateCheckDeps, default it to process.argv in resolveUpdateCheckDeps,
and update the call sites of isDebugLoggingEnabled so they use the resolved deps
instead of relying on the function’s default parameter. This keeps
isDebugLoggingEnabled testable without touching global process.argv and aligns
it with the other injected dependencies in this module.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/lib/update-check.ts`:
- Around line 135-138: The debug write in readUpdateCheckCache is appending an
explicit newline even though resolved.stderr already terminates the message,
causing double spacing in debug output. Update the debug logging strings in this
catch block (and any similar resolved.stderr calls in update-check.ts) to be
newline-free so the output formatting matches the advisory path.

---

Nitpick comments:
In `@src/lib/update-check.ts`:
- Around line 120-123: Thread argv through the dependency injection path in
update-check.ts: add argv to UpdateCheckDeps and ResolvedUpdateCheckDeps,
default it to process.argv in resolveUpdateCheckDeps, and update the call sites
of isDebugLoggingEnabled so they use the resolved deps instead of relying on the
function’s default parameter. This keeps isDebugLoggingEnabled testable without
touching global process.argv and aligns it with the other injected dependencies
in this module.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 16e4c2a9-8257-4487-9bb1-4ed1a6199d77

📥 Commits

Reviewing files that changed from the base of the PR and between 3305dfa and 330e17f.

📒 Files selected for processing (1)
  • src/lib/update-check.ts

Comment thread src/lib/update-check.ts
Comment on lines +135 to +138
} catch (err) {
if (isDebugLoggingEnabled()) {
resolved.stderr(`[debug] readUpdateCheckCache: ${err instanceof Error ? err.message : String(err)}\n`);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Inspect resolveUpdateCheckDeps / default stderr implementation for newline handling
rg -n -B2 -A8 'resolveUpdateCheckDeps|stderr:' src/lib/update-check.ts

Repository: TestSprite/testsprite-cli

Length of output: 2763


🏁 Script executed:

#!/bin/bash
sed -n '130,160p' src/lib/update-check.ts
printf '\n---\n'
sed -n '280,295p' src/lib/update-check.ts

Repository: TestSprite/testsprite-cli

Length of output: 2016


Drop the explicit \n in the debug writes. resolved.stderr already adds a newline, so the debug messages print with a doubled blank line. Keep those strings newline-free to match the advisory call.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/lib/update-check.ts` around lines 135 - 138, The debug write in
readUpdateCheckCache is appending an explicit newline even though
resolved.stderr already terminates the message, causing double spacing in debug
output. Update the debug logging strings in this catch block (and any similar
resolved.stderr calls in update-check.ts) to be newline-free so the output
formatting matches the advisory path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant