Skip to content

refactor: split capture flow into focused modules and harden mask failures#155

Merged
neonwatty merged 2 commits into
mainfrom
feat/redaction-architecture
May 11, 2026
Merged

refactor: split capture flow into focused modules and harden mask failures#155
neonwatty merged 2 commits into
mainfrom
feat/redaction-architecture

Conversation

@neonwatty
Copy link
Copy Markdown
Collaborator

Summary

  • Extracts the screenshot/redaction pipeline from src/widget/index.ts into four focused modules (screenshot-options, capture-loading, annotation-flow, capture-flow); index.ts loses ~450 lines of capture/annotation flow.
  • Converts mixed string/object unions to discriminated unions (ScreenshotChoice, CaptureWithLoadingResult, internal ChosenCaptureResult) with exhaustiveness checks, eliminating overloaded null semantics and illegal {screenshot, returnToForm: true} states.
  • Adds a MaskApplicationError class and a distinct "Privacy masking failed" modal so a mask failure no longer masquerades as a generic capture failure where the user might click "Skip Screenshot" and silently submit without an image.
  • New redactionNoteHtml helper in ui.ts collapses four near-identical inline-styled HTML strings across two modules.
  • Adds unit coverage for the four returnToForm: true cancel paths (screenshot-options cancel, capture-loading cancel, annotation cancel) and the native-viewport redactionUnavailable flag — previously these branches were only exercised by E2E.
  • New public/test/masking-layout-edge.html fixture + E2E tests asserting transformed / sticky / fixed redaction targets stay masked after scrolling.

Pre-PR review gate run: code-reviewer, pr-test-analyzer, code-simplifier, silent-failure-hunter, and type-design-analyzer dispatched in parallel against the staged diff; critical and type-design findings have been addressed.

Test plan

  • npm run lint — 0 errors (24 pre-existing warnings)
  • npm run build (tsc + widget tsconfig) — clean
  • npm run build:widget — 82.7 kB bundle
  • npm test — 204/204 unit tests pass (was 200; +4 cancel-path and viewport tests)
  • E2E (CI) — exercises full-page, area, element, viewport, and masking-layout-edge fixture
  • Live preview tests (CI)

…lures

Extract the screenshot/redaction pipeline from src/widget/index.ts into
four focused modules: screenshot-options, capture-loading, annotation-flow,
and capture-flow. Adds new public/test fixture and unit coverage.

Type design:
- ScreenshotChoice is now a discriminated union with consistent `kind`
  tags and an exhaustiveness check at the call site.
- CaptureWithLoadingResult is { kind: 'ok' | 'skipped' | 'cancelled' }
  so callers stop overloading `null`.
- Internal ChosenCaptureResult is { captured | empty | returnToForm },
  removing illegal-state combinations (e.g. screenshot + returnToForm).

Mask failure safety:
- New MaskApplicationError class is thrown from canvas/image failures
  inside applyMaskToImage so callers can distinguish them from raw
  capture errors.
- capture-loading shows a distinct "Privacy masking failed" modal that
  refuses to retry and only offers Skip / Cancel — previously a mask
  failure was indistinguishable from a generic capture failure and a
  "Skip Screenshot" click could silently submit with no image while
  the user thought capture had failed.

UI helper:
- redactionNoteHtml in ui.ts replaces four near-identical inline-styled
  HTML strings across screenshot-options and annotation-flow.
@neonwatty neonwatty force-pushed the feat/redaction-architecture branch from 9ab2ace to aa0eef5 Compare May 11, 2026 22:24
@neonwatty neonwatty added this pull request to the merge queue May 11, 2026
Merged via the queue into main with commit a321881 May 11, 2026
6 checks passed
@neonwatty neonwatty deleted the feat/redaction-architecture branch May 11, 2026 22:47
@github-actions
Copy link
Copy Markdown

🎉 This PR is included in version 1.33.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant