Files
sausheong b1bdc0ca51 Add data-agent example: data.gov.sg open-data assistant
Five tools covering Singapore's open-data APIs (no API key required):
- datagov_weather: 2-hour forecast by area (NEA)
- datagov_air_quality: PSI 24hr + PM2.5 1hr by region
- datagov_environment: temperature, humidity, rainfall, UV, wind
- datagov_search_datasets: catalog search via api-production v2
- datagov_query_dataset: row-level CKAN datastore_search

Mirrors the lta-agent composition (BYO tools, in-memory session,
no Skills/Memory/Subagents) — second proof that the harness API
isn't accidentally Felix-shaped. Live endpoint smoke test gated
behind '-tags=live' so default 'go test ./...' stays offline.
2026-05-07 17:00:38 +08:00

103 lines
2.9 KiB
Go

// Live integration smoke test against data.gov.sg endpoints.
// Skipped by default; run with: go test -tags=live ./examples/data-agent/
//go:build live
package main
import (
"context"
"encoding/json"
"strings"
"testing"
)
func TestWeather_Live(t *testing.T) {
ctx := context.Background()
out, err := (&WeatherForecastTool{}).Execute(ctx, json.RawMessage(`{"area":"Bedok"}`))
if err != nil {
t.Fatal(err)
}
if out.Error != "" {
t.Fatalf("tool error: %s", out.Error)
}
if !strings.Contains(out.Output, "Bedok") {
t.Fatalf("expected Bedok in output, got: %s", out.Output)
}
}
func TestAirQuality_Live(t *testing.T) {
ctx := context.Background()
out, err := (&AirQualityTool{}).Execute(ctx, json.RawMessage(`{"region":"west"}`))
if err != nil {
t.Fatal(err)
}
if out.Error != "" {
t.Fatalf("tool error: %s", out.Error)
}
if !strings.Contains(out.Output, "west") || !strings.Contains(out.Output, "psi_24hr") {
t.Fatalf("missing expected keys in output: %s", out.Output)
}
}
func TestEnvironment_StationReading_Live(t *testing.T) {
ctx := context.Background()
for _, kind := range []string{"air-temperature", "relative-humidity", "rainfall", "wind-speed", "wind-direction"} {
t.Run(kind, func(t *testing.T) {
in, _ := json.Marshal(map[string]string{"kind": kind})
out, err := (&EnvironmentReadingTool{}).Execute(ctx, in)
if err != nil {
t.Fatal(err)
}
if out.Error != "" {
t.Fatalf("tool error: %s", out.Error)
}
if !strings.Contains(out.Output, "station_id") {
t.Fatalf("expected station_id in output for %s, got: %s", kind, out.Output)
}
})
}
}
func TestEnvironment_UV_Live(t *testing.T) {
ctx := context.Background()
out, err := (&EnvironmentReadingTool{}).Execute(context.Background(), json.RawMessage(`{"kind":"uv"}`))
_ = ctx
if err != nil {
t.Fatal(err)
}
if out.Error != "" {
t.Fatalf("tool error: %s", out.Error)
}
if !strings.Contains(out.Output, "hourly") {
t.Fatalf("expected 'hourly' in UV output, got: %s", out.Output)
}
}
func TestDatasetSearch_Live(t *testing.T) {
out, err := (&DatasetSearchTool{}).Execute(context.Background(), json.RawMessage(`{"query":"hdb resale"}`))
if err != nil {
t.Fatal(err)
}
if out.Error != "" {
t.Fatalf("tool error: %s", out.Error)
}
if !strings.Contains(out.Output, "dataset_id") {
t.Fatalf("expected dataset_id in search output: %s", out.Output)
}
}
func TestDatasetQuery_Live(t *testing.T) {
// Stable HDB resale dataset id used by data.gov.sg docs/examples.
out, err := (&DatasetQueryTool{}).Execute(context.Background(),
json.RawMessage(`{"dataset_id":"d_8b84c4ee58e3cfc0ece0d773c8ca6abc","limit":2}`))
if err != nil {
t.Fatal(err)
}
if out.Error != "" {
t.Fatalf("tool error: %s", out.Error)
}
if !strings.Contains(out.Output, "records") || !strings.Contains(out.Output, "fields") {
t.Fatalf("expected records+fields in output: %s", out.Output)
}
}