|
9 | 9 | extractJsonBlock, |
10 | 10 | generateHermesConfig, |
11 | 11 | incompleteOutputReason, |
| 12 | + stripShutdownNoise, |
12 | 13 | } from './agent.utility.js'; |
13 | 14 |
|
14 | 15 | describe('buildVerifySpec', () => { |
@@ -282,3 +283,41 @@ describe('eventInsertRows', () => { |
282 | 283 | expect(rows.map((r) => r.seq)).toEqual([5, 6]); |
283 | 284 | }); |
284 | 285 | }); |
| 286 | + |
| 287 | +describe('stripShutdownNoise', () => { |
| 288 | + const STANZA = [ |
| 289 | + 'Exception ignored in: <generator object Langfuse._create_span_with_parent_context at 0x7f04789a74c0>', |
| 290 | + 'Traceback (most recent call last):', |
| 291 | + ' File "/usr/local/lib/hermes-agent/venv/lib/python3.11/site-packages/langfuse/_client/client.py", line 1196, in _create_span_with_parent_context', |
| 292 | + ' File "/usr/local/share/uv/python/cpython-3.11.15/lib/python3.11/contextlib.py", line 158, in __exit__', |
| 293 | + ' File "/usr/local/lib/hermes-agent/venv/lib/python3.11/site-packages/opentelemetry/trace/__init__.py", line 616, in use_span', |
| 294 | + 'TypeError: isinstance() arg 2 must be a type, a tuple of types, or a union', |
| 295 | + ].join('\n'); |
| 296 | + |
| 297 | + it('removes the langfuse shutdown stanza while keeping surrounding output', () => { |
| 298 | + const input = `real warning line\n${STANZA}\nanother real line`; |
| 299 | + const out = stripShutdownNoise(input); |
| 300 | + |
| 301 | + expect(out).toContain('real warning line'); |
| 302 | + expect(out).toContain('another real line'); |
| 303 | + expect(out).not.toContain('isinstance() arg 2'); |
| 304 | + expect(out).not.toContain('_create_span_with_parent_context'); |
| 305 | + expect(out).not.toContain('Traceback'); |
| 306 | + }); |
| 307 | + |
| 308 | + it('leaves a genuine error traceback untouched', () => { |
| 309 | + const realError = [ |
| 310 | + 'Traceback (most recent call last):', |
| 311 | + ' File "app.py", line 10, in <module>', |
| 312 | + 'ValueError: something actually broke', |
| 313 | + ].join('\n'); |
| 314 | + |
| 315 | + expect(stripShutdownNoise(realError)).toBe(realError); |
| 316 | + }); |
| 317 | + |
| 318 | + it('is a no-op when the stanza is absent', () => { |
| 319 | + expect(stripShutdownNoise('plain stderr\n[worker_guard] capped read_file')).toBe( |
| 320 | + 'plain stderr\n[worker_guard] capped read_file', |
| 321 | + ); |
| 322 | + }); |
| 323 | +}); |
0 commit comments