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

Incorrect code suggestion #505

Open
alvin-r opened this issue Nov 18, 2024 · 1 comment
Open

Incorrect code suggestion #505

alvin-r opened this issue Nov 18, 2024 · 1 comment
Assignees
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@alvin-r
Copy link

alvin-r commented Nov 18, 2024

Environment details

  • OS: macOS 14.5
  • Node.js version: v22.7.0
  • npm version: 10.8.2
  • code-suggester version: 4.3.4

Steps to reproduce

You can recreate my PR at https://github.com/alvin-r/code-suggester-bug/pull/1/files.

  1. Create a PR, adding a new file with the name 'common_tags.py' with:
from __future__ import annotations


def find_common_tags(articles: list[dict[str, list[str]]]) -> set[str]:
    if not articles:
        return set()

    common_tags = articles[0]["tags"]
    for article in articles[1:]:
        common_tags = [tag for tag in common_tags if tag in article["tags"]]
    return set(common_tags)
  1. Use the reviewPullRequest. You can use this script:
import { Octokit } from "@octokit/rest"
import { reviewPullRequest } from "code-suggester"

async function reviewPR() {
  // Initialize authenticated Octokit instance
  const octokit = new Octokit({
    auth: <YOUR_GITHUB_TOKEN>,
  })

  // Define the files to review with their changes
  const diffContents = new Map()
  diffContents.set("common_tags.py", {
    oldContent: `from __future__ import annotations


def find_common_tags(articles: list[dict[str, list[str]]]) -> set[str]:
    if not articles:
        return set()

    common_tags = articles[0]["tags"]
    for article in articles[1:]:
        common_tags = [tag for tag in common_tags if tag in article["tags"]]
    return set(common_tags)`,

    newContent: `from __future__ import annotations


def find_common_tags(articles: list[dict[str, list[str]]]) -> set[str]:
    if not articles:
        return set()

    common_tags = set(articles[0]["tags"])
    for article in articles[1:]:
        common_tags.intersection_update(article["tags"])
    return common_tags`,
  })

  // Configure review options
  const options = {
    owner: "alvin-r",
    repo: "code-suggester-bug",
    pullNumber: 1,
    pageSize: 100,
  }

  try {
    const result = await reviewPullRequest(octokit, diffContents, options)
    console.log("Review completed:", result)
  } catch (error) {
    console.error("Review failed:", error)
  }
}

reviewPR()
  1. When the review is created, the suggested code does not remove the 'return set(common_tags)' from the original code. You can see the comment created in https://github.com/alvin-r/code-suggester-bug/pull/1/files.
@alvin-r alvin-r added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Nov 18, 2024
@misrasaurabh1
Copy link

Hi @chingor13 , we running into many other bugs with code-suggester as I am using it for codeflash.ai's github diff creation. Would appreciate a quick look here at the bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

3 participants