uttrflow / uttrflow/uttrflow-swift

Move MLXCandidateScorer's text helpers into a covered file, and test contextNeverCopied

Open
#759 0 comments 0 reactions 0 assignees View on GitHub
area:ai-suggestions enhancement P2
Dominant language
Swift
Stars
4
Forks
17
Avg merge
3h 32m
Merged PRs (30d)
277

Description

## What happens

`Sources/UttrflowLocalModel/MLXCandidateScorer.swift` (689 lines) is excluded from coverage as "downloads gigabytes and runs GPU inference". About half of it is pure text handling that never touches MLX: `contextNeverCopied` (line 235), `trimmed` (246), `joined` (281), `wholeWords` (288), `choice` (412), `tokenBudget` (423), `parse` (452), `echoes` (475), `continuation` (485), `echo` and `repaired` (518, 537), `comparable` (560), `isDegenerate` (577), `unmarked` (585), `typedPart` (642) and `firstScoredIndex` (648).

Most of them are tested (`CompletionParsingTests`, `CompletionParsingPropertyTests`, `PromptTests`, `TokenChoiceTests`, `CandidateScorerSpanTests`), but because the file is excluded none of that counts, and the gate can't tell when one of them loses its test. `contextNeverCopied(in:)`, which decides which screen lines a suggestion may never simply copy, has no test at all (`grep -rn contextNeverCopied Tests` finds nothing).

Measured on origin/main `26d7bc1` with `swift test --enable-code-coverage` (5,384 tests, all passing) and `xcrun llvm-cov export` over the test binary. The regions named below have an execution count of 0: no test runs them, so a change that breaks them passes `make verify`.

## Why it matters

These helpers decide what text an AI suggestion may show: echoes of the typed text removed, degenerate repetition refused (#538), copied context refused. A regression in any of them is visible to the user, and today it's outside the 95% floor. This is the follow-up #641 asks for.

## How to reproduce

`grep -n "static func" Sources/UttrflowLocalModel/MLXCandidateScorer.swift`, and compare with `Scripts/coverage_report.py`'s exclusion for the file.

## Acceptance criteria

- The static text helpers move to a new file in `UttrflowLocalModel` (for example `CompletionText.swift`) that is not excluded. `MLXCandidateScorer` calls them, and behaviour doesn't change.
- Existing tests point at the new type and still pass. The module stays at or above 95% with the moved code counted.
- `contextNeverCopied(in:)` gets tests for a situation with and without screen context, and for lines the typed text already contains.
- The exclusion reason for `MLXCandidateScorer.swift` names only model loading and inference.
- Each new test fails when the branch it covers is broken. Check this by hand before opening the PR: temporarily change the branch (flip the condition or return the other value), see the test fail, then restore it.

Contributor guide

Open the contributing guide

Research direction

Start with Sources/UttrflowLocalModel/MLXCandidateScorer.swift and the exclusion in Scripts/coverage_report.py; identify the listed text helpers and their existing coverage in CompletionParsingTests, CompletionParsingPropertyTests, PromptTests, TokenChoiceTests, and CandidateScorerSpanTests. Add coverage for contextNeverCopied with and without screen context, including already-typed lines. Done means behavior is unchanged, tests pass, and the coverage floor remains at least 95% with only loading and inference excluded.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
testing-qa
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.