Files
nav-carte/worker/test/proposition.test.js
T
JulesandClaude Opus 5.5 22618356aa feat(aep-15): vocabulaire du type proposé et extraction bornée
lib/taxonomie.js recopie les sept types et sept postures du site ; un test
garde l'égalité avec utils/taxonomie.ts. Hors vocabulaire : null.
lib/extraction.js borne la sortie du modèle avant R6 et R3 ; sans page,
confiance faible.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 18:52:34 +01:00

101 lines
4.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* Lot 15 — la proposition de type et de postures reste dans le vocabulaire du site (sinon null),
* et l'extraction rendue par le modèle est bornée avant d'entrer dans R6 et R3.
*/
import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { TYPES_ORGANISATION, POSTURES, LIBELLES_TYPE, LIBELLES_POSTURE, proposerType, proposerPostures } from '../lib/taxonomie.js';
import { extractionDepuisModele } from '../lib/extraction.js';
const ici = dirname(fileURLToPath(import.meta.url));
const SITE = readFileSync(join(ici, '..', '..', 'utils', 'taxonomie.ts'), 'utf-8');
/** Lit `export const NOM = [ ... ] as const` dans le fichier du site. */
function tableauDuSite(nom) {
const m = SITE.match(new RegExp(`export const ${nom} = \\[([^\\]]*)\\]`));
assert.ok(m, `${nom} introuvable dans utils/taxonomie.ts`);
return [...m[1].matchAll(/'([^']+)'/g)].map(x => x[1]);
}
/** Lit `export const NOM: Record<…> = { clé: 'libellé', … }` dans le fichier du site. */
function libellesDuSite(nom) {
const m = SITE.match(new RegExp(`export const ${nom}[^=]*= \\{([^}]*)\\}`));
assert.ok(m, `${nom} introuvable dans utils/taxonomie.ts`);
return Object.fromEntries([...m[1].matchAll(/'?([a-z-]+)'?:\s*'([^']+)'/g)].map(x => [x[1], x[2]]));
}
describe('lot 15 · vocabulaire du worker = vocabulaire du site (utils/taxonomie.ts)', () => {
it('sept types, sept postures, mêmes valeurs dans le même ordre', () => {
assert.deepEqual(TYPES_ORGANISATION, tableauDuSite('TYPES_ORGANISATION'));
assert.deepEqual(POSTURES, tableauDuSite('POSTURES'));
assert.equal(TYPES_ORGANISATION.length, 7);
assert.equal(POSTURES.length, 7);
});
it('mêmes libellés', () => {
assert.deepEqual(LIBELLES_TYPE, libellesDuSite('LIBELLES_TYPE'));
assert.deepEqual(LIBELLES_POSTURE, libellesDuSite('LIBELLES_POSTURE'));
});
});
describe('lot 15 · type et postures proposés', () => {
it('type : valeur ou libellé du vocabulaire, sinon null', () => {
assert.equal(proposerType('association'), 'association');
assert.equal(proposerType('Média'), 'media');
assert.equal(proposerType(' Syndicat '), 'syndicat');
for (const hors of ['collectif', 'ecosysteme', 'reseau', 'Association loi 1901', '', null, undefined, 42, ['association'], { type: 'agence' }]) {
assert.equal(proposerType(hors), null, JSON.stringify(hors));
}
});
it('postures : seules celles du vocabulaire, sans doublon, dans l’ordre du site', () => {
assert.deepEqual(proposerPostures(['Low tech', 'participatif', 'décroissance', 'Coopératif', 'participatif', 7]), ['cooperative', 'low-tech', 'participatif']);
assert.deepEqual(proposerPostures('regenerative'), []);
assert.deepEqual(proposerPostures(null), []);
assert.deepEqual(proposerPostures(['Bas carbone', 'Écoconstruction', 'Régénératif']), ['regenerative', 'bas-carbone', 'ecoconstruction']);
});
});
describe('lot 15 · extraction rendue par le modèle, bornée', () => {
it('champs hors format → null ou liste vide ; indices booléens seulement', () => {
const x = extractionDepuisModele({
objet: ' Portal.Place ', variantes: ['Portal Place', 'Portal Place', 3], porteurs: 'Mike Gilliland',
point_de_vue: 'officiel', confiance: 'certaine',
designations: [
{ nom: 'Portal.Place', indices: { agit: true, peut_cesser: 'oui', methode: false, inconnu: true }, date: 'hier' },
{ indices: { agit: true } },
'texte',
],
}, { avecPage: true });
assert.equal(x.objet, 'Portal.Place');
assert.deepEqual(x.variantes, ['Portal Place']);
assert.deepEqual(x.porteurs, []);
assert.equal(x.point_de_vue, null);
assert.equal(x.confiance, 'faible', 'confiance hors vocabulaire → faible');
assert.equal(x.designations.length, 1);
assert.deepEqual(x.designations[0].indices, { agit: true, methode: false });
assert.equal(x.designations[0].date, null);
});
it('sans page, la confiance est faible quoi que dise le modèle', () => {
assert.equal(extractionDepuisModele({ objet: 'X', confiance: 'haute' }, { avecPage: false }).confiance, 'faible');
assert.equal(extractionDepuisModele({ objet: 'X', confiance: 'haute' }, { avecPage: true }).confiance, 'haute');
});
it('au plus cinq désignations, noms bornés à 200 caractères', () => {
const x = extractionDepuisModele({ objet: 'a'.repeat(500), designations: Array.from({ length: 9 }, (_, i) => ({ nom: `d${i}`, indices: {} })) }, { avecPage: true });
assert.equal(x.objet.length, 200);
assert.equal(x.designations.length, 5);
});
it('sortie absente ou illisible → extraction vide, jamais d’exception', () => {
for (const s of [null, undefined, 'texte', 42, []]) {
const x = extractionDepuisModele(s, { avecPage: true });
assert.equal(x.objet, null);
assert.deepEqual(x.designations, []);
}
});
});