tests: add LeastRecentlyUsedCache regression tests #671

Manually merged
github merged 5 commits from gh-pr/671/head into gh-pr/671/base 2026-11-26 09:28:50 +00:00
Owner

@⁠c0sxm0s on GitHub · 2026-09-17 12:50 UTC · original
c0sxm0s:lru-cache-tests → main · +236 −16 · 6 files · 5 commits · merged 2026-09-25 22:42 UTC

Summary

Common::LeastRecentlyUsedCache had no dedicated regression tests, unlike the
other common containers (BitArray, SlotVector usage, page tables). Add
LruCacheTests.cpp covering walk order, ForEachItemBelow tick filtering,
early-exit boolean callbacks, Touch reordering / ignored older ticks, Free,
and freed-id reuse. Registered as the lru_cache CTest and added to the
kyty_tests aggregate target.

Test

  • _Build/windows/lru_cache_tests.exe passes
  • ctest -R lru_cache passes on Windows (clang-cl 23.1.1, Qt 6.12.0)
**@⁠c0sxm0s** on GitHub · 2026-09-17 12:50 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/671) `c0sxm0s:lru-cache-tests` → `main` · +236 −16 · 6 files · 5 commits · merged 2026-09-25 22:42 UTC ## Summary Common::LeastRecentlyUsedCache had no dedicated regression tests, unlike the other common containers (BitArray, SlotVector usage, page tables). Add LruCacheTests.cpp covering walk order, ForEachItemBelow tick filtering, early-exit boolean callbacks, Touch reordering / ignored older ticks, Free, and freed-id reuse. Registered as the lru_cache CTest and added to the kyty_tests aggregate target. ## Test - `_Build/windows/lru_cache_tests.exe` passes - `ctest -R lru_cache` passes on Windows (clang-cl 23.1.1, Qt 6.12.0)
When the primary feed is reachable but its tag differs from the build tag,
the result was discarded and the GitHub API fallback was consulted. If the
fallback request failed (api.github.com rate-limits unauthenticated
requests), the launcher reported an error even though the primary feed had
already returned a usable update answer with a working release URL. Keep
the primary feed answer and show it if the fallback fails.
--screen-width, --screen-height, --gpu, and --vblank-frequency were parsed
with Common::ToInt32/ToInt64, which ignores std::from_chars errors and
returns 0, so values like "--screen-width abc" or "--gpu xyz" were
silently accepted: zero screen size, or GPU 0 selected instead of auto
(-1). Reject invalid values with an error message like the other options,
using from_chars-based helpers (ParseUint32/ParseInt32); reject zero
screen dimensions.
Cover the LRU cache walk order, tick filtering in ForEachItemBelow,
early-exit boolean callbacks, Touch reordering and same-tick skips,
Free, and freed-id reuse by later inserts. Modeled on BitArrayTests.
Collect(cache, 35) also visits c when Touch(c, 35) failed to update
its tick (30 <= 35). Use a cutoff of 30 and expect only b.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:28:49 +00:00
github manually merged commit a3b0540ba5 into gh-pr/671/base 2026-11-26 09:28:50 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-09-17 12:58 UTC · original · edited 2026-09-17 13:08 UTC

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: a2465336-c742-4a64-b467-b88c3b9f7c71

📥 Commits

Reviewing files that changed from the base of the PR and between 263fa0e7a8 and af684a70a8.

📒 Files selected for processing (1)
  • tests/LruCacheTests.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/LruCacheTests.cpp

Included review availability: Your plan provides up to 10 included reviews per hour; 5 remain after this review.


📝 Walkthrough

Walkthrough

The pull request improves update-feed fallback handling and preserves usable primary-feed results. It adds strict parsing for launcher dimensions, GPU index, and vblank frequency. It adds standalone tests for Common::LeastRecentlyUsedCache and registers them with CTest and the aggregate test target.

Priority: ⬇️ Low

Change: Bug fix

Merge Risk: ⚪ Minimal · up to af684

No concrete current-head behavior risk remains from the fallback, argument parsing, or LRU test changes.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 15.38% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary change: adding regression tests for LeastRecentlyUsedCache.
Description check ✅ Passed The description directly explains the added regression tests, their coverage, CTest registration, aggregate target, and test results.
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.

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

