fix(scope-engine): Normalize UPPERCASE trigger docs to lowercase ScopeDocumentType
All checks were successful
CI/CD / go-lint (push) Has been skipped
CI/CD / python-lint (push) Has been skipped
CI/CD / nodejs-lint (push) Has been skipped
CI/CD / test-go-ai-compliance (push) Successful in 56s
CI/CD / test-python-backend-compliance (push) Successful in 42s
CI/CD / test-python-document-crawler (push) Successful in 24s
CI/CD / test-python-dsms-gateway (push) Successful in 26s
CI/CD / deploy-hetzner (push) Successful in 2m57s

Critical bug fix: mandatoryDocuments in Hard-Trigger-Rules used UPPERCASE
names (VVT, TOM, DSE) that never matched lowercase ScopeDocumentType keys
(vvt, tom, dsi). This meant no trigger documents were ever recognized as
mandatory in buildDocumentScope().

- Add normalizeDocType() mapping function with alias support
  (DSE→dsi, LOESCHKONZEPT→lf, DSR_PROZESS→betroffenenrechte, etc.)
- Fix buildDocumentScope() to use normalized doc types
- Fix estimateEffort() to use lowercase keys matching ScopeDocumentType
- Add 2 tests for UPPERCASE normalization and alias resolution

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Benjamin Admin
2026-03-12 09:39:31 +01:00
parent c88653b221
commit cf60c39658
2 changed files with 105 additions and 25 deletions

View File

@@ -265,6 +265,42 @@ describe('buildDocumentScope', () => {
})
})
it('normalizes UPPERCASE trigger doc names to lowercase ScopeDocumentType', () => {
const t = trigger('HT-test', 'L2', {
category: 'test',
mandatoryDocuments: ['VVT', 'TOM', 'DSFA'],
})
const docs = complianceScopeEngine.buildDocumentScope('L2', [t], [])
const vvt = docs.find((d: any) => d.documentType === 'vvt')
const tom = docs.find((d: any) => d.documentType === 'tom')
const dsfa = docs.find((d: any) => d.documentType === 'dsfa')
expect(vvt).toBeDefined()
expect(vvt!.requirement).toBe('mandatory')
expect(vvt!.triggeredBy).toContain('HT-test')
expect(tom).toBeDefined()
expect(tom!.requirement).toBe('mandatory')
expect(dsfa).toBeDefined()
expect(dsfa!.requirement).toBe('mandatory')
})
it('normalizes aliased doc names (DSE→dsi, LOESCHKONZEPT→lf)', () => {
const t = trigger('HT-alias', 'L2', {
category: 'test',
mandatoryDocuments: ['DSE', 'LOESCHKONZEPT', 'DSR_PROZESS'],
})
const docs = complianceScopeEngine.buildDocumentScope('L2', [t], [])
const dsi = docs.find((d: any) => d.documentType === 'dsi')
const lf = docs.find((d: any) => d.documentType === 'lf')
const betroffenenrechte = docs.find((d: any) => d.documentType === 'betroffenenrechte')
expect(dsi).toBeDefined()
expect(dsi!.requirement).toBe('mandatory')
expect(dsi!.triggeredBy).toContain('HT-alias')
expect(lf).toBeDefined()
expect(lf!.requirement).toBe('mandatory')
expect(betroffenenrechte).toBeDefined()
expect(betroffenenrechte!.requirement).toBe('mandatory')
})
it('documents sorted: mandatory first', () => {
const decision = complianceScopeEngine.evaluate([
ans('data_art9', ['gesundheit']),