Skip to content

Adds teams cache remove command. Closes #3205#3224

Closed
Jwaegebaert wants to merge 16 commits intopnp:mainfrom
Jwaegebaert:dev/teamsCache
Closed

Adds teams cache remove command. Closes #3205#3224
Jwaegebaert wants to merge 16 commits intopnp:mainfrom
Jwaegebaert:dev/teamsCache

Conversation

@Jwaegebaert
Copy link
Copy Markdown
Contributor

Closes #3205

@Jwaegebaert Jwaegebaert marked this pull request as draft April 12, 2022 15:26
@Jwaegebaert
Copy link
Copy Markdown
Contributor Author

Hey @waldekmastykarz, at this point I've worked out some logic for clearing the teams cache for a MacOS and a Windows. For Windows I have been able to do some extensive testing but not yet for the MacOS. Here I have done some research into the logic that would handle this but I'm not 100% sure that this is correct. Could you possibly check this out?

Copy link
Copy Markdown
Member

@waldekmastykarz waldekmastykarz left a comment

Choose a reason for hiding this comment

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

Great start! Let's do a couple of small adjustments before we continue. I'll also check how it works on mac.

Comment thread src/m365/teams/commands/cache/cache-remove.ts Outdated
Comment thread src/m365/teams/commands/cache/cache-remove.ts Outdated
Comment thread src/m365/teams/commands/cache/cache-remove.ts Outdated
Comment thread src/m365/teams/commands/cache/cache-remove.ts Outdated
Comment thread src/m365/teams/commands/cache/cache-remove.ts Outdated
Comment thread src/m365/teams/commands/cache/cache-remove.ts Outdated
Comment thread src/m365/teams/commands/cache/cache-remove.ts Outdated
Comment thread src/m365/teams/commands/cache/cache-remove.ts Outdated
Comment thread docs/docs/cmd/teams/cache/cache-remove.md
Comment thread src/m365/teams/commands/cache/cache-remove.ts
@Jwaegebaert
Copy link
Copy Markdown
Contributor Author

Hey @waldekmastykarz, I updated the PR with the adjusments you suggested. For the issue I had with mocking the environment variables within the validate function should be working now.

@garrytrinder
Copy link
Copy Markdown
Member

@Jwaegebaert thank you for your changes following the review from @waldekmastykarz 👏🏻

If you are happy for another review or take place, please mark the PR as Ready for Review so that we know to take a another look 👍🏻

@Jwaegebaert Jwaegebaert marked this pull request as ready for review May 1, 2022 18:08
@waldekmastykarz waldekmastykarz self-assigned this May 13, 2022
Copy link
Copy Markdown
Member

@waldekmastykarz waldekmastykarz left a comment

Choose a reason for hiding this comment

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

Let's do a few adjustments. I'll also have a look how we can get it to work on macOS

Comment thread src/m365/teams/commands/cache/cache-remove.ts Outdated
Comment thread src/m365/teams/commands/cache/cache-remove.ts
Comment thread docs/docs/cmd/teams/cache/cache-remove.md Outdated
Comment thread docs/docs/cmd/teams/cache/cache-remove.md Outdated
Comment thread docs/docs/cmd/teams/cache/cache-remove.md Outdated
Comment thread docs/docs/cmd/teams/cache/cache-remove.md Outdated
Comment thread docs/docs/cmd/teams/cache/cache-remove.md Outdated
Comment thread docs/docs/cmd/teams/cache/cache-remove.md Outdated
Comment thread docs/docs/cmd/teams/cache/cache-remove.md Outdated
@waldekmastykarz waldekmastykarz marked this pull request as draft May 13, 2022 09:13
@waldekmastykarz waldekmastykarz removed their assignment May 24, 2022
@Jwaegebaert Jwaegebaert marked this pull request as ready for review May 29, 2022 17:47
@waldekmastykarz waldekmastykarz self-assigned this Jun 7, 2022
Copy link
Copy Markdown
Member

@waldekmastykarz waldekmastykarz left a comment

