MCPcopy Create free account
hub / github.com/Niko1221/Strata / main

Function main

engine/src/program/conv_cache_test.cpp:57–189  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55}
56
57int main() {
58 std::printf("conv_cache_test\n");
59 { // --prompt-cache-spread: 200 turns of 1,000 tokens after a 9,525-token system prompt, 6 checkpoints
60 const int64_t end = 9525 + 200 * 1000;
61 const int64_t lru6 = reuse_after_edit(false, 9525, 1000, 200, 6, 6000);
62 const int64_t spread6 = reuse_after_edit(true, 9525, 1000, 200, 6, 6000);
63 std::printf(" an edit 6K before the end: least recent use reuses %lld, spread %lld of %lld\n", (long long) lru6,
64 (long long) spread6, (long long) end);
65 check(lru6 == 9525, "least recent use: an edit 6K back falls through to the root");
66 check(end - spread6 < 4 * 6000, "spread: an edit 6K back reads less than 24K again");
67 const int64_t spread42 = reuse_after_edit(true, 9525, 1000, 200, 6, 42000);
68 check(end - spread42 < 4 * 42000, "spread: an edit 42K back reads less than 168K again");
69 check(reuse_after_edit(true, 9525, 1000, 200, 6, 500) == end - 1000, "spread: the turn before is still kept");
70 }
71 {
72 const std::vector<int64_t> lens = {100, 200, 300, 400};
73 const std::vector<uint64_t> stamps = {1, 2, 3, 4};
74 const bool pinned[] = {false, true, true, false};
75 check(spread_victim(lens.data(), stamps.data(), 4, 3, nullptr, pinned) ==
76 eviction_victim(stamps.data(), 4, 3, nullptr, pinned),
77 "spread: every candidate pinned - the plain policy");
78 check(spread_victim(lens.data(), stamps.data(), 2, 1, nullptr, nullptr) == 0,
79 "spread: two items, one slot - the plain policy");
80 }
81 {
82 const std::vector<uint64_t> stamps = {1, 2, 3, 4, 5, 6, 7}; // chat A: root + six turns, one over
83 check(eviction_victim(stamps.data(), stamps.size(), 6) == 1,
84 "over budget with fresh stamps: the oldest leaf leaves (the FIFO it was)");
85 }
86 {
87 // chat B mounts through the root long after it was created; its stamp stays ancient
88 const std::vector<uint64_t> stamps = {1, 100, 101, 102, 103, 104, 105};
89 const size_t v = eviction_victim(stamps.data(), stamps.size(), 6);
90 check(v == 1, "the root's stale stamp never makes it the victim");
91 check(v != 0, "the root - the shared prefix - is never the victim");
92 }
93 {
94 // the same chain after mounting checkpoint 1: its stamp jumps, the rotation moves to the next leaf
95 const std::vector<uint64_t> stamped = {1, 8, 3, 4, 5, 6, 7};
96 check(eviction_victim(stamped.data(), stamped.size(), 6) == 2,
97 "after a mount, the rotation takes the next least recently used leaf");
98 }
99 {
100 const std::vector<uint64_t> stamps = {1, 90, 91, 92};
101 check(eviction_victim(stamps.data(), stamps.size(), 2) == 1,
102 "a two-slot budget keeps root + newest and drops the leaf in between");
103 check(eviction_victim(stamps.data(), stamps.size(), 1) == 0,
104 "a one-slot budget has no pin: the oldest leaves, the newest point stays");
105 }
106 {
107 const std::vector<uint64_t> stamps = {7, 3, 3, 5};
108 const size_t a = eviction_victim(stamps.data(), stamps.size(), 4);
109 const size_t b = eviction_victim(stamps.data(), stamps.size(), 4);
110 check(a == 1 && b == 1, "ties among equally stale leaves: the earlier index, deterministically");
111 }
112 { // --prompt-cache-tail: the tail checkpoint goes first; never the root, never the newest item
113 const std::vector<uint64_t> st = {1, 2, 3, 4, 5, 6, 7};
114 const bool t2[7] = {false, false, false, true, false, false, false};

Callers

nothing calls this directly

Calls 8

reuse_after_editFunction · 0.85
spread_victimFunction · 0.85
eviction_victimFunction · 0.85
restore_fitsFunction · 0.85
rewind_keepFunction · 0.85
checkFunction · 0.70
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected