-
Notifications
You must be signed in to change notification settings - Fork 0
feat: test creation and commit in /tests #13
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import os | ||
| import subprocess | ||
|
|
||
| def commit_tests(): | ||
| try: | ||
| branch = os.getenv("GITHUB_HEAD_REF") # PR branch | ||
|
|
||
| subprocess.run(["git", "config", "user.name", "github-actions"], check=True) | ||
| subprocess.run(["git", "config", "user.email", "actions@github.com"], check=True) | ||
|
|
||
| subprocess.run(["git", "add", "tests/"], check=True) | ||
| subprocess.run(["git", "commit", "-m", "Add AI-generated tests"], check=True) | ||
|
|
||
| subprocess.run(["git", "push", "origin", f"HEAD:{branch}"], check=True) | ||
|
|
||
| print("Tests pushed to PR branch") | ||
|
|
||
| except Exception as e: | ||
| print("Commit Failed", e) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,7 +34,12 @@ def generate_tests(diff:str,context:list =None)->str: | |
| } | ||
| ], | ||
| ) | ||
| return response.choices[0].message.content.strip() | ||
| content =response.choices[0].message.content.strip() | ||
| if content.startswith("```"): | ||
| content = content.split("```")[1] # Extract code from markdown | ||
| if content.startswith("python"): | ||
| content = content[len("python"):] # Remove language specifier | ||
| return content.strip() | ||
|
Comment on lines
+37
to
+42
|
||
| except Exception as e: | ||
| return f"Error generating tests:{str(e)}" | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3,8 +3,8 @@ | |||||
| from agent.indexing.embedder import get_embeddings | ||||||
| from agent.indexing.vector_store import store_embeddings, query_embeddings | ||||||
| from agent.llm.test_generator import generate_tests | ||||||
|
|
||||||
| import subprocess | ||||||
| from agent.github.committer import commit_tests | ||||||
|
||||||
| from agent.github.committer import commit_tests | |
| from agent.github.commiter import commit_tests |
Copilot
AI
Mar 31, 2026
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 generated test content is written directly to tests/test_generated.py even when generate_tests() returns an error string (it returns "Error generating tests:..." on exceptions). This can lead to committing a non-test error message into the repository. Consider checking for the error sentinel (or otherwise validating that the output is Python test code) before writing/committing.
Copilot
AI
Mar 31, 2026
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.
commit_tests() is called unconditionally in the PR workflow. Combined with the workflow trigger on pull_request and a constant commit message, this can create repeated commits / reruns, or attempts to commit when nothing changed. Add a guard (e.g., only commit when tests/test_generated.py differs, and/or skip when the actor is the actions bot / commit message matches).
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import pytest | ||
| import os | ||
| from agent.github.committer import commit_tests | ||
| from agent.main import get_pr_diff | ||
|
|
||
| def test_commit_tests(): | ||
| commit_tests() | ||
|
|
||
| def test_get_pr_diff_empty(): | ||
| with pytest.raises(subprocess.CalledProcessError): | ||
| get_pr_diff() | ||
|
|
||
| def test_commit_tests_exception(): | ||
| try: | ||
| commit_tests() | ||
| except Exception as e: | ||
| assert str(e) | ||
|
|
||
| def test_get_pr_diff_no_diff(): | ||
| diff = get_pr_diff() | ||
| assert diff.strip() == "" | ||
|
|
||
| def test_commit_tests_push(): | ||
| subprocess.run(["git", "config", "user.name", "github-actions"], check=True) | ||
| subprocess.run(["git", "config", "user.email", "actions@github.com"], check=True) | ||
| commit_tests() |
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.
Changing
contentspermission towriteenables pushing commits from this workflow. Onpull_requesttriggers this has two concrete risks: (1) the push can retrigger the workflow and create a commit loop unless you add explicit safeguards, and (2) for fork PRs the token won’t be able to push anyway, so the job will repeatedly attempt/fail. Consider addingif:guards (e.g., only run on non-fork PRs and skip whengithub.actoris the actions bot), and ensure checkout/push targets the PR head branch if committing is intended.