mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-25 14:17:31 +00:00
fix(plugins): bind a Buffer a plugin passes to its own database as bytes
A Buffer crosses the plugin IPC as its JSON form, so db.query, db.exec and db.tx now turn that form back into the bytes before binding, as the plugin docs promise.
This commit is contained in:
@@ -142,6 +142,30 @@ describe('PluginSupervisor — isolated runtime', () => {
|
||||
expect(events.some((e) => e.topic === '__log')).toBe(true);
|
||||
});
|
||||
|
||||
it('binds a Buffer a plugin passes to ctx.db as its bytes across the fork, in query, exec and tx', async () => {
|
||||
const events: Array<{ topic: string; data: unknown }> = [];
|
||||
sup = makeSupervisor(events);
|
||||
writePlugin(
|
||||
'binkeys',
|
||||
`module.exports = {
|
||||
async onLoad(ctx) {
|
||||
await ctx.db.migrate('001', 'CREATE TABLE kv (k BLOB PRIMARY KEY, v TEXT)');
|
||||
await ctx.db.exec('INSERT INTO kv (k, v) VALUES (?, ?)', Buffer.from([1, 0, 2]), 'exec');
|
||||
await ctx.db.tx([{ sql: 'INSERT INTO kv (k, v) VALUES (?, ?)', args: [Buffer.from([3, 0, 4]), 'tx'] }]);
|
||||
const rows = await ctx.db.query('SELECT v, hex(k) AS h FROM kv WHERE k IN (?, ?) ORDER BY v', Buffer.from([1, 0, 2]), Buffer.from([3, 0, 4]));
|
||||
ctx.log.info('bin', { rows });
|
||||
}
|
||||
};`,
|
||||
);
|
||||
|
||||
await sup.activate('binkeys', new Set(['db:own']), {});
|
||||
|
||||
expect(logMeta<{ rows: unknown[] }>(events, 'bin').rows).toEqual([
|
||||
{ v: 'exec', h: '010002' },
|
||||
{ v: 'tx', h: '030004' },
|
||||
]);
|
||||
});
|
||||
|
||||
it('dispatches invoke.hook + invoke.event across the fork (provider hooks + event subscriptions)', async () => {
|
||||
const events: Array<{ topic: string; data: unknown }> = [];
|
||||
sup = makeSupervisor(events);
|
||||
|
||||
Reference in New Issue
Block a user