fix(conformance): withCapture propagates inner brands + chain test + docstring fixes

This commit is contained in:
2026-05-12 23:00:50 +02:00
parent 046bd0829e
commit 83f135b5e1
4 changed files with 97 additions and 7 deletions

View File

@@ -28,6 +28,8 @@ export function withCapture<Args extends unknown[], R>(
tags: Record<string, string>,
fn: (...args: Args) => Promise<R>,
): Captured<(...args: Args) => Promise<R>> {
const PROPAGATED_BRANDS = ["__instrumented", "__audited"] as const;
const wrapped: (...args: Args) => Promise<R> = async (...args) => {
try {
return await fn(...args);
@@ -39,6 +41,14 @@ export function withCapture<Args extends unknown[], R>(
throw err;
}
};
// Propagate brands from the inner function (e.g. __audited from withAudit,
// __instrumented if already spanned) so the outermost binding carries all brands.
// __captured is omitted here because it is attached explicitly below.
for (const brand of PROPAGATED_BRANDS) {
if ((fn as unknown as Record<string, unknown>)[brand] === true) {
attachBrand(wrapped, brand);
}
}
attachBrand(wrapped, "__captured");
return wrapped as Captured<(...args: Args) => Promise<R>>;
}