✨ feat(agent): 重构 Agent 分层并修复普通聊天助手消息未写入 Redis 的问题 🔧 按职责重构 backend/agent 目录为 route/chat/quicknote 三层结构 🔄 将随口记链路拆分为 graph/nodes/tool/state/prompt,其中 graph 仅负责连线 🏃 新增 quicknote runner(方法引用)来收口节点依赖,提升代码可读性 🔀 将控制码分流逻辑抽离到 agent/route,服务层改为薄封装调用 📚 更新相关 README 与测试引用路径,保持原业务逻辑不变 🐛 修复普通聊天链路遗漏 assistant 写入 Redis 的问题(确保 MySQL 和 Redis 的口径一致)
124 lines
3.4 KiB
Go
124 lines
3.4 KiB
Go
package quicknote
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestParseOptionalDeadlineWithNow_Absolute(t *testing.T) {
|
|
loc := quickNoteLocation()
|
|
now := time.Date(2026, 3, 12, 10, 15, 0, 0, loc)
|
|
|
|
deadline, err := parseOptionalDeadlineWithNow("2026-03-20 18:30", now)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if deadline == nil {
|
|
t.Fatalf("deadline should not be nil")
|
|
}
|
|
|
|
want := time.Date(2026, 3, 20, 18, 30, 0, 0, loc)
|
|
if !deadline.Equal(want) {
|
|
t.Fatalf("unexpected deadline, got=%s want=%s", deadline.Format(time.RFC3339), want.Format(time.RFC3339))
|
|
}
|
|
}
|
|
|
|
func TestParseOptionalDeadlineWithNow_RelativeTomorrowWithoutClock(t *testing.T) {
|
|
loc := quickNoteLocation()
|
|
now := time.Date(2026, 3, 12, 10, 15, 0, 0, loc)
|
|
|
|
deadline, err := parseOptionalDeadlineWithNow("明天交计网实验报告", now)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if deadline == nil {
|
|
t.Fatalf("deadline should not be nil")
|
|
}
|
|
|
|
want := time.Date(2026, 3, 13, 23, 59, 0, 0, loc)
|
|
if !deadline.Equal(want) {
|
|
t.Fatalf("unexpected deadline, got=%s want=%s", deadline.Format(time.RFC3339), want.Format(time.RFC3339))
|
|
}
|
|
}
|
|
|
|
func TestParseOptionalDeadlineWithNow_RelativeTomorrowWithClock(t *testing.T) {
|
|
loc := quickNoteLocation()
|
|
now := time.Date(2026, 3, 12, 10, 15, 0, 0, loc)
|
|
|
|
deadline, err := parseOptionalDeadlineWithNow("明天下午3点交计网实验报告", now)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if deadline == nil {
|
|
t.Fatalf("deadline should not be nil")
|
|
}
|
|
|
|
want := time.Date(2026, 3, 13, 15, 0, 0, 0, loc)
|
|
if !deadline.Equal(want) {
|
|
t.Fatalf("unexpected deadline, got=%s want=%s", deadline.Format(time.RFC3339), want.Format(time.RFC3339))
|
|
}
|
|
}
|
|
|
|
func TestParseOptionalDeadlineWithNow_RelativeWeekday(t *testing.T) {
|
|
loc := quickNoteLocation()
|
|
now := time.Date(2026, 3, 12, 10, 15, 0, 0, loc) // 周四
|
|
|
|
deadline, err := parseOptionalDeadlineWithNow("下周一上午9点开组会", now)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if deadline == nil {
|
|
t.Fatalf("deadline should not be nil")
|
|
}
|
|
|
|
want := time.Date(2026, 3, 16, 9, 0, 0, 0, loc)
|
|
if !deadline.Equal(want) {
|
|
t.Fatalf("unexpected deadline, got=%s want=%s", deadline.Format(time.RFC3339), want.Format(time.RFC3339))
|
|
}
|
|
}
|
|
|
|
func TestParseOptionalDeadlineFromUserInput_NoHint(t *testing.T) {
|
|
loc := quickNoteLocation()
|
|
now := time.Date(2026, 3, 12, 10, 15, 0, 0, loc)
|
|
|
|
deadline, hasHint, err := parseOptionalDeadlineFromUserInput("帮我记一下要复习计网", now)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if hasHint {
|
|
t.Fatalf("expected no time hint")
|
|
}
|
|
if deadline != nil {
|
|
t.Fatalf("deadline should be nil when no time hint")
|
|
}
|
|
}
|
|
|
|
func TestParseOptionalDeadlineFromUserInput_InvalidDate(t *testing.T) {
|
|
loc := quickNoteLocation()
|
|
now := time.Date(2026, 3, 12, 10, 15, 0, 0, loc)
|
|
|
|
deadline, hasHint, err := parseOptionalDeadlineFromUserInput("2026-13-45 25:99 交实验", now)
|
|
if err == nil {
|
|
t.Fatalf("expected error but got nil")
|
|
}
|
|
if !hasHint {
|
|
t.Fatalf("expected hasHint=true")
|
|
}
|
|
if deadline != nil {
|
|
t.Fatalf("deadline should be nil for invalid date")
|
|
}
|
|
}
|
|
|
|
func TestParseOptionalDeadlineWithNow_Invalid(t *testing.T) {
|
|
loc := quickNoteLocation()
|
|
now := time.Date(2026, 3, 12, 10, 15, 0, 0, loc)
|
|
|
|
deadline, err := parseOptionalDeadlineWithNow("记得尽快处理", now)
|
|
if err == nil {
|
|
t.Fatalf("expected error but got nil")
|
|
}
|
|
if deadline != nil {
|
|
t.Fatalf("deadline should be nil for invalid input")
|
|
}
|
|
}
|