data(taxonomie): M3 le mapping type × postures des 211 fiches, utils/taxonomie et son test (B4a)

- data/taxonomie/organisations.json : 91 org:<Id NocoDB> + 120 structure:<id>, type
  d'organisation et postures de la taxonomie N, une source par valeur.
- Règle : le type d'abord par les champs (type_org, nom, type_principal, première phrase
  de la description), autre quand rien ne tranche ; une posture seulement si un hashtag,
  une pensée, la famille ou la description la porte. README : la règle et comment
  corriger une entrée sur Gitea ; B4b la portera dans NocoDB.
- utils/taxonomie.ts (pur) : vocabulaire, libellés, classement avec repli autre,
  contrôle du mapping. useFicheAdapter : toMini(source, classer) pose type et postures.
- scripts/test-taxonomie.mjs (34 cas), dans npm run test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWGVn3kY4vPBaWF9EFkZbz
This commit is contained in:
Jules Neny
2026-11-03 14:54:23 +01:00
co-authored by Claude Opus 5.5
parent 951685ee47
commit 31f563684d
6 changed files with 2864 additions and 2 deletions
+103
View File
@@ -0,0 +1,103 @@
#!/usr/bin/env node
/**
* Test de la taxonomie de la carte (B4a-M3) : vocabulaire (taxonomie N), mapping
* `data/taxonomie/organisations.json` complet (91 org + 120 structures = 211 identifiants),
* aucune valeur hors vocabulaire, aucune posture sans source, repli `autre` pour un
* identifiant absent, et les étiquettes `type` / `postures` posées par `toMini`.
* Charge les VRAIS fichiers via jiti (même patron que test-vue-fiches.mjs).
* Usage : node scripts/test-taxonomie.mjs
*/
import { createJiti } from 'jiti'
import { fileURLToPath } from 'node:url'
import { dirname, join } from 'node:path'
import { readFileSync } from 'node:fs'
const __dirname = dirname(fileURLToPath(import.meta.url))
const racine = join(__dirname, '..')
const jiti = createJiti(import.meta.url)
const T = await jiti.import(join(racine, 'utils', 'taxonomie.ts'))
const A = await jiti.import(join(racine, 'composables', 'useFicheAdapter.ts'))
const reseaux = JSON.parse(readFileSync(join(racine, 'public', 'data', 'reseaux-bifurcation.json'), 'utf8'))
let n = 0
let fail = 0
function ok(cond, libelle, detail = '') {
n++
if (!cond) fail++
console.log(`${cond ? 'OK ' : 'FAIL'} ${libelle}${!cond && detail ? ` → ${detail}` : ''}`)
}
const eq = (a, b) => JSON.stringify(a) === JSON.stringify(b)
// ── Vocabulaire : les sept types et les sept postures de N, un libellé chacun ──
ok(eq([...T.TYPES_ORGANISATION], ['institution', 'association', 'syndicat', 'agence', 'formation', 'media', 'autre']), 'types : les sept valeurs de N, dans l’ordre')
ok(eq([...T.POSTURES], ['regenerative', 'bas-carbone', 'cooperative', 'patrimoine', 'ecoconstruction', 'low-tech', 'participatif']), 'postures : les sept valeurs de N, dans l’ordre')
ok(T.TYPES_ORGANISATION.every((t) => T.LIBELLES_TYPE[t]?.length > 0) && Object.keys(T.LIBELLES_TYPE).length === 7, 'un libellé par type, pas un de plus')
ok(T.POSTURES.every((p) => T.LIBELLES_POSTURE[p]?.length > 0) && Object.keys(T.LIBELLES_POSTURE).length === 7, 'un libellé par posture, pas un de plus')
ok(T.LIBELLES_TYPE.media === 'Média' && T.LIBELLES_POSTURE.ecoconstruction === 'Écoconstruction', 'libellés accentués')
// ── Mapping complet : 211 identifiants ──
const ids = Object.keys(T.MAPPING.entrees)
const orgIds = ids.filter((id) => id.startsWith('org:'))
const structIds = ids.filter((id) => id.startsWith('structure:'))
ok(ids.length === 211, `211 entrées (${ids.length})`)
ok(orgIds.length === 91, `91 structures d'entraide org:<Id> (${orgIds.length})`)
ok(structIds.length === 120, `120 réseaux et agences structure:<id> (${structIds.length})`)
const attendues = reseaux.structures.map((s) => T.idStructure(s.id))
const manquantes = attendues.filter((id) => !T.MAPPING.entrees[id])
ok(manquantes.length === 0, 'chaque structure de reseaux-bifurcation.json a son entrée', manquantes.join(', '))
ok(structIds.every((id) => attendues.includes(id)), 'aucune entrée structure: sans structure dans le JSON')
ok(orgIds.every((id) => /^org:\d+$/.test(id)), 'identifiants org: numériques (Id NocoDB)')
// ── La règle : vocabulaire, sources ──
const ecarts = T.ecartsMapping(T.MAPPING)
ok(ecarts.length === 0, 'mapping conforme : types et postures dans le vocabulaire, une source par valeur', ecarts.slice(0, 5).join(' | '))
const valeursType = new Set(Object.values(T.MAPPING.entrees).map((e) => e.type_organisation))
ok([...valeursType].every((v) => T.TYPES_ORGANISATION.includes(v)), `aucun type hors vocabulaire (${[...valeursType].join(', ')})`)
const sansSource = Object.entries(T.MAPPING.entrees).flatMap(([id, e]) => e.postures.filter((p) => !e.source.postures[p]).map((p) => `${id}/${p}`))
ok(sansSource.length === 0, 'aucune posture sans source', sansSource.join(', '))
ok(Object.values(T.MAPPING.entrees).every((e) => typeof e.nom === 'string' && e.nom.length > 0), 'chaque entrée porte le nom de la fiche (pour qui corrige à la main)')
// L'outil de contrôle lui-même attrape les fautes
const faux = {
version: 1,
entrees: {
'org:1': { type_organisation: 'ong', postures: [], source: { type_organisation: 'x', postures: {} } },
'org:2': { type_organisation: 'agence', postures: ['low-tech'], source: { type_organisation: 'x', postures: {} } },
'org:3': { type_organisation: 'agence', postures: ['verte'], source: { type_organisation: 'x', postures: { verte: 'y' } } },
'org:4': { type_organisation: 'agence', postures: [], source: { type_organisation: '', postures: {} } },
'Org 5': { type_organisation: 'agence', postures: [], source: { type_organisation: 'x', postures: {} } },
},
}
const e = T.ecartsMapping(faux)
ok(e.some((x) => x.startsWith('org:1') && x.includes('hors vocabulaire')), 'contrôle : type hors vocabulaire attrapé')
ok(e.some((x) => x.startsWith('org:2') && x.includes('sans source')), 'contrôle : posture sans source attrapée')
ok(e.some((x) => x.startsWith('org:3') && x.includes('hors vocabulaire')), 'contrôle : posture hors vocabulaire attrapée')
ok(e.some((x) => x.startsWith('org:4') && x.includes('type sans source')), 'contrôle : type sans source attrapé')
ok(e.some((x) => x.startsWith('Org 5') && x.includes('hors forme')), 'contrôle : identifiant hors forme attrapé')
// ── Lecture : classement et repli ──
ok(eq(T.classement('org:999999'), { type: 'autre', postures: [] }), 'identifiant absent → autre, sans posture')
ok(eq(T.classement('structure:inconnue'), { type: 'autre', postures: [] }), 'structure absente → autre')
ok(eq(T.classement('org:1', faux), { type: 'autre', postures: [] }), 'type hors vocabulaire → autre')
ok(eq(T.classement('org:2', faux).postures, []), 'posture sans source → pas affichée')
ok(eq(T.classement('org:3', faux).postures, []), 'posture hors vocabulaire → ignorée')
const rotor = T.classement('structure:f1-rotor')
ok(T.TYPES_ORGANISATION.includes(rotor.type) && rotor.postures.every((p) => T.POSTURES.includes(p)), `structure:f1-rotor lue (${rotor.type} · ${rotor.postures.join(', ')})`)
ok(T.classement('org:106').type === 'institution', 'org:106 (CNOA) → institution (nom : Ordre)')
ok(T.classement('org:37').type === 'syndicat', 'org:37 (UNSFA) → syndicat (nom)')
ok(eq(T.valeursPresentes(T.POSTURES, T.LIBELLES_POSTURE, ['participatif', 'bas-carbone', 'x']).map((v) => v.valeur), ['bas-carbone', 'participatif']), 'valeursPresentes : ordre du vocabulaire, inconnues ignorées')
// ── useFicheAdapter : étiquettes type et postures ──
const s = reseaux.structures.find((x) => x.id === 'f1-rotor')
const mS = A.toMini(s, T.classement)
ok(eq(mS.etiquettes.type, [rotor.type]) && eq(mS.etiquettes.postures, rotor.postures), 'toMini(structure, classement) : étiquettes type et postures')
ok(mS.etiquettes.tags.length > 0 && mS.etiquettes.famille.length > 0, 'toMini : les étiquettes d’avant restent (tags, famille)')
const org = { Id: 106, nom: 'CNOA', echelle: 'National', tags_fonction: 'Juridique', territoire: 'Métropole' }
const mO = A.toMini(org, T.classement)
ok(eq(mO.etiquettes.type, ['institution']) && eq(mO.etiquettes.fonctions, ['Juridique']), 'toMini(org, classement) : type posé, fonctions inchangées')
ok(eq(A.toMini({ ...org, Id: 424242 }, T.classement).etiquettes.type, ['autre']), 'toMini : fiche absente du mapping → type autre')
ok(!('type' in A.toMini(org).etiquettes) && !('type' in [org].map(A.toMini)[0].etiquettes), 'toMini sans classeur (ou avec l’index de map) : rien d’ajouté')
console.log(`\n${n - fail}/${n}`)
if (fail) process.exit(1)