uttrflow / uttrflow/uttrflow-swift
Test the AI suggestion prompt trimming a long text, a first line that alone overflows, and whitespace-only screen lines
- Dominant language
- Swift
- Stars
- 4
- Forks
- 17
- Avg merge
- 3h 32m
- Merged PRs (30d)
- 277
Description
## What happens
`Sources/UttrflowLocalModel/PromptBuilder.swift` keeps the suggestion prompt inside its token budget. These have never run:
- line 204: `leading(_:within:)` when the text is already over the allowance. The binary search below it only runs for such a text, so every test used a text that already fit;
- line 227: `newest(_:within:)` when even the first line doesn't fit and `leading` cuts it to nothing;
- line 241: `nearestLines(_:within:)` trimming trailing whitespace from a screen line.
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
The budget is what keeps a suggestion fast on an 8 GB Mac. If `leading` stops trimming, one long pasted paragraph sends the whole text to the model on every keystroke. If the empty-cut case returns `[""]` instead of `[]`, the prompt gains a blank line that shifts the model's answer.
## How to reproduce
Run `swift test --enable-code-coverage`, then `xcrun llvm-cov show -instr-profile .build/debug/codecov/default.profdata .build/debug/UttrflowPackageTests.xctest/Contents/MacOS/UttrflowPackageTests Sources/UttrflowLocalModel/PromptBuilder.swift` and look for the `0` counts on the lines named above.
## Acceptance criteria
- `PromptBuilder.leading(, within: 20)` returns a prefix whose `estimatedTokens` is at most 20, and which is the longest such prefix.
- `newest([], within: 2)` is `[]` when the cut is empty, and a single cut line otherwise.
- `nearestLines("Reply \nReply\n", within: 50)` keeps "Reply" once, with no trailing spaces.
- 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.
## Where to start
- `Tests/UttrflowLocalModelTests/PromptTests.swift` (suite "The generation prompt") and `PromptPropertyTests.swift`, whose seeded generator suits the "longest prefix" property.
Read `CONTRIBUTING.md` first. Iterate with `swift test --filter `, then run `make verify` before pushing. Only tests change; no product code needs to.
**Size:** S.
Contributor guide
Research direction
Read CONTRIBUTING.md, then inspect the generation-prompt suite in Tests/UttrflowLocalModelTests/PromptTests.swift and the seeded generator in PromptPropertyTests.swift. Add tests covering the three named PromptBuilder branches and run them with swift test --filter . Done means each test detects its targeted branch change and make verify passes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- macos, swift
- Domain
- testing-qa
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 91/100