bmordue / lgm

https://lgm-xi.vercel.app
0 stars 0 forks source link

Sweep: make all API endpoints idempotent #55

Closed bmordue closed 1 year ago

bmordue commented 1 year ago

Details

Identify any API endpoints that cannot reasonably easily be made idempotent. So when I make two identical requests to any endpoint, the responses are identical, and no internal state should change.

Checklist - [X] Modify `api/api.yml` ! No changes made - [X] Modify `lib/controllers/GameController.ts` ✓ https://github.com/bmordue/lgm/commit/a3ff5c7cf6b44be90b7d6f64533bb0f1ec22f350 - [X] Ran sandbox for `lib/controllers/GameController.ts`. ✗ - [X] Modify `lib/controllers/GameController.ts` ✓ https://github.com/bmordue/lgm/commit/64a29d0c5c099e83504418c825b05317c13edee3 - [X] Ran sandbox for `lib/controllers/GameController.ts`. ✓ https://github.com/bmordue/lgm/commit/040d37ddca9039cb55e522c425092d3a81421b0d - [X] Ran sandbox for `lib/controllers/GameController.ts`. ✓ - [X] Modify `lib/service/GameService.ts` ✓ https://github.com/bmordue/lgm/commit/8bff271646253f18a32f3b886bba92e206f781cc - [X] Ran sandbox for `lib/service/GameService.ts`. ✓ https://github.com/bmordue/lgm/commit/76399764a3aa1b542dfb00bb9ac44028c4ecbc47 - [X] Modify `README.md` ✓ https://github.com/bmordue/lgm/commit/bd6741ac558387d0f063f9d0dae4aabcd43df247 - [X] Ran sandbox for `README.md`. ✓ https://github.com/bmordue/lgm/commit/ae2e935a4f21fd08370f76bac12f26be2f852592 ![Flowchart](https://raw.githubusercontent.com/bmordue/lgm/sweep/assets/51d9914060dc2d8a20c1ad9b11eb776dd45993133e3815f67913fa5b48817843_55_flowchart.svg)
sweep-ai[bot] commented 1 year ago

Here's the PR! https://github.com/bmordue/lgm/pull/56.

Sweep Basic Tier: I'm using GPT-4. You have 5 GPT-4 tickets left for the month and 3 for the day. (tracking ID: 7a274f093e)

For more GPT-4 tickets, visit our payment portal. For a one week free trial, try Sweep Pro (unlimited GPT-4 tickets).

Actions (click)

Sandbox Execution ✓

Here are the sandbox execution logs prior to making any changes:

Sandbox logs for d57dea6
npm i 1/4 ✓
added 663 packages, and audited 664 packages in 23s
117 packages are looking for funding
  run `npm fund` for details
3 moderate severity vulnerabilities
To address all issues (including breaking changes), run:
  npm audit fix --force
Run `npm audit` for details.
npm notice 
npm notice New major version of npm available! 9.6.7 -> 10.2.4
npm notice Changelog: 
npm notice Run `npm install -g npm@10.2.4` to update!
npm notice 
trunk init 2/4 ✓
⡿ Downloading Trunk 1.17.2...
⡿ Downloading Trunk 1.17.2...
⢿ Downloading Trunk 1.17.2...
⣻ Downloading Trunk 1.17.2...
⣽ Downloading Trunk 1.17.2...
⣾ Downloading Trunk 1.17.2...
⣷ Downloading Trunk 1.17.2...
⣯ Downloading Trunk 1.17.2...
⣟ Downloading Trunk 1.17.2...
⡿ Downloading Trunk 1.17.2...
⢿ Downloading Trunk 1.17.2...
⣻ Downloading Trunk 1.17.2...
⣽ Downloading Trunk 1.17.2...
⣾ Downloading Trunk 1.17.2...
✔ Downloading Trunk 1.17.2... done
⡿ Verifying Trunk sha256...
✔ Verifying Trunk sha256... done
⡿ Unpacking Trunk...
✔ Unpacking Trunk... done

✔ 10 linters were enabled (.trunk/trunk.yaml)
  actionlint 1.6.26 (3 github-workflow files)
  checkov 3.1.9 (7 json, 9 yaml files)
  eslint 8.54.0 (1 javascript, 17 typescript files)
  git-diff-check (38 files)
  markdownlint 0.37.0 (1 markdown file) (created .markdownlint.yaml)
  osv-scanner 1.4.3 (1 lockfile file)
  prettier 3.1.0 (1 javascript, 6 json, 1 markdown, 17 typescript, 9 yaml files)
  trivy 0.47.0 (9 yaml files)
  trufflehog 3.63.2-rc0 (39 files)
  yamllint 1.33.0 (9 yaml files) (created .yamllint.yaml)
Next Steps
 1. Read documentation
    Our documentation can be found at https://docs.trunk.io
 2. Get help and give feedback
    Join the Trunk community at https://slack.trunk.io
trunk fmt api/api.yml || exit 0 3/4 ✓
Checked 1 file
✔ No issues
trunk check --fix --print-failures api/api.yml 4/4 ✓
Checked 1 file
✔ No issues

