ramstack 0.1.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.
Files changed (215) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +44 -0
  3. package/agents/comment-sicko.md +32 -0
  4. package/agents/poteto-agent.md +9 -0
  5. package/cli/rstack.mjs +539 -0
  6. package/package.json +29 -0
  7. package/skills/architect/README.md +25 -0
  8. package/skills/architect/SKILL.md +83 -0
  9. package/skills/architect/agents/openai.yaml +5 -0
  10. package/skills/architect/references/design-red-flags.md +33 -0
  11. package/skills/architect/references/rationale-template.md +35 -0
  12. package/skills/architect/references/runner-prompt.md +20 -0
  13. package/skills/arena/README.md +21 -0
  14. package/skills/arena/SKILL.md +71 -0
  15. package/skills/arena/agents/openai.yaml +5 -0
  16. package/skills/automate-me/README.md +21 -0
  17. package/skills/automate-me/SKILL.md +109 -0
  18. package/skills/automate-me/agents/openai.yaml +5 -0
  19. package/skills/blast-radius/README.md +21 -0
  20. package/skills/blast-radius/SKILL.md +50 -0
  21. package/skills/blast-radius/agents/openai.yaml +5 -0
  22. package/skills/bro/README.md +16 -0
  23. package/skills/bro/SKILL.md +7 -0
  24. package/skills/bro/agents/openai.yaml +5 -0
  25. package/skills/create-verification-skill/README.md +22 -0
  26. package/skills/create-verification-skill/SKILL.md +44 -0
  27. package/skills/create-verification-skill/agents/openai.yaml +5 -0
  28. package/skills/create-verification-skill/references/feature-map-example/README.md +47 -0
  29. package/skills/create-verification-skill/references/feature-map-example/create-note.md +39 -0
  30. package/skills/create-verification-skill/references/feature-map-example/search.md +45 -0
  31. package/skills/figure-it-out/README.md +22 -0
  32. package/skills/figure-it-out/SKILL.md +55 -0
  33. package/skills/figure-it-out/agents/openai.yaml +5 -0
  34. package/skills/how/README.md +25 -0
  35. package/skills/how/SKILL.md +134 -0
  36. package/skills/how/agents/openai.yaml +3 -0
  37. package/skills/how/references/critic-prompt.md +59 -0
  38. package/skills/how/references/critique-rubric.md +58 -0
  39. package/skills/how/references/explainer-prompt.md +55 -0
  40. package/skills/how/references/explorer-prompt.md +52 -0
  41. package/skills/interrogate/README.md +21 -0
  42. package/skills/interrogate/SKILL.md +112 -0
  43. package/skills/interrogate/agents/openai.yaml +5 -0
  44. package/skills/interrogate/references/code-quality-review.md +47 -0
  45. package/skills/interrogate/references/lead-judgment.md +58 -0
  46. package/skills/interrogate/references/reviewer-prompt.md +72 -0
  47. package/skills/interrogate/references/rubric.md +77 -0
  48. package/skills/maintain-verification-skill/README.md +21 -0
  49. package/skills/maintain-verification-skill/SKILL.md +39 -0
  50. package/skills/maintain-verification-skill/agents/openai.yaml +5 -0
  51. package/skills/no-comments/README.md +22 -0
  52. package/skills/no-comments/SKILL.md +24 -0
  53. package/skills/no-comments/agents/openai.yaml +5 -0
  54. package/skills/poteto-mode/README.md +26 -0
  55. package/skills/poteto-mode/SKILL.md +140 -0
  56. package/skills/poteto-mode/agents/openai.yaml +5 -0
  57. package/skills/poteto-mode/playbooks/authoring-a-skill.md +13 -0
  58. package/skills/poteto-mode/playbooks/autonomous-run.md +13 -0
  59. package/skills/poteto-mode/playbooks/autopilot-full.md +13 -0
  60. package/skills/poteto-mode/playbooks/autopilot-stack.md +16 -0
  61. package/skills/poteto-mode/playbooks/babysit.md +27 -0
  62. package/skills/poteto-mode/playbooks/bug-fix.md +17 -0
  63. package/skills/poteto-mode/playbooks/eval.md +27 -0
  64. package/skills/poteto-mode/playbooks/feature.md +21 -0
  65. package/skills/poteto-mode/playbooks/hillclimb.md +21 -0
  66. package/skills/poteto-mode/playbooks/investigation.md +14 -0
  67. package/skills/poteto-mode/playbooks/multi-phase-plan.md +3 -0
  68. package/skills/poteto-mode/playbooks/opening-a-pr.md +11 -0
  69. package/skills/poteto-mode/playbooks/orchestrate.md +113 -0
  70. package/skills/poteto-mode/playbooks/pause-safely.md +10 -0
  71. package/skills/poteto-mode/playbooks/perf-issue.md +24 -0
  72. package/skills/poteto-mode/playbooks/prototype.md +14 -0
  73. package/skills/poteto-mode/playbooks/refactoring.md +16 -0
  74. package/skills/poteto-mode/playbooks/runtime-forensics.md +11 -0
  75. package/skills/poteto-mode/playbooks/session-pickup.md +13 -0
  76. package/skills/poteto-mode/playbooks/shipping.md +20 -0
  77. package/skills/poteto-mode/playbooks/trace-forensics.md +14 -0
  78. package/skills/poteto-mode/playbooks/visual-parity.md +11 -0
  79. package/skills/poteto-mode/playbooks/worktree-cleanup.md +14 -0
  80. package/skills/poteto-mode/references/bugbot-triage.md +142 -0
  81. package/skills/poteto-mode/references/plan.md +105 -0
  82. package/skills/poteto-mode/scripts/bootstrap.ts +62 -0
  83. package/skills/poteto-mode/scripts/bun.lock +67 -0
  84. package/skills/poteto-mode/scripts/orch/orch.test.ts +634 -0
  85. package/skills/poteto-mode/scripts/orch/orch.ts +578 -0
  86. package/skills/poteto-mode/scripts/orch/store.ts +1607 -0
  87. package/skills/poteto-mode/scripts/package.json +16 -0
  88. package/skills/poteto-mode/scripts/watch-pr/cli.test.ts +224 -0
  89. package/skills/poteto-mode/scripts/watch-pr/cli.ts +223 -0
  90. package/skills/poteto-mode/scripts/watch-pr/fakes.test-helper.ts +118 -0
  91. package/skills/poteto-mode/scripts/watch-pr/github.test.ts +306 -0
  92. package/skills/poteto-mode/scripts/watch-pr/github.ts +699 -0
  93. package/skills/poteto-mode/scripts/watch-pr/policy.test.ts +420 -0
  94. package/skills/poteto-mode/scripts/watch-pr/policy.ts +832 -0
  95. package/skills/poteto-mode/scripts/watch-pr/render.ts +169 -0
  96. package/skills/poteto-mode/scripts/watch-pr/tsconfig.json +13 -0
  97. package/skills/poteto-mode/scripts/watch-pr/types.compile.ts +93 -0
  98. package/skills/poteto-mode/scripts/watch-pr/types.ts +401 -0
  99. package/skills/poteto-mode/scripts/watch-pr/watch-pr +6 -0
  100. package/skills/poteto-mode/scripts/worktree-audit.sh +86 -0
  101. package/skills/principle-boundary-discipline/README.md +17 -0
  102. package/skills/principle-boundary-discipline/SKILL.md +34 -0
  103. package/skills/principle-boundary-discipline/agents/openai.yaml +5 -0
  104. package/skills/principle-build-the-lever/README.md +17 -0
  105. package/skills/principle-build-the-lever/SKILL.md +23 -0
  106. package/skills/principle-build-the-lever/agents/openai.yaml +5 -0
  107. package/skills/principle-encode-lessons-in-structure/README.md +17 -0
  108. package/skills/principle-encode-lessons-in-structure/SKILL.md +31 -0
  109. package/skills/principle-encode-lessons-in-structure/agents/openai.yaml +5 -0
  110. package/skills/principle-exhaust-the-design-space/README.md +17 -0
  111. package/skills/principle-exhaust-the-design-space/SKILL.md +21 -0
  112. package/skills/principle-exhaust-the-design-space/agents/openai.yaml +5 -0
  113. package/skills/principle-experience-first/README.md +17 -0
  114. package/skills/principle-experience-first/SKILL.md +19 -0
  115. package/skills/principle-experience-first/agents/openai.yaml +5 -0
  116. package/skills/principle-fix-root-causes/README.md +17 -0
  117. package/skills/principle-fix-root-causes/SKILL.md +23 -0
  118. package/skills/principle-fix-root-causes/agents/openai.yaml +5 -0
  119. package/skills/principle-foundational-thinking/README.md +17 -0
  120. package/skills/principle-foundational-thinking/SKILL.md +21 -0
  121. package/skills/principle-foundational-thinking/agents/openai.yaml +5 -0
  122. package/skills/principle-guard-the-context-window/README.md +17 -0
  123. package/skills/principle-guard-the-context-window/SKILL.md +17 -0
  124. package/skills/principle-guard-the-context-window/agents/openai.yaml +5 -0
  125. package/skills/principle-laziness-protocol/README.md +17 -0
  126. package/skills/principle-laziness-protocol/SKILL.md +18 -0
  127. package/skills/principle-laziness-protocol/agents/openai.yaml +5 -0
  128. package/skills/principle-make-operations-idempotent/README.md +17 -0
  129. package/skills/principle-make-operations-idempotent/SKILL.md +24 -0
  130. package/skills/principle-make-operations-idempotent/agents/openai.yaml +5 -0
  131. package/skills/principle-migrate-callers-then-delete-legacy-apis/README.md +17 -0
  132. package/skills/principle-migrate-callers-then-delete-legacy-apis/SKILL.md +22 -0
  133. package/skills/principle-migrate-callers-then-delete-legacy-apis/agents/openai.yaml +5 -0
  134. package/skills/principle-minimize-reader-load/README.md +17 -0
  135. package/skills/principle-minimize-reader-load/SKILL.md +23 -0
  136. package/skills/principle-minimize-reader-load/agents/openai.yaml +5 -0
  137. package/skills/principle-model-the-domain/README.md +17 -0
  138. package/skills/principle-model-the-domain/SKILL.md +26 -0
  139. package/skills/principle-model-the-domain/agents/openai.yaml +5 -0
  140. package/skills/principle-never-block-on-the-human/README.md +16 -0
  141. package/skills/principle-never-block-on-the-human/SKILL.md +23 -0
  142. package/skills/principle-never-block-on-the-human/agents/openai.yaml +5 -0
  143. package/skills/principle-outcome-oriented-execution/README.md +16 -0
  144. package/skills/principle-outcome-oriented-execution/SKILL.md +22 -0
  145. package/skills/principle-outcome-oriented-execution/agents/openai.yaml +5 -0
  146. package/skills/principle-prove-it-works/README.md +18 -0
  147. package/skills/principle-prove-it-works/SKILL.md +33 -0
  148. package/skills/principle-prove-it-works/agents/openai.yaml +5 -0
  149. package/skills/principle-redesign-from-first-principles/README.md +16 -0
  150. package/skills/principle-redesign-from-first-principles/SKILL.md +16 -0
  151. package/skills/principle-redesign-from-first-principles/agents/openai.yaml +5 -0
  152. package/skills/principle-separate-before-serializing-shared-state/README.md +16 -0
  153. package/skills/principle-separate-before-serializing-shared-state/SKILL.md +16 -0
  154. package/skills/principle-separate-before-serializing-shared-state/agents/openai.yaml +5 -0
  155. package/skills/principle-sequence-verifiable-units/README.md +18 -0
  156. package/skills/principle-sequence-verifiable-units/SKILL.md +22 -0
  157. package/skills/principle-sequence-verifiable-units/agents/openai.yaml +5 -0
  158. package/skills/principle-subtract-before-you-add/README.md +17 -0
  159. package/skills/principle-subtract-before-you-add/SKILL.md +22 -0
  160. package/skills/principle-subtract-before-you-add/agents/openai.yaml +5 -0
  161. package/skills/principle-type-system-discipline/README.md +19 -0
  162. package/skills/principle-type-system-discipline/SKILL.md +31 -0
  163. package/skills/principle-type-system-discipline/agents/openai.yaml +5 -0
  164. package/skills/recall/README.md +23 -0
  165. package/skills/recall/SKILL.md +35 -0
  166. package/skills/recall/agents/openai.yaml +5 -0
  167. package/skills/reflect/README.md +24 -0
  168. package/skills/reflect/SKILL.md +77 -0
  169. package/skills/reflect/agents/openai.yaml +5 -0
  170. package/skills/reflect/references/divergent-reviewer.md +43 -0
  171. package/skills/reflect/references/judgment-reviewer.md +42 -0
  172. package/skills/reflect/references/synthesizer.md +56 -0
  173. package/skills/reflect/references/tooling-reviewer.md +57 -0
  174. package/skills/setup-rstack/README.md +25 -0
  175. package/skills/setup-rstack/SKILL.md +81 -0
  176. package/skills/setup-rstack/agents/openai.yaml +3 -0
  177. package/skills/show-me-your-work/README.md +23 -0
  178. package/skills/show-me-your-work/SKILL.md +82 -0
  179. package/skills/show-me-your-work/agents/openai.yaml +5 -0
  180. package/skills/show-me-your-work/references/decision-log-template.tsv +1 -0
  181. package/skills/show-me-your-work/scripts/log.sh +40 -0
  182. package/skills/swarm/README.md +21 -0
  183. package/skills/swarm/SKILL.md +46 -0
  184. package/skills/swarm/agents/openai.yaml +5 -0
  185. package/skills/tdd/README.md +21 -0
  186. package/skills/tdd/SKILL.md +44 -0
  187. package/skills/tdd/agents/openai.yaml +5 -0
  188. package/skills/teach/README.md +22 -0
  189. package/skills/teach/SKILL.md +21 -0
  190. package/skills/teach/agents/openai.yaml +5 -0
  191. package/skills/technical-writing/README.md +23 -0
  192. package/skills/technical-writing/SKILL.md +130 -0
  193. package/skills/technical-writing/agents/openai.yaml +5 -0
  194. package/skills/typescript-best-practices/README.md +22 -0
  195. package/skills/typescript-best-practices/SKILL.md +28 -0
  196. package/skills/typescript-best-practices/agents/openai.yaml +3 -0
  197. package/skills/typescript-best-practices/references/patterns.md +292 -0
  198. package/skills/unslop/README.md +21 -0
  199. package/skills/unslop/SKILL.md +80 -0
  200. package/skills/unslop/agents/openai.yaml +3 -0
  201. package/skills/why/README.md +26 -0
  202. package/skills/why/SKILL.md +229 -0
  203. package/skills/why/agents/openai.yaml +3 -0
  204. package/skills/why/references/epistemics.md +144 -0
  205. package/skills/why/references/investigator-prompt.md +103 -0
  206. package/skills/why/references/source-playbook.md +17 -0
  207. package/skills/why/references/sources/code-archaeology.md +88 -0
  208. package/skills/why/references/sources/databricks.md +70 -0
  209. package/skills/why/references/sources/datadog.md +99 -0
  210. package/skills/why/references/sources/incident-postmortem.md +15 -0
  211. package/skills/why/references/sources/linear.md +48 -0
  212. package/skills/why/references/sources/notion.md +55 -0
  213. package/skills/why/references/sources/sentry.md +100 -0
  214. package/skills/why/references/sources/slack.md +54 -0
  215. package/skills/why/references/synthesizer-prompt.md +135 -0
