uttrflow / uttrflow/uttrflow-swift

Move SuggestionCoordinator's snapshot-to-situation mapping into a covered type

Open
#760 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/Uttrflow/Suggestion/SuggestionCoordinator.swift` (770 lines) is excluded as "wiring only". Three private functions in it are pure mappings from a `FocusedFieldSnapshot` to what the model and the capture store see:

- `situation(...)` (line 556): the `GenerationSituation` handed to the model;
- `reading(of:)` (line 752): the `FieldReading` used for capture refusals and corpus grouping;
- `context(of:at:)` (line 762): the `PredictionContext`.

No test reaches them, and the exclusion reason says every rule is `SuggestionSession`, which isn't true of these.

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

`reading(of:)` decides the bundle identifier, role and secure-field flag that `CaptureGate` refuses on (#644, #668). A mistake there, such as dropping the subrole, makes a password field look like an ordinary one to the refusal rules that are tested. `situation` decides which screen text reaches the model.

## How to reproduce

Read `SuggestionCoordinator.swift:556-577` and `:752-770`, and run `grep -rn "FieldReading(" Tests/UttrflowTests`.

## Acceptance criteria

- The three mappings become internal static functions on a type in a covered module (for example beside `FocusedFieldSnapshot` in `UttrflowContext`, or in `UttrflowPredictCapture`), taking a snapshot and returning a value.
- Tests assert that a secure snapshot produces a secure `FieldReading`, that the bundle identifier is passed through with its case unchanged, and that the situation contains the preceding text and screen lines the snapshot holds.
- The exclusion reason for `SuggestionCoordinator.swift` stays accurate.
- 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

Read Sources/Uttrflow/Suggestion/SuggestionCoordinator.swift:556-577 and :752-770, then run grep -rn "FieldReading(" Tests/UttrflowTests. Move the three mappings to a covered type and add tests under Tests/UttrflowTests for secure fields, unchanged bundle identifiers, and snapshot text; verify each test fails when its mapped branch is temporarily broken.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
desktop, testing
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.