-
Notifications
You must be signed in to change notification settings - Fork 423
Break out tracer-config.ts to its own file #158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
sampart
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this refactor - this is a good step forward.
Many of my comments are about the tests; I think it's important that tests act a bit like documentation (since by nature they describe the system's behaviour), or at least that they make sense without much context (as someone may have to fix a failing test without knowing the project well), hence my insistence on good names.
src/setup-tracer.ts
Outdated
| { env: { 'ODASA_TRACER_CONFIGURATION': tracerConfig.spec } }); | ||
| } | ||
|
|
||
| // NB: in CLI mode these will be outputted to a file instead of exported with core.exportVariable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // NB: in CLI mode these will be outputted to a file instead of exported with core.exportVariable | |
| // NB: in CLI mode these will be output to a file rather than exported with core.exportVariable |
src/tracer-config.test.ts
Outdated
| // A very minimal setup | ||
| test('tracerConfig - minimal', async t => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // A very minimal setup | |
| test('tracerConfig - minimal', async t => { | |
| test('tracerConfig - minimal setup', async t => { |
| 'SEMMLE_DEPTRACE_SOCKET': 'SEMMLE_DEPTRACE_SOCKET', | ||
| 'SEMMLE_JAVA_TOOL_OPTIONS': 'SEMMLE_JAVA_TOOL_OPTIONS', | ||
| 'CODEQL_VAR': 'CODEQL_VAR', | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's happened to foo here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
foo is not listed here because it's already in the environment with a different value. That's the point of this test but I agree it's very unclear. I'll add a comment.
| process.env['CODEQL_VAR'] = 'abc'; | ||
|
|
||
| const result = await tracerConfig(codeQL, config, Language.javascript); | ||
| t.deepEqual(result, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this assertion - it looks like no variables have changed.
In particular, the comment above says // Existing vars should not be overwritten, unless they are critical or prefixed with CODEQL_, but CODEQL_VAR is unchanged, as are the critical vars. What am I missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The difference is that foo is missing, and "overwritten" here refers to the values from the CodeQL call overwriting those that exist in the environment already. I've add some comments and swapped setting process.env and setting up the mocked CodeQL response incase that makes it easier to see.
src/tracer-config.test.ts
Outdated
| }); | ||
| }); | ||
|
|
||
| test('concatTracerConfigs - minimal', async t => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| test('concatTracerConfigs - minimal', async t => { | |
| test('concatTracerConfigs - minimal configs correctly combined', async t => { |
src/tracer-config.test.ts
Outdated
| }, | ||
| }); | ||
|
|
||
| t.deepEqual(undefined, await getTracerConfig(config, codeQL)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| t.deepEqual(undefined, await getTracerConfig(config, codeQL)); | |
| t.deepEqual(await getTracerConfig(config, codeQL), undefined); |
src/tracer-config.test.ts
Outdated
| }); | ||
| }); | ||
|
|
||
| test('getTracerConfig - full', async t => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
full what? And when that thing is full, what behaviour are you expecting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've renamed to "valid spec file". The name "full" came from the fact that we've tested each function individually and now we're testing them all at once by calling the outer function.
src/tracer-config.ts
Outdated
| return { env, spec }; | ||
| } | ||
|
|
||
| export async function getTracerConfig( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function and tracerConfig have very similar names. Is it possible to rename them to make their different purposes more obvious? If not, please could you add a one-liner explaining what each one does?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed to getTracerConfigForLanguage and getCombinedTracerConfig and I think that makes things a bit clearer.
src/tracer-config.ts
Outdated
| } | ||
|
|
||
| // Get all the tracer configs and combine them together | ||
| let tracedLanguageConfigs: { [lang: string]: TracerConfig } = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be a constants as you're not reassigning it, just updating its inner values.
| let tracedLanguageConfigs: { [lang: string]: TracerConfig } = {}; | |
| const tracedLanguageConfigs: { [lang: string]: TracerConfig } = {}; |
|
There are still a couple of places where the test names could be better, but I'm slightly at a loss of what to do. I'll merge this later on today and maybe we can improve things before then, but if not then the tests are something we can easily change after merging. |
8eae9ab to
8efabe9
Compare
Pulls a bunch of code from
setup-tracer.tsto a newtracer-config.tsfile. This is the code that generates the environment variables to be set when running later processes so that CodeQL can intercept the compiler commands.This is in preparation for chaning the behaviour when in CLI mode to output the env vars to a file instead of using
core.exportVariable, while keeping all the code that generates the environment the same. Also while I'm doing it I've written tests for this code which was previously untested.Also reverts a bad change from a previous PR of mine. In https://github.com/github/codeql-action/pull/140/files#diff-244be00bfdf0600dd7b228caba9f8232L57 I changed the type of the argument from an object to an array because I thought it wouldn't make a difference, but I missed a call to
Object.keyswhich then silently did the wrong thing of returning keys like 0, 1, 2, 3... This basically didn't make a difference thankfully so tracing still worked, and the only functionality that was broken by this was the requirement to put the spec from cpp at the end.Other than the above noted fix of a regression, this PR shouldn't make any changes to behaviour.
@sampart do you have scope to review this?
Merge / deployment checklist