fix: 修复 CLI repo 与状态别名解析
This commit is contained in:
@@ -270,6 +270,21 @@ async function startMockGitHub(): Promise<{ baseUrl: string; requests: MockReque
|
||||
updated_at: "2026-05-20T03:10:00Z",
|
||||
},
|
||||
];
|
||||
const hwlabIssueList = [
|
||||
{
|
||||
id: 7001,
|
||||
number: 7,
|
||||
title: "HWLAB generic issue fixture",
|
||||
body: "HWLAB issue list body fixture",
|
||||
state: "open",
|
||||
html_url: "https://github.com/pikasTech/HWLAB/issues/7",
|
||||
comments: 0,
|
||||
user: { login: "tester" },
|
||||
labels: [],
|
||||
created_at: "2026-05-20T02:30:00Z",
|
||||
updated_at: "2026-05-20T03:30:00Z",
|
||||
},
|
||||
];
|
||||
const scanIssues = [
|
||||
{
|
||||
id: 2501,
|
||||
@@ -505,6 +520,10 @@ async function startMockGitHub(): Promise<{ baseUrl: string; requests: MockReque
|
||||
sendJson(res, 200, issueList);
|
||||
return;
|
||||
}
|
||||
if (req.method === "GET" && req.url === "/repos/pikasTech/HWLAB/issues?state=open&per_page=2") {
|
||||
sendJson(res, 200, hwlabIssueList);
|
||||
return;
|
||||
}
|
||||
if (req.method === "GET" && req.url === "/repos/pikasTech/unidesk/issues?state=all&per_page=3") {
|
||||
sendJson(res, 200, issueList);
|
||||
return;
|
||||
@@ -654,6 +673,20 @@ export async function runGhCliIssueGuardContract(): Promise<JsonRecord> {
|
||||
assertCondition(listDefaultStateData.state === "open", "issue list should keep default state=open", listDefaultStateData);
|
||||
assertCondition(mock.requests.some((request) => request.method === "GET" && request.url === "/repos/pikasTech/unidesk/issues?state=open&per_page=2"), "issue list default should query state=open", mock.requests);
|
||||
|
||||
const positionalRepoList = await runCli(["gh", "issue", "list", "pikasTech/HWLAB", "--state", "open", "--limit", "2", "--json", "number,title,state,url"], env);
|
||||
assertCondition(positionalRepoList.status === 0, "issue list positional owner/repo should succeed", positionalRepoList.json ?? { stdout: positionalRepoList.stdout });
|
||||
const positionalRepoListData = dataOf(positionalRepoList.json ?? {});
|
||||
assertCondition(positionalRepoListData.repo === "pikasTech/HWLAB", "issue list positional repo should become the actual request repo", positionalRepoListData);
|
||||
const positionalRepoIssues = positionalRepoListData.issues as JsonRecord[];
|
||||
assertCondition(Array.isArray(positionalRepoIssues) && positionalRepoIssues[0]?.number === 7, "issue list positional repo should return HWLAB fixture issue", positionalRepoListData);
|
||||
assertCondition(mock.requests.some((request) => request.method === "GET" && request.url === "/repos/pikasTech/HWLAB/issues?state=open&per_page=2"), "issue list positional repo should query derived repo REST path", mock.requests);
|
||||
|
||||
const positionalRepoConflict = await runCli(["gh", "issue", "list", "pikasTech/HWLAB", "--repo", "pikasTech/unidesk", "--state", "open"], env);
|
||||
assertCondition(positionalRepoConflict.status !== 0, "issue list conflicting positional repo and --repo should fail", positionalRepoConflict.json ?? { stdout: positionalRepoConflict.stdout });
|
||||
const positionalRepoConflictData = failedDataOf(positionalRepoConflict.json ?? {});
|
||||
assertCondition(positionalRepoConflictData.degradedReason === "validation-failed", "issue list repo conflict should be validation-failed", positionalRepoConflictData);
|
||||
assertCondition(String((positionalRepoConflictData.details as JsonRecord)?.message ?? "").includes("positional repo pikasTech/HWLAB"), "issue list repo conflict should name positional repo", positionalRepoConflictData);
|
||||
|
||||
const listDefaultFields = await runCli(["gh", "issue", "list", "--repo", "pikasTech/unidesk", "--state", "all", "--limit", "3"], env);
|
||||
assertCondition(listDefaultFields.status === 0, "issue list should support default fields", listDefaultFields.json ?? { stdout: listDefaultFields.stdout });
|
||||
const listDefaultData = dataOf(listDefaultFields.json ?? {});
|
||||
@@ -1494,6 +1527,7 @@ export async function runGhCliIssueGuardContract(): Promise<JsonRecord> {
|
||||
"issue read/view accept owner/repo#number shorthand and reject conflicting --repo",
|
||||
"issue read/view --raw is explicit full disclosure",
|
||||
"issue list supports state/limit/json with stable selected fields",
|
||||
"issue list positional owner/repo targets the requested repo and conflicting --repo fails",
|
||||
"acceptance issue list command succeeds under mock GitHub",
|
||||
"issue list default fields include labels and filter pull requests",
|
||||
"large gh issue read output is dumped to a temp file with bounded stdout and head/tail metadata",
|
||||
|
||||
Reference in New Issue
Block a user