Skip to content

Commit 51ead9e

Browse files
committed
test(linter): address code review feedback from ako
- Remove change-detector constant test for MPR008 overlap thresholds - Add boundary tests for domain-size rule (exactly at and one over threshold) - Unify nil-reader assertions to check violations != nil consistently
1 parent 593e19a commit 51ead9e

3 files changed

Lines changed: 57 additions & 34 deletions

File tree

mdl/linter/rules/domain_size_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,51 @@ func TestDomainModelSizeRule_NonPersistentIgnored(t *testing.T) {
7878
}
7979
}
8080

81+
func TestDomainModelSizeRule_ExactlyAtThreshold(t *testing.T) {
82+
var entities [][]any
83+
for i := 0; i < DefaultMaxPersistentEntities; i++ {
84+
entities = append(entities, []any{
85+
fmt.Sprintf("id%d", i), fmt.Sprintf("Entity%d", i),
86+
fmt.Sprintf("MyModule.Entity%d", i), "MyModule", "",
87+
"PERSISTENT", "", "", 3, 1, 0, 0, 0,
88+
})
89+
}
90+
91+
db := setupEntitiesDB(t, entities)
92+
defer db.Close()
93+
94+
ctx := linter.NewLintContextFromDB(db)
95+
rule := NewDomainModelSizeRule()
96+
violations := rule.Check(ctx)
97+
98+
if len(violations) != 0 {
99+
t.Errorf("expected 0 violations at threshold (%d entities), got %d", DefaultMaxPersistentEntities, len(violations))
100+
}
101+
}
102+
103+
func TestDomainModelSizeRule_OneOverThreshold(t *testing.T) {
104+
count := DefaultMaxPersistentEntities + 1
105+
var entities [][]any
106+
for i := 0; i < count; i++ {
107+
entities = append(entities, []any{
108+
fmt.Sprintf("id%d", i), fmt.Sprintf("Entity%d", i),
109+
fmt.Sprintf("MyModule.Entity%d", i), "MyModule", "",
110+
"PERSISTENT", "", "", 3, 1, 0, 0, 0,
111+
})
112+
}
113+
114+
db := setupEntitiesDB(t, entities)
115+
defer db.Close()
116+
117+
ctx := linter.NewLintContextFromDB(db)
118+
rule := NewDomainModelSizeRule()
119+
violations := rule.Check(ctx)
120+
121+
if len(violations) != 1 {
122+
t.Fatalf("expected 1 violation at %d entities, got %d", count, len(violations))
123+
}
124+
}
125+
81126
func TestDomainModelSizeRule_Metadata(t *testing.T) {
82127
r := NewDomainModelSizeRule()
83128
if r.ID() != "MPR003" {

mdl/linter/rules/mpr008_overlapping_activities_test.go

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,7 @@ func TestOverlappingActivitiesRule_Metadata(t *testing.T) {
3636
}
3737
}
3838

39-
// NOTE: The full Check() logic for overlapping activities requires ctx.Reader().GetMicroflow()
40-
// which needs a real *mpr.Reader. This rule currently lacks end-to-end coverage;
41-
// behavioral testing requires a real .mpr project. Here we verify constants used for
42-
// overlap threshold.
43-
44-
func TestOverlappingActivities_Constants(t *testing.T) {
45-
if activityBoxWidth != 120 {
46-
t.Errorf("activityBoxWidth = %d, want 120", activityBoxWidth)
47-
}
48-
if activityBoxHeight != 60 {
49-
t.Errorf("activityBoxHeight = %d, want 60", activityBoxHeight)
50-
}
51-
}
52-
53-
// Test the walker function indirectly: the Check method calls an inline collect function
54-
// that processes ActionActivity, LoopedActivity, ExclusiveSplit, and ExclusiveMerge.
55-
// Since collect is defined inline in Check(), we can only test it end-to-end via a real reader.
56-
// For unit coverage, we verify the nil-reader guard and metadata above.
39+
// The Check() method walks microflow positions via ctx.Reader().GetMicroflow() and detects
40+
// overlapping activities using pairwise distance checks against internal heuristic constants
41+
// (activityBoxWidth, activityBoxHeight). Since the collect function is defined inline in
42+
// Check(), behavioral testing requires a real *mpr.Reader with positioned activities.

mdl/linter/rules/security_test.go

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,28 +94,20 @@ func TestWeakPasswordPolicyRule_NilReader(t *testing.T) {
9494
rule := NewWeakPasswordPolicyRule()
9595
violations := rule.Check(ctx)
9696

97-
if len(violations) != 0 {
98-
t.Errorf("expected 0 violations with nil reader, got %d", len(violations))
97+
if violations != nil {
98+
t.Errorf("expected nil with nil reader, got %v", violations)
9999
}
100100
}
101101

102-
func TestWeakPasswordPolicyRule_Metadata(t *testing.T) {
103-
r := NewWeakPasswordPolicyRule()
104-
if r.ID() != "SEC002" {
105-
t.Errorf("ID = %q, want SEC002", r.ID())
106-
}
107-
if r.Category() != "security" {
108-
t.Errorf("Category = %q, want security", r.Category())
109-
}
110-
}
102+
// SEC003: Demo users still active in production
103+
// Without a real MPR file, we can only test the nil-reader early return and metadata.
111104

112105
func TestDemoUsersActiveRule_NilReader(t *testing.T) {
106+
r := NewDemoUsersActiveRule()
113107
ctx := linter.NewLintContextFromDB(nil)
114-
rule := NewDemoUsersActiveRule()
115-
violations := rule.Check(ctx)
116-
117-
if len(violations) != 0 {
118-
t.Errorf("expected 0 violations with nil reader, got %d", len(violations))
108+
violations := r.Check(ctx)
109+
if violations != nil {
110+
t.Errorf("expected nil with nil reader, got %v", violations)
119111
}
120112
}
121113

0 commit comments

Comments
 (0)