fix(ui): сбрасывать снимок при изменении параметров speed-пробы
This commit is contained in:
1 parent
090206c893
commit
7f18fcb6db
11 files changed
+106
-22
No files matched your search
@@ -2,7 +2,7 @@ import { test } from "node:test"
|
||||
import assert from "node:assert/strict"
|
||||
import { emptySpeedProbeObservations } from "@mmapp/contracts"
|
||||
import { publishSpeedProbeSnapshots } from "./speed-probe-snapshot"
|
||||
const probe = { id: "p", srcServerId: "1", dstServerId: "2", enabled: true, ...emptySpeedProbeObservations, lastTxAvgMbps: 0 as number | null, lastRxAvgMbps: 80 as number | null, lastStatus: "done" as "done" | "error" | null, lastRunAt: "2026-10-07T00:00:00Z" as string | null }
|
||||
const probe = { id: "p", srcServerId: "1", dstServerId: "2", srcInterface: "ether1", dstInterface: "ether2", protocol: "tcp" as const, direction: "both" as "both" | "transmit" | "receive", durationSec: "10", enabled: true, ...emptySpeedProbeObservations, lastTxAvgMbps: 0 as number | null, lastRxAvgMbps: 80 as number | null, lastStatus: "done" as "done" | "error" | null, lastRunAt: "2026-10-07T00:00:00Z" as string | null }
|
||||
test("same pair preserves latest zero and snapshot instead of readonly values copied into a stale draft", () => {
|
||||
const next = { ...probe, enabled: false, lastTxAvgMbps: 999, lastRxAvgMbps: 999 }
|
||||
const [saved] = publishSpeedProbeSnapshots([probe], [next])
|
||||
@@ -25,3 +25,9 @@ test("new row and reordered existing rows retain correct ownership without mutat
|
||||
assert.deepEqual(saved.map(p => p.id), ["new", "p"])
|
||||
assert.equal(next.lastRxAvgMbps, 80)
|
||||
})
|
||||
|
||||
for (const edit of [{ srcInterface: "ether3" }, { dstInterface: "ether3" }, { protocol: "udp" as const }, { direction: "transmit" as const }, { durationSec: "20" }]) test("changed measurement " + Object.keys(edit)[0] + " resets all observations without altering history", () => {
|
||||
const [saved] = publishSpeedProbeSnapshots([probe], [{ ...probe, ...edit }])
|
||||
for (const key of Object.keys(emptySpeedProbeObservations)) assert.equal(saved[key as keyof typeof emptySpeedProbeObservations], null)
|
||||
assert.equal(probe.lastRxAvgMbps, 80)
|
||||
})
|
||||
@@ -1,12 +1,12 @@
|
||||
import { emptySpeedProbeObservations, type SpeedProbeRead } from "@mmapp/contracts"
|
||||
import { emptySpeedProbeObservations, sameSpeedMeasurement, type SpeedMeasurementParameters, type SpeedProbeRead } from "@mmapp/contracts"
|
||||
type Observations = Pick<SpeedProbeRead, keyof typeof emptySpeedProbeObservations>
|
||||
type Pair = { id: string; srcServerId: string; dstServerId: string }
|
||||
/** Publish confirmed configuration while preserving the latest snapshot only for the same pair. */
|
||||
type Pair = { id: string } & SpeedMeasurementParameters
|
||||
/** Publish confirmed configuration while preserving the latest snapshot only for the same measurement parameters. */
|
||||
export function publishSpeedProbeSnapshots<T extends Pair & Partial<Observations>>(previous: readonly T[], next: readonly T[]) {
|
||||
const byId = new Map(previous.map(row => [row.id, row]))
|
||||
return next.map(row => {
|
||||
const old = byId.get(row.id)
|
||||
if (!old || old.srcServerId !== row.srcServerId || old.dstServerId !== row.dstServerId) {
|
||||
if (!old || !sameSpeedMeasurement(old, row)) {
|
||||
return { ...row, ...emptySpeedProbeObservations }
|
||||
}
|
||||
const observations = Object.fromEntries(Object.keys(emptySpeedProbeObservations).map(key => [key, old[key as keyof Observations] ?? null])) as Observations
|
||||
|
||||
Reference in new issue
Block a user