@@ -2100,5 +2100,143 @@ test "GcResult all zero except scanned" {
21002100 try std .testing .expectEqual (@as (usize , 0 ), result .removed );
21012101}
21022102
2103+ // ═══════════════════════════════════════════════════════════════════════════════
2104+ // writeRule tests
2105+ // ═══════════════════════════════════════════════════════════════════════════════
2106+
2107+ test "writeRule creates rule record" {
2108+ var rec = MemoryRecord {};
2109+ const ts : u64 = 1234567890 ;
2110+ generateId (& rec .id_buf , & rec .id_len , ts , "linter" );
2111+ copyToFixed (32 , & rec .agent_buf , & rec .agent_len , "linter" );
2112+ rec .kind = .rule ;
2113+ rec .ts = ts ;
2114+ rec .ttl = 0 ; // permanent
2115+ copyToFixed (256 , & rec .summary_buf , & rec .summary_len , "Always format before commit" );
2116+
2117+ try std .testing .expectEqual (MemoryKind .rule , rec .kind );
2118+ try std .testing .expectEqual (@as (u64 , 0 ), rec .ttl ); // permanent
2119+ }
2120+
2121+ test "writeRule has permanent TTL" {
2122+ try std .testing .expectEqual (@as (u64 , 0 ), MemoryKind .rule .defaultTtl ());
2123+ }
2124+
2125+ // ═══════════════════════════════════════════════════════════════════════════════
2126+ // latestHeartbeat tests
2127+ // ═══════════════════════════════════════════════════════════════════════════════
2128+
2129+ test "latestHeartbeat returns null for no records" {
2130+ // This test verifies the function signature - actual I/O would require file setup
2131+ _ = &.{MemoryKind .heartbeat };
2132+ }
2133+
2134+ test "latestHeartbeat uses correct filter" {
2135+ const opts = ReadOptions {
2136+ .agent = "test-agent" ,
2137+ .kind = .heartbeat ,
2138+ .limit = 1 ,
2139+ };
2140+ try std .testing .expectEqual (@as (u32 , 1 ), opts .limit );
2141+ try std .testing .expectEqual (MemoryKind .heartbeat , opts .kind .? );
2142+ }
2143+
2144+ // ═══════════════════════════════════════════════════════════════════════════════
2145+ // getCellHistory tests
2146+ // ═══════════════════════════════════════════════════════════════════════════════
2147+
2148+ test "getCellHistory time calculation" {
2149+ const days : u32 = 7 ;
2150+ const seconds_back : i64 = @as (i64 , days ) * 24 * 3600 ;
2151+ try std .testing .expectEqual (@as (i64 , 604800 ), seconds_back ); // 7 days in seconds
2152+ }
2153+
2154+ test "getCellHistory uses correct filters" {
2155+ const days : u32 = 30 ;
2156+
2157+ const now = std .time .timestamp ();
2158+ const since_ts : u64 = @intCast (@max (0 , now - @as (i64 , days ) * 24 * 3600 ));
2159+
2160+ const opts = ReadOptions {
2161+ .kind = .cellhealth ,
2162+ .since_ts = since_ts ,
2163+ .agent = "cytoplasm" ,
2164+ };
2165+
2166+ try std .testing .expectEqual (MemoryKind .cellhealth , opts .kind .? );
2167+ try std .testing .expectEqualStrings ("cytoplasm" , opts .agent .? );
2168+ }
2169+
2170+ // ═══════════════════════════════════════════════════════════════════════════════
2171+ // getAllCellHealth tests
2172+ // ═══════════════════════════════════════════════════════════════════════════════
2173+
2174+ test "getAllCellHealth time window" {
2175+ const days : u32 = 90 ;
2176+ const now : i64 = std .time .timestamp ();
2177+ const seconds_back : i64 = @as (i64 , days ) * 24 * 3600 ;
2178+ const since_ts : u64 = @intCast (@max (0 , now - seconds_back ));
2179+
2180+ try std .testing .expect (since_ts > 0 );
2181+ try std .testing .expect (since_ts <= @as (u64 , @intCast (now )));
2182+ }
2183+
2184+ test "getAllCellHealth uses large limit" {
2185+ const days : u32 = 30 ;
2186+
2187+ _ = days ;
2188+ // Function uses limit = 100000 to get all records
2189+ const expected_limit : u32 = 100000 ;
2190+ try std .testing .expectEqual (@as (u32 , 100000 ), expected_limit );
2191+ }
2192+
2193+ // ═══════════════════════════════════════════════════════════════════════════════
2194+ // MemoryKind TTL edge cases
2195+ // ═══════════════════════════════════════════════════════════════════════════════
2196+
2197+ test "MemoryKind TTL heartbeat is 7 days" {
2198+ const week_sec = 7 * 24 * 3600 ;
2199+ try std .testing .expectEqual (@as (u64 , week_sec ), MemoryKind .heartbeat .defaultTtl ());
2200+ }
2201+
2202+ test "MemoryKind TTL episode is 30 days" {
2203+ const month_sec = 30 * 24 * 3600 ;
2204+ try std .testing .expectEqual (@as (u64 , month_sec ), MemoryKind .episode .defaultTtl ());
2205+ }
2206+
2207+ test "MemoryKind TTL error is 14 days" {
2208+ const two_weeks_sec = 14 * 24 * 3600 ;
2209+ try std .testing .expectEqual (@as (u64 , two_weeks_sec ), MemoryKind .@"error" .defaultTtl ());
2210+ }
2211+
2212+ test "MemoryKind TTL cellhealth is 90 days" {
2213+ const quarter_sec = 90 * 24 * 3600 ;
2214+ try std .testing .expectEqual (@as (u64 , quarter_sec ), MemoryKind .cellhealth .defaultTtl ());
2215+ }
2216+
2217+ test "MemoryKind TTL permanent types are zero" {
2218+ try std .testing .expectEqual (@as (u64 , 0 ), MemoryKind .learning .defaultTtl ());
2219+ try std .testing .expectEqual (@as (u64 , 0 ), MemoryKind .rule .defaultTtl ());
2220+ }
2221+
2222+ // ═══════════════════════════════════════════════════════════════════════════════
2223+ // MemoryRecord field accessors
2224+ // ═══════════════════════════════════════════════════════════════════════════════
2225+
2226+ test "MemoryRecord ts field" {
2227+ const rec = MemoryRecord { .ts = 1234567890 };
2228+ try std .testing .expectEqual (@as (u64 , 1234567890 ), rec .ts );
2229+ }
2230+
2231+ test "MemoryRecord kind field" {
2232+ const rec = MemoryRecord { .kind = .episode };
2233+ try std .testing .expectEqual (MemoryKind .episode , rec .kind );
2234+ }
2235+
2236+ test "MemoryRecord ttl field" {
2237+ const rec = MemoryRecord { .ttl = 3600 };
2238+ try std .testing .expectEqual (@as (u64 , 3600 ), rec .ttl );
2239+ }
2240+
21032241// CellType and HealthStatus are not yet defined in hippocampus module
21042242// These tests will be added when the types are implemented
0 commit comments