@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,158 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { runNhiScan, nhiToCheckResults } from './nhi-scanner.js';
|
|
3
|
+
import type { ScanContext } from '../../../ports/scanner.port.js';
|
|
4
|
+
|
|
5
|
+
const makeCtx = (files: { relativePath: string; content: string }[]): ScanContext => ({
|
|
6
|
+
projectPath: '/test',
|
|
7
|
+
files: files.map(f => ({
|
|
8
|
+
path: `/test/${f.relativePath}`,
|
|
9
|
+
relativePath: f.relativePath,
|
|
10
|
+
content: f.content,
|
|
11
|
+
extension: f.relativePath.split('.').pop() ?? '',
|
|
12
|
+
})),
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
describe('runNhiScan', () => {
|
|
16
|
+
it('detects OpenAI key in source', () => {
|
|
17
|
+
const ctx = makeCtx([{
|
|
18
|
+
relativePath: 'src/config.ts',
|
|
19
|
+
content: 'const key = "sk-abcdefghijklmnopqrstuvwxyz123456";',
|
|
20
|
+
}]);
|
|
21
|
+
const results = runNhiScan(ctx);
|
|
22
|
+
expect(results.length).toBe(1);
|
|
23
|
+
expect(results[0].category).toBe('api_key');
|
|
24
|
+
expect(results[0].file).toBe('src/config.ts');
|
|
25
|
+
expect(results[0].line).toBe(1);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('detects multiple secrets in same file', () => {
|
|
29
|
+
const ctx = makeCtx([{
|
|
30
|
+
relativePath: 'src/config.ts',
|
|
31
|
+
content: 'const openai = "sk-abcdefghijklmnopqrstuvwxyz123456";\nconst aws = "AKIAIOSFODNN7EXAMPLE";',
|
|
32
|
+
}]);
|
|
33
|
+
const results = runNhiScan(ctx);
|
|
34
|
+
expect(results.length).toBe(2);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('skips test files', () => {
|
|
38
|
+
const ctx = makeCtx([{
|
|
39
|
+
relativePath: 'src/config.test.ts',
|
|
40
|
+
content: 'const key = "sk-abcdefghijklmnopqrstuvwxyz123456";',
|
|
41
|
+
}]);
|
|
42
|
+
const results = runNhiScan(ctx);
|
|
43
|
+
expect(results.length).toBe(0);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('skips .env.example files', () => {
|
|
47
|
+
const ctx = makeCtx([{
|
|
48
|
+
relativePath: '.env.example',
|
|
49
|
+
content: 'OPENAI_KEY=sk-abcdefghijklmnopqrstuvwxyz123456',
|
|
50
|
+
}]);
|
|
51
|
+
const results = runNhiScan(ctx);
|
|
52
|
+
expect(results.length).toBe(0);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('detects private key', () => {
|
|
56
|
+
const ctx = makeCtx([{
|
|
57
|
+
relativePath: 'certs/key.pem',
|
|
58
|
+
content: '-----BEGIN RSA PRIVATE KEY-----\nMIIBogIBAAJBALRiMLAH...',
|
|
59
|
+
}]);
|
|
60
|
+
const results = runNhiScan(ctx);
|
|
61
|
+
expect(results.length).toBe(1);
|
|
62
|
+
expect(results[0].category).toBe('secret');
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('detects GCP service account', () => {
|
|
66
|
+
const ctx = makeCtx([{
|
|
67
|
+
relativePath: 'gcp-creds.json',
|
|
68
|
+
content: '{\n"type": "service_account",\n"project_id": "test"\n}',
|
|
69
|
+
}]);
|
|
70
|
+
const results = runNhiScan(ctx);
|
|
71
|
+
expect(results.length).toBe(1);
|
|
72
|
+
expect(results[0].category).toBe('service_account');
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('detects JWT token', () => {
|
|
76
|
+
const ctx = makeCtx([{
|
|
77
|
+
relativePath: 'src/auth.ts',
|
|
78
|
+
content: 'const token = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0.abc123def456";',
|
|
79
|
+
}]);
|
|
80
|
+
const results = runNhiScan(ctx);
|
|
81
|
+
expect(results.length).toBe(1);
|
|
82
|
+
expect(results[0].category).toBe('token');
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('masks detected secrets', () => {
|
|
86
|
+
const ctx = makeCtx([{
|
|
87
|
+
relativePath: 'src/config.ts',
|
|
88
|
+
content: 'const key = "sk-abcdefghijklmnopqrstuvwxyz123456";',
|
|
89
|
+
}]);
|
|
90
|
+
const results = runNhiScan(ctx);
|
|
91
|
+
expect(results[0].match).not.toContain('abcdefghijklmnopqrstuvwxyz');
|
|
92
|
+
expect(results[0].match).toMatch(/^sk-a\.\.\.3456$/);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('returns empty for clean codebase', () => {
|
|
96
|
+
const ctx = makeCtx([{
|
|
97
|
+
relativePath: 'src/app.ts',
|
|
98
|
+
content: 'const app = express();\napp.listen(3000);',
|
|
99
|
+
}]);
|
|
100
|
+
const results = runNhiScan(ctx);
|
|
101
|
+
expect(results.length).toBe(0);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('detects connection strings', () => {
|
|
105
|
+
const ctx = makeCtx([{
|
|
106
|
+
relativePath: 'src/db.ts',
|
|
107
|
+
content: 'const url = "mongodb://admin:secretpass@cluster.mongodb.net/db";',
|
|
108
|
+
}]);
|
|
109
|
+
const results = runNhiScan(ctx);
|
|
110
|
+
expect(results.length).toBe(1);
|
|
111
|
+
expect(results[0].category).toBe('secret');
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
describe('nhiToCheckResults', () => {
|
|
116
|
+
it('returns pass when no findings', () => {
|
|
117
|
+
const results = nhiToCheckResults([]);
|
|
118
|
+
expect(results.length).toBe(1);
|
|
119
|
+
expect(results[0].type).toBe('pass');
|
|
120
|
+
expect(results[0].checkId).toBe('l4-nhi-clean');
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('converts findings to fail check results', () => {
|
|
124
|
+
const findings = [{
|
|
125
|
+
patternId: 'nhi-openai-key',
|
|
126
|
+
patternName: 'OpenAI API Key',
|
|
127
|
+
category: 'api_key' as const,
|
|
128
|
+
severity: 'critical' as const,
|
|
129
|
+
file: 'src/config.ts',
|
|
130
|
+
line: 5,
|
|
131
|
+
match: 'sk-a...3456',
|
|
132
|
+
description: 'OpenAI API key detected',
|
|
133
|
+
}];
|
|
134
|
+
const results = nhiToCheckResults(findings);
|
|
135
|
+
expect(results.length).toBe(1);
|
|
136
|
+
expect(results[0].type).toBe('fail');
|
|
137
|
+
expect(results[0].checkId).toBe('l4-nhi-api_key');
|
|
138
|
+
if (results[0].type === 'fail') {
|
|
139
|
+
expect(results[0].severity).toBe('critical');
|
|
140
|
+
expect(results[0].articleReference).toBe('Art. 15(4)');
|
|
141
|
+
expect(results[0].file).toBe('src/config.ts');
|
|
142
|
+
expect(results[0].line).toBe(5);
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('maps severity correctly', () => {
|
|
147
|
+
const makeFinding = (severity: 'critical' | 'high' | 'medium') => [{
|
|
148
|
+
patternId: 'test', patternName: 'Test', category: 'secret' as const,
|
|
149
|
+
severity, file: 'f.ts', line: 1, match: '***', description: 'test',
|
|
150
|
+
}];
|
|
151
|
+
const critical = nhiToCheckResults(makeFinding('critical'));
|
|
152
|
+
if (critical[0].type === 'fail') expect(critical[0].severity).toBe('critical');
|
|
153
|
+
const high = nhiToCheckResults(makeFinding('high'));
|
|
154
|
+
if (high[0].type === 'fail') expect(high[0].severity).toBe('high');
|
|
155
|
+
const medium = nhiToCheckResults(makeFinding('medium'));
|
|
156
|
+
if (medium[0].type === 'fail') expect(medium[0].severity).toBe('medium');
|
|
157
|
+
});
|
|
158
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { CheckResult, Severity } from '../../../types/common.types.js';
|
|
2
|
+
import type { ScanContext } from '../../../ports/scanner.port.js';
|
|
3
|
+
import { NHI_PATTERNS, shouldScanFile, type NhiCategory, type NhiPattern } from '../rules/nhi-patterns.js';
|
|
4
|
+
|
|
5
|
+
export interface NhiCheckResult {
|
|
6
|
+
readonly patternId: string;
|
|
7
|
+
readonly patternName: string;
|
|
8
|
+
readonly category: NhiCategory;
|
|
9
|
+
readonly severity: 'critical' | 'high' | 'medium';
|
|
10
|
+
readonly file: string;
|
|
11
|
+
readonly line: number;
|
|
12
|
+
readonly match: string;
|
|
13
|
+
readonly description: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const scanLine = (line: string, lineNum: number, file: string, pattern: NhiPattern): NhiCheckResult | null => {
|
|
17
|
+
const match = pattern.pattern.exec(line);
|
|
18
|
+
if (!match) return null;
|
|
19
|
+
// Mask the matched value for security (show first 4 + last 4 chars)
|
|
20
|
+
const val = match[0];
|
|
21
|
+
const masked = val.length > 12
|
|
22
|
+
? `${val.slice(0, 4)}...${val.slice(-4)}`
|
|
23
|
+
: '***';
|
|
24
|
+
return {
|
|
25
|
+
patternId: pattern.id,
|
|
26
|
+
patternName: pattern.name,
|
|
27
|
+
category: pattern.category,
|
|
28
|
+
severity: pattern.severity,
|
|
29
|
+
file,
|
|
30
|
+
line: lineNum,
|
|
31
|
+
match: masked,
|
|
32
|
+
description: pattern.description,
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const runNhiScan = (ctx: ScanContext): readonly NhiCheckResult[] => {
|
|
37
|
+
const results: NhiCheckResult[] = [];
|
|
38
|
+
|
|
39
|
+
for (const file of ctx.files) {
|
|
40
|
+
if (!shouldScanFile(file.relativePath)) continue;
|
|
41
|
+
|
|
42
|
+
const lines = file.content.split('\n');
|
|
43
|
+
for (let i = 0; i < lines.length; i++) {
|
|
44
|
+
const line = lines[i];
|
|
45
|
+
for (const pattern of NHI_PATTERNS) {
|
|
46
|
+
const result = scanLine(line, i + 1, file.relativePath, pattern);
|
|
47
|
+
if (result) results.push(result);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return results;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const toSeverity = (s: string): Severity =>
|
|
56
|
+
(s === 'critical' || s === 'high' || s === 'medium') ? s : 'high';
|
|
57
|
+
|
|
58
|
+
export const nhiToCheckResults = (results: readonly NhiCheckResult[]): readonly CheckResult[] => {
|
|
59
|
+
if (results.length === 0) {
|
|
60
|
+
return [{
|
|
61
|
+
type: 'pass',
|
|
62
|
+
checkId: 'l4-nhi-clean',
|
|
63
|
+
message: 'No non-human identity secrets detected in source code',
|
|
64
|
+
}];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return results.map((r): CheckResult => ({
|
|
68
|
+
type: 'fail',
|
|
69
|
+
checkId: `l4-nhi-${r.category}`,
|
|
70
|
+
message: `${r.description}: ${r.match} in ${r.file}:${r.line}`,
|
|
71
|
+
severity: toSeverity(r.severity),
|
|
72
|
+
obligationId: 'eu-ai-act-OBL-015',
|
|
73
|
+
articleReference: 'Art. 15(4)',
|
|
74
|
+
fix: 'Remove or externalize the secret from source code. Use environment variables or a secrets manager.',
|
|
75
|
+
file: r.file,
|
|
76
|
+
line: r.line,
|
|
77
|
+
}));
|
|
78
|
+
};
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { checkPassportCompleteness } from './passport-completeness.js';
|
|
3
|
+
import { createScanFile, createScanCtx } from '../../../test-helpers/factories.js';
|
|
4
|
+
|
|
5
|
+
// All 27 required deep-path fields from OBLIGATION_FIELD_MAP must be present and non-empty.
|
|
6
|
+
const fullManifest = JSON.stringify({
|
|
7
|
+
agent_id: 'uuid-123',
|
|
8
|
+
name: 'test-bot',
|
|
9
|
+
display_name: 'Test Bot',
|
|
10
|
+
version: '1.0.0',
|
|
11
|
+
description: 'A test bot',
|
|
12
|
+
type: 'assistant',
|
|
13
|
+
autonomy_level: 'L2',
|
|
14
|
+
autonomy_evidence: { human_approval_gates: 1, unsupervised_actions: 0, no_logging_actions: 0, auto_rated: true },
|
|
15
|
+
framework: 'openai',
|
|
16
|
+
model: { provider: 'openai', model_id: 'gpt-4', data_residency: 'us' },
|
|
17
|
+
owner: { team: 'eng', contact: 'eng@co.com', responsible_person: 'Jane' },
|
|
18
|
+
permissions: { tools: ['search'], denied: [] },
|
|
19
|
+
constraints: { human_approval_required: ['deploy'], prohibited_actions: ['social_scoring'] },
|
|
20
|
+
compliance: { eu_ai_act: { risk_class: 'limited' }, complior_score: 80, last_scan: '2026-03-01' },
|
|
21
|
+
disclosure: { user_facing: true, disclosure_text: 'AI system', ai_marking: { responses_marked: true, method: 'badge' } },
|
|
22
|
+
logging: { actions_logged: true, retention_days: 180 },
|
|
23
|
+
lifecycle: { status: 'active', next_review: '2026-06-01', review_frequency_days: 90 },
|
|
24
|
+
signature: { algorithm: 'ed25519', value: 'abc' },
|
|
25
|
+
source: { mode: 'auto', confidence: 0.9 },
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe('checkPassportCompleteness', () => {
|
|
29
|
+
it('passes for fully complete passport', () => {
|
|
30
|
+
const ctx = createScanCtx([
|
|
31
|
+
createScanFile('.complior/agents/test-bot-manifest.json', fullManifest),
|
|
32
|
+
]);
|
|
33
|
+
|
|
34
|
+
const results = checkPassportCompleteness(ctx);
|
|
35
|
+
expect(results).toHaveLength(1);
|
|
36
|
+
expect(results[0].type).toBe('pass');
|
|
37
|
+
expect(results[0].message).toContain('100%');
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('fails for partially complete passport', () => {
|
|
41
|
+
const partial = JSON.stringify({
|
|
42
|
+
name: 'test-bot',
|
|
43
|
+
version: '1.0.0',
|
|
44
|
+
description: 'A test bot',
|
|
45
|
+
compliance: { eu_ai_act: { risk_class: 'limited' } },
|
|
46
|
+
});
|
|
47
|
+
const ctx = createScanCtx([
|
|
48
|
+
createScanFile('.complior/agents/test-bot-manifest.json', partial),
|
|
49
|
+
]);
|
|
50
|
+
|
|
51
|
+
const results = checkPassportCompleteness(ctx);
|
|
52
|
+
expect(results).toHaveLength(1);
|
|
53
|
+
expect(results[0].type).toBe('fail');
|
|
54
|
+
if (results[0].type === 'fail') {
|
|
55
|
+
expect(results[0].message).toMatch(/\d+%/);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('fails with high severity for mostly empty passport', () => {
|
|
60
|
+
const minimal = JSON.stringify({
|
|
61
|
+
name: 'test-bot',
|
|
62
|
+
compliance: { eu_ai_act: { risk_class: 'high' } },
|
|
63
|
+
});
|
|
64
|
+
const ctx = createScanCtx([
|
|
65
|
+
createScanFile('.complior/agents/test-bot-manifest.json', minimal),
|
|
66
|
+
]);
|
|
67
|
+
|
|
68
|
+
const results = checkPassportCompleteness(ctx);
|
|
69
|
+
expect(results).toHaveLength(1);
|
|
70
|
+
expect(results[0].type).toBe('fail');
|
|
71
|
+
if (results[0].type === 'fail') {
|
|
72
|
+
expect(results[0].severity).toBe('high');
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('checks deep paths — empty owner object counts as unfilled', () => {
|
|
77
|
+
const emptyNested = JSON.stringify({
|
|
78
|
+
name: 'test-bot',
|
|
79
|
+
version: '1.0.0',
|
|
80
|
+
description: 'A test bot',
|
|
81
|
+
agent_id: 'uuid-123',
|
|
82
|
+
type: 'assistant',
|
|
83
|
+
framework: 'openai',
|
|
84
|
+
autonomy_level: 'L2',
|
|
85
|
+
model: {}, // empty — deep path model.provider not filled
|
|
86
|
+
owner: {}, // empty — deep path owner.team not filled
|
|
87
|
+
permissions: {}, // empty — deep path permissions.tools not filled
|
|
88
|
+
constraints: [], // empty array
|
|
89
|
+
compliance: { eu_ai_act: { risk_class: 'limited' } },
|
|
90
|
+
});
|
|
91
|
+
const ctx = createScanCtx([
|
|
92
|
+
createScanFile('.complior/agents/test-bot-manifest.json', emptyNested),
|
|
93
|
+
]);
|
|
94
|
+
|
|
95
|
+
const results = checkPassportCompleteness(ctx);
|
|
96
|
+
expect(results).toHaveLength(1);
|
|
97
|
+
expect(results[0].type).toBe('fail');
|
|
98
|
+
// Deep-path checking: owner.team/contact/responsible_person, model.provider/model_id all empty
|
|
99
|
+
expect(results[0].message).toMatch(/\d+\/\d+ fields/);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('requires oversight fields for high-risk passports', () => {
|
|
103
|
+
// A high-risk passport without oversight should have more missing fields
|
|
104
|
+
const highRiskNoOversight = JSON.stringify({
|
|
105
|
+
...JSON.parse(fullManifest),
|
|
106
|
+
compliance: { eu_ai_act: { risk_class: 'high' }, complior_score: 80, last_scan: '2026-03-01' },
|
|
107
|
+
});
|
|
108
|
+
const ctx = createScanCtx([
|
|
109
|
+
createScanFile('.complior/agents/test-bot-manifest.json', highRiskNoOversight),
|
|
110
|
+
]);
|
|
111
|
+
|
|
112
|
+
const results = checkPassportCompleteness(ctx);
|
|
113
|
+
expect(results).toHaveLength(1);
|
|
114
|
+
expect(results[0].type).toBe('fail');
|
|
115
|
+
// Missing oversight.responsible_person and oversight.override_mechanism
|
|
116
|
+
expect(results[0].message).toMatch(/\d+\/\d+ fields/);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('returns empty for no manifest files', () => {
|
|
120
|
+
const ctx = createScanCtx([
|
|
121
|
+
createScanFile('package.json', '{"dependencies":{"openai":"^4.0.0"}}'),
|
|
122
|
+
]);
|
|
123
|
+
|
|
124
|
+
const results = checkPassportCompleteness(ctx);
|
|
125
|
+
expect(results).toHaveLength(0);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { CheckResult } from '../../../types/common.types.js';
|
|
2
|
+
import type { ScanContext } from '../../../ports/scanner.port.js';
|
|
3
|
+
import { filterPassportManifests, extractRiskClass } from '../../passport/builder/manifest-files.js';
|
|
4
|
+
import { OBLIGATION_FIELD_MAP, getFieldValue, isNonEmpty } from '../../passport/obligation-field-map.js';
|
|
5
|
+
|
|
6
|
+
const CHECK_ID = 'passport-completeness';
|
|
7
|
+
const ARTICLE_REF = 'Art. 26(4)';
|
|
8
|
+
const OBLIGATION_ID = 'eu-ai-act-OBL-011';
|
|
9
|
+
|
|
10
|
+
/** Deep-path fields required for all risk levels. */
|
|
11
|
+
const BASE_FIELDS = OBLIGATION_FIELD_MAP.filter((m) => m.required).map((m) => m.field);
|
|
12
|
+
|
|
13
|
+
/** Additional fields required for high-risk / prohibited passports. */
|
|
14
|
+
const HIGH_RISK_EXTRA = ['oversight.responsible_person', 'oversight.override_mechanism'] as const;
|
|
15
|
+
|
|
16
|
+
const countDeepFields = (manifest: Record<string, unknown>, fields: readonly string[]): number => {
|
|
17
|
+
let filled = 0;
|
|
18
|
+
for (const fieldPath of fields) {
|
|
19
|
+
const value = getFieldValue(manifest as never, fieldPath);
|
|
20
|
+
if (isNonEmpty(value)) {
|
|
21
|
+
filled++;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return filled;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const checkPassportCompleteness = (ctx: ScanContext): readonly CheckResult[] => {
|
|
28
|
+
const passportFiles = filterPassportManifests(ctx.files);
|
|
29
|
+
|
|
30
|
+
if (passportFiles.length === 0) {
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const results: CheckResult[] = [];
|
|
35
|
+
|
|
36
|
+
for (const file of passportFiles) {
|
|
37
|
+
try {
|
|
38
|
+
const manifest = JSON.parse(file.content) as Record<string, unknown>;
|
|
39
|
+
const risk = extractRiskClass(manifest);
|
|
40
|
+
|
|
41
|
+
const requiredFields = risk === 'high' || risk === 'prohibited'
|
|
42
|
+
? [...BASE_FIELDS, ...HIGH_RISK_EXTRA]
|
|
43
|
+
: BASE_FIELDS;
|
|
44
|
+
const totalRequired = requiredFields.length;
|
|
45
|
+
const filled = countDeepFields(manifest, requiredFields);
|
|
46
|
+
const pct = Math.round((filled / totalRequired) * 100);
|
|
47
|
+
const name = (manifest.name as string) ?? file.relativePath;
|
|
48
|
+
|
|
49
|
+
if (pct >= 100) {
|
|
50
|
+
results.push({
|
|
51
|
+
type: 'pass',
|
|
52
|
+
checkId: CHECK_ID,
|
|
53
|
+
message: `Passport Completeness: ${pct}% (${filled}/${totalRequired} fields) — ${name}`,
|
|
54
|
+
});
|
|
55
|
+
} else {
|
|
56
|
+
results.push({
|
|
57
|
+
type: 'fail',
|
|
58
|
+
checkId: CHECK_ID,
|
|
59
|
+
message: `Passport Completeness: ${pct}% (${filled}/${totalRequired} fields) — ${name} (${ARTICLE_REF})`,
|
|
60
|
+
severity: pct < 50 ? 'high' : 'medium',
|
|
61
|
+
obligationId: OBLIGATION_ID,
|
|
62
|
+
articleReference: ARTICLE_REF,
|
|
63
|
+
fix: `Fill missing passport fields using \`complior agent init --force\` or manual edit`,
|
|
64
|
+
file: file.relativePath,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
} catch {
|
|
68
|
+
results.push({
|
|
69
|
+
type: 'fail',
|
|
70
|
+
checkId: CHECK_ID,
|
|
71
|
+
message: `Invalid passport manifest: ${file.relativePath}`,
|
|
72
|
+
severity: 'high',
|
|
73
|
+
obligationId: OBLIGATION_ID,
|
|
74
|
+
articleReference: ARTICLE_REF,
|
|
75
|
+
fix: 'Regenerate passport with `complior agent init --force`',
|
|
76
|
+
file: file.relativePath,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return results;
|
|
82
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { checkPassportPresence } from './passport-presence.js';
|
|
3
|
+
import { createScanFile, createScanCtx } from '../../../test-helpers/factories.js';
|
|
4
|
+
|
|
5
|
+
describe('checkPassportPresence', () => {
|
|
6
|
+
it('passes when passport manifest found', () => {
|
|
7
|
+
const ctx = createScanCtx([
|
|
8
|
+
createScanFile('.complior/agents/my-bot-manifest.json', '{"name":"my-bot"}'),
|
|
9
|
+
createScanFile('package.json', '{"dependencies":{"openai":"^4.0.0"}}'),
|
|
10
|
+
]);
|
|
11
|
+
|
|
12
|
+
const results = checkPassportPresence(ctx);
|
|
13
|
+
expect(results).toHaveLength(1);
|
|
14
|
+
expect(results[0].type).toBe('pass');
|
|
15
|
+
expect(results[0].message).toContain('Agent Passport found');
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('fails when AI SDK detected but no passport', () => {
|
|
19
|
+
const ctx = createScanCtx([
|
|
20
|
+
createScanFile('package.json', '{"dependencies":{"openai":"^4.0.0"}}'),
|
|
21
|
+
createScanFile('src/app.ts', 'const x = 1;'),
|
|
22
|
+
]);
|
|
23
|
+
|
|
24
|
+
const results = checkPassportPresence(ctx);
|
|
25
|
+
expect(results).toHaveLength(1);
|
|
26
|
+
expect(results[0].type).toBe('fail');
|
|
27
|
+
if (results[0].type === 'fail') {
|
|
28
|
+
expect(results[0].severity).toBe('high');
|
|
29
|
+
expect(results[0].fix).toContain('complior agent init');
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('skips when no AI SDK detected', () => {
|
|
34
|
+
const ctx = createScanCtx([
|
|
35
|
+
createScanFile('package.json', '{"dependencies":{"express":"^4.0.0"}}'),
|
|
36
|
+
createScanFile('src/app.ts', 'const x = 1;'),
|
|
37
|
+
]);
|
|
38
|
+
|
|
39
|
+
const results = checkPassportPresence(ctx);
|
|
40
|
+
expect(results).toHaveLength(1);
|
|
41
|
+
expect(results[0].type).toBe('skip');
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('detects multiple passport manifests', () => {
|
|
45
|
+
const ctx = createScanCtx([
|
|
46
|
+
createScanFile('.complior/agents/bot-a-manifest.json', '{"name":"bot-a"}'),
|
|
47
|
+
createScanFile('.complior/agents/bot-b-manifest.json', '{"name":"bot-b"}'),
|
|
48
|
+
createScanFile('package.json', '{"dependencies":{"openai":"^4.0.0"}}'),
|
|
49
|
+
]);
|
|
50
|
+
|
|
51
|
+
const results = checkPassportPresence(ctx);
|
|
52
|
+
expect(results).toHaveLength(1);
|
|
53
|
+
expect(results[0].type).toBe('pass');
|
|
54
|
+
expect(results[0].message).toContain('2 manifest(s)');
|
|
55
|
+
});
|
|
56
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { readdirSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import type { CheckResult } from '../../../types/common.types.js';
|
|
4
|
+
import type { ScanContext } from '../../../ports/scanner.port.js';
|
|
5
|
+
import { AI_SDK_PACKAGES } from '../rules/banned-packages-sdk.js';
|
|
6
|
+
import { filterPassportManifests } from '../../passport/builder/manifest-files.js';
|
|
7
|
+
|
|
8
|
+
const CHECK_ID = 'passport-presence';
|
|
9
|
+
const ARTICLE_REF = 'Art. 26(4)';
|
|
10
|
+
const OBLIGATION_ID = 'eu-ai-act-OBL-011';
|
|
11
|
+
|
|
12
|
+
const hasAiSdk = (ctx: ScanContext): boolean => {
|
|
13
|
+
const pkgFile = ctx.files.find((f) => f.relativePath.endsWith('package.json'));
|
|
14
|
+
if (!pkgFile) return false;
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
const pkg = JSON.parse(pkgFile.content) as Record<string, unknown>;
|
|
18
|
+
const deps = {
|
|
19
|
+
...(pkg.dependencies as Record<string, string> | undefined),
|
|
20
|
+
...(pkg.devDependencies as Record<string, string> | undefined),
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
return Object.keys(deps).some((name) => AI_SDK_PACKAGES.has(name));
|
|
24
|
+
} catch {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Count passport manifests — first check ctx.files (covers tests and configs that
|
|
31
|
+
* include .complior), then fall back to disk read (production: .complior is excluded
|
|
32
|
+
* from EXCLUDED_DIRS in file-collector).
|
|
33
|
+
*/
|
|
34
|
+
const countPassportManifests = (ctx: ScanContext): number => {
|
|
35
|
+
// 1. Check scanned files (works in tests and when .complior is explicitly included)
|
|
36
|
+
const fromCtx = filterPassportManifests(ctx.files).length;
|
|
37
|
+
if (fromCtx > 0) return fromCtx;
|
|
38
|
+
|
|
39
|
+
// 2. Fall back to disk read (production — .complior excluded from scanning)
|
|
40
|
+
try {
|
|
41
|
+
const agentsDir = join(ctx.projectPath, '.complior', 'agents');
|
|
42
|
+
return readdirSync(agentsDir).filter(f => f.endsWith('-manifest.json')).length;
|
|
43
|
+
} catch {
|
|
44
|
+
return 0;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const checkPassportPresence = (ctx: ScanContext): readonly CheckResult[] => {
|
|
49
|
+
const manifestCount = countPassportManifests(ctx);
|
|
50
|
+
|
|
51
|
+
if (manifestCount > 0) {
|
|
52
|
+
return [{
|
|
53
|
+
type: 'pass',
|
|
54
|
+
checkId: CHECK_ID,
|
|
55
|
+
message: `Agent Passport found (${manifestCount} manifest(s)) — ${ARTICLE_REF}`,
|
|
56
|
+
}];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Only fail if AI SDK is detected (no passport needed without AI)
|
|
60
|
+
if (hasAiSdk(ctx)) {
|
|
61
|
+
return [{
|
|
62
|
+
type: 'fail',
|
|
63
|
+
checkId: CHECK_ID,
|
|
64
|
+
message: `No Agent Passport found — AI SDK detected but no .complior/agents/*-manifest.json (${ARTICLE_REF})`,
|
|
65
|
+
severity: 'high',
|
|
66
|
+
obligationId: OBLIGATION_ID,
|
|
67
|
+
articleReference: ARTICLE_REF,
|
|
68
|
+
fix: 'Run `complior agent init` to generate an Agent Passport for your AI system',
|
|
69
|
+
}];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// No AI SDK → skip
|
|
73
|
+
return [{
|
|
74
|
+
type: 'skip',
|
|
75
|
+
checkId: CHECK_ID,
|
|
76
|
+
reason: 'No AI SDK detected — passport not required',
|
|
77
|
+
}];
|
|
78
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Factory for dual-pattern scanner checks.
|
|
3
|
+
* Handles the common pattern: search files for "positive" indicators,
|
|
4
|
+
* search for "context" indicators, return pass/fail/skip.
|
|
5
|
+
*
|
|
6
|
+
* Used by: ai-disclosure (Art. 50.1), content-marking (Art. 50.2).
|
|
7
|
+
*/
|
|
8
|
+
import type { CheckResult } from '../../../types/common.types.js';
|
|
9
|
+
import type { ScanContext, FileInfo } from '../../../ports/scanner.port.js';
|
|
10
|
+
|
|
11
|
+
export interface PatternCheckConfig {
|
|
12
|
+
readonly checkId: string;
|
|
13
|
+
readonly articleRef: string;
|
|
14
|
+
readonly obligationId: string;
|
|
15
|
+
readonly severity: 'critical' | 'high' | 'medium' | 'low';
|
|
16
|
+
/** Patterns that indicate compliance (e.g., disclosure text, watermarking). */
|
|
17
|
+
readonly positivePatterns: readonly RegExp[];
|
|
18
|
+
/** Patterns that indicate the feature IS used but compliance is missing (e.g., chat code, content generation). */
|
|
19
|
+
readonly contextPatterns: readonly RegExp[];
|
|
20
|
+
readonly passMessage: string;
|
|
21
|
+
readonly failMessage: string;
|
|
22
|
+
readonly skipReason: string;
|
|
23
|
+
readonly fix: string;
|
|
24
|
+
/** Optional file filter (e.g., only UI files). Defaults to all files. */
|
|
25
|
+
readonly fileFilter?: (file: FileInfo) => boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const createPatternCheck = (config: PatternCheckConfig) =>
|
|
29
|
+
(ctx: ScanContext): readonly CheckResult[] => {
|
|
30
|
+
const files = config.fileFilter ? ctx.files.filter(config.fileFilter) : ctx.files;
|
|
31
|
+
|
|
32
|
+
let positiveFound = false;
|
|
33
|
+
let contextFound = false;
|
|
34
|
+
|
|
35
|
+
for (const file of files) {
|
|
36
|
+
if (!positiveFound && config.positivePatterns.some((p) => p.test(file.content))) {
|
|
37
|
+
positiveFound = true;
|
|
38
|
+
}
|
|
39
|
+
if (!contextFound && config.contextPatterns.some((p) => p.test(file.content))) {
|
|
40
|
+
contextFound = true;
|
|
41
|
+
}
|
|
42
|
+
if (positiveFound) break;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (positiveFound) {
|
|
46
|
+
return [{
|
|
47
|
+
type: 'pass',
|
|
48
|
+
checkId: config.checkId,
|
|
49
|
+
message: `${config.passMessage} (${config.articleRef})`,
|
|
50
|
+
}];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (contextFound) {
|
|
54
|
+
return [{
|
|
55
|
+
type: 'fail',
|
|
56
|
+
checkId: config.checkId,
|
|
57
|
+
message: `${config.failMessage} (${config.articleRef})`,
|
|
58
|
+
severity: config.severity,
|
|
59
|
+
obligationId: config.obligationId,
|
|
60
|
+
articleReference: config.articleRef,
|
|
61
|
+
fix: config.fix,
|
|
62
|
+
}];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return [{
|
|
66
|
+
type: 'skip',
|
|
67
|
+
checkId: config.checkId,
|
|
68
|
+
reason: config.skipReason,
|
|
69
|
+
}];
|
|
70
|
+
};
|