CI (SIAX Cloud) / integration (push) Skipped
CI (SIAX Cloud) / sonar (push) Skipped
CI (SIAX Cloud) / sonar (pull_request) Skipped
masterplan-lock / check (pull_request) Successful in 5s
Security Scan (SIAX Cloud) / security (push) Successful in 14s
CI (SIAX Cloud) / security (push) Successful in 17s
masterplan-lock / check (push) Successful in 17s
CI (SIAX Cloud) / security (pull_request) Successful in 20s
Security Scan (SIAX Cloud) / security (pull_request) Successful in 21s
CI (SIAX Cloud) / integration (pull_request) Successful in 54s
CI (SIAX Cloud) / quality (push) Successful in 1m24s
CI (SIAX Cloud) / quality (pull_request) Successful in 1m29s
The 9B model spent its whole 4000-token budget on reasoning and came back model_incomplete. Call /api/chat with format=json, think=false and num_predict, and read prompt_eval_count/eval_count/done_reason. Structured extraction no longer needs chain-of-thought.
124 lines
4.0 KiB
TypeScript
124 lines
4.0 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 a native Ollama chat response into the INF0 receipt', async () => {
|
|
const c = client(async (url, init) => {
|
|
expect(String(url)).toMatch(/\/api\/chat$/);
|
|
const body = JSON.parse(String(init?.body));
|
|
expect(body.format).toBe('json');
|
|
expect(body.think).toBe(false);
|
|
return Response.json({
|
|
model: 'hermes-qwen3.5:9b',
|
|
message: { role: 'assistant', content: '{"value":{}}' },
|
|
done: true,
|
|
done_reason: 'stop',
|
|
prompt_eval_count: 12,
|
|
eval_count: 8,
|
|
});
|
|
});
|
|
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',
|
|
message: { role: 'assistant', content: 'x' },
|
|
done: true,
|
|
done_reason: 'stop',
|
|
prompt_eval_count: 1,
|
|
eval_count: 5000,
|
|
}),
|
|
);
|
|
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);
|
|
});
|
|
});
|