augmentLogging = testerFunc => {
  const testerFuncName = `ava ${testerFunc.name || 'test'}`;
  const augmented = (...args) => {
    // Align with ava argument parsing.
    // https://github.com/avajs/ava/blob/c74934853db1d387c46ed1f953970c777feed6a0/lib/parse-test-args.js
    const rawTitle = typeof args[0] === 'string' ? args.shift() : undefined;
    const implFuncOrObj = args.shift();
    const hasRawTitle = typeof rawTitle === 'string';
    let resolvedTitle;
    // Successful test declaration must be possible before `lockdown` allows
    // `harden` to function, but `freeze(arrowFunc)` is a suitable replacement
    // because all objects reachable from the result are intrinsics hardened by
    // lockdown.
    const wrapBuildTitle = (buildTitle, thisObj) => {
      const wrappedBuildTitle = (...titleArgs) => {
        resolvedTitle = apply(buildTitle, thisObj, titleArgs);
        return resolvedTitle;
      };
      return freeze(wrappedBuildTitle);
    };
    const wrapImplFunc = fn => {
      /**
       * @param {import('ava').ExecutionContext} originalT
       */
      const wrappedFunc = originalT => {
        const virtualT = makeVirtualExecutionContext(originalT);
        // Format source like `test("$rawTitle") "$resolvedTitle"`.
        const quotedRawTitle = hasRawTitle ? stringify(rawTitle) : '';
        const quotedResolvedTitle =
          typeof resolvedTitle === 'string' && resolvedTitle !== rawTitle
            ? ` ${stringify(resolvedTitle)}`
            : '';
        const source = `${testerFuncName}(${quotedRawTitle})${quotedResolvedTitle}`;
        return logErrorFirst(fn, virtualT, args, source);
      };
      const buildTitle = fn.title;
      if (buildTitle) {
        wrappedFunc.title = wrapBuildTitle(buildTitle, fn);
      }
      return freeze(wrappedFunc);
    };
    let implArg;
    if (typeof implFuncOrObj === 'function') {
      // Handle common cases like `test(title, t => { ... }, ...)`.
      implArg = wrapImplFunc(implFuncOrObj);
    } else if (typeof implFuncOrObj === 'object' && implFuncOrObj) {
      // Handle cases like `test(title, test.macro(...), ...)`.
      // Note that this will need updating if a future version of ava adds an alternative to `exec`.
      implArg = {
        ...implFuncOrObj,
        exec: wrapImplFunc(implFuncOrObj.exec),
      };
      const buildTitle = implArg.title;
      if (buildTitle) {
        implArg.title = wrapBuildTitle(buildTitle, implArg);
      }
      freeze(implArg);
    } else {
      // Let ava handle this bad input.
      implArg = implFuncOrObj;
    }
    // @ts-expect-error these spreads are acceptable
    return testerFunc(...(hasRawTitle ? [rawTitle] : []), implArg, ...args);
  };
  // re-use other properties (e.g. `.always`)
  // https://github.com/endojs/endo/issues/647#issuecomment-809010961
  Object.assign(augmented, testerFunc);
  // @ts-expect-error cast
  return /** @type {import('ava').OnlyFn} */ augmented;
}
@template {import('ava').OnlyFn} [T=import('ava').TestFn]
@param {T} testerFunc
@returns {T} Not yet frozen!