The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 03:15 UTC
fix(web): refresh resource timeline while diagnostics is open (#30528)
Shaun Hawk committed
Nov 5, 2026 at 23:30 UTC
53f1d09470c98655d270bc71216ae4788516b7f3
2 files changed
+85
packages/client-runtime/src/state/server.test.ts
+83
@@ -14,6 +14,7 @@ import {
14
WS_METHODS,
15
} from "@t3tools/contracts";
16
import { describe, expect, it } from "@effect/vitest";
17
+import { vi } from "vite-plus/test";
18
import * as Cause from "effect/Cause";
19
import * as Deferred from "effect/Deferred";
20
import * as Duration from "effect/Duration";
@@ -36,6 +37,7 @@ import {
37
AVAILABLE_CONNECTION_STATE,
38
PrimaryConnectionTarget,
39
type PreparedConnection,
40
+ type SupervisorConnectionState,
41
} from "../connection/model.ts";
42
import * as EnvironmentRegistry from "../connection/registry.ts";
43
import * as EnvironmentSupervisor from "../connection/supervisor.ts";
@@ -1394,3 +1396,84 @@ describe("provider setup commands", () => {
1396
}).pipe(Effect.scoped),
1397
);
1398
});
1399
+
1400
+describe("resource telemetry history", () => {
1401
+ it.effect("refreshes an initially empty history while mounted and stops after unmount", () =>
1402
+ Effect.gen(function* () {
1403
+ vi.useFakeTimers();
1404
+ try {
1405
+ yield* Effect.scoped(
1406
+ Effect.gen(function* () {
1407
+ let reads = 0;
1408
+ const client = {
1409
+ [WS_METHODS.serverGetResourceTelemetryHistory]: () =>
1410
+ Effect.sync(() => ({
1411
+ retainedSampleCount: reads++,
1412
+ })),
1413
+ } as unknown as WsRpcProtocolClient;
1414
+ const supervisor = EnvironmentSupervisor.EnvironmentSupervisor.of({
1415
+ target: TARGET,
1416
+ state: yield* SubscriptionRef.make<SupervisorConnectionState>({
1417
+ ...AVAILABLE_CONNECTION_STATE,
1418
+ phase: "connected",
1419
+ }),
1420
+ session: yield* SubscriptionRef.make(Option.some(session(client))),
1421
+ prepared: yield* SubscriptionRef.make(Option.none<PreparedConnection>()),
1422
+ connect: Effect.void,
1423
+ disconnect: Effect.void,
1424
+ retryNow: Effect.void,
1425
+ });
1426
+ const environments = EnvironmentRegistry.EnvironmentRegistry.of({
1427
+ run: (_id, effect) =>
1428
+ Effect.provideService(
1429
+ effect,
1430
+ EnvironmentSupervisor.EnvironmentSupervisor,
1431
+ supervisor,
1432
+ ),
1433
+ followStream: (_id, stream) =>
1434
+ Stream.provideService(
1435
+ stream,
1436
+ EnvironmentSupervisor.EnvironmentSupervisor,
1437
+ supervisor,
1438
+ ),
1439
+ } as EnvironmentRegistry.EnvironmentRegistry["Service"]);
1440
+ const runtime = Atom.runtime(
1441
+ Layer.merge(
1442
+ Layer.succeed(EnvironmentRegistry.EnvironmentRegistry, environments),
1443
+ Layer.succeed(Persistence.EnvironmentCacheStore, {
1444
+ loadServerConfig: () => Effect.succeedNone,
1445
+ } as unknown as Persistence.EnvironmentCacheStore["Service"]),
1446
+ ),
1447
+ );
1448
+ const atoms = createServerEnvironmentAtoms(runtime, {
1449
+ initialConfigValueAtom: () => Atom.make(CONFIG),
1450
+ });
1451
+ const registry = yield* Effect.acquireRelease(Effect.sync(AtomRegistry.make), (value) =>
1452
+ Effect.sync(() => value.dispose()),
1453
+ );
1454
+ const history = atoms.resourceTelemetryHistory({
1455
+ environmentId: TARGET.environmentId,
1456
+ input: { windowMs: 900_000, bucketMs: 30_000 },
1457
+ });
1458
+ const unmount = registry.mount(history);
1459
+ const initial = yield* AtomRegistry.getResult(registry, history, {
1460
+ suspendOnWaiting: true,
1461
+ });
1462
+ expect(initial.retainedSampleCount).toBe(0);
1463
+ yield* Effect.promise(() => vi.advanceTimersByTimeAsync(5_000));
1464
+ expect(reads).toBe(2);
1465
+ const updated = yield* AtomRegistry.getResult(registry, history, {
1466
+ suspendOnWaiting: true,
1467
+ });
1468
+ expect(updated.retainedSampleCount).toBe(1);
1469
+ unmount();
1470
+ yield* Effect.promise(() => vi.advanceTimersByTimeAsync(10_000));
1471
+ expect(reads).toBe(2);
1472
+ }),
1473
+ );
1474
+ } finally {
1475
+ vi.useRealTimers();
1476
+ }
1477
+ }),
1478
+ );
1479
+});
packages/client-runtime/src/state/server.ts
+2
@@ -1366,6 +1366,8 @@ export function createServerEnvironmentAtoms<R, E>(
1366
label: "environment-data:server:resource-telemetry-history",
1367
tag: WS_METHODS.serverGetResourceTelemetryHistory,
1368
staleTimeMs: 5_000,
1369
+ refreshIntervalMs: 5_000,
1370
+ idleTtlMs: 0,
1371
}),
1372
searchAcpRegistry: createEnvironmentRpcQueryAtomFamily(runtime, {
1373
label: "environment-data:server:acp-registry:search",