mirror of
https://github.com/MoonshotAI/kimi-code.git
synced 2026-07-25 17:14:54 +00:00
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.
63 lines
2.2 KiB
TypeScript
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);
|
|
});
|
|
});
|