Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Accelerate mock history readiness

rcourtman99af2a0bf257
diff --git a/docs/release-control/v6/internal/subsystems/deployment-installability.md b/docs/release-control/v6/internal/subsystems/deployment-installability.md
index 298db850da..a82eb45bc3 100644
--- a/docs/release-control/v6/internal/subsystems/deployment-installability.md
+++ b/docs/release-control/v6/internal/subsystems/deployment-installability.md
@@ -1826,6 +1826,13 @@ truth inside Playwright helpers. `tests/integration/tests/helpers.ts` may
offer request trackers for browser-shell contract proofs, but those helpers
must observe page-originated traffic only and must not blur browser runtime
requests together with `page.request` or other direct API helper calls.
+The shared authenticated browser fixture must not report the default mock
+runtime ready from inventory alone while historical chart initialization is
+still running. When Core E2E requests the default mock-readiness gate, the
+helper must also prove that storage-pool and physical-disk history cover the
+suite's deepest seven-day chart window. The compose harness must seed that
+same seven-day window by default instead of forcing every parallel shard to
+build unrelated 90-day preview history.
Managed runtime recovery and browser bootstrap proofs therefore need to keep
helper coverage that demonstrates browser-shell request tracking remains
trustworthy when the same test also performs direct health or security-status
diff --git a/docs/release-control/v6/internal/subsystems/monitoring.md b/docs/release-control/v6/internal/subsystems/monitoring.md
index be5cd673d8..3f2a6d4eaf 100644
--- a/docs/release-control/v6/internal/subsystems/monitoring.md
+++ b/docs/release-control/v6/internal/subsystems/monitoring.md
@@ -928,6 +928,14 @@ The seed path must therefore include the canonical terminal `now` sample on
its tiered timeline and anchor seeded series to the canonical metric model at
that timestamp instead of to mutable state fields, so historical charts match
the exact runtime history that would have been recorded live.
+Historical backfills must resolve resource identity, metric bounds, stable
+seed, speed, and role once per series, then append that ordered series to
+`MetricsHistory` under one series-level mutation. They must not repeat
+normalization, hashing, role lookup, locking, retention scans, and capacity
+checks independently for every point. Test harnesses must also bound mock seed
+duration to the deepest history window they actually prove; Core E2E owns a
+seven-day chart contract and must not make every parallel shard build the
+production-preview 90-day timeline.
That means seeded history must sample the shared canonical mock runtime metric
function at every historical timestamp for every mock-owned resource class.
Monitoring must not approximate the past from snapshot/current values and then
diff --git a/internal/mock/metric_runtime.go b/internal/mock/metric_runtime.go
index 2ae136f3c6..3a9e3cc13b 100644
--- a/internal/mock/metric_runtime.go
+++ b/internal/mock/metric_runtime.go
@@ -5,6 +5,7 @@ import (
"strings"
"time"
+ "github.com/rcourtman/pulse-go-rewrite/internal/mockmodel"
"github.com/rcourtman/pulse-go-rewrite/internal/models"
)
@@ -222,6 +223,27 @@ func SampleMetric(resourceClass, resourceID, metric string, at time.Time) float6
return sampleNaturalMetric(resourceClass, resourceID, metric, min, max, metricSpeed(metric), at)
}
+// SampleMetricSeries projects one canonical metric across a timestamp
+// sequence. The resource identity, bounds, seed, speed, and role are invariant
+// for the entire series, so resolve them once instead of repeating string
+// normalization, hashing, and registry lookups for every historical point.
+func SampleMetricSeries(resourceClass, resourceID, metric string, timestamps []time.Time) []float64 {
+ if len(timestamps) == 0 {
+ return nil
+ }
+
+ min, max := MetricBoundsForResource(resourceClass, resourceID, metric)
+ seed := MetricSeed(resourceClass, resourceID, metric)
+ speed := metricSpeed(metric)
+ role := MetricRole(resourceClass, resourceID)
+
+ values := make([]float64, len(timestamps))
+ for i, at := range timestamps {
+ values[i] = mockmodel.ValueAtMetricWithRole(seed, min, max, metric, speed, role, at)
+ }
+ return values
+}
+
func SampleMetricInt(resourceClass, resourceID, metric string, at time.Time) int64 {
return int64(math.Round(SampleMetric(resourceClass, resourceID, metric, at)))
}
diff --git a/internal/mock/metric_runtime_test.go b/internal/mock/metric_runtime_test.go
new file mode 100644
index 0000000000..9eb22e20cd
--- /dev/null
+++ b/internal/mock/metric_runtime_test.go
@@ -0,0 +1,46 @@
+package mock
+
+import (
+ "math"
+ "testing"
+ "time"
+)
+
+func TestSampleMetricSeriesMatchesCanonicalPointSampler(t *testing.T) {
+ start := time.Date(2026, time.July, 19, 12, 0, 0, 0, time.UTC)
+ timestamps := make([]time.Time, 0, 96)
+ for i := 0; i < 96; i++ {
+ timestamps = append(timestamps, start.Add(time.Duration(i)*15*time.Minute))
+ }
+
+ for _, tc := range []struct {
+ resourceClass string
+ resourceID string
+ metric string
+ }{
+ {resourceClass: "node", resourceID: "pve1", metric: "cpu"},
+ {resourceClass: "vm", resourceID: "database-primary", metric: "memory"},
+ {resourceClass: "storage", resourceID: "backup-pool", metric: "usage"},
+ {resourceClass: "disk", resourceID: "NVME-SERIAL-1", metric: "smart_temp"},
+ {resourceClass: "dockerContainer", resourceID: "api-service", metric: "netin"},
+ } {
+ t.Run(tc.resourceClass+"/"+tc.metric, func(t *testing.T) {
+ got := SampleMetricSeries(tc.resourceClass, tc.resourceID, tc.metric, timestamps)
+ if len(got) != len(timestamps) {
+ t.Fatalf("series length = %d, want %d", len(got), len(timestamps))
+ }
+ for i, at := range timestamps {
+ want := SampleMetric(tc.resourceClass, tc.resourceID, tc.metric, at)
+ if math.Abs(got[i]-want) > 1e-12 {
+ t.Fatalf("point %d at %v = %v, want %v", i, at, got[i], want)
+ }
+ }
+ })
+ }
+}
+
+func TestSampleMetricSeriesEmptyInput(t *testing.T) {
+ if got := SampleMetricSeries("vm", "vm-1", "cpu", nil); got != nil {
+ t.Fatalf("empty series = %#v, want nil", got)
+ }
+}
diff --git a/internal/monitoring/metrics_history.go b/internal/monitoring/metrics_history.go
index 6352490ab8..ae6e1bb0c2 100644
--- a/internal/monitoring/metrics_history.go
+++ b/internal/monitoring/metrics_history.go
@@ -171,6 +171,135 @@ func (mh *MetricsHistory) appendMetric(metrics []MetricPoint, point MetricPoint)
return metrics
}
+// appendMetricSeries applies the same retention, duplicate-tail, and capacity
+// rules as appendMetric while amortizing them across a historical backfill.
+// Seed timestamps are ordered oldest-first, matching the live append contract.
+func (mh *MetricsHistory) appendMetricSeries(metrics []MetricPoint, values []float64, timestamps []time.Time) []MetricPoint {
+ count := len(values)
+ if len(timestamps) < count {
+ count = len(timestamps)
+ }
+ if count == 0 {
+ return metrics
+ }
+
+ for i := 0; i < count; i++ {
+ point := MetricPoint{Value: values[i], Timestamp: timestamps[i]}
+ if len(metrics) > 0 && metrics[len(metrics)-1].Timestamp.Equal(point.Timestamp) {
+ metrics[len(metrics)-1] = point
+ } else {
+ metrics = append(metrics, point)
+ }
+ }
+
+ cutoffTime := time.Now().Add(-mh.retentionTime)
+ firstRetained := sort.Search(len(metrics), func(i int) bool {
+ return metrics[i].Timestamp.After(cutoffTime)
+ })
+ if firstRetained == len(metrics) {
+ metrics = metrics[:0]
+ } else if firstRetained > 0 {
+ metrics = metrics[firstRetained:]
+ }
+
+ if len(metrics) > mh.maxDataPoints {
+ metrics = metrics[len(metrics)-mh.maxDataPoints:]
+ }
+ return metrics
+}
+
+func (mh *MetricsHistory) addGuestMetricSeries(guestID, metricType string, values []float64, timestamps []time.Time) {
+ mh.mu.Lock()
+ defer mh.mu.Unlock()
+
+ if _, exists := mh.guestMetrics[guestID]; !exists {
+ mh.guestMetrics[guestID] = &GuestMetrics{}
+ }
+ metrics := mh.guestMetrics[guestID]
+ switch metricType {
+ case "cpu":
+ metrics.CPU = mh.appendMetricSeries(metrics.CPU, values, timestamps)
+ case "memory":
+ metrics.Memory = mh.appendMetricSeries(metrics.Memory, values, timestamps)
+ case "disk":
+ metrics.Disk = mh.appendMetricSeries(metrics.Disk, values, timestamps)
+ case "diskread":
+ metrics.DiskRead = mh.appendMetricSeries(metrics.DiskRead, values, timestamps)
+ case "diskwrite":
+ metrics.DiskWrite = mh.appendMetricSeries(metrics.DiskWrite, values, timestamps)
+ case "netin":
+ metrics.NetworkIn = mh.appendMetricSeries(metrics.NetworkIn, values, timestamps)
+ case "netout":
+ metrics.NetworkOut = mh.appendMetricSeries(metrics.NetworkOut, values, timestamps)
+ case "temperature":
+ metrics.Temperature = mh.appendMetricSeries(metrics.Temperature, values, timestamps)
+ }
+}
+
+func (mh *MetricsHistory) addNodeMetricSeries(nodeID, metricType string, values []float64, timestamps []time.Time) {
+ mh.mu.Lock()
+ defer mh.mu.Unlock()
+
+ if _, exists := mh.nodeMetrics[nodeID]; !exists {
+ mh.nodeMetrics[nodeID] = &GuestMetrics{}
+ }
+ metrics := mh.nodeMetrics[nodeID]
+ switch metricType {
+ case "cpu":
+ metrics.CPU = mh.appendMetricSeries(metrics.CPU, values, timestamps)
+ case "memory":
+ metrics.Memory = mh.appendMetricSeries(metrics.Memory, values, timestamps)
+ case "disk":
+ metrics.Disk = mh.appendMetricSeries(metrics.Disk, values, timestamps)
+ case "netin":
+ metrics.NetworkIn = mh.appendMetricSeries(metrics.NetworkIn, values, timestamps)
+ case "netout":
+ metrics.NetworkOut = mh.appendMetricSeries(metrics.NetworkOut, values, timestamps)
+ case "temperature":
+ metrics.Temperature = mh.appendMetricSeries(metrics.Temperature, values, timestamps)
+ }
+}
+
+func (mh *MetricsHistory) addStorageMetricSeries(storageID, metricType string, values []float64, timestamps []time.Time) {
+ mh.mu.Lock()
+ defer mh.mu.Unlock()
+
+ if _, exists := mh.storageMetrics[storageID]; !exists {
+ mh.storageMetrics[storageID] = &StorageMetrics{}
+ }
+ metrics := mh.storageMetrics[storageID]
+ switch metricType {
+ case "usage":
+ metrics.Usage = mh.appendMetricSeries(metrics.Usage, values, timestamps)
+ case "used":
+ metrics.Used = mh.appendMetricSeries(metrics.Used, values, timestamps)
+ case "total":
+ metrics.Total = mh.appendMetricSeries(metrics.Total, values, timestamps)
+ case "avail":
+ metrics.Avail = mh.appendMetricSeries(metrics.Avail, values, timestamps)
+ }
+}
+
+func (mh *MetricsHistory) addDiskMetricSeries(resourceID, metricType string, values []float64, timestamps []time.Time) {
+ mh.mu.Lock()
+ defer mh.mu.Unlock()
+
+ if _, exists := mh.diskMetrics[resourceID]; !exists {
+ mh.diskMetrics[resourceID] = &DiskMetrics{}
+ }
+ metrics := mh.diskMetrics[resourceID]
+ switch metricType {
+ case "disk":
+ metrics.Utilization = mh.appendMetricSeries(metrics.Utilization, values, timestamps)
+ case "diskread":
+ metrics.DiskRead = mh.appendMetricSeries(metrics.DiskRead, values, timestamps)
+ case "diskwrite":
+ metrics.DiskWrite = mh.appendMetricSeries(metrics.DiskWrite, values, timestamps)
+ case "smart_temp":
+ metrics.Temperature = mh.appendMetricSeries(metrics.Temperature, values, timestamps)
+ }
+}
+
// GetGuestMetrics returns historical metrics for a guest
func (mh *MetricsHistory) GetGuestMetrics(guestID string, metricType string, duration time.Duration) []MetricPoint {
mh.mu.RLock()
diff --git a/internal/monitoring/metrics_history_test.go b/internal/monitoring/metrics_history_test.go
index 8823777426..28d0cad113 100644
--- a/internal/monitoring/metrics_history_test.go
+++ b/internal/monitoring/metrics_history_test.go
@@ -170,6 +170,48 @@ func TestAppendMetric(t *testing.T) {
}
}
+func TestAppendMetricSeriesMatchesPointAppendSemantics(t *testing.T) {
+ now := time.Now().UTC().Truncate(time.Second)
+ timestamps := []time.Time{
+ now.Add(-2 * time.Hour),
+ now.Add(-45 * time.Minute),
+ now.Add(-30 * time.Minute),
+ now.Add(-15 * time.Minute),
+ now,
+ }
+ values := []float64{10, 20, 30, 40, 50}
+
+ pointHistory := NewMetricsHistory(3, time.Hour)
+ seriesHistory := NewMetricsHistory(3, time.Hour)
+ var pointResult []MetricPoint
+ for i := range values {
+ pointResult = pointHistory.appendMetric(pointResult, MetricPoint{
+ Value: values[i],
+ Timestamp: timestamps[i],
+ })
+ }
+ seriesResult := seriesHistory.appendMetricSeries(nil, values, timestamps)
+
+ if len(seriesResult) != len(pointResult) {
+ t.Fatalf("series result length = %d, want %d", len(seriesResult), len(pointResult))
+ }
+ for i := range pointResult {
+ if seriesResult[i] != pointResult[i] {
+ t.Fatalf("series point %d = %+v, want %+v", i, seriesResult[i], pointResult[i])
+ }
+ }
+
+ replacement := []float64{99}
+ seriesResult = seriesHistory.appendMetricSeries(
+ seriesResult,
+ replacement,
+ []time.Time{timestamps[len(timestamps)-1]},
+ )
+ if got := seriesResult[len(seriesResult)-1].Value; got != 99 {
+ t.Fatalf("duplicate terminal timestamp value = %v, want 99", got)
+ }
+}
+
func TestMetricsHistoryStoresGuestAndNodeTemperature(t *testing.T) {
mh := NewMetricsHistory(10, time.Hour)
now := time.Now()
diff --git a/internal/monitoring/mock_metrics_history.go b/internal/monitoring/mock_metrics_history.go
index 19242c6216..0b05020b08 100644
--- a/internal/monitoring/mock_metrics_history.go
+++ b/internal/monitoring/mock_metrics_history.go
@@ -477,12 +477,7 @@ func canonicalMetricSeries(resourceType, resourceID, metric string, timestamps [
if len(timestamps) == 0 || strings.TrimSpace(resourceID) == "" {
return nil
}
-
- values := make([]float64, len(timestamps))
- for i, ts := range timestamps {
- values[i] = mock.SampleMetric(resourceType, resourceID, metric, ts)
- }
- return values
+ return mock.SampleMetricSeries(resourceType, resourceID, metric, timestamps)
}
func seedMockMetricsHistory(mh *MetricsHistory, ms *metrics.Store, graph mock.FixtureGraph, now time.Time, seedDuration, interval time.Duration) {
@@ -606,16 +601,21 @@ func seedMockMetricsHistory(mh *MetricsHistory, ms *metrics.Store, graph mock.Fi
}
usageSeries := canonicalMetricSeries("storage", storageID, "usage", seedTimestamps)
+ usedSeries := make([]float64, numPoints)
+ availSeries := make([]float64, numPoints)
+ totalSeries := make([]float64, numPoints)
for i := 0; i < numPoints; i++ {
- ts := seedTimestamps[i]
usage := clampFloat(usageSeries[i], 0, 100)
used := currentTotal * (usage / 100.0)
- avail := math.Max(0, currentTotal-used)
- mh.AddStorageMetric(storageID, "usage", usage, ts)
- mh.AddStorageMetric(storageID, "used", used, ts)
- mh.AddStorageMetric(storageID, "avail", avail, ts)
- mh.AddStorageMetric(storageID, "total", currentTotal, ts)
- }
+ usageSeries[i] = usage
+ usedSeries[i] = used
+ availSeries[i] = math.Max(0, currentTotal-used)
+ totalSeries[i] = currentTotal
+ }
+ mh.addStorageMetricSeries(storageID, "usage", usageSeries, seedTimestamps)
+ mh.addStorageMetricSeries(storageID, "used", usedSeries, seedTimestamps)
+ mh.addStorageMetricSeries(storageID, "avail", availSeries, seedTimestamps)
+ mh.addStorageMetricSeries(storageID, "total", totalSeries, seedTimestamps)
seedStoreStorageSeries(storageID, currentTotal)
}
@@ -628,12 +628,9 @@ func seedMockMetricsHistory(mh *MetricsHistory, ms *metrics.Store, graph mock.Fi
memSeries := canonicalMetricSeries("node", node.ID, "memory", seedTimestamps)
diskSeries := canonicalMetricSeries("node", node.ID, "disk", seedTimestamps)
- for i := 0; i < numPoints; i++ {
- ts := seedTimestamps[i]
- mh.AddNodeMetric(node.ID, "cpu", cpuSeries[i], ts)
- mh.AddNodeMetric(node.ID, "memory", memSeries[i], ts)
- mh.AddNodeMetric(node.ID, "disk", diskSeries[i], ts)
- }
+ mh.addNodeMetricSeries(node.ID, "cpu", cpuSeries, seedTimestamps)
+ mh.addNodeMetricSeries(node.ID, "memory", memSeries, seedTimestamps)
+ mh.addNodeMetricSeries(node.ID, "disk", diskSeries, seedTimestamps)
seedStoreSeries("node", node.ID, "cpu", "memory", "disk")
}
@@ -679,28 +676,19 @@ func seedMockMetricsHistory(mh *MetricsHistory, ms *metrics.Store, graph mock.Fi
netOutSeries = canonicalMetricSeries(storeType, storeID, "netout", seedTimestamps)
}
- for i := 0; i < numPoints; i++ {
- ts := seedTimestamps[i]
- for _, metricID := range uniqueMetricIDs {
- mh.AddGuestMetric(metricID, "cpu", cpuSeries[i], ts)
- mh.AddGuestMetric(metricID, "memory", memSeries[i], ts)
- }
+ for _, metricID := range uniqueMetricIDs {
+ mh.addGuestMetricSeries(metricID, "cpu", cpuSeries, seedTimestamps)
+ mh.addGuestMetricSeries(metricID, "memory", memSeries, seedTimestamps)
if includeDisk {
- for _, metricID := range uniqueMetricIDs {
- mh.AddGuestMetric(metricID, "disk", diskSeries[i], ts)
- }
+ mh.addGuestMetricSeries(metricID, "disk", diskSeries, seedTimestamps)
}
if includeDiskIO {
- for _, metricID := range uniqueMetricIDs {
- mh.AddGuestMetric(metricID, "diskread", diskReadSeries[i], ts)
- mh.AddGuestMetric(metricID, "diskwrite", diskWriteSeries[i], ts)
- }
+ mh.addGuestMetricSeries(metricID, "diskread", diskReadSeries, seedTimestamps)
+ mh.addGuestMetricSeries(metricID, "diskwrite", diskWriteSeries, seedTimestamps)
}
if includeNetwork {
- for _, metricID := range uniqueMetricIDs {
- mh.AddGuestMetric(metricID, "netin", netInSeries[i], ts)
- mh.AddGuestMetric(metricID, "netout", netOutSeries[i], ts)
- }
+ mh.addGuestMetricSeries(metricID, "netin", netInSeries, seedTimestamps)
+ mh.addGuestMetricSeries(metricID, "netout", netOutSeries, seedTimestamps)
}
}
@@ -816,13 +804,10 @@ func seedMockMetricsHistory(mh *MetricsHistory, ms *metrics.Store, graph mock.Fi
busySeries := canonicalMetricSeries("disk", resourceID, "disk", seedTimestamps)
diskReadSeries := canonicalMetricSeries("disk", resourceID, "diskread", seedTimestamps)
diskWriteSeries := canonicalMetricSeries("disk", resourceID, "diskwrite", seedTimestamps)
- for i := 0; i < numPoints; i++ {
- ts := seedTimestamps[i]
- mh.AddDiskMetric(resourceID, "smart_temp", tempSeries[i], ts)
- mh.AddDiskMetric(resourceID, "disk", busySeries[i], ts)
- mh.AddDiskMetric(resourceID, "diskread", diskReadSeries[i], ts)
- mh.AddDiskMetric(resourceID, "diskwrite", diskWriteSeries[i], ts)
- }
+ mh.addDiskMetricSeries(resourceID, "smart_temp", tempSeries, seedTimestamps)
+ mh.addDiskMetricSeries(resourceID, "disk", busySeries, seedTimestamps)
+ mh.addDiskMetricSeries(resourceID, "diskread", diskReadSeries, seedTimestamps)
+ mh.addDiskMetricSeries(resourceID, "diskwrite", diskWriteSeries, seedTimestamps)
seedStoreSeries("disk", resourceID, "smart_temp", "disk", "diskread", "diskwrite")
}
@@ -921,10 +906,7 @@ func seedMockMetricsHistory(mh *MetricsHistory, ms *metrics.Store, graph mock.Fi
for _, pool := range trueNASFixtures.Pools {
poolKey := mock.TrueNASPoolMetricID(trueNASFixtures.System.Hostname, pool.Name)
diskSeries := canonicalMetricSeries("storage", poolKey, "usage", seedTimestamps)
- for i := 0; i < numPoints; i++ {
- ts := seedTimestamps[i]
- mh.AddGuestMetric(poolKey, "disk", diskSeries[i], ts)
- }
+ mh.addGuestMetricSeries(poolKey, "disk", diskSeries, seedTimestamps)
recordStorageTimeline(poolKey, float64(pool.TotalBytes))
}
@@ -932,10 +914,7 @@ func seedMockMetricsHistory(mh *MetricsHistory, ms *metrics.Store, graph mock.Fi
dsKey := mock.TrueNASDatasetMetricID(trueNASFixtures.System.Hostname, dataset.Name)
totalBytes := dataset.UsedBytes + dataset.AvailBytes
diskSeries := canonicalMetricSeries("storage", dsKey, "usage", seedTimestamps)
- for i := 0; i < numPoints; i++ {
- ts := seedTimestamps[i]
- mh.AddGuestMetric(dsKey, "disk", diskSeries[i], ts)
- }
+ mh.addGuestMetricSeries(dsKey, "disk", diskSeries, seedTimestamps)
recordStorageTimeline(dsKey, float64(totalBytes))
}
diff --git a/tests/integration/docker-compose.test.yml b/tests/integration/docker-compose.test.yml
index d3c0ca259b..4ffffbba00 100644
--- a/tests/integration/docker-compose.test.yml
+++ b/tests/integration/docker-compose.test.yml
@@ -79,6 +79,10 @@ services:
# Mock mode is the default shared-estate contract. Dedicated lifecycle
# jobs can disable it without maintaining a second compose definition.
- PULSE_MOCK_MODE=${PULSE_MOCK_MODE:-true}
+ # Seven days is the deepest live-history window exercised by Core E2E.
+ # Keep the harness seed proportional to that contract instead of making
+ # every parallel shard build the production-preview 90-day timeline.
+ - PULSE_MOCK_TRENDS_SEED_DURATION=${PULSE_MOCK_TRENDS_SEED_DURATION:-168h}
# Dev-only endpoints the suite depends on (first-run reset in the
# first-session specs) are gated on development mode.
- PULSE_DEV=true
diff --git a/tests/integration/scripts/managed-local-backend.test.mjs b/tests/integration/scripts/managed-local-backend.test.mjs
index 1ad3b21b65..a8b9c7f97e 100644
--- a/tests/integration/scripts/managed-local-backend.test.mjs
+++ b/tests/integration/scripts/managed-local-backend.test.mjs
@@ -167,6 +167,17 @@ test('multi-tenant release auth reuses storage state and classifies login rate l
assert.match(helpers, /\/too many\/i\.test\(lastOutcome\) \? 15_000/);
});
+test('shared browser readiness waits for the bounded mock history contract', async () => {
+ const helpers = await fs.readFile(path.join(integrationRoot, 'tests', 'helpers.ts'), 'utf8');
+ const compose = await fs.readFile(path.join(integrationRoot, 'docker-compose.test.yml'), 'utf8');
+
+ assert.match(compose, /PULSE_MOCK_TRENDS_SEED_DURATION=\$\{PULSE_MOCK_TRENDS_SEED_DURATION:-168h\}/);
+ assert.match(helpers, /"\/api\/storage-charts\?range=10080"/);
+ assert.match(helpers, /hasDeepSeries\(pool\.used\)/);
+ assert.match(helpers, /hasDeepSeries\(disk\.temperature\)/);
+ assert.match(helpers, /default mock history should cover the seven-day Core E2E chart window/);
+});
+
test('multi-tenant release org switching waits for selected org UI state', async () => {
const helpers = await fs.readFile(path.join(integrationRoot, 'tests', 'helpers.ts'), 'utf8');
diff --git a/tests/integration/tests/62-storage-growth-column.spec.ts b/tests/integration/tests/62-storage-growth-column.spec.ts
index 06c14d6936..b8b40d9c7c 100644
--- a/tests/integration/tests/62-storage-growth-column.spec.ts
+++ b/tests/integration/tests/62-storage-growth-column.spec.ts
@@ -141,7 +141,7 @@ async function firstVisibleGrowthRow(
// (24h) label for a pool matches the delta derived from the same 24h
// used-capacity history the /api/storage-charts endpoint serves.
test.describe.serial('Storage growth column', () => {
- test.setTimeout(120_000);
+ test.setTimeout(180_000);
test('renders storage-history growth deltas for the 24h window', async ({
page,
@@ -165,7 +165,9 @@ test.describe.serial('Storage growth column', () => {
timeout: 30_000,
});
- const probeResponse = await apiRequest(page, '/api/storage-charts?range=1440');
+ const probeResponse = await apiRequest(page, '/api/storage-charts?range=1440', {
+ timeout: 60_000,
+ });
expect(probeResponse.ok()).toBeTruthy();
const probePayload = (await probeResponse.json()) as StorageChartsResponse;
const seriesId = await firstVisibleGrowthRow(page, probePayload);
@@ -179,7 +181,9 @@ test.describe.serial('Storage growth column', () => {
// racing a single snapshot against the render.
await expect
.poll(async () => {
- const response = await apiRequest(page, '/api/storage-charts?range=1440');
+ const response = await apiRequest(page, '/api/storage-charts?range=1440', {
+ timeout: 60_000,
+ });
if (!response.ok()) return 'payload-error';
const payload = (await response.json()) as StorageChartsResponse;
const expected = growthLabelForPool(payload.pools?.[seriesId]);
diff --git a/tests/integration/tests/helpers.ts b/tests/integration/tests/helpers.ts
index d96c3baeda..0e0ea61760 100644
--- a/tests/integration/tests/helpers.ts
+++ b/tests/integration/tests/helpers.ts
@@ -1141,6 +1141,15 @@ type E2ERuntimeState = {
resources?: E2ERuntimeStateResource[];
};
+type E2EMetricPoint = {
+ timestamp?: number;
+};
+
+type E2EStorageCharts = {
+ pools?: Record<string, { used?: E2EMetricPoint[] }>;
+ disks?: Record<string, { temperature?: E2EMetricPoint[] }>;
+};
+
const requiresDefaultMockRuntimeReadiness = (): boolean =>
["1", "true", "yes", "on"].includes(
String(process.env.PULSE_E2E_REQUIRE_DEFAULT_MOCK_READY || "")
@@ -1205,6 +1214,52 @@ async function waitForDefaultMockRuntimeReady(page: Page): Promise<void> {
},
)
.toBe(true);
+
+ const hasDeepSeries = (points: E2EMetricPoint[] | undefined): boolean => {
+ const timestamps = (points ?? [])
+ .map((point) => Number(point.timestamp))
+ .filter(Number.isFinite)
+ .sort((left, right) => left - right);
+ if (timestamps.length < 2) {
+ return false;
+ }
+ return timestamps[timestamps.length - 1] - timestamps[0] > 5 * 24 * 60 * 60 * 1000;
+ };
+
+ // Inventory becomes available before the monitor has finished building its
+ // historical mock timeline. Do not advertise the shared browser fixture as
+ // ready until the deepest Core E2E chart window is queryable for both pools
+ // and disks.
+ await expect
+ .poll(
+ async () => {
+ const response = await apiRequest(
+ page,
+ "/api/storage-charts?range=10080",
+ { timeout: 60_000 },
+ ).catch(() => null);
+ if (!response?.ok()) {
+ return false;
+ }
+
+ const charts = (await response.json()) as E2EStorageCharts;
+ return (
+ Object.values(charts.pools ?? {}).some((pool) =>
+ hasDeepSeries(pool.used),
+ ) &&
+ Object.values(charts.disks ?? {}).some((disk) =>
+ hasDeepSeries(disk.temperature),
+ )
+ );
+ },
+ {
+ message:
+ "default mock history should cover the seven-day Core E2E chart window before browser fixtures start",
+ timeout: 180_000,
+ intervals: [1_000, 2_000, 5_000],
+ },
+ )
+ .toBe(true);
}
export async function createAuthenticatedStorageState(