server/testing_server_core.ts

Runtime-agnostic test-binary core for the TS canonical zzz server.

Shared by the Deno (testing_server_deno.ts) and Node (testing_server_node.ts) test-binary adapters: same create_zzz_app factory, same _testing_reset registration, same reset_state closure, same daemon-info + shutdown discipline. The two runtime adapters only supply the boundary primitives that diverge between Deno and Node (HTTP serve, WS upgrade construction, signal registration, pid, exit).

Production stays on Deno (server.ts). Both test entries register _testing_reset from fuz_app's create_testing_actions factory with a zzz reset_state closure that closes all workspaces, kills terminals via PtyManager.kill_all, and wipes the optional ZZZ_TESTING_SCRATCH_DIR tree.

NEVER ship in a release. The module reaches into fuz_app's testing/cross_backend/ modules which throw at production-bundle load via assert_dev_env. The testing_ filename prefix mirrors the Rust testing_zzz_server convention and is enforced for the Rust side by cargo xtask check-release's dep-graph audit.

Declarations
#

4 declarations

view source

PreparedWebsocket
#

server/testing_server_core.ts view source

PreparedWebsocket

Result of an adapter's WS preparation step.

upgrade_websocket is the Hono UpgradeWebSocket closure the dispatcher uses to register the WS endpoint. attach_to_server is called after serve() returns a ServeHandle — Node uses it for injectWebSocket(server); Deno leaves it undefined.

upgrade_websocket

type UpgradeWebSocket

attach_to_server

type (handle: ServeHandle) => void

ServeHandle
#

server/testing_server_core.ts view source

ServeHandle

Adapter-built handle to a bound HTTP server.

shutdown stops accepting new connections and waits for in-flight ones to drain. native is an adapter-specific server reference — used by Node's @hono/node-ws injectWebSocket(server) post-serve hook; Deno leaves it unset (Deno.serve doesn't need post-serve WS wiring).

shutdown

type () => Promise<void>

native

Adapter-specific server ref for post-serve hooks. Type-erased at the seam.

type unknown

start_testing_server
#

server/testing_server_core.ts view source

(adapter: TestingServerAdapter): Promise<void>

Boot the test-mode zzz server using the supplied runtime adapter.

Mirrors server.ts's start_server (Deno production) at the surface level — same env loading, bind validation, daemon-info lifecycle, and shutdown drain — but forces `enable_test_actions: true, swaps stub_password_deps` in place of argon2, and registers the _testing_reset RPC action with a zzz domain reset_state closure.

adapter

returns

Promise<void>

TestingServerAdapter
#

server/testing_server_core.ts view source

TestingServerAdapter

Runtime adapter contract for the test-binary entry.

Each adapter (testing_server_deno.ts, testing_server_node.ts) implements this and hands the shape to {@link start_testing_server}. The core owns env load, bind validation, create_zzz_app construction, WS endpoint wiring, daemon-info write, and shutdown coordination; the adapter owns the runtime-boundary primitives.

runtime_label

Human-readable runtime label for log output (e.g. "Deno", "Node").

type string

runtime

RuntimeDeps capability bundle from create_deno_runtime / create_node_runtime.

type RuntimeDeps

get_connection_ip

Extract the raw TCP connection IP from a Hono context.

type (c: Context) => string | undefined

prepare_websocket

Build the WS upgrade closure after create_zzz_app returns the app.

type (app: Hono) => PreparedWebsocket

serve

Bind app.fetch to port on hostname; return a {@link ServeHandle}.

type (options: {fetch: Hono['fetch']; port: number; hostname: string}) => ServeHandle

pid

Current process pid (for daemon.json).

type number

register_shutdown_signals

Register SIGINT/SIGTERM listeners that invoke handler once each.

type (handler: () => Promise<void>) => void

exit

Forceful exit on graceful-shutdown completion or fatal error.

type (code: number) => never

Depends on
#

Imported by
#