**@⁠coderabbitai[bot]** on GitHub · 2026-09-17 12:58 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/671#issuecomment-5714732236) · edited 2026-09-17 13:08 UTC <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/671#gh-light-mode-only"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg" alt="Review Change Stack" width="202" height="32"></a><a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/671#gh-dark-mode-only"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg" alt="Review Change Stack" width="202" height="32"></a> <!-- review_stack_entry_end --> <!-- recent_review_start --> No actionable comments were generated in the recent review. 🎉 <details> <summary>ℹ️ Recent review info</summary> <details> <summary>⚙️ Run configuration</summary> **Configuration used**: Path: .coderabbit.yaml **Review profile**: CHILL **Plan**: Advanced **Run ID**: `a2465336-c742-4a64-b467-b88c3b9f7c71` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 263fa0e7a874f8565567a47cd9cdfcfba413743d and af684a70a887deb55063aa524c1c0b96cef8e7f4. </details> <details> <summary>📒 Files selected for processing (1)</summary> * `tests/LruCacheTests.cpp` </details> <details> <summary>🚧 Files skipped from review as they are similar to previous changes (1)</summary> * tests/LruCacheTests.cpp </details> **Included review availability:** Your plan provides up to 10 included reviews per hour; 5 remain after this review. </details> --- <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary>📝 Walkthrough</summary> ## Walkthrough The pull request improves update-feed fallback handling and preserves usable primary-feed results. It adds strict parsing for launcher dimensions, GPU index, and vblank frequency. It adds standalone tests for `Common::LeastRecentlyUsedCache` and registers them with CTest and the aggregate test target. </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ⬇️ Low <!-- change_assessment_commit:"af684a70a887deb55063aa524c1c0b96cef8e7f4" --> **Change:** Bug fix <!-- change_assessment_end --> <!-- final_review_risk_start --> **Merge Risk:** _⚪ Minimal_ · up to `af684` <!-- final_review_risk_coverage:{"sourceCommitId":"af684a70a887deb55063aa524c1c0b96cef8e7f4","coveredCommitId":"af684a70a887deb55063aa524c1c0b96cef8e7f4","kind":"reviewed"} --> No concrete current-head behavior risk remains from the fallback, argument parsing, or LRU test changes. <!-- final_review_risk_end --> <!-- pre_merge_checks_walkthrough_start --> <details> <summary>🚥 Pre-merge checks | ✅ 4 | ❌ 1</summary> ### ❌ Failed checks (1 warning) | Check name | Status | Explanation | Resolution | | :----------------: | :--------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :--------------------------------------------------------------------------------- | | Docstring Coverage | ⚠️ Warning | Docstring coverage is 15.38% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 4 files. | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary>✅ Passed checks (4 passed)</summary> | Check name | Status | Explanation | | :------------------------: | :------- | :------------------------------------------------------------------------------------------------------------------------------------ | | Title check | ✅ Passed | The title clearly and concisely describes the primary change: adding regression tests for LeastRecentlyUsedCache. | | Description check | ✅ Passed | The description directly explains the added regression tests, their coverage, CTest registration, aggregate target, and test results. | | 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. | </details> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- tips_start --> --- <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-09-17 12:58 UTC · original · edited 2026-09-17 13:05 UTC
On tests/LruCacheTests.cpp line 96 (outdated):

