Files
0pt/tests/document-workbench/decision-ollama-client.test.ts
T
admin 525bf6b9a0
CI (SIAX Cloud) / sonar (pull_request) Skipped
CI (SIAX Cloud) / integration (push) Skipped
CI (SIAX Cloud) / sonar (push) Skipped
masterplan-lock / check (pull_request) Successful in 3s
masterplan-lock / check (push) Successful in 5s
Security Scan (SIAX Cloud) / security (push) Successful in 15s
CI (SIAX Cloud) / security (pull_request) Successful in 22s
CI (SIAX Cloud) / security (push) Successful in 23s
Security Scan (SIAX Cloud) / security (pull_request) Successful in 23s
CI (SIAX Cloud) / integration (pull_request) Successful in 30s
CI (SIAX Cloud) / quality (push) Successful in 45s
CI (SIAX Cloud) / quality (pull_request) Successful in 1m18s
feat(workbench): use the decision server's local model while the AI API is on hold
- DecisionOllamaGatewayClient calls the self-hosted Ollama on
  server-decision-01 (tailnet HTTP only for loopback/RFC1918/100.64-127),
  keeps the same local admission and reports providerKind=local.
- createInf0Gateway prefers it over INF0/LiteLLM when configured.
- Evidence is computed deterministically from values when a small model omits
  offsets; a value must occur exactly once in the source or the result goes to
  review. This makes a 9B local model usable without weakening verification.

Tests: 4 new gateway cases + 2 evidence-derivation cases; full typecheck green.
2026-11-02 17:09:42 +01:00

114 lines
3.8 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import {
DecisionOllamaGatewayClient,
assertTrustedDecisionOllamaUrl,
} from '../../src/document-workbench/decision-ollama-client';
import { Inf0OutcomeUnknownError } from '../../src/document-workbench/inf0-gateway-client';
import { createInf0Gateway } from '../../src/document-workbench/inf0-gateway';
const context = {
tenantId: 't_0pt',
projectId: 'prj_default',
actorId: 'user_1',
capability: '0pt.document.structure.v1',
correlationId: 'corr-1',
};
const admission = {
tenantId: 't_0pt',
projectId: 'prj_default',
jobId: 'job-1',
modelId: 'hermes-qwen3.5:9b',
dataClass: 'low',
maxInputTokens: 1000,
maxOutputTokens: 200,
maximumCredits: 0,
};
const policy = {
tenantId: 't_0pt',
projectId: 'prj_default',
allowedModelIds: ['hermes-qwen3.5:9b'],
allowedDataClasses: ['low'],
destination: 'internal' as const,
externalTransferAllowed: false,
maxInputTokens: 1000,
maxOutputTokens: 200,
};
const messages = [
{ role: 'system' as const, content: 'system' },
{ role: 'user' as const, content: 'data' },
];
function client(fetchImpl: typeof fetch, model = 'hermes-qwen3.5:9b') {
return new DecisionOllamaGatewayClient({
baseUrl: 'http://100.96.133.104:11434',
model,
fetchImpl,
});
}
describe('decision server Ollama gateway', () => {
it('accepts tailnet/RFC1918 HTTP but refuses a public HTTP endpoint', () => {
expect(() => assertTrustedDecisionOllamaUrl('http://100.96.133.104:11434')).not.toThrow();
expect(() => assertTrustedDecisionOllamaUrl('http://192.168.1.10:11434')).not.toThrow();
expect(() => assertTrustedDecisionOllamaUrl('https://ai.example.test')).not.toThrow();
expect(() => assertTrustedDecisionOllamaUrl('http://8.8.8.8:11434')).toThrow();
expect(() => assertTrustedDecisionOllamaUrl('http://user:pass@100.96.133.104:11434')).toThrow();
});
it('maps an OpenAI-compatible Ollama response into the INF0 receipt', async () => {
const c = client(async () =>
Response.json({
model: 'hermes-qwen3.5:9b',
choices: [{ message: { content: '{"value":{}}' }, finish_reason: 'stop' }],
usage: { prompt_tokens: 12, completion_tokens: 8, total_tokens: 20 },
}),
);
await expect(
c.complete({ context, admission, policy, reservation: undefined, inputTokens: 12, messages }),
).resolves.toMatchObject({
status: 'model_stopped',
modelExecuted: 'hermes-qwen3.5:9b',
providerKind: 'local',
totalTokens: 20,
});
});
it('refuses an external destination and malformed usage', async () => {
const c = client(async () =>
Response.json({
model: 'hermes-qwen3.5:9b',
choices: [{ message: { content: 'x' }, finish_reason: 'stop' }],
usage: { prompt_tokens: 1, completion_tokens: 1, total_tokens: 99 },
}),
);
await expect(
c.complete({
context,
admission,
policy: { ...policy, destination: 'external' },
reservation: undefined,
inputTokens: 1,
messages,
}),
).rejects.toThrow(/denied/i);
await expect(
c.complete({ context, admission, policy, reservation: undefined, inputTokens: 1, messages }),
).rejects.toBeInstanceOf(Inf0OutcomeUnknownError);
});
it('is preferred over the INF0/LiteLLM path when configured', () => {
expect(
createInf0Gateway({
DECISION_OLLAMA_URL: 'http://100.96.133.104:11434',
DECISION_OLLAMA_MODEL: 'hermes-qwen3.5:9b',
INF0_GATEWAY_LITELLM_KEY: 'sk-test',
} as unknown as NodeJS.ProcessEnv),
).toBeInstanceOf(DecisionOllamaGatewayClient);
expect(
createInf0Gateway({
INF0_GATEWAY_LITELLM_KEY: 'sk-test',
} as unknown as NodeJS.ProcessEnv),
).not.toBeInstanceOf(DecisionOllamaGatewayClient);
});
});