Skip to content

Commit 4c3cca0

Browse files
authored
fix: exec name alias should be respected when ws verb aliases are set (#324)
Fixes a bug where an executable's alias is not being added to the cache when the workspace has verb overrides set.
1 parent 7a9522e commit 4c3cca0

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

internal/cache/executables_cache.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ func enumerateExecutableAliasRefs(
277277
) executable.RefList {
278278
refs := make(executable.RefList, 0)
279279

280+
// Always include explicit verb aliases defined on the executable itself
280281
for _, v := range exec.VerbAliases {
281282
if err := v.Validate(); err != nil {
282283
continue
@@ -287,26 +288,30 @@ func enumerateExecutableAliasRefs(
287288
}
288289
}
289290

291+
// Always include name (ID) aliases for the executable's primary verb
292+
for _, id := range exec.AliasesIDs() {
293+
refs = append(refs, executable.NewRef(id, exec.Verb))
294+
}
295+
290296
switch {
291297
case override == nil:
292-
// use default aliases
298+
// use default aliases (related verbs for the primary verb)
293299
for _, verb := range executable.RelatedVerbs(exec.Verb) {
294300
refs = append(refs, executable.NewRef(exec.ID(), verb))
295301
for _, id := range exec.AliasesIDs() {
296302
refs = append(refs, executable.NewRef(id, verb))
297303
}
298304
}
299305
case len(*override) == 0:
300-
// disable all aliases if override is set but empty
301-
return refs
306+
// verb overrides explicitly disable verb aliases; keep only name aliases and explicit verb aliases
307+
// nothing more to add
302308
default:
303309
// use overrides if provided
304310
o := *override
305311
if verbs, found := o[exec.Verb.String()]; found {
306312
for _, v := range verbs {
307313
vv := executable.Verb(v)
308314
if err := vv.Validate(); err != nil {
309-
// If the verb is not valid, skip it
310315
continue
311316
}
312317
refs = append(refs, executable.NewRef(exec.ID(), vv))

internal/cache/executables_cache_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,13 @@ var _ = Describe("ExecutableCacheImpl", func() {
270270
Expect(err).NotTo(HaveOccurred())
271271
Expect(exec).NotTo(BeNil())
272272
Expect(exec.Name).To(Equal("test-alias"))
273+
274+
// And should still be able to access via name alias using the primary verb
275+
aliasRunRef := executable.Ref("run test/testdata:alias1")
276+
execFromAlias, err := execCache.GetExecutableByRef(aliasRunRef)
277+
Expect(err).NotTo(HaveOccurred())
278+
Expect(execFromAlias).NotTo(BeNil())
279+
Expect(execFromAlias.Name).To(Equal("test-alias"))
273280
})
274281
})
275282

0 commit comments

Comments
 (0)