Choose a reason for hiding this comment

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

We're getting there. Let's do a few more adjustments and we'll be able to merge it. Awesome stuff! 👏

Comment thread src/m365/teams/commands/cache/cache-remove.ts Outdated
Comment thread src/m365/teams/commands/cache/cache-remove.ts Outdated
}
catch {
if (this.verbose) {
logger.logToStderr('Teams client isn\'t running');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This message isn't quite right. We can end up here, if there's an issue with closing Teams, which in some cases, like on my work mac, requires running CLI with sudo (I wonder btw. if we could run into the same on Windows where we might need to run the command in an Admin terminal process). Let's make a distinction between Teams not running (which is perfectly fine to proceed) and the command being unable to close Teams (where we need to stop execution) and communicate it to the user.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point! Within the catch I have put an extra check to ensure the teams client isn't running. For all other cases, users will get the error message. I've also applied this to the function removeCacheFiles.

if (errorMessage.includes('ERROR: The process "Teams.exe" not found.')) {
  if (this.verbose) {
    logger.logToStderr('Teams client isn\'t running');
  }
} else {
  throw new Error(errorMessage);
}

Here you can see that I'm looking specifically at the error message I get when the command on windows can't find teams.exe. With this logic, it would also be interesting to make a comparison with the output a mac would send. What do you think of this approach?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's see if there's a different way about it so that we don't need to rely on string comparison that's different between OSes but also languages. On mac we can see if we found a Teams PID or not, so that's a reliable way to see if Teams is running or not. If we can do the same on Windows, then we'd have a more reliable way of detection.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point, should we maybe take this into a new issue, so we can do a bit more of research on it. Currently I am having trouble fetching the Teams PID and validating the output.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We can use the current approach for now and meanwhile look at alternatives.

Comment thread src/m365/teams/commands/cache/cache-remove.ts Outdated
@waldekmastykarz waldekmastykarz marked this pull request as draft June 7, 2022 08:49
@waldekmastykarz waldekmastykarz removed their assignment Jun 7, 2022
@Jwaegebaert Jwaegebaert marked this pull request as ready for review June 7, 2022 19:58
@waldekmastykarz waldekmastykarz self-assigned this Jun 16, 2022
Copy link
Copy Markdown
Member

@waldekmastykarz waldekmastykarz left a comment

Choose a reason for hiding this comment

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

Works like a charm! Let's do one small change to how we return error and update tests so that they correctly verify the command's behavior.

Comment thread src/m365/teams/commands/cache/cache-remove.ts Outdated
Comment thread src/m365/teams/commands/cache/cache-remove.spec.ts Outdated
Comment thread src/m365/teams/commands/cache/cache-remove.spec.ts Outdated
Comment thread src/m365/teams/commands/cache/cache-remove.ts Outdated
@waldekmastykarz waldekmastykarz marked this pull request as draft June 16, 2022 09:19
@waldekmastykarz waldekmastykarz removed their assignment Jun 16, 2022
@Jwaegebaert Jwaegebaert marked this pull request as ready for review June 16, 2022 19:23
@waldekmastykarz waldekmastykarz self-assigned this Jun 28, 2022
Copy link
Copy Markdown
Member

@waldekmastykarz waldekmastykarz left a comment

Choose a reason for hiding this comment

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

Works nicely! Let's capture ideas for improvement in a separate issue:

  • detect Teams PID on Windows to avoid failing if Teams is not running
  • detect if the Teams cache folder exists to avoid failing if it doesn't

@Jwaegebaert
Copy link
Copy Markdown
Contributor Author

@waldekmastykarz thanks for your help on this one! I will create these issues later today 😄

@waldekmastykarz
Copy link
Copy Markdown
Member

Merged manually. Thank you! 👏

@waldekmastykarz
Copy link
Copy Markdown
Member

@waldekmastykarz thanks for your help on this one! I will create these issues later today 😄

Thank you for all the hard work and sticking with us 👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New command: teams cache remove

3 participants