mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-18 21:16:47 +00:00
95f9f031c4
The entity reads of the plugin RPC surface handed plugins whatever their query produced, mostly SELECT t.*, with credentials stripped by a denylist (withoutFeedToken). Every column a migration added reached every plugin holding the read grant, and renaming one was an unversioned break of a published API. protocol/output-contract.ts now states, for every wire method, what its result is: rows of one of the nine entities the SDK types (trip, place, day, reservation, packingItem, tripFile, budgetItem, assignment, user), a value the host builds itself, or a read model passed on as the REST route returns it. The router applies it to each result on the way out, so an entity row keeps exactly the fields plugins received when the list was drawn, in the same order and with the same values, minus the trip's feed_token (listMine, create and update used to carry it as null). The table is keyed by every method, so a new one does not compile without an entry. output-contract.schema.test.ts holds the lists to the migrated schema: a new column on a whole-row table fails until it is published or withheld, and each entity method is called on the real services to prove the contract drops nothing but the withheld fields. gen:plugin-facts publishes the lists to the SDK as PLUGIN_ENTITY_FIELDS and PLUGIN_METHOD_RESULT, and the SDK's entity interfaces are type-checked against them. Place.day_id, which no read ever delivered, is deprecated rather than removed. KNOWN_ADDONS is generated from ADDON_IDS as well, which adds the dawarich, roadtrip and tours ids the hand-kept copy lacked. The SDK goes to 1.9.0, and its README and the plugin wiki pages describe what a ctx call returns.
52 lines
2.6 KiB
TypeScript
52 lines
2.6 KiB
TypeScript
/**
|
|
* The output contract as the SDK publishes it. The lists are generated from the host's
|
|
* protocol/output-contract.ts (server check:plugin-facts keeps them in sync) and the
|
|
* entity interfaces in src/index.ts are type-checked against them; these cases pin the
|
|
* runtime side: what the exports hold and that they cover the method vocabulary.
|
|
*/
|
|
import { describe, it, expect } from 'vitest';
|
|
import { PLUGIN_ENTITY_FIELDS, PLUGIN_METHOD_RESULT } from '../src/index.js';
|
|
import { KNOWN_ADDONS } from '../src/manifest.js';
|
|
import { KNOWN_METHODS } from '../src/generated/host-facts.js';
|
|
|
|
describe('PLUGIN_ENTITY_FIELDS', () => {
|
|
it('names the fields plugins rely on and never a credential', () => {
|
|
expect(PLUGIN_ENTITY_FIELDS.trip).toEqual(expect.arrayContaining(['id', 'user_id', 'title', 'start_date', 'end_date', 'currency']));
|
|
expect(PLUGIN_ENTITY_FIELDS.trip).not.toContain('feed_token');
|
|
expect(PLUGIN_ENTITY_FIELDS.user).toEqual(['id', 'username', 'display_name', 'avatar']);
|
|
expect(PLUGIN_ENTITY_FIELDS.place).toEqual(expect.arrayContaining(['trip_id', 'name', 'lat', 'lng', 'category_id', 'notes']));
|
|
// A place has no day of its own: Place.day_id is deprecated, never delivered.
|
|
expect(PLUGIN_ENTITY_FIELDS.place).not.toContain('day_id');
|
|
});
|
|
|
|
it('lists every field once', () => {
|
|
for (const fields of Object.values(PLUGIN_ENTITY_FIELDS)) {
|
|
expect(new Set(fields).size).toBe(fields.length);
|
|
}
|
|
});
|
|
});
|
|
|
|
describe('PLUGIN_METHOD_RESULT', () => {
|
|
it('describes every wire method plus the three unconditional ones', () => {
|
|
for (const method of KNOWN_METHODS) expect(PLUGIN_METHOD_RESULT[method]).toBeDefined();
|
|
for (const method of ['plugins.call', 'events.emit', 'settings.get']) expect(PLUGIN_METHOD_RESULT[method]).toBeDefined();
|
|
expect(Object.keys(PLUGIN_METHOD_RESULT)).toHaveLength(KNOWN_METHODS.length + 3);
|
|
});
|
|
|
|
it('names only entities that have a field list, or host or readModel', () => {
|
|
for (const result of Object.values(PLUGIN_METHOD_RESULT)) {
|
|
const entity = result.replace(/\[\]$/, '');
|
|
expect(entity in PLUGIN_ENTITY_FIELDS || entity === 'host' || entity === 'readModel').toBe(true);
|
|
}
|
|
expect(PLUGIN_METHOD_RESULT['trips.getById']).toBe('trip');
|
|
expect(PLUGIN_METHOD_RESULT['trips.getPlaces']).toBe('place[]');
|
|
expect(PLUGIN_METHOD_RESULT['db.query']).toBe('host');
|
|
});
|
|
});
|
|
|
|
describe('KNOWN_ADDONS', () => {
|
|
it('carries the addons the hand-kept copy had missed', () => {
|
|
expect(KNOWN_ADDONS).toEqual(expect.arrayContaining(['dawarich', 'roadtrip', 'tours', 'budget', 'collections']));
|
|
});
|
|
});
|