Stabilize SDK mode integration test

This commit is contained in:
Nathan Flurry 2026-03-10 22:37:27 -07:00
parent 24e99ac5e7
commit ec8b6afea9
274 changed files with 5412 additions and 7893 deletions

View file

@ -27,13 +27,7 @@ export function setFrontendErrorContext(context: FrontendErrorContext): void {
function sanitizeContext(input: FrontendErrorContext): FrontendErrorContext {
const output: FrontendErrorContext = {};
for (const [key, value] of Object.entries(input)) {
if (
value === null ||
value === undefined ||
typeof value === "string" ||
typeof value === "number" ||
typeof value === "boolean"
) {
if (value === null || value === undefined || typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
output[key] = value;
}
}

View file

@ -32,9 +32,7 @@ export function defaultFrontendErrorLogPath(startDirectory: string = process.cwd
return resolve(root, DEFAULT_RELATIVE_LOG_PATH);
}
export function createFrontendErrorCollectorRouter(
options: FrontendErrorCollectorRouterOptions = {}
): Hono {
export function createFrontendErrorCollectorRouter(options: FrontendErrorCollectorRouterOptions = {}): Hono {
const logFilePath = options.logFilePath ?? defaultFrontendErrorLogPath();
const reporter = trimText(options.reporter, 128) ?? DEFAULT_REPORTER;
let ensureLogPathPromise: Promise<void> | null = null;
@ -46,7 +44,7 @@ export function createFrontendErrorCollectorRouter(
ok: true,
logFilePath,
reporter,
})
}),
);
app.post("/events", async (c) => {
@ -78,7 +76,7 @@ export function createFrontendErrorCollectorRouter(
userAgent: userAgent ?? null,
clientIp: clientIp ?? null,
receivedAt,
})
}),
);
}
@ -96,7 +94,7 @@ export function createFrontendErrorCollectorRouter(
ok: true,
accepted: normalizedEvents.length,
},
202
202,
);
});
@ -260,16 +258,8 @@ function readClientIp(forwardedFor: string | undefined): string | null {
return trimText(first, 64) ?? null;
}
function isAllowedContextValue(
value: unknown
): value is string | number | boolean | null | undefined {
return (
value === null ||
value === undefined ||
typeof value === "string" ||
typeof value === "number" ||
typeof value === "boolean"
);
function isAllowedContextValue(value: unknown): value is string | number | boolean | null | undefined {
return value === null || value === undefined || typeof value === "string" || typeof value === "number" || typeof value === "boolean";
}
function isObject(value: unknown): value is Record<string, unknown> {

View file

@ -2,9 +2,7 @@ import type { FrontendErrorCollectorScriptOptions } from "./types.js";
const DEFAULT_REPORTER = "openhandoff-frontend";
export function createFrontendErrorCollectorScript(
options: FrontendErrorCollectorScriptOptions
): string {
export function createFrontendErrorCollectorScript(options: FrontendErrorCollectorScriptOptions): string {
const config = {
endpoint: options.endpoint,
reporter: options.reporter ?? DEFAULT_REPORTER,

View file

@ -1,10 +1,4 @@
export type FrontendErrorKind =
| "window-error"
| "resource-error"
| "unhandled-rejection"
| "console-error"
| "fetch-error"
| "fetch-response-error";
export type FrontendErrorKind = "window-error" | "resource-error" | "unhandled-rejection" | "console-error" | "fetch-error" | "fetch-response-error";
export interface FrontendErrorContext {
route?: string;

View file

@ -15,9 +15,7 @@ export interface FrontendErrorCollectorVitePluginOptions {
includeFetchErrors?: boolean;
}
export function frontendErrorCollectorVitePlugin(
options: FrontendErrorCollectorVitePluginOptions = {}
): Plugin {
export function frontendErrorCollectorVitePlugin(options: FrontendErrorCollectorVitePluginOptions = {}): Plugin {
const mountPath = normalizePath(options.mountPath ?? DEFAULT_MOUNT_PATH);
const logFilePath = options.logFilePath ?? defaultFrontendErrorLogPath(process.cwd());
const reporter = options.reporter ?? "openhandoff-vite";

View file

@ -50,6 +50,6 @@ describe("frontend error collector script", () => {
endpoint: "/__openhandoff/frontend-errors/events",
});
expect(script).toContain("/__openhandoff/frontend-errors/events");
expect(script).toContain("window.addEventListener(\"error\"");
expect(script).toContain('window.addEventListener("error"');
});
});

View file

@ -3,6 +3,6 @@ import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
environment: "node",
include: ["test/**/*.test.ts"]
}
include: ["test/**/*.test.ts"],
},
});