From ab150e1f2bb7b0fa87a6926f0c6cb4ff77e4427c Mon Sep 17 00:00:00 2001 From: Prajeeth H Date: Mon, 24 Aug 2026 02:40:54 +0530 Subject: [PATCH] test(startup): assert disabled boot path log output at runtime (#11016) (#11265) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Validated on the combined 8-PR board: 88/88 across the board's focused suites, typecheck:core + dashboard-typecheck clean, static gates within baseline. The subprocess spawn this test does timed out locally on the shared devbox under load 35 (ETIMEDOUT on tsx bootstrap — environment, not the test); CI runs it unloaded. Runtime log-output assertion for the disabled credential-health boot path, closing the #11016 follow-up suggested on #11029. Thank you @Prajeeth-12! --- ...redential-health-disabled-boot-log.test.ts | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 tests/unit/credential-health-disabled-boot-log.test.ts diff --git a/tests/unit/credential-health-disabled-boot-log.test.ts b/tests/unit/credential-health-disabled-boot-log.test.ts new file mode 100644 index 0000000000..e6eb92b9cc --- /dev/null +++ b/tests/unit/credential-health-disabled-boot-log.test.ts @@ -0,0 +1,93 @@ +import test from "node:test"; +import assert from "node:assert/strict"; +import { execFileSync } from "node:child_process"; +import { readFileSync, existsSync } from "node:fs"; +import { resolve, dirname } from "node:path"; +import { fileURLToPath } from "node:url"; + +// #11016 follow-up (suggested by maintainer on PR #11029): assert that the +// disabled boot path produces the correct "[STARTUP] Credential health scheduler +// disabled" log at runtime. +// +// Two complementary assertions: +// 1. Runtime: spawn a subprocess that imports the real scheduler with the disable +// env set, calls initCredentialHealthCheck(), and logs the result using the +// same conditional from instrumentation-node.ts — verifying the actual output. +// 2. Static: read src/instrumentation-node.ts and assert the boot wiring still +// uses initCredentialHealthCheck()'s return value to select the log message. +// This breaks if the production conditional is removed or refactored away. + +const thisDir = dirname(fileURLToPath(import.meta.url)); +const projectRoot = resolve(thisDir, "../.."); + +// In CI: projectRoot has a real node_modules. +// In a worktree: the junction may not work with tsx; fall back to the main checkout. +function resolveMainCheckout(): string { + const hasRealNodeModules = existsSync(resolve(projectRoot, "node_modules", ".package-lock.json")); + if (hasRealNodeModules) return projectRoot; + const candidate = resolve(projectRoot, "../../.."); + if (existsSync(resolve(candidate, "node_modules", ".package-lock.json"))) return candidate; + return projectRoot; +} + +const mainCwd = resolveMainCheckout(); + +const BOOT_DISABLED_SCRIPT = ` + process.env.OMNIROUTE_DISABLE_CREDENTIAL_HEALTH_CHECK = "true"; + const { initCredentialHealthCheck } = await import( + "./src/lib/credentialHealth/scheduler.ts" + ); + const started = initCredentialHealthCheck(); + console.log( + started + ? "[STARTUP] Credential health scheduler started" + : "[STARTUP] Credential health scheduler disabled" + ); + process.exit(0); +`; + +test("disabled scheduler emits [STARTUP] Credential health scheduler disabled via the real initCredentialHealthCheck", () => { + const result = execFileSync( + process.execPath, + ["--import", "tsx/esm", "--input-type=module", "--eval", BOOT_DISABLED_SCRIPT], + { + cwd: mainCwd, + env: { + ...process.env, + OMNIROUTE_DISABLE_CREDENTIAL_HEALTH_CHECK: "true", + NODE_NO_WARNINGS: "1", + }, + encoding: "utf8", + timeout: 30_000, + } + ); + + assert.match( + result, + /\[STARTUP\] Credential health scheduler disabled/, + "must log the disabled message when OMNIROUTE_DISABLE_CREDENTIAL_HEALTH_CHECK is set" + ); + assert.doesNotMatch( + result, + /\[STARTUP\] Credential health scheduler started/, + "must NOT log the started message when disabled" + ); +}); + +test("instrumentation-node.ts wires initCredentialHealthCheck return to the log conditional", () => { + const src = readFileSync( + resolve(projectRoot, "src/instrumentation-node.ts"), + "utf8" + ).replace(/\r\n/g, "\n"); + + assert.match( + src, + /const started = initCredentialHealthCheck\(\)/, + "boot wiring must capture the return value of initCredentialHealthCheck()" + ); + assert.match( + src, + /started[\s\S]{0,50}\?[\s\S]{0,80}scheduler started[\s\S]{0,50}:[\s\S]{0,80}scheduler disabled/, + "boot wiring must use the return value to select started vs disabled log" + ); +});