singularity-forge/src/tests/fetch-test-helpers.ts
Mikael Hugo b24f426f2b batch: snapshot of in-flight v2 work
This commit captures uncommitted modifications that accumulated in the
working tree across multiple in-progress workstreams. It is a snapshot
to clear the deck before sf v3 work begins; individual workstreams
should land separately on top of this.

Notable additions:
- trace-collector.ts, traces.ts, src/tests/trace-export.test.ts —
  trace export plumbing
- biome.json — Biome linter configuration
- .gitignore — exclude native/npm/**/*.node compiled binaries

The bulk of the diff is across src/resources/extensions/sf/ (301 files)
and src/resources/extensions/sf/tests/ (277 files), reflecting the
ongoing sf extension work. Specific feature commits should follow this
snapshot rather than being archaeology'd out of it.

The 76MB native/npm/linux-x64-gnu/forge_engine.node compiled binary
was left out of the commit — it's now gitignored and built locally.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-29 12:42:31 +02:00

30 lines
792 B
TypeScript

/**
* Shared fetch-mocking utilities for test files that need to intercept
* globalThis.fetch and inspect request headers/body.
*/
export function normalizeHeaders(
headers: HeadersInit | undefined,
): Record<string, string> | undefined {
if (headers == null) return undefined;
if (headers instanceof Headers) {
const result: Record<string, string> = {};
headers.forEach((v, k) => {
result[k] = v;
});
return result;
}
if (Array.isArray(headers)) return Object.fromEntries(headers);
return headers as Record<string, string>;
}
export function parseJsonBody(
body: BodyInit | null | undefined,
): Record<string, unknown> | undefined {
if (body == null || typeof body !== "string") return undefined;
try {
return JSON.parse(body);
} catch {
return undefined;
}
}