@@ -0,0 +1,155 @@
+#include "common/lruCache.h"
+
+#include <cstdint>
+#include <cstdio>
+#include <cstdlib>
+#include <string>
+#include <vector>
+
+namespace {
+
+void Check(bool value, const char *message) {
+  if (!value) {
+    std::fprintf(stderr, "LruCacheTests: failed: %s\n", message);
+    std::abort();
+  }
+}
+
+// Collect the objects reachable through ForEachItemBelow(), in visit order.
+std::vector<std::string> Collect(Common::LeastRecentlyUsedCache<std::string, uint64_t> &cache,
+                                 uint64_t tick) {
+  std::vector<std::string> visited;
+  cache.ForEachItemBelow(tick, [&](const std::string &object) { visited.push_back(object); });
+  return visited;
+}
+
+void TestInsertAndVisitOrder() {
+  Common::LeastRecentlyUsedCache<std::string, uint64_t> cache;
+  const auto a = cache.Insert("a", 10);
+  const auto b = cache.Insert("b", 20);
+  const auto c = cache.Insert("c", 30);
+
+  Check(a != b && b != c && a != c, "Insert returned duplicate ids");
+
+  const auto all = Collect(cache, UINT64_MAX);
+  Check(all.size() == 3 && all[0] == "a" && all[1] == "b" && all[2] == "c",
+        "inserted items are not visited in insertion order");
+
+  const auto below = Collect(cache, 20);
+  Check(below.size() == 2 && below[0] == "a" && below[1] == "b",
+        "ForEachItemBelow visited an item above the tick");
+
+  const auto none = Collect(cache, 5);
+  Check(none.empty(), "ForEachItemBelow visited items below an empty tick");
+}
+
+void TestEarlyExitCallback() {
+  Common::LeastRecentlyUsedCache<std::string, uint64_t> cache;
+  (void)cache.Insert("a", 10);
+  (void)cache.Insert("b", 20);
+  (void)cache.Insert("c", 30);
+
+  std::vector<std::string> visited;
+  cache.ForEachItemBelow(UINT64_MAX, [&](const std::string &object) {
+    visited.push_back(object);
+    return true; // stop after the first item
+  });
+  Check(visited.size() == 1 && visited[0] == "a", "boolean callback did not stop the walk");
+
+  std::vector<std::string> all_visited;
+  cache.ForEachItemBelow(UINT64_MAX, [&](const std::string &object) {
+    all_visited.push_back(object);
+    return false;
+  });
+  Check(all_visited.size() == 3, "false-returning callback did not visit every item");
+}
+
+void TestTouchReordersAndSkips() {
+  Common::LeastRecentlyUsedCache<std::string, uint64_t> cache;
+  const auto a = cache.Insert("a", 10);
+  const auto b = cache.Insert("b", 20);
+  const auto c = cache.Insert("c", 30);
+
+  // Touching the last item must not change the order.
+  cache.Touch(c, 35);
+  auto order = Collect(cache, UINT64_MAX);
+  Check(order.size() == 3 && order[0] == "a" && order[1] == "b" && order[2] == "c",
+        "touching the newest item changed the order");
+
+  // An older or equal tick must be ignored.
+  cache.Touch(a, 10);
+  cache.Touch(a, 5);
+  order = Collect(cache, UINT64_MAX);
+  Check(order[0] == "a" && order[1] == "b" && order[2] == "c",
+        "an ignored touch changed the order");
+
+  // Touching the oldest item moves it to the newest end.
+  cache.Touch(a, 40);
+  order = Collect(cache, UINT64_MAX);
+  Check(order.size() == 3 && order[0] == "b" && order[1] == "c" && order[2] == "a",
+        "touching an item did not move it to the newest end");
+
+  // The touched item now carries its new tick for tick filtering
+  // (a=40, b=20, c=35 after the touches above).
+  const auto below = Collect(cache, 35);
+  Check(below.size() == 2 && below[0] == "b" && below[1] == "c",
+        "touched item did not adopt its new tick");

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Use a cutoff that detects a stale newest-item tick.

Collect(cache, 35) includes c when its tick is either 35 or its old value of 30. The test can pass if Touch(c, 35) does not update the tick. Use a cutoff of 30 and expect only b.

Proposed fix
-  const auto below = Collect(cache, 35);
-  Check(below.size() == 2 && below[0] == "b" && below[1] == "c",
+  const auto below = Collect(cache, 30);
+  Check(below.size() == 1 && below[0] == "b",
         "touched item did not adopt its new tick");
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

  const auto below = Collect(cache, 30);
  Check(below.size() == 1 && below[0] == "b",
        "touched item did not adopt its new tick");

✅ Addressed in commit af684a7

**@⁠coderabbitai[bot]** on GitHub · 2026-09-17 12:58 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/671#discussion_r4037066117) · edited 2026-09-17 13:05 UTC On `tests/LruCacheTests.cpp` line 96 (outdated): ```diff @@ -0,0 +1,155 @@ +#include "common/lruCache.h" + +#include <cstdint> +#include <cstdio> +#include <cstdlib> +#include <string> +#include <vector> + +namespace { + +void Check(bool value, const char *message) { + if (!value) { + std::fprintf(stderr, "LruCacheTests: failed: %s\n", message); + std::abort(); + } +} + +// Collect the objects reachable through ForEachItemBelow(), in visit order. +std::vector<std::string> Collect(Common::LeastRecentlyUsedCache<std::string, uint64_t> &cache, + uint64_t tick) { + std::vector<std::string> visited; + cache.ForEachItemBelow(tick, [&](const std::string &object) { visited.push_back(object); }); + return visited; +} + +void TestInsertAndVisitOrder() { + Common::LeastRecentlyUsedCache<std::string, uint64_t> cache; + const auto a = cache.Insert("a", 10); + const auto b = cache.Insert("b", 20); + const auto c = cache.Insert("c", 30); + + Check(a != b && b != c && a != c, "Insert returned duplicate ids"); + + const auto all = Collect(cache, UINT64_MAX); + Check(all.size() == 3 && all[0] == "a" && all[1] == "b" && all[2] == "c", + "inserted items are not visited in insertion order"); + + const auto below = Collect(cache, 20); + Check(below.size() == 2 && below[0] == "a" && below[1] == "b", + "ForEachItemBelow visited an item above the tick"); + + const auto none = Collect(cache, 5); + Check(none.empty(), "ForEachItemBelow visited items below an empty tick"); +} + +void TestEarlyExitCallback() { + Common::LeastRecentlyUsedCache<std::string, uint64_t> cache; + (void)cache.Insert("a", 10); + (void)cache.Insert("b", 20); + (void)cache.Insert("c", 30); + + std::vector<std::string> visited; + cache.ForEachItemBelow(UINT64_MAX, [&](const std::string &object) { + visited.push_back(object); + return true; // stop after the first item + }); + Check(visited.size() == 1 && visited[0] == "a", "boolean callback did not stop the walk"); + + std::vector<std::string> all_visited; + cache.ForEachItemBelow(UINT64_MAX, [&](const std::string &object) { + all_visited.push_back(object); + return false; + }); + Check(all_visited.size() == 3, "false-returning callback did not visit every item"); +} + +void TestTouchReordersAndSkips() { + Common::LeastRecentlyUsedCache<std::string, uint64_t> cache; + const auto a = cache.Insert("a", 10); + const auto b = cache.Insert("b", 20); + const auto c = cache.Insert("c", 30); + + // Touching the last item must not change the order. + cache.Touch(c, 35); + auto order = Collect(cache, UINT64_MAX); + Check(order.size() == 3 && order[0] == "a" && order[1] == "b" && order[2] == "c", + "touching the newest item changed the order"); + + // An older or equal tick must be ignored. + cache.Touch(a, 10); + cache.Touch(a, 5); + order = Collect(cache, UINT64_MAX); + Check(order[0] == "a" && order[1] == "b" && order[2] == "c", + "an ignored touch changed the order"); + + // Touching the oldest item moves it to the newest end. + cache.Touch(a, 40); + order = Collect(cache, UINT64_MAX); + Check(order.size() == 3 && order[0] == "b" && order[1] == "c" && order[2] == "a", + "touching an item did not move it to the newest end"); + + // The touched item now carries its new tick for tick filtering + // (a=40, b=20, c=35 after the touches above). + const auto below = Collect(cache, 35); + Check(below.size() == 2 && below[0] == "b" && below[1] == "c", + "touched item did not adopt its new tick"); ``` _🎯 Functional Correctness_ | _🟡 Minor_ | _⚡ Quick win_ **Use a cutoff that detects a stale newest-item tick.** `Collect(cache, 35)` includes `c` when its tick is either `35` or its old value of `30`. The test can pass if `Touch(c, 35)` does not update the tick. Use a cutoff of `30` and expect only `b`. <details> <summary>Proposed fix</summary> ```diff - const auto below = Collect(cache, 35); - Check(below.size() == 2 && below[0] == "b" && below[1] == "c", + const auto below = Collect(cache, 30); + Check(below.size() == 1 && below[0] == "b", "touched item did not adopt its new tick"); ``` </details> <!-- suggestion_start --> <details> <summary>📝 Committable suggestion</summary> > ‼️ **IMPORTANT** > Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements. ```suggestion const auto below = Collect(cache, 30); Check(below.size() == 1 && below[0] == "b", "touched item did not adopt its new tick"); ``` </details> <!-- suggestion_end --> <!-- fingerprinting:phantom:poseidon:tapir --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:ea07a59208f17e483c25a6c7 --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commit af684a7
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-09-17 12:58 UTC · original · reviewed

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 287c1e8f-d245-4537-8f1a-02e32f393438

📥 Commits

Reviewing files that changed from the base of the PR and between a6144f794b and 263fa0e7a8.

📒 Files selected for processing (5)
  • CMakeLists.txt
  • src/launcher/include/updateChecker.h
  • src/launcher/src/updateChecker.cpp
  • src/main.cpp
  • tests/LruCacheTests.cpp

Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-09-17 12:58 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/671#pullrequestreview-5235925630) · **reviewed** **Actionable comments posted: 1** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> **Configuration used**: Path: .coderabbit.yaml **Review profile**: CHILL **Plan**: Advanced **Run ID**: `287c1e8f-d245-4537-8f1a-02e32f393438` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between a6144f794bc657524e0ab15402c22fb894a86f95 and 263fa0e7a874f8565567a47cd9cdfcfba413743d. </details> <details> <summary>📒 Files selected for processing (5)</summary> * `CMakeLists.txt` * `src/launcher/include/updateChecker.h` * `src/launcher/src/updateChecker.cpp` * `src/main.cpp` * `tests/LruCacheTests.cpp` </details> **Included review availability:** Your plan provides up to 10 included reviews per hour; 7 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
This discussion has been locked. Commenting is limited to contributors.
No description provided.