83 lines
3.1 KiB
Go
83 lines
3.1 KiB
Go
package playground
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
|
|
"doormile/internal/testpg"
|
|
)
|
|
|
|
// The booking executors against a real Postgres. Skipped unless
|
|
// REGISTRY_TEST_DSN points at a THROWAWAY database (see
|
|
// internal/ai/registry/store_integration_test.go for how to start one).
|
|
//
|
|
// The table is a minimal stand-in for pickupbookings WITH personal columns,
|
|
// so the test proves the executors never select them.
|
|
func TestBookingExecutorsSelectNoPersonalColumns(t *testing.T) {
|
|
dsn := os.Getenv("REGISTRY_TEST_DSN")
|
|
if dsn == "" {
|
|
t.Skip("REGISTRY_TEST_DSN not set; skipping Postgres integration test")
|
|
}
|
|
db := testpg.Open(t, dsn, "aiplayground_test")
|
|
for _, q := range []string{
|
|
`DROP TABLE IF EXISTS pickupbookings`,
|
|
`CREATE TABLE pickupbookings (
|
|
bookingid serial PRIMARY KEY, bookingno text NOT NULL, tenantid int, status text,
|
|
pickuppincode text, deliverypincode text, deliverycity text,
|
|
pickuplatitude double precision, pickuplongitude double precision,
|
|
deliverylatitude double precision, deliverylongitude double precision,
|
|
assignedmileruserid int, routekm double precision, createdat timestamp,
|
|
pickupaddress text, deliveryaddress text, notes text)`,
|
|
`INSERT INTO pickupbookings (bookingno, status, pickuppincode, deliverypincode, deliverycity,
|
|
pickuplatitude, pickuplongitude, deliverylatitude, deliverylongitude, createdat, pickupaddress, deliveryaddress, notes)
|
|
VALUES ('DM-1', 'Created', '641001', '641002', 'Coimbatore', 11.01684, 76.95583, 11.0, 76.9, '2026-09-29 12:30', '12 MG Road', '4 Park St', 'call 9876543210'),
|
|
('DM-2', 'Cancelled', '641001', '641003', 'Coimbatore', 11.0, 76.9, 11.0, 76.9, '2026-09-29 12:40', 'x', 'y', 'z')`,
|
|
} {
|
|
if err := db.Exec(q).Error; err != nil {
|
|
t.Fatalf("setup: %v", err)
|
|
}
|
|
}
|
|
execs := Executors(db, nil)
|
|
if _, ok := execs["nearby_milers"]; ok {
|
|
t.Fatal("nearby_milers offered without Redis")
|
|
}
|
|
|
|
run := func(tool, input string) string {
|
|
out, err := execs[tool](context.Background(), json.RawMessage(input))
|
|
if err != nil {
|
|
t.Fatalf("%s: %v", tool, err)
|
|
}
|
|
b, _ := json.Marshal(Redact(out))
|
|
return string(b)
|
|
}
|
|
|
|
got := run("get_booking_cache", `{"booking_id":1}`)
|
|
for _, leaked := range []string{"MG Road", "Park St", "9876543210"} {
|
|
if strings.Contains(got, leaked) {
|
|
t.Fatalf("personal data %q in %s", leaked, got)
|
|
}
|
|
}
|
|
for _, want := range []string{`"found":true`, `"pickuplat":11.02`, `"createdat_ist":"2026-09-29 12:30"`, `"status":"Created"`} {
|
|
if !strings.Contains(got, want) {
|
|
t.Fatalf("missing %s in %s", want, got)
|
|
}
|
|
}
|
|
if !strings.Contains(run("get_booking_cache", `{"booking_id":99}`), `"found":false`) {
|
|
t.Fatal("missing booking should be found:false")
|
|
}
|
|
if _, err := execs["get_booking_cache"](context.Background(), json.RawMessage(`{}`)); err == nil {
|
|
t.Fatal("booking_id should be required")
|
|
}
|
|
|
|
scan := run("scan_bookings", `{"status":"Cancelled"}`)
|
|
if !strings.Contains(scan, `"count":1`) || !strings.Contains(scan, `"Cancelled":1`) {
|
|
t.Fatalf("scan = %s", scan)
|
|
}
|
|
if all := run("scan_bookings", `{"limit":500}`); !strings.Contains(all, `"count":2`) {
|
|
t.Fatalf("scan all = %s", all)
|
|
}
|
|
}
|