Skip to content

REF: trial focused benchmark and approval deduplication - #98

Merged
merefield merged 1 commit into
mainfrom
refactor/benchmark-approval-reuse
Nov 5, 2026
Merged

merefield merged 1 commit into
mainfrom
refactor/benchmark-approval-reuse

Conversation

@merefield

Copy link
Copy Markdown
Owner

Why

Trial a small, behaviour-preserving cleanup based on the new jscpd report, and exercise the main-owned duplication ratchet on a real application PR. Keep the scope deliberately limited to three well-understood repeated implementations rather than pursuing every normalised match.

Changes

  • Benchmark API-EQ accounting: share measurement-to-cost calculation between built-in benchmarks and DigBench. Preserve per-response model attribution/fallback, cached-token pricing, long-context response boundaries, unknown-price rejection and discarding partial cost when any response is unpriced. Built-in benchmarks retain their separate prohibited-tool policy; DigBench's permitted tool use remains supported.
  • Terminal approval rendering: share positioned-button row assembly, retaining each approval type's existing button generation, action renderer, colours, wrapping and click geometry. No changes to approval decisions, confirmation rules or shortcuts.
  • Benchmark presentation resets: share transient run/detail/hover/confirmation resets between starting a run and clearing results. Keep result retention, scope selection, filters, sorting, ranking preferences and caller-specific lifecycle/form behaviour separate.

No changes to rollout-log scanning, DigBench interruption/cleanup, pricing data, UI design, commands, dependencies, version, duplication tooling or baseline. The local released binary is not replaced.

Duplication measurements

Same pinned scanner/policy, comparing this branch with main at 36655ec. Every gated metric is equal or lower; no new production clone candidates are reported.

Scan Clones before → after Duplicated lines before → after Duplicated tokens before → after
exact-50 34 → 31 316 → 285 2,466 → 2,231
renamed-50 152 → 149 1,576 → 1,537 11,451 → 11,175
exact-100 2 → 2 28 → 28 274 → 274
renamed-100 12 → 11 225 → 212 2,043 → 1,928

Maintained production Go is 28 lines smaller. Add 206 lines of regression tests, with no existing tests removed or weakened. These are modest reuse/correctness-maintenance improvements, not a claim of dramatic binary-size or runtime-performance savings. Scanner duplicated-line spans overlap and are not unique removable LOC. Test duplication remains report-only.

Validation

  • New table-driven tests exercise both benchmark runners with explicit expected prices: cached input, observed zero vs unknown telemetry, rerouted and fallback models, raw-response long-context pricing, ambiguous cumulative long-context usage, unknown model/cache-write prices, missing raw usage and repeated progress updates without stale/double-counted cost. Separately verify the built-in tool prohibition does not leak into DigBench.
  • New button tests preserve exact ANSI/wide-character positioning and blank rows, and verify both approval/profile action renderers across all five themes and narrow/wide widths.
  • New start/clear tests check stale detail/cache/hover/confirmation cleanup while retaining preferences and caller-specific history/scope behaviour.
  • Existing targeted benchmark, approval and profile regressions pass.
  • Full race-enabled core suite with coverage passes: go test -race -cover -timeout 10m -skip '^TestLocalisedScreens$' ./....
  • go vet ./... and go build -trimpath ./... pass.
  • make screenshots-check: all seven existing TUI screenshot fixtures are unchanged for v0.27.2.
  • Main's duplication baseline is unchanged; the normal main-only writer will ratchet it after merge and successful CI. Ordinary application PRs do not run a duplicate candidate-checker comparison.

CI retains the complete 17-locale matrix and Linux/macOS/Windows coverage; it is not removed or skipped in the workflow.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain, and the focused deduplication is supported by targeted regression coverage spanning pricing, rendering, lifecycle cleanup, and preference retention.

No open issues 🎉

What changed in this PR

This PR performs focused deduplication across benchmark cost accounting, monitor button rendering, and benchmark presentation resets while preserving existing behavior. It also adds regression coverage for pricing, rendering geometry, lifecycle state, and preference retention.

Changes:

  • Shares API-equivalent cost calculation between built-in benchmarks and DigBench while retaining distinct tool policies.
  • Reuses positioned-button row rendering for approval and profile controls.
  • Centralizes transient benchmark presentation resets for run start and result clearing.
  • Adds targeted regression tests for pricing, telemetry edge cases, UI rendering, and state cleanup.
File Summary
internal/​ui/​monitor_profile.go Reuses shared button-row rendering for profile controls.
internal/​ui/​monitor_buttons_test.go Verifies button positioning, widths, renderers, themes, and terminal widths.
internal/​ui/​monitor_approval.go Provides shared positioned monitor button row assembly.
internal/​ui/​model.go Centralizes transient benchmark presentation resets.
internal/​ui/​benchmark_reset_test.go Verifies reset cleanup while retaining preferences and lifecycle state.
internal/​codex/​digbench.go Reuses shared cost calculation for DigBench results.
internal/​codex/​benchmark.go Adds shared benchmark measurement cost calculation while preserving tool restrictions.
internal/​codex/​benchmark_measurements_test.go Tests pricing parity, telemetry handling, and distinct tool policies.

Review effort: Lite

@merefield
merefield merged commit 7bf69d1 into main Nov 5, 2026
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.

2 participants