@@ -19,40 +19,70 @@ mutate: ## Run mutation tests
1919ifeq ($(origin MUTANT_NODE_INDEX ) , environment)
2020 @NODE_DISPLAY_INDEX=$$(( $(MUTANT_NODE_INDEX) + 1 )); \
2121 echo "Running mutation tests in parallel (Node $$NODE_DISPLAY_INDEX/$(MUTANT_TOTAL_NODES)) for rails_application"; \
22- \
23- echo "--- DEBUG: Generating canonical list of subjects from .mutant.yml using 'mutant util subjects' ---"; \
24- RAILS_ENV=test bundle exec mutant util subjects > .canonical_subjects.tmp; \
25- if [ $$? -ne 0 ]; then echo "ERROR: 'mutant util subjects' failed!"; exit 1; fi; \
26- CANONICAL_COUNT=$$(cat .canonical_subjects.tmp | wc -l); \
27- echo "--- DEBUG: Canonical subjects count (from mutant util subjects): $$CANONICAL_COUNT"; \
28- echo "--- DEBUG: Content of .canonical_subjects.tmp (first 10 lines): ---"; \
29- head -n 10 .canonical_subjects.tmp || echo "File .canonical_subjects.tmp is empty."; \
30- echo "--- END DEBUG (canonical subjects) ---"; \
31- \
32- echo "--- DEBUG: Dividing canonical subjects for this node ($(MUTANT_NODE_INDEX)) ---"; \
33- awk "NR % $(MUTANT_TOTAL_NODES) == $(MUTANT_NODE_INDEX)" .canonical_subjects.tmp > .node_subjects.tmp; \
34- if [ $$? -ne 0 ]; then echo "ERROR: awk command failed to divide subjects!"; exit 1; fi; \
35- NODE_SUBJECT_COUNT=$$(cat .node_subjects.tmp | wc -l); \
36- echo "--- DEBUG: Subjects for this node count: $$NODE_SUBJECT_COUNT"; \
37- echo "--- DEBUG: Content of .node_subjects.tmp (first 10 lines): ---"; \
38- head -n 10 .node_subjects.tmp || echo "File .node_subjects.tmp is empty."; \
39- echo "--- END DEBUG (node subjects) ---"; \
40- \
41- SUBJECT_ARGS=$$(cat .node_subjects.tmp | xargs); \
22+ echo "--- DEBUG: Checking target directories [$(MUTANT_TARGET_DIRS)] ---"; \
23+ ls -ld $(MUTANT_TARGET_DIRS) || (echo "ERROR: Target directories not found!" && exit 1); \
24+ echo "--- DEBUG: Finding potential subject files ---"; \
25+ find $(MUTANT_TARGET_DIRS) -name '*.rb' \
26+ -not -path '*/test/*' \
27+ -not -path '*/spec/*' \
28+ -not -path 'config/*' \
29+ -not -path '*/initializers/*' \
30+ -not -path 'db/*' \
31+ -not -path 'vendor/*' \
32+ -print > .all_files.tmp; \
33+ if [ $$? -ne 0 ]; then echo "ERROR: find command failed!"; exit 1; fi; \
34+ FOUND_COUNT=$$(cat .all_files.tmp | wc -l); \
35+ echo "--- DEBUG: Found files count: $$FOUND_COUNT"; \
36+ echo "--- DEBUG: Content of .all_files.tmp (first 5 lines): ---"; \
37+ head -n 5 .all_files.tmp || echo "File .all_files.tmp is empty."; \
38+ echo "--- END DEBUG (find) ---"; \
39+ echo "--- DEBUG: Running awk to create .node_files.tmp ---"; \
40+ awk "NR % $(MUTANT_TOTAL_NODES) == $(MUTANT_NODE_INDEX)" .all_files.tmp > .node_files.tmp; \
41+ if [ $$? -ne 0 ]; then echo "ERROR: awk command failed!"; exit 1; fi; \
42+ NODE_COUNT=$$(cat .node_files.tmp | wc -l); \
43+ echo "--- DEBUG: Files count for this node ($(MUTANT_NODE_INDEX)): $$NODE_COUNT"; \
44+ echo "--- DEBUG: Content of .node_files.tmp (first 5 lines): ---"; \
45+ head -n 5 .node_files.tmp || echo "File .node_files.tmp is empty."; \
46+ echo "--- END DEBUG (awk) ---"; \
47+ echo "--- DEBUG: Attempting to derive subject names for this node... ---"; \
48+ DERIVED_NAMES=$$(cat .node_files.tmp | perl -ne 'next unless /\S/; chomp; s# ^(app/(controllers|models|helpers|jobs|mailers|channels|client_panel|read_models|services)|lib)/##; s#\.rb$$##; my @parts = split /\//; my $$result = ""; foreach my $$part (@parts) { next unless $$part; $$part =~ s#_([a-z])#uc($$1)#eg; $$result .= ucfirst($$part) . "::"; } $$result =~ s/::$$//; print "$$result\n" if $$result && $$result !~ /^::/'); \
49+ PERL_EXIT_CODE=$$?; \
50+ if [ $$PERL_EXIT_CODE -ne 0 ]; then \
51+ echo "ERROR: Perl command failed with exit code $$PERL_EXIT_CODE"; \
52+ elif [ -z "$$DERIVED_NAMES" ] && [ "$$NODE_COUNT" -gt 0 ]; then \
53+ echo "WARN: Perl command produced no output, but node files exist."; \
54+ elif [ -z "$$DERIVED_NAMES" ]; then \
55+ echo "Perl command produced no output (expected if no files for node)."; \
56+ else \
57+ echo "--- DEBUG: Derived names (before subject filter): ---"; \
58+ echo "$$DERIVED_NAMES" > .derived_names.tmp; \
59+ cat .derived_names.tmp; \
60+ fi; \
61+ echo "--- END DEBUG (perl) ---"; \
62+ echo "--- DEBUG: Filtering derived names based on .mutant.yml 'subjects' patterns for rails_application ---"; \
63+ SUBJECT_PATTERNS_RAILS_APP='^(Orders::|ClientOrders::)'; \
64+ if [ -f .derived_names.tmp ]; then \
65+ grep -E "$$SUBJECT_PATTERNS_RAILS_APP" .derived_names.tmp > .filtered_names.tmp || true; \
66+ else \
67+ touch .filtered_names.tmp; \
68+ fi; \
69+ FILTERED_NAMES_CONTENT=$$(cat .filtered_names.tmp); \
70+ echo "--- DEBUG: Filtered names (after subject filter, from .filtered_names.tmp): ---"; \
71+ echo "$$FILTERED_NAMES_CONTENT"; \
72+ SUBJECT_ARGS=$$(cat .filtered_names.tmp | xargs); \
4273 echo "--- DEBUG: SUBJECT_ARGS for mutant: [$$SUBJECT_ARGS]"; \
43- \
4474 if [ -z "$$SUBJECT_ARGS" ]; then \
45- echo "No subjects assigned to this node. Skipping."; \
75+ echo "No subjects matching 'subjects' criteria found for this node. Skipping."; \
4676 else \
47- echo "Attempting to run mutant for subjects: $$SUBJECT_ARGS"; \
77+ echo "Attempting to run mutant for filtered subjects: $$SUBJECT_ARGS"; \
4878 RAILS_ENV=test bundle exec mutant run $$SUBJECT_ARGS; \
4979 MUTANT_EXIT_CODE=$$?; \
5080 if [ $$MUTANT_EXIT_CODE -ne 0 ]; then \
5181 echo "ERROR: mutant run failed with exit code $$MUTANT_EXIT_CODE"; \
5282 exit $$MUTANT_EXIT_CODE; \
5383 fi; \
5484 fi; \
55- rm -f .canonical_subjects .tmp .node_subjects .tmp .all_files.tmp . derived_names.tmp .filtered_names.tmp # Clean up all potential temp files
85+ rm -f .all_files .tmp .node_files .tmp .derived_names.tmp .filtered_names.tmp
5686else
5787 @echo "Running mutation tests locally for rails_application (mutant discovers subjects from .mutant.yml)"
5888 @RAILS_ENV=test bundle exec mutant run
0 commit comments