feat(runtime+admin): A2 LLM异步提取接线 + A4 Tracing接线 + A6通知后端聚合
A2 异步记忆提取:
- loop/memory.go: asyncExtractor接口(ExtractAsync)+extractMemoryAsync(60s超时,WithOutCancel,dispatch即返回,后台落库,失败仅Warn)+persistMemories共用
- run.go 三个回合落定点改异步提取; 删除run.go逐步提取(design/03'每轮后', 避免多轮工具N次LLM调用/重复写)
- cmd/cyrene/extractor.go buildMemoryExtractor: llmGroupUsable为真→LLMExtractor, 否则回落ManualExtractor(日志说明); keylessEndpoint放行loopback/私网
A4 可观测性 Tracing:
- cmd/cyrene/observability.go: newAppTraceWriter+traceFanout(多sink)+gatewaySpanSink(走gw.ObserveSpan,喂环形缓冲+LLM/subagent指标)
- wire.go 注入; 未改trace/gateway数据结构
A6 通知后端:
- internal/services/gateway/notifications.go(311行): GET /admin/notifications?type=&before=&limit= (adminAuth)
- 聚合已有源(obs.audit SQLite + s.backthink), createdAt倒序, id=source:id; 类型派生(channel/system/audit/backthink); 无新建表/无新Deps/wire零改动
- 诚实: backthink仅shouldPush计, 未注入源为空, 报错500, 未读游标后置
- 契约与前端Y一致: {id,type,title,body,source,createdAt}, before含游标(<=), type未知400
- Docs/api-client v0.33
全仓 build/vet/test绿(56包)+win/darwin/linux-arm64交叉编译绿; 新增测试(memory_async/extractor/observability/notifications)
This commit is contained in:
1 parent
34c8cc4dca
commit
153a9d6211
12 files changed
+1427
-11
No files matched your search
@@ -0,0 +1,79 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/config"
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/memory"
|
||||
modelpkg "git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/model"
|
||||
)
|
||||
|
||||
// testRuntimeLLM builds a provider stack from env alone (the pointed-at
|
||||
// models.json does not exist), so a test controls the active group through the
|
||||
// flat LLM config exactly as a keyless .env boot would.
|
||||
func testRuntimeLLM(t *testing.T, env config.LLMConfig) *modelpkg.RuntimeLLM {
|
||||
t.Helper()
|
||||
return modelpkg.NewRuntimeLLM(filepath.Join(t.TempDir(), "models.json"), env, testLog())
|
||||
}
|
||||
|
||||
// TestBuildMemoryExtractor_LLMWhenCredentials proves a configured provider group
|
||||
// selects the LLM extractor (design/03 §1).
|
||||
func TestBuildMemoryExtractor_LLMWhenCredentials(t *testing.T) {
|
||||
t.Parallel()
|
||||
a := &app{
|
||||
log: testLog(),
|
||||
llm: testRuntimeLLM(t, config.LLMConfig{
|
||||
BaseURL: "https://api.example.com/v1",
|
||||
APIKey: "sk-test",
|
||||
Model: "gpt-4o-mini",
|
||||
}),
|
||||
}
|
||||
if _, ok := a.buildMemoryExtractor("persona-a").(*memory.LLMExtractor); !ok {
|
||||
t.Fatalf("extractor = %T, want *memory.LLMExtractor (credentials configured)", a.buildMemoryExtractor("persona-a"))
|
||||
}
|
||||
}
|
||||
|
||||
// TestBuildMemoryExtractor_ManualWhenNoCredentials proves the keyless fallback: a
|
||||
// boot without an API key (and without a local endpoint) keeps the deterministic
|
||||
// ManualExtractor instead of firing a doomed model call on every turn.
|
||||
func TestBuildMemoryExtractor_ManualWhenNoCredentials(t *testing.T) {
|
||||
t.Parallel()
|
||||
a := &app{log: testLog(), llm: testRuntimeLLM(t, config.LLMConfig{})}
|
||||
if _, ok := a.buildMemoryExtractor("persona-a").(*memory.ManualExtractor); !ok {
|
||||
t.Fatalf("extractor = %T, want *memory.ManualExtractor (no usable llm group)", a.buildMemoryExtractor("persona-a"))
|
||||
}
|
||||
|
||||
bare := &app{log: testLog()}
|
||||
if _, ok := bare.buildMemoryExtractor("persona-a").(*memory.ManualExtractor); !ok {
|
||||
t.Fatalf("extractor = %T, want *memory.ManualExtractor (nil provider stack)", bare.buildMemoryExtractor("persona-a"))
|
||||
}
|
||||
}
|
||||
|
||||
// TestLLMGroupUsable_KeylessLocalEndpoint locks the ollama-style case: a local
|
||||
// OpenAI-compatible server needs no API key, so extraction stays LLM-backed.
|
||||
func TestLLMGroupUsable_KeylessLocalEndpoint(t *testing.T) {
|
||||
t.Parallel()
|
||||
cases := []struct {
|
||||
name string
|
||||
env config.LLMConfig
|
||||
ready bool
|
||||
}{
|
||||
{name: "api key", env: config.LLMConfig{BaseURL: "https://api.example.com/v1", APIKey: "sk", Model: "m"}, ready: true},
|
||||
{name: "loopback keyless", env: config.LLMConfig{BaseURL: "http://127.0.0.1:11434/v1", Model: "llama3"}, ready: true},
|
||||
{name: "localhost keyless", env: config.LLMConfig{BaseURL: "http://localhost:1234/v1", Model: "m"}, ready: true},
|
||||
{name: "private keyless", env: config.LLMConfig{BaseURL: "http://192.168.1.20:11434/v1", Model: "m"}, ready: true},
|
||||
{name: "remote keyless", env: config.LLMConfig{BaseURL: "https://api.example.com/v1", Model: "m"}, ready: false},
|
||||
{name: "no model", env: config.LLMConfig{BaseURL: "https://api.example.com/v1", APIKey: "sk"}, ready: false},
|
||||
{name: "no base url", env: config.LLMConfig{APIKey: "sk", Model: "m"}, ready: false},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
tc := tc
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
if got := llmGroupUsable(testRuntimeLLM(t, tc.env)); got != tc.ready {
|
||||
t.Fatalf("llmGroupUsable = %v, want %v", got, tc.ready)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user