testing/daemon_info.ts

Daemon-info file plumbing for the testing servers — ~/.{name}/run/daemon.json, written at startup and read for stale-process detection.

view source

Declarations
#

6 declarations

DaemonInfo
#

testing/daemon_info.ts view source

value + type

{ version: number; pid: number; port: number; started: string; app_version: string; } import {DaemonInfo} from '@fuzdev/fuz_app/testing/daemon_info.js';

Daemon info schema for ~/.{name}/run/daemon.json, a strict @fuzdev/fuz_schema object schema.

version

Schema version.

type number

pid

Server process ID.

type number

port

Port the server is listening on.

type number

started

When the server started, an RFC 3339 date and time in UTC (2026-01-01T00:00:00.000Z): a four-digit year, seconds required, a fraction of up to 9 digits or none, Z and no offset — fuz_schema's iso_datetime.

type string

app_version

Package version of the application.

type string

get_app_dir
#

testing/daemon_info.ts view source

(runtime: Pick<EnvDeps, "env_get">, name: string): string | null import {get_app_dir} from '@fuzdev/fuz_app/testing/daemon_info.js';

Get an app's home directory path (~/.{name}).

runtime

runtime with env_get capability

type Pick<EnvDeps, "env_get">

name

application name (e.g., "tx", "zzz")

type string

returns

string | null

path to the app directory, or null if $HOME is not set

get_daemon_info_path
#

testing/daemon_info.ts view source

(runtime: Pick<EnvDeps, "env_get">, name: string): string | null import {get_daemon_info_path} from '@fuzdev/fuz_app/testing/daemon_info.js';

Get the daemon info file path (~/.{name}/run/daemon.json).

runtime

runtime with env_get capability

type Pick<EnvDeps, "env_get">

name

application name

type string

returns

string | null

path to daemon.json, or null if $HOME is not set

is_daemon_running
#

testing/daemon_info.ts view source

(runtime: ProcessProbeDeps, pid: number): boolean import {is_daemon_running} from '@fuzdev/fuz_app/testing/daemon_info.js';

Whether the daemon a daemon.json names is still running: its pid is a process this process may signal (probe_process).

A process another user owns ('not_permitted') is not the daemon — its pid was reused — so it reads as not running, as does a pid that names no single process (0, a negative number, a non-integer, out of pid_t range).

runtime

runtime with the process probe

pid

the process ID daemon.json recorded

type number

returns

boolean

true if the process is running and this process may signal it

read_daemon_info
#

testing/daemon_info.ts view source

(runtime: Pick<EnvDeps, "env_get"> & Pick<FsReadDeps, "stat" | "read_text_file"> & LogDeps, name: string): Promise<{ version: number; pid: number; port: number; started: string; app_version: string; } | null> import {read_daemon_info} from '@fuzdev/fuz_app/testing/daemon_info.js';

Read and validate daemon info from the PID file.

runtime

runtime with file read and env capabilities

type Pick<EnvDeps, "env_get"> & Pick<FsReadDeps, "stat" | "read_text_file"> & LogDeps

name

application name

type string

returns

Promise<DaemonInfo | null>

parsed daemon info, or null if missing or invalid

write_daemon_info
#

testing/daemon_info.ts view source

(runtime: Pick<EnvDeps, "env_get"> & Pick<FsWriteDeps, "mkdir" | "rename" | "write_text_file">, name: string, info: { version: number; pid: number; port: number; started: string; app_version: string; }): Promise<...> import {write_daemon_info} from '@fuzdev/fuz_app/testing/daemon_info.js';

Write daemon info to the PID file, creating directories as needed.

runtime

runtime with file write and env capabilities

type Pick<EnvDeps, "env_get"> & Pick<FsWriteDeps, "mkdir" | "write_text_file" | "rename">

name

application name

type string

info

daemon info to write

returns

Promise<void>

throws

  • Error - if `$HOME` is not set

mutates

  • filesystem — creates `~/.{name}/run/` and atomically writes `daemon.json`

Depends on
#

Imported by
#