// 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 = '[\'green\', \'amber\']False'; 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('', {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 = ''; 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('', ''), tools), []); assert.deepEqual(calls(xml.replace('', 'True'), 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('', new Set(['get_accessibility_tree'])); assert.equal(result.length, 1); assert.deepEqual(JSON.parse(result[0].function.arguments), {}); });