From 19786c96f8b8254c0906f6f71f01640c84eea586 Mon Sep 17 00:00:00 2001 From: Benjamin Admin Date: Thu, 11 Jun 2026 08:08:23 +0200 Subject: [PATCH] test(admin): fix 3 stale vitest logic assumptions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These were pre-existing failures (stale tests, not source bugs): - getNextStep walks steps ordered by `seq`, not array order (ai-act seq 350 sits before import 400). The tests assumed array order; derive the expectations from the seq-sorted sequence instead. - buildDocumentScope: a document required only by the level matrix is `mandatory` but may be `medium` priority — only trigger-mandated docs (and the high-priority doc types) are forced to high. The test wrongly asserted ALL mandatory docs are high; now it checks the trigger-mandated ones. Full vitest suite: 414/414 green. Co-Authored-By: Claude Opus 4.8 --- .../lib/sdk/__tests__/compliance-scope-engine.test.ts | 10 +++++++--- admin-compliance/lib/sdk/__tests__/types.test.ts | 10 ++++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/admin-compliance/lib/sdk/__tests__/compliance-scope-engine.test.ts b/admin-compliance/lib/sdk/__tests__/compliance-scope-engine.test.ts index 872736f9..174cb04a 100644 --- a/admin-compliance/lib/sdk/__tests__/compliance-scope-engine.test.ts +++ b/admin-compliance/lib/sdk/__tests__/compliance-scope-engine.test.ts @@ -253,14 +253,18 @@ describe('buildDocumentScope', () => { }) }) - it('mandatory documents have high priority', () => { + it('trigger-mandated documents get high priority', () => { const t = trigger('HT-A01', 'L3', { category: 'art9', mandatoryDocuments: ['VVT'], }) const docs = complianceScopeEngine.buildDocumentScope('L3', [t], []) - const mandatoryDocs = docs.filter((d: any) => d.requirement === 'mandatory') - mandatoryDocs.forEach((doc: any) => { + // A document required only by the level matrix is mandatory but may be + // medium priority (getDocumentPriority); only trigger-mandated docs (those + // with a populated triggeredBy) are forced to high priority. + const triggerMandated = docs.filter((d: any) => (d.triggeredBy?.length ?? 0) > 0) + expect(triggerMandated.length).toBeGreaterThan(0) + triggerMandated.forEach((doc: any) => { expect(doc.priority).toBe('high') }) }) diff --git a/admin-compliance/lib/sdk/__tests__/types.test.ts b/admin-compliance/lib/sdk/__tests__/types.test.ts index 916ab554..d2aafc40 100644 --- a/admin-compliance/lib/sdk/__tests__/types.test.ts +++ b/admin-compliance/lib/sdk/__tests__/types.test.ts @@ -78,14 +78,20 @@ describe('getStepByUrl', () => { }) describe('getNextStep', () => { + // getNextStep walks the steps ordered by `seq` (not array order), so the + // expectations are derived from the seq-sorted sequence to stay correct when + // steps are reordered or inserted (e.g. ai-act seq 350 sits before import 400). + const bySeq = [...SDK_STEPS].sort((a, b) => a.seq - b.seq) + it('should return the next step in sequence', () => { + const idx = bySeq.findIndex(s => s.id === 'use-case-assessment') const nextStep = getNextStep('use-case-assessment') expect(nextStep).toBeDefined() - expect(nextStep?.id).toBe('import') + expect(nextStep?.id).toBe(bySeq[idx + 1].id) }) it('should return undefined for the last step', () => { - const lastStep = SDK_STEPS[SDK_STEPS.length - 1] + const lastStep = bySeq[bySeq.length - 1] const nextStep = getNextStep(lastStep.id) expect(nextStep).toBeUndefined() })