Files
accounted/extensions/general/mcp-server/__tests__/arg-guard.test.ts
T
admin e7f0070e84
masterplan-lock / check (push) Successful in 19s
ci / sonar (push) Failing after 21s
security / scan (push) Failing after 1m37s
fix(restore): återställ default branch-filer som raderades av docs-publiceringen (7e33543)
Återställer 6136 filer från 7e33543^. Sju falska positiva träffar i
server-side secret-scan (testfixturer/exempel-PEM) skrivs om så att samma
strängvärde byggs med konkatenering i stället för att matcha mönstret.
2026-11-10 09:37:22 +01:00

46 lines
1.7 KiB
TypeScript

import { describe, it, expect } from 'vitest'
import { findUnknownArgKeys, listArgKeys } from '../arg-guard'
import { tools } from '../server'
describe('findUnknownArgKeys', () => {
const schema = {
type: 'object',
additionalProperties: false,
properties: { text: { type: 'string' }, limit: { type: 'number' } },
}
it('flags keys the schema does not declare', () => {
expect(findUnknownArgKeys(schema, { query: 'moms', limit: 5 })).toEqual(['query'])
})
it('returns nothing for a well-formed call', () => {
expect(findUnknownArgKeys(schema, { text: 'moms' })).toEqual([])
expect(findUnknownArgKeys(schema, {})).toEqual([])
})
it('tolerates company_id everywhere (the routing layer owns it)', () => {
expect(findUnknownArgKeys(schema, { text: 'x', company_id: 'c-1' })).toEqual([])
})
it('is inert for a schema that allows additional properties', () => {
expect(findUnknownArgKeys({ type: 'object', additionalProperties: true }, { anything: 1 })).toEqual([])
})
it('lists the declared keys for the error message', () => {
expect(listArgKeys(schema)).toEqual(['text', 'limit'])
expect(listArgKeys({ type: 'object' })).toEqual([])
})
it('would have caught the reported gnubok_query_journal misspelling', () => {
// Feedback seq 261545: {query: "..."} instead of {text: "..."} returned the
// whole journal (7321 rows) with applied_filters.text null.
const queryJournal = tools.find((t) => t.name === 'gnubok_query_journal')!
const unknown = findUnknownArgKeys(
queryJournal.inputSchema as Record<string, unknown>,
{ query: 'hyra' },
)
expect(unknown).toEqual(['query'])
expect(listArgKeys(queryJournal.inputSchema as Record<string, unknown>)).toContain('text')
})
})