Commit Graph

100 Commits

Author SHA1 Message Date
Claudio Ortolina f7f38d580e Enable unaliased modules ex_slop check 2026-04-22 20:37:09 +01:00
Claudio Ortolina 06ae5f8271 Share recent tracks fixture between Last.fm tests 2026-04-19 07:50:15 +01:00
Claudio Ortolina fd6eab82c0 Track fixture files as external resources 2026-04-17 14:02:45 +01:00
Claudio Ortolina 079f2a5f0f Add BraveSearch facade tests 2026-04-17 13:57:36 +01:00
Claudio Ortolina 88906e10ad Add ex_slop, configure it, run it and fix issues 2026-04-12 22:07:27 +01:00
Claudio Ortolina e575f2af9e Stub color extractor in tests
Makes the test suite much faster
2026-03-26 22:58:39 +00:00
Claudio Ortolina d5be6e6182 Remove on tour tracking functionality (source unreliable) 2026-03-24 15:01:16 +00:00
Claudio Ortolina 028f111300 Stabilize rate limiter tests by using dependency injection 2026-03-16 11:21:24 +00:00
Claudio Ortolina abb6a5f8f4 Update dependencies
fluxon 2.3.4 => 2.3.5

Includes a test fix due to some internal changes in Fluxon.
2026-03-15 10:18:07 +00:00
Claudio Ortolina 9e1dbfd530 Re-enable Credo ModuleDoc check
Closes #108
2026-03-13 10:52:01 +00:00
Claudio Ortolina 6a89d31d4c Don't extract dominant colors if provided in params
This as the side effect of massively speeding up the test suite: on M1,
it goes from 24 seconds to 14.
2026-03-07 09:05:44 +00:00
Claudio Ortolina a23f772c04 Re-enable Credo CyclomaticComplexity check 2026-03-06 10:08:25 +00:00
Claudio Ortolina f9b381570f Extract artist infos fixtures 2026-03-06 08:58:59 +00:00
Claudio Ortolina 3819afca4d Extract fixture 2026-03-06 08:53:25 +00:00
Claudio Ortolina 7ec3e68e58 Relax assertions on colors
As dominant colors are not stable on different environments
2026-03-03 16:13:23 +00:00
Claudio Ortolina c7285a2f80 Move more fixtures to compile time 2026-02-16 10:30:14 +00:00
Claudio Ortolina 2f7e2caa3c Cache fixtures 2026-02-16 09:50:10 +00:00
Claudio Ortolina bcae291cff Support getting artist bios from Wikipedia (experimental) 2026-02-09 15:20:06 +00:00
Claudio Ortolina 84159a1c0d Improve test coverage
Files Created (8 files, 54 new tests)

  Fixtures

  1. test/support/fixtures/music_library/record_sets.ex — record_set/1
and record_set_with_records/2 helpers
  2. test/support/fixtures/music_library/online_store_templates.ex —
online_store_template/1 helper

  Context Tests

  3. test/music_library/record_sets_test.exs — 20 tests covering search,
count, CRUD, add/remove/move records
  4. test/music_library/online_store_templates_test.exs — 8 tests
covering list, CRUD, URL generation, validation
  5. test/music_library/search_test.exs — 5 tests covering universal
search and search counts
  6. test/music_library/notes_test.exs — 4 tests covering get, create,
update

  LiveView Tests

  7. test/music_library_web/live/record_set_live/index_test.exs — 11
tests covering listing, empty state, search, ordering,
create/edit/delete sets, remove records, reorder records
  8.
test/music_library_web/live/online_store_template_live/index_test.exs —
6 tests covering listing, create/edit/delete, toggle enabled

  Results

  - 297 tests, 0 failures (up from 243 — 54 new tests added)
  - All existing tests continue to pass

There's a remaining gettext warning that needs to be investigated
2026-02-07 10:39:22 +00:00
Claudio Ortolina 7b697827fd Don't scrobble releases with zero duration 2025-10-23 10:27:08 +01:00
Claudio Ortolina a265f2ae52 Address Credo warnings 2025-09-16 12:57:03 +03:00
Claudio Ortolina dae334b1b7 Scrobbled tracks CRUD
- Failing tests
- Warnings
2025-09-16 12:45:36 +03:00
Claudio Ortolina 6c98b164eb Update more MusicBrainz fixtures 2025-09-15 14:31:55 +03:00
Claudio Ortolina b2283a3e5e Fix fixture path 2025-09-15 14:20:43 +03:00
Claudio Ortolina 2ef4eb2d2e Refresh fixtures 2025-09-15 14:02:53 +03:00
Claudio Ortolina 5aaa7708ee Add tests for On This Day functionality 2025-09-10 17:52:11 +03:00
Claudio Ortolina dc77d337c0 Migrate from embedded covers to assets 2025-09-01 16:20:41 +03:00
Claudio Ortolina 64fdea7e9d Use LazyHTML to escape markup in test 2025-08-05 09:06:58 +03:00
Claudio Ortolina aee08cc2bb Use Enum for scrobble rule type 2025-07-04 14:23:19 +01:00
Claudio Ortolina d91685b646 First rough implementation of scrobble rules (Claude)
This plan outlines the implementation of functionality to manage
arbitrary rules for fixing data in the `scrobbled_tracks` table. The
system will support two types of transformations:

1. **Album Rule**: Update the album MusicBrainz ID of all tracks
belonging to a specific album (identified by album title)
2. **Artist Rule**: Update the artist MusicBrainz ID of all tracks
belonging to a specific artist (identified by artist name)

- `scrobbled_tracks` table exists with the following structure:
  - `scrobbled_at_uts` (integer, primary key)
  - `musicbrainz_id` (string) - track MusicBrainz ID
  - `title` (string) - track title
  - `cover_url` (string)
  - `scrobbled_at_label` (string)
  - `artist` (map) - embedded artist data with `musicbrainz_id` and
`name`
  - `album` (map) - embedded album data with `musicbrainz_id` and
`title`
  - `last_fm_data` (map) - raw Last.fm API response

- `LastFm.Track` - Schema for scrobbled tracks
- `LastFm.Artist` - Embedded artist schema
- `LastFm.Album` - Embedded album schema

- Main navigation has Stats, Collection, Wishlist sections
- "More" dropdown contains development tools and utilities
- Uses Phoenix LiveView for interactive components

**File**:
`priv/repo/migrations/YYYYMMDDHHMMSS_create_scrobble_rules.exs`

Create `scrobble_rules` table with:

- `id` (primary key)
- `type` (string) - "album" or "artist"
- `match_value` (string) - album title or artist name to match
- `target_musicbrainz_id` (string) - MusicBrainz ID to set
- `enabled` (boolean) - whether rule is active
- `description` (text) - optional description for the rule
- `inserted_at` (timestamp)
- `updated_at` (timestamp)

Indexes:

- `type, match_value` (compound index for efficient matching)
- `enabled` (for filtering active rules)

**File**: `lib/music_library/scrobble_rules/scrobble_rule.ex`

Create Ecto schema with:

- Field definitions matching migration
- Validations:
  - `type` must be "album" or "artist"
  - `match_value` required and non-empty
  - `target_musicbrainz_id` required and non-empty
  - `enabled` defaults to true
- Changeset functions for create/update operations

**File**: `lib/music_library/scrobble_rules.ex`

Implement context functions:

- `list_scrobble_rules(opts \\ [])` - list all rules with optional
filtering
- `get_scrobble_rule!(id)` - get specific rule by ID
- `create_scrobble_rule(attrs)` - create new rule
- `update_scrobble_rule(rule, attrs)` - update existing rule
- `delete_scrobble_rule(rule)` - delete rule
- `change_scrobble_rule(rule, attrs \\ %{})` - create changeset
- `list_enabled_rules()` - get only enabled rules for worker
- `apply_album_rule(rule)` - apply album transformation
- `apply_artist_rule(rule)` - apply artist transformation
- `apply_all_rules()` - apply all enabled rules

**File**: `lib/music_library_web/components/layouts/app.html.heex`

Add new navigation link in the "More" dropdown:

- Icon: `hero-adjustments-horizontal`
- Label: "Scrobble Rules"
- Route: `/scrobble-rules`
- Position: After "Oban" link, before separator

**File**: `lib/music_library_web/router.ex`

Add new LiveView routes in the authenticated scope:

- `/scrobble-rules` - index page
- `/scrobble-rules/new` - create new rule
- `/scrobble-rules/:id/edit` - edit existing rule

**File**: `lib/music_library_web/live/scrobble_rules_live/index.ex`

Implement LiveView with:

- List view showing all rules with status indicators
- Create/Edit forms with validation
- Delete confirmation
- Filter controls (by type, enabled/disabled)
- Manual rule application triggers
- Real-time updates via PubSub

**Template**:
`lib/music_library_web/live/scrobble_rules_live/index.html.heex`

- Table layout with rule details
- Action buttons (Edit, Delete, Apply)
- Form components for create/edit
- Status indicators for enabled/disabled rules

**File**:
`lib/music_library_web/live/scrobble_rules_live/form_component.ex`

Create reusable form component:

- Type selection (album/artist)
- Match value input with validation
- Target MusicBrainz ID input
- Description textarea
- Enable/disable toggle
- Save/Cancel actions

Where possible, use the components available at
<https://docs.fluxonui.com/1.1.4/overview.html>.

**File**: `lib/music_library/scrobble_rules/worker.ex`

Implement Oban worker:

- Scheduled to run periodically (e.g., every 30 minutes)
- Fetches all enabled rules
- Applies each rule in sequence
- Logs application results
- Handles errors gracefully
- Tracks last application time

**File**: `test/music_library/scrobble_rules_test.exs`

- Test all context functions
- Test rule application logic
- Test edge cases and error handling

**File**: `test/music_library/scrobble_rules/scrobble_rule_test.exs`

- Test schema validations
- Test changeset functions
- Test constraint validations

**File**: `test/music_library_web/live/scrobble_rules_live_test.exs`

- Test LiveView interactions
- Test form submissions
- Test real-time updates
- Test navigation and routing

**File**: `test/music_library/scrobble_rules/worker_test.exs`

- Test job execution
- Test rule application
- Test error handling
- Test scheduling

- Ensure atomic operations when applying rules
- Validate MusicBrainz IDs before applying
- Log all transformations for audit trail

- Index optimization for rule matching
- Batch processing for large datasets
- Rate limiting for external API calls

- Clear feedback on rule application
- Preview mode to show what would change
- Bulk operations for managing multiple rules
- Export/import functionality for rule sets

- Input validation and sanitization
- Rate limiting on rule creation
- Audit logging for all changes

```sql
-- scrobble_rules table
CREATE TABLE scrobble_rules (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  type TEXT NOT NULL CHECK (type IN ('album', 'artist')),
  match_value TEXT NOT NULL,
  target_musicbrainz_id TEXT NOT NULL,
  enabled BOOLEAN NOT NULL DEFAULT TRUE,
  description TEXT,
  inserted_at TIMESTAMP NOT NULL,
  updated_at TIMESTAMP NOT NULL
);

CREATE INDEX idx_scrobble_rules_type_match ON scrobble_rules(type,
match_value);
CREATE INDEX idx_scrobble_rules_enabled ON scrobble_rules(enabled);
```

```
lib/music_library/
├── scrobble_rules/
│   ├── scrobble_rule.ex          # Schema
│   └── worker.ex                 # Oban worker
└── scrobble_rules.ex             # Context

lib/music_library_web/
└── live/
    └── scrobble_rules_live/
        ├── index.ex              # LiveView
        ├── index.html.heex       # Template
        └── form_component.ex     # Form component

priv/repo/migrations/
└── YYYYMMDDHHMMSS_create_scrobble_rules.exs

test/
├── music_library/
│   ├── scrobble_rules_test.exs
│   └── scrobble_rules/
│       ├── scrobble_rule_test.exs
│       └── worker_test.exs
└── music_library_web/
    └── live/
        └── scrobble_rules_live_test.exs
```

1. Database migration and schema
2. Context module with basic CRUD operations
3. LiveView interface for rule management
4. Navigation and routing updates
5. Periodic worker implementation
6. Comprehensive testing
7. Documentation and deployment

This plan ensures a robust, maintainable solution that integrates
seamlessly with the existing Music Library application architecture.
2025-07-03 16:47:08 +01:00
Claudio Ortolina 07d9db6011 Speed up tests by caching cover data
Suggested and executed by Claude
2025-06-14 21:15:06 +03:00
Claudio Ortolina c5e47cbc8c Display dominant colors from the db 2025-06-07 20:07:23 +01:00
Claudio Ortolina 27c1cc0eda Import artist joinphrase 2025-06-03 18:16:47 +01:00
Claudio Ortolina 676c2e4290 Enable quokka with :module_directives rule 2025-05-28 19:41:57 +01:00
Claudio Ortolina fba621db10 Include artists in get_release 2025-05-04 21:50:23 +01:00
Claudio Ortolina f4fe638a95 Display tracks for records with a selected release 2025-05-04 21:10:40 +01:00
Claudio Ortolina 3e7341d4ca Support choosing a selected release 2025-05-01 17:42:40 +01:00
Claudio Ortolina e083950138 Rename record.release to record.release_date
Includes changes to dependent tables (i.e. the record search index) and
related functions.
2025-05-01 14:04:57 +01:00
Claudio Ortolina ad6e8503ed Add tests around data consistency bg jobs for artist info 2025-04-29 21:05:02 +01:00
Claudio Ortolina fa49e73385 When creating a record, queue a job to fetch artist info 2025-04-29 16:56:22 +01:00
Claudio Ortolina f1dd45e438 Show country flag for artist 2025-04-29 09:58:06 +01:00
Claudio Ortolina 34069636a0 Add tests for Artists.fetch_artist_info/1 2025-04-28 11:04:45 +01:00
Claudio Ortolina 1f43e1d993 Use JSON instead of Jason where possible
In some places, we need pretty printing so it's not possible to remove
the dependency.
2025-03-23 08:34:25 +00:00
Claudio Ortolina 93f6b260b2 Extract test fixture for release_group_releases 2025-03-01 07:40:00 +00:00
Claudio Ortolina a218942110 Remove mox in favour of built-in Req stubs 2025-02-28 16:41:16 +00:00
Claudio Ortolina 3d11cd585d Use built-in Req stub for LastFm tests 2025-02-27 13:43:49 +00:00
Claudio Ortolina 25567eeb26 Extract trigger_hook/3-4 test helper 2025-02-25 14:03:08 +00:00
Claudio Ortolina 7df136c890 Sort aliases 2025-02-20 15:27:01 +00:00
Claudio Ortolina b2daa561d7 Use aliases 2025-02-20 15:27:01 +00:00
Claudio Ortolina 163bbe8902 Add test for importing a record via barcode scan 2025-02-18 20:40:04 +00:00