Files
extension/packages/canva/test/config.test.ts
T
Hanzo Dev 71f76cd97e feat(canva): Hanzo AI for Canva — Apps SDK copy assistant
A side-panel Canva app over the published @hanzo/ai: generate copy, rewrite
the selected text in place, translate, brainstorm content ideas, and ask.

- design-core.ts (PURE): the five-action catalog, prompt builders, design-
  context assembly + budget truncation, and response parsing (fence/quote/
  list-marker stripping). Mirrors @hanzo/figma's design-core. Fully unit-tested.
- hanzo.ts: thin over @hanzo/ai (createAiClient) — the only model-gateway path.
- canva.ts: thin over @canva/design — observe the plaintext selection, replace
  it via a fresh draft, insert a new text element at the cursor.
- app.tsx: the @canva/app-ui-kit panel (model picker, action picker, output,
  ideas). index.tsx mounts it under AppUiProvider.
- config.ts: api.hanzo.ai /v1 gateway, default zen5, hk- key guard.

40 vitest tests green, tsc --noEmit clean, esbuild build succeeds. Registered
in pnpm-workspace.yaml.
2026-07-03 21:08:04 -07:00

37 lines
1.2 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import {
HANZO_API_BASE_URL,
DEFAULT_MODEL,
chatCompletionsURL,
modelsURL,
isHanzoKey,
} from '../src/config';
describe('gateway config', () => {
it('points at api.hanzo.ai with /v1 endpoints (never /api/)', () => {
expect(HANZO_API_BASE_URL).toBe('https://api.hanzo.ai');
expect(chatCompletionsURL()).toBe('https://api.hanzo.ai/v1/chat/completions');
expect(modelsURL()).toBe('https://api.hanzo.ai/v1/models');
expect(chatCompletionsURL()).not.toContain('/api/');
});
it('defaults to a Zen model', () => {
expect(DEFAULT_MODEL).toBe('zen5');
});
});
describe('isHanzoKey', () => {
it('accepts a well-formed hk- key (trimming whitespace)', () => {
expect(isHanzoKey('hk-abcdef0123456789ABCDEF')).toBe(true);
expect(isHanzoKey(' hk-abcdef0123456789ABCDEF ')).toBe(true);
});
it('rejects the wrong prefix, too-short, or non-string', () => {
expect(isHanzoKey('sk-abcdef0123456789ABCDEF')).toBe(false);
expect(isHanzoKey('hk-short')).toBe(false);
expect(isHanzoKey('')).toBe(false);
expect(isHanzoKey(undefined)).toBe(false);
expect(isHanzoKey(null)).toBe(false);
});
});