Skip to content

refactor: reduce production complexity across stack - #380

Merged
ty-everett merged 3 commits into
mainfrom
codex/sonar-production-complexity-4
Jul 28, 2026
Merged

ty-everett merged 3 commits into
mainfrom
codex/sonar-production-complexity-4

Conversation

@ty-everett

@ty-everett ty-everett commented Jul 28, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Advances tracker #324 with a broad production-only complexity and validation wave spanning SDK, Overlay Topics, Overlay Discovery, and Wallet Toolbox.

  • refactors 25 targeted Sonar S3776 hotspots into smaller, behavior-preserving units
  • adds focused adverse-path and runtime-characterization coverage across all four affected package families
  • consolidates shared registry and discovery validation while preserving signature/linkage semantics
  • hardens BTMS attacker-controlled asset ledgers by using Map instead of prototype-bearing objects
  • advances source package versions to SDK 2.2.6, Overlay Topics 1.6.4, Overlay Discovery 2.1.3, and Wallet Toolbox/client/mobile 2.4.9
  • updates package documentation and repository-health baselines

This is source-only maintenance. It does not publish packages, create tags/releases, or change deployment behavior. Deployable infrastructure remains pinned to currently published package versions.

Validation

Local validation:

  • pnpm install --frozen-lockfile
  • all 36 workspace builds
  • repo-wide typecheck, lint, and format checks
  • SDK: 5,744 passing tests
  • Overlay Topics: 371 passing tests and 1 governed skip
  • Overlay Discovery: 90 passing tests
  • Wallet Toolbox: 1,287 passing tests and 5 governed skips
  • pnpm audit:security (0 known vulnerabilities)
  • pnpm health:check (64/64; 37 projects, 30 public packages, 0 contract findings, 0 control errors)
  • pnpm check-versions
  • pnpm codegen:check
  • pnpm docs:examples
  • pnpm license:pack-check
  • affected-package pack:check
  • pnpm test:governance
  • pnpm conformance
  • git diff --check

Hosted validation on exact head 593d7059b6eda6487d027664ca1dcbba2780682b:

  • Codecov patch gate passed at 91.20198% (736 hits, 23 misses, 48 partials); the 90% threshold was preserved
  • SonarQube Cloud quality gate passed with 0 new issues, 0 security hotspots, and 0.7% duplication on new code
  • CodeQL, Socket, dependency review, repository health, conformance, docs, build/lint/policy, browser/mobile, coverage, mutation-quality, and merge gates all passed

Boundaries

The deferred QA/fuzz/manual/browser/performance program remains deferred to the final phase tracked in #324. Sonar administrative configuration is unchanged. Public-service CORS/CSP defaults are unchanged.

@sirdeggen

Copy link
Copy Markdown
Contributor

@copilot make sure the codecov actually passes before we merge this.

@sonarqubecloud

Copy link
Copy Markdown

@ty-everett ty-everett left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maintainer review completed against exact head 593d7059b6eda6487d027664ca1dcbba2780682b.

I reviewed the refactor boundaries, behavior-preserving validation flow, signature/linkage handling, BTMS untrusted-key storage, public-service compatibility, package-version facts, and source-only release boundary. The focused adverse-path additions cover malformed token/envelope/script/input paths and the shared validators without weakening acceptance of additional signed fields.

The earlier Codecov concern is resolved: the authoritative patch check passes at 91.20198% (736 hits, 23 misses, 48 partials) with the repository's 90% threshold unchanged. Sonar reports 0 new issues and 0 security hotspots; CodeQL, Socket, dependency review, audit, build/lint/typecheck/format, coverage, browser/mobile, mutation-quality, governance, conformance, docs, packaging, and merge gates are green. There are no unresolved review threads and I found no merge-blocking issue.

No packages, tags, releases, images, or deployments are created by this PR.

@ty-everett
ty-everett merged commit bb7d3f2 into main Jul 28, 2026
57 checks passed
@ty-everett
ty-everett deleted the codex/sonar-production-complexity-4 branch July 28, 2026 03:16
Copilot stopped work on behalf of sirdeggen due to an error July 28, 2026 03:16
if (question.service !== 'ls_ship') {
throw new Error('Lookup service not supported!')
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[suggestion] Invalid non-object query handling now throws TypeError instead of Error with the same message. The SLAP path has the same change. Message-based callers and the new tests still work, but any consumer that branches on error.name === 'Error', error.constructor === Error, or serializes error class names will observe a patch-level behavioral change.

Suggestion: Keep throwing Error for full compatibility, or document the change and add an explicit regression test asserting error is a TypeError if that is intentional.

}

export function validateOptionalStringArray(value: unknown, path: string): void {
if (value !== undefined && !Array.isArray(value)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[suggestion] validateOptionalStringArray only checks Array.isArray(value). Values such as topics: [1, 2] or topics: [null] pass validation even though the error text claims "an array of strings". This matches the previous SHIP inline check, but centralizing the helper is the right moment to close the gap; invalid element types can still reach storage/query layers.

Suggestion: Validate every element with typeof item === 'string' (and optionally reject empty strings if protocol requires it). Extend the discovery lookup rejection tests with a non-string array element case.

onRejectedOutput: (outputIndex: number, error: unknown) => void
}

export async function identifyPushDropOutputs({

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[suggestion] Several topic managers (BasketMap, CertMap, ProtoMap, WalletConfig) now depend on this shared admit/reject loop, and BTMS / TokenDemo / UMP / Fractionalize were also restructured. New automated coverage appears only for overlay-discovery-services. A regression in the shared loop (shape assertion, empty-admit throw, previousCoins logging gate) would affect multiple managers without a direct unit test net.

Suggestion: Add focused unit tests for identifyPushDropOutputs / assertTransactionInputsAndOutputs (valid output, rejected output, empty admit with/without previousCoins, invalid beef) and at least one smoke test per refactored high-value path (BTMS retention, UMP v3 field validation).


export function validatePaginationQuery(query: PaginationQuery): void {
const { limit, skip, sortOrder } = query
if (limit !== undefined && (typeof limit !== 'number' || limit < 0)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] The shared limit check rejects only limit < 0, so 0 is accepted, but the error message still says "must be a positive number". The same wording existed before; consolidating it makes the inaccurate message the single source of truth.

Suggestion: Change the message to "non-negative number" (or reject limit === 0 if positive is truly required). Align the skip message wording the same way.

return previousCoins !== undefined && previousCoins.length > 0
}

function logSHIPSummary(outputsToAdmit: number[], previousCoins: number[]): void {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] hasPreviousCoins and the summary logging helpers are duplicated almost identically in SLAPTopicManager.ts. That reintroduces the kind of copy-paste surface this PR otherwise reduces.

Suggestion: Move shared previous-coin / summary helpers next to isAdmissibleDiscoveryOutput (or a small discoveryTopicLogging.ts) and parameterize the emoji/protocol strings.

@@ -83,19 +90,17 @@ export class Services implements WalletServices {
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] Extracting configureOptionalProviders dropped the useful comment that tstn intentionally has no WhatsOnChain / block-explorer provider and therefore raw-tx / UTXO / status / history lookups have no provider on that chain. The control flow appears preserved (hasWhatsOnChain = this.chain !== 'tstn'), but future maintainers lose the rationale.

Suggestion: Restore a short comment on hasWhatsOnChain or above initializeReadServices documenting the tstn provider gap.

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.

2 participants