pr-shepherd 0.23.0 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +2 -1
- package/bin/cli/fix-formatter.mjs +2 -1
- package/bin/cli/iterate-instructions.mjs +1 -1
- package/bin/cli/list-formatters.mjs +3 -2
- package/bin/commands/check.mjs +6 -2
- package/bin/commands/iterate/classify.mjs +13 -7
- package/bin/commands/iterate/fix-code.mjs +2 -2
- package/bin/commands/iterate/index.mjs +4 -1
- package/bin/commands/iterate/render.mjs +3 -0
- package/bin/commands/iterate/stall.mjs +1 -1
- package/bin/commands/resolve-instructions.mjs +5 -2
- package/bin/commands/resolve-mutate.mjs +14 -6
- package/bin/commands/resolve.mjs +7 -3
- package/bin/comments/authors.mjs +19 -1
- package/bin/comments/minimize-policy.mjs +6 -5
- package/bin/comments/review-thread-markers.mjs +18 -0
- package/bin/comments/thread-visibility.mjs +5 -5
- package/bin/comments/visible-comments.mjs +2 -2
- package/bin/config/load.mjs +7 -0
- package/bin/config.json +14 -0
- package/bin/github/batch-parsers.mjs +2 -0
- package/bin/github/client.mjs +1 -2
- package/bin/github/gql/batch-pr.gql +3 -0
- package/bin/reporters/agent.mjs +1 -0
- package/bin/state/seen-comments.mjs +40 -4
- package/package.json +8 -4
- package/plugins/pr-shepherd/.codex-plugin/plugin.json +1 -1
- package/bin/checks/triage.test-support.mjs +0 -60
- package/bin/cli/iterate-lean.test-support.mjs +0 -3
- package/bin/cli-parser.clean.test-support.mjs +0 -44
- package/bin/cli-parser.commit-suggestion.test-support.mjs +0 -65
- package/bin/cli-parser.iterate-fix.test-support.mjs +0 -43
- package/bin/cli-parser.iterate-fixtures.mjs +0 -75
- package/bin/cli-parser.iterate.test-support.mjs +0 -44
- package/bin/cli-parser.test-support.mjs +0 -47
- package/bin/commands/check.test-support.mjs +0 -147
- package/bin/commands/clean.test-support.mjs +0 -47
- package/bin/commands/commit-suggestion.apply.test-support.mjs +0 -87
- package/bin/commands/commit-suggestion.test-support.mjs +0 -112
- package/bin/commands/iterate-stall.test-support.mjs +0 -24
- package/bin/commands/iterate-test-support.mjs +0 -150
- package/bin/commands/iterate-thread-test-support.mjs +0 -18
- package/bin/commands/iterate.fix-code-in-progress.test-support.mjs +0 -127
- package/bin/commands/poll.test-support.mjs +0 -77
- package/bin/commands/resolve.test-support.mjs +0 -116
- package/bin/commands/shepherd-journal.test-support.mjs +0 -7
- package/bin/comments/outdated.mjs +0 -15
- package/bin/comments/resolve.test-support.mjs +0 -44
- package/bin/github/batch-parsers.test-support.mjs +0 -66
- package/bin/github/batch.test-support.mjs +0 -66
- package/bin/github/client.test-support.mjs +0 -55
- package/bin/github/http.test-support.mjs +0 -51
- package/bin/state/seen-comments.test-support.mjs +0 -19
- package/bin/suggestions/patch.test-support.mjs +0 -2
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { vi, beforeEach } from "vitest";
|
|
2
|
-
vi.mock("../github/client.mts", () => ({
|
|
3
|
-
getRepoInfo: vi.fn().mockResolvedValue({ owner: "owner", name: "repo" }),
|
|
4
|
-
getCurrentPrNumber: vi.fn().mockResolvedValue(42),
|
|
5
|
-
}));
|
|
6
|
-
vi.mock("../state/seen-comments.mts", async (importOriginal) => {
|
|
7
|
-
const actual = await importOriginal();
|
|
8
|
-
return {
|
|
9
|
-
...actual,
|
|
10
|
-
loadSeenMap: vi.fn().mockResolvedValue(new Map()),
|
|
11
|
-
markSeen: vi.fn().mockResolvedValue(undefined),
|
|
12
|
-
};
|
|
13
|
-
});
|
|
14
|
-
vi.mock("../github/batch.mts", () => ({
|
|
15
|
-
fetchPrBatch: vi.fn(),
|
|
16
|
-
}));
|
|
17
|
-
vi.mock("../comments/resolve.mts", () => ({
|
|
18
|
-
autoResolveOutdated: vi.fn(),
|
|
19
|
-
applyResolveOptions: vi.fn(),
|
|
20
|
-
}));
|
|
21
|
-
vi.mock("../config/load.mts", () => ({
|
|
22
|
-
loadConfig: vi.fn().mockReturnValue({
|
|
23
|
-
resolve: {
|
|
24
|
-
shaPoll: { intervalMs: 2000, maxAttempts: 10 },
|
|
25
|
-
fetchReviewSummaries: true,
|
|
26
|
-
},
|
|
27
|
-
actions: {
|
|
28
|
-
autoResolveOutdated: true,
|
|
29
|
-
autoMarkReady: true,
|
|
30
|
-
commitSuggestions: true,
|
|
31
|
-
},
|
|
32
|
-
}),
|
|
33
|
-
}));
|
|
34
|
-
import { runResolveFetch, runResolveMutate } from "./resolve.mjs";
|
|
35
|
-
import { getCurrentPrNumber } from "../github/client.mjs";
|
|
36
|
-
import { fetchPrBatch } from "../github/batch.mjs";
|
|
37
|
-
import { autoResolveOutdated, applyResolveOptions } from "../comments/resolve.mjs";
|
|
38
|
-
import { loadConfig } from "../config/load.mjs";
|
|
39
|
-
import { loadSeenMap, markSeen, hashBody } from "../state/seen-comments.mjs";
|
|
40
|
-
const mockGetCurrentPrNumber = vi.mocked(getCurrentPrNumber);
|
|
41
|
-
const mockFetchPrBatch = vi.mocked(fetchPrBatch);
|
|
42
|
-
const mockAutoResolveOutdated = vi.mocked(autoResolveOutdated);
|
|
43
|
-
const mockApplyResolveOptions = vi.mocked(applyResolveOptions);
|
|
44
|
-
const mockLoadConfig = vi.mocked(loadConfig);
|
|
45
|
-
const mockLoadSeenMap = vi.mocked(loadSeenMap);
|
|
46
|
-
const mockMarkSeen = vi.mocked(markSeen);
|
|
47
|
-
const BASE_OPTS = { format: "text" };
|
|
48
|
-
function makeBatchData(overrides = {}) {
|
|
49
|
-
return {
|
|
50
|
-
nodeId: "PR_kgDOAAA",
|
|
51
|
-
number: 42,
|
|
52
|
-
state: "OPEN",
|
|
53
|
-
isDraft: false,
|
|
54
|
-
mergeable: "MERGEABLE",
|
|
55
|
-
mergeStateStatus: "CLEAN",
|
|
56
|
-
reviewDecision: "APPROVED",
|
|
57
|
-
headRefOid: "abc123",
|
|
58
|
-
headRefName: "feature",
|
|
59
|
-
headRepoWithOwner: "owner/repo",
|
|
60
|
-
baseRefName: "main",
|
|
61
|
-
reviewRequests: [],
|
|
62
|
-
latestReviews: [],
|
|
63
|
-
reviewThreads: [],
|
|
64
|
-
comments: [],
|
|
65
|
-
changesRequestedReviews: [],
|
|
66
|
-
reviewSummaries: [],
|
|
67
|
-
approvedReviews: [],
|
|
68
|
-
checks: [],
|
|
69
|
-
branchProtection: null,
|
|
70
|
-
...overrides,
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
function makeThread(overrides = {}) {
|
|
74
|
-
return {
|
|
75
|
-
id: "t-1",
|
|
76
|
-
isResolved: false,
|
|
77
|
-
isOutdated: false,
|
|
78
|
-
isMinimized: false,
|
|
79
|
-
path: "src/foo.ts",
|
|
80
|
-
line: 1,
|
|
81
|
-
startLine: null,
|
|
82
|
-
author: "alice",
|
|
83
|
-
authorType: "Unknown",
|
|
84
|
-
body: "fix this",
|
|
85
|
-
url: "",
|
|
86
|
-
createdAtUnix: 1_700_000_000,
|
|
87
|
-
...overrides,
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
function makeComment(overrides = {}) {
|
|
91
|
-
return {
|
|
92
|
-
id: "c-1",
|
|
93
|
-
isMinimized: false,
|
|
94
|
-
author: "bob",
|
|
95
|
-
authorType: "Unknown",
|
|
96
|
-
body: "nit",
|
|
97
|
-
url: "",
|
|
98
|
-
createdAtUnix: 1_700_000_000,
|
|
99
|
-
...overrides,
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
export function registerHooks() {
|
|
103
|
-
beforeEach(() => {
|
|
104
|
-
vi.clearAllMocks();
|
|
105
|
-
mockFetchPrBatch.mockResolvedValue({ data: makeBatchData() });
|
|
106
|
-
mockAutoResolveOutdated.mockResolvedValue({ resolved: [], errors: [] });
|
|
107
|
-
mockApplyResolveOptions.mockResolvedValue({
|
|
108
|
-
repliedThreads: [],
|
|
109
|
-
resolvedThreads: [],
|
|
110
|
-
minimizedComments: [],
|
|
111
|
-
dismissedReviews: [],
|
|
112
|
-
errors: [],
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
export { BASE_OPTS, applyResolveOptions, autoResolveOutdated, fetchPrBatch, getCurrentPrNumber, hashBody, loadConfig, loadSeenMap, makeBatchData, makeComment, makeThread, markSeen, mockApplyResolveOptions, mockAutoResolveOutdated, mockFetchPrBatch, mockGetCurrentPrNumber, mockLoadConfig, mockLoadSeenMap, mockMarkSeen, runResolveFetch, runResolveMutate, };
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { buildShepherdJournalInstruction, SHEPHERD_JOURNAL_APPEND_HINT, SHEPHERD_JOURNAL_FIRST_LOOK_GUIDANCE, SHEPHERD_JOURNAL_REFERENCE_GUIDANCE_THREADS_AND_COMMENTS_IN_ITEM_HEADINGS, SHEPHERD_JOURNAL_REFERENCE_GUIDANCE_THREADS_AND_COMMENTS_IN_ITEMS, SHEPHERD_JOURNAL_SECTION, SHEPHERD_JOURNAL_SECTION_PATTERN, } from "./shepherd-journal.mjs";
|
|
2
|
-
import { buildFixInstructions } from "./iterate/render.mjs";
|
|
3
|
-
import { buildFetchInstructions } from "./resolve-instructions.mjs";
|
|
4
|
-
function countMentions(text, phrase) {
|
|
5
|
-
return (text.match(new RegExp(phrase, "g")) ?? []).length;
|
|
6
|
-
}
|
|
7
|
-
export { SHEPHERD_JOURNAL_APPEND_HINT, SHEPHERD_JOURNAL_FIRST_LOOK_GUIDANCE, SHEPHERD_JOURNAL_REFERENCE_GUIDANCE_THREADS_AND_COMMENTS_IN_ITEMS, SHEPHERD_JOURNAL_REFERENCE_GUIDANCE_THREADS_AND_COMMENTS_IN_ITEM_HEADINGS, SHEPHERD_JOURNAL_SECTION, SHEPHERD_JOURNAL_SECTION_PATTERN, buildFetchInstructions, buildFixInstructions, buildShepherdJournalInstruction, countMentions, };
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Determines which review threads should be auto-resolved as outdated.
|
|
3
|
-
*
|
|
4
|
-
* A thread is eligible for auto-resolution when:
|
|
5
|
-
* - `isOutdated == true` (GitHub marks these when the diff hunk changed), AND
|
|
6
|
-
* - `isResolved == false`.
|
|
7
|
-
*
|
|
8
|
-
* GitHub's `isOutdated` flag means the thread's referenced code has changed
|
|
9
|
-
* enough that the comment no longer points to a live diff line. These threads
|
|
10
|
-
* are visually collapsed on GitHub and are safe to resolve programmatically.
|
|
11
|
-
*/
|
|
12
|
-
/** Returns the subset of threads that should be auto-resolved as outdated. */
|
|
13
|
-
export function getOutdatedThreads(threads) {
|
|
14
|
-
return threads.filter((t) => t.isOutdated && !t.isResolved);
|
|
15
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { vi, beforeEach } from "vitest";
|
|
2
|
-
// ---------------------------------------------------------------------------
|
|
3
|
-
// Mock github/client.mts before any imports.
|
|
4
|
-
// ---------------------------------------------------------------------------
|
|
5
|
-
vi.mock("../github/client.mts", () => ({
|
|
6
|
-
graphqlWithRateLimit: vi.fn(),
|
|
7
|
-
getPrHeadSha: vi.fn(),
|
|
8
|
-
}));
|
|
9
|
-
import { applyResolveOptions, autoResolveOutdated } from "./resolve.mjs";
|
|
10
|
-
import { graphqlWithRateLimit, getPrHeadSha } from "../github/client.mjs";
|
|
11
|
-
const mockGraphql = vi.mocked(graphqlWithRateLimit);
|
|
12
|
-
const mockGetPrHeadSha = vi.mocked(getPrHeadSha);
|
|
13
|
-
const REPO = { owner: "owner", name: "repo" };
|
|
14
|
-
/** Build a mock response with the correct nested shape for each alias type (r/m/d). */
|
|
15
|
-
function makeBulkResponse(doc) {
|
|
16
|
-
const str = typeof doc === "string" ? doc : "";
|
|
17
|
-
const data = {};
|
|
18
|
-
for (const match of str.matchAll(/^\s+([a-z]\d+):/gm)) {
|
|
19
|
-
const alias = match[1];
|
|
20
|
-
if (alias === undefined)
|
|
21
|
-
continue;
|
|
22
|
-
if (alias.startsWith("r"))
|
|
23
|
-
data[alias] = { thread: { isResolved: true } };
|
|
24
|
-
else if (alias.startsWith("p"))
|
|
25
|
-
data[alias] = { comment: { id: `${alias}-comment` } };
|
|
26
|
-
else if (alias.startsWith("m"))
|
|
27
|
-
data[alias] = { minimizedComment: { isMinimized: true } };
|
|
28
|
-
else if (alias.startsWith("d"))
|
|
29
|
-
data[alias] = { pullRequestReview: { state: "DISMISSED" } };
|
|
30
|
-
else
|
|
31
|
-
data[alias] = {};
|
|
32
|
-
}
|
|
33
|
-
return { data };
|
|
34
|
-
}
|
|
35
|
-
// ---------------------------------------------------------------------------
|
|
36
|
-
// applyResolveOptions
|
|
37
|
-
// ---------------------------------------------------------------------------
|
|
38
|
-
export function registerHooks() {
|
|
39
|
-
beforeEach(() => {
|
|
40
|
-
vi.clearAllMocks();
|
|
41
|
-
mockGraphql.mockImplementation(async (doc) => makeBulkResponse(doc));
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
export { REPO, applyResolveOptions, autoResolveOutdated, getPrHeadSha, graphqlWithRateLimit, makeBulkResponse, mockGetPrHeadSha, mockGraphql, };
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { vi, beforeEach } from "vitest";
|
|
2
|
-
vi.mock("./client.mts", () => ({
|
|
3
|
-
graphql: vi.fn(),
|
|
4
|
-
graphqlWithRateLimit: vi.fn(),
|
|
5
|
-
}));
|
|
6
|
-
import { fetchPrBatch } from "./batch.mjs";
|
|
7
|
-
import { graphql, graphqlWithRateLimit } from "./client.mjs";
|
|
8
|
-
const mockGraphql = vi.mocked(graphql);
|
|
9
|
-
const mockGraphqlWithRateLimit = vi.mocked(graphqlWithRateLimit);
|
|
10
|
-
const REPO = { owner: "owner", name: "repo" };
|
|
11
|
-
// ---------------------------------------------------------------------------
|
|
12
|
-
// Helpers
|
|
13
|
-
// ---------------------------------------------------------------------------
|
|
14
|
-
function makeRawPr(overrides = {}) {
|
|
15
|
-
return {
|
|
16
|
-
id: "PR_kgDOAAA",
|
|
17
|
-
number: 42,
|
|
18
|
-
state: "OPEN",
|
|
19
|
-
isDraft: false,
|
|
20
|
-
mergeable: "MERGEABLE",
|
|
21
|
-
mergeStateStatus: "CLEAN",
|
|
22
|
-
reviewDecision: "APPROVED",
|
|
23
|
-
headRefOid: "abc123",
|
|
24
|
-
headRefName: "feature",
|
|
25
|
-
headRepository: { nameWithOwner: "owner/repo" },
|
|
26
|
-
baseRefName: "main",
|
|
27
|
-
reviewRequests: { nodes: [] },
|
|
28
|
-
latestReviews: { nodes: [] },
|
|
29
|
-
reviewThreads: {
|
|
30
|
-
pageInfo: { hasPreviousPage: false, startCursor: null },
|
|
31
|
-
nodes: [],
|
|
32
|
-
},
|
|
33
|
-
comments: {
|
|
34
|
-
pageInfo: { hasPreviousPage: false, startCursor: null },
|
|
35
|
-
nodes: [],
|
|
36
|
-
},
|
|
37
|
-
changesRequestedReviews: {
|
|
38
|
-
pageInfo: { hasPreviousPage: false, startCursor: null },
|
|
39
|
-
nodes: [],
|
|
40
|
-
},
|
|
41
|
-
reviewSummaries: {
|
|
42
|
-
pageInfo: { hasPreviousPage: false, startCursor: null },
|
|
43
|
-
nodes: [],
|
|
44
|
-
},
|
|
45
|
-
approvedReviews: {
|
|
46
|
-
pageInfo: { hasPreviousPage: false, startCursor: null },
|
|
47
|
-
nodes: [],
|
|
48
|
-
},
|
|
49
|
-
commits: { nodes: [{ commit: { statusCheckRollup: null } }] },
|
|
50
|
-
...overrides,
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
function makeResponse(pr = makeRawPr()) {
|
|
54
|
-
return { data: { repository: { pullRequest: pr } } };
|
|
55
|
-
}
|
|
56
|
-
// ---------------------------------------------------------------------------
|
|
57
|
-
// PR not found
|
|
58
|
-
// ---------------------------------------------------------------------------
|
|
59
|
-
export function registerHooks() {
|
|
60
|
-
beforeEach(() => {
|
|
61
|
-
vi.clearAllMocks();
|
|
62
|
-
mockGraphql.mockResolvedValue(makeResponse());
|
|
63
|
-
mockGraphqlWithRateLimit.mockResolvedValue(makeResponse());
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
export { REPO, fetchPrBatch, graphql, graphqlWithRateLimit, makeRawPr, makeResponse, mockGraphql, mockGraphqlWithRateLimit, };
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { vi, beforeEach } from "vitest";
|
|
2
|
-
vi.mock("./client.mts", () => ({
|
|
3
|
-
graphql: vi.fn(),
|
|
4
|
-
graphqlWithRateLimit: vi.fn(),
|
|
5
|
-
}));
|
|
6
|
-
import { fetchPrBatch } from "./batch.mjs";
|
|
7
|
-
import { graphql, graphqlWithRateLimit } from "./client.mjs";
|
|
8
|
-
const mockGraphql = vi.mocked(graphql);
|
|
9
|
-
const mockGraphqlWithRateLimit = vi.mocked(graphqlWithRateLimit);
|
|
10
|
-
const REPO = { owner: "owner", name: "repo" };
|
|
11
|
-
// ---------------------------------------------------------------------------
|
|
12
|
-
// Helpers
|
|
13
|
-
// ---------------------------------------------------------------------------
|
|
14
|
-
function makeRawPr(overrides = {}) {
|
|
15
|
-
return {
|
|
16
|
-
id: "PR_kgDOAAA",
|
|
17
|
-
number: 42,
|
|
18
|
-
state: "OPEN",
|
|
19
|
-
isDraft: false,
|
|
20
|
-
mergeable: "MERGEABLE",
|
|
21
|
-
mergeStateStatus: "CLEAN",
|
|
22
|
-
reviewDecision: "APPROVED",
|
|
23
|
-
headRefOid: "abc123",
|
|
24
|
-
headRefName: "feature",
|
|
25
|
-
headRepository: { nameWithOwner: "owner/repo" },
|
|
26
|
-
baseRefName: "main",
|
|
27
|
-
reviewRequests: { nodes: [] },
|
|
28
|
-
latestReviews: { nodes: [] },
|
|
29
|
-
reviewThreads: {
|
|
30
|
-
pageInfo: { hasPreviousPage: false, startCursor: null },
|
|
31
|
-
nodes: [],
|
|
32
|
-
},
|
|
33
|
-
comments: {
|
|
34
|
-
pageInfo: { hasPreviousPage: false, startCursor: null },
|
|
35
|
-
nodes: [],
|
|
36
|
-
},
|
|
37
|
-
changesRequestedReviews: {
|
|
38
|
-
pageInfo: { hasPreviousPage: false, startCursor: null },
|
|
39
|
-
nodes: [],
|
|
40
|
-
},
|
|
41
|
-
reviewSummaries: {
|
|
42
|
-
pageInfo: { hasPreviousPage: false, startCursor: null },
|
|
43
|
-
nodes: [],
|
|
44
|
-
},
|
|
45
|
-
approvedReviews: {
|
|
46
|
-
pageInfo: { hasPreviousPage: false, startCursor: null },
|
|
47
|
-
nodes: [],
|
|
48
|
-
},
|
|
49
|
-
commits: { nodes: [{ commit: { statusCheckRollup: null } }] },
|
|
50
|
-
...overrides,
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
function makeResponse(pr = makeRawPr()) {
|
|
54
|
-
return { data: { repository: { pullRequest: pr } } };
|
|
55
|
-
}
|
|
56
|
-
// ---------------------------------------------------------------------------
|
|
57
|
-
// reviewSummaries — COMMENTED reviews surfaced for agent-driven minimize
|
|
58
|
-
// ---------------------------------------------------------------------------
|
|
59
|
-
export function registerHooks() {
|
|
60
|
-
beforeEach(() => {
|
|
61
|
-
vi.clearAllMocks();
|
|
62
|
-
mockGraphql.mockResolvedValue(makeResponse());
|
|
63
|
-
mockGraphqlWithRateLimit.mockResolvedValue(makeResponse());
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
export { REPO, fetchPrBatch, graphql, graphqlWithRateLimit, makeRawPr, makeResponse, mockGraphql, mockGraphqlWithRateLimit, };
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { vi, beforeEach, afterEach } from "vitest";
|
|
2
|
-
import { _resetTokenCache } from "./http.mjs";
|
|
3
|
-
export const mockFetch = vi.fn();
|
|
4
|
-
vi.stubGlobal("fetch", mockFetch);
|
|
5
|
-
const { _mockExecFile } = vi.hoisted(() => ({ _mockExecFile: vi.fn() }));
|
|
6
|
-
export const mockExecFile = _mockExecFile;
|
|
7
|
-
vi.mock("node:child_process", () => ({
|
|
8
|
-
execFile: (cmd, args, optsOrCb, maybeCb) => {
|
|
9
|
-
const cb = typeof optsOrCb === "function" ? optsOrCb : maybeCb;
|
|
10
|
-
_mockExecFile(cmd, args)
|
|
11
|
-
.then((result) => cb(null, result))
|
|
12
|
-
.catch((err) => cb(err, { stdout: "", stderr: "" }));
|
|
13
|
-
},
|
|
14
|
-
}));
|
|
15
|
-
export function gqlOk(data) {
|
|
16
|
-
return {
|
|
17
|
-
ok: true,
|
|
18
|
-
status: 200,
|
|
19
|
-
headers: new Headers({ "content-type": "application/json" }),
|
|
20
|
-
json: () => Promise.resolve({ data }),
|
|
21
|
-
text: () => Promise.resolve(JSON.stringify({ data })),
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
export function restOk(data) {
|
|
25
|
-
return {
|
|
26
|
-
ok: true,
|
|
27
|
-
status: 200,
|
|
28
|
-
headers: new Headers({ "content-type": "application/json" }),
|
|
29
|
-
json: () => Promise.resolve(data),
|
|
30
|
-
text: () => Promise.resolve(JSON.stringify(data)),
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
export function gqlErrors(errors) {
|
|
34
|
-
return {
|
|
35
|
-
ok: true,
|
|
36
|
-
status: 200,
|
|
37
|
-
headers: new Headers({ "content-type": "application/json" }),
|
|
38
|
-
json: () => Promise.resolve({ data: null, errors }),
|
|
39
|
-
text: () => Promise.resolve(JSON.stringify({ data: null, errors })),
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
export function registerClientHooks() {
|
|
43
|
-
beforeEach(() => {
|
|
44
|
-
mockFetch.mockReset();
|
|
45
|
-
mockExecFile.mockReset();
|
|
46
|
-
_resetTokenCache();
|
|
47
|
-
delete process.env["GITHUB_TOKEN"];
|
|
48
|
-
delete process.env["GITHUB_PERSONAL_ACCESS_TOKEN"];
|
|
49
|
-
process.env["GH_TOKEN"] = "test-token";
|
|
50
|
-
});
|
|
51
|
-
afterEach(() => {
|
|
52
|
-
delete process.env["GH_TOKEN"];
|
|
53
|
-
_resetTokenCache();
|
|
54
|
-
});
|
|
55
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { vi, beforeEach } from "vitest";
|
|
2
|
-
// ---------------------------------------------------------------------------
|
|
3
|
-
// Stub fetch and child_process globally before any imports.
|
|
4
|
-
// ---------------------------------------------------------------------------
|
|
5
|
-
const mockFetch = vi.fn();
|
|
6
|
-
vi.stubGlobal("fetch", mockFetch);
|
|
7
|
-
const { mockExecFile } = vi.hoisted(() => ({ mockExecFile: vi.fn() }));
|
|
8
|
-
vi.mock("node:child_process", () => ({
|
|
9
|
-
execFile: (cmd, args, optsOrCb, maybeCb) => {
|
|
10
|
-
const cb = typeof optsOrCb === "function" ? optsOrCb : maybeCb;
|
|
11
|
-
mockExecFile(cmd, args)
|
|
12
|
-
.then((result) => cb(null, result))
|
|
13
|
-
.catch((err) => cb(err, { stdout: "", stderr: "" }));
|
|
14
|
-
},
|
|
15
|
-
}));
|
|
16
|
-
import { GitHubRequestError, graphql, graphqlWithRateLimit, rest, restText, _resetTokenCache, } from "./http.mjs";
|
|
17
|
-
// ---------------------------------------------------------------------------
|
|
18
|
-
// Helpers
|
|
19
|
-
// ---------------------------------------------------------------------------
|
|
20
|
-
function jsonOk(data) {
|
|
21
|
-
return {
|
|
22
|
-
ok: true,
|
|
23
|
-
status: 200,
|
|
24
|
-
headers: new Headers({ "content-type": "application/json" }),
|
|
25
|
-
json: () => Promise.resolve(data),
|
|
26
|
-
text: () => Promise.resolve(JSON.stringify(data)),
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
function gqlOk(data) {
|
|
30
|
-
return {
|
|
31
|
-
ok: true,
|
|
32
|
-
status: 200,
|
|
33
|
-
headers: new Headers({ "content-type": "application/json" }),
|
|
34
|
-
json: () => Promise.resolve({ data }),
|
|
35
|
-
text: () => Promise.resolve(JSON.stringify({ data })),
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
// ---------------------------------------------------------------------------
|
|
39
|
-
// Token resolution
|
|
40
|
-
// ---------------------------------------------------------------------------
|
|
41
|
-
export function registerHooks() {
|
|
42
|
-
beforeEach(() => {
|
|
43
|
-
mockFetch.mockReset();
|
|
44
|
-
mockExecFile.mockReset();
|
|
45
|
-
_resetTokenCache();
|
|
46
|
-
delete process.env["GH_TOKEN"];
|
|
47
|
-
delete process.env["GITHUB_TOKEN"];
|
|
48
|
-
delete process.env["GITHUB_PERSONAL_ACCESS_TOKEN"];
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
export { GitHubRequestError, _resetTokenCache, gqlOk, graphql, graphqlWithRateLimit, jsonOk, mockExecFile, mockFetch, rest, restText, };
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { beforeEach, afterEach } from "vitest";
|
|
2
|
-
import { randomBytes, createHash } from "node:crypto";
|
|
3
|
-
import { rm } from "node:fs/promises";
|
|
4
|
-
export function idToFilename(id) {
|
|
5
|
-
return createHash("sha256").update(id, "utf8").digest("hex") + ".json";
|
|
6
|
-
}
|
|
7
|
-
export const testKey = { owner: "test-owner", repo: "test-repo", pr: 123 };
|
|
8
|
-
export const testId = "PRRT_kwDOTest123";
|
|
9
|
-
export let testStateDir;
|
|
10
|
-
export function registerHooks() {
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
testStateDir = `${process.env["TMPDIR"] ?? "/tmp"}/shepherd-seen-test-${randomBytes(4).toString("hex")}`;
|
|
13
|
-
process.env["PR_SHEPHERD_STATE_DIR"] = testStateDir;
|
|
14
|
-
});
|
|
15
|
-
afterEach(async () => {
|
|
16
|
-
delete process.env["PR_SHEPHERD_STATE_DIR"];
|
|
17
|
-
await rm(testStateDir, { recursive: true, force: true });
|
|
18
|
-
});
|
|
19
|
-
}
|