feat(chat,proxy): add @schedule mentions and localize proxy/schedule errors

- Support @schedule mentions in DB search, server mention resolution, and frontend mention parsing/i18n.
- Return structured product error codes for proxy route validation and localize them in proxy/schedule UI.
- Preserve unchanged proxy routes when rescheduling an existing schedule whose pool has no active nodes.
This commit is contained in:
ji ruo committed 2026-12-03 14:15:52 +08:00
1 parent 8568c41528
commit e6241dda09
15 files changed
+312 -49

No files matched your search

+44
View File
@@ -12,6 +12,21 @@ import (
"github.com/Autumn-27/artex/db"
)
func TestChatMentionScheduleParsing(t *testing.T) {
refs, err := parseChatMentions("请修改 @[计划任务#3 夜间扫描] 和 @[schedule#3 重复] 以及 @[schedule#9 应急复测] 和 @[计划#12 周末巡检]")
if err != nil {
t.Fatalf("parseChatMentions error: %v", err)
}
if len(refs) != 3 {
t.Fatalf("expected 3 deduplicated schedule refs, got %+v", refs)
}
for i, wantID := range []int64{3, 9, 12} {
if refs[i].Kind != "schedule" || refs[i].ID != wantID {
t.Fatalf("ref[%d] = %+v, want schedule #%d", i, refs[i], wantID)
}
}
}
func TestChatScheduleToolsAndServerClock(t *testing.T) {
dsn := strings.TrimSpace(os.Getenv("ARTEX_PG_DSN"))
@@ -95,6 +110,31 @@ func TestChatScheduleToolsAndServerClock(t *testing.T) {
t.Fatalf("update_task_schedule failed: err=%v res=%+v", err, updRes)
}
updText := ""
// 2b. Search schedule mentions via DB and compose @[schedule#ID] snapshot.
page, err := pg.SearchChatMentionsPage(context.Background(), "schedule", "工作日", "")
if err != nil {
t.Fatalf("SearchChatMentionsPage(schedule): %v", err)
}
foundMention := false
for _, item := range page.Items {
if item.Kind == "schedule" && item.ID == schedID {
foundMention = true
if !strings.Contains(item.Description, "18:00-23:45") {
t.Fatalf("expected schedule time window in mention description, got %+v", item)
}
}
}
if !foundMention {
t.Fatalf("expected schedule #%d in SearchChatMentionsPage results, got %+v", schedID, page.Items)
}
injected, err := composeChatMentionMessage(pg, fmt.Sprintf("把 @[schedule#%d 工作日夜间扫描] 改成 23:45 结束", schedID))
if err != nil {
t.Fatalf("composeChatMentionMessage(schedule): %v", err)
}
if !strings.Contains(injected, "工作日夜间扫描") || !strings.Contains(injected, `"proxy_mode":"pool"`) || !strings.Contains(injected, `"server_time"`) {
t.Fatalf("unexpected injected schedule snapshot: %s", injected)
}
for _, b := range updRes.Content {
updText += b.Text
}
@@ -122,4 +162,8 @@ func TestChatScheduleToolsAndServerClock(t *testing.T) {
if err != nil || delRes.IsError {
t.Fatalf("delete_task_schedule failed: err=%v res=%+v", err, delRes)
}
// Verify deleted schedule mention returns a clean input error.
if _, err := composeChatMentionMessage(pg, fmt.Sprintf("查看 @[schedule#%d 已删]", schedID)); err == nil {
t.Fatalf("expected error for deleted schedule mention")
}
}