Skip to content

Conversation

@opieter-aws
Copy link
Contributor

@opieter-aws opieter-aws commented May 6, 2025

Problem

showConnectionPrompt unit tests were failing

Solution

  • Ensure DeviceFlow is used for auth
  • Stub login
  • Assert whether the login was called with builder ID instead of if the log line was emitted

  • Treat all work as PUBLIC. Private feature/x branches will not be squash-merged at release time.
  • Your code changes must meet the guidelines in CONTRIBUTING.md.
  • License: I confirm that my contribution is made under the terms of the Apache 2.0 license.

@github-actions
Copy link

github-actions bot commented May 6, 2025

  • This pull request implements a feat or fix, so it must include a changelog entry (unless the fix is for an unreleased feature). Review the changelog guidelines.
    • Note: beta or "experiment" features that have active users should announce fixes in the changelog.
    • If this is not a feature or fix, use an appropriate type from the title guidelines. For example, telemetry-only changes should use the telemetry type.

@opieter-aws opieter-aws marked this pull request as ready for review May 6, 2025 20:51
@opieter-aws opieter-aws requested a review from a team as a code owner May 6, 2025 20:51
Comment on lines +51 to +52
assert.strictEqual(loginStub.called, true)
assert.strictEqual(loginStub.firstCall.args[0], constants.builderIdStartUrl)
Copy link
Contributor

Choose a reason for hiding this comment

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

why can't we test the logged messages now ? can an equivalent log message be added in the relevant place in the new module ? that allows testing the real codepath (or something closer to it), instead of stubs.

Copy link
Contributor Author

@opieter-aws opieter-aws May 6, 2025

Choose a reason for hiding this comment

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

The getTestLogger().getLoggedEntries() call was failing to pick up the logger. The issue with only testing a log line is that the test won't fail if the functionality is removed or changes (the login call with AWS ID is what we care about asserting here, not a logged string). I did not spend time to dive deeper into it because it's a secondary assertion IMO

Copy link
Contributor

@justinmk3 justinmk3 May 7, 2025

Choose a reason for hiding this comment

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

The issue with only testing a log line is that the test won't fail if the functionality is removed or changes (the login call with AWS ID is what we care about asserting here, not a logged string)

Sure, but that applies to any kind of telemetry (aka logs): the telemetry is wrong if logic changes without updating the telemetry. And a similar situation applies when stubs/mocks are used: asserting that a method was called doesn't actually test that the functionality works, and can easily drift (also, asserting stubs leads to brittle tests).

@opieter-aws opieter-aws requested a review from justinmk3 May 7, 2025 14:03
@opieter-aws opieter-aws merged commit 4b0ec4d into aws:feature/amazonqLSP-auth May 7, 2025
19 of 37 checks passed
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.

2 participants