-
Notifications
You must be signed in to change notification settings - Fork 2k
feat: add a REST sample and test for AML AI #3809
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
|
Here is the summary of changes. You are about to add 1 region tag.
This comment is generated by snippet-bot.
|
subfuzion
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.
A few changes requested, but looks good overall. Thanks.
subfuzion
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.
Approved. Test fails because financialservices.googleapis.com isn't enabled (pending: cl/674939991).
|
|
||
| // node listLocations.js | ||
| main().catch(err => { | ||
| console.error(err); |
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.
Changed this so mocha's reporter prints the reason for the failure. The current mocha test reporter filters out stdout but prints stderr, see logs using console.log() vs. console.error().
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.
cl/674939991 is merged, waiting on API enablement now.
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.
Hi @irataxy The API was enabled (internal: cl/676595619). Looks like a few conflicts must be resolved to get this merged, however. Do you have bandwidth to follow up, or would you like to convert this to a draft or close it for now?
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.
Converted to draft for now
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.
@irataxy The PR to enable the financialservices api was merged. I'm going to take this out of draft mode and rerun tests to confirm.
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.
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.
Hi @irataxy and reviewers,
I'm currently reviewing this pull request and will post my detailed review in a few minutes. In the meantime, here's a quick summary to help everyone get up to speed:
This pull request adds a new REST sample and test for the AML AI product. The changes include:
- A new directory
aml-aicontaining the sample code (listLocations.js) and its corresponding test (aml-ai.test.js). - A new GitHub Actions workflow (
aml-ai.yaml) for building and testing the sample. - Updates to
CODEOWNERSto assign ownership of the new sample. - Updates to
.github/workflows/utils/workflows.jsonto include the new workflow. - A
package.jsonfile for managing dependencies within theaml-aidirectory.
The intent is to provide a clear and concise example of how to use the AML AI API to list locations. The test verifies that the sample correctly retrieves the expected location information.
If there's anything unclear or missing from this summary, please let me know. I'll provide a more detailed review shortly.
And now, a little haiku to lighten the mood:
Code flows like a stream,
Tests run, a green light appears,
Joy fills the coder's heart.
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 pull request adds a REST sample and test for AML AI. The implementation looks good, and the inclusion of tests and adherence to the contribution guidelines is commendable. Here are a few suggestions for improvement:
| permissions: | ||
| contents: 'read' | ||
| id-token: 'write' | ||
| if: github.event.action != 'labeled' || github.event.label.name == 'actions:force-run' |
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.
Consider adding a comment explaining the purpose of the actions:force-run label and when it should be used.
| if: github.event.action != 'labeled' || github.event.label.name == 'actions:force-run' | |
| if: github.event.action != 'labeled' || github.event.label.name == 'actions:force-run' # Allows manual rerun via label |
| permissions: | ||
| contents: 'read' | ||
| id-token: 'write' | ||
| if: github.event_name == 'schedule' && always() # always() submits logs even if tests fail |
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.
| scopes: 'https://www.googleapis.com/auth/cloud-platform', | ||
| headers: {'Content-Type': 'application/json; charset=utf-8'}, | ||
| }); | ||
| // TODO(developer): update the project ID as needed |
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 TODO should be more specific about how the developer should update the project ID. Is it via an environment variable? Should it be hardcoded? Provide an example.
| // TODO(developer): update the project ID as needed | |
| // TODO(developer): Replace with your project ID. For example: | |
| // const projectId = 'my-project-id'; |
| try { | ||
| response = await client.request({url, method: 'GET'}); | ||
| } catch (err) { | ||
| throw new Error(`API request failed: ${err}`); |
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.
Instead of just logging the error message, consider including the original error object (err) as well. This can be helpful for debugging. Also, consider logging the status code if available.
| throw new Error(`API request failed: ${err}`); | |
| throw new Error(`API request failed: ${err.message} (status: ${err.status}, error: ${err})`); |
| console.log(JSON.stringify(response.data)); | ||
| }; | ||
|
|
||
| return await listLocations(); |
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.
| const cloudRegion = 'us-central1'; | ||
|
|
||
| it('should get the AML AI API locations', () => { | ||
| const output = execSync('node listLocations.js', {cwd}); |
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.
It's good practice to assert on the full response or specific fields within the response data, rather than just checking if a string is included. This makes the test more robust and less prone to false positives. Also, consider using JSON.parse() to parse the output and assert on the structured data.
| const output = execSync('node listLocations.js', {cwd}); | |
| const output = JSON.parse(execSync('node listLocations.js', {cwd})); | |
| assert.ok(output.locations.some(location => location.locationId === cloudRegion)); |
Description
Fixes b: 355523386
Note: Before submitting a pull request, please open an issue for discussion if you are not associated with Google.
Checklist
npm test(see Testing)npm run lint(see Style)GoogleCloudPlatform/nodejs-docs-samples. Not a fork.