Skip to content
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

Adds command spp model remove. Closes #6118 #6410

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mkm17
Copy link
Contributor

@mkm17 mkm17 commented Oct 6, 2024

Adds command spp model remove. Closes #6118

@milanholemans
Copy link
Contributor

Thank you, well try to review it ASAP!

@mkm17 mkm17 force-pushed the issues/6118_spp_model_remove branch from 5afaf7c to 9a84d0e Compare October 13, 2024 20:55
@milanholemans milanholemans self-assigned this Oct 17, 2024
Copy link
Contributor

@milanholemans milanholemans left a comment

Choose a reason for hiding this comment

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

Nice stuff, I made a few comments along the way. Could you take a look at them, please?

Comment on lines +122 to +128
private getCorrectRequestUrl(siteUrl: string, args: CommandArgs): string {
if (args.options.id) {
return `${siteUrl}/_api/machinelearning/models/getbyuniqueid('${args.options.id}')`;
}

return `${siteUrl}/_api/machinelearning/models/getbytitle('${formatting.encodeQueryParameter(args.options.title!)}')`;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of creating a new function for this, let's just use an if/else statement with a variable.

this.validators.push(
async (args: CommandArgs) => {
if (args.options.id && !validation.isValidGuid(args.options.id)) {
return `${args.options.id} is not a valid GUID`;
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's repeat the option name so the user knows exactly which option is failing.

Suggested change
return `${args.options.id} is not a valid GUID`;
return `${args.options.id} is not a valid GUID for option 'id'.`;

public async commandAction(logger: Logger, args: CommandArgs): Promise<void> {
try {
if (!args.options.force) {
const confirmationResult = await cli.promptForConfirmation({ message: `Are you sure you want to remove the model '${args.options.id || args.options.title}'?` });
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
const confirmationResult = await cli.promptForConfirmation({ message: `Are you sure you want to remove the model '${args.options.id || args.options.title}'?` });
const confirmationResult = await cli.promptForConfirmation({ message: `Are you sure you want to remove model '${args.options.id || args.options.title}'?` });


it('correctly handles an access denied error', async () => {
sinon.stub(request, 'get').callsFake(async (opts) => {
if (opts.url === `https://contoso.sharepoint.com/sites/portal/_api/web?$select=WebTemplateConfiguration`) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of throwing an error for this API, I think it's more useful to throw an error when a non existing name or title is passed when removing a model.

});

await command.action(logger, { options: { siteUrl: 'https://contoso.sharepoint.com/sites/portal', id: '9b1b1e42-794b-4c71-93ac-5ed92488b67f' } });
assert.strictEqual(stubDelete.lastCall.args[0].url, `https://contoso.sharepoint.com/sites/portal/_api/machinelearning/models/getbyuniqueid('9b1b1e42-794b-4c71-93ac-5ed92488b67f')`);
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's use assert(stubDelete.calledOnce).

});

await command.action(logger, { options: { siteUrl: 'https://contoso.sharepoint.com/sites/portal', id: '164720c8-35ee-4157-ba26-db6726264f9d', force: true } });
assert.strictEqual(stubDelete.lastCall.args[0].url, `https://contoso.sharepoint.com/sites/portal/_api/machinelearning/models/getbyuniqueid('164720c8-35ee-4157-ba26-db6726264f9d')`);
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's just check if the delete request was fired. If the URL doesn't match, it will throw an error anyway.

Comment on lines +220 to +221
assert.strictEqual(stubDelete.lastCall.args[0].url, `https://contoso.sharepoint.com/sites/portal/_api/machinelearning/models/getbyuniqueid('9b1b1e42-794b-4c71-93ac-5ed92488b67f')`);
assert(confirmationStub.calledOnce);
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment here.

Comment on lines +245 to +246
assert.strictEqual(stubDelete.lastCall.args[0].url, `https://contoso.sharepoint.com/sites/portal/_api/machinelearning/models/getbytitle('ModelName')`);
assert(confirmationStub.calledOnce);
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's just check if the delete request was fired. If the URL doesn't match, it will throw an error anyway.

}
};

await request.delete(requestOptions);
Copy link
Contributor

Choose a reason for hiding this comment

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

It's kinda sad that when you specify a name that doesn't exist, it just succeeds. Is there a way for us to check if the request actually works?
After doing a quick test, seems like odata.null: true is returned when the specified model doesn't exist. Is this something we can check and throw a custom error?


## Remarks

Note that this model will be removed from all libraries before it can be deleted.
Copy link
Contributor

Choose a reason for hiding this comment

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

Weird wording, shouldn't it be should be removed? Maybe it's worth to put this in a note admonition.

@milanholemans milanholemans marked this pull request as draft October 17, 2024 20:57
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.

New command: m365 spp model remove
2 participants