Skip to content

Commit ba5031b

Browse files
committed
Generate canonical list of subjects with mutant.
1 parent 48f1733 commit ba5031b

File tree

1 file changed

+24
-54
lines changed

1 file changed

+24
-54
lines changed

rails_application/Makefile

Lines changed: 24 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -19,70 +19,40 @@ mutate: ## Run mutation tests
1919
ifeq ($(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-
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 patterns ---"; \
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 to modules, from .filtered_names.tmp): ---"; \
71-
echo "$$FILTERED_NAMES_CONTENT"; \
72-
SUBJECT_ARGS=$$(cat .filtered_names.tmp | xargs); \
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); \
7342
echo "--- DEBUG: SUBJECT_ARGS for mutant: [$$SUBJECT_ARGS]"; \
43+
\
7444
if [ -z "$$SUBJECT_ARGS" ]; then \
75-
echo "No subjects matching module criteria (Orders::*, ClientOrders::*) found for this node. Skipping."; \
45+
echo "No subjects assigned to this node. Skipping."; \
7646
else \
77-
echo "Attempting to run mutant for filtered subjects: $$SUBJECT_ARGS"; \
47+
echo "Attempting to run mutant for subjects: $$SUBJECT_ARGS"; \
7848
RAILS_ENV=test bundle exec mutant run $$SUBJECT_ARGS; \
7949
MUTANT_EXIT_CODE=$$?; \
8050
if [ $$MUTANT_EXIT_CODE -ne 0 ]; then \
8151
echo "ERROR: mutant run failed with exit code $$MUTANT_EXIT_CODE"; \
8252
exit $$MUTANT_EXIT_CODE; \
8353
fi; \
8454
fi; \
85-
rm -f .all_files.tmp .node_files.tmp .derived_names.tmp .filtered_names.tmp
55+
rm -f .canonical_subjects.tmp .node_subjects.tmp .all_files.tmp .derived_names.tmp .filtered_names.tmp # Clean up all potential temp files
8656
else
8757
@echo "Running mutation tests locally for rails_application (mutant discovers subjects from .mutant.yml)"
8858
@RAILS_ENV=test bundle exec mutant run

0 commit comments

Comments
 (0)