feat(wasteland): add listClaims tRPC procedure#3148
Conversation
|
|
||
| const rigFilter = input.rigHandle ?? null; | ||
| const candidates = openPulls.filter( | ||
| p => !rigFilter || !p.creator_name || p.creator_name === rigFilter |
There was a problem hiding this comment.
WARNING: creator_name filter is too permissive — fetches extra PRs for no reason
When rigFilter is set, the expression !rigFilter || !p.creator_name || p.creator_name === rigFilter passes through every PR whose creator_name is null or empty. Those PRs then trigger a full getPull detail fetch (up to the concurrency limit) even though they will almost certainly be discarded later during the branch-name check at line 1113.
If the goal is to fetch fewer PRs when filtering by rig, the null-creator guard should be removed — they aren't matches:
| p => !rigFilter || !p.creator_name || p.creator_name === rigFilter | |
| p => !rigFilter || p.creator_name === rigFilter |
Code Review SummaryStatus: 3 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
SUGGESTION
Other Observations (not in diff)
SQL injection concern (informational — mitigated): PR kind priority (informational): No test covers a title containing both Files Reviewed (7 files)
Fix these issues in Kilo Cloud Reviewed by claude-sonnet-4.6 · 918,531 tokens |
| classifyInbox: vi.fn(), | ||
| })); | ||
|
|
||
| import { TRPCError } from '@trpc/server'; |
There was a problem hiding this comment.
WARNING: TRPCError is imported but never used
This import will be flagged by the linter. The FORBIDDEN test asserts via .rejects.toThrow(/Only wasteland owners/) (a string match) rather than checking instanceof TRPCError or its code. Either use the import to make the assertion more precise, or remove it.
| import { TRPCError } from '@trpc/server'; |
| type: 'org', | ||
| orgId: 'org-1', | ||
| }); | ||
| mockCtx.orgMemberships = [{ orgId: 'org-1', role: 'member' }]; |
There was a problem hiding this comment.
WARNING: Module-level mockCtx is mutated without being reset — potential test pollution
mockCtx is declared once at module scope and orgMemberships is overwritten here. vi.clearAllMocks() in beforeEach only resets mock call counts/return values; it does not restore plain object properties. If this test runs before any other test that relies on mockCtx.orgMemberships being empty, it will inherit the mutated value.
Reset it at the end of this test, or reset it in beforeEach:
beforeEach(() => {
vi.clearAllMocks();
mockCtx.orgMemberships = [];
...
});|
|
||
| expect(result.claims).toHaveLength(1); | ||
| expect(result.claims[0].pending_pr).not.toBeNull(); | ||
| expect(result.claims[0].pending_pr!.pull_id).toBe('42'); |
There was a problem hiding this comment.
SUGGESTION: Non-null assertions (!) on pending_pr — prefer a narrowing check
The coding standards prohibit ! non-null assertions. Line 292 already asserts not.toBeNull(), but TypeScript still sees pending_pr as T | null. Use optional chaining with a fallback or narrow with a local variable to avoid the !:
const pr = result.claims[0].pending_pr;
if (!pr) throw new Error('expected pending_pr to be set');
expect(pr.pull_id).toBe('42');
expect(pr.kind).toBe('claim');
expect(pr.from_branch).toBe('wl/rig-alpha/w-item1');
expect(pr.state).toBe('Open');
Summary
Add
wasteland.listClaimstRPC query procedure that returns all currently claimed wanted items in a wasteland, enriched with in-flight DoltHub PR metadata. This powers the Claims overview page UI.RpcClaimOutputschema inschemas.tswithitem(WantedBoardRowOutput) + optionalpending_pr(pull_id, pr_url, kind, from_branch, state, timestamps)listClaimsprocedure withwastelandId, optionalrigHandlefilter, andlimit(1-200, default 100){ claims: [] })inferPrKindhelper toclaims.util.tsfor PR kind classification (claim/done/unclaim/edit/unknown)wasteland.listClaimsat 30 req/minclaims.listrouter.d.tstype declarations for the web appinferPrKind(9 test cases)Verification
pnpm --filter cloudflare-wasteland testpasses (21 tests)pnpm --filter cloudflare-wasteland typecheckpassesVisual Changes
N/A (backend only)
Reviewer Notes
inferPrKindhelper uses keyword matching on PR titles — this is a heuristic mirroring how the inbox classifier works, but not as sophisticated. If the PR title doesn't contain known verbs, it falls back to'unknown'.init.ts— the pathwasteland.listClaimsmaps to the config key.