@complior/engine 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.well-known/ai-compliance.json +16 -0
- package/COMPLIANCE.md +64 -0
- package/data/data-integrity.test.ts +75 -0
- package/data/eval/eval-mappings.json +33 -0
- package/data/llm/model-pricing.json +15 -0
- package/data/llm/model-routing.json +36 -0
- package/data/onboarding/risk-profile.json +17 -0
- package/data/regulations/eu-ai-act/README.md +245 -0
- package/data/regulations/eu-ai-act/applicability-tree.json +160 -0
- package/data/regulations/eu-ai-act/cross-mapping.json +175 -0
- package/data/regulations/eu-ai-act/localization.json +186 -0
- package/data/regulations/eu-ai-act/obligations.json +3981 -0
- package/data/regulations/eu-ai-act/regulation-meta.json +482 -0
- package/data/regulations/eu-ai-act/scoring.json +342 -0
- package/data/regulations/eu-ai-act/technical-requirements.json +2590 -0
- package/data/regulations/eu-ai-act/timeline.json +160 -0
- package/data/regulations/jurisdictions/at.json +15 -0
- package/data/regulations/jurisdictions/be.json +15 -0
- package/data/regulations/jurisdictions/bg.json +15 -0
- package/data/regulations/jurisdictions/cy.json +15 -0
- package/data/regulations/jurisdictions/cz.json +15 -0
- package/data/regulations/jurisdictions/de.json +15 -0
- package/data/regulations/jurisdictions/dk.json +15 -0
- package/data/regulations/jurisdictions/ee.json +15 -0
- package/data/regulations/jurisdictions/es.json +15 -0
- package/data/regulations/jurisdictions/fi.json +15 -0
- package/data/regulations/jurisdictions/fr.json +15 -0
- package/data/regulations/jurisdictions/gr.json +15 -0
- package/data/regulations/jurisdictions/hr.json +15 -0
- package/data/regulations/jurisdictions/hu.json +15 -0
- package/data/regulations/jurisdictions/ie.json +15 -0
- package/data/regulations/jurisdictions/is.json +15 -0
- package/data/regulations/jurisdictions/it.json +15 -0
- package/data/regulations/jurisdictions/li.json +15 -0
- package/data/regulations/jurisdictions/lt.json +15 -0
- package/data/regulations/jurisdictions/lu.json +15 -0
- package/data/regulations/jurisdictions/lv.json +15 -0
- package/data/regulations/jurisdictions/mt.json +15 -0
- package/data/regulations/jurisdictions/nl.json +15 -0
- package/data/regulations/jurisdictions/no.json +15 -0
- package/data/regulations/jurisdictions/pl.json +15 -0
- package/data/regulations/jurisdictions/pt.json +15 -0
- package/data/regulations/jurisdictions/ro.json +15 -0
- package/data/regulations/jurisdictions/se.json +15 -0
- package/data/regulations/jurisdictions/si.json +15 -0
- package/data/regulations/jurisdictions/sk.json +15 -0
- package/data/scanner/check-id-categories.json +81 -0
- package/data/scanner/confidence-params.json +16 -0
- package/data/scanner/limits.json +4 -0
- package/data/schemas/http-contract-sample.json +79 -0
- package/data/schemas/http-contract.json +144 -0
- package/data/semgrep-rules/bare-call.yaml +37 -0
- package/data/semgrep-rules/injection.yaml +73 -0
- package/data/semgrep-rules/missing-error-handling.yaml +58 -0
- package/data/semgrep-rules/unsafe-deser.yaml +65 -0
- package/data/templates/eu-ai-act/ai-literacy.md +184 -0
- package/data/templates/eu-ai-act/art5-screening.md +131 -0
- package/data/templates/eu-ai-act/data-governance.md +145 -0
- package/data/templates/eu-ai-act/declaration-of-conformity.md +161 -0
- package/data/templates/eu-ai-act/fria.md +127 -0
- package/data/templates/eu-ai-act/gpai-systemic-risk.md +150 -0
- package/data/templates/eu-ai-act/gpai-transparency.md +166 -0
- package/data/templates/eu-ai-act/incident-report.md +188 -0
- package/data/templates/eu-ai-act/instructions-for-use.md +202 -0
- package/data/templates/eu-ai-act/monitoring-policy.md +110 -0
- package/data/templates/eu-ai-act/qms.md +180 -0
- package/data/templates/eu-ai-act/risk-management-system.md +123 -0
- package/data/templates/eu-ai-act/technical-documentation.md +287 -0
- package/data/templates/eu-ai-act/worker-notification.md +143 -0
- package/data/templates/policies/biometrics-ai-policy.md +214 -0
- package/data/templates/policies/critical-infra-ai-policy.md +228 -0
- package/data/templates/policies/education-ai-policy.md +184 -0
- package/data/templates/policies/finance-ai-policy.md +191 -0
- package/data/templates/policies/healthcare-ai-policy.md +197 -0
- package/data/templates/policies/hr-ai-policy.md +178 -0
- package/data/templates/policies/legal-ai-policy.md +189 -0
- package/data/templates/policies/migration-ai-policy.md +239 -0
- package/engine.log +7 -0
- package/package.json +74 -0
- package/src/composition-root.ts +791 -0
- package/src/data/eval/conformity-tests.test.ts +122 -0
- package/src/data/eval/ct-1-transparency.ts +106 -0
- package/src/data/eval/ct-10-gpai.ts +25 -0
- package/src/data/eval/ct-11-industry.ts +42 -0
- package/src/data/eval/ct-2-oversight.ts +41 -0
- package/src/data/eval/ct-3-explanation.ts +14 -0
- package/src/data/eval/ct-4-bias.ts +83 -0
- package/src/data/eval/ct-5-accuracy.ts +41 -0
- package/src/data/eval/ct-6-robustness.ts +81 -0
- package/src/data/eval/ct-7-prohibited.ts +52 -0
- package/src/data/eval/ct-8-logging.ts +68 -0
- package/src/data/eval/ct-9-risk-awareness.ts +33 -0
- package/src/data/eval/deterministic-evaluator.ts +120 -0
- package/src/data/eval/index.ts +55 -0
- package/src/data/eval/judge-prompts.ts +146 -0
- package/src/data/eval/llm-judged-tests.ts +279 -0
- package/src/data/eval/llm-tests.test.ts +83 -0
- package/src/data/eval/remediation/ct-1-transparency.ts +91 -0
- package/src/data/eval/remediation/ct-10-gpai.ts +94 -0
- package/src/data/eval/remediation/ct-11-industry.ts +94 -0
- package/src/data/eval/remediation/ct-2-oversight.ts +71 -0
- package/src/data/eval/remediation/ct-3-explanation.ts +70 -0
- package/src/data/eval/remediation/ct-4-bias.ts +70 -0
- package/src/data/eval/remediation/ct-5-accuracy.ts +70 -0
- package/src/data/eval/remediation/ct-6-robustness.ts +70 -0
- package/src/data/eval/remediation/ct-7-prohibited.ts +94 -0
- package/src/data/eval/remediation/ct-8-logging.ts +94 -0
- package/src/data/eval/remediation/ct-9-risk-awareness.ts +94 -0
- package/src/data/eval/remediation/index.ts +89 -0
- package/src/data/eval/remediation/owasp-art5.ts +15 -0
- package/src/data/eval/remediation/owasp-llm01.ts +72 -0
- package/src/data/eval/remediation/owasp-llm02.ts +72 -0
- package/src/data/eval/remediation/owasp-llm03.ts +15 -0
- package/src/data/eval/remediation/owasp-llm04.ts +15 -0
- package/src/data/eval/remediation/owasp-llm05.ts +15 -0
- package/src/data/eval/remediation/owasp-llm06.ts +15 -0
- package/src/data/eval/remediation/owasp-llm07.ts +15 -0
- package/src/data/eval/remediation/owasp-llm08.ts +15 -0
- package/src/data/eval/remediation/owasp-llm09.ts +15 -0
- package/src/data/eval/remediation/owasp-llm10.ts +15 -0
- package/src/data/eval/remediation/remediation.test.ts +229 -0
- package/src/data/eval/remediation/test-mapping.ts +290 -0
- package/src/data/eval/security-rubrics.ts +381 -0
- package/src/data/finding-explanations.json +453 -0
- package/src/data/industry-patterns.ts +161 -0
- package/src/data/registry-cards.ts +368 -0
- package/src/data/regulation/index.ts +5 -0
- package/src/data/regulation/jurisdiction-data.test.ts +73 -0
- package/src/data/regulation/jurisdiction-data.ts +65 -0
- package/src/data/regulation/regulation-data.ts +19 -0
- package/src/data/regulation/regulation-loader.test.ts +107 -0
- package/src/data/regulation/regulation-loader.ts +56 -0
- package/src/data/scanner-constants.ts +46 -0
- package/src/data/schemas/schemas-core.ts +140 -0
- package/src/data/schemas/schemas-supplementary.ts +211 -0
- package/src/data/schemas/schemas.ts +28 -0
- package/src/data/security/attack-probes.test.ts +62 -0
- package/src/data/security/attack-probes.ts +496 -0
- package/src/data/security/eu-ai-act-security.ts +40 -0
- package/src/data/security/index.ts +19 -0
- package/src/data/security/mitre-atlas.test.ts +43 -0
- package/src/data/security/mitre-atlas.ts +93 -0
- package/src/data/security/nist-ai-rmf.ts +43 -0
- package/src/data/security/owasp-llm-top10.test.ts +60 -0
- package/src/data/security/owasp-llm-top10.ts +138 -0
- package/src/data/template-registry.ts +53 -0
- package/src/data/tool-versions.json +22 -0
- package/src/domain/audit/audit-package.test.ts +152 -0
- package/src/domain/audit/audit-package.ts +166 -0
- package/src/domain/audit/audit-trail.test.ts +121 -0
- package/src/domain/audit/audit-trail.ts +174 -0
- package/src/domain/audit/index.ts +8 -0
- package/src/domain/audit/permissions-matrix.test.ts +136 -0
- package/src/domain/audit/permissions-matrix.ts +121 -0
- package/src/domain/certification/adversarial/bias-tests.ts +95 -0
- package/src/domain/certification/adversarial/evaluators.ts +304 -0
- package/src/domain/certification/adversarial/index.ts +11 -0
- package/src/domain/certification/adversarial/prompt-injection.ts +103 -0
- package/src/domain/certification/adversarial/safety-boundary.ts +132 -0
- package/src/domain/certification/aiuc1-readiness.test.ts +236 -0
- package/src/domain/certification/aiuc1-readiness.ts +298 -0
- package/src/domain/certification/aiuc1-requirements.ts +235 -0
- package/src/domain/certification/index.ts +10 -0
- package/src/domain/certification/redteam-runner.test.ts +97 -0
- package/src/domain/certification/redteam-runner.ts +205 -0
- package/src/domain/certification/test-runner.test.ts +232 -0
- package/src/domain/certification/test-runner.ts +289 -0
- package/src/domain/cost/cost-estimator.test.ts +187 -0
- package/src/domain/cost/cost-estimator.ts +133 -0
- package/src/domain/disclaimer.test.ts +52 -0
- package/src/domain/disclaimer.ts +39 -0
- package/src/domain/documents/ai-enricher.test.ts +120 -0
- package/src/domain/documents/ai-enricher.ts +159 -0
- package/src/domain/documents/document-generator.test.ts +318 -0
- package/src/domain/documents/document-generator.ts +239 -0
- package/src/domain/documents/index.ts +9 -0
- package/src/domain/documents/passport-helpers.ts +25 -0
- package/src/domain/documents/policy-generator.test.ts +252 -0
- package/src/domain/documents/policy-generator.ts +94 -0
- package/src/domain/documents/worker-notification-generator.test.ts +162 -0
- package/src/domain/documents/worker-notification-generator.ts +141 -0
- package/src/domain/eval/adapters/adapter-port.ts +94 -0
- package/src/domain/eval/adapters/adapters.test.ts +303 -0
- package/src/domain/eval/adapters/anthropic-adapter.ts +57 -0
- package/src/domain/eval/adapters/auto-detect.ts +104 -0
- package/src/domain/eval/adapters/create-chat-adapter.ts +106 -0
- package/src/domain/eval/adapters/custom-adapter.ts +74 -0
- package/src/domain/eval/adapters/http-adapter.ts +66 -0
- package/src/domain/eval/adapters/index.ts +7 -0
- package/src/domain/eval/adapters/ollama-adapter.ts +48 -0
- package/src/domain/eval/adapters/openai-adapter.ts +58 -0
- package/src/domain/eval/adapters/with-timeout.ts +25 -0
- package/src/domain/eval/conformity-score.test.ts +161 -0
- package/src/domain/eval/conformity-score.ts +135 -0
- package/src/domain/eval/eval-constants.ts +55 -0
- package/src/domain/eval/eval-evidence.test.ts +85 -0
- package/src/domain/eval/eval-evidence.ts +103 -0
- package/src/domain/eval/eval-fix-generator.test.ts +421 -0
- package/src/domain/eval/eval-fix-generator.ts +205 -0
- package/src/domain/eval/eval-passport.test.ts +82 -0
- package/src/domain/eval/eval-passport.ts +89 -0
- package/src/domain/eval/eval-remediation-report.test.ts +682 -0
- package/src/domain/eval/eval-remediation-report.ts +170 -0
- package/src/domain/eval/eval-report.ts +108 -0
- package/src/domain/eval/eval-runner.test.ts +609 -0
- package/src/domain/eval/eval-runner.ts +593 -0
- package/src/domain/eval/eval-to-findings.test.ts +293 -0
- package/src/domain/eval/eval-to-findings.ts +83 -0
- package/src/domain/eval/index.ts +31 -0
- package/src/domain/eval/llm-judge.test.ts +139 -0
- package/src/domain/eval/llm-judge.ts +168 -0
- package/src/domain/eval/remediation-types.ts +90 -0
- package/src/domain/eval/security-integration.test.ts +196 -0
- package/src/domain/eval/security-integration.ts +136 -0
- package/src/domain/eval/types.test.ts +173 -0
- package/src/domain/eval/types.ts +244 -0
- package/src/domain/eval/verdict-utils.ts +45 -0
- package/src/domain/fixer/create-fixer.ts +101 -0
- package/src/domain/fixer/diff.ts +70 -0
- package/src/domain/fixer/fix-history.ts +23 -0
- package/src/domain/fixer/fixer.test.ts +306 -0
- package/src/domain/fixer/index.ts +9 -0
- package/src/domain/fixer/strategies/bandit-fix.ts +61 -0
- package/src/domain/fixer/strategies/bias-testing.ts +49 -0
- package/src/domain/fixer/strategies/ci-compliance.ts +57 -0
- package/src/domain/fixer/strategies/content-marking.ts +45 -0
- package/src/domain/fixer/strategies/cve-upgrade.ts +66 -0
- package/src/domain/fixer/strategies/data-governance.ts +65 -0
- package/src/domain/fixer/strategies/disclosure.ts +69 -0
- package/src/domain/fixer/strategies/doc-code-sync.ts +53 -0
- package/src/domain/fixer/strategies/documentation.ts +59 -0
- package/src/domain/fixer/strategies/error-handler.ts +63 -0
- package/src/domain/fixer/strategies/hitl-gate.ts +67 -0
- package/src/domain/fixer/strategies/index.ts +61 -0
- package/src/domain/fixer/strategies/kill-switch-test.ts +85 -0
- package/src/domain/fixer/strategies/kill-switch.ts +53 -0
- package/src/domain/fixer/strategies/license-fix.ts +57 -0
- package/src/domain/fixer/strategies/log-retention.ts +40 -0
- package/src/domain/fixer/strategies/logging.ts +59 -0
- package/src/domain/fixer/strategies/metadata.ts +45 -0
- package/src/domain/fixer/strategies/permission-guard.ts +84 -0
- package/src/domain/fixer/strategies/record-keeping.ts +69 -0
- package/src/domain/fixer/strategies/secret-rotation.ts +52 -0
- package/src/domain/fixer/strategies.test.ts +341 -0
- package/src/domain/fixer/template-engine.test.ts +64 -0
- package/src/domain/fixer/template-engine.ts +38 -0
- package/src/domain/fixer/types.ts +88 -0
- package/src/domain/frameworks/aiuc1-framework.test.ts +159 -0
- package/src/domain/frameworks/aiuc1-framework.ts +126 -0
- package/src/domain/frameworks/collect-foundation-metrics.test.ts +96 -0
- package/src/domain/frameworks/collect-foundation-metrics.ts +34 -0
- package/src/domain/frameworks/eu-ai-act-framework.test.ts +117 -0
- package/src/domain/frameworks/eu-ai-act-framework.ts +100 -0
- package/src/domain/frameworks/framework-registry.test.ts +91 -0
- package/src/domain/frameworks/framework-registry.ts +38 -0
- package/src/domain/frameworks/index.ts +8 -0
- package/src/domain/frameworks/mitre-atlas-framework.test.ts +53 -0
- package/src/domain/frameworks/mitre-atlas-framework.ts +53 -0
- package/src/domain/frameworks/owasp-llm-framework.test.ts +77 -0
- package/src/domain/frameworks/owasp-llm-framework.ts +54 -0
- package/src/domain/frameworks/score-plugin-framework.ts +117 -0
- package/src/domain/fria/fria-generator.test.ts +273 -0
- package/src/domain/fria/fria-generator.ts +366 -0
- package/src/domain/import/promptfoo-importer.test.ts +103 -0
- package/src/domain/import/promptfoo-importer.ts +151 -0
- package/src/domain/onboarding/guided-onboarding.test.ts +144 -0
- package/src/domain/onboarding/guided-onboarding.ts +135 -0
- package/src/domain/passport/builder/domain-mapper.ts +9 -0
- package/src/domain/passport/builder/manifest-builder.test.ts +546 -0
- package/src/domain/passport/builder/manifest-builder.ts +535 -0
- package/src/domain/passport/builder/manifest-diff.test.ts +105 -0
- package/src/domain/passport/builder/manifest-diff.ts +89 -0
- package/src/domain/passport/builder/manifest-files.ts +17 -0
- package/src/domain/passport/crypto-signer.test.ts +93 -0
- package/src/domain/passport/crypto-signer.ts +157 -0
- package/src/domain/passport/discovery/agent-discovery.test.ts +296 -0
- package/src/domain/passport/discovery/agent-discovery.ts +325 -0
- package/src/domain/passport/discovery/autonomy-analyzer.test.ts +141 -0
- package/src/domain/passport/discovery/autonomy-analyzer.ts +113 -0
- package/src/domain/passport/discovery/permission-scanner.test.ts +191 -0
- package/src/domain/passport/discovery/permission-scanner.ts +414 -0
- package/src/domain/passport/export/a2a-mapper.ts +75 -0
- package/src/domain/passport/export/aiuc1-mapper.ts +126 -0
- package/src/domain/passport/export/export.test.ts +207 -0
- package/src/domain/passport/export/index.ts +41 -0
- package/src/domain/passport/export/nist-mapper.ts +227 -0
- package/src/domain/passport/import/a2a-importer.test.ts +133 -0
- package/src/domain/passport/import/a2a-importer.ts +156 -0
- package/src/domain/passport/import/index.ts +2 -0
- package/src/domain/passport/index.ts +32 -0
- package/src/domain/passport/obligation-field-map.test.ts +113 -0
- package/src/domain/passport/obligation-field-map.ts +117 -0
- package/src/domain/passport/passport-validator.test.ts +156 -0
- package/src/domain/passport/passport-validator.ts +126 -0
- package/src/domain/passport/scan-to-compliance.test.ts +336 -0
- package/src/domain/passport/scan-to-compliance.ts +166 -0
- package/src/domain/passport/test-generator.test.ts +93 -0
- package/src/domain/passport/test-generator.ts +136 -0
- package/src/domain/proxy/index.ts +11 -0
- package/src/domain/proxy/json-rpc.test.ts +72 -0
- package/src/domain/proxy/json-rpc.ts +53 -0
- package/src/domain/proxy/policy-engine.test.ts +259 -0
- package/src/domain/proxy/policy-engine.ts +137 -0
- package/src/domain/proxy/proxy-bridge.ts +125 -0
- package/src/domain/proxy/proxy-interceptor.test.ts +184 -0
- package/src/domain/proxy/proxy-interceptor.ts +120 -0
- package/src/domain/proxy/proxy-types.ts +35 -0
- package/src/domain/registry/compute-agent-score.test.ts +279 -0
- package/src/domain/registry/compute-agent-score.ts +162 -0
- package/src/domain/reporter/audit-report.test.ts +87 -0
- package/src/domain/reporter/audit-report.ts +116 -0
- package/src/domain/reporter/badge-generator.test.ts +54 -0
- package/src/domain/reporter/badge-generator.ts +40 -0
- package/src/domain/reporter/compliance-md.ts +45 -0
- package/src/domain/reporter/index.ts +7 -0
- package/src/domain/reporter/pdf-renderer.ts +282 -0
- package/src/domain/reporter/share.test.ts +92 -0
- package/src/domain/reporter/share.ts +80 -0
- package/src/domain/scanner/ast/swc-analyzer.test.ts +49 -0
- package/src/domain/scanner/ast/swc-analyzer.ts +124 -0
- package/src/domain/scanner/attestations.ts +97 -0
- package/src/domain/scanner/checks/ai-disclosure.test.ts +90 -0
- package/src/domain/scanner/checks/ai-disclosure.ts +54 -0
- package/src/domain/scanner/checks/ai-literacy.ts +163 -0
- package/src/domain/scanner/checks/behavioral-constraints.test.ts +167 -0
- package/src/domain/scanner/checks/behavioral-constraints.ts +86 -0
- package/src/domain/scanner/checks/compliance-metadata.ts +63 -0
- package/src/domain/scanner/checks/content-marking.ts +74 -0
- package/src/domain/scanner/checks/dep-deep-scan.test.ts +318 -0
- package/src/domain/scanner/checks/dep-deep-scan.ts +137 -0
- package/src/domain/scanner/checks/documentation.test.ts +88 -0
- package/src/domain/scanner/checks/documentation.ts +79 -0
- package/src/domain/scanner/checks/git-history.test.ts +120 -0
- package/src/domain/scanner/checks/git-history.ts +163 -0
- package/src/domain/scanner/checks/gpai-systemic-risk.test.ts +84 -0
- package/src/domain/scanner/checks/gpai-systemic-risk.ts +98 -0
- package/src/domain/scanner/checks/gpai-transparency.ts +94 -0
- package/src/domain/scanner/checks/index.ts +28 -0
- package/src/domain/scanner/checks/industry/index.ts +40 -0
- package/src/domain/scanner/checks/industry/industry.test.ts +287 -0
- package/src/domain/scanner/checks/interaction-logging.test.ts +113 -0
- package/src/domain/scanner/checks/interaction-logging.ts +142 -0
- package/src/domain/scanner/checks/nhi-scanner.test.ts +158 -0
- package/src/domain/scanner/checks/nhi-scanner.ts +78 -0
- package/src/domain/scanner/checks/passport-completeness.test.ts +127 -0
- package/src/domain/scanner/checks/passport-completeness.ts +82 -0
- package/src/domain/scanner/checks/passport-presence.test.ts +56 -0
- package/src/domain/scanner/checks/passport-presence.ts +78 -0
- package/src/domain/scanner/checks/pattern-check-factory.ts +70 -0
- package/src/domain/scanner/checks/permission-scanner.test.ts +279 -0
- package/src/domain/scanner/checks/permission-scanner.ts +90 -0
- package/src/domain/scanner/checks/presence-check-factory.test.ts +124 -0
- package/src/domain/scanner/checks/presence-check-factory.ts +275 -0
- package/src/domain/scanner/compliance-diff.test.ts +165 -0
- package/src/domain/scanner/compliance-diff.ts +138 -0
- package/src/domain/scanner/confidence.test.ts +235 -0
- package/src/domain/scanner/confidence.ts +156 -0
- package/src/domain/scanner/constants.ts +13 -0
- package/src/domain/scanner/create-scanner.ts +573 -0
- package/src/domain/scanner/cross-layer.test.ts +372 -0
- package/src/domain/scanner/cross-layer.ts +232 -0
- package/src/domain/scanner/data/ai-packages.ts +82 -0
- package/src/domain/scanner/debt-calculator.test.ts +89 -0
- package/src/domain/scanner/debt-calculator.ts +111 -0
- package/src/domain/scanner/drift.test.ts +191 -0
- package/src/domain/scanner/drift.ts +73 -0
- package/src/domain/scanner/evidence-store.test.ts +207 -0
- package/src/domain/scanner/evidence-store.ts +195 -0
- package/src/domain/scanner/evidence.test.ts +104 -0
- package/src/domain/scanner/evidence.ts +71 -0
- package/src/domain/scanner/external/bandit-runner.test.ts +45 -0
- package/src/domain/scanner/external/bandit-runner.ts +90 -0
- package/src/domain/scanner/external/checks.ts +321 -0
- package/src/domain/scanner/external/dedup.test.ts +79 -0
- package/src/domain/scanner/external/dedup.ts +94 -0
- package/src/domain/scanner/external/detect-secrets-runner.test.ts +58 -0
- package/src/domain/scanner/external/detect-secrets-runner.ts +81 -0
- package/src/domain/scanner/external/external-scanner.test.ts +221 -0
- package/src/domain/scanner/external/external-scanner.ts +36 -0
- package/src/domain/scanner/external/finding-mapper.test.ts +95 -0
- package/src/domain/scanner/external/finding-mapper.ts +138 -0
- package/src/domain/scanner/external/index.ts +15 -0
- package/src/domain/scanner/external/mappings.ts +93 -0
- package/src/domain/scanner/external/modelscan-runner.test.ts +35 -0
- package/src/domain/scanner/external/modelscan-runner.ts +101 -0
- package/src/domain/scanner/external/path-utils.ts +8 -0
- package/src/domain/scanner/external/runner-port.ts +45 -0
- package/src/domain/scanner/external/semgrep-runner.test.ts +52 -0
- package/src/domain/scanner/external/semgrep-runner.ts +94 -0
- package/src/domain/scanner/external/types.ts +32 -0
- package/src/domain/scanner/finding-attribution.test.ts +444 -0
- package/src/domain/scanner/finding-attribution.ts +195 -0
- package/src/domain/scanner/finding-explainer.test.ts +157 -0
- package/src/domain/scanner/finding-explainer.ts +73 -0
- package/src/domain/scanner/fix-diff-builder.test.ts +272 -0
- package/src/domain/scanner/fix-diff-builder.ts +477 -0
- package/src/domain/scanner/import-graph.test.ts +162 -0
- package/src/domain/scanner/import-graph.ts +198 -0
- package/src/domain/scanner/languages/adapter.test.ts +105 -0
- package/src/domain/scanner/languages/adapter.ts +239 -0
- package/src/domain/scanner/layers/index.ts +24 -0
- package/src/domain/scanner/layers/layer1-files.ts +54 -0
- package/src/domain/scanner/layers/layer2-docs.test.ts +1207 -0
- package/src/domain/scanner/layers/layer2-docs.ts +297 -0
- package/src/domain/scanner/layers/layer2-parsing.ts +217 -0
- package/src/domain/scanner/layers/layer3-config.test.ts +187 -0
- package/src/domain/scanner/layers/layer3-config.ts +279 -0
- package/src/domain/scanner/layers/layer3-parsers.ts +73 -0
- package/src/domain/scanner/layers/layer4-patterns.test.ts +397 -0
- package/src/domain/scanner/layers/layer4-patterns.ts +216 -0
- package/src/domain/scanner/layers/layer5-docs.test.ts +99 -0
- package/src/domain/scanner/layers/layer5-docs.ts +250 -0
- package/src/domain/scanner/layers/layer5-llm.test.ts +146 -0
- package/src/domain/scanner/layers/layer5-llm.ts +262 -0
- package/src/domain/scanner/layers/layer5-targeted.test.ts +93 -0
- package/src/domain/scanner/layers/layer5-targeted.ts +233 -0
- package/src/domain/scanner/layers/lockfile-parsers.test.ts +320 -0
- package/src/domain/scanner/layers/lockfile-parsers.ts +184 -0
- package/src/domain/scanner/regulation-version.test.ts +54 -0
- package/src/domain/scanner/regulation-version.ts +23 -0
- package/src/domain/scanner/role-filter.test.ts +116 -0
- package/src/domain/scanner/role-filter.ts +51 -0
- package/src/domain/scanner/rules/banned-packages-data.ts +553 -0
- package/src/domain/scanner/rules/banned-packages-sdk.ts +65 -0
- package/src/domain/scanner/rules/banned-packages.test.ts +249 -0
- package/src/domain/scanner/rules/banned-packages.ts +55 -0
- package/src/domain/scanner/rules/comment-filter.test.ts +115 -0
- package/src/domain/scanner/rules/comment-filter.ts +297 -0
- package/src/domain/scanner/rules/index.ts +9 -0
- package/src/domain/scanner/rules/nhi-patterns.test.ts +128 -0
- package/src/domain/scanner/rules/nhi-patterns.ts +60 -0
- package/src/domain/scanner/rules/pattern-rules.ts +1152 -0
- package/src/domain/scanner/sbom.test.ts +136 -0
- package/src/domain/scanner/sbom.ts +103 -0
- package/src/domain/scanner/scan-cache.test.ts +136 -0
- package/src/domain/scanner/scan-cache.ts +115 -0
- package/src/domain/scanner/scanner.test.ts +125 -0
- package/src/domain/scanner/score-calculator.test.ts +363 -0
- package/src/domain/scanner/score-calculator.ts +189 -0
- package/src/domain/scanner/security-score.test.ts +107 -0
- package/src/domain/scanner/security-score.ts +116 -0
- package/src/domain/scanner/source-filter.ts +24 -0
- package/src/domain/scanner/validators.ts +223 -0
- package/src/domain/shared/compliance-constants.ts +48 -0
- package/src/domain/shared/disclosure-patterns.ts +16 -0
- package/src/domain/shared/index.ts +6 -0
- package/src/domain/shared/parse-dependencies.ts +21 -0
- package/src/domain/supply-chain/dependency-analyzer.ts +138 -0
- package/src/domain/supply-chain/index.ts +3 -0
- package/src/domain/supply-chain/supply-chain.test.ts +211 -0
- package/src/domain/supply-chain/types.ts +32 -0
- package/src/domain/whatif/config-fixer.ts +187 -0
- package/src/domain/whatif/index.ts +6 -0
- package/src/domain/whatif/scenario-engine.ts +121 -0
- package/src/domain/whatif/simulate-actions.test.ts +161 -0
- package/src/domain/whatif/simulate-actions.ts +114 -0
- package/src/domain/whatif/whatif.test.ts +135 -0
- package/src/e2e/gaps-e2e.test.ts +259 -0
- package/src/e2e/smoke.test.ts +101 -0
- package/src/hooks/hooks-export.test.ts +81 -0
- package/src/hooks/installer.ts +113 -0
- package/src/http/cors.test.ts +38 -0
- package/src/http/create-router.ts +259 -0
- package/src/http/routes/agent.route.ts +380 -0
- package/src/http/routes/audit.route.ts +66 -0
- package/src/http/routes/badge.route.ts +23 -0
- package/src/http/routes/cert.route.ts +66 -0
- package/src/http/routes/chat.route.ts +228 -0
- package/src/http/routes/cost.route.ts +33 -0
- package/src/http/routes/debt.route.ts +29 -0
- package/src/http/routes/disclaimer.route.ts +64 -0
- package/src/http/routes/eval.route.ts +161 -0
- package/src/http/routes/events.route.test.ts +108 -0
- package/src/http/routes/events.route.ts +71 -0
- package/src/http/routes/external-scan.route.ts +24 -0
- package/src/http/routes/file.route.ts +54 -0
- package/src/http/routes/fix.route.ts +219 -0
- package/src/http/routes/frameworks.route.test.ts +66 -0
- package/src/http/routes/frameworks.route.ts +36 -0
- package/src/http/routes/git.route.ts +27 -0
- package/src/http/routes/guided-onboarding.route.ts +65 -0
- package/src/http/routes/import.route.ts +64 -0
- package/src/http/routes/jurisdiction.route.ts +22 -0
- package/src/http/routes/obligations.route.test.ts +122 -0
- package/src/http/routes/obligations.route.ts +110 -0
- package/src/http/routes/onboarding.route.ts +53 -0
- package/src/http/routes/provider.route.ts +42 -0
- package/src/http/routes/proxy.route.ts +40 -0
- package/src/http/routes/redteam.route.ts +84 -0
- package/src/http/routes/report.route.ts +29 -0
- package/src/http/routes/scan.route.ts +104 -0
- package/src/http/routes/share.route.ts +44 -0
- package/src/http/routes/shell.route.ts +27 -0
- package/src/http/routes/status.route.ts +66 -0
- package/src/http/routes/supply-chain.route.ts +121 -0
- package/src/http/routes/sync.route.ts +328 -0
- package/src/http/routes/tools.route.ts +29 -0
- package/src/http/routes/whatif.route.ts +96 -0
- package/src/http/utils/validation.ts +31 -0
- package/src/index.ts +1 -0
- package/src/infra/bundle-fetcher.ts +77 -0
- package/src/infra/cache-storage.ts +34 -0
- package/src/infra/event-bus.ts +31 -0
- package/src/infra/file-collector.ts +61 -0
- package/src/infra/file-ops-adapter.ts +95 -0
- package/src/infra/file-watcher.test.ts +90 -0
- package/src/infra/file-watcher.ts +106 -0
- package/src/infra/git-adapter.ts +93 -0
- package/src/infra/git-history-adapter.ts +41 -0
- package/src/infra/headless-browser.ts +178 -0
- package/src/infra/llm-adapter.test.ts +83 -0
- package/src/infra/llm-adapter.ts +86 -0
- package/src/infra/logger.ts +27 -0
- package/src/infra/project-config.test.ts +74 -0
- package/src/infra/project-config.ts +35 -0
- package/src/infra/rate-limiter.test.ts +36 -0
- package/src/infra/rate-limiter.ts +34 -0
- package/src/infra/retry.ts +46 -0
- package/src/infra/saas-client.ts +123 -0
- package/src/infra/search-adapter.ts +113 -0
- package/src/infra/shell-adapter.ts +68 -0
- package/src/infra/tool-manager.test.ts +99 -0
- package/src/infra/tool-manager.ts +197 -0
- package/src/llm/agents/agent-modes.test.ts +44 -0
- package/src/llm/agents/modes.ts +68 -0
- package/src/llm/routing/cost-routing.test.ts +37 -0
- package/src/llm/routing/cost-tracker.ts +74 -0
- package/src/llm/routing/model-routing.test.ts +79 -0
- package/src/llm/routing/model-routing.ts +38 -0
- package/src/llm/routing/pricing.ts +19 -0
- package/src/llm/sse-protocol.ts +77 -0
- package/src/llm/tool-definitions.ts +83 -0
- package/src/llm/tool-executors.ts +80 -0
- package/src/llm/tools/types.ts +13 -0
- package/src/mcp/create-mcp-stack.ts +82 -0
- package/src/mcp/handlers.ts +245 -0
- package/src/mcp/index.ts +28 -0
- package/src/mcp/mcp-server.test.ts +80 -0
- package/src/mcp/server.ts +79 -0
- package/src/mcp/tools.ts +48 -0
- package/src/onboarding/auto-detect.ts +164 -0
- package/src/onboarding/onboarding.test.ts +89 -0
- package/src/onboarding/profile.ts +169 -0
- package/src/onboarding/questions.ts +112 -0
- package/src/onboarding/wizard.ts +66 -0
- package/src/output/github-issue.ts +32 -0
- package/src/output/json-output.ts +67 -0
- package/src/ports/browser.port.ts +23 -0
- package/src/ports/events.port.ts +28 -0
- package/src/ports/llm.port.ts +23 -0
- package/src/ports/logger.port.ts +6 -0
- package/src/ports/process.port.ts +6 -0
- package/src/ports/scanner.port.ts +15 -0
- package/src/server.ts +134 -0
- package/src/services/badge-service.ts +67 -0
- package/src/services/chat-service.test.ts +162 -0
- package/src/services/chat-service.ts +152 -0
- package/src/services/cost-service.ts +52 -0
- package/src/services/debt-service.ts +65 -0
- package/src/services/eval-integration.test.ts +132 -0
- package/src/services/eval-service.test.ts +373 -0
- package/src/services/eval-service.ts +463 -0
- package/src/services/external-scan-service.ts +60 -0
- package/src/services/file-service.ts +37 -0
- package/src/services/fix-service.test.ts +470 -0
- package/src/services/fix-service.ts +648 -0
- package/src/services/framework-service.test.ts +159 -0
- package/src/services/framework-service.ts +67 -0
- package/src/services/onboarding-service.ts +165 -0
- package/src/services/passport-audit.ts +244 -0
- package/src/services/passport-documents.ts +258 -0
- package/src/services/passport-service-utils.ts +72 -0
- package/src/services/passport-service.test.ts +251 -0
- package/src/services/passport-service.ts +339 -0
- package/src/services/proxy-service.ts +81 -0
- package/src/services/report-service.ts +72 -0
- package/src/services/scan-service.test.ts +470 -0
- package/src/services/scan-service.ts +335 -0
- package/src/services/share-service.ts +108 -0
- package/src/services/shared/backup.ts +23 -0
- package/src/services/status-service.ts +38 -0
- package/src/services/undo-service.test.ts +190 -0
- package/src/services/undo-service.ts +144 -0
- package/src/test-helpers/factories.ts +116 -0
- package/src/types/common.schemas.ts +147 -0
- package/src/types/common.types.ts +292 -0
- package/src/types/contract.test.ts +217 -0
- package/src/types/errors.ts +52 -0
- package/src/types/framework.types.ts +87 -0
- package/src/types/passport-schemas.ts +241 -0
- package/src/types/passport.types.ts +296 -0
- package/src/version.ts +1 -0
- package/tsconfig.json +20 -0
- package/vitest.config.ts +9 -0
|
@@ -0,0 +1,682 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { generateRemediationReport, renderRemediationMarkdown } from './eval-remediation-report.js';
|
|
3
|
+
import type { EvalResult, EvalCategory, TestResult, CategoryScore } from './types.js';
|
|
4
|
+
import type { CategoryPlaybook, RemediationAction, RemediationReport } from './remediation-types.js';
|
|
5
|
+
import { CT_1_PLAYBOOK } from '../../data/eval/remediation/ct-1-transparency.js';
|
|
6
|
+
import { CT_7_PLAYBOOK } from '../../data/eval/remediation/ct-7-prohibited.js';
|
|
7
|
+
import { ALL_CT_PLAYBOOKS } from '../../data/eval/remediation/index.js';
|
|
8
|
+
|
|
9
|
+
// ── Helpers ──────────────────────────────────────────────────
|
|
10
|
+
|
|
11
|
+
const mockFailure = (testId: string, category: string, owaspCategory?: string): TestResult => ({
|
|
12
|
+
testId,
|
|
13
|
+
name: `Test ${testId}`,
|
|
14
|
+
category: category as EvalCategory,
|
|
15
|
+
method: 'deterministic' as const,
|
|
16
|
+
verdict: 'fail' as const,
|
|
17
|
+
score: 0,
|
|
18
|
+
confidence: 75,
|
|
19
|
+
reasoning: 'test failure',
|
|
20
|
+
probe: 'test probe',
|
|
21
|
+
response: 'test response',
|
|
22
|
+
latencyMs: 100,
|
|
23
|
+
timestamp: new Date().toISOString(),
|
|
24
|
+
...(owaspCategory ? { owaspCategory } : {}),
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const mockPass = (testId: string, category: string): TestResult => ({
|
|
28
|
+
testId,
|
|
29
|
+
name: `Test ${testId}`,
|
|
30
|
+
category: category as EvalCategory,
|
|
31
|
+
method: 'deterministic' as const,
|
|
32
|
+
verdict: 'pass' as const,
|
|
33
|
+
score: 100,
|
|
34
|
+
confidence: 90,
|
|
35
|
+
reasoning: 'test passed',
|
|
36
|
+
probe: 'test probe',
|
|
37
|
+
response: 'good response',
|
|
38
|
+
latencyMs: 50,
|
|
39
|
+
timestamp: new Date().toISOString(),
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const mockCategoryScore = (
|
|
43
|
+
category: string,
|
|
44
|
+
passed: number,
|
|
45
|
+
failed: number,
|
|
46
|
+
total?: number,
|
|
47
|
+
): CategoryScore => ({
|
|
48
|
+
category: category as EvalCategory,
|
|
49
|
+
score: total ? Math.round((passed / (total || 1)) * 100) : (failed === 0 ? 100 : 0),
|
|
50
|
+
grade: failed === 0 ? 'A' : 'F',
|
|
51
|
+
passed,
|
|
52
|
+
failed,
|
|
53
|
+
errors: 0,
|
|
54
|
+
inconclusive: 0,
|
|
55
|
+
skipped: 0,
|
|
56
|
+
total: total ?? (passed + failed),
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const mockEvalResult = (
|
|
60
|
+
results: TestResult[],
|
|
61
|
+
categories: CategoryScore[],
|
|
62
|
+
overrides?: Partial<EvalResult>,
|
|
63
|
+
): EvalResult => ({
|
|
64
|
+
target: 'http://localhost:3000',
|
|
65
|
+
tier: 'basic',
|
|
66
|
+
overallScore: overrides?.overallScore ?? 45,
|
|
67
|
+
grade: overrides?.grade ?? 'F',
|
|
68
|
+
categories,
|
|
69
|
+
results,
|
|
70
|
+
totalTests: results.length,
|
|
71
|
+
passed: results.filter((r) => r.verdict === 'pass').length,
|
|
72
|
+
failed: results.filter((r) => r.verdict === 'fail').length,
|
|
73
|
+
errors: results.filter((r) => r.verdict === 'error').length,
|
|
74
|
+
inconclusive: 0,
|
|
75
|
+
skipped: 0,
|
|
76
|
+
duration: 1234,
|
|
77
|
+
timestamp: new Date().toISOString(),
|
|
78
|
+
criticalCapped: false,
|
|
79
|
+
...overrides,
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
const makeAction = (
|
|
83
|
+
id: string,
|
|
84
|
+
priority: 'critical' | 'high' | 'medium' | 'low',
|
|
85
|
+
type: 'system_prompt' | 'api_config' | 'infrastructure' | 'process' = 'system_prompt',
|
|
86
|
+
): RemediationAction => ({
|
|
87
|
+
id,
|
|
88
|
+
type,
|
|
89
|
+
title: `Action ${id}`,
|
|
90
|
+
description: `Description for ${id}`,
|
|
91
|
+
example: `"Example instruction for ${id}"`,
|
|
92
|
+
priority,
|
|
93
|
+
effort: 'minimal',
|
|
94
|
+
article_ref: 'Art.99',
|
|
95
|
+
user_guidance: {
|
|
96
|
+
why: `Reason for ${id}`,
|
|
97
|
+
what_to_do: [`Step 1 for ${id}`, `Step 2 for ${id}`],
|
|
98
|
+
verification: `Verify ${id}`,
|
|
99
|
+
resources: ['https://example.com'],
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
const makePlaybook = (categoryId: string, actions: RemediationAction[]): CategoryPlaybook => ({
|
|
104
|
+
category_id: categoryId,
|
|
105
|
+
label: `Category ${categoryId}`,
|
|
106
|
+
article_ref: 'Art.99',
|
|
107
|
+
description: `Playbook for ${categoryId}`,
|
|
108
|
+
actions,
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
// ── generateRemediationReport ────────────────────────────────
|
|
112
|
+
|
|
113
|
+
describe('generateRemediationReport', () => {
|
|
114
|
+
it('generates a report with all required fields from failures across 2 categories', () => {
|
|
115
|
+
const results: TestResult[] = [
|
|
116
|
+
mockFailure('CT-1-001', 'transparency'),
|
|
117
|
+
mockFailure('CT-1-002', 'transparency'),
|
|
118
|
+
mockFailure('CT-7-001', 'prohibited'),
|
|
119
|
+
mockPass('CT-1-003', 'transparency'),
|
|
120
|
+
];
|
|
121
|
+
const categories: CategoryScore[] = [
|
|
122
|
+
mockCategoryScore('transparency', 1, 2, 3),
|
|
123
|
+
mockCategoryScore('prohibited', 0, 1, 1),
|
|
124
|
+
];
|
|
125
|
+
const evalResult = mockEvalResult(results, categories, { overallScore: 30, grade: 'F' });
|
|
126
|
+
|
|
127
|
+
const remediation: Record<string, RemediationAction[]> = {
|
|
128
|
+
'CT-1-001': [CT_1_PLAYBOOK.actions[0]],
|
|
129
|
+
'CT-1-002': [CT_1_PLAYBOOK.actions[0], CT_1_PLAYBOOK.actions[1]],
|
|
130
|
+
'CT-7-001': [CT_7_PLAYBOOK.actions[0]],
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const report = generateRemediationReport(evalResult, remediation, [CT_1_PLAYBOOK, CT_7_PLAYBOOK]);
|
|
134
|
+
|
|
135
|
+
expect(report.score).toBe(30);
|
|
136
|
+
expect(report.grade).toBe('F');
|
|
137
|
+
expect(report.total_failures).toBe(3);
|
|
138
|
+
expect(report.actions.length).toBeGreaterThan(0);
|
|
139
|
+
expect(report.critical_gaps.length).toBeGreaterThan(0);
|
|
140
|
+
expect(report.timestamp).toBeTruthy();
|
|
141
|
+
expect(typeof report.timestamp).toBe('string');
|
|
142
|
+
// timestamp is ISO-8601
|
|
143
|
+
expect(report.timestamp).toMatch(/^\d{4}-\d{2}-\d{2}T/);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('report actions have all required fields', () => {
|
|
147
|
+
const results: TestResult[] = [
|
|
148
|
+
mockFailure('CT-1-001', 'transparency'),
|
|
149
|
+
mockFailure('CT-1-002', 'transparency'),
|
|
150
|
+
];
|
|
151
|
+
const categories: CategoryScore[] = [
|
|
152
|
+
mockCategoryScore('transparency', 0, 2, 2),
|
|
153
|
+
];
|
|
154
|
+
const evalResult = mockEvalResult(results, categories, { overallScore: 20, grade: 'F' });
|
|
155
|
+
|
|
156
|
+
const remediation: Record<string, RemediationAction[]> = {
|
|
157
|
+
'CT-1-001': [CT_1_PLAYBOOK.actions[0]],
|
|
158
|
+
'CT-1-002': [CT_1_PLAYBOOK.actions[1]],
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
const report = generateRemediationReport(evalResult, remediation, [CT_1_PLAYBOOK]);
|
|
162
|
+
|
|
163
|
+
for (const action of report.actions) {
|
|
164
|
+
expect(action.id).toBeTruthy();
|
|
165
|
+
expect(typeof action.title).toBe('string');
|
|
166
|
+
expect(action.title.length).toBeGreaterThan(0);
|
|
167
|
+
expect(typeof action.description).toBe('string');
|
|
168
|
+
expect(action.description.length).toBeGreaterThan(0);
|
|
169
|
+
expect(typeof action.example).toBe('string');
|
|
170
|
+
expect(['critical', 'high', 'medium', 'low']).toContain(action.priority);
|
|
171
|
+
expect(['minimal', 'moderate', 'significant']).toContain(action.effort);
|
|
172
|
+
expect(typeof action.article_ref).toBe('string');
|
|
173
|
+
expect(action.article_ref.length).toBeGreaterThan(0);
|
|
174
|
+
expect(typeof action.affected_tests).toBe('number');
|
|
175
|
+
expect(action.affected_tests).toBeGreaterThanOrEqual(1);
|
|
176
|
+
expect(typeof action.timeline).toBe('string');
|
|
177
|
+
expect(['this week', 'next week', 'this month', 'backlog']).toContain(action.timeline);
|
|
178
|
+
expect(Array.isArray(action.steps)).toBe(true);
|
|
179
|
+
expect(action.steps.length).toBeGreaterThan(0);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('sorts actions by priority: critical before high before medium', () => {
|
|
184
|
+
const criticalAction = makeAction('CRIT-1', 'critical');
|
|
185
|
+
const highAction = makeAction('HIGH-1', 'high');
|
|
186
|
+
const mediumAction = makeAction('MED-1', 'medium');
|
|
187
|
+
|
|
188
|
+
const playbookA = makePlaybook('cat-a', [mediumAction]);
|
|
189
|
+
const playbookB = makePlaybook('cat-b', [highAction]);
|
|
190
|
+
const playbookC = makePlaybook('cat-c', [criticalAction]);
|
|
191
|
+
|
|
192
|
+
const results: TestResult[] = [
|
|
193
|
+
mockFailure('T-001', 'cat-a' as EvalCategory),
|
|
194
|
+
mockFailure('T-002', 'cat-b' as EvalCategory),
|
|
195
|
+
mockFailure('T-003', 'cat-c' as EvalCategory),
|
|
196
|
+
];
|
|
197
|
+
const categories: CategoryScore[] = [
|
|
198
|
+
mockCategoryScore('cat-a', 0, 1, 1),
|
|
199
|
+
mockCategoryScore('cat-b', 0, 1, 1),
|
|
200
|
+
mockCategoryScore('cat-c', 0, 1, 1),
|
|
201
|
+
];
|
|
202
|
+
const evalResult = mockEvalResult(results, categories);
|
|
203
|
+
|
|
204
|
+
const remediation: Record<string, RemediationAction[]> = {
|
|
205
|
+
'T-001': [mediumAction],
|
|
206
|
+
'T-002': [highAction],
|
|
207
|
+
'T-003': [criticalAction],
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
const report = generateRemediationReport(evalResult, remediation, [playbookA, playbookB, playbookC]);
|
|
211
|
+
|
|
212
|
+
expect(report.actions.length).toBe(3);
|
|
213
|
+
expect(report.actions[0].priority).toBe('critical');
|
|
214
|
+
expect(report.actions[1].priority).toBe('high');
|
|
215
|
+
expect(report.actions[2].priority).toBe('medium');
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it('limits actions to maximum 10', () => {
|
|
219
|
+
// Create 15 unique actions across multiple categories
|
|
220
|
+
const actions: RemediationAction[] = [];
|
|
221
|
+
for (let i = 1; i <= 15; i++) {
|
|
222
|
+
actions.push(makeAction(`ACT-${i}`, 'high'));
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const playbooks: CategoryPlaybook[] = [];
|
|
226
|
+
const results: TestResult[] = [];
|
|
227
|
+
const remediation: Record<string, RemediationAction[]> = {};
|
|
228
|
+
const categories: CategoryScore[] = [];
|
|
229
|
+
|
|
230
|
+
for (let i = 0; i < 15; i++) {
|
|
231
|
+
const catId = `cat-${i}` as EvalCategory;
|
|
232
|
+
playbooks.push(makePlaybook(catId, [actions[i]]));
|
|
233
|
+
const testId = `T-${i + 1}`;
|
|
234
|
+
results.push(mockFailure(testId, catId));
|
|
235
|
+
remediation[testId] = [actions[i]];
|
|
236
|
+
categories.push(mockCategoryScore(catId, 0, 1, 1));
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const evalResult = mockEvalResult(results, categories);
|
|
240
|
+
const report = generateRemediationReport(evalResult, remediation, playbooks);
|
|
241
|
+
|
|
242
|
+
expect(report.actions.length).toBe(10);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
it('detects critical gaps for category with pass rate < 0.20', () => {
|
|
246
|
+
// accuracy: 1 passed, 9 failed = 10% pass rate → critical gap
|
|
247
|
+
const results: TestResult[] = [
|
|
248
|
+
mockPass('CT-5-001', 'accuracy'),
|
|
249
|
+
...Array.from({ length: 9 }, (_, i) => mockFailure(`CT-5-${i + 2}`, 'accuracy')),
|
|
250
|
+
];
|
|
251
|
+
const categories: CategoryScore[] = [
|
|
252
|
+
mockCategoryScore('accuracy', 1, 9, 10),
|
|
253
|
+
];
|
|
254
|
+
const evalResult = mockEvalResult(results, categories, { overallScore: 10, grade: 'F' });
|
|
255
|
+
|
|
256
|
+
const remediation: Record<string, RemediationAction[]> = {};
|
|
257
|
+
for (const r of results.filter((r) => r.verdict === 'fail')) {
|
|
258
|
+
remediation[r.testId] = [makeAction('ACC-A1', 'high')];
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const report = generateRemediationReport(evalResult, remediation, []);
|
|
262
|
+
|
|
263
|
+
expect(report.critical_gaps).toContain('accuracy');
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
it('detects critical gaps for transparency with any failure', () => {
|
|
267
|
+
// transparency: 9 passed, 1 failed = 90% pass rate, but transparency is always critical on failure
|
|
268
|
+
const results: TestResult[] = [
|
|
269
|
+
...Array.from({ length: 9 }, (_, i) => mockPass(`CT-1-${i + 1}`, 'transparency')),
|
|
270
|
+
mockFailure('CT-1-010', 'transparency'),
|
|
271
|
+
];
|
|
272
|
+
const categories: CategoryScore[] = [
|
|
273
|
+
mockCategoryScore('transparency', 9, 1, 10),
|
|
274
|
+
];
|
|
275
|
+
const evalResult = mockEvalResult(results, categories, { overallScore: 90, grade: 'A' });
|
|
276
|
+
|
|
277
|
+
const remediation: Record<string, RemediationAction[]> = {
|
|
278
|
+
'CT-1-010': [CT_1_PLAYBOOK.actions[0]],
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
const report = generateRemediationReport(evalResult, remediation, [CT_1_PLAYBOOK]);
|
|
282
|
+
|
|
283
|
+
expect(report.critical_gaps).toContain('transparency');
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
it('detects critical gaps for prohibited with any failure', () => {
|
|
287
|
+
const results: TestResult[] = [
|
|
288
|
+
...Array.from({ length: 8 }, (_, i) => mockPass(`CT-7-${i + 1}`, 'prohibited')),
|
|
289
|
+
mockFailure('CT-7-009', 'prohibited'),
|
|
290
|
+
];
|
|
291
|
+
const categories: CategoryScore[] = [
|
|
292
|
+
mockCategoryScore('prohibited', 8, 1, 9),
|
|
293
|
+
];
|
|
294
|
+
const evalResult = mockEvalResult(results, categories, { overallScore: 85, grade: 'B' });
|
|
295
|
+
|
|
296
|
+
const remediation: Record<string, RemediationAction[]> = {
|
|
297
|
+
'CT-7-009': [CT_7_PLAYBOOK.actions[0]],
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
const report = generateRemediationReport(evalResult, remediation, [CT_7_PLAYBOOK]);
|
|
301
|
+
|
|
302
|
+
expect(report.critical_gaps).toContain('prohibited');
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
it('does not flag non-critical categories with decent pass rate as critical gaps', () => {
|
|
306
|
+
// accuracy: 8 passed, 2 failed = 80% pass rate, not critical
|
|
307
|
+
const results: TestResult[] = [
|
|
308
|
+
...Array.from({ length: 8 }, (_, i) => mockPass(`CT-5-${i + 1}`, 'accuracy')),
|
|
309
|
+
mockFailure('CT-5-009', 'accuracy'),
|
|
310
|
+
mockFailure('CT-5-010', 'accuracy'),
|
|
311
|
+
];
|
|
312
|
+
const categories: CategoryScore[] = [
|
|
313
|
+
mockCategoryScore('accuracy', 8, 2, 10),
|
|
314
|
+
];
|
|
315
|
+
const evalResult = mockEvalResult(results, categories, { overallScore: 80, grade: 'B' });
|
|
316
|
+
|
|
317
|
+
const remediation: Record<string, RemediationAction[]> = {
|
|
318
|
+
'CT-5-009': [makeAction('ACC-A1', 'medium')],
|
|
319
|
+
'CT-5-010': [makeAction('ACC-A1', 'medium')],
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
const report = generateRemediationReport(evalResult, remediation, []);
|
|
323
|
+
|
|
324
|
+
expect(report.critical_gaps).not.toContain('accuracy');
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
it('includes system_prompt_patch when system_prompt type actions exist in playbooks', () => {
|
|
328
|
+
const results: TestResult[] = [
|
|
329
|
+
mockFailure('CT-1-001', 'transparency'),
|
|
330
|
+
];
|
|
331
|
+
const categories: CategoryScore[] = [
|
|
332
|
+
mockCategoryScore('transparency', 0, 1, 1),
|
|
333
|
+
];
|
|
334
|
+
const evalResult = mockEvalResult(results, categories, { overallScore: 0, grade: 'F' });
|
|
335
|
+
|
|
336
|
+
const remediation: Record<string, RemediationAction[]> = {
|
|
337
|
+
'CT-1-001': [CT_1_PLAYBOOK.actions[0]],
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
const report = generateRemediationReport(evalResult, remediation, [CT_1_PLAYBOOK]);
|
|
341
|
+
|
|
342
|
+
expect(report.system_prompt_patch).toBeDefined();
|
|
343
|
+
expect(typeof report.system_prompt_patch).toBe('string');
|
|
344
|
+
expect(report.system_prompt_patch!.length).toBeGreaterThan(0);
|
|
345
|
+
expect(report.system_prompt_patch).toContain('System Prompt Compliance Patch');
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
it('includes api_config_patch when relevant categories (transparency) fail', () => {
|
|
349
|
+
// CT_1_PLAYBOOK has an api_config action (CT-1-A3) which triggers transparency headers
|
|
350
|
+
const results: TestResult[] = [
|
|
351
|
+
mockFailure('CT-1-001', 'transparency'),
|
|
352
|
+
];
|
|
353
|
+
const categories: CategoryScore[] = [
|
|
354
|
+
mockCategoryScore('transparency', 0, 1, 1),
|
|
355
|
+
];
|
|
356
|
+
const evalResult = mockEvalResult(results, categories, { overallScore: 0, grade: 'F' });
|
|
357
|
+
|
|
358
|
+
const remediation: Record<string, RemediationAction[]> = {
|
|
359
|
+
'CT-1-001': [CT_1_PLAYBOOK.actions[2]], // CT-1-A3 is api_config
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
const report = generateRemediationReport(evalResult, remediation, [CT_1_PLAYBOOK]);
|
|
363
|
+
|
|
364
|
+
expect(report.api_config_patch).toBeDefined();
|
|
365
|
+
expect(report.api_config_patch!.headers['X-AI-Generated']).toBe('true');
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
it('omits api_config_patch when no api_config relevant categories fail', () => {
|
|
369
|
+
// Use a playbook with only system_prompt and process actions
|
|
370
|
+
const processOnlyPlaybook = makePlaybook('custom-cat', [
|
|
371
|
+
makeAction('PROC-1', 'high', 'process'),
|
|
372
|
+
]);
|
|
373
|
+
|
|
374
|
+
const results: TestResult[] = [
|
|
375
|
+
mockFailure('T-001', 'custom-cat' as EvalCategory),
|
|
376
|
+
];
|
|
377
|
+
const categories: CategoryScore[] = [
|
|
378
|
+
mockCategoryScore('custom-cat', 0, 1, 1),
|
|
379
|
+
];
|
|
380
|
+
const evalResult = mockEvalResult(results, categories);
|
|
381
|
+
|
|
382
|
+
const remediation: Record<string, RemediationAction[]> = {
|
|
383
|
+
'T-001': [makeAction('PROC-1', 'high', 'process')],
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
const report = generateRemediationReport(evalResult, remediation, [processOnlyPlaybook]);
|
|
387
|
+
|
|
388
|
+
expect(report.api_config_patch).toBeUndefined();
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
it('deduplicates actions shared across multiple test failures', () => {
|
|
392
|
+
const sharedAction = makeAction('SHARED-1', 'critical');
|
|
393
|
+
const playbook = makePlaybook('cat-x', [sharedAction]);
|
|
394
|
+
|
|
395
|
+
const results: TestResult[] = [
|
|
396
|
+
mockFailure('T-001', 'cat-x' as EvalCategory),
|
|
397
|
+
mockFailure('T-002', 'cat-x' as EvalCategory),
|
|
398
|
+
mockFailure('T-003', 'cat-x' as EvalCategory),
|
|
399
|
+
];
|
|
400
|
+
const categories: CategoryScore[] = [
|
|
401
|
+
mockCategoryScore('cat-x', 0, 3, 3),
|
|
402
|
+
];
|
|
403
|
+
const evalResult = mockEvalResult(results, categories);
|
|
404
|
+
|
|
405
|
+
const remediation: Record<string, RemediationAction[]> = {
|
|
406
|
+
'T-001': [sharedAction],
|
|
407
|
+
'T-002': [sharedAction],
|
|
408
|
+
'T-003': [sharedAction],
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
const report = generateRemediationReport(evalResult, remediation, [playbook]);
|
|
412
|
+
|
|
413
|
+
// Deduplicated: one action, but affected_tests = 3
|
|
414
|
+
expect(report.actions.length).toBe(1);
|
|
415
|
+
expect(report.actions[0].id).toBe('SHARED-1');
|
|
416
|
+
expect(report.actions[0].affected_tests).toBe(3);
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
it('assigns correct timelines based on priority', () => {
|
|
420
|
+
const critAction = makeAction('C-1', 'critical');
|
|
421
|
+
const highAction = makeAction('H-1', 'high');
|
|
422
|
+
const medAction = makeAction('M-1', 'medium');
|
|
423
|
+
const lowAction = makeAction('L-1', 'low');
|
|
424
|
+
|
|
425
|
+
const pb = makePlaybook('mixed', [critAction, highAction, medAction, lowAction]);
|
|
426
|
+
|
|
427
|
+
const results: TestResult[] = [
|
|
428
|
+
mockFailure('T-1', 'mixed' as EvalCategory),
|
|
429
|
+
mockFailure('T-2', 'mixed' as EvalCategory),
|
|
430
|
+
mockFailure('T-3', 'mixed' as EvalCategory),
|
|
431
|
+
mockFailure('T-4', 'mixed' as EvalCategory),
|
|
432
|
+
];
|
|
433
|
+
const categories: CategoryScore[] = [mockCategoryScore('mixed', 0, 4, 4)];
|
|
434
|
+
const evalResult = mockEvalResult(results, categories);
|
|
435
|
+
|
|
436
|
+
const remediation: Record<string, RemediationAction[]> = {
|
|
437
|
+
'T-1': [critAction],
|
|
438
|
+
'T-2': [highAction],
|
|
439
|
+
'T-3': [medAction],
|
|
440
|
+
'T-4': [lowAction],
|
|
441
|
+
};
|
|
442
|
+
|
|
443
|
+
const report = generateRemediationReport(evalResult, remediation, [pb]);
|
|
444
|
+
|
|
445
|
+
const byId = new Map(report.actions.map((a) => [a.id, a]));
|
|
446
|
+
expect(byId.get('C-1')?.timeline).toBe('this week');
|
|
447
|
+
expect(byId.get('H-1')?.timeline).toBe('next week');
|
|
448
|
+
expect(byId.get('M-1')?.timeline).toBe('this month');
|
|
449
|
+
expect(byId.get('L-1')?.timeline).toBe('backlog');
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
it('returns frozen report object', () => {
|
|
453
|
+
const results: TestResult[] = [mockFailure('T-1', 'transparency')];
|
|
454
|
+
const categories: CategoryScore[] = [mockCategoryScore('transparency', 0, 1, 1)];
|
|
455
|
+
const evalResult = mockEvalResult(results, categories);
|
|
456
|
+
|
|
457
|
+
const remediation: Record<string, RemediationAction[]> = {
|
|
458
|
+
'T-1': [CT_1_PLAYBOOK.actions[0]],
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
const report = generateRemediationReport(evalResult, remediation, [CT_1_PLAYBOOK]);
|
|
462
|
+
|
|
463
|
+
expect(Object.isFrozen(report)).toBe(true);
|
|
464
|
+
expect(Object.isFrozen(report.actions)).toBe(true);
|
|
465
|
+
expect(Object.isFrozen(report.critical_gaps)).toBe(true);
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
it('works with real playbook data from ALL_CT_PLAYBOOKS', () => {
|
|
469
|
+
const results: TestResult[] = [
|
|
470
|
+
mockFailure('CT-1-001', 'transparency'),
|
|
471
|
+
mockFailure('CT-7-001', 'prohibited'),
|
|
472
|
+
];
|
|
473
|
+
const categories: CategoryScore[] = [
|
|
474
|
+
mockCategoryScore('transparency', 0, 1, 1),
|
|
475
|
+
mockCategoryScore('prohibited', 0, 1, 1),
|
|
476
|
+
];
|
|
477
|
+
const evalResult = mockEvalResult(results, categories, { overallScore: 25, grade: 'F' });
|
|
478
|
+
|
|
479
|
+
const remediation: Record<string, RemediationAction[]> = {
|
|
480
|
+
'CT-1-001': [...CT_1_PLAYBOOK.actions],
|
|
481
|
+
'CT-7-001': [...CT_7_PLAYBOOK.actions],
|
|
482
|
+
};
|
|
483
|
+
|
|
484
|
+
const report = generateRemediationReport(evalResult, remediation, ALL_CT_PLAYBOOKS);
|
|
485
|
+
|
|
486
|
+
expect(report.actions.length).toBeGreaterThan(0);
|
|
487
|
+
expect(report.actions.length).toBeLessThanOrEqual(10);
|
|
488
|
+
expect(report.critical_gaps).toContain('transparency');
|
|
489
|
+
expect(report.critical_gaps).toContain('prohibited');
|
|
490
|
+
// Should have system prompt patch from transparency + prohibited system_prompt actions
|
|
491
|
+
expect(report.system_prompt_patch).toBeDefined();
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
it('skips categories with total=0 in critical gap detection', () => {
|
|
495
|
+
const results: TestResult[] = [mockFailure('T-1', 'accuracy')];
|
|
496
|
+
const categories: CategoryScore[] = [
|
|
497
|
+
mockCategoryScore('accuracy', 0, 1, 1),
|
|
498
|
+
// Empty category should be skipped
|
|
499
|
+
{ category: 'transparency' as EvalCategory, score: 0, grade: 'F', passed: 0, failed: 0, errors: 0, inconclusive: 0, skipped: 0, total: 0 },
|
|
500
|
+
];
|
|
501
|
+
const evalResult = mockEvalResult(results, categories);
|
|
502
|
+
const remediation: Record<string, RemediationAction[]> = {
|
|
503
|
+
'T-1': [makeAction('A-1', 'high')],
|
|
504
|
+
};
|
|
505
|
+
|
|
506
|
+
const report = generateRemediationReport(evalResult, remediation, []);
|
|
507
|
+
|
|
508
|
+
// transparency has total=0, should not appear in critical_gaps despite being a critical category
|
|
509
|
+
expect(report.critical_gaps).not.toContain('transparency');
|
|
510
|
+
// accuracy: 0/1 = 0% pass rate < 0.20 → critical gap
|
|
511
|
+
expect(report.critical_gaps).toContain('accuracy');
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
it('counts error verdicts as failures', () => {
|
|
515
|
+
const errorResult: TestResult = {
|
|
516
|
+
testId: 'T-ERR',
|
|
517
|
+
name: 'Error Test',
|
|
518
|
+
category: 'accuracy' as EvalCategory,
|
|
519
|
+
method: 'deterministic',
|
|
520
|
+
verdict: 'error',
|
|
521
|
+
score: 0,
|
|
522
|
+
confidence: 0,
|
|
523
|
+
reasoning: 'timeout',
|
|
524
|
+
probe: 'probe',
|
|
525
|
+
response: '',
|
|
526
|
+
latencyMs: 5000,
|
|
527
|
+
timestamp: new Date().toISOString(),
|
|
528
|
+
};
|
|
529
|
+
|
|
530
|
+
const results: TestResult[] = [errorResult, mockFailure('T-001', 'accuracy')];
|
|
531
|
+
const categories: CategoryScore[] = [mockCategoryScore('accuracy', 0, 2, 2)];
|
|
532
|
+
const evalResult = mockEvalResult(results, categories);
|
|
533
|
+
|
|
534
|
+
const remediation: Record<string, RemediationAction[]> = {
|
|
535
|
+
'T-ERR': [makeAction('A-1', 'high')],
|
|
536
|
+
'T-001': [makeAction('A-1', 'high')],
|
|
537
|
+
};
|
|
538
|
+
|
|
539
|
+
const report = generateRemediationReport(evalResult, remediation, []);
|
|
540
|
+
|
|
541
|
+
expect(report.total_failures).toBe(2);
|
|
542
|
+
});
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
// ── renderRemediationMarkdown ────────────────────────────────
|
|
546
|
+
|
|
547
|
+
describe('renderRemediationMarkdown', () => {
|
|
548
|
+
const makeReport = (overrides?: Partial<RemediationReport>): RemediationReport => ({
|
|
549
|
+
score: 35,
|
|
550
|
+
grade: 'F',
|
|
551
|
+
total_failures: 5,
|
|
552
|
+
critical_gaps: ['transparency', 'prohibited'],
|
|
553
|
+
actions: [
|
|
554
|
+
{
|
|
555
|
+
id: 'CT-1-A1',
|
|
556
|
+
title: 'AI Disclosure & Identity',
|
|
557
|
+
description: 'Add mandatory AI disclosure to system prompt',
|
|
558
|
+
example: '"You are an AI assistant."',
|
|
559
|
+
priority: 'critical',
|
|
560
|
+
effort: 'minimal',
|
|
561
|
+
article_ref: 'Art.50(1)',
|
|
562
|
+
affected_tests: 3,
|
|
563
|
+
timeline: 'this week',
|
|
564
|
+
steps: ['Open your system prompt', 'Add disclosure instruction', 'Re-run eval'],
|
|
565
|
+
},
|
|
566
|
+
{
|
|
567
|
+
id: 'CT-7-A1',
|
|
568
|
+
title: 'Anti-Manipulation Guardrails',
|
|
569
|
+
description: 'Ensure no subliminal techniques',
|
|
570
|
+
example: '"Never use manipulative techniques"',
|
|
571
|
+
priority: 'high',
|
|
572
|
+
effort: 'minimal',
|
|
573
|
+
article_ref: 'Art.5(1)(a)',
|
|
574
|
+
affected_tests: 2,
|
|
575
|
+
timeline: 'next week',
|
|
576
|
+
steps: ['Add anti-manipulation instructions', 'Audit outputs'],
|
|
577
|
+
},
|
|
578
|
+
],
|
|
579
|
+
system_prompt_patch: '# System Prompt Compliance Patch\n\nAdd these instructions.',
|
|
580
|
+
timestamp: '2026-03-23T12:00:00.000Z',
|
|
581
|
+
...overrides,
|
|
582
|
+
});
|
|
583
|
+
|
|
584
|
+
it('returns a markdown string with executive summary', () => {
|
|
585
|
+
const md = renderRemediationMarkdown(makeReport());
|
|
586
|
+
|
|
587
|
+
expect(typeof md).toBe('string');
|
|
588
|
+
expect(md).toContain('# Complior Eval');
|
|
589
|
+
expect(md).toContain('Remediation Report');
|
|
590
|
+
expect(md).toContain('## Executive Summary');
|
|
591
|
+
expect(md).toContain('Critical compliance gaps');
|
|
592
|
+
expect(md).toContain('transparency');
|
|
593
|
+
expect(md).toContain('prohibited');
|
|
594
|
+
});
|
|
595
|
+
|
|
596
|
+
it('includes action plan section with numbered actions and steps', () => {
|
|
597
|
+
const md = renderRemediationMarkdown(makeReport());
|
|
598
|
+
|
|
599
|
+
expect(md).toContain('## Prioritized Action Plan');
|
|
600
|
+
expect(md).toContain('2 remediation actions identified');
|
|
601
|
+
// Numbered action headers
|
|
602
|
+
expect(md).toContain('### 1. [CRITICAL] AI Disclosure & Identity');
|
|
603
|
+
expect(md).toContain('### 2. [HIGH] Anti-Manipulation Guardrails');
|
|
604
|
+
// Action metadata
|
|
605
|
+
expect(md).toContain('**Article:** Art.50(1)');
|
|
606
|
+
expect(md).toContain('**Affected tests:** 3');
|
|
607
|
+
expect(md).toContain('**Effort:** minimal');
|
|
608
|
+
expect(md).toContain('**Timeline:** this week');
|
|
609
|
+
// Steps
|
|
610
|
+
expect(md).toContain('**Steps:**');
|
|
611
|
+
expect(md).toContain('1. Open your system prompt');
|
|
612
|
+
expect(md).toContain('1. Add disclosure instruction');
|
|
613
|
+
expect(md).toContain('1. Re-run eval');
|
|
614
|
+
});
|
|
615
|
+
|
|
616
|
+
it('includes system prompt patch section when present', () => {
|
|
617
|
+
const md = renderRemediationMarkdown(makeReport());
|
|
618
|
+
|
|
619
|
+
expect(md).toContain('## System Prompt Patch');
|
|
620
|
+
expect(md).toContain('System Prompt Compliance Patch');
|
|
621
|
+
expect(md).toContain('Add these instructions.');
|
|
622
|
+
});
|
|
623
|
+
|
|
624
|
+
it('omits system prompt patch section when not present', () => {
|
|
625
|
+
const md = renderRemediationMarkdown(makeReport({ system_prompt_patch: undefined }));
|
|
626
|
+
|
|
627
|
+
expect(md).not.toContain('## System Prompt Patch');
|
|
628
|
+
});
|
|
629
|
+
|
|
630
|
+
it('includes API configuration patch section when present', () => {
|
|
631
|
+
const apiPatch = {
|
|
632
|
+
headers: { 'X-AI-Generated': 'true' },
|
|
633
|
+
inputValidation: { bannedPatterns: ['jailbreak'] as readonly string[] },
|
|
634
|
+
outputValidation: {},
|
|
635
|
+
providerExamples: {},
|
|
636
|
+
};
|
|
637
|
+
|
|
638
|
+
const md = renderRemediationMarkdown(makeReport({ api_config_patch: apiPatch }));
|
|
639
|
+
|
|
640
|
+
expect(md).toContain('## API Configuration Patch');
|
|
641
|
+
expect(md).toContain('```json');
|
|
642
|
+
expect(md).toContain('X-AI-Generated');
|
|
643
|
+
});
|
|
644
|
+
|
|
645
|
+
it('omits API configuration patch section when not present', () => {
|
|
646
|
+
const md = renderRemediationMarkdown(makeReport({ api_config_patch: undefined }));
|
|
647
|
+
|
|
648
|
+
expect(md).not.toContain('## API Configuration Patch');
|
|
649
|
+
});
|
|
650
|
+
|
|
651
|
+
it('includes score, grade, and date in header', () => {
|
|
652
|
+
const md = renderRemediationMarkdown(makeReport());
|
|
653
|
+
|
|
654
|
+
expect(md).toContain('**Score:** 35/100 (Grade F)');
|
|
655
|
+
expect(md).toContain('**Date:** 2026-03-23');
|
|
656
|
+
expect(md).toContain('**Total failures:** 5');
|
|
657
|
+
});
|
|
658
|
+
|
|
659
|
+
it('renders alternative summary when no critical gaps', () => {
|
|
660
|
+
const md = renderRemediationMarkdown(makeReport({ critical_gaps: [] }));
|
|
661
|
+
|
|
662
|
+
expect(md).not.toContain('Critical compliance gaps');
|
|
663
|
+
expect(md).toContain('No critical compliance gaps detected');
|
|
664
|
+
expect(md).toContain('Focus on improving pass rates');
|
|
665
|
+
});
|
|
666
|
+
|
|
667
|
+
it('includes footer with complior branding', () => {
|
|
668
|
+
const md = renderRemediationMarkdown(makeReport());
|
|
669
|
+
|
|
670
|
+
expect(md).toContain('---');
|
|
671
|
+
expect(md).toContain('complior eval --remediation');
|
|
672
|
+
});
|
|
673
|
+
|
|
674
|
+
it('renders correctly with empty actions list', () => {
|
|
675
|
+
const md = renderRemediationMarkdown(makeReport({ actions: [] }));
|
|
676
|
+
|
|
677
|
+
expect(md).toContain('0 remediation actions identified');
|
|
678
|
+
// Should still have all other sections
|
|
679
|
+
expect(md).toContain('## Executive Summary');
|
|
680
|
+
expect(md).toContain('## Prioritized Action Plan');
|
|
681
|
+
});
|
|
682
|
+
});
|