Ran the deployed workflow for real (temporary webhook trigger, briefly
activated, immediately deactivated and removed after each attempt) against
the real GLPI MySQL database and a real OpenAI credential. Found and fixed:
1. $env access is blocked on this n8n instance (N8N_BLOCK_ENV_ACCESS_IN_NODE).
parseConfig($env) threw "access to env vars denied" on the very first
Code node. Config now comes from the "Config - Coordenador GLPI v2" Set
node instead (same pattern the V1 workflow already used) -- expanded
that node with all 13 tunable parameters, and pointed the 3 affected
node drivers (build-sql-candidatos, decide-needs-ai, select-top10) at
it instead of $env.
2. Data Table "upsert" operation requires both `columns` (values) and a
separate `filters` (match condition) -- I had only set columns with
matchingColumns, which isn't enough; n8n refused to activate the
workflow ("Missing or invalid required parameters: filters"). Added
filters.conditions matching on ticket_id to both memory-writing Data
Table nodes.
3. Real architecture bug: "Data Table - Buscar Memoria" sat inline in the
41-candidate chain (Mesclar Contexto -> Buscar Memoria -> Decidir
Necessidade de IA). A bulk "get all rows" Data Table node run with 41
input items produced 41 identical fetches and its OWN output (the empty
memory table on a first run) replaced the 41 candidates entirely --
"Decidir Necessidade de IA" received 0 items and the whole main branch
silently skipped. Moved the memory fetch to a parallel branch off
Config (fires once) and added a real Merge node ("Merge - Aguardar
Memoria") to guarantee both the candidates and the memory rows have
executed before "Decidir Necessidade de IA" runs -- same synchronization
pattern already used for context and for the shadow comparison.
Also fixed a cosmetic bug found in the real message output: buildTopMessage
produced a quadruple newline between the header and the first ticket block
([header, '', ...blocks].join('\n\n') double-counts the blank line already
inserted by the '\n\n' join). Added a regression test.
Verified with a real execution (id 13599, 24/08/2026 19:25 UTC) against the
live GLPI database: 41 real candidates, 30 sent to OpenAI (capped), 11
fallback-capped, memory table populated with 41 real rows including
genuine WAITING_VENDOR/WAITING_REQUESTER classifications with real
blocker_type/waiting_for fields extracted from real ticket task content,
and a real shadow_runs row comparing Legacy x V2 (4 tickets removed by V2:
2 for INSUFFICIENT_CONTEXT, 1 WAITING_REQUESTER, 1 WAITING_VENDOR; 4 added).
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
52 lines
2.2 KiB
JavaScript
52 lines
2.2 KiB
JavaScript
const { test } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const { buildTopMessage, buildCoordinationDigest, shortActionLabel, tituloCurto } = require('./message');
|
|
|
|
function selectedItem(overrides) {
|
|
return Object.assign({
|
|
ticket: {
|
|
id: 38611, titulo: 'Colocar etiqueta sala 03', tecnico_atribuido: 'Sem tecnico atribuido',
|
|
sem_tecnico: true, sla_vencido: false, dias_sem_interacao: 2, link_glpi: 'https://glpi/x?id=38611',
|
|
},
|
|
aiClassification: { classification: 'UNASSIGNED_ACTIONABLE', next_action: 'Atribuir e executar', is_fallback: false },
|
|
}, overrides);
|
|
}
|
|
|
|
test('mensagem final contem cabecalho, id, link e acao curta', () => {
|
|
const msg = buildTopMessage([selectedItem({})], '24/08', {});
|
|
assert.ok(msg.includes('#38611'));
|
|
assert.ok(msg.includes('https://glpi/x?id=38611'));
|
|
assert.ok(msg.includes('→'));
|
|
assert.ok(msg.includes('24/08'));
|
|
});
|
|
|
|
test('mensagem NAO contem score, confianca ou justificativa longa', () => {
|
|
const msg = buildTopMessage([selectedItem({})], '24/08', {});
|
|
assert.ok(!/confian(c|ç)a/i.test(msg));
|
|
assert.ok(!/score/i.test(msg));
|
|
});
|
|
|
|
test('linha de acao e curta (limite de tamanho)', () => {
|
|
const label = shortActionLabel({ classification: 'ACTIONABLE_NOW', next_action: 'x'.repeat(100), is_fallback: false });
|
|
assert.ok(label.length <= 40);
|
|
});
|
|
|
|
test('tituloCurto limita a 60 caracteres', () => {
|
|
const curto = tituloCurto('a'.repeat(100));
|
|
assert.ok(curto.length <= 60);
|
|
});
|
|
|
|
test('digest de coordenacao vazio retorna null (nao manda lista igual todo dia)', () => {
|
|
assert.equal(buildCoordinationDigest([], '24/08'), null);
|
|
});
|
|
|
|
test('mensagem nao tem linhas em branco duplicadas entre cabecalho e blocos', () => {
|
|
const msg = buildTopMessage([selectedItem({}), selectedItem({ ticket: { ...selectedItem({}).ticket, id: 38612 } })], '24/08', {});
|
|
assert.ok(!msg.includes('\n\n\n'), 'nao deveria haver 3+ quebras de linha seguidas');
|
|
});
|
|
|
|
test('digest de coordenacao lista apenas os itens passados (novos/alterados)', () => {
|
|
const digest = buildCoordinationDigest([{ ticket: { id: 37691 }, aiClassification: { reason: 'aguardando definicao' }, exclusionReason: 'needs_coordination' }], '24/08');
|
|
assert.ok(digest.includes('#37691'));
|
|
});
|