First vertical slice: Even client, bridge, contract v1, tests, docs
Client (apps/even-client): pure interaction reducer with generation-based stale-result rejection, HUD renderer, measured pagination, Even Hub SDK 0.0.16 adapter, bridge HTTP client, phone pairing/status/diagnostics page. Bridge (services/bridge): device pairing and revocable expiring credentials, turn engine with idempotent submit, cancel, deadlines and restart recovery, Hermes Runs API adapter, OpenAI-compatible STT adapter, operator CLI. Contract (packages/contracts): versioned schemas, types and error codes. Tests: 122 unit/integration (fakes), 6 simulator scenarios (Even Hub simulator 0.9.5), 9 scenarios against a real Hermes v0.23.1 gateway with a stub model. No real STT, real model or physical device has been exercised; see docs/test-evidence.md and docs/device-test-plan.md. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import {
|
||||
AudioTurnQuery,
|
||||
check,
|
||||
ContractError,
|
||||
ERROR_CODES,
|
||||
ERROR_CODE_LIST,
|
||||
ErrorResponse,
|
||||
firstError,
|
||||
parse,
|
||||
SCHEMA_VERSION,
|
||||
TextTurnRequest,
|
||||
TurnResult,
|
||||
} from '../src/index.ts';
|
||||
|
||||
const ID = '11111111-1111-4111-8111-111111111111';
|
||||
|
||||
describe('contract v1', () => {
|
||||
const text = {
|
||||
schema_version: SCHEMA_VERSION,
|
||||
request_id: ID,
|
||||
conversation_id: ID,
|
||||
locale: 'en-US',
|
||||
input: { kind: 'text', text: 'hello' },
|
||||
};
|
||||
|
||||
it('accepts a well-formed text turn and rejects extra or malformed fields', () => {
|
||||
expect(check(TextTurnRequest, text)).toBe(true);
|
||||
expect(check(TextTurnRequest, { ...text, hermes_session_id: 'x' })).toBe(false);
|
||||
expect(check(TextTurnRequest, { ...text, profile: 'someone-else' })).toBe(false);
|
||||
expect(check(TextTurnRequest, { ...text, request_id: 'not-a-uuid' })).toBe(false);
|
||||
expect(check(TextTurnRequest, { ...text, request_id: 'ABCDEF12-1111-4111-8111-111111111111' })).toBe(false);
|
||||
expect(check(TextTurnRequest, { ...text, schema_version: 2 })).toBe(false);
|
||||
expect(check(TextTurnRequest, { ...text, locale: 'en_US; DROP' })).toBe(false);
|
||||
expect(check(TextTurnRequest, { ...text, input: { kind: 'text', text: '' } })).toBe(false);
|
||||
expect(check(TextTurnRequest, { ...text, input: { kind: 'text', text: 'x'.repeat(4001) } })).toBe(false);
|
||||
expect(check(TextTurnRequest, { ...text, input: { kind: 'audio', text: 'x' } })).toBe(false);
|
||||
});
|
||||
|
||||
it('audio metadata admits exactly one validated format', () => {
|
||||
const q = {
|
||||
schema_version: '1',
|
||||
request_id: ID,
|
||||
conversation_id: ID,
|
||||
locale: 'en-US',
|
||||
input_kind: 'audio',
|
||||
encoding: 'pcm_s16le',
|
||||
sample_rate: '16000',
|
||||
channels: '1',
|
||||
};
|
||||
expect(check(AudioTurnQuery, q)).toBe(true);
|
||||
for (const bad of [{ sample_rate: '8000' }, { channels: '2' }, { encoding: 'opus' }, { input_kind: 'text' }, { extra: '1' }]) {
|
||||
expect(check(AudioTurnQuery, { ...q, ...bad })).toBe(false);
|
||||
}
|
||||
});
|
||||
|
||||
it('a turn result keeps state, terminal flag and outcome distinct', () => {
|
||||
const result = {
|
||||
schema_version: SCHEMA_VERSION,
|
||||
request_id: ID,
|
||||
conversation_id: ID,
|
||||
state: 'done',
|
||||
terminal: true,
|
||||
outcome: 'unknown',
|
||||
cancel_requested: false,
|
||||
input_text: null,
|
||||
answer_text: null,
|
||||
error: { code: 'outcome_unknown', message: 'Unknown.', retryable: false },
|
||||
replayed: false,
|
||||
created_at: '2026-01-01T00:00:00.000Z',
|
||||
updated_at: '2026-01-01T00:00:00.000Z',
|
||||
timings: { transcribe_ms: null, agent_ms: 12 },
|
||||
};
|
||||
expect(check(TurnResult, result)).toBe(true);
|
||||
expect(check(TurnResult, { ...result, outcome: 'approval_required' })).toBe(false);
|
||||
expect(check(TurnResult, { ...result, state: 'ANSWER' })).toBe(false);
|
||||
expect(check(TurnResult, { ...result, error: { code: 'made_up', message: '', retryable: false } })).toBe(false);
|
||||
expect(firstError(TurnResult, { ...result, state: 'ANSWER' })).toContain('/state');
|
||||
expect(() => parse(TurnResult, {}, 'turn')).toThrow(ContractError);
|
||||
});
|
||||
|
||||
it('error codes are stable, and nothing ambiguous is ever marked retryable', () => {
|
||||
expect(ERROR_CODE_LIST).toContain('outcome_unknown');
|
||||
for (const code of ['outcome_unknown', 'agent_failed', 'agent_interrupted', 'agent_timeout', 'approval_timeout', 'request_id_conflict'] as const) {
|
||||
expect(ERROR_CODES[code].retryable, code).toBe(false);
|
||||
}
|
||||
for (const code of ['stt_empty', 'stt_timeout', 'interrupted_before_agent', 'agent_unreachable'] as const) {
|
||||
expect(ERROR_CODES[code].retryable, code).toBe(true);
|
||||
}
|
||||
expect(check(ErrorResponse, { schema_version: 1, error: { code: 'rate_limited', message: 'x', retryable: true } })).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user