Files
StarPilot/openpilot/starpilot/galaxy/tests/test_crash_reports.mjs
T
firestar5683 80fbb4f6db Feature registration
Register vehicle controls, planner modes, UI actions and Galaxy services after their providers exist. Wire the shared runtime entrypoints and cover their combined behavior.

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
Co-authored-by: Daniel Koepping <elkoled@gmail.com>
Co-authored-by: Danny <dannyirwin31@yahoo.com>
Co-authored-by: DimitriChrysafis <Dimitri.chrysafis@gmail.com>
Co-authored-by: Dom <168790843+firestar5683@users.noreply.github.com>
Co-authored-by: Harald Schäfer <harald.the.engineer@gmail.com>
Co-authored-by: Kacper Rączy <gfw.kra@gmail.com>
Co-authored-by: Prabhaav Pillai <prabhaav@msu.edu>
Co-authored-by: dirwin31 <83434411+dirwin31@users.noreply.github.com>
Co-authored-by: firestarsdog <229254897+firestarsdog@users.noreply.github.com>
Co-authored-by: stef <19478336+stefpi@users.noreply.github.com>
Co-authored-by: whoisdomi <dcantu83@gmail.com>

Co-authored-by: Intelli <contact@intelli.software>
Co-authored-by: haraschax <6804392+haraschax@users.noreply.github.com>
Co-authored-by: prabhaavp <prabhaav@msu.edu>
2026-10-14 20:02:39 -05:00

66 lines
2.7 KiB
JavaScript

import assert from "node:assert/strict"
import { CrashReportsFeed } from "../web/js/crash-reports.js"
const flush = async () => { for (let i = 0; i < 8; i++) await Promise.resolve() }
function fixture() {
const requests = [], states = []
let unauthorized = 0
const feed = new CrashReportsFeed({ publish: (state) => states.push(state), unauthorized: () => { unauthorized++ },
fetcher: (url, options) => new Promise((resolve) => requests.push({ url, signal: options.signal, resolve })) })
const reply = async (index, body, status = 200) => {
requests[index].resolve({ ok: status === 200, status, json: async () => body })
await flush()
}
return { feed, requests, states, reply, get unauthorized() { return unauthorized } }
}
const listing = { schemaVersion: 1, scanIncomplete: true, listLimited: false, reports: [
{ id: "first", name: "report-one", size: 10, modifiedAt: 100 },
{ id: "second", name: "report-two", size: 20, modifiedAt: 90 },
] }
const normal = fixture()
normal.feed.start()
assert.equal(normal.requests[0].url, "./api/crash-reports")
await normal.reply(0, listing)
assert.equal(normal.states.at(-1).scanIncomplete, true)
normal.feed.open(listing.reports[0])
assert.equal(normal.requests[1].url, "./api/crash-reports/first")
normal.feed.open(listing.reports[1])
assert.equal(normal.requests[1].signal.aborted, true)
await normal.reply(2, { schemaVersion: 1, name: "report-two", text: "current", truncated: false })
assert.equal(normal.states.at(-1).preview.text, "current")
const count = normal.states.length
await normal.reply(1, { schemaVersion: 1, name: "report-one", text: "stale", truncated: false })
assert.equal(normal.states.length, count)
normal.feed.stop()
assert.equal(normal.states.at(-1).preview, null)
assert.deepEqual(normal.states.at(-1).reports, [])
const exited = fixture()
exited.feed.start()
exited.feed.stop()
await exited.reply(0, listing)
assert.deepEqual(exited.states.at(-1).reports, [])
const revoked = fixture()
revoked.feed.start()
await revoked.reply(0, { error: "Sign in" }, 401)
assert.equal(revoked.unauthorized, 1)
assert.deepEqual(revoked.states.at(-1).reports, [])
const failure = fixture()
failure.feed.start()
await failure.reply(0, listing)
failure.feed.open(listing.reports[0])
await failure.reply(1, { error: "Report changed" }, 409)
assert.equal(failure.states.at(-1).preview, null)
assert.equal(failure.states.at(-1).selected, null)
assert.equal(failure.states.at(-1).previewStatus, "unavailable")
failure.feed.open(listing.reports[0])
await failure.reply(2, { schemaVersion: 1, name: "report-one", text: "sample", truncated: true })
assert.equal(failure.states.at(-1).preview.truncated, true)
failure.feed.stop()
console.log("Crash report client lifecycle checks passed")