Skip to content

The agent that grows with you

test: isolate PM plugin fixtures and remove timing and thread contention

ethernete7f9b865f959
diff --git a/apps/desktop/src/app/settings/model-settings.test.tsx b/apps/desktop/src/app/settings/model-settings.test.tsx
index e9c914d7f63..5da2a20c5d8 100644
--- a/apps/desktop/src/app/settings/model-settings.test.tsx
+++ b/apps/desktop/src/app/settings/model-settings.test.tsx
@@ -5,6 +5,10 @@ import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vite
import type * as ConfigApi from '@/api/config'
+// Import during collection: a cold transform under CI load must not consume
+// the first profile-scope test's timeout before the component even renders.
+import { ModelSettings } from './model-settings'
+
// Radix Select calls scrollIntoView on its items when the content opens; jsdom
// doesn't implement it (nor hasPointerCapture / releasePointerCapture), so stub
// them to let the dropdown open in tests.
@@ -91,8 +95,7 @@ afterEach(() => {
profileSwitchHandler = null
})
-async function renderModelSettings(scopeProfile?: string) {
- const { ModelSettings } = await import('./model-settings')
+function renderModelSettings(scopeProfile?: string): ReturnType<typeof render> {
const client = new QueryClient({ defaultOptions: { queries: { retry: false } } })
return render(
@@ -112,7 +115,7 @@ describe('ModelSettings profile scope', () => {
// `undefined`, or every read repaints the primary's model and the user's
// change looks reverted.
it('follows the active profile (undefined, never null) when unscoped', async () => {
- await renderModelSettings()
+ renderModelSettings()
await waitFor(() => expect(getGlobalModelInfo).toHaveBeenCalledWith(undefined))
expect(getGlobalModelOptions).toHaveBeenCalledWith(undefined, undefined)
@@ -121,7 +124,7 @@ describe('ModelSettings profile scope', () => {
})
it('reads through the explicit scope override when one is set', async () => {
- await renderModelSettings('research')
+ renderModelSettings('research')
await waitFor(() => expect(getGlobalModelInfo).toHaveBeenCalledWith('research'))
expect(getGlobalModelOptions).toHaveBeenCalledWith(undefined, 'research')
@@ -132,7 +135,7 @@ describe('ModelSettings profile scope', () => {
describe('ModelSettings', () => {
it('loads the current main model and lists configured providers only', async () => {
- await renderModelSettings()
+ renderModelSettings()
await waitFor(() => expect(getGlobalModelInfo).toHaveBeenCalled())
await waitFor(() => expect(getGlobalModelOptions).toHaveBeenCalled())
@@ -152,7 +155,7 @@ describe('ModelSettings', () => {
getGlobalModelInfo.mockResolvedValueOnce({ provider, model: '' })
getGlobalModelOptions.mockResolvedValueOnce({ providers: [] })
- await renderModelSettings()
+ renderModelSettings()
const providerSelect = (await screen.findAllByRole('combobox'))[0]
@@ -172,7 +175,7 @@ describe('ModelSettings', () => {
getGlobalModelInfo.mockResolvedValueOnce({ provider: 'retired-provider', model: '' })
getGlobalModelOptions.mockResolvedValueOnce({ providers: [] })
- await renderModelSettings()
+ renderModelSettings()
fireEvent.click(await screen.findByRole('button', { name: 'Set up provider' }))
@@ -195,7 +198,7 @@ describe('ModelSettings', () => {
]
})
- await renderModelSettings()
+ renderModelSettings()
fireEvent.click(await screen.findByRole('button', { name: 'Set up Anthropic' }))
@@ -231,7 +234,7 @@ describe('ModelSettings', () => {
]
})
- await renderModelSettings()
+ renderModelSettings()
expect((await screen.findAllByRole('combobox'))[0].textContent).toContain('Custom A')
await act(async () => {
@@ -269,7 +272,7 @@ describe('ModelSettings', () => {
gateway_tools: []
})
- await renderModelSettings()
+ renderModelSettings()
const providerSelect = (await screen.findAllByRole('combobox'))[0]
fireEvent.click(providerSelect)
@@ -299,7 +302,7 @@ describe('ModelSettings', () => {
agent: { reasoning_effort: 'medium', service_tier: 'normal' },
auxiliary: { curator: { provider: 'auto', model: '', reasoning_effort: 'high' } }
})
- await renderModelSettings()
+ renderModelSettings()
await waitFor(() => expect(getHermesConfigRecord).toHaveBeenCalled())
const fastSwitch = await screen.findByRole('switch')
@@ -321,14 +324,14 @@ describe('ModelSettings', () => {
]
})
- await renderModelSettings()
+ renderModelSettings()
await waitFor(() => expect(getHermesConfigRecord).toHaveBeenCalled())
expect(screen.queryByRole('switch')).toBeNull()
})
it('renders the auxiliary task rows', async () => {
- await renderModelSettings()
+ renderModelSettings()
expect(await screen.findByText('Vision')).toBeTruthy()
// #97297 — the three canonical slots the backend serves must have rows too.
@@ -344,7 +347,7 @@ describe('ModelSettings', () => {
tasks: [{ task: 'vision', provider: 'nous', model: 'hermes-4', base_url: '', reasoning_effort: null }]
})
- await renderModelSettings()
+ renderModelSettings()
expect(screen.queryByRole('combobox', { name: 'Vision reasoning effort' })).toBeNull()
@@ -373,7 +376,7 @@ describe('ModelSettings', () => {
})
it('assigns an auxiliary task to the main model via setModelAssignment', async () => {
- await renderModelSettings()
+ renderModelSettings()
// One "Set to main" button per task slot; the first is Vision.
const setToMainButtons = await screen.findAllByRole('button', { name: 'Set to main' })
@@ -408,7 +411,7 @@ describe('ModelSettings', () => {
tasks: [{ task: 'vision', provider: 'auto', model: '', base_url: '' }]
})
- await renderModelSettings()
+ renderModelSettings()
const setToMainButtons = await screen.findAllByRole('button', { name: 'Set to main' })
fireEvent.click(setToMainButtons[0])
@@ -433,7 +436,7 @@ describe('ModelSettings', () => {
stale_aux: [{ task: 'compression', provider: 'nous', model: 'hermes-4' }]
})
- await renderModelSettings()
+ renderModelSettings()
await waitFor(() => expect(getGlobalModelInfo).toHaveBeenCalled())
const applyButton = await screen.findByRole('button', { name: 'Apply' })
@@ -450,7 +453,7 @@ describe('ModelSettings', () => {
tasks: [{ task: 'curator', provider: 'openrouter', model: 'anthropic/claude-opus-4.7', base_url: '' }]
})
- await renderModelSettings()
+ renderModelSettings()
// Banner present on load, no switch required.
expect(await screen.findByText(/still run on/)).toBeTruthy()
@@ -462,7 +465,7 @@ describe('ModelSettings', () => {
tasks: [{ task: 'vision', provider: 'main', model: 'kimi-k3', base_url: '' }]
})
- await renderModelSettings()
+ renderModelSettings()
await screen.findAllByRole('button', { name: 'Set to main' })
// 'main' is a backend-supported alias that tracks the active main provider
@@ -491,7 +494,7 @@ describe('ModelSettings', () => {
]
})
- await renderModelSettings()
+ renderModelSettings()
// The public custom endpoint still bills a provider, so the banner stays —
// but it names only that one task, not the free LAN pin.
@@ -552,7 +555,7 @@ describe('ModelSettings MoA preset editor', () => {
})
async function openReferenceEditor() {
- await renderModelSettings()
+ renderModelSettings()
expect(await screen.findByText('Reference 1')).toBeTruthy()
}
@@ -703,7 +706,7 @@ describe('ModelSettings code-skew 503', () => {
it('unwraps the stale-backend 503 instead of dumping IPC JSON', async () => {
getGlobalModelOptions.mockRejectedValueOnce(skewError)
- await renderModelSettings()
+ renderModelSettings()
await waitFor(() => {
expect(screen.getByText(/running old code after an update/i)).toBeTruthy()
@@ -722,7 +725,7 @@ describe('ModelSettings code-skew 503', () => {
getGlobalModelOptions.mockRejectedValueOnce(skewError)
- await renderModelSettings()
+ renderModelSettings()
await waitFor(() => expect(screen.getByRole('button', { name: 'Restart backend' })).toBeTruthy())
fireEvent.click(screen.getByRole('button', { name: 'Restart backend' }))
diff --git a/tests/gateway/test_gateway_shutdown.py b/tests/gateway/test_gateway_shutdown.py
index 3e9f7ab237d..db07059ebc9 100644
--- a/tests/gateway/test_gateway_shutdown.py
+++ b/tests/gateway/test_gateway_shutdown.py
@@ -171,26 +171,48 @@ async def test_planned_service_exit_issues_no_restart_of_its_own(monkeypatch):
@pytest.mark.asyncio
async def test_unexpected_signal_starts_teardown_after_bounded_interrupt_grace():
+ from types import SimpleNamespace
+
runner, adapter = make_restart_runner()
runner._restart_drain_timeout = 0.0
runner._signal_initiated_shutdown = True
- runner._signal_interrupt_grace_timeout = 0.01
- runner._running_agents = {"session": MagicMock()}
+ runner._signal_interrupt_grace_timeout = 0.25
+ running_agent = MagicMock()
+ runner._running_agents = {"session": running_agent}
+ now = 0.0
+ sleeps = []
disconnect_started = asyncio.Event()
+ async def advance_grace(delay):
+ nonlocal now
+ assert running_agent.interrupt.called
+ assert not disconnect_started.is_set()
+ sleeps.append(delay)
+ now += delay
+ await asyncio.sleep(0)
+
async def disconnect():
+ assert runner._running_agents == {"session": running_agent}
disconnect_started.set()
adapter.disconnect = disconnect
+ # Advance only the shutdown clock. Real cleanup and executor scheduling do not
+ # consume the grace budget, and asyncio's own deadlines keep their real clock.
+ shutdown_asyncio = SimpleNamespace(**vars(asyncio))
+ shutdown_asyncio.get_running_loop = lambda: SimpleNamespace(time=lambda: now)
+ shutdown_asyncio.sleep = advance_grace
- with patch("gateway.status.remove_pid_file"), patch(
- "gateway.status.publish_runtime_status"
+ with (
+ patch("gateway.status.remove_pid_file"),
+ patch("gateway.status.publish_runtime_status"),
+ patch("gateway.run_shutdown.asyncio", shutdown_asyncio),
):
- stop_task = asyncio.create_task(runner.stop())
- await asyncio.wait_for(disconnect_started.wait(), timeout=0.75)
- await stop_task
+ await asyncio.wait_for(runner.stop(), timeout=10)
+ assert sleeps
+ assert sum(sleeps[:-1]) < runner._signal_interrupt_grace_timeout <= now
+ assert disconnect_started.is_set()
assert runner._shutdown_event.is_set() is True
diff --git a/tests/hermes_cli/test_enable_no_capabilities.py b/tests/hermes_cli/test_enable_no_capabilities.py
index 7aa06d5cd8c..71c92ceb54e 100644
--- a/tests/hermes_cli/test_enable_no_capabilities.py
+++ b/tests/hermes_cli/test_enable_no_capabilities.py
@@ -4,6 +4,11 @@ from unittest.mock import MagicMock
import pytest
import hermes_yaml as yaml
+from tests.hermes_cli.plugin_worker_support import (
+ isolated_python as isolated_python,
+ plugin_world as plugin_world,
+)
+
@pytest.mark.parametrize(
"caps,flag,existing,answer,expected,prompts",
@@ -16,9 +21,9 @@ import hermes_yaml as yaml
(["tools.override"], None, None, "y", True, 1),
],
)
-def test_enable_consent(tmp_path, monkeypatch, caps, flag, existing, answer, expected, prompts):
- monkeypatch.setenv("HERMES_HOME", str(tmp_path))
- plugin = tmp_path / "plugins" / "hook-only-probe"
+def test_enable_consent(plugin_world, monkeypatch, caps, flag, existing, answer, expected, prompts):
+ home = plugin_world.home
+ plugin = home / "plugins" / "hook-only-probe"
plugin.mkdir(parents=True)
manifest = {"name": "hook-only-probe", "version": "0.1.0", "hooks": ["transform_llm_output"]}
if caps is not None:
@@ -28,7 +33,7 @@ def test_enable_consent(tmp_path, monkeypatch, caps, flag, existing, answer, exp
initial = {} if existing is None else {
"plugins": {"entries": {"hook-only-probe": {"allow_tool_override": existing}}}
}
- (tmp_path / "config.yaml").write_text(yaml.safe_dump(initial), encoding="utf-8")
+ (home / "config.yaml").write_text(yaml.safe_dump(initial), encoding="utf-8")
from hermes_cli import plugins_cmd
console = MagicMock()
@@ -38,7 +43,7 @@ def test_enable_consent(tmp_path, monkeypatch, caps, flag, existing, answer, exp
monkeypatch.setattr("sys.stdout.isatty", lambda: True)
plugins_cmd.cmd_enable("hook-only-probe", allow_tool_override=flag)
assert console.input.call_count == prompts
- config = yaml.safe_load((tmp_path / "config.yaml").read_text(encoding="utf-8"))
+ config = yaml.safe_load((home / "config.yaml").read_text(encoding="utf-8"))
assert "hook-only-probe" in config["plugins"]["enabled"]
entry = config["plugins"].get("entries", {}).get("hook-only-probe", {})
assert entry.get("allow_tool_override") is expected
diff --git a/tests/hermes_cli/test_plugin_install_ref.py b/tests/hermes_cli/test_plugin_install_ref.py
index 7f62de6039d..f7588da4f45 100644
--- a/tests/hermes_cli/test_plugin_install_ref.py
+++ b/tests/hermes_cli/test_plugin_install_ref.py
@@ -4,18 +4,27 @@ from __future__ import annotations
import argparse
import json
-import shutil
import subprocess
from pathlib import Path
import pytest
-from tests.pm._fixtures import isolated_python # noqa: F401
+from tests.hermes_cli.plugin_worker_support import (
+ isolated_python as isolated_python,
+ plugin_world as plugin_world,
+)
import hermes_yaml as yaml
from hermes_cli.subcommands.plugins import build_plugins_parser
[email protected](autouse=True)
+def _offline_pm(plugin_world):
+ # Keep real worker publication/rollback, without provisioning pinned tools
+ # into every temporary home. These installs start with no plugin selection.
+ (plugin_world.home / "config.yaml").unlink()
+
+
def _git(repo: Path, *args: str) -> str:
result = subprocess.run(
["git", *args], cwd=repo, check=True, capture_output=True, text=True
diff --git a/tests/tools/test_image_source.py b/tests/tools/test_image_source.py
index 5b410250bea..d4c0a07647b 100644
--- a/tests/tools/test_image_source.py
+++ b/tests/tools/test_image_source.py
@@ -543,7 +543,12 @@ class TestHeicDetection:
monkeypatch.setenv("TERMINAL_ENV", "local")
heic = tmp_path / "photo.heic"
- Image.new("RGB", (8, 8), (120, 60, 200)).save(str(heic), format="HEIF")
+ # x265's default CPU-sized pool can exhaust CI threads and hang the encoder.
+ # This fixture needs one worker, not a pool per parallel test process.
+ Image.new("RGB", (8, 8), (120, 60, 200)).save(
+ str(heic), format="HEIF",
+ enc_params={"x265:pools": "none", "x265:frame-threads": "1"},
+ )
res = await isrc.resolve_image_source(str(heic), isrc.ResolveContext())
assert res.mime == "image/heic"