fix(aep-15): description, nom et ville du modèle bornés avant la colonne
Checkpoint 22/11, correction 4. Ces trois textes n'étaient bornés que par leur type. lib/extraction.js::texteBorne les coupe à 300, 200 et 100 caractères (en points de code), une chaîne vide vaut null. Antérieur au lot, mais le lot touche ces lignes. Tests : texteBorne seul, et un PATCH à blanc où le modèle rend 1 200 / 450 / 400 caractères. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+9
-6
@@ -35,7 +35,7 @@ import { dirname, join } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { messageFicheEnrichie, hoteDuLien } from './lib/messageNtfy.js';
|
||||
import { recupererPage, controlerAdresse, tableRedirections } from './lib/recupererPage.js';
|
||||
import { extractionDepuisModele } from './lib/extraction.js';
|
||||
import { extractionDepuisModele, texteBorne, MAX_COLONNES } from './lib/extraction.js';
|
||||
import {
|
||||
CHAMPS_BASE, CHAMPS_ECRITS, VERSION_SORTIE, baseDepuisFiches, passeAdresse, resoudreLot,
|
||||
propositionTaxonomie, statutApresEnrichissement, relireScrape, lienPrincipal, lirePagine,
|
||||
@@ -683,7 +683,8 @@ async function run() {
|
||||
const normalizedTags = [...new Set(rawTags.map(normalizeTag).filter(Boolean))];
|
||||
|
||||
const updateData = {
|
||||
description_enrichie: typeof enriched.description === 'string' ? enriched.description : null,
|
||||
// Checkpoint 22/11 : les textes du modèle écrits en colonne sont bornés (300, 200, 100).
|
||||
description_enrichie: texteBorne(enriched.description, MAX_COLONNES.description_enrichie),
|
||||
tags_fonction: normalizedTags.join(','),
|
||||
moderation_status: statutApresEnrichissement(resolu?.r6),
|
||||
ai_processed: true,
|
||||
@@ -700,11 +701,13 @@ async function run() {
|
||||
};
|
||||
|
||||
// Nom : ne remplacer que le placeholder posé par le formulaire assoupli (B5-M1).
|
||||
if (typeof enriched.nom === 'string' && enriched.nom && typeof row.nom === 'string' && row.nom.startsWith('[à qualifier]')) {
|
||||
updateData.nom = enriched.nom;
|
||||
const nomPropose = texteBorne(enriched.nom, MAX_COLONNES.nom);
|
||||
if (nomPropose && typeof row.nom === 'string' && row.nom.startsWith('[à qualifier]')) {
|
||||
updateData.nom = nomPropose;
|
||||
}
|
||||
if (typeof enriched.ville === 'string' && enriched.ville && !row.localisation_ville) {
|
||||
updateData.localisation_ville = enriched.ville;
|
||||
const villeProposee = texteBorne(enriched.ville, MAX_COLONNES.localisation_ville);
|
||||
if (villeProposee && !row.localisation_ville) {
|
||||
updateData.localisation_ville = villeProposee;
|
||||
}
|
||||
// submission_type : ne réajuster que si l'utilisateur n'avait pas choisi de chip
|
||||
// (marqueur posé par utils/submitLibre.ts::toOrgaPayload — "Type : non précisé").
|
||||
|
||||
@@ -24,6 +24,21 @@ function texte(v, max = MAX_NOM) {
|
||||
return s ? s.slice(0, max) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Champs du modèle écrits tels quels dans une colonne (checkpoint 22/11) : bornés en longueur.
|
||||
* Coupés en points de code (jamais au milieu d'un caractère) ; seuls les bords sont rognés.
|
||||
*/
|
||||
export const MAX_COLONNES = { description_enrichie: 300, nom: 200, localisation_ville: 100 };
|
||||
|
||||
/** Texte du modèle destiné à une colonne → chaîne bornée à `max` caractères, ou null (vide compris). */
|
||||
export function texteBorne(v, max) {
|
||||
if (typeof v !== 'string') return null;
|
||||
const s = v.trim();
|
||||
if (!s) return null;
|
||||
const car = Array.from(s);
|
||||
return car.length > max ? car.slice(0, max).join('').trimEnd() : s;
|
||||
}
|
||||
|
||||
function listeTextes(v, max = MAX_LISTE) {
|
||||
if (!Array.isArray(v)) return [];
|
||||
return [...new Set(v.map(x => texte(x)).filter(Boolean))].slice(0, max);
|
||||
|
||||
@@ -365,3 +365,18 @@ describe('checkpoint 22/11 · pagination de la base de R6 (correction 3)', () =>
|
||||
assert.equal(r.finale(401).sortie.r6.cible.id, 'fiche:2000');
|
||||
});
|
||||
});
|
||||
|
||||
describe('checkpoint 22/11 · sortie du modèle bornée avant la colonne (correction 4)', () => {
|
||||
it('description 300, nom 200, ville 100 : jamais plus long dans le PATCH', () => {
|
||||
const r = jouer({
|
||||
lignes: [ficheDepuis({ soumis: { url: 'https://exemple.org' } }, 501)],
|
||||
base: [],
|
||||
modele: { 501: { nom: 'N'.repeat(450), description: 'D'.repeat(1200), ville: 'V'.repeat(400), objet: 'Exemple', porteurs: [], designations: [], confiance: 'haute' } },
|
||||
});
|
||||
const f = r.finale(501);
|
||||
assert.equal(f.description_enrichie.length, 300);
|
||||
assert.equal(f.nom.length, 200);
|
||||
assert.equal(f.localisation_ville.length, 100);
|
||||
champsTenus(r.patchs);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -8,7 +8,7 @@ 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';
|
||||
import { extractionDepuisModele, texteBorne, MAX_COLONNES } from '../lib/extraction.js';
|
||||
|
||||
const ici = dirname(fileURLToPath(import.meta.url));
|
||||
const SITE = readFileSync(join(ici, '..', '..', 'utils', 'taxonomie.ts'), 'utf-8');
|
||||
@@ -98,3 +98,13 @@ describe('lot 15 · extraction rendue par le modèle, bornée', () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('checkpoint 22/11 · textes du modèle écrits en colonne, bornés (correction 4)', () => {
|
||||
it('300, 200 et 100 caractères ; coupe en points de code ; vide et non-texte → null', () => {
|
||||
assert.deepEqual(MAX_COLONNES, { description_enrichie: 300, nom: 200, localisation_ville: 100 });
|
||||
assert.equal(texteBorne('a'.repeat(500), 300).length, 300);
|
||||
assert.equal(texteBorne(' Lyon ', 100), 'Lyon');
|
||||
assert.equal(texteBorne('é'.repeat(99) + '😀😀', 100), 'é'.repeat(99) + '😀', 'jamais la moitié d’un émoji');
|
||||
for (const v of [null, undefined, 42, {}, ['x'], '', ' ']) assert.equal(texteBorne(v, 100), null);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user