Skip to content

Unit Coverage Audit

Status: complete · Last updated: 2026-06-18 (shieldkit@0.2.0)
Policy: every implemented runtime capability in src/ has positive (+) and negative (−) unit tests in tests/unit/. Adversarial/integration layers add breadth; they do not replace this matrix.

Sign-off checklist

  • [x] All public exports from src/index.ts covered
  • [x] All src/utils/* modules have dedicated unit tests
  • [x] Middleware paths: input, output (generate + stream), cost, audit, repair
  • [x] Guards: injection, PII, keywords — block/warn/redact + benign
  • [x] TEST_VERBOSE=1 logs audit/guard/contrast decisions (default: silent CI)

Public API

Module / APIPositive (+)Negative (−)Unit test fileStatus
shield()passthrough generationstrict injection blockconfig.test.tscovered
resolveConfig balanced/strict/cheap/local/custompreset valuesconfig.test.tscovered
shieldGenerateTextvalid output, repair successrepair exhausted, non-repair error rethrowshield-generate.test.tscovered
shieldStreamTextschema merge + stream, homoglyph blockstrict injection block on streamshield-stream-text.test.tscovered
guardToolsallow, approval, auditdeny, max calls, require approvalguard-tools.test.tscovered
createShieldContext / getOrCreateSessioncreate + reusecontext.test.tscovered
resetSessionclears sessioncontext.test.ts, cost-tracking.test.tscovered
recordSessionUsageincrements totalscontext.test.tscovered
createRequestContextdefaults + overridescontext.test.tscovered
ShieldBlockedErrorpropertieserrors.test.tscovered
ShieldBudgetErrorpropertieserrors.test.ts, cost-tracking.test.tscovered
ShieldRepairErrorpropertieserrors.test.ts, shield-generate.test.tscovered
ShieldToolErrorpropertieserrors.test.ts, guard-tools.test.tscovered

Guards

ModulePositive (+)Negative (−)Unit test fileStatus
injectionGuarddetect injectionbenign textguards.test.tscovered
injectionGuard warntriggered + warn actionguards.test.tscovered
piiGuard email/phone/ssn/cardredactinvalid Luhn card ignoredguards.test.tscovered
piiGuard blocktriggeredguards.test.tscovered
keywordGuarddeny matchno match / boundaryguards.test.tscovered

Middleware

ModulePositive (+)Negative (−)Unit test fileStatus
Input injectionstrict blockinput-guardrails.test.tscovered
Input injection warnallows requestinput-warn.test.tscovered
Input PIIredact string + multi-partinput-guardrails.test.tscovered
Output stream PII/keywordredactblockoutput-guardrails.test.tscovered
Output generate PII/keywordredactblockoutput-generate.test.tscovered
Cost enforcerecords usageShieldBudgetErrorcost-tracking.test.tscovered
Cost track-onlymultiple calls OKcost-tracking.test.tscovered
Cost stream pre-estimatebudget block before streamcost-tracking.test.tscovered
Cost budget.warnaudit at warnAtPercentcost-warn.test.tscovered
Audit generate lifecyclestart + completeblocked on injectionaudit-logging.test.ts, audit-stream.test.tscovered
Audit stream lifecyclestart + completeguard.triggered on blockaudit-stream.test.tscovered
Repair retryvalid JSON after retryrepair.test.tscovered
Repair feedbackwith/without partialrepair.test.tscovered
Repair disabledreturns raw outputrepair-disabled.test.tscovered

Utils

ModulePositive (+)Negative (−)Unit test fileStatus
usage.tsmerge, counts, normalizeempty usageutils/usage.test.tscovered
prompt.tsextract, merge, redact, transforminvalid provider optionsutils/prompt.test.tscovered
deep-merge.tsnested mergeundefined skip, array replaceutils/deep-merge.test.tscovered
output-guards.tsgenerate redactkeyword blockutils/output-guards.test.tscovered
audit.tsconsole basic/detaileddisabled, sink swallowutils/audit.test.tscovered
stream-collector.tscollect text + usageutils/stream-collector.test.tscovered
guard-normalize.tshomoglyph + zero-width fold, inj-009 benignutils/guard-normalize.test.tscovered
token-estimator.tsknown/unknown modelszero cost/texttoken-estimator.test.tscovered
json-repair.tsrepair + validateinvalid schemajson-repair.test.tscovered

Release tooling

Script / workflowPositive (+)Negative (−)Unit test fileStatus
extract-changelog-section.mjs + publishsection extract, v prefixmissing / invalid versionscripts/extract-changelog-section.test.tscovered

Explicit non-goals (no unit tests required)

CapabilityNotes
Frontier API providersRUN_FRONTIER_REDTEAM=1 smoke only
generateObject / streamObjectLegacy API; documented gap
Multi-instance serverless budgetsArchitectural limitation
ML-based injectionNot implemented

Verbose test logging

bash
TEST_VERBOSE=1 npm run test:run

Logs [test:contrast], [test:redteam], and [test:<scope>] lines. CONTRAST_VERBOSE=1 is an alias. Default CI runs are silent.