import '../assert_dev_env.js';
/**
 * Deno runtime adapter for spawnable cross-process test server binaries.
 *
 * Binds `Deno.serve` and `hono/deno`'s module-level `upgradeWebSocket`. The
 * shared `testing_server_core.ts` owns the rest. Counterpart to
 * `testing_server_node.ts` — together they isolate the JS-runtime axis (Deno
 * vs Node V8) on identical TS surfaces, and the Rust spine binary covers the
 * cross-language axis.
 *
 * `Deno` globals are declared locally (mirroring `runtime/deno.ts`) so this
 * module typechecks under fuz_app's Node-based config without a `deno.json`
 * or `@types/deno`. It is only ever *run* under Deno.
 *
 * @module
 */
import { upgradeWebSocket } from 'hono/deno';
import { create_deno_runtime } from '../../runtime/deno.js';
/** Build the Deno {@link TestingServerAdapter}. */
export const create_deno_testing_adapter = () => ({
    runtime_label: 'Deno',
    runtime: create_deno_runtime([]),
    get_connection_ip: (c) => c.env?.remoteAddr?.hostname,
    // Deno's WS upgrade is module-level and stateless — no post-serve attach.
    prepare_websocket: () => ({ upgrade_websocket: upgradeWebSocket }),
    serve: ({ fetch, port, hostname }) => {
        const server = Deno.serve({ port, hostname }, fetch);
        const handle = { shutdown: () => server.shutdown(), native: server };
        return handle;
    },
    pid: Deno.pid,
    register_shutdown_signals: (handler) => {
        Deno.addSignalListener('SIGINT', () => void handler());
        Deno.addSignalListener('SIGTERM', () => void handler());
    },
    exit: (code) => Deno.exit(code),
});
