Add full test suite with unit, integration, and E2E smoke tests.

Introduce test.bat orchestrating Go/Vitest/Playwright phases, expand coverage across server, agent, and dashboard, and document in tests/README.md.
This commit is contained in:
drjones
2026-05-29 10:04:52 -07:00
parent f9e26bb1a6
commit e55f11a657
23 changed files with 1052 additions and 12 deletions

View File

@@ -184,16 +184,30 @@ func (c *AgentClient) authenticate() error {
return nil
}
func jobPayloadHasError(payload json.RawMessage) bool {
_, ok := jobPayloadErrorMessage(payload)
return ok
}
func jobPayloadErrorMessage(payload json.RawMessage) (string, bool) {
var raw map[string]json.RawMessage
if err := json.Unmarshal(payload, &raw); err != nil {
return "", false
}
errMsg, ok := raw["error"]
if !ok {
return "", false
}
return strings.Trim(string(errMsg), `"`), true
}
func (c *AgentClient) handleMessage(msg Message) {
switch msg.Type {
case "new_job":
var raw map[string]json.RawMessage
if err := json.Unmarshal(msg.Payload, &raw); err != nil {
log.Printf("[agent] bad job payload: %v", err)
return
}
if errMsg, ok := raw["error"]; ok {
log.Printf("[agent] job error from server: %s", string(errMsg))
if jobPayloadHasError(msg.Payload) {
if msg, _ := jobPayloadErrorMessage(msg.Payload); msg != "" {
log.Printf("[agent] job error from server: %s", msg)
}
c.write(Message{Type: "get_job", Payload: json.RawMessage("{}")})
return
}

31
agent/client/jobs_test.go Normal file
View File

@@ -0,0 +1,31 @@
package client
import (
"encoding/json"
"testing"
)
func TestJobPayloadDetectsServerError(t *testing.T) {
raw := json.RawMessage(`{"error":"pool not connected"}`)
if !jobPayloadHasError(raw) {
t.Fatal("expected error detection")
}
msg, ok := jobPayloadErrorMessage(raw)
if !ok || msg != "pool not connected" {
t.Fatalf("unexpected message: %q ok=%v", msg, ok)
}
}
func TestJobPayloadNoErrorOnValidJob(t *testing.T) {
raw := json.RawMessage(`{"job_id":"abc","blob":"deadbeef","height":1}`)
if jobPayloadHasError(raw) {
t.Fatal("valid job should not report error")
}
}
func TestJobPayloadEmptyBlobNotErrorField(t *testing.T) {
raw := json.RawMessage(`{"job_id":"abc","blob":""}`)
if jobPayloadHasError(raw) {
t.Fatal("empty blob is not an error field")
}
}