fix: validate compaction config pairs

This commit is contained in:
Yichen Jiang
2026-07-21 14:49:57 +08:00
parent b6f6c58435
commit 49a9bca9f6
8 changed files with 96 additions and 16 deletions

View File

@@ -80,7 +80,9 @@ declare module 'cordis' {
/** Replay owner for one service-wide estimator and isolated per-session folds. */
export class TokenMeterService extends Service {
static Config: z<TokenMeterConfig> = z.object({})
// Schemastery preserves untrusted loader keys on an empty object schema;
// the public type excludes settings while validateConfigKeys rejects them.
static Config: z<TokenMeterConfig> = z.object({}) as unknown as z<TokenMeterConfig>
private readonly states = new WeakMap<Session, ReplayState>()

View File

@@ -7,7 +7,7 @@
import type { TokenUsage } from '@deepseek-ai/dsh-llm'
/** Token-meter plugin configuration; the fixed estimator has no settings. */
export type TokenMeterConfig = object
export type TokenMeterConfig = Record<string, never>
/** The baseline from which a signed surface delta produces current pressure. */
export type TokenMeasurementBaseline =

View File

@@ -1,4 +1,4 @@
import { describe, expect, it } from 'vitest'
import { describe, expect, expectTypeOf, it } from 'vitest'
import { Context } from 'cordis'
import { CallId } from '@deepseek-ai/dsh-llm'
import type { ContentBlock, Message, TokenUsage } from '@deepseek-ai/dsh-llm'
@@ -87,10 +87,15 @@ function expectSurfaceTotal(measurement: TokenMeasurement): void {
}
describe('TokenMeterService configuration and registration', () => {
it('exposes an empty public configuration type', () => {
expectTypeOf<{}>().toExtend<TokenMeterConfig>()
expectTypeOf<{ contextWindow: number }>().not.toExtend<TokenMeterConfig>()
})
it.each(['models', 'contextWindow', 'contextWidow'])(
'rejects stale or unknown top-level config key %s',
(key) => {
expect(() => meter({ [key]: {} }))
expect(() => meter({ [key]: {} } as unknown as TokenMeterConfig))
.toThrow(`TokenMeterConfig: unknown key "${key}"`)
},
)