test(metis): cover remote progress updates

This commit is contained in:
codex 2026-04-21 05:02:49 -03:00
parent 651a11f5a5
commit 1a3cd78e8a

View File

@ -59,3 +59,55 @@ func TestParseRemoteProgressLogsFindsLatestMarker(t *testing.T) {
t.Fatalf("unexpected update: %#v", update)
}
}
func TestParseRemoteProgressLogsSkipsMalformedMarkers(t *testing.T) {
logs := strings.Join([]string{
"plain log line",
progressLogPrefix + "{bad-json",
ProgressLogLine(RemoteProgressUpdate{Stage: "flash", ProgressPct: 90, Message: "writing"}),
}, "\n")
update, ok := parseRemoteProgressLogs(logs)
if !ok {
t.Fatal("expected valid marker after malformed marker")
}
if update.Stage != "flash" || update.ProgressPct != 90 || update.Message != "writing" {
t.Fatalf("unexpected update: %#v", update)
}
}
func TestApplyRemoteProgressUpdatesOnlyRunningJobs(t *testing.T) {
app := newTestApp(t)
running := app.newJob("replace", "titan-13", "titan-22", "/dev/sda")
app.setJob(running.ID, func(j *Job) {
j.Status = JobRunning
j.Stage = "queued"
j.ProgressPct = 10
})
queued := app.newJob("build", "titan-14", "titan-22", "")
app.applyRemoteProgress("", RemoteProgressUpdate{Stage: "ignored"})
app.applyRemoteProgress("missing", RemoteProgressUpdate{Stage: "ignored"})
app.applyRemoteProgress(queued.ID, RemoteProgressUpdate{Stage: "ignored", ProgressPct: 99})
app.applyRemoteProgress(
running.ID,
RemoteProgressUpdate{
Stage: "flash",
ProgressPct: 80,
Message: "writing image",
WrittenBytes: 1024,
TotalBytes: 2048,
},
)
app.applyRemoteProgress(running.ID, RemoteProgressUpdate{ProgressPct: 70})
got := app.job(running.ID)
if got.Stage != "flash" || got.ProgressPct != 80 || got.Message != "writing image" {
t.Fatalf("running job was not updated correctly: %+v", got)
}
if got.Written != 1024 || got.Total != 2048 || got.StageStartedAt.IsZero() {
t.Fatalf("remote byte/stage fields not applied: %+v", got)
}
if app.job(queued.ID).Stage == "ignored" {
t.Fatalf("queued job should not receive remote progress")
}
}