feat(core-shared/instrumentation): withCapture attaches runtime __captured marker

This commit is contained in:
2026-05-12 22:40:44 +02:00
parent 9e21baf5fb
commit 77fddcde78
2 changed files with 13 additions and 0 deletions

View File

@@ -3,6 +3,7 @@ import { withCapture } from "@/instrumentation/with-capture";
import type { ILogger } from "@/instrumentation/logger.interface";
import { isReported } from "@/instrumentation/reported-flag";
import type { Captured } from "@/conformance/brands";
import { isCaptured } from "@/conformance/brand-runtime";
function makeLogger(): ILogger & { captureException: ReturnType<typeof vi.fn> } {
return {
@@ -70,3 +71,13 @@ describe("withCapture — brand", () => {
expectTypeOf(wrapped).toMatchTypeOf<Captured<typeof fn>>();
});
});
describe("withCapture — runtime brand", () => {
it("attaches __captured as a non-enumerable property on the wrapped function", async () => {
const logger = makeLogger();
const fn = async (a: number) => a + 1;
const wrapped = withCapture(logger, { layer: "use-case" }, fn);
expect(isCaptured(wrapped)).toBe(true);
expect(Object.keys(wrapped)).not.toContain("__captured");
});
});

View File

@@ -1,5 +1,6 @@
import type { ILogger } from "./logger.interface";
import type { Captured } from "../conformance/brands";
import { attachBrand } from "../conformance/brand-runtime";
import { isReported, markReported } from "./reported-flag";
/**
@@ -38,5 +39,6 @@ export function withCapture<Args extends unknown[], R>(
throw err;
}
};
attachBrand(wrapped, "__captured");
return wrapped as Captured<(...args: Args) => Promise<R>>;
}