Skip to content

Remove dead logic, duplicated helpers, and style slop - #41

Merged
0x0bug merged 6 commits into
mainfrom
fix/clean-code-slop
Jul 26, 2026
Merged

Remove dead logic, duplicated helpers, and style slop#41
0x0bug merged 6 commits into
mainfrom
fix/clean-code-slop

Conversation

@0x0bug

@0x0bug 0x0bug commented Jul 26, 2026

Copy link
Copy Markdown
Owner

What changed

Mechanical clean-code fixes. No intended production behavior changes. Invalid synthetic snapshots with null parent entries now return a structured failure instead of no result; the only user-visible production difference is normalized label spacing in report output (three misaligned columns).

Dead logic removed

  • Test-WdtTuiUnicodeLogoSupport computed a Windows Terminal signal and then ignored it in a tautological expression ($utf8 -and ($wt -or $utf8)$utf8). The dead signal and its two parameters are removed from the detection chain (Test-WdtTuiUnicodeLogoSupport, Get-WdtTuiLogoModeDecision, Get-WdtTuiLogoMode). Documented behavior — Unicode logo on interactive UTF-8 output — is unchanged (README "Unicode and ASCII logo modes", docs/usage.md) and is now pinned by direct tests.
  • The trailing return in Test-WdtSnapshotMembership (process-runner) was removed as unreachable, which was true for the production path — snapshot entries are always non-null pscustomobjects, so the loop can only exit through in-loop returns. Re-review found the function is also called directly with synthetic snapshots (tests), where a parent key present with a $null value would have ended the walk and returned nothing. The parent lookup is now guarded explicitly (ContainsKey + null check → SnapshotParentMissing), keeping the function total without reintroducing a dead-looking trailing line, with a regression test that fails without the guard.
  • Test-WdtAllowedW32tmProcessShape accepted -LocalFunctionNames and never read it; Test-WdtAllowedNewObjectCommand and Get-WdtMemberSafetyIssue carried the parameter only to forward it. The whole forwarding chain is removed. Get-WdtCommandSafetyIssue keeps its parameter — it genuinely uses it.
  • An assignment whose value was immediately discarded before continue in the TUI resize path now discards explicitly ($null =).

Duplication removed

  • Group-EventLogEvents reimplemented the events module's own ConvertTo-OneLineMessage inline (same 240/237 truncation constants). It now calls the helper. tests/diagnostic-classification.tests.ps1 imports the helper alongside the function under test — the isolated-import harness was why the inline copy existed in the first place.

Consistency

  • Protect-WdtRegexMatches assigned to the automatic $matches variable; renamed to $regexMatches. This is hygiene only — modules run in separate child processes, so no cross-contamination was possible. (The same pattern exists in scripts/bootstrap/run.ps1:13, intentionally not fixed here: the bootstrap is under a byte-stability contract with the published site copy and the SHA-256 pinned in tests/bootstrap-sync.tests.ps1; it needs a coordinated WDT-change → site-sync pass.)
  • $approvalInventory / $ApprovalInventory casing unified in the services module.
  • Report label columns re-aligned: Pending states (Suspicious) (services), Samples (performance), findings-summary hashtable in report-common.

Regression tests added

  • Test-WdtSnapshotMembership with a parent key mapped to $null returns structured SnapshotParentMissing (verified to fail without the guard).
  • Get-WdtTuiLogoModeDecision contract: overrides, redirected output, UTF-8 vs OEM encodings (6 cases).
  • ConvertTo-OneLineMessage through Group-EventLogEvents: whitespace-only → No message; >240 chars → 240 with ...; newline collapse.

Verification

  • scripts/validate.ps1: pass on PowerShell 7 and Windows PowerShell 5.1 (0 parser / 0 safety / 0 layout / 0 generated).
  • Full test suite (19 files × both engines): all pass.
  • Live smoke: -Module Events,Services,Performance -PrivacyMode → exit 0, Collection completeness: Complete, event messages one-lined and truncated by the shared helper, aligned labels confirmed in the generated report.
  • git diff --check: clean.

Not touched

scripts/bootstrap/run.ps1 (byte-stability contract), the +4 menu-count coupling in Get-WdtTuiVisibleIndexes and cross-module helper consolidation (Write-Section/Format-Bytes/ConvertTo-SafeSingleLine → report-common) — those need AST-allowlist changes and deserve their own PR.

🤖 Generated with Claude Code

skrewss and others added 6 commits July 26, 2026 19:48
The TUI Unicode-logo check computed a Windows Terminal signal that a
tautological expression then ignored; documented behavior (interactive
UTF-8 output) is unchanged. Stop-WdtProcessTree's membership walk can
only exit through in-loop returns, so the trailing return was
unreachable. The W32tm shape check accepted a LocalFunctionNames
parameter it never read, and two policy functions existed only to
forward it.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Group-EventLogEvents reimplemented the module's own one-line-message
helper inline with the same 240-character truncation; the
classification test now imports the helper alongside the function
under test. Protect-WdtRegexMatches assigned to the automatic
$matches variable, which crash parsing elsewhere reads after -match.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Removing the trailing return in Test-WdtSnapshotMembership left one
representable hashtable state uncovered: a parent key present with a
null value would end the walk and return nothing. Production code
cannot create that state (snapshot entries are always non-null
pscustomobjects), but the function is also called directly with
synthetic snapshots, so the walk now guards the parent lookup
explicitly and stays total.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@0x0bug
0x0bug marked this pull request as ready for review July 26, 2026 20:56
@0x0bug
0x0bug merged commit 0b5da21 into main Jul 26, 2026
1 check 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.

2 participants