-
Notifications
You must be signed in to change notification settings - Fork 0
branch:enrich retries entries whose ticket never resolved #103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+91
−4
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import { describe, test, expect } from "bun:test"; | ||
| import { createCacheHandlers } from "../handlers/cache.ts"; | ||
| import { fakeStore } from "./fake-cache-store.ts"; | ||
|
|
||
| const HOUR = 60 * 60 * 1000; | ||
|
|
||
| function makeCtx(entries: Record<string, any>) { | ||
| const ctx = { cache: fakeStore(entries), refreshCache: async () => {} } as any; | ||
| return ctx; | ||
| } | ||
|
|
||
| describe("branch:enrich heals an entry whose ticket never resolved", () => { | ||
| test("a complete entry is served from cache without re-enriching", async () => { | ||
| const ctx = makeCtx({ | ||
| b: { linearId: "ACME-1", ticket: { identifier: "ACME-1" }, mr: null, fetchedAt: Date.now() - HOUR }, | ||
| }); | ||
| const res = await createCacheHandlers(ctx)["branch:enrich"]!({ branch: "b", repoPath: "/tmp/x" }); | ||
| expect(res.ok).toBe(true); | ||
| expect(res.source).toBe("cache"); | ||
| }); | ||
|
|
||
| test("an entry with no linear id at all stays a cache hit", async () => { | ||
| // Nothing to resolve: re-enriching would spend a lookup per read forever. | ||
| const ctx = makeCtx({ b: { linearId: null, ticket: null, mr: null, fetchedAt: 1 } }); | ||
| const res = await createCacheHandlers(ctx)["branch:enrich"]!({ branch: "b", repoPath: "/tmp/x" }); | ||
| expect(res.source).toBe("cache"); | ||
| }); | ||
|
|
||
| test("an id resolved but no ticket is INCOMPLETE, and re-enriches", async () => { | ||
| const ctx = makeCtx({ | ||
| b: { linearId: "ACME-1", ticket: null, mr: null, fetchedAt: Date.now() - HOUR }, | ||
| }); | ||
| const res = await createCacheHandlers(ctx)["branch:enrich"]!({ | ||
| branch: "b", | ||
| repoPath: "/tmp/x", | ||
| // The enricher is injected so the test never reaches the network. | ||
| enrich: async () => { | ||
| ctx.cache.entries.b.ticket = { identifier: "ACME-1", title: "t", url: "u" }; | ||
| }, | ||
| }); | ||
| expect(res.source).toBe("fresh"); | ||
| expect(res.data.ticket.identifier).toBe("ACME-1"); | ||
| }); | ||
|
|
||
| test("a recent incomplete entry is not retried, so a genuinely missing ticket costs one lookup", async () => { | ||
| let calls = 0; | ||
| const ctx = makeCtx({ | ||
| b: { linearId: "ACME-1", ticket: null, mr: null, fetchedAt: Date.now() - 1_000 }, | ||
| }); | ||
| const res = await createCacheHandlers(ctx)["branch:enrich"]!({ | ||
| branch: "b", | ||
| repoPath: "/tmp/x", | ||
| enrich: async () => { | ||
| calls++; | ||
| }, | ||
| }); | ||
| expect(calls).toBe(0); | ||
| expect(res.source).toBe("cache"); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Force enrichment after an incomplete cache entry.
When
isIncomplete(cached)is true, this call still letsenrichBranchesuse its own existing-entry cache path. It returns the unresolved entry and starts a detached refresh, so this handler can returnsource: "fresh"withticket: null. SetforceRefresh: truefor this path. The injected test does not exercise this normal enrichment path.Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents