@@ -7,7 +7,7 @@ import { pathToFileURL } from "node:url";
77import * as serviceModule from "../src/service" ;
88import { saveConfig } from "../src/config" ;
99import { windowsEnvIndirectBatchValue } from "../src/lib/win-paths" ;
10- import { assertServiceAuthEnvironment , assertServiceEnvironmentMatchesInstall , bakedServicePathsDiagnostic , confirmServiceServing , launchdListenPort , systemdListenPort , buildPlist , buildUnit , buildWindowsLauncherVbs , buildWindowsSchtasksCreateArgs , buildWindowsSchtasksCreateArgsForXml , buildWindowsServiceScript , buildWindowsTaskXml , deriveWindowsServiceDiagnostic , deriveWindowsServiceDiagnosticForCurrentUser , installFreshWindowsSchedulerSafely , installServiceSafely , launchctlLoadFailed , launchdJobMatchesPlist , normalizeServiceSubcommand , parseServiceArgs , parseServiceInstallState , planServiceCommand , prepareServiceInstall , probeServiceInstallation , readWindowsSchedulerXmlState , registerFreshWindowsSchedulerTask , removeNativeWindowsServiceForScheduler , repairService , resolveServiceListenPort , runLaunchctl , selectServiceSubcommand , serviceLogPath , serviceStartableFromTray , serviceStatusReport , serviceRetryCommand , serviceStatusSummary , stableLauncherEntry , systemdNeedsDaemonReload , systemdServiceInstallCleanupOps , uninstallSystemd , windowsListenPort , winswListenPort , startLaunchd , windowsTaskRegistrationHealthy } from "../src/service" ;
10+ import { assertServiceAuthEnvironment , assertServiceEnvironmentMatchesInstall , bakedServicePathsDiagnostic , buildPlist , buildUnit , buildWindowsLauncherVbs , buildWindowsSchtasksCreateArgs , buildWindowsSchtasksCreateArgsForXml , buildWindowsServiceScript , buildWindowsTaskXml , confirmServiceServing , deriveWindowsServiceDiagnostic , deriveWindowsServiceDiagnosticForCurrentUser , installFreshWindowsSchedulerSafely , installServiceSafely , launchctlLoadFailed , launchdJobMatchesPlist , launchdListenPort , normalizeServiceSubcommand , parseServiceArgs , parseServiceInstallState , planServiceCommand , prepareServiceInstall , probeServiceInstallation , readWindowsSchedulerXmlState , registerFreshWindowsSchedulerTask , removeNativeWindowsServiceForScheduler , repairService , resolveServiceListenPort , runLaunchctl , selectServiceSubcommand , SERVICE_INSTALL_HEALTH_MS , serviceInstallHealthMs , serviceLogPath , serviceRetryCommand , serviceStartableFromTray , serviceStatusReport , serviceStatusSummary , stableLauncherEntry , startLaunchd , systemdListenPort , systemdNeedsDaemonReload , systemdServiceInstallCleanupOps , uninstallSystemd , windowsListenPort , windowsTaskRegistrationHealthy , winswListenPort } from "../src/service" ;
1111import type { ServiceDiagnostic } from "../src/service" ;
1212import { definitionCarriesCredential , resolvedProxyEnv , writeServiceDefinitionFile } from "../src/service" ;
1313import { buildWinswXml } from "../src/lib/winsw" ;
@@ -3142,9 +3142,52 @@ describe("service serving confirmation", () => {
31423142 now : ( ) => 0 ,
31433143 timeoutMs : 0 ,
31443144 } ) ;
3145- expect ( probes ) . toBe ( 1 ) ;
3145+ // At least once, which is what the name asks: a zero budget must not
3146+ // return without knocking. The exact count is not the contract — the
3147+ // deadline grace probe adds one when the caller did give it time.
3148+ expect ( probes ) . toBeGreaterThanOrEqual ( 1 ) ;
3149+ } ) ;
3150+
3151+ // #3009: a Windows cold start does NTFS ACL hardening and journal recovery
3152+ // before the listener exists, so the service can bind seconds after the
3153+ // deadline and then stay healthy. `ocx service repair` reported that as a
3154+ // terminal failure with exit 1, and the caller's fallback is to start a
3155+ // second proxy against a port that is about to be taken.
3156+ test ( "accepts a service that binds during the grace after the deadline" , async ( ) => {
3157+ let now = 0 ;
3158+ let probes = 0 ;
3159+ const out = await confirmServiceServing ( {
3160+ port : 10100 ,
3161+ // Answers only once the clock is past the deadline, which is the shape
3162+ // the report describes: healthy, just not within the budget.
3163+ probe : async ( ) => { probes += 1 ; return now > 2_000 ; } ,
3164+ sleep : async ms => { now += ms ; } ,
3165+ now : ( ) => now ,
3166+ timeoutMs : 2_000 ,
3167+ } ) ;
3168+ expect ( out ) . toEqual ( { ok : true , port : 10100 } ) ;
3169+ expect ( probes ) . toBeGreaterThan ( 1 ) ;
31463170 } ) ;
31473171
3172+ test ( "still fails a service that never binds" , async ( ) => {
3173+ let now = 0 ;
3174+ const out = await confirmServiceServing ( {
3175+ port : 10100 ,
3176+ probe : async ( ) => false ,
3177+ sleep : async ms => { now += ms ; } ,
3178+ now : ( ) => now ,
3179+ timeoutMs : 2_000 ,
3180+ } ) ;
3181+ expect ( out ) . toEqual ( { ok : false , port : 10100 } ) ;
3182+ } ) ;
3183+
3184+ // Windows is the platform the extra budget exists for; everything else keeps
3185+ // the original 20s so this cannot slow a healthy Linux install down.
3186+ test ( "gives Windows a longer cold-start budget than the other platforms" , ( ) => {
3187+ expect ( serviceInstallHealthMs ( "win32" ) ) . toBeGreaterThan ( serviceInstallHealthMs ( "linux" ) ) ;
3188+ expect ( serviceInstallHealthMs ( "linux" ) ) . toBe ( SERVICE_INSTALL_HEALTH_MS ) ;
3189+ expect ( serviceInstallHealthMs ( "darwin" ) ) . toBe ( SERVICE_INSTALL_HEALTH_MS ) ;
3190+ } ) ;
31483191 // A service reinstall invalidates the pidfile, so resolving the target through
31493192 // it (findLiveProxy) would report a serving service as dead. Ask the baked port.
31503193 test ( "probes the port it was given rather than resolving one" , async ( ) => {
0 commit comments