When code changes affect what the app sends (RPC/HTTP payloads/options) or what the app decides based on the environment, add targeted tests that (1) assert the exact externally observable behavior and (2) make the inputs deterministic.
Practical rules:
session.create), write a regression test that triggers the path (e.g., via the hook) and asserts the exact payload contains the new field/value.timeoutMs), add a focused unit test that calls the wrapper (or mounts the relevant layer) and asserts the options passed to the underlying API client.Example (Vitest-style contract assertion):
import { describe, it, expect, vi } from 'vitest'
import { renderHook } from '@testing-library/react'
import { useSessionLifecycle } from './useSessionLifecycle'
vi.mock('../rpc', () => ({
rpc: vi.fn(),
}))
it('sends launch cwd in session.create payload', async () => {
process.env.HERMES_CWD = '/expected/launch/dir'
const { rpc } = await import('../rpc')
;(rpc as unknown as ReturnType<typeof vi.fn>).mockResolvedValue({ /* ... */ })
const { result } = renderHook(() =>
useSessionLifecycle({ /* required opts */ })
)
await result.current.newSession(/* args that lead to startNewSession */)
expect(rpc).toHaveBeenCalledWith('session.create', expect.objectContaining({
cwd: '/expected/launch/dir',
}))
})
Apply the same pattern to wrapper options (assert timeoutMs) and to environment detection (inject sysfs/DMI inputs rather than reading the host).
Enter the URL of a public GitHub repository