Skip to content

Commit 488b609

Browse files
authored
address comments
1 parent ccad8f8 commit 488b609

3 files changed

Lines changed: 66 additions & 3 deletions

File tree

pkg/github/granular_tools_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func TestIssuesGranularToolset(t *testing.T) {
9494

9595
t.Run("all granular tools have correct feature flag", func(t *testing.T) {
9696
for _, tool := range granularToolsForToolset(ToolsetMetadataIssues.ID, FeatureFlagIssuesGranular) {
97-
assert.Equal(t, []string{FeatureFlagIssuesGranular}, tool.FeatureFlagEnable, "tool %s", tool.Tool.Name)
97+
assert.Contains(t, tool.FeatureFlagEnable, FeatureFlagIssuesGranular, "tool %s should require the granular flag", tool.Tool.Name)
9898
}
9999
})
100100
}
@@ -129,7 +129,7 @@ func TestPullRequestsGranularToolset(t *testing.T) {
129129

130130
t.Run("all granular tools have correct feature flag", func(t *testing.T) {
131131
for _, tool := range granularToolsForToolset(ToolsetMetadataPullRequests.ID, FeatureFlagPullRequestsGranular) {
132-
assert.Equal(t, []string{FeatureFlagPullRequestsGranular}, tool.FeatureFlagEnable, "tool %s", tool.Tool.Name)
132+
assert.Contains(t, tool.FeatureFlagEnable, FeatureFlagPullRequestsGranular, "tool %s should require the granular flag", tool.Tool.Name)
133133
}
134134
})
135135
}

pkg/github/issues_granular.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,6 @@ func GranularSetIssueFields(t translations.TranslationHelperFunc) inventory.Serv
11311131
return utils.NewToolResultText(string(r)), nil, nil
11321132
},
11331133
)
1134-
st.FeatureFlagEnable = []string{FeatureFlagIssuesGranular}
1134+
st.FeatureFlagEnable = []string{FeatureFlagIssuesGranular, FeatureFlagIssueFields}
11351135
return st
11361136
}

pkg/inventory/registry_test.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,69 @@ func TestFeatureFlagBoth(t *testing.T) {
11451145
}
11461146
}
11471147

1148+
func TestFeatureFlagMultipleEnableFlags(t *testing.T) {
1149+
// Tool requires BOTH flag_a AND flag_b (AND semantics).
1150+
tool := mockTool("dual_enable_tool", "toolset1", true)
1151+
tool.FeatureFlagEnable = []string{"flag_a", "flag_b"}
1152+
tools := []ServerTool{tool}
1153+
1154+
// Neither flag enabled → excluded
1155+
checkerNone := func(_ context.Context, _ string) (bool, error) { return false, nil }
1156+
regNone := mustBuild(t, NewBuilder().SetTools(tools).WithToolsets([]string{"all"}).WithFeatureChecker(checkerNone))
1157+
if len(regNone.AvailableTools(context.Background())) != 0 {
1158+
t.Error("Tool should be excluded when no enable flags are on")
1159+
}
1160+
1161+
// Only flag_a enabled → excluded (flag_b still missing)
1162+
checkerOnlyA := func(_ context.Context, flag string) (bool, error) { return flag == "flag_a", nil }
1163+
regOnlyA := mustBuild(t, NewBuilder().SetTools(tools).WithToolsets([]string{"all"}).WithFeatureChecker(checkerOnlyA))
1164+
if len(regOnlyA.AvailableTools(context.Background())) != 0 {
1165+
t.Error("Tool should be excluded when only one of two enable flags is on")
1166+
}
1167+
1168+
// Both flags enabled → included
1169+
checkerBoth := func(_ context.Context, _ string) (bool, error) { return true, nil }
1170+
regBoth := mustBuild(t, NewBuilder().SetTools(tools).WithToolsets([]string{"all"}).WithFeatureChecker(checkerBoth))
1171+
if len(regBoth.AvailableTools(context.Background())) != 1 {
1172+
t.Error("Tool should be included when all enable flags are on")
1173+
}
1174+
}
1175+
1176+
func TestFeatureFlagMultipleDisableFlags(t *testing.T) {
1177+
// Tool is blocked when EITHER kill_a OR kill_b is enabled (OR semantics).
1178+
tool := mockTool("dual_disable_tool", "toolset1", true)
1179+
tool.FeatureFlagDisable = []string{"kill_a", "kill_b"}
1180+
tools := []ServerTool{tool}
1181+
1182+
// Neither kill flag on → included
1183+
checkerNone := func(_ context.Context, _ string) (bool, error) { return false, nil }
1184+
regNone := mustBuild(t, NewBuilder().SetTools(tools).WithToolsets([]string{"all"}).WithFeatureChecker(checkerNone))
1185+
if len(regNone.AvailableTools(context.Background())) != 1 {
1186+
t.Error("Tool should be included when no disable flags are on")
1187+
}
1188+
1189+
// Only kill_a on → excluded
1190+
checkerOnlyA := func(_ context.Context, flag string) (bool, error) { return flag == "kill_a", nil }
1191+
regOnlyA := mustBuild(t, NewBuilder().SetTools(tools).WithToolsets([]string{"all"}).WithFeatureChecker(checkerOnlyA))
1192+
if len(regOnlyA.AvailableTools(context.Background())) != 0 {
1193+
t.Error("Tool should be excluded when the first disable flag is on")
1194+
}
1195+
1196+
// Only kill_b on → excluded
1197+
checkerOnlyB := func(_ context.Context, flag string) (bool, error) { return flag == "kill_b", nil }
1198+
regOnlyB := mustBuild(t, NewBuilder().SetTools(tools).WithToolsets([]string{"all"}).WithFeatureChecker(checkerOnlyB))
1199+
if len(regOnlyB.AvailableTools(context.Background())) != 0 {
1200+
t.Error("Tool should be excluded when the second disable flag is on")
1201+
}
1202+
1203+
// Both kill flags on → excluded
1204+
checkerBoth := func(_ context.Context, _ string) (bool, error) { return true, nil }
1205+
regBoth := mustBuild(t, NewBuilder().SetTools(tools).WithToolsets([]string{"all"}).WithFeatureChecker(checkerBoth))
1206+
if len(regBoth.AvailableTools(context.Background())) != 0 {
1207+
t.Error("Tool should be excluded when all disable flags are on")
1208+
}
1209+
}
1210+
11481211
func TestFeatureFlagError(t *testing.T) {
11491212
tools := []ServerTool{
11501213
mockToolWithFlags("needs_flag", "toolset1", true, "my_feature", ""),

0 commit comments

Comments
 (0)