From 77fddcde78f0a2a8be32d5e3aeeabd7215a7fcd4 Mon Sep 17 00:00:00 2001 From: Danijel Martinek Date: Tue, 12 May 2026 22:40:44 +0200 Subject: [PATCH] feat(core-shared/instrumentation): withCapture attaches runtime __captured marker --- .../src/instrumentation/with-capture.test.ts | 11 +++++++++++ .../core-shared/src/instrumentation/with-capture.ts | 2 ++ 2 files changed, 13 insertions(+) diff --git a/packages/core-shared/src/instrumentation/with-capture.test.ts b/packages/core-shared/src/instrumentation/with-capture.test.ts index 28b4803..179534f 100644 --- a/packages/core-shared/src/instrumentation/with-capture.test.ts +++ b/packages/core-shared/src/instrumentation/with-capture.test.ts @@ -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 } { return { @@ -70,3 +71,13 @@ describe("withCapture — brand", () => { expectTypeOf(wrapped).toMatchTypeOf>(); }); }); + +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"); + }); +}); diff --git a/packages/core-shared/src/instrumentation/with-capture.ts b/packages/core-shared/src/instrumentation/with-capture.ts index ed17420..9807a81 100644 --- a/packages/core-shared/src/instrumentation/with-capture.ts +++ b/packages/core-shared/src/instrumentation/with-capture.ts @@ -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( throw err; } }; + attachBrand(wrapped, "__captured"); return wrapped as Captured<(...args: Args) => Promise>; }