forked from Blendman974/faceclaw
Fixes to evenhub extensions library
This commit is contained in:
1 parent
4bf2769d24
commit
07859c95ad
8 files changed
+203
-34
No files matched your search
@@ -117,6 +117,27 @@ test('cancelled tools and late callbacks cannot mutate the next turn or its hist
|
||||
assert.equal(session.isTurnActive(), false);
|
||||
});
|
||||
|
||||
test('tool names are sanitized, shortened to 64 characters, kept distinct, and mapped back', () => {
|
||||
const env = sessions();
|
||||
const pkg = 'com.example.some-long-developer-name.evenhub';
|
||||
const names = ['glasses.get_state', `app.${pkg}.set_metronome_tempo_and_signature`,
|
||||
`app.${pkg}.set_metronome_tempo_and_signature_v2`, 'a.b', 'a_b'];
|
||||
const registry = { listTools: () => names.map(name => ({ name, description: '', inputSchema: { type: 'object' } })) };
|
||||
const session = new env.AssistantSession(config(), registry);
|
||||
session.sendUtterance('hi', {}, callbacks());
|
||||
const turn = env.turns.at(-1);
|
||||
const apiNames = turn.buildTools().map(tool => tool.name);
|
||||
assert.equal(apiNames[0], 'glasses_get_state');
|
||||
assert.ok(apiNames.every(name => /^[a-zA-Z0-9_-]{1,64}$/.test(name)), apiNames.join(', '));
|
||||
assert.equal(new Set(apiNames).size, names.length);
|
||||
assert.match(apiNames[1], /^app_com_example_/);
|
||||
assert.match(apiNames[1], /tempo_and_signature$/);
|
||||
assert.deepEqual(apiNames.slice(3), ['a_b', 'a_b_2']);
|
||||
assert.deepEqual(apiNames.map(turn.resolveToolName), names);
|
||||
// The same canonical name shortens the same way on the next turn.
|
||||
assert.deepEqual(turn.buildTools().map(tool => tool.name), apiNames);
|
||||
});
|
||||
|
||||
test('synchronous provider errors do not leave a permanently active turn', () => {
|
||||
const env = sessions(); env.setError();
|
||||
const session = new env.AssistantSession(config());
|
||||
|
||||
@@ -30,6 +30,16 @@ function page() {
|
||||
return { win, fc, posted };
|
||||
}
|
||||
|
||||
test('the package helper returns the shim, and treats unversioned 0.8.0-0.8.2 hosts as absent', () => {
|
||||
const { loader } = require('./helpers/load-typescript.cjs');
|
||||
const helper = (window) => loader(window === undefined ? {} : { window })('evenhub-extensions/src/index.ts').getFaceclawExtensions();
|
||||
const { win, fc } = page();
|
||||
assert.equal(helper(win), fc);
|
||||
assert.equal(helper({ getFaceclawExtensions: () => ({ getVersion: () => 'Faceclaw/0.8.2' }) }), null);
|
||||
assert.equal(helper({}), null);
|
||||
assert.equal(helper(undefined), null);
|
||||
});
|
||||
|
||||
test('the shim implements exactly the members the package declares', () => {
|
||||
const { fc } = page();
|
||||
assert.deepEqual(Object.keys(fc).sort(), interfaceMembers('FaceclawExtensions'));
|
||||
|
||||
@@ -260,3 +260,40 @@ test('EvenHub buzzer RPC uses the host action on iOS and chunks and paces long s
|
||||
assert.equal(played.length, 2);
|
||||
h.session.close();
|
||||
});
|
||||
|
||||
test('EvenHub buzzer RPC rejects the app promise when sending fails', async () => {
|
||||
const sounds = loader()('app/ui/sound-effects.ts');
|
||||
const h = sessionHarness({ '../../ui/sound-effects': sounds }, () => Promise.reject(new Error('link lost')));
|
||||
await assert.rejects(h.session.dispatchExtension('playBuzzer', [[{ freq: 880, ms: 50 }]]), /link lost/);
|
||||
h.session.close();
|
||||
});
|
||||
|
||||
test('EvenHub assistant tools skip malformed names and schemas with a warning in the app console', () => {
|
||||
const offered = [];
|
||||
const h = sessionHarness({ '../../assistant/tool-registry': { toolRegistry: { setAppTools: provider => offered.push(provider), removeAppTools() {} } } });
|
||||
const warnings = [];
|
||||
h.web.console = { warn: message => warnings.push(message) };
|
||||
const object = { type: 'object', properties: { n: { type: 'number' } }, required: ['n'] };
|
||||
h.session.dispatchExtension('setAssistantTools', [[
|
||||
{ name: 'ok', description: 'fine', parameters: object },
|
||||
{ name: 'no_params', description: 'defaults' },
|
||||
{ name: 'has space', parameters: object },
|
||||
{ name: 'x'.repeat(65), parameters: object },
|
||||
{ name: 'untyped', parameters: { properties: {} } },
|
||||
{ name: 'string', parameters: { type: 'string' } },
|
||||
{ name: 'union', parameters: { type: 'object', anyOf: [object] } },
|
||||
{ name: 'bad_props', parameters: { type: 'object', properties: [] } },
|
||||
{ name: 'bad_required', parameters: { type: 'object', required: 'n' } },
|
||||
]]);
|
||||
// Through JSON: the default schema is built in the session's realm.
|
||||
assert.deepEqual(JSON.parse(JSON.stringify(offered[0].specs.map(spec => [spec.name, spec.inputSchema]))), [
|
||||
['ok', object],
|
||||
['no_params', { type: 'object', properties: {} }],
|
||||
]);
|
||||
assert.equal(warnings.length, 7);
|
||||
assert.ok(warnings.every(message => message.startsWith('Faceclaw: setAssistantTools: skipped tool')));
|
||||
assert.match(warnings[0], /"has space": name must be/);
|
||||
assert.match(warnings[2], /"untyped": parameters must be a JSON Schema with type "object"/);
|
||||
assert.match(warnings[4], /"union": parameters can't use oneOf, anyOf or allOf/);
|
||||
h.session.close();
|
||||
});
|
||||
Reference in new issue
Block a user