// Auto-generated by scripts/gen_parity_tests.py from docs/runtime-parity.md.
// Module: node:async_hooks
// This file is a byte-for-byte parity test against `node --experimental-strip-types`.
// Edit the TODO lines below to exercise each API; rerun
// `./run_parity_tests.sh --filter test_parity_async_hooks` to verify.

import * as async_hooks from "node:async_hooks";


// ── Functions ──
try {
  console.log("async_hooks.executionAsyncId() typeof:", typeof async_hooks.executionAsyncId());
} catch (e: any) { console.log("executionAsyncId ERR:", e && e.message); }

try {
  console.log("async_hooks.triggerAsyncId() typeof:", typeof async_hooks.triggerAsyncId());
} catch (e: any) { console.log("triggerAsyncId ERR:", e && e.message); }

// PERRY-SKIP: async_hooks.executionAsyncResource() — return shape varies across runtimes.

// ── createHook ──
try {
  const hook = async_hooks.createHook({
    init() {},
    before() {},
    after() {},
    destroy() {},
    promiseResolve() {},
  });
  console.log("createHook typeof:", typeof hook);
  console.log("createHook.enable typeof:", typeof hook.enable);
  console.log("createHook.disable typeof:", typeof hook.disable);
  hook.enable();
  console.log("hook enabled OK");
  hook.disable();
  console.log("hook disabled OK");
} catch (e: any) { console.log("createHook ERR:", e && e.message); }

// PERRY-SKIP: async_hooks.asyncWrapProviders — bag of internal constants; host-dependent shape.

// ── Class: AsyncResource ──
try {
  const ar = new async_hooks.AsyncResource("MyResource");
  console.log("AsyncResource typeof:", typeof ar);
  console.log("AsyncResource.asyncId typeof:", typeof ar.asyncId());
  console.log("AsyncResource.triggerAsyncId typeof:", typeof ar.triggerAsyncId());
  const result = ar.runInAsyncScope(() => 42, null);
  console.log("AsyncResource.runInAsyncScope result:", result);
  ar.emitDestroy();
  console.log("AsyncResource.emitDestroy OK");
} catch (e: any) { console.log("AsyncResource ERR:", e && e.message); }

try {
  let parentId = 0;
  const events: string[] = [];
  const hook = async_hooks.createHook({
    init(asyncId: number, type: string, triggerAsyncId: number) {
      if (type === "ParentResource") events.push(`init-parent:${asyncId > 0}`);
      if (type === "ChildResource") events.push(`init-child:${triggerAsyncId === parentId}`);
    },
    before(asyncId: number) {
      if (asyncId === parentId) events.push("before-parent");
    },
    after(asyncId: number) {
      if (asyncId === parentId) events.push("after-parent");
    },
  });
  hook.enable();
  const parent = new async_hooks.AsyncResource("ParentResource");
  parentId = parent.asyncId();
  let execMatched = false;
  let childTriggerMatched = false;
  const scoped = parent.runInAsyncScope((a: number, b: number) => {
    execMatched = async_hooks.executionAsyncId() === parentId;
    const child = new async_hooks.AsyncResource("ChildResource");
    childTriggerMatched = child.triggerAsyncId() === parentId;
    child.emitDestroy();
    return a + b;
  }, null, 20, 22);
  parent.emitDestroy();
  hook.disable();
  console.log("AsyncResource lifecycle result:", scoped, execMatched, childTriggerMatched, events.join("|"));
} catch (e: any) { console.log("AsyncResource lifecycle ERR:", e && e.message); }

try {
  const order: string[] = [];
  const h1 = async_hooks.createHook({ init(_id: number, type: string) { if (type === "OrderResource") order.push("A"); } });
  const h2 = async_hooks.createHook({ init(_id: number, type: string) { if (type === "OrderResource") order.push("B"); } });
  h1.enable();
  h2.enable();
  new async_hooks.AsyncResource("OrderResource").emitDestroy();
  h1.disable();
  h2.disable();
  console.log("multiple hooks order:", order.join(""));
} catch (e: any) { console.log("multiple hooks ERR:", e && e.message); }

try {
  const seen: string[] = [];
  const h1 = async_hooks.createHook({ init(_id: number, type: string) { if (type === "DisableResource") seen.push("A"); } });
  const h2 = async_hooks.createHook({ init(_id: number, type: string) { if (type === "DisableResource") seen.push("B"); } });
  h1.enable();
  h2.enable();
  h1.disable();
  new async_hooks.AsyncResource("DisableResource").emitDestroy();
  h2.disable();
  console.log("disable one hook:", seen.join(""));
} catch (e: any) { console.log("disable hook ERR:", e && e.message); }

// PERRY-SKIP: AsyncResource.bind / static AsyncResource.bind — newer API surface, not exercised here.

// ── Class: AsyncLocalStorage ──
try {
  const als = new async_hooks.AsyncLocalStorage();
  console.log("AsyncLocalStorage typeof:", typeof als);
  console.log("AsyncLocalStorage.getStore (outside run):", als.getStore());
  const ran = als.run({ user: "alice" }, () => {
    const store: any = als.getStore();
    return store && store.user;
  });
  console.log("AsyncLocalStorage.run inner store user:", ran);
  console.log("AsyncLocalStorage.getStore (after run):", als.getStore());
  const exited = als.run({ user: "bob" }, () => {
    return als.exit(() => {
      return als.getStore();
    });
  });
  console.log("AsyncLocalStorage.exit returned:", exited);
  als.disable();
  console.log("AsyncLocalStorage.disable OK");
} catch (e: any) { console.log("AsyncLocalStorage ERR:", e && e.message); }

// PERRY-SKIP: AsyncLocalStorage.enterWith / bind / snapshot / static bind+snapshot — newer surface, omitted for determinism.

// Coverage: 4 auto-emitted, 25 TODO, 0 skip-listed.
