fix(mesh): probe upstream synchronously in route diagnostic (F-11) (#1100)

GET /api/mesh/aliases/:alias/diagnostic returned a cached state derived
from the last latency/error maps. Those maps only mutated when someone
called POST .../test or when a cross-node connect logged an event, so
once an upstream stopped the diagnostic kept reporting "healthy" until
the 60 s alias-cache refresh pruned the alias entirely.

The GET now calls testUpstream synchronously after the alias-resolved,
opted-in, tunnel-up short-circuits. Probe failures land in routeErrorMap
via logActivity (cross-node already did this; same-node timeout/error
paths now log probe.fail in the same shape), so the state computation
flips to "unreachable" on the same request that exposed the stopped
upstream. A new routeProbeAtMap stamps freshness and surfaces in the
response as lastProbeAt; the route detail sheet renders "Last probe
<age> · <ms>" using the existing formatTimeAgo helper.
This commit is contained in:
Anso
2026-05-18 16:48:09 -04:00
committed by GitHub
parent 7d2b8bee7a
commit c460bb87a8
5 changed files with 241 additions and 5 deletions
@@ -49,6 +49,16 @@ describe('MeshService diagnostic — local-node pilot state (M-12)', () => {
// 'tunnel down'.
vi.spyOn(PilotTunnelManager.getInstance(), 'hasActiveTunnel').mockReturnValue(false);
// F-11: getRouteDiagnostic now probes synchronously. Stub testUpstream
// so the unit test does not depend on a live TCP socket on port 9000.
// The stub writes routeLatencyMap in lockstep with the real probe
// success path so the state computation below resolves to 'healthy'.
vi.spyOn(svc, 'testUpstream').mockImplementation(async (alias: string) => {
(svc as unknown as { routeLatencyMap: Map<string, number> }).routeLatencyMap.set(alias, 5);
(svc as unknown as { routeProbeAtMap: Map<string, number> }).routeProbeAtMap.set(alias, Date.now());
return { ok: true, latencyMs: 5 };
});
(svc as unknown as { aliasCache: Map<string, unknown> }).aliasCache = new Map([
['echo.audit-mesh-prod.local.sencho', {
host: 'echo.audit-mesh-prod.local.sencho',