From 493ded8c7619db787d5c405457dded6ee5028c1f Mon Sep 17 00:00:00 2001 From: Jakub Rozmiarek Date: Mon, 12 Jan 2026 10:29:15 +0100 Subject: [PATCH 1/6] Set cookie to ensure current_store is correctly selected. --- apps/rails_application/test/test_helper.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/rails_application/test/test_helper.rb b/apps/rails_application/test/test_helper.rb index 5f5bfb79..1bbc3e48 100644 --- a/apps/rails_application/test/test_helper.rb +++ b/apps/rails_application/test/test_helper.rb @@ -142,6 +142,7 @@ def before_setup Configuration.new.call(Rails.configuration.event_store, Rails.configuration.command_bus) @default_store_id = ensure_default_store + cookies[:current_store_id] = @default_store_id result end From e6f51f85f82444ad05212a169010e51f61b94fce Mon Sep 17 00:00:00 2001 From: Jakub Rozmiarek Date: Mon, 12 Jan 2026 11:15:21 +0100 Subject: [PATCH 2/6] Addeed spec to make sure filtering by store_id does work and to kill corresponding mutant. --- .../invoices/assign_store_to_invoice_test.rb | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/apps/rails_application/test/invoices/assign_store_to_invoice_test.rb b/apps/rails_application/test/invoices/assign_store_to_invoice_test.rb index 439deb91..4768a44b 100644 --- a/apps/rails_application/test/invoices/assign_store_to_invoice_test.rb +++ b/apps/rails_application/test/invoices/assign_store_to_invoice_test.rb @@ -91,5 +91,37 @@ def test_assigns_store_to_correct_invoice_when_multiple_invoices_exist assert_equal(store_id_1, invoice_1.store_id) assert_equal(store_id_2, invoice_2.store_id) end + + def test_returns_nil_when_invoice_exists_in_different_store + event_store = Rails.configuration.event_store + store_id_1 = SecureRandom.uuid + store_id_2 = SecureRandom.uuid + invoice_id = SecureRandom.uuid + + event_store.publish( + Invoicing::InvoiceItemAdded.new( + data: { + invoice_id: invoice_id, + product_id: SecureRandom.uuid, + title: "Test Product", + quantity: 1, + unit_price: 100, + vat_rate: { rate: 20, code: "VAT" } + } + ) + ) + + event_store.publish( + Stores::InvoiceRegistered.new( + data: { + store_id: store_id_1, + invoice_id: invoice_id + } + ) + ) + + assert_nil Invoices.find_invoice_in_store(invoice_id, store_id_2) + assert_not_nil Invoices.find_invoice_in_store(invoice_id, store_id_1) + end end end From 4f3c7cc09c053ae9bc540afb8790aa264e5148c9 Mon Sep 17 00:00:00 2001 From: Jakub Rozmiarek Date: Mon, 12 Jan 2026 12:16:12 +0100 Subject: [PATCH 3/6] Trigger full coverage mutation to test the fix. --- .github/workflows/rails_application-coverage.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/rails_application-coverage.yml b/.github/workflows/rails_application-coverage.yml index 8f2ea509..db709583 100644 --- a/.github/workflows/rails_application-coverage.yml +++ b/.github/workflows/rails_application-coverage.yml @@ -14,6 +14,7 @@ on: paths: - "apps/rails_application/Gemfile.lock" - ".github/workflows/rails_application-coverage.yml" + - "apps/rails_application/test/test_helper.rb" schedule: - cron: '0 17 * * *' jobs: From f7d620f9cf17961ad52f9aea9b8bde9683d069d1 Mon Sep 17 00:00:00 2001 From: Jakub Rozmiarek Date: Fri, 16 Jan 2026 11:51:40 +0100 Subject: [PATCH 4/6] Prepare test db before running full mutation test that include integration tests. --- .github/workflows/rails_application-coverage.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/rails_application-coverage.yml b/.github/workflows/rails_application-coverage.yml index db709583..5f69e8b2 100644 --- a/.github/workflows/rails_application-coverage.yml +++ b/.github/workflows/rails_application-coverage.yml @@ -60,6 +60,12 @@ jobs: ruby-version: ruby-3.4.6 bundler-cache: true working-directory: apps/rails_application + - name: Prepare test database + run: bin/rails db:test:prepare + working-directory: apps/rails_application + env: + DATABASE_URL: "postgres://postgres:secret@localhost:5432/cqrs-es-sample-with-res_test" + RAILS_ENV: test - name: Run full mutation testing run: make -C apps/rails_application mutate env: From dc6affb1896b75b9daa655b19088bb592320b51c Mon Sep 17 00:00:00 2001 From: Jakub Rozmiarek Date: Fri, 16 Jan 2026 12:43:53 +0100 Subject: [PATCH 5/6] Prepare test db before running full mutation test to prevent using development db. --- apps/rails_application/Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/rails_application/Makefile b/apps/rails_application/Makefile index 3898e74f..f5212855 100644 --- a/apps/rails_application/Makefile +++ b/apps/rails_application/Makefile @@ -7,6 +7,8 @@ dev: @$(MAKE) -j 2 web css mutate: ## Run full mutation tests + @echo "Preparing test database..." + @RAILS_ENV=test bin/rails db:test:prepare @echo "Running full mutation tests..." @RAILS_ENV=test bundle exec mutant run From a759ddc9dfcc5a4027f55731079a651ad0d6b328 Mon Sep 17 00:00:00 2001 From: Jakub Rozmiarek Date: Fri, 16 Jan 2026 14:07:14 +0100 Subject: [PATCH 6/6] Use single job for mutation testing on CI to avoid race conditions --- .github/workflows/rails_application-coverage.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/rails_application-coverage.yml b/.github/workflows/rails_application-coverage.yml index 5f69e8b2..a5222f01 100644 --- a/.github/workflows/rails_application-coverage.yml +++ b/.github/workflows/rails_application-coverage.yml @@ -67,7 +67,8 @@ jobs: DATABASE_URL: "postgres://postgres:secret@localhost:5432/cqrs-es-sample-with-res_test" RAILS_ENV: test - name: Run full mutation testing - run: make -C apps/rails_application mutate + run: RAILS_ENV=test bundle exec mutant run --jobs 1 + working-directory: apps/rails_application env: DATABASE_URL: "postgres://postgres:secret@localhost:5432/cqrs-es-sample-with-res_test" RAILS_ENV: test