Skip to content

refactor: reduce cognitive complexity in differential-cache (batch 3a) - #141

Merged
sarthakagrawal927 merged 1 commit into
mainfrom
fix/reduce-complexity-batch3a
Aug 15, 2026
Merged

refactor: reduce cognitive complexity in differential-cache (batch 3a)#141
sarthakagrawal927 merged 1 commit into
mainfrom
fix/reduce-complexity-batch3a

Conversation

@sarthakagrawal927

Copy link
Copy Markdown
Member

Part of #117

Summary

Reduces cognitive complexity in apps/desktop/src/lib/warm-verification/differential-cache.ts by extracting helper functions from six over-complex functions, bringing every function below the cognitive complexity threshold of 20.

Changes

  • prepareDependencies (CCN 24 → ≤20): Extracted #prepareDependenciesUnlocked private method from the inline #exclusive callback.
  • createWritableTarget (CCN 27 → ≤20): Extracted #createWritableTargetUnlocked private method from the inline #exclusive callback.
  • hashApplicationPayload (CCN 36 → ≤20): Split into collectAncestors, collectApplicationEntries, processApplicationEntry, filterApplicationDirectories, and hashApplicationRecords.
  • inspectDependencyLayout (CCN 77 → ≤20): Split into walkDependencyRoot, processDependencyChild, and inspectDependencyLink.
  • cleanupRoot (CCN 21 → ≤20): Extracted collectExpiredEntries and measureActiveTargets helpers.
  • cleanupTransients (CCN 59 → ≤20): Split into cleanupTransientRole, processTransientEntry, handleInvalidTransient, handleStaleTransient, measureRetainedTarget, and cleanupTrash.

Verification

  • pnpm exec biome lint --config-path=biome.code-health.json --only=complexity/noExcessiveCognitiveComplexity — 0 violations
  • pnpm quality:complexity — PASS
  • pnpm lint — PASS
  • pnpm quality:duplication — PASS (0.80% < 0.81 threshold)
  • All 21 differential-cache.test.ts unit tests pass

Constraints

  • Pure refactoring — no behavior changes
  • No suppressions (biome-ignore, eslint-disable)
  • All helpers extracted to module level
  • Diff: 756 insertions, 507 deletions (well under 4000/6000 line limits)

Extract helper functions from six over-complex functions in
differential-cache.ts to bring every function below the cognitive
complexity threshold of 20:

- prepareDependencies: extract #prepareDependenciesUnlocked private method
- createWritableTarget: extract #createWritableTargetUnlocked private method
- hashApplicationPayload: split into collectAncestors,
  collectApplicationEntries, processApplicationEntry,
  filterApplicationDirectories, hashApplicationRecords
- inspectDependencyLayout: split into walkDependencyRoot,
  processDependencyChild, inspectDependencyLink
- cleanupRoot: extract collectExpiredEntries and measureActiveTargets
- cleanupTransients: split into cleanupTransientRole, processTransientEntry,
  handleInvalidTransient, handleStaleTransient, measureRetainedTarget,
  cleanupTrash

Pure refactoring — no behavior changes, no suppressions.

Part of #117
@sarthakagrawal927
sarthakagrawal927 merged commit 566d7b0 into main Aug 15, 2026
3 checks passed
@sarthakagrawal927
sarthakagrawal927 deleted the fix/reduce-complexity-batch3a branch August 15, 2026 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant