|
4 | 4 | ProviderInstanceId, |
5 | 5 | type PullRequestReviewGuideResult, |
6 | 6 | } from "@t3tools/contracts"; |
7 | | -import { guideNoticeState, reviewGuideState } from "./reviewGuideState"; |
| 7 | +import { guideNoticeState, reviewGuideState, shouldAutoGenerateGuide } from "./reviewGuideState"; |
8 | 8 |
|
9 | 9 | const guide: NonNullable<PullRequestReviewGuideResult["guide"]> = { |
10 | 10 | headSha: "old-head", |
@@ -99,6 +99,32 @@ describe("guide notice transitions", () => { |
99 | 99 | expect(guideNoticeState({ ...view, data, running: true }).kind).toBe("writing"); |
100 | 100 | }); |
101 | 101 |
|
| 102 | + it("automatically writes for a new head after a previous head failed", () => { |
| 103 | + const data: PullRequestReviewGuideResult = { |
| 104 | + guide: null, |
| 105 | + currentHeadSha: "new-head", |
| 106 | + run: { |
| 107 | + _tag: "Failed", |
| 108 | + headSha: "old-head", |
| 109 | + failedAt: guide.generatedAt, |
| 110 | + detail: "Writer disconnected", |
| 111 | + }, |
| 112 | + }; |
| 113 | + expect(shouldAutoGenerateGuide({ ...view, data })).toBe(true); |
| 114 | + expect(guideNoticeState({ ...view, data }).kind).toBe("writing"); |
| 115 | + const failedHead = { ...data, currentHeadSha: "old-head" }; |
| 116 | + expect(shouldAutoGenerateGuide({ ...view, data: failedHead })).toBe(false); |
| 117 | + expect(guideNoticeState({ ...view, data: failedHead }).kind).toBe("failed"); |
| 118 | + }); |
| 119 | + |
| 120 | + it("does not auto-start without data or permission, during a run, or over a saved guide", () => { |
| 121 | + expect(shouldAutoGenerateGuide(view)).toBe(false); |
| 122 | + const data = { guide: null, run: null, currentHeadSha: "head" }; |
| 123 | + expect(shouldAutoGenerateGuide({ ...view, data, canWrite: false })).toBe(false); |
| 124 | + expect(shouldAutoGenerateGuide({ ...view, data, running: true })).toBe(false); |
| 125 | + expect(shouldAutoGenerateGuide({ ...view, data: { ...data, guide } })).toBe(false); |
| 126 | + }); |
| 127 | + |
102 | 128 | it("keeps a stale guide readable through rewriting and completion", () => { |
103 | 129 | const data = { guide, currentHeadSha: "head", run: null }; |
104 | 130 | expect(guideNoticeState({ ...view, data }).kind).toBe("stale"); |
|
0 commit comments