Update hivegrid-cloud reference to latest main
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e98d38e716
commit
7b21524c86
3781 files changed
+373484
-225607
No files matched your search
+47
@@ -0,0 +1,47 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { sanitizeErrorReportValue, __internal } from "./sanitize.js";
|
||||
|
||||
/**
|
||||
* The byte-length computation has three layers: Buffer (Node), TextEncoder
|
||||
* (browser / edge), and a `value.length` last resort. Node always provides
|
||||
* Buffer, so these tests stub the globals to exercise the runtime-portability
|
||||
* fallbacks the source comment promises. The truncation guarantee (large blobs
|
||||
* never leak verbatim) must hold in every runtime.
|
||||
*/
|
||||
describe("sanitizeErrorReportValue byte-length fallbacks", () => {
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
it("uses the TextEncoder fallback to truncate when Buffer is unavailable", () => {
|
||||
vi.stubGlobal("Buffer", undefined);
|
||||
|
||||
const huge = "a".repeat(__internal.MAX_STRING_BYTES + 16);
|
||||
const result = sanitizeErrorReportValue({ blob: huge }) as { blob: string };
|
||||
|
||||
expect(result.blob).toMatch(/^<string truncated, \d+ bytes>$/);
|
||||
expect(result.blob).not.toContain("aaa");
|
||||
});
|
||||
|
||||
it("still truncates via String#length when neither Buffer nor TextEncoder exist", () => {
|
||||
vi.stubGlobal("Buffer", undefined);
|
||||
vi.stubGlobal("TextEncoder", undefined);
|
||||
|
||||
const huge = "b".repeat(__internal.MAX_STRING_BYTES + 1);
|
||||
const result = sanitizeErrorReportValue({ blob: huge }) as { blob: string };
|
||||
|
||||
expect(result.blob).toMatch(/^<string truncated, \d+ bytes>$/);
|
||||
expect(result.blob).not.toContain("bbb");
|
||||
});
|
||||
|
||||
it("does not truncate a sub-limit string when running on the fallback paths", () => {
|
||||
vi.stubGlobal("Buffer", undefined);
|
||||
vi.stubGlobal("TextEncoder", undefined);
|
||||
|
||||
const small = "ok";
|
||||
const result = sanitizeErrorReportValue({ blob: small }) as { blob: string };
|
||||
|
||||
expect(result.blob).toBe(small);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user