Repository navigation
Executing TestDeleteRun alias test does not safe guard pre-existing configuration #10590
Copy link
Copy link
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Activity
Thanks to @williammartin for calling out pre-existing test helper for setting up an isolated, mocked
Configto use; perhaps this is the more appropriate fix for this bug. 🤔Lines 85 to 114 in 7924274
// NewIsolatedTestConfig sets up a Mock keyring, creates a blank config // overwrites the ghConfig.Read function that returns a singleton config // in the real implementation, sets the GH_CONFIG_DIR env var so that // any call to Write goes to a different location on disk, and then returns // the blank config and a function that reads any data written to disk. func NewIsolatedTestConfig(t *testing.T) (*cfg, func(io.Writer, io.Writer)) { keyring.MockInit() c := ghConfig.ReadFromString("") cfg := cfg{c} // The real implementation of config.Read uses a sync.Once // to read config files and initialise package level variables // that are used from then on. // // This means that tests can't be isolated from each other, so // we swap out the function here to return a new config each time. ghConfig.Read = func(_ *ghConfig.Config) (*ghConfig.Config, error) { return c, nil } // The config.Write method isn't defined in the same way as Read to allow // the function to be swapped out and it does try to write to disk. // // We should consider whether it makes sense to change that but in the meantime // we can use GH_CONFIG_DIR env var to ensure the tests remain isolated. readConfigs := StubWriteConfig(t) return &cfg, readConfigs } From IPM:
- impactful work for us as maintainers because it's wiping our local configurations
- should be quick
- added a commit that references this issue
on Mar 26, 2025 - Melissa Xie (2025/03/26 08:20 -0700):mxie left a comment (cli/cli#10590) From IPM:Sorry for the dumb question but what does IPM mean, please? Thanks!
👋 @shindere Sorry we missed this comment! I just found it again today.
IPM is our internal "iteration planning meeting". We will occasionally add some notes to the issues we discuss regarding prioritization, blockers, technical decisions etc.
- Okay thanks!
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
Describe the bug
Collaborating with @BagToad after raising awareness of his aliases disappearing unpredictably, we have been periodically checking in whether my aliases have disappeared. This morning, I believe I found the cause due to a missing safeguard within the
gh alias deletetest below, which does not mockConfig.WriteFunc()function the same asgh alias settest does:cli/pkg/cmd/alias/delete/delete_test.go
Lines 87 to 185 in 7924274
cli/pkg/cmd/alias/set/set_test.go
Lines 98 to 290 in 7924274
Stepping through the debugger shows the
deleteRun()call will overwrite the test executor'sconfig.yaml(all of it!) with the final test scenario wiping out all aliases.I believe this is due to the test missing the following safeguard:
cli/pkg/cmd/alias/set/set_test.go
Lines 285 to 287 in 7924274
Affected version
N/A
Steps to reproduce the behavior
Expected vs actual behavior
gh aliastests do not affect the test executor's configuration file.Logs
Unsure how to get better logs here as part of the testing suite and being related to non-HTTP behavior.