diff --git a/.pi/orksorksorks/alanvardy-var-1178-complete-icon-turns-green-when-activated/done.md b/.pi/orksorksorks/alanvardy-var-1178-complete-icon-turns-green-when-activated/done.md new file mode 100644 index 00000000..849263fc --- /dev/null +++ b/.pi/orksorksorks/alanvardy-var-1178-complete-icon-turns-green-when-activated/done.md @@ -0,0 +1,7 @@ +# Done + +- **What was built**: The iOS complete toolbar icon's green now lasts exactly as long as the green screen flash. `CompletionFlash.duration` defaults to `CompletionGlow().duration` (0.50 s) instead of `CreationFeedback.displayDuration` (1.0 s). `CreationFeedback.displayDuration` stayed at 1.0 s so the dictation checkmark hold is unchanged; no `SingleThreadCore` change. +- **Commit SHA(s)**: `e3422e9f` (implementation) + artifact commits `small.md`; branch `alanvardy-var-1178-complete-icon-turns-green-when-activated`. +- **Verification**: `make format` clean; `scripts/test-one.sh SingleThreadTests/CompletionFlashTests` → `ok: 4 case(s) ran` (including new `defaultDurationMatchesCompletionGlow` and `dictationCheckmarkDurationStaysOneSecond`). Simulator pinned via `.simulator_id`. +- **Reviewer findings**: No P0/P1 blockers. Two report-only P2 nits: (1) `defaultDurationMatchesCompletionGlow` ties to `CompletionGlow().duration` rather than a literal, so it guards drift from the glow default but not an absolute 0.5 s; (2) the coupling uses a fresh `CompletionGlow()` value rather than `ContentViewModel`'s shared instance — coincides today because both use the class default. Both deferred; neither affects behavior. +- **Remaining manual items**: Full CI gate (`./scripts/test.sh` via the `run-gate` skill) not run here per SMALL staging; on-device/simulator visual confirmation that the icon green and screen flash end together is left to the user. Worker lane timed out (30 min) during the optional `CompletionGlowTests` run before committing, so the implementation commit was made by the parent after re-verification. diff --git a/.pi/orksorksorks/alanvardy-var-1178-complete-icon-turns-green-when-activated/small.md b/.pi/orksorksorks/alanvardy-var-1178-complete-icon-turns-green-when-activated/small.md new file mode 100644 index 00000000..8648daf0 --- /dev/null +++ b/.pi/orksorksorks/alanvardy-var-1178-complete-icon-turns-green-when-activated/small.md @@ -0,0 +1,60 @@ +# Task + +Linear VAR-1178 — "Complete icon turns green when activated." Temporarily turn +the complete icon green when completing a task, lasting **just as long as the +green screen flash**. + +## Current state on this branch + +An earlier commit (`62616b49 feat(complete): tint the complete toolbar item +green on success`) already made the iOS complete toolbar icon turn green: +`SingleThread/ContentView+Toolbar.swift` `completeToolbarLabel` renders +`Label(SharedStrings.completeAction, systemImage: "checkmark.circle.fill")` +with `.foregroundStyle(.green)` when `viewModel.completionFlash.isActive`. + +The remaining gap is **duration**. The icon's green is driven by +`CompletionFlash.duration` (`SingleThread/CompletionFlash.swift`), which +defaults to `CreationFeedback.displayDuration` = **1.0 s** +(`SingleThread/CreationFeedback.swift`). The green screen flash is driven by +`CompletionGlow.duration` = **0.50 s** +(`SingleThreadCore/Sources/SingleThreadCore/CompletionGlow.swift`). So today +the icon stays green roughly twice as long as the flash. + +## What to build + +Make the complete icon's green last the same time as the green screen flash — +i.e. tie `CompletionFlash.duration` (or the value used for the completion-icon +green) to the glow duration (0.50 s), following the same +`trigger → Task.sleep(duration) → isActive = false` pattern the two classes +already share. Keep the change localized to the completion icon's green +duration; do not regress the dictation checkmark's own `CreationFeedback` +timing. + +Note: `completionFlash.trigger()` in `SingleThread/ContentViewModel.swift` runs +unconditionally on success, while the glow is gated by +`showCompletionGlow.isEnabled`; only the duration needs to change here. + +## Why SMALL + +Single app-target UI/timing change (≤~5 files, no `SingleThreadCore` change +required), follows the existing transient-state pattern (A), no unknowns or new +API (B), no schema (C), no new subsystem/shared code (D), no human design +decision (E), and only local test updates (F). + +## Key files + +- `SingleThread/CompletionFlash.swift` — icon green state + `duration` (the + thing to change). +- `SingleThread/CreationFeedback.swift` — `displayDuration = 1.0` currently + used as the flash default. +- `SingleThreadCore/Sources/SingleThreadCore/CompletionGlow.swift` — glow + `duration = 0.50` (source of truth for the flash length). +- `SingleThread/ContentView+Toolbar.swift` (`completeToolbarLabel`, L144–153) + — where the icon is tinted green. +- `SingleThread/ContentViewModel.swift` L191 — `completionFlash.trigger()`. +- `SingleThreadTests/CompletionFlashTests.swift` — update + `defaultDurationMatchesDictationCheckmark` (L43–45) and add an assertion + tying the completion-icon duration to `CompletionGlow.duration`. +- Optional: `SingleThread/ContentView+ActionMenu.swift` `macCompleteButton` + (L117–131) if the macOS icon should tint too — confirm scope; no UI test + currently covers the glow or green tint. diff --git a/SingleThread/AppViewModel.swift b/SingleThread/AppViewModel.swift index 3a0ed4a3..98be8ac0 100644 --- a/SingleThread/AppViewModel.swift +++ b/SingleThread/AppViewModel.swift @@ -206,9 +206,11 @@ final class AppViewModel { speechTranscriber: ReminderDictation(), urlOpener: urlOpener) if ProcessInfo.processInfo.arguments.contains("--ui-testing-glow") { - // UI-test seam: keep the glow visible long enough for a - // deterministic `exists` assertion (production duration is 0.50 s). + // UI-test seam: keep the glow — and the matching toolbar-icon tint — + // visible long enough for deterministic assertions and a pixel probe + // (production duration is 0.50 s). viewModel.completionGlow.duration = 2.0 + viewModel.completionFlash.duration = 2.0 } if ProcessInfo.processInfo.arguments.contains("--ui-testing-reduced-glow") { // UI-test seam: shorten the glow (production duration is 0.50 s) diff --git a/SingleThread/CompletionFlash.swift b/SingleThread/CompletionFlash.swift index 8f266145..95d32768 100644 --- a/SingleThread/CompletionFlash.swift +++ b/SingleThread/CompletionFlash.swift @@ -1,12 +1,12 @@ import Foundation import Observation +import SingleThreadCore /// A transient flag that tints the complete toolbar item green for a moment /// after a successful completion. Mirrors ``SingleThreadCore/CompletionGlow``'s /// trigger / auto-dismiss shape but owns no overlay — the toolbar item reads -/// `isActive` directly. The duration matches the dictation success indicator -/// (``CreationFeedback/displayDuration``) so both confirmations land on the -/// same beat. +/// `isActive` directly. The duration matches the green screen flash +/// (``CompletionGlow``) so the icon and the flash land on the same beat. @MainActor @Observable final class CompletionFlash { @@ -16,8 +16,9 @@ final class CompletionFlash { private(set) var isActive = false /// Seconds the tint stays on. Injectable for tests (e.g. 0.05 s); defaults - /// to the dictation checkmark's on-screen time. - var duration: TimeInterval = CreationFeedback.displayDuration + /// to the green screen flash's on-screen time so the icon's green lasts + /// exactly as long as the flash. + var duration: TimeInterval = CompletionGlow().duration /// Turns the tint on, resetting the auto-dismiss timer if already active. func trigger() { diff --git a/SingleThread/ContentView+Toolbar.swift b/SingleThread/ContentView+Toolbar.swift index bac71431..76c35c23 100644 --- a/SingleThread/ContentView+Toolbar.swift +++ b/SingleThread/ContentView+Toolbar.swift @@ -144,7 +144,11 @@ /// default toolbar tint (kept untouched rather than re-specified). @ViewBuilder private var completeToolbarLabel: some View { if viewModel.completionFlash.isActive { - Label(SharedStrings.completeAction, systemImage: "checkmark.circle.fill") + // A bare `Image`, not a `Label`: a toolbar `Button` supplies the + // tint, so a nested `Label`'s `.foregroundStyle(.green)` is + // dropped and the icon never turns green. Mirrors + // ``dictateToolbarLabel``'s coloured states. + Image(systemName: "checkmark.circle.fill") .foregroundStyle(.green) } else { Label(SharedStrings.completeAction, systemImage: "checkmark.circle.fill") diff --git a/SingleThread/CreationFeedback.swift b/SingleThread/CreationFeedback.swift index b6a36039..b82ddac5 100644 --- a/SingleThread/CreationFeedback.swift +++ b/SingleThread/CreationFeedback.swift @@ -11,9 +11,9 @@ enum CreationFeedback { // MARK: Internal - /// Seconds the success/failure icon stays visible. Shared with the complete - /// toolbar item's green flash (``CompletionFlash``) so both confirmations - /// last the same beat. + /// Seconds the success/failure icon stays visible. Owned by the + /// dictate-and-save flow only — the complete toolbar item's green flash + /// (``CompletionFlash``) instead matches the glow's duration. static let displayDuration: TimeInterval = 1.0 var systemImage: String { diff --git a/SingleThreadTests/CompletionFlashTests.swift b/SingleThreadTests/CompletionFlashTests.swift index 321149a4..0c3e0941 100644 --- a/SingleThreadTests/CompletionFlashTests.swift +++ b/SingleThreadTests/CompletionFlashTests.swift @@ -40,8 +40,13 @@ struct CompletionFlashTests { } @Test - func defaultDurationMatchesDictationCheckmark() { - #expect(CompletionFlash().duration == CreationFeedback.displayDuration) + func defaultDurationMatchesCompletionGlow() { + #expect(CompletionFlash().duration == CompletionGlow().duration) + } + + @Test + func dictationCheckmarkDurationStaysOneSecond() { + #expect(CreationFeedback.displayDuration == 1.0) } } diff --git a/SingleThreadUITests/SingleThreadUITests.swift b/SingleThreadUITests/SingleThreadUITests.swift index e5ac2bef..e4b9fb0c 100644 --- a/SingleThreadUITests/SingleThreadUITests.swift +++ b/SingleThreadUITests/SingleThreadUITests.swift @@ -6,6 +6,9 @@ // import XCTest +#if os(iOS) + import UIKit +#endif final class SingleThreadUITests: XCTestCase { @@ -287,4 +290,107 @@ final class SingleThreadUITests: XCTestCase { XCTAssertTrue(app.staticTexts["Appearance"].waitForExistence(timeout: 5), "Appearance should render from the system locale") } + + /// Regression: the complete toolbar item must render *green* while the + /// completion flash is active. Unit tests cover the `CompletionFlash` + /// state machine, but nothing asserted the colour reached the toolbar — and + /// it did not: a nested `Label`'s `.foregroundStyle` is overridden by the + /// toolbar button's style, so the icon kept its idle tint (the dictate + /// button dodges this by colouring a bare `Image`). This probes the + /// rendered pixels, the only layer where the bug was observable. + /// `--ui-testing-glow` stretches both transient timers to 2 s. + #if os(iOS) + @MainActor + func testCompleteToolbarIconTintsGreen() throws { + let app = XCUIApplication() + app.launchArguments = [ + "--seed", + // Two reminders so the completion leaves the toolbar cluster + // (`showsActionButtons` requires a visible reminder) in place. + // swiftlint:disable:next line_length + "{\"reminders\":[{\"title\":\"Milk\",\"priority\":5},{\"title\":\"Eggs\",\"priority\":1}],\"calendars\":[\"Groceries\"],\"isEntitled\":true}", + "--ui-testing-noop-settle", + "--ui-testing-glow" + ] + app.launch() + + // Assert on the control under test, not a title: the seed's + // priority-5 "Milk" sorts behind the priority-1 "Eggs", so the + // first card is Eggs and a title assertion would chase the wrong + // reminder. The button's presence proves the seeded card loaded. + let complete = app.buttons["completeButton"] + XCTAssertTrue( + complete.waitForExistence(timeout: 5), + "Complete toolbar item should render") + let iconFrame = complete.frame + complete.tap() + + // The flash is stretched to 2 s under --ui-testing-glow; poll while + // it is active so a slow screenshot can't race the tint. + let deadline = Date().addingTimeInterval(2.5) + var sawGreen = false + while Date() < deadline { + if containsSaturatedGreen( + XCUIScreen.main.screenshot(), + in: iconFrame) { + sawGreen = true + break + } + } + XCTAssertTrue( + sawGreen, + "Complete toolbar icon should render green while the completion flash is active") + } + + /// Whether `region` (screen points) of `screenshot` holds a run of + /// saturated-green pixels. The 10 % glow wash sits well below the + /// threshold, so only the icon's own green trips it. Scanning the whole + /// crop makes the drawn buffer's row order irrelevant. + private func containsSaturatedGreen( + _ screenshot: XCUIScreenshot, + in region: CGRect) -> Bool { + let uiImage = screenshot.image + guard let image = uiImage.cgImage else { return false } + let scale = CGFloat(image.width) / uiImage.size.width + let pixelRegion = CGRect( + x: region.minX * scale, + y: region.minY * scale, + width: region.width * scale, + height: region.height * scale) + .intersection(CGRect(x: 0, y: 0, width: image.width, height: image.height)) + guard pixelRegion.width >= 1, pixelRegion.height >= 1, + let crop = image.cropping(to: pixelRegion) + else { return false } + + let width = crop.width + let height = crop.height + var pixels = [UInt8](repeating: 0, count: width * height * 4) + let drew = pixels.withUnsafeMutableBytes { buffer -> Bool in + guard let context = CGContext( + data: buffer.baseAddress, + width: width, + height: height, + bitsPerComponent: 8, + bytesPerRow: width * 4, + space: CGColorSpaceCreateDeviceRGB(), + bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue) + else { return false } + context.draw(crop, in: CGRect(x: 0, y: 0, width: width, height: height)) + return true + } + guard drew else { return false } + + var greenCount = 0 + for index in stride(from: 0, to: pixels.count, by: 4) { + let red = Int(pixels[index]) + let green = Int(pixels[index + 1]) + let blue = Int(pixels[index + 2]) + if green > 120, green - red > 60, green - blue > 60 { + greenCount += 1 + if greenCount >= 40 { return true } + } + } + return false + } + #endif }