Skip to content

test: corrupt team cache is non-fatal for issue view (#194)#244

Merged
Zious11 merged 2 commits intodevelopfrom
test/corrupt-team-cache-194
Apr 21, 2026
Merged

test: corrupt team cache is non-fatal for issue view (#194)#244
Zious11 merged 2 commits intodevelopfrom
test/corrupt-team-cache-194

Conversation

@Zious11
Copy link
Copy Markdown
Owner

@Zious11 Zious11 commented Apr 21, 2026

Summary

Adds an integration test that writes truncated JSON to teams.json, runs jr issue view, and asserts the command succeeds with an actionable hint surfaced inline in the Team row. Locks the graceful-degradation guarantee against regressions.

Divergence from issue's original proposal

The issue proposed "assert stderr contains a warning about the cache". That's the I/O-error path (src/cli/issue/list.rs:951eprintln!("warning: failed to read team cache: {e}")). But corrupt JSON takes a different path:

  • src/cache.rs:23-26 maps serde_json::from_str errors to Ok(None) (not Err)
  • The handler at list.rs:947 then uses the same fall-through as a cold cache: "{UUID} (name not cached — run 'jr team list --refresh')" inline in the output table

That fall-through is equally actionable — running the refresh overwrites the corrupt file, fixing the problem. So the test pins the real behavior (stdout has the UUID + inline hint) rather than asserting the stderr warning that doesn't fire for this path.

If we later decide corrupt caches warrant their own user-facing signal (distinct from "cache empty"), that's a production change to read_cache, not a test change — worth a separate issue.

Test plan

  • cargo fmt --all -- --check clean
  • cargo clippy --all-targets -- -D warnings clean
  • cargo test — 814 passed, 0 failed (baseline 813 + 1 new)
  • The new test verified green in isolation

Scope

Single test, no production changes. Uses existing common::fixtures::issue_response_with_team fixture.

Refs #194

Add integration test that writes truncated JSON to teams.json, runs
`jr issue view`, and asserts the command succeeds with an actionable
hint ("name not cached — run 'jr team list --refresh'") inline in the
Team row.

Scope note: the issue's original proposal called for "stderr contains a
warning about the cache", but that's the I/O-error path
(src/cli/issue/list.rs:951). Corrupt JSON takes a different path —
src/cache.rs:23-26 maps serde_json::from_str failures to Ok(None), and
the handler at list.rs:947 surfaces the same inline hint used for a
cold cache. That hint is equally actionable (user runs the refresh to
overwrite the corrupt file), so the test pins the real behavior rather
than asserting the stderr warning that doesn't exist for this path.

Refs #194
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds an integration test to ensure jr issue view gracefully falls back (non-fatal) when the team cache file (teams.json) is corrupt, surfacing the UUID plus the existing “name not cached — run 'jr team list --refresh'” hint inline.

Changes:

  • Add issue_view_corrupt_team_cache_falls_back_gracefully integration test that writes invalid JSON to teams.json.
  • Assert jr issue view succeeds and stdout includes both the team UUID and the cache-refresh hint.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/issue_view_errors.rs Outdated
Per Copilot review: the comment said "Truncated JSON" but the previous
content ("{ not json") was malformed tokens rather than a truncation.
Use `{"teams": [` — valid JSON opening abruptly cut off — so the test
fixture matches its stated partial-write scenario.

Both inputs trigger the same Ok(None) fall-through (verified by the
unit test at src/cache.rs:661), so coverage is unchanged.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Zious11 Zious11 merged commit 3c02c02 into develop Apr 21, 2026
11 checks passed
@Zious11 Zious11 deleted the test/corrupt-team-cache-194 branch April 21, 2026 16:10
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.

2 participants