The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
test(inference): address review — assertable templates, a real precondition, offline Ollama
M3gA-Mindb74e3a7c887d
diff --git a/app/src/components/settings/panels/__tests__/EmbeddingsSetupModal.test.tsx b/app/src/components/settings/panels/__tests__/EmbeddingsSetupModal.test.tsxindex fc69eba4c1..52553fc120 100644--- a/app/src/components/settings/panels/__tests__/EmbeddingsSetupModal.test.tsx+++ b/app/src/components/settings/panels/__tests__/EmbeddingsSetupModal.test.tsx@@ -15,7 +15,24 @@ import type {} from '../../../../services/api/embeddingsApi';import EmbeddingsSetupModal, { type EmbeddingsSetupModalProps } from '../EmbeddingsSetupModal';-vi.mock('../../../../lib/i18n/I18nContext', () => ({ useT: () => ({ t: (key: string) => key }) }));+/**+ * The mock returns the key for most lookups, which keeps assertions readable.+ * Two keys are the exception: `testSuccess` and `testFailed` are TEMPLATES that+ * the component fills with `.replace('{dims}', …)` / `.replace('{error}', …)`+ * (`EmbeddingsSetupModal.tsx:191-195`). Returning the bare key there makes+ * `.replace()` a no-op, so the substituted value never reaches the DOM and a+ * component that stopped surfacing it would keep the test green. Returning the+ * real templates (from `en.ts`) is what makes the substitution assertable.+ */+vi.mock('../../../../lib/i18n/I18nContext', () => ({+ useT: () => ({+ t: (key: string) => {+ if (key === 'settings.embeddings.testSuccess') return 'Connected: {dims} dimensions';+ if (key === 'settings.embeddings.testFailed') return 'Failed: {error}';+ return key;+ },+ }),+}));const provider = (over: Partial<EmbeddingProviderEntry> = {}): EmbeddingProviderEntry => ({slug: 'openai',@@ -155,12 +172,17 @@ describe('EmbeddingsSetupModal — feedback', () => {it('reports a successful test with the dimensions the provider returned', () => {renderModal({ setupTestResult: result({ actual_dimensions: 1536 }) });- expect(screen.getByText('settings.embeddings.testSuccess')).toBeInTheDocument();+ expect(screen.getByText('Connected: 1536 dimensions')).toBeInTheDocument();+ });++ it('falls back to ? when the provider reports no dimension count', () => {+ renderModal({ setupTestResult: result({ actual_dimensions: undefined }) });+ expect(screen.getByText('Connected: ? dimensions')).toBeInTheDocument();});- it('reports a failed test', () => {+ it('reports a failed test with the provider error', () => {renderModal({ setupTestResult: result({ success: false, error: 'bad key' }) });- expect(screen.getByText('settings.embeddings.testFailed')).toBeInTheDocument();+ expect(screen.getByText('Failed: bad key')).toBeInTheDocument();});it('surfaces a save error verbatim', () => {@@ -168,7 +190,9 @@ describe('EmbeddingsSetupModal — feedback', () => {expect(screen.getByText('could not write config')).toBeInTheDocument();});- it('shows progress labels and locks both buttons while testing', () => {+ // Testing locks the Test button only — Save stays live on purpose, so a user+ // who has already pasted a working key is not blocked behind a slow probe.+ it('locks Test but leaves Save available while a test is running', () => {renderModal({ setupKey: 'sk-live', setupTesting: true });expect(screen.getByRole('button', { name: 'settings.embeddings.testing' })).toBeDisabled();diff --git a/app/src/components/settings/panels/__tests__/ProviderSetupErrorNotice.test.tsx b/app/src/components/settings/panels/__tests__/ProviderSetupErrorNotice.test.tsxindex 03be772a71..a8704610d2 100644--- a/app/src/components/settings/panels/__tests__/ProviderSetupErrorNotice.test.tsx+++ b/app/src/components/settings/panels/__tests__/ProviderSetupErrorNotice.test.tsx@@ -110,6 +110,27 @@ describe('presentProviderSetupError', () => {expect(summary).toBe('Provider setup failed.');});+ // CHARACTERISES A GAP, not desired behaviour. `presentProviderSetupError`+ // performs no redaction: `findProviderJsonMessage` lifts the provider's+ // `message` verbatim and `details` is the raw error. The backend redacts a+ // fixed set of known token prefixes, so a CUSTOM provider echoing an+ // arbitrary-shaped credential reaches the DOM intact.+ //+ // Pinned so the gap is visible and regression-locked rather than implied.+ // Redacting at this boundary is a product change — it would also hide+ // diagnostics a user may need — so it belongs in its own PR, not in a+ // test-only one. Recorded in ~/tinyhuman/bugs/W1-ui-bugs.md. When redaction+ // lands, invert these assertions.+ it('echoes an arbitrary provider credential verbatim (known gap)', () => {+ const secret = 'zz-corp-9f8e7d6c5b4a3210';+ const { summary, details } = present(+ `Could not reach CustomLLM: {"error":{"message":"Invalid token: ${secret}"}}`+ );++ expect(summary).toContain(secret);+ expect(details).toContain(secret);+ });+it('preserves the raw error as details, untouched', () => {const raw = 'Could not reach OpenAI: provider returned 401 {"message":"nope"}';expect(present(raw).details).toBe(raw);diff --git a/app/src/pages/dev/__tests__/AgentInsightsPreview.test.tsx b/app/src/pages/dev/__tests__/AgentInsightsPreview.test.tsxindex 40eb87362e..31e063ef0c 100644--- a/app/src/pages/dev/__tests__/AgentInsightsPreview.test.tsx+++ b/app/src/pages/dev/__tests__/AgentInsightsPreview.test.tsx@@ -78,14 +78,23 @@ describe('AgentInsightsPreview', () => {expect(running.some(e => e.status === 'running')).toBe(true);expect(running.some(e => e.status === 'success')).toBe(true);expect(running.some(e => e.subagent)).toBe(true);+ expect(running.some(e => e.status === 'error')).toBe(true);});it('settles every non-error entry to success and leaves errors alone', () => {const { running, settled } = renderPreview();+ // Precondition, not decoration: the "leaves errors alone" half of this test+ // only exercises anything if the fixture actually contains an error entry.+ // Without this, removing the error fixture (or flipping it to 'success')+ // would leave the test green while it silently stopped checking+ // preservation at all.+ expect(running.some(e => e.status === 'error')).toBe(true);+settled.forEach((entry, i) => {expect(entry.status).toBe(running[i].status === 'error' ? 'error' : 'success');});+ expect(settled.some(e => e.status === 'error')).toBe(true);expect(settled.some(e => e.status === 'running')).toBe(false);});diff --git a/tests/raw_coverage/inference_local_controllers_rpc_raw_coverage_e2e.rs b/tests/raw_coverage/inference_local_controllers_rpc_raw_coverage_e2e.rsindex ebe4b83c58..a17f7ed301 100644--- a/tests/raw_coverage/inference_local_controllers_rpc_raw_coverage_e2e.rs+++ b/tests/raw_coverage/inference_local_controllers_rpc_raw_coverage_e2e.rs@@ -27,8 +27,20 @@//!//! # Offline discipline//!-//! Temp workspaces, a temp PATH, and a stub `piper` shell script only. Nothing-//! here starts a server, opens a socket, or downloads an asset: the download and+//! Temp workspaces, a temp PATH, and a stub `piper` shell script only.+//!+//! Two of these controllers (`assets_status`, `downloads_progress`) reach+//! `LocalAiService::assets_status`, which probes `GET {ollama_base_url}/api/tags`+//! with a two-second timeout. That base URL defaults to `localhost:11434` and is+//! also taken from the ambient `OLLAMA_HOST`, so without pinning it this suite+//! would make real socket calls — behaving differently on a machine that+//! happens to be running Ollama, and costing up to two seconds per call. Every+//! test therefore pins `OPENHUMAN_OLLAMA_BASE_URL` (the app-specific override,+//! `ollama.rs:76`) to a closed loopback port and clears `OLLAMA_HOST`, so the+//! probe is refused immediately and deterministically.+//!+//! Beyond that, nothing here starts a server, opens a listening socket, or+//! downloads an asset: the download and//! STT paths are driven to their *rejection* branches on purpose, because the//! bundled whisper.cpp engine was deleted and `transcribe` is now a hosted proxy//! call with no local binary to stub — see the note at@@ -92,6 +104,19 @@ impl Drop for EnvVarGuard {}}+/// Point the Ollama health probe at a closed loopback port and clear the+/// ambient override, so `assets_status` fails its probe instantly instead of+/// dialling a real service (or waiting out a two-second timeout).+///+/// Port 9 is the discard port: nothing listens, so connect() is refused rather+/// than hanging. Returned as guards — hold them for the life of the test.+fn pin_offline_ollama() -> (EnvVarGuard, EnvVarGuard) {+ (+ EnvVarGuard::set("OPENHUMAN_OLLAMA_BASE_URL", "http://127.0.0.1:9"),+ EnvVarGuard::unset("OLLAMA_HOST"),+ )+}+fn controller<'a>(controllers: &'a [RegisteredController],function: &str,@@ -433,6 +458,9 @@ async fn inference_transcribe_controllers_cover_params_trimming_and_local_reject#[tokio::test]async fn inference_download_asset_controller_covers_disabled_unknown_and_case_folding() {let _lock = env_lock();+ // `download_asset` ends in `assets_status`, which probes Ollama — pin it+ // even though every branch asserted here errors before reaching that call.+ let _ollama = pin_offline_ollama();let tmp = tempdir().expect("tempdir");let mut config = temp_config(&tmp);config.local_ai.runtime_enabled = false;@@ -570,6 +598,7 @@ async fn inference_agent_chat_simple_controller_covers_params_and_prompt_guard()#[tokio::test]async fn inference_status_controllers_tolerate_extra_params_and_reject_bad_urls() {let _lock = env_lock();+ let _ollama = pin_offline_ollama();let tmp = tempdir().expect("tempdir");let mut config = temp_config(&tmp);config.local_ai.runtime_enabled = false;