Skip to content

src/signals/improvement.ts reimplements clamp() instead of reusing the canonical one from slop.ts #6607

Description

@JSONbored

Context

src/signals/improvement.ts defines its own private clamp function at the bottom of the file (lines 257-259):

function clamp(value: number, min: number, max: number): number {
  return Math.min(max, Math.max(min, value));
}

src/signals/slop.ts already re-exports a clamp function with the identical (value, min, max) signature and identical Math.min(max, Math.max(min, value)) body, sourced from packages/loopover-engine/src/signals/slop.ts:405. improvement.ts already imports from ./slop at line 29 (import { buildMissingTestEvidenceFinding, type SlopChangedFile } from "./slop";), so the dependency is already established — clamp simply was never added to that same import.

The sibling file src/signals/issue-slop.ts:7 already demonstrates the correct pattern this file should follow: import { clamp, slopBandFor, type SlopAssessment } from "./slop";.

improvement.ts's local clamp is used once, to bound improvementScore in buildStructuralImprovementAssessment (lines 123-130).

Requirements

  • Remove the local clamp function definition from src/signals/improvement.ts (lines 257-259).
  • Add clamp to the existing import from ./slop on line 29 of src/signals/improvement.ts (import { buildMissingTestEvidenceFinding, clamp, type SlopChangedFile } from "./slop";), matching the import style already used by src/signals/issue-slop.ts:7.
  • This is a pure refactor: the computed improvementScore value (and every build*Finding helper's output) must be byte-identical to before this change — both implementations already share the same signature and body.

Deliverables

  • src/signals/improvement.ts imports clamp from ./slop instead of defining its own copy
  • Existing tests for buildStructuralImprovementAssessment and its build*Finding helpers pass unmodified

Test Coverage Requirements

Touches src/signals/improvement.ts, under src/** — this repo's Codecov patch gate (99%+ on changed lines) applies to the changed import line. No new test file should be required: improvementScore's clamping behavior is already exercised by improvement.ts's existing test suite, and the replacement clamp is byte-identical in behavior to the one it replaces.

Expected Outcome

src/signals/improvement.ts has no locally-duplicated clamp implementation; it reuses the same canonical clamp that every other consumer of slop.ts's exports (e.g. issue-slop.ts) already shares.

Links & Resources

  • src/signals/improvement.ts:29,123-130,257-259
  • src/signals/slop.ts (re-export of clamp)
  • src/signals/issue-slop.ts:7 (existing precedent for importing clamp from ./slop)
  • packages/loopover-engine/src/signals/slop.ts:405 (canonical implementation)

Metadata

Metadata

Assignees

No one assigned

    Labels

    gittensor:bugGittensor-scored bug fix — scores a 0.05x multiplier.help wantedExtra attention is needed

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions