RC-1
This commit is contained in:
@@ -89,3 +89,90 @@ func TestSitemapIndexCollectsChildURLs(t *testing.T) {
|
||||
t.Fatalf("unexpected sitemap items: %+v", items)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunnerStatusDoesNotTreatCachedConfigAsLiveConnection(t *testing.T) {
|
||||
r := &Runner{
|
||||
cfg: RunnerConfig{BrainURL: "http://127.0.0.1:8091", AgentID: "agent-test", Version: "test"},
|
||||
remote: RemoteConfig{IssuedAt: time.Now().UTC(), Tasks: []Task{{ID: "cached-task"}}},
|
||||
diag: runnerDiagnostics{ConfigSource: "cache", CacheLoadedAt: time.Now().UTC()},
|
||||
}
|
||||
st := r.Status()
|
||||
if st["brain_connected"] != false {
|
||||
t.Fatalf("cached config must not be reported as live connection: %+v", st)
|
||||
}
|
||||
if st["connection_state"] != "cached_config_only" {
|
||||
t.Fatalf("unexpected state: %+v", st)
|
||||
}
|
||||
if st["brain_url_warning"] == "" {
|
||||
t.Fatalf("expected loopback warning: %+v", st)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunnerStatusReportsFreshBrainConnection(t *testing.T) {
|
||||
now := time.Now().UTC()
|
||||
r := &Runner{
|
||||
cfg: RunnerConfig{BrainURL: "http://brain:8090", AgentID: "agent-test", Version: "test"},
|
||||
remote: RemoteConfig{IssuedAt: now},
|
||||
diag: runnerDiagnostics{ConfigSource: "brain", LastConfigAttemptAt: now.Add(-time.Second), LastConfigSuccessAt: now},
|
||||
}
|
||||
st := r.Status()
|
||||
if st["brain_connected"] != true || st["connection_state"] != "connected" {
|
||||
t.Fatalf("expected live connection: %+v", st)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunnerStatusAcceptsConnectedLoopbackForNativeTest(t *testing.T) {
|
||||
now := time.Now().UTC()
|
||||
r := &Runner{
|
||||
cfg: RunnerConfig{BrainURL: "http://127.0.0.1:8091", AgentID: "agent-test", Version: "test"},
|
||||
remote: RemoteConfig{IssuedAt: now},
|
||||
diag: runnerDiagnostics{ConfigSource: "brain", LastConfigSuccessAt: now, LastHeartbeatSuccess: now},
|
||||
}
|
||||
st := r.Status()
|
||||
if st["brain_connected"] != true {
|
||||
t.Fatalf("expected connected loopback to be accepted: %+v", st)
|
||||
}
|
||||
if st["brain_url_warning"] != "" {
|
||||
t.Fatalf("connected native loopback must not be warned as broken: %+v", st)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnsureInboxClassifierVersionRequeuesArchivedOnce(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
store, err := OpenStore(t.TempDir())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer store.Close()
|
||||
agent, _, err := store.CreateAgent(ctx, "agent-a", "Agent A")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
task, err := store.UpsertTask(ctx, Task{ID: "task-a", AgentID: agent.ID, Name: "Security", Type: "rss", URL: "https://example.org/feed", Enabled: true, PollInterval: "1h", MaxItems: 10})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = store.Ingest(ctx, agent.ID, task.ID, []Document{{URL: "https://example.org/a", Title: "Security update", Text: "Dies ist ein ausreichend langer Sicherheitsartikel mit mehreren Details, damit das Dokument in die Source Inbox aufgenommen und klassifiziert werden kann."}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
claimed, err := store.ClaimInbox(ctx, 1)
|
||||
if err != nil || len(claimed) != 1 {
|
||||
t.Fatalf("claim failed: %#v %v", claimed, err)
|
||||
}
|
||||
if err := store.CompleteClassification(ctx, claimed[0].ID, "archived", .4, "kb-1", map[string]any{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
n, err := store.EnsureInboxClassifierVersion(ctx, 2)
|
||||
if err != nil || n != 1 {
|
||||
t.Fatalf("expected one requeued archived item, n=%d err=%v", n, err)
|
||||
}
|
||||
items, err := store.ListInbox(ctx, "received", 10)
|
||||
if err != nil || len(items) != 1 {
|
||||
t.Fatalf("expected requeued received item: %#v %v", items, err)
|
||||
}
|
||||
n, err = store.EnsureInboxClassifierVersion(ctx, 2)
|
||||
if err != nil || n != 0 {
|
||||
t.Fatalf("classifier migration must be one-shot, n=%d err=%v", n, err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user