fix: restore go compatibility for runtime models

This commit is contained in:
Yoilun
2026-05-25 18:32:10 +08:00
parent d573bde194
commit bb8b8fe732
11 changed files with 262 additions and 60 deletions

View File

@@ -1,6 +1,7 @@
package server
import (
"database/sql"
"encoding/json"
"net/http"
"net/http/httptest"
@@ -9,6 +10,8 @@ import (
"testing"
"codex-agent-manager/internal/app"
_ "modernc.org/sqlite"
)
func TestAgentsEndpointReturnsAgentItems(t *testing.T) {
@@ -117,6 +120,48 @@ func TestRuntimeThreadsEndpointReturnsEmptyWhenSQLiteMissing(t *testing.T) {
}
}
func TestRuntimeThreadsEndpointReturnsPartialSourceEvidence(t *testing.T) {
root := t.TempDir()
db, err := sql.Open("sqlite", filepath.Join(root, "goals_1.sqlite"))
if err != nil {
t.Fatal(err)
}
defer db.Close()
if _, err := db.Exec(`CREATE TABLE thread_goals (thread_id TEXT, goal TEXT, status TEXT, updated_at TEXT)`); err != nil {
t.Fatal(err)
}
req := httptest.NewRequest(http.MethodGet, "/api/runtime/threads", nil)
rec := httptest.NewRecorder()
New(app.Config{CodexHome: root, HTTPAddr: "127.0.0.1:0"}).ServeHTTP(rec, req)
if rec.Code != http.StatusOK {
t.Fatalf("status = %d, body = %s", rec.Code, rec.Body.String())
}
var body struct {
Source struct {
Kind string `json:"kind"`
Confidence string `json:"confidence"`
} `json:"source"`
Sources map[string]struct {
Kind string `json:"kind"`
Confidence string `json:"confidence"`
} `json:"sources"`
}
if err := json.Unmarshal(rec.Body.Bytes(), &body); err != nil {
t.Fatalf("invalid json: %v", err)
}
if body.Source.Kind != "sqlite_partial" || body.Source.Confidence != "partial" {
t.Fatalf("unexpected aggregate source: %#v", body.Source)
}
if body.Sources["state"].Kind != "sqlite_missing" || body.Sources["state"].Confidence != "low" {
t.Fatalf("unexpected state source: %#v", body.Sources["state"])
}
if body.Sources["goals"].Kind != "sqlite_readonly" || body.Sources["goals"].Confidence != "high" {
t.Fatalf("unexpected goals source: %#v", body.Sources["goals"])
}
}
func TestWorkflowEventsEndpointReturnsEvents(t *testing.T) {
root := t.TempDir()
if err := os.WriteFile(filepath.Join(root, "task_plan.md"), []byte("| 3 | in_progress | Runtime model |\n"), 0o644); err != nil {