Skip to content

Conversation

@robertbrignull
Copy link
Contributor

This primarily fixes a bug from #109 where we were not running the default queries in certain cases and this was causing workflows to fail. If a config file was provided but disable-default-queries was not in that config file then we were not running the default queries.

I've added a unit test to catch this case. I considered adding an integration test too but wasn't sure if that was overkill and a waste of resources given how much longer the integration tests take to run.

While writing the unit test, I discovered another issue that I have also included in this PR. Many of the unit tests set environment variables because this is how action input values are controlled. These values were persisting between tests and causing interference. In this we I add some code to reset environment variables between tests, and add in all the necessary declarations to get the tests to pass again. I could pull this part out to a separate PR if that would be preferable, though the two PRs would conflict.

Merge / deployment checklist

  • Confirm this change is backwards compatible with existing workflows.
  • Confirm the readme has been updated if necessary.

Copy link
Contributor

@sampart sampart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this.

process.stderr.write = wrapOutput(t.context) as any;

// Many tests modify environment variables. Take a copy now so that
// We reset them after the test to keep tests independent of each other.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// We reset them after the test to keep tests independent of each other.
// we reset them after the test to keep tests independent of each other.

// We reset them after the test to keep tests independent of each other.
// process.env only has strings fields, so a shallow copy is fine.
t.context.env = {};
Object.assign(process.env, t.context.env);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Object.assign(process.env, t.context.env);
Object.assign(t.context.env, process.env);

Is this the wrong way round? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign says:

The Object.assign() method copies all enumerable own properties from one or more source objects to a target object. It returns the target object.
const returnedTarget = Object.assign(target, source);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching that blunder. I read the doc but not the parameter names and for some reason assumed the last parameter would be the target.

Fixed now. So I think we must have been setting the environment to empty at the end of each test. So it was still achieving what we wanted, but potentially doing too much.

process.env['GITHUB_WORKSPACE'] = tmpDir;

// Check that the default behaviour is to add the default queries.
// In this case if a config file is specified by does not include
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// In this case if a config file is specified by does not include
// In this case if a config file is specified but does not include

},
});

// Just create a generic config object with non-default values for all fields
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Just create a generic config object with non-default values for all fields
// Just create a generic config object with a non-default value for one of the fields

In the other place where you use this comment, you specify way more fields, hence my suggested change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. That comment was copy-pasted and I didn't spot it was now incorrect. I've updated to say the actual important points of this config.

@robertbrignull
Copy link
Contributor Author

Note I've also run some tests in a private repo with a config that triggers the bug. I've checked that I can reproduce it, and that it's fixed both by reverting the previous PR, and by merging this PR.

@robertbrignull robertbrignull merged commit 9769e4a into main Jul 21, 2020
@robertbrignull robertbrignull deleted the default_queries_fix branch July 21, 2020 12:11
This was referenced Jul 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants