Skip to content

Commit 9169878

Browse files
authored
[Repo Assist] test(rust-guard): add list_commits tests for default-branch vs feature-branch integrity (#6095)
🤖 *This PR was created by Repo Assist, an automated AI assistant.* ## Summary Adds two unit tests to `response_paths.rs` for the `list_commits` handler — the only response-path handler that had **zero test coverage** (identified in issue #6086, Improvement 2). ## Why This Matters The `sha` field in `list_commits` tool args drives `is_default_branch_ref()` → merged-level integrity promotion. This is a **security-relevant decision**: a regression that treats all commits as default-branch would silently over-elevate integrity labels, allowing feature-branch commits to be treated as if they had merged status. ## Tests Added | Test | Scenario | Assertion | |------|----------|-----------| | `list_commits_default_branch_gets_merged_integrity` | `sha = "main"` | `default_labels.integrity` contains `merged:octocat/hello-world`; `items_path` is `None` (root array) | | `list_commits_feature_branch_public_repo_has_no_merged_integrity` | `sha = "feature/my-branch"` | `default_labels.integrity` has no `merged:` prefix; `items_path` is `None` | Both tests are self-contained and require no backend mocking (the `is_repo_private` backend returns `None` → `false` in `#[cfg(test)]`). ## Test Status ``` running 413 tests test result: ok. 413 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out ``` (411 pre-existing + 2 new) Closes #6086 (Improvement 2) > Generated by [Repo Assist](https://github.com/github/gh-aw-mcpg/actions/runs/26165758577/agentic_workflow) · ● 5.7M · [◷](https://github.com/search?q=repo%3Agithub%2Fgh-aw-mcpg+%22gh-aw-workflow-id%3A+repo-assist%22&type=pullrequests) > > To install this [agentic workflow](https://github.com/githubnext/agentics/blob/851905c06e905bf362a9f6cc54f912e3df747d55/workflows/repo-assist.md), run > ``` > gh aw add githubnext/agentics@851905c > ``` <!-- gh-aw-agentic-workflow: Repo Assist, engine: copilot, version: 1.0.40, model: claude-sonnet-4.6, id: 26165758577, workflow_id: repo-assist, run: https://github.com/github/gh-aw-mcpg/actions/runs/26165758577 --> <!-- gh-aw-workflow-id: repo-assist -->
2 parents 2c61c05 + cda9f33 commit 9169878

1 file changed

Lines changed: 88 additions & 0 deletions

File tree

guards/github-guard/rust-guard/src/labels/response_paths.rs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,4 +751,92 @@ mod tests {
751751
let result = label_response_paths("unknown_tool", &json!({}), &json!({}), &ctx());
752752
assert!(result.is_none(), "unknown tool should produce no path labels");
753753
}
754+
755+
// === list_commits tests ===
756+
// The sha field drives is_default_branch → merged-level integrity, which is a
757+
// security-relevant decision. A regression here (e.g. treating all commits as
758+
// default-branch) would over-elevate integrity labels. Both tests are self-contained
759+
// and require no backend mocking.
760+
761+
#[test]
762+
fn list_commits_default_branch_gets_merged_integrity() {
763+
let tool_args = json!({"owner": "octocat", "repo": "hello-world", "sha": "main"});
764+
let commit = json!({
765+
"sha": "abc1234def5678",
766+
"commit": {"message": "fix: a bug"},
767+
"author": {"login": "octocat"},
768+
"author_association": "OWNER"
769+
});
770+
let response = json!({
771+
"content": [{
772+
"type": "text",
773+
"text": serde_json::to_string(&json!([commit])).expect("response should serialize")
774+
}]
775+
});
776+
777+
let result = label_response_paths("list_commits", &tool_args, &response, &ctx())
778+
.expect("list_commits should produce path labels");
779+
780+
assert_eq!(result.labeled_paths.len(), 1);
781+
assert_eq!(result.labeled_paths[0].path, "/0");
782+
assert!(
783+
result.items_path.is_none(),
784+
"list_commits root array should have items_path = None, got {:?}",
785+
result.items_path
786+
);
787+
788+
// Default branch (main) → default_labels integrity must include a merged: label
789+
let default_integrity = &result
790+
.default_labels
791+
.as_ref()
792+
.expect("default_labels should be set")
793+
.integrity;
794+
let merged_label = format!("{}octocat/hello-world", label_constants::MERGED_PREFIX);
795+
assert!(
796+
default_integrity.contains(&merged_label),
797+
"default-branch default_labels should have merged-level integrity; got {:?}",
798+
default_integrity
799+
);
800+
}
801+
802+
#[test]
803+
fn list_commits_feature_branch_public_repo_has_no_merged_integrity() {
804+
let tool_args =
805+
json!({"owner": "octocat", "repo": "hello-world", "sha": "feature/my-branch"});
806+
let commit = json!({
807+
"sha": "deadbeef12345678",
808+
"commit": {"message": "wip: in progress"},
809+
"author_association": "CONTRIBUTOR"
810+
});
811+
let response = json!({
812+
"content": [{
813+
"type": "text",
814+
"text": serde_json::to_string(&json!([commit])).expect("response should serialize")
815+
}]
816+
});
817+
818+
let result = label_response_paths("list_commits", &tool_args, &response, &ctx())
819+
.expect("list_commits should produce path labels");
820+
821+
assert_eq!(result.labeled_paths.len(), 1);
822+
assert!(
823+
result.items_path.is_none(),
824+
"list_commits root array should have items_path = None"
825+
);
826+
827+
// Non-default branch of public repo (is_repo_private returns None → false in
828+
// test cfg) → default_labels integrity must NOT contain any merged: label.
829+
let default_integrity = &result
830+
.default_labels
831+
.as_ref()
832+
.expect("default_labels should be set")
833+
.integrity;
834+
assert!(
835+
!default_integrity
836+
.iter()
837+
.any(|l| l.starts_with(label_constants::MERGED_PREFIX)),
838+
"feature-branch commit on public repo should NOT have merged-level integrity; got {:?}",
839+
default_integrity
840+
);
841+
}
754842
}

0 commit comments

Comments
 (0)