Skip to content

Conversation

@kugaevsky
Copy link

@kugaevsky kugaevsky commented Oct 19, 2025

✨ Summary

This PR improves User-Agent data extraction, test performance, and fixture handling in device_detector.
It introduces browser engine detection, parallelized RSpec, and a cleaner, modular test architecture.

🧠 What’s Changed

🔧 Bugfixes

  • Fix regexes path to absolute ones in order to remove regex loading problem when gem works like a gem

🕵️ User-Agent Data Extraction

  • Added detection of browser family, engine and engine version
  • Improved parser behavior for version comparison and error resilience
  • Cleaned up duplicated parsing logic in DeviceDetector::Parser

⚡ Test Performance

  • Added parallel_tests gem to enable multi-core RSpec execution
  • Enabled progress and failure logging
  • Split large monolithic specs into smaller, parallel-friendly groups

🧩 Code Structure

  • Extracted shared detector logic into reusable examples
  • Added FixtureNormalizerHelper for consistent fixture structure
  • Refactored FixturesLoaderHelper with smarter path resolution and caching
  • Removed unused fields (short_name, redundant attributes) from test fixtures

🧪 Test Consistency

  • Unified expectations across OS, device, and client detectors
  • Rewrote fixture normalization to handle missing keys and edge cases
  • Simplified duplicate tests into shared examples for better maintainability
  • Expanded RSpec coverage for cache reset and fixture reloading behavior

🧰 Developer Experience

  • Cleaner RSpec output (progress + failures)
  • Easier debugging via tmp/failing_specs.log
  • Consistent YAML fixture normalization, improving contribution safety
  • Introduced DeviceDetector.reset_cache! for global cache reinitialization
  • Implemented .add_fixture_path and .reset_custom_fixtures! for dynamic fixture loading in parsers

* restructured RSpec tests for DeviceDetector with subject, let, and context;
* replaced explicit class instantiations with described_class.new;
* extracted utility logic into new helpers (ConditionalHelper, MatcherHelper);
* cleaned up spec_helper.rb, auto-requiring all files under spec/support;
* improved fixture specs and test isolation.
* added FixturesLoaderHelper with YAML-to-JSON caching via Oj for faster spec runs;
* integrated caching and helper loading into spec_helper.rb with bootsnap setup;
* removed redundant require_relative statements from specs;
* added development dependencies (bootsnap, oj, rubocop-rspec) and new RSpec task in Rakefile;
* cleaned up .gitignore and deleted outdated bot_spec.rb.
* added engine and engine_version parsing based on browser_engine.yml
* implemented build_engine_version with regex-based UA extraction
* updated specs to validate engine name, version, and family
* improved DeviceDetector::Parser for safer version comparison
* refactored helper methods and cleaned up duplicated logic
* update fixtures
* update regexes
* switch update fixtures & regexes rake tasks to revision instead of branch
* enabled parallel test execution with parallel_tests
* extracted shared detector examples into a reusable module
* split detector fixture specs into multiple smaller files for parallel runs
* introduced FixtureNormalizerHelper for consistent fixture key/value normalization
* fix regexes path to absolute ones
* moved parser class registration to a class-level constant

improved and expanded RSpec coverage for class-level methods
- introduced `DeviceDetector.reset_cache!` for global cache reinitialization
- added MemoryCache#purge! to fully clear in-memory cache contents
- implemented `.add_fixture_path and `.reset_custom_fixtures!` for dynamic fixture loading in parsers
- refactored regex loading to merge multiple fixture sources safely
- expanded RSpec coverage for cache reset and fixture reloading behavior
- update fixtures to last revision of Matomo repo
- fix path to custom regex file in tests
@kugaevsky
Copy link
Author

@matisojka @benzimmer any comments?

@iagooar
Copy link
Contributor

iagooar commented Nov 7, 2025

I think @spiderpug is the guy to look into this!

@benzimmer benzimmer self-assigned this Nov 10, 2025
@benzimmer benzimmer self-requested a review November 10, 2025 14:15
@benzimmer
Copy link
Contributor

@kugaevsky Hey Nick, thanks for the PR. It's really hard to review to be honest. Would it be possible to split the different topics into smaller PRs that we can check independently?
That said, I think you can leave out the parallel specs part, since I don't think that 10-15% speed improvement is worth the code changes it requires.

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.

3 participants