Skip to content

Conversation

@robertbrignull
Copy link
Contributor

Pulls a bunch of code from setup-tracer.ts to a new tracer-config.ts file. 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.keys which 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

  • 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 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.

{ env: { 'ODASA_TRACER_CONFIGURATION': tracerConfig.spec } });
}

// NB: in CLI mode these will be outputted to a file instead of exported with core.exportVariable
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
// 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

Comment on lines 27 to 28
// A very minimal setup
test('tracerConfig - minimal', async t => {
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
// 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',
}
Copy link
Contributor

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?

Copy link
Contributor Author

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, {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

});
});

test('concatTracerConfigs - minimal', async t => {
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
test('concatTracerConfigs - minimal', async t => {
test('concatTracerConfigs - minimal configs correctly combined', async t => {

},
});

t.deepEqual(undefined, await getTracerConfig(config, codeQL));
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
t.deepEqual(undefined, await getTracerConfig(config, codeQL));
t.deepEqual(await getTracerConfig(config, codeQL), undefined);

});
});

test('getTracerConfig - full', async t => {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

return { env, spec };
}

export async function getTracerConfig(
Copy link
Contributor

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?

Copy link
Contributor Author

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.

}

// Get all the tracer configs and combine them together
let tracedLanguageConfigs: { [lang: string]: TracerConfig } = {};
Copy link
Contributor

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.

Suggested change
let tracedLanguageConfigs: { [lang: string]: TracerConfig } = {};
const tracedLanguageConfigs: { [lang: string]: TracerConfig } = {};

@robertbrignull
Copy link
Contributor Author

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.

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.

3 participants