kimi-code/packages/agent-core/test/config/resolve.test.ts
Kai 93eb70a727
feat(env): migrate kimi-cli model request params and auto-update toggle (#458)
* feat(env): migrate kimi-cli model request params and auto-update toggle

Migrate still-relevant environment variables from kimi-cli:

- KIMI_MODEL_TEMPERATURE / KIMI_MODEL_TOP_P: sampling params applied
  globally to any kimi provider (not tied to KIMI_MODEL_NAME).
- KIMI_MODEL_THINKING_KEEP: Moonshot preserved-thinking passthrough
  (thinking.keep), injected only while Thinking is on.
- KIMI_CODE_NO_AUTO_UPDATE (legacy alias KIMI_CLI_NO_AUTO_UPDATE):
  fully disables the update preflight.

Wires env -> provider in Agent.get llm() via applyKimiEnvGenerationParams,
reusing kosong's existing GenerationKwargs / thinking.keep support.
KIMI_MODEL_MAX_TOKENS is intentionally untouched: it already flows through
the completion-budget path.

* fix(env): apply Kimi sampling params to compaction requests too

Sink KIMI_MODEL_TEMPERATURE / KIMI_MODEL_TOP_P into ConfigState.provider so
every request built from config.provider — main loop and full-history
compaction alike — carries them, matching kimi-cli where these live on the
shared create_llm provider. thinking.keep stays in Agent.llm because it
depends on the runtime thinking state (compaction runs thinking-off and
correctly skips it).

Splits applyKimiEnvGenerationParams into applyKimiEnvSamplingParams (applied
at provider construction) and applyKimiEnvThinkingKeep (applied in Agent.llm).

Addresses PR review feedback about compaction requests bypassing the wrapped
provider.
2026-06-05 14:54:24 +08:00

37 lines
1.3 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { parseFloatEnv } from '../../src/config/resolve';
import { KimiError } from '../../src/errors';
function expectConfigInvalid(fn: () => unknown): void {
try {
fn();
} catch (error) {
expect(error).toBeInstanceOf(KimiError);
expect((error as KimiError).code).toBe('config.invalid');
return;
}
throw new Error('expected function to throw');
}
describe('parseFloatEnv', () => {
it('returns undefined when unset, empty, or blank', () => {
expect(parseFloatEnv(undefined, 'KIMI_MODEL_TEMPERATURE')).toBeUndefined();
expect(parseFloatEnv('', 'KIMI_MODEL_TEMPERATURE')).toBeUndefined();
expect(parseFloatEnv(' ', 'KIMI_MODEL_TEMPERATURE')).toBeUndefined();
});
it('parses valid floats and integers', () => {
expect(parseFloatEnv('0.3', 'KIMI_MODEL_TEMPERATURE')).toBe(0.3);
expect(parseFloatEnv('1', 'KIMI_MODEL_TEMPERATURE')).toBe(1);
expect(parseFloatEnv(' 0.95 ', 'KIMI_MODEL_TOP_P')).toBe(0.95);
expect(parseFloatEnv('0', 'KIMI_MODEL_TEMPERATURE')).toBe(0);
});
it.each(['abc', '1.2.3', 'NaN', '1,5'])(
'throws config.invalid for non-numeric value %s',
(value) => {
expectConfigInvalid(() => parseFloatEnv(value, 'KIMI_MODEL_TEMPERATURE'));
},
);
});