Skip to content

Commit 795d447

Browse files
Copilotalexec
andauthored
Rename selectorMap type to selectors (#99)
* Initial plan * Rename selectorMap to selectors Co-authored-by: alexec <1142830+alexec@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: alexec <1142830+alexec@users.noreply.github.com>
1 parent fb16aaa commit 795d447

4 files changed

Lines changed: 58 additions & 58 deletions

File tree

main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type codingContext struct {
2020
workDir string
2121
resume bool
2222
params Params
23-
includes selectorMap
23+
includes selectors
2424
remotePaths []string
2525
emitTaskFrontmatter bool
2626

@@ -40,7 +40,7 @@ func main() {
4040

4141
cc := &codingContext{
4242
params: make(Params),
43-
includes: make(selectorMap),
43+
includes: make(selectors),
4444
output: os.Stdout,
4545
logOut: flag.CommandLine.Output(),
4646
cmdRunner: func(cmd *exec.Cmd) error {

main_test.go

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func TestRun(t *testing.T) {
3939
workDir string
4040
resume bool
4141
params Params
42-
includes selectorMap
42+
includes selectors
4343
setupFiles func(t *testing.T, tmpDir string)
4444
wantErr bool
4545
errContains string
@@ -140,7 +140,7 @@ func TestRun(t *testing.T) {
140140
cc.params = make(Params)
141141
}
142142
if cc.includes == nil {
143-
cc.includes = make(selectorMap)
143+
cc.includes = make(selectors)
144144
}
145145

146146
err = cc.run(context.Background(), tt.args)
@@ -164,7 +164,7 @@ func TestFindTaskFile(t *testing.T) {
164164
tests := []struct {
165165
name string
166166
taskName string
167-
includes selectorMap
167+
includes selectors
168168
setupFiles func(t *testing.T, tmpDir string)
169169
downloadedDirs []string // Directories to add to downloadedDirs
170170
wantErr bool
@@ -208,7 +208,7 @@ func TestFindTaskFile(t *testing.T) {
208208
{
209209
name: "task with matching selector",
210210
taskName: "filtered_task",
211-
includes: selectorMap{
211+
includes: selectors{
212212
"env": map[string]bool{"prod": true},
213213
},
214214
setupFiles: func(t *testing.T, tmpDir string) {
@@ -222,7 +222,7 @@ func TestFindTaskFile(t *testing.T) {
222222
{
223223
name: "task with non-matching selector",
224224
taskName: "filtered_task",
225-
includes: selectorMap{
225+
includes: selectors{
226226
"env": map[string]bool{"dev": true},
227227
},
228228
setupFiles: func(t *testing.T, tmpDir string) {
@@ -331,7 +331,7 @@ func TestFindTaskFile(t *testing.T) {
331331
includes: tt.includes,
332332
}
333333
if cc.includes == nil {
334-
cc.includes = make(selectorMap)
334+
cc.includes = make(selectors)
335335
}
336336
cc.includes.SetValue("task_name", tt.taskName)
337337

@@ -372,7 +372,7 @@ func TestFindExecuteRuleFiles(t *testing.T) {
372372
tests := []struct {
373373
name string
374374
resume bool
375-
includes selectorMap
375+
includes selectors
376376
setupFiles func(t *testing.T, tmpDir string)
377377
downloadedDirs []string // Directories to add to downloadedDirs
378378
wantTokens int
@@ -406,7 +406,7 @@ func TestFindExecuteRuleFiles(t *testing.T) {
406406
{
407407
name: "exclude rule with non-matching selector",
408408
resume: false,
409-
includes: selectorMap{
409+
includes: selectors{
410410
"env": map[string]bool{"prod": true},
411411
},
412412
setupFiles: func(t *testing.T, tmpDir string) {
@@ -419,7 +419,7 @@ func TestFindExecuteRuleFiles(t *testing.T) {
419419
{
420420
name: "include rule with matching selector",
421421
resume: false,
422-
includes: selectorMap{
422+
includes: selectors{
423423
"env": map[string]bool{"prod": true},
424424
},
425425
setupFiles: func(t *testing.T, tmpDir string) {
@@ -479,7 +479,7 @@ func TestFindExecuteRuleFiles(t *testing.T) {
479479
{
480480
name: "bootstrap script should not run on excluded files",
481481
resume: false,
482-
includes: selectorMap{
482+
includes: selectors{
483483
"env": map[string]bool{"prod": true},
484484
},
485485
setupFiles: func(t *testing.T, tmpDir string) {
@@ -532,7 +532,7 @@ func TestFindExecuteRuleFiles(t *testing.T) {
532532
},
533533
}
534534
if cc.includes == nil {
535-
cc.includes = make(selectorMap)
535+
cc.includes = make(selectors)
536536
}
537537

538538
// Set downloadedDirs if specified in test case
@@ -794,7 +794,7 @@ func TestWriteTaskFileContent(t *testing.T) {
794794
emitTaskFrontmatter: tt.emitTaskFrontmatter,
795795
output: &output,
796796
logOut: &logOut,
797-
includes: make(selectorMap),
797+
includes: make(selectors),
798798
}
799799

800800
// Parse task file first
@@ -861,16 +861,16 @@ func TestParseTaskFile(t *testing.T) {
861861
name string
862862
taskFile string
863863
setupFiles func(t *testing.T, tmpDir string) string // returns task file path
864-
initialIncludes selectorMap
865-
expectedIncludes selectorMap // expected includes after parsing
864+
initialIncludes selectors
865+
expectedIncludes selectors // expected includes after parsing
866866
wantErr bool
867867
errContains string
868868
}{
869869
{
870870
name: "task without selectors field",
871871
taskFile: "task.md",
872-
initialIncludes: make(selectorMap),
873-
expectedIncludes: make(selectorMap),
872+
initialIncludes: make(selectors),
873+
expectedIncludes: make(selectors),
874874
setupFiles: func(t *testing.T, tmpDir string) string {
875875
taskPath := filepath.Join(tmpDir, "task.md")
876876
createMarkdownFile(t, taskPath,
@@ -883,8 +883,8 @@ func TestParseTaskFile(t *testing.T) {
883883
{
884884
name: "task with selectors field",
885885
taskFile: "task.md",
886-
initialIncludes: make(selectorMap),
887-
expectedIncludes: selectorMap{
886+
initialIncludes: make(selectors),
887+
expectedIncludes: selectors{
888888
"language": map[string]bool{"Go": true},
889889
"env": map[string]bool{"prod": true},
890890
},
@@ -900,8 +900,8 @@ func TestParseTaskFile(t *testing.T) {
900900
{
901901
name: "task with selectors merges with existing includes",
902902
taskFile: "task.md",
903-
initialIncludes: selectorMap{"existing": map[string]bool{"value": true}},
904-
expectedIncludes: selectorMap{
903+
initialIncludes: selectors{"existing": map[string]bool{"value": true}},
904+
expectedIncludes: selectors{
905905
"existing": map[string]bool{"value": true},
906906
"language": map[string]bool{"Python": true},
907907
},
@@ -917,8 +917,8 @@ func TestParseTaskFile(t *testing.T) {
917917
{
918918
name: "task with array selector values",
919919
taskFile: "task.md",
920-
initialIncludes: make(selectorMap),
921-
expectedIncludes: selectorMap{
920+
initialIncludes: make(selectors),
921+
expectedIncludes: selectors{
922922
"rule_name": map[string]bool{"rule1": true, "rule2": true},
923923
},
924924
setupFiles: func(t *testing.T, tmpDir string) string {
@@ -933,8 +933,8 @@ func TestParseTaskFile(t *testing.T) {
933933
{
934934
name: "selectors from -s flag and task file are additive",
935935
taskFile: "task.md",
936-
initialIncludes: selectorMap{"var": map[string]bool{"arg1": true}},
937-
expectedIncludes: selectorMap{
936+
initialIncludes: selectors{"var": map[string]bool{"arg1": true}},
937+
expectedIncludes: selectors{
938938
"var": map[string]bool{"arg1": true, "arg2": true},
939939
},
940940
setupFiles: func(t *testing.T, tmpDir string) string {
@@ -949,8 +949,8 @@ func TestParseTaskFile(t *testing.T) {
949949
{
950950
name: "task with integer selector value",
951951
taskFile: "task.md",
952-
initialIncludes: make(selectorMap),
953-
expectedIncludes: selectorMap{
952+
initialIncludes: make(selectors),
953+
expectedIncludes: selectors{
954954
"version": map[string]bool{"42": true},
955955
},
956956
setupFiles: func(t *testing.T, tmpDir string) string {
@@ -965,7 +965,7 @@ func TestParseTaskFile(t *testing.T) {
965965
{
966966
name: "task with invalid selectors field type",
967967
taskFile: "task.md",
968-
initialIncludes: make(selectorMap),
968+
initialIncludes: make(selectors),
969969
setupFiles: func(t *testing.T, tmpDir string) string {
970970
taskPath := filepath.Join(tmpDir, "task.md")
971971
createMarkdownFile(t, taskPath,
@@ -988,7 +988,7 @@ func TestParseTaskFile(t *testing.T) {
988988
includes: tt.initialIncludes,
989989
}
990990
if cc.includes == nil {
991-
cc.includes = make(selectorMap)
991+
cc.includes = make(selectors)
992992
}
993993

994994
err := cc.parseTaskFile()
@@ -1156,7 +1156,7 @@ func TestTaskSelectorsFilterRulesByRuleName(t *testing.T) {
11561156
var output, logOut bytes.Buffer
11571157
cc := &codingContext{
11581158
workDir: tmpDir,
1159-
includes: make(selectorMap),
1159+
includes: make(selectors),
11601160
output: &output,
11611161
logOut: &logOut,
11621162
cmdRunner: func(cmd *exec.Cmd) error {
@@ -1220,7 +1220,7 @@ func TestTaskFileWalker(t *testing.T) {
12201220
tests := []struct {
12211221
name string
12221222
taskName string
1223-
includes selectorMap
1223+
includes selectors
12241224
fileInfo fileInfoMock
12251225
filePath string
12261226
fileContent string // frontmatter + content
@@ -1303,7 +1303,7 @@ func TestTaskFileWalker(t *testing.T) {
13031303
matchingTaskFile: tt.existingMatch,
13041304
}
13051305
if cc.includes == nil {
1306-
cc.includes = make(selectorMap)
1306+
cc.includes = make(selectors)
13071307
}
13081308
cc.includes.SetValue("task_name", tt.taskName)
13091309

@@ -1335,7 +1335,7 @@ func TestTaskFileWalker(t *testing.T) {
13351335
func TestRuleFileWalker(t *testing.T) {
13361336
tests := []struct {
13371337
name string
1338-
includes selectorMap
1338+
includes selectors
13391339
fileInfo fileInfoMock
13401340
filePath string
13411341
fileContent string
@@ -1373,7 +1373,7 @@ func TestRuleFileWalker(t *testing.T) {
13731373
},
13741374
{
13751375
name: "exclude rule with non-matching selector",
1376-
includes: selectorMap{"env": map[string]bool{"prod": true}},
1376+
includes: selectors{"env": map[string]bool{"prod": true}},
13771377
fileInfo: fileInfoMock{isDir: false, name: "rule.md"},
13781378
filePath: "rule.md",
13791379
fileContent: "---\nenv: dev\n---\n# Dev Rule",
@@ -1383,7 +1383,7 @@ func TestRuleFileWalker(t *testing.T) {
13831383
},
13841384
{
13851385
name: "include rule with matching selector",
1386-
includes: selectorMap{"env": map[string]bool{"prod": true}},
1386+
includes: selectors{"env": map[string]bool{"prod": true}},
13871387
fileInfo: fileInfoMock{isDir: false, name: "rule.md"},
13881388
filePath: "rule.md",
13891389
fileContent: "---\nenv: prod\n---\n# Prod Rule",
@@ -1418,7 +1418,7 @@ func TestRuleFileWalker(t *testing.T) {
14181418
},
14191419
}
14201420
if cc.includes == nil {
1421-
cc.includes = make(selectorMap)
1421+
cc.includes = make(selectors)
14221422
}
14231423

14241424
walker := cc.ruleFileWalker(context.Background())

selector_map.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import (
55
"strings"
66
)
77

8-
// selectorMap stores selector key-value pairs where values are stored in inner maps
8+
// selectors stores selector key-value pairs where values are stored in inner maps
99
// Multiple values for the same key use OR logic (match any value in the inner map)
1010
// Each value can be represented exactly once per key
11-
type selectorMap map[string]map[string]bool
11+
type selectors map[string]map[string]bool
1212

13-
func (s *selectorMap) String() string {
13+
func (s *selectors) String() string {
1414
if *s == nil {
1515
return "{}"
1616
}
@@ -29,14 +29,14 @@ func (s *selectorMap) String() string {
2929
return fmt.Sprintf("{%s}", strings.Join(parts, ", "))
3030
}
3131

32-
func (s *selectorMap) Set(value string) error {
32+
func (s *selectors) Set(value string) error {
3333
// Parse key=value format with trimming
3434
kv := strings.SplitN(value, "=", 2)
3535
if len(kv) != 2 {
3636
return fmt.Errorf("invalid selector format: %s", value)
3737
}
3838
if *s == nil {
39-
*s = make(selectorMap)
39+
*s = make(selectors)
4040
}
4141
key := strings.TrimSpace(kv[0])
4242
newValue := strings.TrimSpace(kv[1])
@@ -57,9 +57,9 @@ func (s *selectorMap) Set(value string) error {
5757
// SetValue sets a value in the inner map for the given key.
5858
// If the key doesn't exist, it creates a new inner map.
5959
// Each value can be represented exactly once per key.
60-
func (s *selectorMap) SetValue(key, value string) {
60+
func (s *selectors) SetValue(key, value string) {
6161
if *s == nil {
62-
*s = make(selectorMap)
62+
*s = make(selectors)
6363
}
6464
if (*s)[key] == nil {
6565
(*s)[key] = make(map[string]bool)
@@ -69,7 +69,7 @@ func (s *selectorMap) SetValue(key, value string) {
6969

7070
// GetValue returns true if the given value exists in the inner map for the given key.
7171
// Returns false if the key doesn't exist or the value is not present.
72-
func (s *selectorMap) GetValue(key, value string) bool {
72+
func (s *selectors) GetValue(key, value string) bool {
7373
if *s == nil {
7474
return false
7575
}
@@ -83,7 +83,7 @@ func (s *selectorMap) GetValue(key, value string) bool {
8383
// matchesIncludes returns true if the frontmatter matches all include selectors
8484
// If a key doesn't exist in frontmatter, it's allowed
8585
// Multiple values for the same key use OR logic (matches if frontmatter value is in the inner map)
86-
func (includes *selectorMap) matchesIncludes(frontmatter frontMatter) bool {
86+
func (includes *selectors) matchesIncludes(frontmatter frontMatter) bool {
8787
for key, values := range *includes {
8888
fmValue, exists := frontmatter[key]
8989
if !exists {

0 commit comments

Comments
 (0)