- Go model/IPC/FTS 通道/SQLite/API 写入(RFC3339 严判 400)+ Rust struct/schema/builder/6×读侧 col_str - recall 降档块在 MMR 之前(选择与展示共用同一套分数),过期 intention rerank 分置 -1 → 展示分 -0.445 - 关态 intentionExpired 恒 false ⇒ 降档块零赋值;AC2 HEAD vs 新版同库同 sidecar 现采基线 fresh 逐位一致 - 单测:关态逐位/开态下沉且在场/负分压过全部正常分/纯度(他类、未过期、空=永久) - 回滚:env 置 0 或 unset(每调用读 env,无需重启);磁盘列 additive 保留不删 t_88cc9cb8
62 lines
2.1 KiB
Go
62 lines
2.1 KiB
Go
package models
|
||
|
||
// intention_ttl_test.go — 2026-11-07 t_88cc9cb8 意图 TTL(category=intention + expires_at)
|
||
//
|
||
// 锁定两件事(回归闸门):
|
||
// 1. MemoryRecord / RecallResult 都携带 ExpiresAt 且 JSON 键名 = "expires_at"
|
||
// —— 键名是 IPC payload 与 Rust builder `r["expires_at"]` 的契约,改键名 = 静默丢字段。
|
||
// 2. omitempty:不传 = JSON 无此键 = 永久有效(关态/存量行为不变的序列化前提)。
|
||
|
||
import (
|
||
"encoding/json"
|
||
"strings"
|
||
"testing"
|
||
)
|
||
|
||
func TestExpiresAt_JSONKeyContract(t *testing.T) {
|
||
rec := MemoryRecord{ID: "m1", Category: "intention", ExpiresAt: "2026-11-08T00:00:00Z"}
|
||
b, err := json.Marshal(rec)
|
||
if err != nil {
|
||
t.Fatalf("marshal: %v", err)
|
||
}
|
||
s := string(b)
|
||
if !strings.Contains(s, `"expires_at":"2026-11-08T00:00:00Z"`) {
|
||
t.Fatalf("✗ MemoryRecord JSON 缺 expires_at 契约键:%s", s)
|
||
}
|
||
// 回环:反序列化读回
|
||
var got MemoryRecord
|
||
if err := json.Unmarshal(b, &got); err != nil {
|
||
t.Fatalf("unmarshal: %v", err)
|
||
}
|
||
if got.ExpiresAt != "2026-11-08T00:00:00Z" {
|
||
t.Fatalf("✗ 回环 ExpiresAt=%q", got.ExpiresAt)
|
||
}
|
||
}
|
||
|
||
func TestExpiresAt_OmitEmptyMeansPermanent(t *testing.T) {
|
||
// 不传 = JSON 不带键(Rust as_str().unwrap_or("") ⇒ 空 = 永久有效)
|
||
b, err := json.Marshal(MemoryRecord{ID: "m2", Category: "distilled"})
|
||
if err != nil {
|
||
t.Fatalf("marshal: %v", err)
|
||
}
|
||
if strings.Contains(string(b), "expires_at") {
|
||
t.Fatalf("✗ 未声明时不应输出 expires_at 键(存量兼容):%s", b)
|
||
}
|
||
}
|
||
|
||
func TestRecallResult_ExpiresAtPassthrough(t *testing.T) {
|
||
// RecallResult 直通("响应值==库值"判据的序列化前提)
|
||
b, err := json.Marshal(RecallResult{ID: "m3", ExpiresAt: "2026-12-01T00:00:00+08:00"})
|
||
if err != nil {
|
||
t.Fatalf("marshal: %v", err)
|
||
}
|
||
if !strings.Contains(string(b), `"expires_at":"2026-12-01T00:00:00+08:00"`) {
|
||
t.Fatalf("✗ RecallResult JSON 缺 expires_at:%s", b)
|
||
}
|
||
// 空 = omitempty 不输出(关态响应逐字节兼容)
|
||
b2, _ := json.Marshal(RecallResult{ID: "m4"})
|
||
if strings.Contains(string(b2), "expires_at") {
|
||
t.Fatalf("✗ 空 ExpiresAt 不应输出键(响应兼容):%s", b2)
|
||
}
|
||
}
|