package timeagent import ( "strings" "testing" "time" ) func TestResolveBuildsCalendarRanges(t *testing.T) { loc := time.FixedZone("CST", 8*60*60) ctx := Resolve(time.Date(2026, 6, 10, 13, 14, 15, 0, loc)) if got := FormatSQLRange(ctx.Today); got != "start=2026-06-10 00:00:00, end_exclusive=2026-06-11 00:00:00" { t.Fatalf("today = %s", got) } if got := FormatSQLRange(ctx.ThisMonth); got != "start=2026-06-01 00:00:00, end_exclusive=2026-07-01 00:00:00" { t.Fatalf("this month = %s", got) } if got := FormatSQLRange(ctx.ThisWeek); got != "start=2026-06-08 00:00:00, end_exclusive=2026-06-15 00:00:00" { t.Fatalf("this week = %s", got) } } func TestBuildContextIncludesSQLHints(t *testing.T) { ctx := Resolve(time.Date(2026, 6, 10, 13, 14, 15, 0, time.UTC)) text := BuildContext(ctx, "需要日期范围") for _, want := range []string{"时间工具结果", "本月", "start=", "end_exclusive=", "星期三", "星期一", "半开区间", "需要日期范围"} { if !strings.Contains(text, want) { t.Fatalf("context missing %q:\n%s", want, text) } } } func TestToolDefinitionAndExecuteTool(t *testing.T) { definition := ToolDefinition("custom description") if definition.Function == nil || definition.Function.Name != ToolName || definition.Function.Description != "custom description" { t.Fatalf("unexpected definition: %#v", definition) } text, err := ExecuteTool(`{"reason":"测试原因"}`, time.Date(2026, 6, 10, 13, 14, 15, 0, time.UTC)) if err != nil { t.Fatal(err) } for _, want := range []string{"时间工具结果", "2026-06-10", "星期三", "本月", "start=", "end_exclusive=", "测试原因"} { if !strings.Contains(text, want) { t.Fatalf("tool result missing %q:\n%s", want, text) } } }