File size: 2,283 Bytes
4e23b01
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
 * `ModelCapability` type and `UNKNOWN_CAPABILITY` default — pure
 * type/helper layer. Per-wire `getModelCapability` tables live in
 * `capability-providers.test.ts`.
 */

import { UNKNOWN_CAPABILITY, isUnknownCapability, type ModelCapability } from '#/capability';
import { describe, expect, it } from 'vitest';

describe('ModelCapability / UNKNOWN_CAPABILITY', () => {
  it('UNKNOWN_CAPABILITY has all boolean fields false', () => {
    expect(UNKNOWN_CAPABILITY.image_in).toBe(false);
    expect(UNKNOWN_CAPABILITY.video_in).toBe(false);
    expect(UNKNOWN_CAPABILITY.audio_in).toBe(false);
    expect(UNKNOWN_CAPABILITY.thinking).toBe(false);
    expect(UNKNOWN_CAPABILITY.tool_use).toBe(false);
  });

  it('UNKNOWN_CAPABILITY.max_context_tokens is 0 (unknown)', () => {
    expect(UNKNOWN_CAPABILITY.max_context_tokens).toBe(0);
  });

  it('accepts a well-formed ModelCapability literal (type guard)', () => {
    const cap: ModelCapability = {
      image_in: true,
      video_in: false,
      audio_in: false,
      thinking: true,
      tool_use: true,
      max_context_tokens: 128_000,
    };
    expect(cap.image_in).toBe(true);
    expect(cap.max_context_tokens).toBe(128_000);
  });

  it('UNKNOWN_CAPABILITY is read-only (frozen or otherwise immutable)', () => {
    // Defensive: future code should not be able to mutate the shared default.
    // We accept either Object.isFrozen() or a thrown TypeError on mutation
    // attempt (strict mode). Either way, the observed value afterwards must
    // still be the conservative default.
    const beforeImage = UNKNOWN_CAPABILITY.image_in;
    try {
      (UNKNOWN_CAPABILITY as unknown as { image_in: boolean }).image_in = true;
    } catch {
      // frozen in strict mode — fine
    }
    expect(UNKNOWN_CAPABILITY.image_in).toBe(beforeImage);
    expect(UNKNOWN_CAPABILITY.image_in).toBe(false);
  });

  it('detects copied UNKNOWN_CAPABILITY objects by structure', () => {
    const copiedUnknown: ModelCapability = {
      image_in: false,
      video_in: false,
      audio_in: false,
      thinking: false,
      tool_use: false,
      max_context_tokens: 0,
    };
    expect(isUnknownCapability(UNKNOWN_CAPABILITY)).toBe(true);
    expect(isUnknownCapability(copiedUnknown)).toBe(true);
  });
});