Sandbox passed on the latest main, so sandbox checks will be enabled for this issue.


Step 1: 🔎 Searching

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I looked at (click to expand). If some file is missing from here, you can mention the path in the ticket description. https://github.com/bmordue/lgm/blob/d57dea6bd2514f9bd169b0123c55fc2b57d7c9e3/README.md#L1-L40 https://github.com/bmordue/lgm/blob/d57dea6bd2514f9bd169b0123c55fc2b57d7c9e3/lib/service/Rules.ts#L99-L203

Step 2: ⌨️ Coding

trunk fmt lib/controllers/GameController.ts || exit 0 1/2 ✓
  FAILURES  
 prettier  lib/controllers/GameController.ts  .trunk/out/sXep3.yaml
  NOTICES  
 A tool failed to run. You can open the details yaml file for more information.
Checked 0 files
✖ No issues, 1 failure
trunk check --fix --print-failures lib/controllers/GameController.ts 2/2 ❌ (`1`)
  ISSUES  
lib/controllers/GameController.ts:35:0
 35:0  high  Parsing error: Declaration or statement expected.  eslint/
  FAILURES  
 prettier  lib/controllers/GameController.ts  .trunk/out/Q3Rdu.yaml
  NOTICES  
 A tool failed to run. You can open the details yaml file for more information.
Checked 1 file
✖ 1 new issue
# .trunk/out/Q3Rdu.yaml
trunk_cli_version: 1.17.2
title: prettier exited with exit_code=2
report:
  - prettier exited with exit_code=2
  - linter:
      command: |
        /root/.cache/trunk/tools/prettier/3.1.0-a552fdee5ef3daae1274e7dca8183c14/node_modules/.bin/prettier -w lib/controllers/GameController.ts
      stdin_path: (none)
      run_from: /tmp/trunk-0/Y8dlw3/FBgEV0
      timeout: 10m
      rerun: (cd /tmp/trunk-0/Y8dlw3/FBgEV0; env -i PATH=/root/.cache/trunk/tools/prettier/3.1.0-a552fdee5ef3daae1274e7dca8183c14/node_modules/.bin:/root/.cache/trunk/tools/node/18.12.1-00ae74f39ac4de3ff3c7e3686016ebf3/bin:/root/.cache/trunk/tools/node/18.12.1-00ae74f39ac4de3ff3c7e3686016ebf3:/root/.nvm/versions/node/v18.17.0/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin HOME=/root NODE_PATH=/root/.cache/trunk/tools/prettier/3.1.0-a552fdee5ef3daae1274e7dca8183c14/node_modules /root/.cache/trunk/tools/prettier/3.1.0-a552fdee5ef3daae1274e7dca8183c14/node_modules/.bin/prettier -w lib/controllers/GameController.ts)
      affects_cache:
        - package.json
      direct_configs:
        []
      exit_status: exited
      exit_code: 2
      stdout: (none)
      stderr: |
        [error] lib/controllers/GameController.ts: SyntaxError: Declaration or statement expected. (35:1)
        [error]   33 |     const playerId = context.params.path.playerId;
        [error]   34 |     return GameService.turnResults(gameId, turn, playerId);
        [error] > 35 | };
        [error]      | ^
        [error]   36 |     const turn = context.params.path.turn;
        [error]   37 |     const playerId = context.params.path.playerId;
        [error]   38 |     return GameService.turnResults(gameId, turn, playerId);
    parser: |
      (none)

trunk fmt lib/controllers/GameController.ts || exit 0 1/2 ✓
 ✔ Formatted lib/controllers/GameController.ts
Re-checking autofixed files...

Checked 1 file
✔ No issues
trunk check --fix --print-failures lib/controllers/GameController.ts 2/2 ✓
Checked 1 file
✔ No issues

trunk fmt lib/controllers/GameController.ts || exit 0 1/2 ✓
Checked 1 file
✔ No issues
trunk check --fix --print-failures lib/controllers/GameController.ts 2/2 ✓
Checked 1 file
✔ No issues

trunk fmt lib/service/GameService.ts || exit 0 1/2 ✓
 ✔ Formatted lib/service/GameService.ts
Re-checking autofixed files...

Checked 1 file
✔ No issues
trunk check --fix --print-failures lib/service/GameService.ts 2/2 ✓
Checked 1 file
✔ No issues

trunk fmt README.md || exit 0 1/2 ✓
 ✔ Formatted README.md
Re-checking autofixed files...

Checked 1 file
✔ No issues
trunk check --fix --print-failures README.md 2/2 ✓
  ISSUES  
README.md:11:0
 11:0  low  Fenced code blocks should have a language specified  markdownlint/MD040
 32:0  low  Multiple top-level headings in the same document     markdownlint/MD025
Checked 1 file
2 existing issues


Step 3: 🔁 Code Review

I have finished reviewing the code for completeness. I did not find errors for sweep/idempotent-endpoints.


🎉 Latest improvements to Sweep:


💡 To recreate the pull request edit the issue title or description. To tweak the pull request, leave a comment on the pull request. Join Our Discord