testutil

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package testutil 提供 N07 缓存命中率 E2E 的 Mock DeepSeek 工具。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LongestCommonPrefix

func LongestCommonPrefix(a, b string) int

LongestCommonPrefix 返回两个字符串的最长公共前缀长度。

Types

type MockChatRequest

type MockChatRequest struct {
	Messages []struct {
		Role    string `json:"role"`
		Content any    `json:"content"`
	} `json:"messages"`
}

MockChatRequest 是进入 mock 的请求(我们只关心 prompt 文本)。

type PrefixCacheSimulator

type PrefixCacheSimulator struct {
	// contains filtered or unexported fields
}

PrefixCacheSimulator 模拟 DeepSeek prefix cache:

  • 记录每轮 prompt 文本;
  • 命中 = 当前 prompt 与上一轮 prompt 的最长公共前缀占比(字符比);
  • 稳定循环命中率高;切 preset 后首轮低、随后攀升(与官方 KV cache 行为一致)。

func NewDeepSeekMock

func NewDeepSeekMock() (*httptest.Server, *PrefixCacheSimulator)

NewDeepSeekMock 创建一个 DeepSeek 模拟服务器,返回每次请求解析出的 usage 缓存字段。 hitRatio 由 PrefixCacheSimulator 每请求推导。

func NewPrefixCacheSimulator

func NewPrefixCacheSimulator() *PrefixCacheSimulator

NewPrefixCacheSimulator 创建模拟器。

func (*PrefixCacheSimulator) Simulate

func (s *PrefixCacheSimulator) Simulate(prompt string) (hit, miss int)

Simulate 对一次请求计算命中/未命中所占 token。 返回 (hitTokens, missTokens)。命中按与上次 prompt 的公共前缀占比;失配则全 miss。

type PrefixHash

type PrefixHash struct {
	// PromptText 拼接后的 prompt 文本。
	PromptText string
	// Tokens 估 token 数(chars/4)。
	Tokens int
}

PrefixHash 是 prompt 前缀指纹,用于缓存命中判定。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL