Stabilize AMSC chart detail overlays

This commit is contained in:
2569718930@qq.com
2026-06-15 03:13:08 +08:00
parent 39977e4431
commit 6b9caf8dc2
6 changed files with 152 additions and 6 deletions
@@ -253,6 +253,13 @@ export async function runTests() {
chartLogicSource.includes("primeCityDetailCache"),
"visible terminal chart detail fetches should be coalesced into one batch request and prime the shared chart cache",
);
assert(
chartLogicSource.includes('from "@/lib/backend-api"') &&
chartLogicSource.includes("buildBrowserBackendHeaders") &&
chartLogicSource.includes('await buildBrowserBackendHeaders({ Accept: "application/json" })') &&
chartLogicSource.includes("headers,"),
"terminal chart detail batch fetches must attach the browser Supabase bearer so users without Supabase cookies do not get backend 401 and empty charts",
);
assert(
chartLogicSource.includes('scope: "chart"') &&
chartLogicSource.includes("params.toString()"),
@@ -267,7 +274,7 @@ export async function runTests() {
chartLogicSource.includes("missing?: string[]"),
"frontend city detail batch payload should understand partial responses and missing city markers",
);
const flushCityDetailBatchBlock = chartLogicSource.match(/async function flushCityDetailBatch[\s\S]*?\r?\n}\r?\n\r?\nfunction fetchCityDetailBatchWithTimeout/)?.[0] || "";
const flushCityDetailBatchBlock = chartLogicSource.match(/async function flushCityDetailBatch[\s\S]*?\r?\n}\r?\n\r?\n(?:async\s+)?function fetchCityDetailBatchWithTimeout/)?.[0] || "";
assert(
flushCityDetailBatchBlock.includes("partialMissingCities") &&
flushCityDetailBatchBlock.includes("resolveBatchWaiters(waiters, null)") &&
@@ -12,6 +12,7 @@ import type {
} from "@/lib/dashboard-types";
import { buildDebBaselinePath } from "@/lib/temperature-chart-paths";
import { DASHBOARD_REFRESH_POLICY_MS } from "@/lib/refresh-policy";
import { buildBrowserBackendHeaders } from "@/lib/backend-api";
import type { CityPatch } from "@/hooks/use-sse-patches";
const ROLLING_WINDOW_BEFORE_MS = 12 * 60 * 60 * 1000;
const ROLLING_WINDOW_AFTER_LIVE_MS = 2 * 60 * 60 * 1000;
@@ -1715,7 +1716,7 @@ function resolveAllBatchWaitersAsNull(
});
}
function fetchCityDetailBatchWithTimeout(
async function fetchCityDetailBatchWithTimeout(
cities: string[],
resolution: string,
forceRefresh: boolean,
@@ -1730,8 +1731,9 @@ function fetchCityDetailBatchWithTimeout(
resolution,
scope: "chart",
});
const headers = await buildBrowserBackendHeaders({ Accept: "application/json" });
return fetch(`/api/cities/detail-batch?${params.toString()}`, {
headers: { Accept: "application/json" },
headers,
signal: controller.signal,
})
.then(async (res) => {