Skip to content

test(ci): add Swift CoreTests, Node reader/sanitizer tests, and strict CI checks - #5

Merged
willtmc merged 1 commit into
mainfrom
test/swift-and-js-unit-tests
Nov 25, 2026
Merged

willtmc merged 1 commit into
mainfrom
test/swift-and-js-unit-tests

Conversation

@willtmc

@willtmc willtmc commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Summary

Adds zero-dependency Swift and Node.js unit test suites, a unified ./scripts/test.sh test runner, and strict Swift concurrency checks in GitHub Actions CI.

Changes

  • tests/CoreTests.swift (new): Standalone Swift test executable compiled directly against Core.swift with -swift-version 5 -warn-concurrency -warnings-as-errors (140 assertions):
    • normalizeURL: valid http/https, bare domains, punycode TLDs, localhost + port, IPv4/IPv6 literals, and rejection of typos, whitespace, invalid ports/IPs, and non-HTTP schemes (javascript:, file:, data:, mailto:, ftp:).
    • parseLaunchURL: skips macOS defaults flag pairs (-AppleLanguages en, -NSDocumentRevisionsDebugMode YES, -psn_*, -k=v), handles --, and extracts valid URLs.
    • isAllowedExternalURL: permits http/https/mailto and blocks file:, shortcuts:, smb:, ssh:, javascript:, data:, tel:, and empty-host/specifier URLs.
    • matchesExpectedReaderURL: validates about:blank, exact/root-path/case-insensitive/fragment matches, and rejects mismatched scheme/host/port/path/query.
    • readwiseEndpointURL, readwiseUpdateURL, readwiseReaderBaseURL: safe query encoding, percent-encoded docID, and traversal/delimiter rejection (/, \\, .., ?, #).
    • slimDoc: preserves readable top-level article/email/rss fields, drops NSNull and extra fields, and rejects child docs and non-readable categories.
    • jsonLiteral: escapes </script>, quotes/backslashes, and \u2028/\u2029 line separators with round-trip verification.
    • themeWindowAppearance: Paper (#fbf9f4), Sepia (#f3ead6), Dark (#161616), case-insensitivity, and nil/unknown fallback.
  • tests/reader.test.mjs (new): Zero-dependency node:test + node:assert/strict suite (7 tests):
    • Syntax checks (vm.Script) for Resources/extract.js, Resources/Readability.js, and the inline <script> in Resources/reader.html.
    • Verifies Resources/Readability.js @mozilla/readability v0.6.0 header and executes _getJSONLD against a @graph JSON-LD document to verify the arrow-function this.REGEXPS fix.
    • Verifies WCAG AA contrast ratios across Paper, Sepia, and Dark themes (>= 4.5:1 for fg, muted, link, err vs --bg and input surface; >= 3.0:1 for border).
    • Verifies Resources/reader.html structural & a11y invariants (overflow: clip, <main>, <article>, role="tablist", role="dialog", aria-live="polite", prefers-reduced-motion, twoup-end, window.twoupZoom, D.focusUrl, D.dir).
    • Executes the verbatim sanitize() implementation from Resources/reader.html against XSS/clobbering/URL-smuggling vectors (<script>, #end/#status IDs, <base>, <svg><a xlink:href>, control-char javascript:, data:image/svg+xml, srcset) and verifies safe https:, mailto:, #hash, resolved relative URLs, and data:image/png preservation.
    • Executes Resources/extract.js (__twoupExtract) verifying #hash anchor preservation (both configurable and non-configurable documentURI), lazy <picture><source data-srcset> promotion + placeholder <img> fallback, and dir: "rtl" passthrough.
  • scripts/test.sh (new, executable): Runs bash -n, shellcheck -S error (when installed), plutil -lint Info.plist, strict -warn-concurrency -warnings-as-errors typechecks on Core.swift main.swift and make_icon.swift, compiles & runs tests/CoreTests.swift in a mktemp binary cleaned up on exit, and runs node --test tests/reader.test.mjs.
  • .github/workflows/ci.yml (updated): Runs ./scripts/test.sh, ./build.sh --build-only, codesign --verify --deep --strict build/TwoUp.app, and verifies TwoUp.icns.

No production files were modified.

Verification

  • ./scripts/test.sh: passed (CoreTests: 140 passed, 0 failed; reader.test.mjs: 7 passed, 0 failed; shellcheck, plutil, strict Swift concurrency typechecks all clean)
  • ./build.sh --build-only && codesign --verify --deep --strict build/TwoUp.app && test -s build/TwoUp.app/Contents/Resources/TwoUp.icns: passed

@willtmc
willtmc merged commit 2fa6694 into main Nov 25, 2026
1 check passed
@willtmc
willtmc deleted the test/swift-and-js-unit-tests branch November 25, 2026 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant