Skip to content

refactor(scraper): Phase 4 — cross-cutting CancellationToken propagation#737

Merged
astar-development-jb merged 2 commits into
mainfrom
feature/scraper-phase4-cancellation-tokens
Jul 12, 2026
Merged

refactor(scraper): Phase 4 — cross-cutting CancellationToken propagation#737
astar-development-jb merged 2 commits into
mainfrom
feature/scraper-phase4-cancellation-tokens

Conversation

@jbarden

@jbarden jbarden commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Summary

Implements Phase 4 (cross-cutting items 13–14) of docs/astar-dev-wallpaper-scraper/code-review-2026-07-10.v2.md:

  • Item 13 — CancellationToken propagation. The repositories already accepted and propagated tokens after Phases 1–2; this closes the remaining gaps:
    • ConfigurationSaver.SaveUpdatedConfigurationAsync now requires a CancellationToken and passes it to CreateDbContextAsync, SingleAsync, and SaveChangesAsync, using the token-aware Try.RunAsync(operation, cancellationToken) overload. All four call sites (PagedScrapeRunner, SearchWorkflow, TopWallpapersWorkflow, SubscriptionsWorkflow) forward their workflow token.
    • DataSeed.SeedTagsToIgnoreAsync / SeedScrapeConfigurationAsync / SeedFileClassificationsAsync accept and propagate a token (SaveChangesAsync, File.ReadAllLinesAsync).
    • DatabaseInitializationService.InitialiseAsync(CancellationToken = default) propagates to CreateDbContextAsync, MigrateAsync, and the seed calls; also switches from sync CreateDbContext() to CreateDbContextAsync.
  • Item 14 — per-section configuration update methods: already implemented in Phase 3 (ScrapeConfigurationService.UpdateConnectionStrings / UpdateUserConfiguration / UpdateSearchConfiguration / UpdateScrapeDirectories / UpsertSearchCategories); verified, no change needed.

Out of scope, flagged for follow-up: ScrapeConfigurationViewModel (UI layer; long-lived context, underscore-prefixed fields) and MainWindow.axaml.cs CancellationToken.None in UI event handlers.

Type of change

  • Feature
  • Bug fix
  • Refactor
  • CI/CD
  • Documentation
  • Maintenance

Related issues / links

Closes #736. Follows #735 (Phase 3), #730/#728/#727/#726 (Phase 2), #721 (Phase 1).

How was this tested?

  • Unit tests added/updated
  • Manual validation
  • Not applicable

Failing tests committed first (TDD), then production code. New tests: token-passed-to-factory and cancelled-token behaviour for ConfigurationSaver, DataSeed (all three seed methods), and DatabaseInitializationService.

dotnet clean && dotnet build --no-restore: 0 errors. 8 warnings, all pre-existing on main (NU1903 vulnerable SQLitePCLRaw.lib.e_sqlite3 in spikes/, AVLN3001 Avalonia XAML resources) — none in the changed projects.

dotnet test --no-build: 3,176 total, 0 failed, 1 skipped (pre-existing skip in AStar.Dev.Utilities.Tests.Unit). Scraper unit project: 448 passed, 0 failed (7 new tests).

Impacted areas

apps/desktop/Scraper/AStar.Dev.Wallpaper.Scraper, apps/desktop/Scraper/AStar.Dev.Wallpaper.Scraper.Tests.Unit


TDD Checklist (required)

  • Builds locally
  • Tests pass (dotnet test)
  • No new analyzer warnings
  • Public API changes reviewed
  • Documentation updated (if applicable)
  • Not applicable

How to run tests locally

# Restore and run tests
dotnet restore AStar.Dev.slnx
dotnet test --verbosity normal

Notes for reviewers

  • Ensure CI passed for all OS runners where configured.
  • SaveUpdatedConfigurationAsync token parameter is required (no default) so future call sites must propagate; InitialiseAsync keeps = default because the app-startup caller has no token source.
  • With a cancelled token, Try.RunAsync rethrows OperationCanceledException rather than converting it to a Fail result — this matches the documented behaviour of the token-aware overload.

🤖 Generated with Claude Code

jbarden and others added 2 commits July 12, 2026 04:48
#736)

ConfigurationSaver, DataSeed, and DatabaseInitializationService must accept
and propagate a CancellationToken.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…igurationSaver, DataSeed, and DatabaseInitializationService (#736)

ConfigurationSaver.SaveUpdatedConfigurationAsync now requires a token and
passes it to CreateDbContextAsync, SingleAsync, and SaveChangesAsync via the
token-aware Try.RunAsync overload. All four call sites (PagedScrapeRunner,
SearchWorkflow, TopWallpapersWorkflow, SubscriptionsWorkflow) forward their
workflow token. DataSeed methods and DatabaseInitializationService.InitialiseAsync
accept and propagate tokens, and initialisation now uses CreateDbContextAsync.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Test results

3 149 tests   - 20   3 147 ✅  - 21   1m 4s ⏱️ - 1m 12s
   12 suites  -  1       1 💤 ± 0 
   12 files    -  1       1 ❌ + 1 

For more details on these failures, see this check.

Results for commit 91aeee8. ± Comparison against base commit 83beb20.

This pull request removes 27 and adds 7 tests. Note that renamed tests count towards both.
AStar.Dev.OneDrive.Sync.Client.Tests.Integration.Data.GivenSyncedItemRepository_WhenSearchingForDuplicates ‑ when_duplicates_exist_for_one_account_they_do_not_appear_in_another_accounts_results
AStar.Dev.OneDrive.Sync.Client.Tests.Integration.Data.GivenSyncedItemRepository_WhenSearchingForDuplicates ‑ when_files_have_same_name_but_different_sizes_then_not_returned
AStar.Dev.OneDrive.Sync.Client.Tests.Integration.Data.GivenSyncedItemRepository_WhenSearchingForDuplicates ‑ when_files_have_same_size_but_different_names_then_not_returned
AStar.Dev.OneDrive.Sync.Client.Tests.Integration.Data.GivenSyncedItemRepository_WhenSearchingForDuplicates ‑ when_files_share_size_and_filename_then_both_are_returned
AStar.Dev.OneDrive.Sync.Client.Tests.Integration.Data.GivenSyncedItemRepository_WhenSearchingForDuplicates ‑ when_folders_share_size_and_name_they_are_excluded_from_duplicate_detection
AStar.Dev.OneDrive.Sync.Client.Tests.Integration.Data.GivenSyncedItemRepository_WhenSearchingForDuplicates ‑ when_items_have_null_size_they_are_excluded_from_duplicate_detection
AStar.Dev.OneDrive.Sync.Client.Tests.Integration.Data.GivenSyncedItemRepository_WhenSearchingForDuplicates ‑ when_no_duplicate_files_exist_then_returns_empty_list
AStar.Dev.OneDrive.Sync.Client.Tests.Integration.Data.GivenSyncedItemRepository_WhenSearchingForDuplicates ‑ when_three_files_share_size_and_name_then_all_three_are_returned
AStar.Dev.OneDrive.Sync.Client.Tests.Integration.Data.GivenTheMigrationDropFileClassificationRulesTable ‑ when_all_migrations_are_applied_then_file_classification_rules_table_does_not_exist
AStar.Dev.OneDrive.Sync.Client.Tests.Integration.FileClassification.GivenFileAutoCategorisor ‑ when_path_contains_documents_token_then_result_is_none
…
AStar.Dev.Wallpaper.Scraper.Tests.Unit.Services.GivenADatabaseInitializationService ‑ when_initialising_with_a_cancellation_token_then_the_token_is_passed_to_the_context_factory
AStar.Dev.Wallpaper.Scraper.Tests.Unit.Services.GivenADatabaseInitializationService ‑ when_initialising_with_a_cancelled_token_then_an_operation_canceled_exception_is_thrown
AStar.Dev.Wallpaper.Scraper.Tests.Unit.Services.GivenDataSeed ‑ when_seeding_file_classifications_with_a_cancelled_token_then_an_operation_canceled_exception_is_thrown
AStar.Dev.Wallpaper.Scraper.Tests.Unit.Services.GivenDataSeed ‑ when_seeding_scrape_configuration_with_a_cancelled_token_then_an_operation_canceled_exception_is_thrown
AStar.Dev.Wallpaper.Scraper.Tests.Unit.Services.GivenDataSeed ‑ when_seeding_tags_to_ignore_with_a_cancelled_token_then_an_operation_canceled_exception_is_thrown
AStar.Dev.Wallpaper.Scraper.Tests.Unit.Support.GivenAConfigurationSaver ‑ when_saving_with_a_cancellation_token_then_the_token_is_passed_to_the_context_factory
AStar.Dev.Wallpaper.Scraper.Tests.Unit.Support.GivenAConfigurationSaver ‑ when_saving_with_a_cancelled_token_then_an_operation_canceled_exception_is_thrown

@astar-development-jb
astar-development-jb enabled auto-merge (squash) July 12, 2026 03:59
@astar-development-jb
astar-development-jb merged commit a40a208 into main Jul 12, 2026
5 of 7 checks passed
@astar-development-jb
astar-development-jb deleted the feature/scraper-phase4-cancellation-tokens branch July 12, 2026 04:00
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.

refactor(scraper): Phase 4 — cross-cutting CancellationToken propagation

2 participants