wip: desparate models fucking around
This commit is contained in:
@@ -192,4 +192,49 @@ describe('assistantPanelSpec', () => {
|
||||
expect(result).not.toBeNull();
|
||||
expect(result?.elements).toHaveLength(7);
|
||||
});
|
||||
|
||||
it('parses canonical protocol envelope JSON and extracts assistant text plus ui spec', () => {
|
||||
const raw = JSON.stringify({
|
||||
protocolVersion: '2.0',
|
||||
assistantText: 'Here is your chart.',
|
||||
ui: {
|
||||
specVersion: '1',
|
||||
elements: [
|
||||
{
|
||||
type: 'chart',
|
||||
chartType: 'bar',
|
||||
data: {
|
||||
labels: ['aside', 'article'],
|
||||
datasets: [{ data: [181, 53] }],
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'text',
|
||||
content: 'Breakdown details',
|
||||
},
|
||||
],
|
||||
},
|
||||
intent: 'summarize',
|
||||
needsInput: { required: false, fields: [] },
|
||||
actions: [],
|
||||
confidence: 0.9,
|
||||
traceId: 'trace-1',
|
||||
});
|
||||
|
||||
const result = extractAssistantResponseContent(raw);
|
||||
|
||||
expect(result.displayText).toBe('Here is your chart.');
|
||||
expect(result.panelSpec).not.toBeNull();
|
||||
expect(result.panelSpec?.elements[0]).toMatchObject({
|
||||
type: 'chart',
|
||||
series: [
|
||||
{ label: 'aside', value: 181 },
|
||||
{ label: 'article', value: 53 },
|
||||
],
|
||||
});
|
||||
expect(result.panelSpec?.elements[1]).toEqual({
|
||||
type: 'text',
|
||||
text: 'Breakdown details',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
56
tests/renderer/navigation/protocolActionPolicies.test.ts
Normal file
56
tests/renderer/navigation/protocolActionPolicies.test.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { buildActionPoliciesFromEnvelope } from '../../../src/renderer/navigation/protocolActionPolicies';
|
||||
|
||||
describe('buildActionPoliciesFromEnvelope', () => {
|
||||
it('preserves server-provided action policies', () => {
|
||||
const result = buildActionPoliciesFromEnvelope({
|
||||
actions: [
|
||||
{
|
||||
id: 'a1',
|
||||
action: 'openSettings',
|
||||
policy: 'confirm',
|
||||
requiresConfirmation: true,
|
||||
},
|
||||
],
|
||||
needsInput: {
|
||||
required: false,
|
||||
fields: [],
|
||||
},
|
||||
});
|
||||
|
||||
expect(result).toEqual({
|
||||
openSettings: 'confirm',
|
||||
});
|
||||
});
|
||||
|
||||
it('adds confirm policy for submitNeedsInput when clarification is required', () => {
|
||||
const result = buildActionPoliciesFromEnvelope({
|
||||
actions: [],
|
||||
needsInput: {
|
||||
required: true,
|
||||
fields: [{ key: 'date', label: 'Date', inputType: 'date' }],
|
||||
},
|
||||
});
|
||||
|
||||
expect(result.submitNeedsInput).toBe('confirm');
|
||||
});
|
||||
|
||||
it('does not override explicit server policy for submitNeedsInput', () => {
|
||||
const result = buildActionPoliciesFromEnvelope({
|
||||
actions: [
|
||||
{
|
||||
id: 'a1',
|
||||
action: 'submitNeedsInput',
|
||||
policy: 'danger',
|
||||
requiresConfirmation: true,
|
||||
},
|
||||
],
|
||||
needsInput: {
|
||||
required: true,
|
||||
fields: [{ key: 'title', label: 'Title', inputType: 'text' }],
|
||||
},
|
||||
});
|
||||
|
||||
expect(result.submitNeedsInput).toBe('danger');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user