-
Notifications
You must be signed in to change notification settings - Fork 0
Tell the reviewer which repository it is reading #98
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
Merged
+143
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "os/exec" | ||
| "strings" | ||
| "testing" | ||
| ) | ||
|
|
||
| // Reviews on kai-desktop#288 and kai-desktop#300 (2026-09-08) stated they were | ||
| // reading "the kai-engine repo" and "the kai-server working tree". Nothing in | ||
| // the run could have told them otherwise: the CI job clones into `mktemp -d`, | ||
| // so the workspace is a random path, and the prompt named the repository | ||
| // nowhere — while rcReviewSystem requires one in the output. These assert the | ||
| // answer is now supplied rather than guessed. | ||
| func TestRepoIdentityPrefersTheWorkflowsOwnAnswer(t *testing.T) { | ||
| // GITHUB_REPOSITORY_FULLNAME wins, because the CI workflow prefers it for | ||
| // exactly the case where the kai org name and the GitHub org name differ. | ||
| t.Setenv("GITHUB_REPOSITORY_FULLNAME", "kaicontext/kai-desktop") | ||
| t.Setenv("GITHUB_REPOSITORY", "kai/kai-desktop") | ||
| if got := rcRepoIdentity(t.TempDir()); got != "kaicontext/kai-desktop" { | ||
| t.Errorf("rcRepoIdentity = %q, want the GitHub-side slug", got) | ||
| } | ||
| } | ||
|
|
||
| func TestRepoIdentityFallsBackToGithubRepository(t *testing.T) { | ||
| t.Setenv("GITHUB_REPOSITORY_FULLNAME", "") | ||
| t.Setenv("GITHUB_REPOSITORY", "kaicontext/kai-cli") | ||
| if got := rcRepoIdentity(t.TempDir()); got != "kaicontext/kai-cli" { | ||
| t.Errorf("rcRepoIdentity = %q, want kaicontext/kai-cli", got) | ||
| } | ||
| } | ||
|
|
||
| // The local path: a human running `kai review-commit` has no GitHub | ||
| // environment at all, and the checkout's own remote is the answer. | ||
| func TestRepoIdentityReadsTheOriginRemote(t *testing.T) { | ||
| t.Setenv("GITHUB_REPOSITORY_FULLNAME", "") | ||
| t.Setenv("GITHUB_REPOSITORY", "") | ||
| dir := t.TempDir() | ||
| for _, args := range [][]string{ | ||
| {"init", "--quiet"}, | ||
| {"remote", "add", "origin", "git@github.com:kaicontext/kai-desktop.git"}, | ||
| } { | ||
| cmd := exec.Command("git", args...) | ||
| cmd.Dir = dir | ||
| if out, err := cmd.CombinedOutput(); err != nil { | ||
| t.Skipf("git %v unavailable here: %v (%s)", args, err, out) | ||
| } | ||
| } | ||
| if got := rcRepoIdentity(dir); got != "kaicontext/kai-desktop" { | ||
| t.Errorf("rcRepoIdentity = %q, want the slug from the origin remote", got) | ||
| } | ||
| } | ||
|
|
||
| // Nothing resolves: say nothing. An unnamed boundary is recoverable, a | ||
| // confidently wrong one is not — inventing a name here would rebuild the | ||
| // defect this closes. | ||
| func TestRepoIdentityStaysSilentWhenItCannotTell(t *testing.T) { | ||
| t.Setenv("GITHUB_REPOSITORY_FULLNAME", "") | ||
| t.Setenv("GITHUB_REPOSITORY", "") | ||
| if got := rcRepoIdentity(t.TempDir()); got != "" { | ||
| t.Errorf("rcRepoIdentity = %q in a non-repo with no environment, want empty", got) | ||
| } | ||
| if got := rcRepoHeader(""); got != "" { | ||
| t.Errorf("rcRepoHeader(\"\") = %q, want empty", got) | ||
| } | ||
| } | ||
|
|
||
| // The header has to name the repo where the system prompt asks for it: the | ||
| // boundary sentence. Naming it once at the top and not in the instruction the | ||
| // model is following is how it got ignored before. | ||
| func TestRepoHeaderNamesTheBoundary(t *testing.T) { | ||
| got := rcRepoHeader("kaicontext/kai-desktop") | ||
| for _, want := range []string{ | ||
| "REPOSITORY: kaicontext/kai-desktop", | ||
| `within kaicontext/kai-desktop, the only caller is X`, | ||
| "Do not name a different repository", | ||
| } { | ||
| if !strings.Contains(got, want) { | ||
| t.Errorf("header missing %q:\n%s", want, got) | ||
| } | ||
| } | ||
| if !strings.HasSuffix(got, "\n\n") { | ||
| t.Error("header must end with a blank line so it does not run into AUTHOR CONTEXT") | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
prefers
GITHUB_REPOSITORY_FULLNAME, a non-standard GitHub Actions variable; no workflow in this repo sets it, and the one that does is in kai-server and out of reach, so the precedence is unverified (though it degrades gracefully toGITHUB_REPOSITORY).