@outputai/core 0.7.1-next.ed233ce.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@outputai/core",
3
- "version": "0.7.1-next.ed233ce.0",
3
+ "version": "0.8.0",
4
4
  "description": "The core module of the output framework",
5
5
  "type": "module",
6
6
  "exports": {
@@ -3,6 +3,7 @@ import { createChildLogger } from '#logger';
3
3
  const log = createChildLogger( 'Interruption' );
4
4
 
5
5
  const FORCE_QUIT_GRACE_MS = 1000;
6
+ const INTERRUPTION_SIGNALS = [ 'SIGTERM', 'SIGINT', 'SIGUSR2' ];
6
7
 
7
8
  export const setupInterruptionHandler = cb => {
8
9
  const state = { interruptionReceivedAt: null };
@@ -28,6 +29,5 @@ export const setupInterruptionHandler = cb => {
28
29
  cb();
29
30
  };
30
31
 
31
- process.on( 'SIGTERM', () => handle( 'SIGTERM' ) );
32
- process.on( 'SIGINT', () => handle( 'SIGINT' ) );
32
+ INTERRUPTION_SIGNALS.forEach( signal => process.on( signal, () => handle( signal ) ) );
33
33
  };
@@ -29,11 +29,12 @@ describe( 'setupInterruptionHandler', () => {
29
29
  process.exit = originalExit;
30
30
  } );
31
31
 
32
- it( 'registers SIGTERM and SIGINT handlers', () => {
32
+ it( 'registers interruption signal handlers', () => {
33
33
  setupInterruptionHandler( callback );
34
34
 
35
35
  expect( process.on ).toHaveBeenCalledWith( 'SIGTERM', expect.any( Function ) );
36
36
  expect( process.on ).toHaveBeenCalledWith( 'SIGINT', expect.any( Function ) );
37
+ expect( process.on ).toHaveBeenCalledWith( 'SIGUSR2', expect.any( Function ) );
37
38
  } );
38
39
 
39
40
  it( 'logs and invokes callback on first SIGTERM', () => {
@@ -58,6 +59,17 @@ describe( 'setupInterruptionHandler', () => {
58
59
  expect( exitMock ).not.toHaveBeenCalled();
59
60
  } );
60
61
 
62
+ it( 'logs and invokes callback on first SIGUSR2', () => {
63
+ setupInterruptionHandler( callback );
64
+
65
+ onHandlers.SIGUSR2();
66
+
67
+ expect( mockLog.info ).toHaveBeenCalledWith( 'Signal Received', { signal: 'SIGUSR2' } );
68
+ expect( mockLog.warn ).toHaveBeenCalledWith( 'Initiating shutdown...' );
69
+ expect( callback ).toHaveBeenCalledOnce();
70
+ expect( exitMock ).not.toHaveBeenCalled();
71
+ } );
72
+
61
73
  it( 'ignores a second signal received within the grace period', () => {
62
74
  vi.useFakeTimers();
63
75
  setupInterruptionHandler( callback );