@@ -0,0 +1,306 @@
1
+ import { describe, expect, it } from "bun:test";
2
+ import {
3
+ ChecksUnavailable,
4
+ WatcherQueryError,
5
+ mapRollupNode,
6
+ orderStack,
7
+ parsePullRequest,
8
+ parseReviewThreads,
9
+ resolveChecks,
10
+ resolveContext,
11
+ } from "./github.ts";
12
+ import {
13
+ fakeReader,
14
+ failedCheck,
15
+ passingCheck,
16
+ pendingCheck,
17
+ } from "./fakes.test-helper.ts";
18
+ import { parsePrNumber } from "./types.ts";
19
+
20
+ const context = {
21
+ owner: "owner",
22
+ repo: "repo",
23
+ number: parsePrNumber(42),
24
+ };
25
+
26
+ describe("checks fallback chain", () => {
27
+ it("uses a non-empty fast-path result without a rollup query", async () => {
28
+ const reader = fakeReader({
29
+ fastPath: { kind: "checks", checks: [passingCheck("fast")] },
30
+ });
31
+ const read = await resolveChecks(reader, context);
32
+ expect(read.source).toBe("gh-pr-checks");
33
+ expect(read.checks.map((check) => check.name)).toEqual(["fast"]);
34
+ expect(reader.calls).toEqual(["checksFastPath"]);
35
+ });
36
+
37
+ it("paginates GraphQL when the fast path is unusable", async () => {
38
+ const reader = fakeReader({
39
+ fastPath: { kind: "unusable", exitCode: 8, stderr: "" },
40
+ rollupPages: [
41
+ { checks: [passingCheck("first")], endCursor: "next" },
42
+ { checks: [failedCheck("second")], endCursor: null },
43
+ ],
44
+ });
45
+ const read = await resolveChecks(reader, context);
46
+ expect(read.source).toBe("graphql-rollup");
47
+ expect(read.checks.map((check) => check.name)).toEqual(["first", "second"]);
48
+ expect(reader.calls).toEqual([
49
+ "checksFastPath",
50
+ "checkRollupPage:null",
51
+ "checkRollupPage:next",
52
+ ]);
53
+ });
54
+
55
+ it("falls back when valid fast-path JSON represented an empty list", async () => {
56
+ const reader = fakeReader({
57
+ fastPath: { kind: "checks", checks: [] },
58
+ rollupPages: [{ checks: [pendingCheck("fallback")], endCursor: null }],
59
+ });
60
+ expect((await resolveChecks(reader, context)).checks[0].name).toBe(
61
+ "fallback"
62
+ );
63
+ expect(reader.calls).toEqual(["checksFastPath", "checkRollupPage:null"]);
64
+ });
65
+
66
+ it("fails closed when both paths are empty", async () => {
67
+ const reader = fakeReader({
68
+ fastPath: {
69
+ kind: "unusable",
70
+ exitCode: 8,
71
+ stderr: "credential cannot read checks",
72
+ },
73
+ });
74
+ await expect(resolveChecks(reader, context)).rejects.toBeInstanceOf(
75
+ ChecksUnavailable
76
+ );
77
+ expect(reader.calls).toEqual(["checksFastPath", "checkRollupPage:null"]);
78
+ });
79
+ });
80
+
81
+ describe("rollup node mapping", () => {
82
+ it("maps terminal and non-terminal CheckRun states fail closed", () => {
83
+ const cases = [
84
+ ["IN_PROGRESS", null, "pending", "PENDING"],
85
+ ["COMPLETED", "SUCCESS", "passed", "SUCCESS"],
86
+ ["COMPLETED", "NEUTRAL", "skipped", "NEUTRAL"],
87
+ ["COMPLETED", "SKIPPED", "skipped", "SKIPPED"],
88
+ ["COMPLETED", "ACTION_REQUIRED", "failed", "ACTION_REQUIRED"],
89
+ ["COMPLETED", "TIMED_OUT", "failed", "FAILURE"],
90
+ ["COMPLETED", "FUTURE_VALUE", "failed", "FAILURE"],
91
+ ] as const;
92
+ for (const [status, conclusion, kind, reportedState] of cases) {
93
+ expect(
94
+ mapRollupNode({
95
+ __typename: "CheckRun",
96
+ name: "ci",
97
+ status,
98
+ conclusion,
99
+ })
100
+ ).toMatchObject({ kind, reportedState });
101
+ }
102
+ });
103
+
104
+ it("classifies an in-progress Code Review Gate from the rollup as the gate", () => {
105
+ expect(
106
+ mapRollupNode({
107
+ __typename: "CheckRun",
108
+ name: "Code Review Gate",
109
+ status: "IN_PROGRESS",
110
+ conclusion: null,
111
+ })
112
+ ).toMatchObject({ kind: "code-review-gate" });
113
+ expect(
114
+ mapRollupNode({
115
+ __typename: "StatusContext",
116
+ context: "Code Review Gate",
117
+ state: "PENDING",
118
+ })
119
+ ).toMatchObject({ kind: "code-review-gate" });
120
+ });
121
+
122
+ it("maps StatusContext states and drops unknown typenames", () => {
123
+ expect(
124
+ mapRollupNode({
125
+ __typename: "StatusContext",
126
+ context: "ci",
127
+ state: "EXPECTED",
128
+ })
129
+ ).toMatchObject({ kind: "pending", reportedState: "PENDING" });
130
+ expect(
131
+ mapRollupNode({
132
+ __typename: "StatusContext",
133
+ context: "ci",
134
+ state: "FUTURE_VALUE",
135
+ })
136
+ ).toMatchObject({ kind: "failed", reportedState: "FUTURE_VALUE" });
137
+ expect(mapRollupNode({ __typename: "FutureNode" })).toBeNull();
138
+ });
139
+ });
140
+
141
+ describe("closed enum parsing", () => {
142
+ const rawPullRequest = {
143
+ mergeable: "MERGEABLE",
144
+ mergeStateStatus: "CLEAN",
145
+ reviewDecision: "APPROVED",
146
+ headRefOid: "head",
147
+ headRefName: "feature",
148
+ baseRefName: "main",
149
+ state: "OPEN",
150
+ mergedAt: null,
151
+ isDraft: false,
152
+ };
153
+
154
+ it("accepts mergeStateStatus CONFLICTING", () => {
155
+ expect(
156
+ parsePullRequest(
157
+ { ...rawPullRequest, mergeStateStatus: "CONFLICTING" },
158
+ context
159
+ ).mergeStateStatus
160
+ ).toBe("CONFLICTING");
161
+ });
162
+
163
+ it("reads gh's empty reviewDecision as no decision rather than a parse failure", () => {
164
+ expect(
165
+ parsePullRequest({ ...rawPullRequest, reviewDecision: "" }, context)
166
+ .reviewDecision
167
+ ).toBeNull();
168
+ });
169
+
170
+ it("still rejects an unknown reviewDecision", () => {
171
+ expect(() =>
172
+ parsePullRequest({ ...rawPullRequest, reviewDecision: "MAYBE" }, context)
173
+ ).toThrow(WatcherQueryError);
174
+ });
175
+
176
+ it("rejects unknown enum values as retryable errors carrying the raw value", () => {
177
+ try {
178
+ parsePullRequest(
179
+ { ...rawPullRequest, mergeStateStatus: "FUTURE_STATE" },
180
+ context
181
+ );
182
+ throw new Error("expected parser to throw");
183
+ } catch (error) {
184
+ expect(error).toBeInstanceOf(WatcherQueryError);
185
+ if (!(error instanceof WatcherQueryError)) throw error;
186
+ expect(error.failure).toMatchObject({
187
+ kind: "missing-key",
188
+ retryable: true,
189
+ rawValue: '"FUTURE_STATE"',
190
+ });
191
+ }
192
+ });
193
+ });
194
+
195
+ it("annotates Bugbot threads with distinct review-pass counts", () => {
196
+ const response = {
197
+ data: {
198
+ repository: {
199
+ pullRequest: {
200
+ reviewThreads: {
201
+ nodes: [
202
+ {
203
+ id: "one",
204
+ isResolved: false,
205
+ comments: {
206
+ nodes: [
207
+ {
208
+ body: "RUN_ID: run-1",
209
+ createdAt: "now",
210
+ path: "a.ts",
211
+ line: 1,
212
+ author: { login: "bugbot" },
213
+ },
214
+ ],
215
+ },
216
+ },
217
+ {
218
+ id: "two",
219
+ isResolved: false,
220
+ comments: {
221
+ nodes: [
222
+ {
223
+ body: "CURSOR_AUTOMATION_ID: run-2 severity high",
224
+ createdAt: "now",
225
+ path: null,
226
+ line: null,
227
+ author: { login: "cursor" },
228
+ },
229
+ ],
230
+ },
231
+ },
232
+ {
233
+ id: "resolved",
234
+ isResolved: true,
235
+ comments: {
236
+ nodes: [
237
+ {
238
+ body: "RUN_ID: run-3",
239
+ createdAt: "now",
240
+ path: null,
241
+ line: null,
242
+ author: { login: "bugbot" },
243
+ },
244
+ ],
245
+ },
246
+ },
247
+ ],
248
+ },
249
+ },
250
+ },
251
+ },
252
+ };
253
+ const threads = parseReviewThreads(response);
254
+ expect(threads).toHaveLength(2);
255
+ expect(threads.map((thread) => thread.isBugbot)).toEqual([true, true]);
256
+ expect(threads.map((thread) => thread.bugbotReviewPasses)).toEqual([3, 3]);
257
+ });
258
+
259
+ describe("context and stack discovery", () => {
260
+ it("returns a fully explicit context without any reader call", async () => {
261
+ const reader = fakeReader();
262
+ expect(
263
+ await resolveContext({
264
+ reader,
265
+ owner: "explicit",
266
+ repo: "repo",
267
+ pr: context.number,
268
+ })
269
+ ).toEqual({ owner: "explicit", repo: "repo", number: context.number });
270
+ expect(reader.calls).toEqual([]);
271
+ });
272
+
273
+ it("uses the local origin before currentPr for an explicit number", async () => {
274
+ const reader = fakeReader({ origin: { owner: "local", repo: "checkout" } });
275
+ expect(
276
+ await resolveContext({
277
+ reader,
278
+ owner: null,
279
+ repo: null,
280
+ pr: context.number,
281
+ })
282
+ ).toEqual({ owner: "local", repo: "checkout", number: context.number });
283
+ expect(reader.calls).toEqual(["originRepo"]);
284
+ });
285
+
286
+ it("orders the connected stack bottom-to-top", () => {
287
+ const ordered = orderStack(context, [
288
+ {
289
+ number: parsePrNumber(41),
290
+ headRefName: "base-feature",
291
+ baseRefName: "main",
292
+ },
293
+ {
294
+ number: context.number,
295
+ headRefName: "feature",
296
+ baseRefName: "base-feature",
297
+ },
298
+ {
299
+ number: parsePrNumber(43),
300
+ headRefName: "upstack",
301
+ baseRefName: "feature",
302
+ },
303
+ ]);
304
+ expect(ordered.map((item) => Number(item.number))).toEqual([41, 42, 43]);
305
+ });
306
+ });