kimi-code/packages/kosong/test/capability.test.ts
7Sageer ecd7a0afb6
refactor: resolve model capabilities via a static table lookup (#776)
Replace the per-provider getCapability instance method, and the throwaway
provider instantiation used only for capability probing, with a static
getModelCapability(wire, model) entry point in kosong. The same
capability-registry tables are consulted, so resolution stays behaviorally
identical; it no longer constructs a temporary provider or forges an API key.

Also drop the unused getContextSizeLimit interface method.
2026-06-15 17:58:08 +08:00

63 lines
2.2 KiB
TypeScript

/**
* `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);
});
});