Feat v0.5.1 chat core (#31)
All checks were successful
All checks were successful
Co-authored-by: Jeffrey Smith <jasafpro@gmail.com> Co-committed-by: Jeffrey Smith <jasafpro@gmail.com>
This commit was merged in pull request #31.
This commit is contained in:
@@ -226,6 +226,104 @@ func TestDBViewRejectsUnknownView(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// ── before / after range parameters ──────────
|
||||
|
||||
func TestDBQueryBefore(t *testing.T) {
|
||||
db, cfg := newTestDB(t)
|
||||
db.Exec(`INSERT INTO ext_test_ext_logs (id, message, created_at) VALUES ('a', 'old', '2026-01-01T00:00:00Z')`)
|
||||
db.Exec(`INSERT INTO ext_test_ext_logs (id, message, created_at) VALUES ('b', 'mid', '2026-02-01T00:00:00Z')`)
|
||||
db.Exec(`INSERT INTO ext_test_ext_logs (id, message, created_at) VALUES ('c', 'new', '2026-03-01T00:00:00Z')`)
|
||||
|
||||
result, err := execScript(t, cfg, `rows = db.query("logs", before={"created_at": "2026-02-15T00:00:00Z"}, order="created_at")`)
|
||||
if err != nil {
|
||||
t.Fatalf("script error: %v", err)
|
||||
}
|
||||
rowsStr := result.Globals["rows"].String()
|
||||
if !strings.Contains(rowsStr, "old") || !strings.Contains(rowsStr, "mid") {
|
||||
t.Errorf("expected old and mid rows, got: %s", rowsStr)
|
||||
}
|
||||
if strings.Contains(rowsStr, "new") {
|
||||
t.Errorf("unexpected 'new' row in before results: %s", rowsStr)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDBQueryAfter(t *testing.T) {
|
||||
db, cfg := newTestDB(t)
|
||||
db.Exec(`INSERT INTO ext_test_ext_logs (id, message, created_at) VALUES ('a', 'old', '2026-01-01T00:00:00Z')`)
|
||||
db.Exec(`INSERT INTO ext_test_ext_logs (id, message, created_at) VALUES ('b', 'mid', '2026-02-01T00:00:00Z')`)
|
||||
db.Exec(`INSERT INTO ext_test_ext_logs (id, message, created_at) VALUES ('c', 'new', '2026-03-01T00:00:00Z')`)
|
||||
|
||||
result, err := execScript(t, cfg, `rows = db.query("logs", after={"created_at": "2026-02-01T00:00:00Z"}, order="created_at")`)
|
||||
if err != nil {
|
||||
t.Fatalf("script error: %v", err)
|
||||
}
|
||||
rowsStr := result.Globals["rows"].String()
|
||||
if !strings.Contains(rowsStr, "new") {
|
||||
t.Errorf("expected 'new' row, got: %s", rowsStr)
|
||||
}
|
||||
if strings.Contains(rowsStr, "old") || strings.Contains(rowsStr, "mid") {
|
||||
t.Errorf("unexpected old/mid rows in after results: %s", rowsStr)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDBQueryBeforeWithFilters(t *testing.T) {
|
||||
db, cfg := newTestDB(t)
|
||||
db.Exec(`INSERT INTO ext_test_ext_logs (id, message, user_id, created_at) VALUES ('a', 'u1-old', 'u1', '2026-01-01T00:00:00Z')`)
|
||||
db.Exec(`INSERT INTO ext_test_ext_logs (id, message, user_id, created_at) VALUES ('b', 'u1-new', 'u1', '2026-03-01T00:00:00Z')`)
|
||||
db.Exec(`INSERT INTO ext_test_ext_logs (id, message, user_id, created_at) VALUES ('c', 'u2-old', 'u2', '2026-01-01T00:00:00Z')`)
|
||||
|
||||
result, err := execScript(t, cfg, `rows = db.query("logs", filters={"user_id": "u1"}, before={"created_at": "2026-02-01T00:00:00Z"})`)
|
||||
if err != nil {
|
||||
t.Fatalf("script error: %v", err)
|
||||
}
|
||||
rowsStr := result.Globals["rows"].String()
|
||||
if !strings.Contains(rowsStr, "u1-old") {
|
||||
t.Errorf("expected u1-old, got: %s", rowsStr)
|
||||
}
|
||||
if strings.Contains(rowsStr, "u1-new") || strings.Contains(rowsStr, "u2-old") {
|
||||
t.Errorf("unexpected rows: %s", rowsStr)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDBQueryBeforeAfterCombined(t *testing.T) {
|
||||
db, cfg := newTestDB(t)
|
||||
db.Exec(`INSERT INTO ext_test_ext_logs (id, message, created_at) VALUES ('a', 'old', '2026-01-01T00:00:00Z')`)
|
||||
db.Exec(`INSERT INTO ext_test_ext_logs (id, message, created_at) VALUES ('b', 'mid', '2026-02-01T00:00:00Z')`)
|
||||
db.Exec(`INSERT INTO ext_test_ext_logs (id, message, created_at) VALUES ('c', 'new', '2026-03-01T00:00:00Z')`)
|
||||
|
||||
result, err := execScript(t, cfg, `rows = db.query("logs", after={"created_at": "2026-01-15T00:00:00Z"}, before={"created_at": "2026-02-15T00:00:00Z"})`)
|
||||
if err != nil {
|
||||
t.Fatalf("script error: %v", err)
|
||||
}
|
||||
rowsStr := result.Globals["rows"].String()
|
||||
if !strings.Contains(rowsStr, "mid") {
|
||||
t.Errorf("expected mid row, got: %s", rowsStr)
|
||||
}
|
||||
if strings.Contains(rowsStr, "old") || strings.Contains(rowsStr, "new") {
|
||||
t.Errorf("unexpected old/new rows: %s", rowsStr)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDBQueryBeforeEmptyDict(t *testing.T) {
|
||||
_, cfg := newTestDB(t)
|
||||
// Empty before dict should be a no-op (same as no before)
|
||||
_, err := execScript(t, cfg, `rows = db.query("logs", before={})`)
|
||||
if err != nil {
|
||||
t.Fatalf("empty before dict should not error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDBQueryBeforeInvalidColumn(t *testing.T) {
|
||||
_, cfg := newTestDB(t)
|
||||
_, err := execScript(t, cfg, `rows = db.query("logs", before={"bad name": "x"})`)
|
||||
if err == nil {
|
||||
t.Fatal("expected error for invalid column name in before")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "invalid column name") {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// ── namespace isolation ──────────────────────
|
||||
|
||||
func TestDBQueryRejectsOtherExtensionTable(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user