feat: add diagnostics and telemetry runtime

This commit is contained in:
donghyeon-ka
2026-07-26 16:42:27 +09:00
parent 2fa0baa577
commit 5173b6c8d6
43 changed files with 1760 additions and 116 deletions
+27 -2
View File
@@ -3,6 +3,8 @@ import { describe, expect, it, vi } from "vitest";
import { createApplication } from "../../src/application/create-application.js";
import { createAnonymousSessionAdapter } from "../../src/adapters/auth/external-session-adapter.js";
import type { StoragePort } from "../../src/application/ports/storage-port.js";
import type { DiagnosticsPort } from "../../src/application/ports/diagnostics-port.js";
import type { TelemetryPort } from "../../src/application/ports/telemetry-port.js";
type ReleaseFixture = {
buildId: string;
@@ -40,12 +42,15 @@ function applicationWith(options: {
storage?: StoragePort;
refresh?: () => Promise<ReturnType<typeof release>>;
reload?: () => void;
diagnostics?: DiagnosticsPort;
telemetry?: TelemetryPort;
}) {
const current = release("build-a", "release-a");
return createApplication({
session: createAnonymousSessionAdapter(),
preferences: options.storage ?? memoryStorage(),
diagnostics: { emit: () => {} },
diagnostics: options.diagnostics ?? { record: () => {} },
telemetry: options.telemetry ?? { emit: () => {} },
releaseInfo: {
getCurrent: async () => current,
refresh:
@@ -59,7 +64,13 @@ function applicationWith(options: {
describe("production chunk recovery application input", () => {
it("reloads exactly once for one active build/release pair", async () => {
const reload = vi.fn();
const application = applicationWith({ reload });
const record = vi.fn<DiagnosticsPort["record"]>();
const emit = vi.fn<TelemetryPort["emit"]>();
const application = applicationWith({
reload,
diagnostics: { record },
telemetry: { emit },
});
const input = {
chunkId: "route-home",
failureKind: "CHUNK_LOAD_FAILURE" as const,
@@ -69,6 +80,20 @@ describe("production chunk recovery application input", () => {
action: "reload-once",
releasePair: "build-a/release-a->build-b/release-b",
});
expect(record).toHaveBeenCalledWith({
level: "warn",
eventId: "release.mismatch.detected",
context: {
build_id: "build-a",
active_release_id: "release-b",
mismatch_kind: "BUILD_MISMATCH",
},
});
expect(emit).toHaveBeenCalledWith("release.mismatch.detected", {
build_id: "build-a",
active_release_id: "release-b",
mismatch_kind: "BUILD_MISMATCH",
});
await expect(application.recovery.recoverChunk(input)).resolves.toEqual({
action: "support",
reason: "reload-already-attempted",