openvibers/openvibe.network Commits

Design's ai.chat reaches the production grant row (#534)

OP OpenVibers committed 11 days ago · 74c4de1a80 · 2 files, +33 −0

Network #533 added ai.chat to Design's default AI grant, but the seed inserts with ON CONFLICT DO NOTHING, so
production's row kept ['ai.generate'] and Design's frames still failed. CHANGED_DEFAULT_NAMESPACES now moves a
row still exactly as the old default seeded it; test/design-ai-chat-grant.test.js sets the old row and boots.

Changes

ddiff --git a/server/identity/principals.js b/server/identity/principals.js
iindex dfd69024..4322262c 100644
---- a/server/identity/principals.js
++++ b/server/identity/principals.js
@@@ -784,6 +784,10 @@ const CHANGED_DEFAULT_NAMESPACES = [
['media-hub', 'ai.run.create', 'openvibe.ai', ['media.analyze'], ['media.analyze', 'pics.describe_image']],
// Search's embedder runs AI workflow ai.embed (contracts 0.234.0; POST /api/v1/embed for hybrid ranking).
['search', 'ai.run.create', 'openvibe.ai', ['research.*'], ['research.*', 'ai.embed']],
++ // Design's frames with a preference run ai.chat (Design #57, 10-31). Network #533 added it to the default; the
++ // production row, seeded before, kept ['ai.generate'] (the seed never changes an existing row), so frames still
++ // failed until this moved it.
++ ['design', 'ai.run.create', 'openvibe.ai', ['ai.generate'], ['ai.generate', 'ai.chat']],
];
async function ensureSchema(db) {
ddiff --git a/test/design-ai-chat-grant.test.js b/test/design-ai-chat-grant.test.js
nnew file mode 100644
iindex 00000000..a108cab1
---- /dev/null
++++ b/test/design-ai-chat-grant.test.js
@@@ -0,0 +1,29 @@
++/**
++ * Design's AI grant reaches the row production already has (11-02): Design's frames with a preference run AI's ai.chat
++ * workflow, and the default grant names ai.generate and ai.chat. The seed never changes an existing row, so a row
++ * seeded before with ['ai.generate'] must be moved at boot; a row someone edited by hand is left alone.
++ *
++ * node test/design-ai-chat-grant.test.js
++ */
++'use strict';
++const assert = require('assert');
++const { getDb } = require('../server/db/database');
++const principals = require('../server/identity/principals');
++
++(async () => {
++ const db = getDb();
++ await principals.ensureSchema(db);
++ const row = async () => JSON.parse((await db.prepare("SELECT namespaces FROM principal_grants WHERE client_id = 'design' AND capability = 'ai.run.create' AND audience = 'openvibe.ai'").get()).namespaces);
++ assert.deepStrictEqual((await row()).sort(), ['ai.chat', 'ai.generate'], 'a fresh database gets both');
++
++ // Production's row, as the old default seeded it.
++ await db.prepare("UPDATE principal_grants SET namespaces = ? WHERE client_id = 'design' AND capability = 'ai.run.create' AND audience = 'openvibe.ai'").run(JSON.stringify(['ai.generate']));
++ await principals.ensureSchema(db);
++ assert.deepStrictEqual(await row(), ['ai.generate', 'ai.chat'], 'the old default row is moved at boot');
++
++ // A row edited by hand stays as it was.
++ await db.prepare("UPDATE principal_grants SET namespaces = ? WHERE client_id = 'design' AND capability = 'ai.run.create' AND audience = 'openvibe.ai'").run(JSON.stringify(['ai.generate', 'custom.x']));
++ await principals.ensureSchema(db);
++ assert.deepStrictEqual(await row(), ['ai.generate', 'custom.x'], 'an edited row is left alone');
++ console.log('design ai.chat grant: all checks passed');
++})().catch((e) => { console.error(e); process.exit(1); });