webbrain-one's picture
Release Compass Tiny v2.1: tested v24 q4f16 WebGPU, validation and caveats
3632834 verified
Raw
History Blame Contribute Delete
2.38 kB
// Portable CPU-only checks for the separately audited optional helper.
import test from 'node:test';
import assert from 'node:assert/strict';
import {parseMiniCpmParamValue as parse, parseMiniCpmToolCalls as calls} from './minicpm5-tool-parser.mjs';
const tools = [{type: 'function', function: {name: 'save_labels', parameters: {
type: 'object', properties: {labels: {type: 'array', items: {type: 'string'}}, enabled: {type: 'boolean'}},
}}}];
const xml = '<function name="save_labels"><param name="labels">[\'green\', \'amber\']</param><param name="enabled">False</param></function>';
test('v24 native list and boolean keep their argument types', () => {
assert.deepEqual(JSON.parse(calls(xml, tools)[0].function.arguments), {labels: ['green', 'amber'], enabled: false});
});
test('CDATA URL and string-typed JSON stay strings', () => {
assert.equal(parse('<![CDATA[https://example.net/find?name=blue&sort=recent]]>', {type: 'string'}), 'https://example.net/find?name=blue&sort=recent');
assert.equal(parse('{"message":""}', {type: 'string'}), '{"message":""}');
});
test('unknown tool names and mixed unknown batches are rejected', () => {
const unknown = '<function name="unprovided_tool"></function>';
assert.deepEqual(calls(unknown, tools), []);
assert.deepEqual(calls(xml + unknown, tools), []);
assert.deepEqual(calls(xml, []), []);
});
test('malformed and duplicate native fields are not repaired', () => {
assert.deepEqual(calls(xml.replace('</function>', ''), tools), []);
assert.deepEqual(calls(xml.replace('</function>', '<param name="enabled">True</param></function>'), tools), []);
assert.deepEqual(calls(xml + 'garbage', tools), []);
});
test('nested literals do not evaluate code or pollute prototypes', () => {
assert.deepEqual(parse("{'flag': True, 'next': None, 'xs': [1, 2.5]}"), {flag: true, next: null, xs: [1, 2.5]});
assert.equal(parse("['x', dangerous()]"), "['x', dangerous()]");
assert.equal(parse('True + exec()'), 'True + exec()');
parse("{'__proto__': {'polluted': True}}");
assert.equal(Object.prototype.polluted, undefined);
});
test('zero-argument native functions remain valid', () => {
const result = calls('<function name="get_accessibility_tree"></function>', new Set(['get_accessibility_tree']));
assert.equal(result.length, 1);
assert.deepEqual(JSON.parse(result[0].function.arguments), {});
});