55package net .ladenthin .llama .value ;
66
77import static org .junit .jupiter .api .Assertions .assertEquals ;
8+ import static org .junit .jupiter .api .Assertions .assertFalse ;
89import static org .junit .jupiter .api .Assertions .assertTrue ;
910
1011import com .fasterxml .jackson .databind .ObjectMapper ;
@@ -28,9 +29,11 @@ private ServerMetrics parse(String json) throws Exception {
2829 + "\" n_prompt_tokens_processed\" :10,\" t_prompt_processing\" :5,"
2930 + "\" n_tokens_predicted\" :20,\" t_tokens_generation\" :8,"
3031 + "\" n_decode_total\" :300,\" n_busy_slots_total\" :4,\" n_tokens_max\" :4096,"
32+ // next_token is an ARRAY of one object — this mirrors llama.cpp's server_slot::to_json
33+ // at b9739, not a bare object; SlotMetrics must unwrap next_token[0].
3134 + "\" slots\" :[{\" id\" :0,\" n_ctx\" :4096,\" is_processing\" :true,"
3235 + "\" n_prompt_tokens\" :100,\" n_prompt_tokens_processed\" :20,"
33- + "\" n_prompt_tokens_cache\" :80,\" next_token\" :{\" n_decoded\" :7,\" n_remain\" :9}},"
36+ + "\" n_prompt_tokens_cache\" :80,\" next_token\" :[ {\" n_decoded\" :7,\" n_remain\" :9}] },"
3437 + "{\" id\" :1}]}" ;
3538
3639 @ Test
@@ -110,6 +113,16 @@ public void typedSlotMetricsExposeCacheCounts() throws Exception {
110113 assertEquals (9L , slot .getRemainingTokens ());
111114 assertEquals (0 , slot .asJson ().path ("id" ).asInt ());
112115 assertTrue (slot .toString ().contains ("n_prompt_tokens_cache" ));
116+
117+ // Assert against the SECOND slot (id=1, no is_processing) so the id and is_processing
118+ // accessors are pinned to non-default values a constant-return mutant cannot satisfy:
119+ // slot 0's id==0 and is_processing==true coincide with the mutated constants.
120+ SlotMetrics idle = m .getSlotMetrics ().get (1 );
121+ assertEquals (1 , idle .getId ());
122+ assertFalse (idle .isProcessing ());
123+ // next_token absent on the idle slot — accessors fall back to zero, not throw.
124+ assertEquals (0L , idle .getDecodedTokens ());
125+ assertEquals (0L , idle .getRemainingTokens ());
113126 }
114127
115128 @ Test
0 commit comments