mirror of
https://github.com/instructkr/claude-code.git
synced 2026-04-06 03:08:48 +03:00
fix: cover merged prompt cache behavior
This commit is contained in:
@@ -500,15 +500,22 @@ fn stable_hash_bytes(bytes: &[u8]) -> u64 {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use std::sync::{Mutex, OnceLock};
|
||||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
detect_cache_break, read_json, request_hash_hex, sanitize_path_segment, PromptCache,
|
detect_cache_break, read_json, request_hash_hex, sanitize_path_segment, PromptCache,
|
||||||
PromptCacheConfig, PromptCachePaths, TrackedPromptState, REQUEST_FINGERPRINT_PREFIX,
|
PromptCacheConfig, PromptCachePaths, TrackedPromptState, REQUEST_FINGERPRINT_PREFIX,
|
||||||
};
|
};
|
||||||
use crate::test_env_lock;
|
|
||||||
use crate::types::{InputMessage, MessageRequest, MessageResponse, OutputContentBlock, Usage};
|
use crate::types::{InputMessage, MessageRequest, MessageResponse, OutputContentBlock, Usage};
|
||||||
|
|
||||||
|
fn test_env_lock() -> std::sync::MutexGuard<'static, ()> {
|
||||||
|
static LOCK: OnceLock<Mutex<()>> = OnceLock::new();
|
||||||
|
LOCK.get_or_init(|| Mutex::new(()))
|
||||||
|
.lock()
|
||||||
|
.unwrap_or_else(std::sync::PoisonError::into_inner)
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn path_builder_sanitizes_session_identifier() {
|
fn path_builder_sanitizes_session_identifier() {
|
||||||
let paths = PromptCachePaths::for_session("session:/with spaces");
|
let paths = PromptCachePaths::for_session("session:/with spaces");
|
||||||
|
|||||||
@@ -4,9 +4,10 @@ use std::sync::{Mutex as StdMutex, OnceLock};
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use api::{
|
use api::{
|
||||||
ApiClient, ApiError, AuthSource, ContentBlockDelta, ContentBlockDeltaEvent,
|
AnthropicClient, ApiClient, ApiError, AuthSource, ContentBlockDelta, ContentBlockDeltaEvent,
|
||||||
ContentBlockStartEvent, InputContentBlock, InputMessage, MessageDeltaEvent, MessageRequest,
|
ContentBlockStartEvent, InputContentBlock, InputMessage, MessageDeltaEvent, MessageRequest,
|
||||||
OutputContentBlock, ProviderClient, StreamEvent, ToolChoice, ToolDefinition,
|
OutputContentBlock, PromptCache, PromptCacheConfig, ProviderClient, StreamEvent, ToolChoice,
|
||||||
|
ToolDefinition,
|
||||||
};
|
};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use telemetry::{ClientIdentity, MemoryTelemetrySink, SessionTracer, TelemetryEvent};
|
use telemetry::{ClientIdentity, MemoryTelemetrySink, SessionTracer, TelemetryEvent};
|
||||||
@@ -562,10 +563,10 @@ async fn send_message_tracks_unexpected_prompt_cache_breaks() {
|
|||||||
let request = sample_request(false);
|
let request = sample_request(false);
|
||||||
let client = AnthropicClient::new("test-key")
|
let client = AnthropicClient::new("test-key")
|
||||||
.with_base_url(server.base_url())
|
.with_base_url(server.base_url())
|
||||||
.with_prompt_cache(PromptCache::with_config(api::PromptCacheConfig {
|
.with_prompt_cache(PromptCache::with_config(PromptCacheConfig {
|
||||||
session_id: "break-session".to_string(),
|
session_id: "break-session".to_string(),
|
||||||
completion_ttl: Duration::from_secs(0),
|
completion_ttl: Duration::from_secs(0),
|
||||||
..api::PromptCacheConfig::default()
|
..PromptCacheConfig::default()
|
||||||
}));
|
}));
|
||||||
|
|
||||||
client
|
client
|
||||||
|
|||||||
Reference in New Issue
Block a user