mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-04-28 19:52:02 +00:00
Sync upstream Gemini-CLI v0.8.2 (#838)
This commit is contained in:
parent
096fabb5d6
commit
eb95c131be
644 changed files with 70389 additions and 23709 deletions
125
packages/core/src/utils/schemaValidator.test.ts
Normal file
125
packages/core/src/utils/schemaValidator.test.ts
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
/**
|
||||
* @license
|
||||
* Copyright 2025 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { SchemaValidator } from './schemaValidator.js';
|
||||
|
||||
describe('SchemaValidator', () => {
|
||||
it('should allow any params if schema is undefined', () => {
|
||||
const params = {
|
||||
foo: 'bar',
|
||||
};
|
||||
expect(SchemaValidator.validate(undefined, params)).toBeNull();
|
||||
});
|
||||
|
||||
it('rejects null params', () => {
|
||||
const schema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
};
|
||||
expect(SchemaValidator.validate(schema, null)).toBe(
|
||||
'Value of params must be an object',
|
||||
);
|
||||
});
|
||||
|
||||
it('rejects params that are not objects', () => {
|
||||
const schema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
};
|
||||
expect(SchemaValidator.validate(schema, 'not an object')).toBe(
|
||||
'Value of params must be an object',
|
||||
);
|
||||
});
|
||||
|
||||
it('allows schema with extra properties', () => {
|
||||
const schema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
example_enum: {
|
||||
type: 'string',
|
||||
enum: ['FOO', 'BAR'],
|
||||
// enum-descriptions is not part of the JSON schema spec.
|
||||
// This test verifies that the SchemaValidator allows the
|
||||
// use of extra keywords, like this one, in the schema.
|
||||
'enum-descriptions': ['a foo', 'a bar'],
|
||||
},
|
||||
},
|
||||
};
|
||||
const params = {
|
||||
example_enum: 'BAR',
|
||||
};
|
||||
|
||||
expect(SchemaValidator.validate(schema, params)).toBeNull();
|
||||
});
|
||||
|
||||
it('allows custom format values', () => {
|
||||
const schema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
duration: {
|
||||
type: 'string',
|
||||
// See: https://cloud.google.com/docs/discovery/type-format
|
||||
format: 'google-duration',
|
||||
},
|
||||
mask: {
|
||||
type: 'string',
|
||||
format: 'google-fieldmask',
|
||||
},
|
||||
foo: {
|
||||
type: 'string',
|
||||
format: 'something-totally-custom',
|
||||
},
|
||||
},
|
||||
};
|
||||
const params = {
|
||||
duration: '10s',
|
||||
mask: 'foo.bar,biz.baz',
|
||||
foo: 'some value',
|
||||
};
|
||||
expect(SchemaValidator.validate(schema, params)).toBeNull();
|
||||
});
|
||||
|
||||
it('allows valid values for known formats', () => {
|
||||
const schema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
today: {
|
||||
type: 'string',
|
||||
format: 'date',
|
||||
},
|
||||
},
|
||||
};
|
||||
const params = {
|
||||
today: '2025-04-08',
|
||||
};
|
||||
expect(SchemaValidator.validate(schema, params)).toBeNull();
|
||||
});
|
||||
|
||||
it('rejects invalid values for known formats', () => {
|
||||
const schema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
today: {
|
||||
type: 'string',
|
||||
format: 'date',
|
||||
},
|
||||
},
|
||||
};
|
||||
const params = {
|
||||
today: 'this is not a date',
|
||||
};
|
||||
expect(SchemaValidator.validate(schema, params)).not.toBeNull();
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue