feat(v2): add state-based cooldown with critical override
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
efba7792fa
commit
014c48d578
@@ -0,0 +1,50 @@
|
||||
const { test } = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { computeCooldown } = require('./cooldown');
|
||||
|
||||
const CONFIG = { cooldownDays: 1 };
|
||||
const NOW = new Date('2026-08-24T08:00:00Z').getTime();
|
||||
const ONE_DAY = 24 * 60 * 60 * 1000;
|
||||
|
||||
function ticket(overrides) {
|
||||
return Object.assign({ sla_vencido: false, prioridade: 2, urgencia: 2 }, overrides);
|
||||
}
|
||||
|
||||
test('WAITING_VENDOR sem mudanca de contexto fica bloqueado (nao repete diariamente)', () => {
|
||||
const memory = { consecutive_days_sent: 2, last_sent_at: NOW - ONE_DAY, next_review_at: NOW + ONE_DAY };
|
||||
const result = computeCooldown({ ticket: ticket({}), classification: 'WAITING_VENDOR', contextChanged: false, memory, now: NOW, config: CONFIG });
|
||||
assert.equal(result.blocked, true);
|
||||
});
|
||||
|
||||
test('enviado ontem sem mudanca recebe penalidade crescente', () => {
|
||||
const memory = { consecutive_days_sent: 3, last_sent_at: NOW - ONE_DAY, next_review_at: null };
|
||||
const result = computeCooldown({ ticket: ticket({}), classification: 'ACTIONABLE_NOW', contextChanged: false, memory, now: NOW, config: CONFIG });
|
||||
assert.ok(result.penalty > 0);
|
||||
assert.equal(result.blocked, false);
|
||||
});
|
||||
|
||||
test('mudanca de contexto real desbloqueia mesmo em estado de espera', () => {
|
||||
const memory = { consecutive_days_sent: 2, last_sent_at: NOW - ONE_DAY, next_review_at: NOW + ONE_DAY };
|
||||
const result = computeCooldown({ ticket: ticket({}), classification: 'WAITING_VENDOR', contextChanged: true, memory, now: NOW, config: CONFIG });
|
||||
assert.equal(result.blocked, false);
|
||||
});
|
||||
|
||||
test('NEEDS_COORDINATION sempre bloqueado para o Top 10 diario', () => {
|
||||
const result = computeCooldown({ ticket: ticket({}), classification: 'NEEDS_COORDINATION', contextChanged: false, memory: null, now: NOW, config: CONFIG });
|
||||
assert.equal(result.blocked, true);
|
||||
assert.equal(result.reason, 'needs_coordination');
|
||||
});
|
||||
|
||||
test('chamado critico (SLA vencido + prioridade alta) quebra o cooldown', () => {
|
||||
const memory = { consecutive_days_sent: 4, last_sent_at: NOW - ONE_DAY, next_review_at: NOW + ONE_DAY };
|
||||
const critico = ticket({ sla_vencido: true, prioridade: 5 });
|
||||
const result = computeCooldown({ ticket: critico, classification: 'WAITING_VENDOR', contextChanged: false, memory, now: NOW, config: CONFIG });
|
||||
assert.equal(result.blocked, false);
|
||||
assert.equal(result.breakCooldown, true);
|
||||
});
|
||||
|
||||
test('sem memoria previa nunca bloqueia por cooldown', () => {
|
||||
const result = computeCooldown({ ticket: ticket({}), classification: 'ACTIONABLE_NOW', contextChanged: true, memory: null, now: NOW, config: CONFIG });
|
||||
assert.equal(result.blocked, false);
|
||||
assert.equal(result.penalty, 0);
|
||||
});
|
||||
Reference in New Issue
Block a user