singularity-forge/web/lib/__tests__/shutdown-gate.test.ts
ace-pm 35dc87ef53 chore: sync workspace state after rebrand
- Rebrand commits already in history (gsd → forge)
- Sync pre-existing doc, docker, and CI config updates
- All rebrand artifacts verified in place:
  * Native crates: forge-engine, forge-ast, forge-grep
  * Log prefixes: [forge] across 22+ files
  * Binary: ~/bin/sf-run
  * Workspace scopes: @sf-run/*, @singularity-forge/*
  * Nix flake: Rust toolchain ready

System ready for: nix develop && bun run build:native

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 14:54:20 +02:00

83 lines
2.3 KiB
TypeScript

import { describe, test, beforeEach, afterEach } from "node:test";
import assert from "node:assert/strict";
import {
scheduleShutdown,
cancelShutdown,
isShutdownPending,
isDaemonMode,
} from "../shutdown-gate.ts";
describe("shutdown-gate", () => {
afterEach(() => {
// Always clean up any pending timers between tests
cancelShutdown();
delete process.env.SF_WEB_DAEMON_MODE;
});
describe("default mode (no daemon)", () => {
test("scheduleShutdown() sets a pending timer", () => {
scheduleShutdown();
assert.equal(isShutdownPending(), true);
});
test("cancelShutdown() clears the pending timer", () => {
scheduleShutdown();
cancelShutdown();
assert.equal(isShutdownPending(), false);
});
test("isDaemonMode() returns false", () => {
assert.equal(isDaemonMode(), false);
});
});
describe("daemon mode (SF_WEB_DAEMON_MODE=1)", () => {
beforeEach(() => {
process.env.SF_WEB_DAEMON_MODE = "1";
});
test("isDaemonMode() returns true", () => {
assert.equal(isDaemonMode(), true);
});
test("scheduleShutdown() does not schedule a timer", () => {
scheduleShutdown();
assert.equal(
isShutdownPending(),
false,
"shutdown timer must not be set in daemon mode",
);
});
test("scheduleShutdown() is safe to call multiple times", () => {
scheduleShutdown();
scheduleShutdown();
scheduleShutdown();
assert.equal(isShutdownPending(), false);
});
});
describe("daemon mode is not activated by other values", () => {
test("SF_WEB_DAEMON_MODE=0 does not enable daemon mode", () => {
process.env.SF_WEB_DAEMON_MODE = "0";
assert.equal(isDaemonMode(), false);
scheduleShutdown();
assert.equal(isShutdownPending(), true);
});
test("SF_WEB_DAEMON_MODE=true does not enable daemon mode", () => {
process.env.SF_WEB_DAEMON_MODE = "true";
assert.equal(isDaemonMode(), false);
scheduleShutdown();
assert.equal(isShutdownPending(), true);
});
test("unset SF_WEB_DAEMON_MODE does not enable daemon mode", () => {
delete process.env.SF_WEB_DAEMON_MODE;
assert.equal(isDaemonMode(), false);
scheduleShutdown();
assert.equal(isShutdownPending(), true);
});
});
});