From 237c6767ab07eaf7c1daf7f7956829e6d87addde Mon Sep 17 00:00:00 2001 From: Jarvis Jr Hermes Date: Sun, 4 Oct 2026 11:11:42 +0000 Subject: [PATCH] fix: deduplicate synthetic quality exclusions --- scripts/ai-kpi.mjs | 2 +- scripts/ai-kpi.test.mjs | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/scripts/ai-kpi.mjs b/scripts/ai-kpi.mjs index daf1138..ac59235 100644 --- a/scripts/ai-kpi.mjs +++ b/scripts/ai-kpi.mjs @@ -117,7 +117,7 @@ export function calculate(f) { kpis['deployment-rework-rate']=result(effects.filter(r=>r.planned===false && Boolean(r.incident_id)).length,effects.length,as_of,{unknown:effects.filter(r=>typeof r.planned!=='boolean' || (r.planned===false && !Object.hasOwn(r,'incident_id'))).length}); const [affected,accepted]=matureDefects(f.changes,f.defects,as_of,start,end); const matureChanges=unique(f.changes).filter(r=>visible(r,as_of) && within(r.accepted_at,start,end) && time(r.accepted_at)+horizon(r)<=time(as_of)); - kpis['escaped-quality-rate']=result(affected,accepted,as_of,{unknown:matureChanges.filter(r=>r.linkage_complete!==true).length,exclusions:{outside_window_immature_or_late:f.changes.length-matureChanges.length},pending_triage_count:unique(f.defects).filter(r=>visible(r,as_of) && r.confirmed!==true).length}); + kpis['escaped-quality-rate']=result(affected,accepted,as_of,{unknown:matureChanges.filter(r=>r.linkage_complete!==true).length,exclusions:{outside_window_immature_or_late:unique(f.changes).length-matureChanges.length},pending_triage_count:unique(f.defects).filter(r=>visible(r,as_of) && r.confirmed!==true).length}); const attempts=unique(f.attempts).filter(r=>visible(r,as_of)); kpis['policy-effects']=result(attempts.filter(r=>r.actual_effect===true).length,attempts.length,as_of,{unknown:attempts.filter(r=>typeof r.actual_effect!=='boolean').length,blocked_count:attempts.filter(r=>r.blocked===true).length}); const {eligible}=taskCohort(f.events,start,end,as_of); diff --git a/scripts/ai-kpi.test.mjs b/scripts/ai-kpi.test.mjs index dfce99b..705218d 100644 --- a/scripts/ai-kpi.test.mjs +++ b/scripts/ai-kpi.test.mjs @@ -5,6 +5,12 @@ const moduleUrl = new URL('./ai-kpi.mjs', import.meta.url); import { spawnSync } from 'node:child_process'; import * as api from './ai-kpi.mjs'; const fixture = () => JSON.parse(readFileSync(new URL('./fixtures/ai-kpi-synthetic.json', import.meta.url))); +test('semantic change duplicates preserve the complete quality report including exclusions', () => { + const original = fixture(); + const repeated = fixture(); + repeated.changes.push({...repeated.changes[0]}); + assert.deepEqual(api.calculate(repeated).kpis['escaped-quality-rate'], api.calculate(original).kpis['escaped-quality-rate']); +}); test('CLI report exposes implemented KPI contracts and explicit omissions', async () => { const m = await import(moduleUrl); assert.equal(typeof m.calculate, 'function');