|
|
@ -22,12 +22,6 @@ describe('getWebFetchBody', () => { |
|
|
).toBe('[{"a":1}]'); |
|
|
).toBe('[{"a":1}]'); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
it('should get an object after a text in brackets', () => { |
|
|
|
|
|
expect( |
|
|
|
|
|
getWebFetchBody({ candidate: `[Note] ${BODY}`, isJson: true }) |
|
|
|
|
|
).toBe(BODY); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it.each([ |
|
|
it.each([ |
|
|
['the raw message', FAILURE_MESSAGE], |
|
|
['the raw message', FAILURE_MESSAGE], |
|
|
[ |
|
|
[ |
|
|
@ -63,7 +57,20 @@ describe('getWebFetchBody', () => { |
|
|
'a body with broken JSON', |
|
|
'a body with broken JSON', |
|
|
'{"items":{"a":{"id":1,"value":0.1},"b\\":{\\"id\\":2,\\"value\\":0.2},"c":{"id":3,"value":0.3}}}' |
|
|
'{"items":{"a":{"id":1,"value":0.1},"b\\":{\\"id\\":2,\\"value\\":0.2},"c":{"id":3,"value":0.3}}}' |
|
|
], |
|
|
], |
|
|
['two JSON objects', `${BODY}\n\n${BODY}`] |
|
|
['two JSON objects', `${BODY}\n\n${BODY}`], |
|
|
|
|
|
['a citation marker', 'The fetch failed with HTTP 403 [1].'], |
|
|
|
|
|
['an empty array after a text', 'No data was returned []'], |
|
|
|
|
|
['an object after a citation marker', 'Sources [1]: {"a":1}'], |
|
|
|
|
|
['an object after a text in brackets', `[Note] ${BODY}`], |
|
|
|
|
|
[ |
|
|
|
|
|
'an array in a broken object', |
|
|
|
|
|
'{"name":"bad\\q","items":[{"id":1},{"id":2}],"total":2}' |
|
|
|
|
|
], |
|
|
|
|
|
['an object in a broken array', '[{"a":1},]'], |
|
|
|
|
|
[ |
|
|
|
|
|
'a false tool call', |
|
|
|
|
|
'\n\n{"url":"https://www.example.com/data.json"}</parameter>' |
|
|
|
|
|
] |
|
|
])('should reject %s', (_, candidate) => { |
|
|
])('should reject %s', (_, candidate) => { |
|
|
expect(getWebFetchBody({ candidate, isJson: true })).toBeUndefined(); |
|
|
expect(getWebFetchBody({ candidate, isJson: true })).toBeUndefined(); |
|
|
}); |
|
|
}); |
|
|
@ -73,16 +80,6 @@ describe('getWebFetchBody', () => { |
|
|
|
|
|
|
|
|
expect(getWebFetchBody({ candidate, isJson: true })).toBe(candidate); |
|
|
expect(getWebFetchBody({ candidate, isJson: true })).toBe(candidate); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
it('should leave a false tool call to the check of the caller', () => { |
|
|
|
|
|
expect( |
|
|
|
|
|
getWebFetchBody({ |
|
|
|
|
|
candidate: |
|
|
|
|
|
'\n\n{"url":"https://www.example.com/data.json"}</parameter>', |
|
|
|
|
|
isJson: true |
|
|
|
|
|
}) |
|
|
|
|
|
).toBe('{"url":"https://www.example.com/data.json"}'); |
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
describe('with a route for other content', () => { |
|
|
describe('with a route for other content', () => { |
|
|
|