Skip to content

Commit 1fd914f

Browse files
committed
fix(sim-setup): don't probe a Compose-internal Ollama from the host
1 parent 9f13dd7 commit 1fd914f

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

‎packages/sim-setup/src/checks.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,18 @@ describe("doctor probing a Compose install's host Ollama", () => {
197197
expect(await ollamaFinding()).toMatchObject({ status: 'pass' })
198198
})
199199

200+
it('does not probe a Compose-internal Ollama service from the host', async () => {
201+
mockHttpHealth.mockImplementation(async () => false)
202+
const ctx = { ...rootContext({ OLLAMA_URL: 'http://ollama:11434' }), live: true }
203+
204+
const findings = await runChecks(ctx, ['live'])
205+
206+
expect(findings.find((finding) => finding.message.includes('ollama'))).toMatchObject({
207+
status: 'skip',
208+
})
209+
expect(mockHttpHealth).not.toHaveBeenCalledWith('http://ollama:11434/api/tags')
210+
})
211+
200212
it('warns when Ollama answers on neither loopback nor the bridge', async () => {
201213
mockHttpHealth.mockImplementation(async () => false)
202214

‎packages/sim-setup/src/checks.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,9 +839,34 @@ function hostOllamaUrls(ollamaUrl: string, compose: boolean): string[] {
839839
}
840840
}
841841

842+
/**
843+
* The Compose service a compose install's `OLLAMA_URL` names, such as `ollama`
844+
* from the bundled overlay. A single-label host other than `localhost` resolves
845+
* only on the Compose network, so the host cannot probe it.
846+
*/
847+
function composeServiceHost(ollamaUrl: string, compose: boolean): string | null {
848+
if (!compose) return null
849+
try {
850+
const { hostname } = new URL(ollamaUrl)
851+
return /^[a-z0-9_-]+$/i.test(hostname) && !isLoopbackHostname(hostname) ? hostname : null
852+
} catch {
853+
return null
854+
}
855+
}
856+
842857
async function checkOllama(sim: EnvFile, compose: boolean): Promise<Finding[]> {
843858
const ollamaUrl = sim.vars.get('OLLAMA_URL')
844859
if (!ollamaUrl) return []
860+
const service = composeServiceHost(ollamaUrl, compose)
861+
if (service) {
862+
return [
863+
{
864+
group: 'live',
865+
status: 'skip',
866+
message: `ollama: OLLAMA_URL names the Compose service "${service}", reachable only inside the stack`,
867+
},
868+
]
869+
}
845870
let reachable = false
846871
for (const probeUrl of hostOllamaUrls(ollamaUrl, compose)) {
847872
if (await httpHealth(`${probeUrl.replace(/\/$/, '')}/api/tags`)) {

0 commit comments

Comments
 (0)