CI / build-and-test (push) Successful in 14m43s
7.3: capturedAt/source au registre + 6 adaptateurs + module provenance.ts + ?debug=1 (search-transport.mjs). 7.4: ProviderHealthService + badge source degradee. 7.6: squelettes par provider + snapshots progressifs + transport NDJSON /api/search. 8.1: ProviderAdapter unifie (search enveloppe + channelContent/channelMeta/capabilities) via getProviderAdapter + test de contrat offline.
103 lines
5.5 KiB
JavaScript
103 lines
5.5 KiB
JavaScript
/**
|
|
* Phase 8.1 — CONTRAT UNIQUE `ProviderAdapter`.
|
|
*
|
|
* Chaque provider expose LA MÊME forme : `{ id, label, search, suggest?,
|
|
* channelContent, channelMeta, capabilities }`. C'est le garde-fou du « un seul
|
|
* fichier par provider devient l'unique point de contact » : si quelqu'un ajoute
|
|
* un provider à la peine, ou casse un des 6 points de contact, la suite tombe.
|
|
*
|
|
* Aucun réseau n'est touché : la forme est vérifiée structurellement, et les
|
|
* membres appelables restent appelables (une recherche réelle se fait dans les
|
|
* suites des fixtures).
|
|
*/
|
|
import { describe, it } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
|
|
const { providerAdapters, providerRegistry, PROVIDER_CAPABILITIES, PROVIDER_IDS, getProviderAdapter } =
|
|
await import('../providers/registry.mjs');
|
|
|
|
const REQUIRED = ['id', 'label', 'search', 'channelContent', 'channelMeta', 'capabilities'];
|
|
|
|
describe('Phase 8.1 — contrat unique ProviderAdapter', () => {
|
|
it('les 6 providers sont présents et dans l\'ordre canonique', () => {
|
|
assert.deepEqual(Object.keys(providerAdapters).sort(), ['dm', 'od', 'pt', 'ru', 'tw', 'yt']);
|
|
assert.deepEqual(PROVIDER_IDS, ['yt', 'dm', 'tw', 'pt', 'od', 'ru']);
|
|
});
|
|
|
|
for (const pid of PROVIDER_IDS) {
|
|
it(`${pid}: forme complète du contrat`, () => {
|
|
const a = providerAdapters[pid];
|
|
assert.ok(a, 'adaptateur présent');
|
|
assert.equal(a.id, pid, 'id aligné');
|
|
assert.ok(String(a.label || '').length > 0, 'label non vide');
|
|
for (const key of REQUIRED) {
|
|
assert.ok(key in a, `clé requise \`${key}\` présente`);
|
|
}
|
|
assert.equal(typeof a.id, 'string', '`id` est une chaîne');
|
|
assert.equal(typeof a.label, 'string', '`label` est une chaîne');
|
|
assert.equal(typeof a.capabilities, 'object', '`capabilities` est un objet');
|
|
for (const member of ['search', 'channelContent', 'channelMeta']) {
|
|
assert.equal(typeof a[member], 'function', `\`${member}\` est appelable`);
|
|
}
|
|
if ('suggest' in a) {
|
|
assert.ok(a.suggest === undefined || typeof a.suggest === 'function', '`suggest` est fonction ou undefined');
|
|
}
|
|
if ('fetchChannelById' in a) {
|
|
assert.ok(a.fetchChannelById === undefined || typeof a.fetchChannelById === 'function',
|
|
'`fetchChannelById` (compat) est fonction ou undefined');
|
|
}
|
|
if ('suggest' in a && a.suggest !== undefined) {
|
|
assert.equal(typeof a.suggest, 'function', 'suggest est une fonction quand elle existe');
|
|
}
|
|
});
|
|
|
|
it(`${pid}: capabilities déclarées fidèles au comportement`, () => {
|
|
const a = providerAdapters[pid];
|
|
const caps = a.capabilities;
|
|
assert.equal(caps, PROVIDER_CAPABILITIES[pid], 'la même instance de capacités que la constante');
|
|
assert.equal(typeof caps.suggest, 'boolean', 'suggest: booléen');
|
|
assert.equal(typeof caps.live, 'boolean', 'live: booléen');
|
|
assert.equal(caps.channelMeta, true, 'chaque provider a des métadonnées de chaîne');
|
|
assert.ok(Array.isArray(caps.channelContent) && caps.channelContent.length > 0, 'liste de types de contenu non vide');
|
|
assert.ok(caps.channelContent.every((t) => ['videos', 'shorts', 'playlists', 'live'].includes(t)),
|
|
'types de contenu dans le vocabulaire connu');
|
|
assert.equal(caps.suggest, typeof a.suggest === 'function', 'suggest déclaré ⟺ suggest fourni');
|
|
assert.equal(caps.live, pid === 'tw', 'seul Twitch est live (fait observable)');
|
|
});
|
|
|
|
it(`${pid}: search du contrat EST la recherche enveloppée (cache → ref → provenance)`, () => {
|
|
// Le point de contact unifié doit servir la version DÉJÀ enveloppée par le
|
|
// registre (cache, channelRef, provenance) — pas une copie nue de module.
|
|
assert.equal(providerAdapters[pid].search, providerRegistry[pid].search,
|
|
'même fonction que le registre (les wrappers s\'appliquent en amont)');
|
|
});
|
|
|
|
it(`${pid}: channelContent et channelMeta sont câblés (appelables, distincts)`, () => {
|
|
const a = providerAdapters[pid];
|
|
assert.equal(typeof a.channelContent, 'function', 'channelContent appelable');
|
|
assert.equal(typeof a.channelMeta, 'function', 'channelMeta appelable');
|
|
assert.notEqual(a.channelContent, a.channelMeta, 'deux responsabilités distinctes');
|
|
// Le test de délégation se fait sans réseau : pour ru, ruContent passe par
|
|
// `ctx.searchRegistry` — on peut donc l'observer offline (cf. plus bas).
|
|
});
|
|
}
|
|
|
|
it('ru: channelContent délègue au registre de recherche via le contexte (offline)', async () => {
|
|
const a = providerAdapters.ru;
|
|
const fakeItem = { id: 'r1', title: 'Rumble seed', channelId: 'peerless-canal', uploaderName: 'peerless' };
|
|
const fakeRegistry = {
|
|
ru: { search: async () => [fakeItem, { id: 'r2', title: 'autre channel', channelId: 'autre' }] },
|
|
};
|
|
const out = await a.channelContent('peerless-canal', { type: 'videos', limit: 5 }, { searchRegistry: fakeRegistry });
|
|
assert.ok(Array.isArray(out.items), 'items normalisés');
|
|
assert.equal(out.items.length, 1, 'filtre par channelId canonique');
|
|
assert.equal(out.items[0].id, 'r1', 'l\'item retenu est le bon');
|
|
});
|
|
|
|
it('getProviderAdapter est l\'accès unique (et retombe sur le registre)', () => {
|
|
for (const pid of PROVIDER_IDS) {
|
|
assert.equal(getProviderAdapter(pid), providerAdapters[pid], `${pid} via getProviderAdapter`);
|
|
}
|
|
assert.equal(getProviderAdapter('nope'), undefined, 'provider inconnu : pas de crash, undefined propre');
|
|
});
|
|
}); |