T-16: M0.1b — Make repo-wide bun test green: fix queue, shutdown-signal and research-workflow test failures

This commit is contained in:
Studio 2026-11-27 12:01:06 -05:00
parent 890761e0d5
commit 9c4e87cdfd
17 changed files with 366 additions and 266 deletions

View file

@ -15,6 +15,7 @@ export class Shutdown {
private shutdownTimeout: number;
private callbacks: CallbackEntry[] = [];
private signalHandlersRegistered = false;
private registeredSignalHandlers = new Map<NodeJS.Signals, () => void>();
private shutdownPromise: Promise<void> | null = null;
private triggerSignal: string | null = null;
@ -33,6 +34,37 @@ export class Shutdown {
return Shutdown.instance;
}
/**
* Dispose the singleton instance and remove its signal listeners.
*/
static reset(): void {
if (Shutdown.instance) {
Shutdown.instance.dispose();
Shutdown.instance = null;
}
}
/**
* Remove process signal handlers registered by this instance.
*/
removeSignalHandlers(): void {
for (const [signal, listener] of this.registeredSignalHandlers) {
process.off(signal, listener);
}
this.registeredSignalHandlers.clear();
this.signalHandlersRegistered = false;
}
/**
* Clean up signal listeners and clear singleton reference if this is the active singleton.
*/
dispose(): void {
this.removeSignalHandlers();
if (Shutdown.instance === this) {
Shutdown.instance = null;
}
}
/**
* Get current shutdown status
*/
@ -153,7 +185,7 @@ export class Shutdown {
signals.forEach(signal => {
// Use process.on instead of process.once to handle multiple signals
process.on(signal, async () => {
const listener = async () => {
this.logger.info(`Received ${signal} signal`);
// If already shutting down, ignore the signal
@ -178,7 +210,10 @@ export class Shutdown {
process.exit(1);
}
});
};
this.registeredSignalHandlers.set(signal, listener);
process.on(signal, listener);
this.logger.debug(`Registered handler for ${signal}`);
});