Skip to content

refactor(conformance): reduce cognitive complexity in sdk dispatcher#82

Merged
sirdeggen merged 3 commits intomainfrom
sonar/w2-conformance-sdk
May 7, 2026
Merged

refactor(conformance): reduce cognitive complexity in sdk dispatcher#82
sirdeggen merged 3 commits intomainfrom
sonar/w2-conformance-sdk

Conversation

@sirdeggen
Copy link
Copy Markdown
Contributor

Summary

Wave 2 cognitive complexity refactor — clear all 8 S3776 violations in conformance/runner/ts/dispatchers/sdk.ts.

  • dispatchECDSA (was 34): extracted ecdsaMessageTooLarge, ecdsaPubkeyInfinity, ecdsaExplicitSignatureVerify, ecdsaBatchMessages, ecdsaWrongPubkey, ecdsaSignAndVerify into sdkHelpers.ts
  • dispatchMerklePath (was 55): extracted merklePathLeafPair, merklePathCoinbase, merklePathFromBump, computeMerkleRootFromDisplayTxids
  • dispatchSerialization (was 55): extracted serializationRawHex, serializationEfHex, serializationBeefHex, serializationBumpHex; post-switch fallthrough collapsed to 4 guard lines
  • dispatchSignature (was 46): extracted signatureFromPrivkey, signatureFromDer, signatureFromCompact
  • dispatchBSM (was 26): extracted bsmVerifyDer, bsmVerifyCompact, bsmRecovery
  • dispatchEvaluation (was 71): extracted evalWriteBn, evalWriteBnRange, evalFindAndDelete, evalHex, evalBinary, evalP2PKH, evalScriptPubkey, evalDataLengthBytes, evalScriptAsm plus the three node fixture dispatchers
  • dispatchPrivateKey (was 21) and dispatchNodeTransactionFixture (was 21): moved to helpers with no structural change needed — shape already clean after extraction elsewhere
  • Removed dead StorageUtils import (getURLForHash/getHashFromURL/isValidURL were never used)
  • Eliminated redundant odd-length hex padding (hexToBytes already handles it)
  • Extracted duplicate fill-byte parsing into a module-private parseFillByte helper

Verification

  • node conformance/runner/src/runner.js
  • 71 vector files, 6601 vectors — all pass, zero parse/structure errors

Refs: #38 #44

Extract 30+ sub-handler functions into sdkHelpers.ts to bring all 8
S3776 violations (max complexity 71) below the 15-allowed threshold.
Removes dead StorageUtils import and redundant odd-hex padding.
6601 conformance vectors continue to pass.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@codecov
Copy link
Copy Markdown

codecov Bot commented May 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

sirdeggen and others added 2 commits May 7, 2026 11:57
…lpers

Extract helpers to bring functions at L195 (CC 19) and L696 (CC 21) under
the cognitive-complexity limit of 15.

- merklePathFromBump (CC 19) → split into assertMerklePathStructure,
  assertTxidMerkleRoots, assertSparseTxidRoots; public function now CC 2
- dispatchNodeTransactionFixture (CC 21) → split into
  parseTransactionOrReturnInvalid, countRejectedSpends, countOneSpend;
  public function now CC 3

Co-Authored-By: Claude Opus 4.7 <[email protected]>
ECDSA usage moved to sdkHelpers.ts during the L195/L696 refactor (commit
1b04e0e); the import in sdk.ts is now dead. decodeMessage is exported
from sdk.ts but never consumed by sdkHelpers.ts.
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 7, 2026

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@sirdeggen sirdeggen merged commit 4d18033 into main May 7, 2026
8 of 9 checks passed
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