mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-24 21:30:17 +08:00
6274705848
Frontend half of the logging overhaul. Capture: - Add a global error boundary plus window error/unhandledrejection handlers that persist renderer errors via tauri-plugin-log (new @tauri-apps/plugin-log dependency + log:default capability), so a white-screen crash leaves a trace. Redaction (two layers over every logged value): - Structured serializer: redact by sensitive property name (arrays and nested values included) and by opaque value shape. - Text layer, the universal final pass: redact URL credentials/query, auth schemes, known secret shapes, and named-key array/object values. The container rule closes prefix+JSON, double-encoded, and POJO-error bypasses regardless of which entrypoint the structured data came from. - Render Errors as redacted message + native stack across V8 and WebKit (macOS/Linux) without depending on a single stack format. - Bound all inputs and drop oversized JSON to keep the UI responsive. i18n: - zh / en / ja / zh-TW for the new log settings and error text.
37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
const reportFrontendError = vi.hoisted(() => vi.fn());
|
|
|
|
vi.mock("@/lib/frontendLogger", () => ({
|
|
reportFrontendError,
|
|
}));
|
|
|
|
import { render, screen } from "@testing-library/react";
|
|
import { FrontendErrorBoundary } from "@/components/FrontendErrorBoundary";
|
|
|
|
function ThrowingChild(): React.ReactNode {
|
|
throw new Error("sensitive render failure");
|
|
}
|
|
|
|
describe("FrontendErrorBoundary", () => {
|
|
it("reports render failures and replaces the broken tree", () => {
|
|
const consoleError = vi
|
|
.spyOn(console, "error")
|
|
.mockImplementation(() => undefined);
|
|
|
|
render(
|
|
<FrontendErrorBoundary>
|
|
<ThrowingChild />
|
|
</FrontendErrorBoundary>,
|
|
);
|
|
|
|
expect(screen.getByRole("alert")).toBeInTheDocument();
|
|
expect(screen.getByRole("button")).toBeInTheDocument();
|
|
expect(reportFrontendError).toHaveBeenCalledWith(
|
|
"react.error_boundary",
|
|
expect.objectContaining({ message: "sensitive render failure" }),
|
|
expect.any(String),
|
|
);
|
|
|
|
consoleError.mockRestore();
|
|
});
|
|
});
|