fix(slice5): validate raw metadata input + prune stale bulk selections

Code-review follow-ups:
- Validate the raw submitted value before apply_values coerces it, in both
  the single-edit and bulk endpoints — a scalar set onto a tags field now
  rejects (422 / rejected) instead of silently char-splitting into a list.
- Catalog prunes bulk selections to the currently-visible (filtered) entries
  after each list fetch, so the bulk bar can't act on rows the user has
  filtered out of view.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ben Stull
2026-06-07 21:03:29 -07:00
parent 8eee907893
commit 7886840362
4 changed files with 76 additions and 7 deletions
+10 -1
View File
@@ -93,7 +93,16 @@ export default function Catalog({ viewer, onProposeRFC, version }) {
Object.entries(selections).map(([f, set]) => [f, [...set]])
)
listRFCs(pid, cid, { selections: selObj, malformed: malformedOnly })
.then(d => { setRfcs(d.items); setFacets(d.facets || {}) })
.then(d => {
setRfcs(d.items); setFacets(d.facets || {})
// §22.4a SLICE-5: drop any bulk selections that the new (filtered)
// list no longer contains, so the bar can't act on hidden rows.
const visible = new Set(d.items.map(it => it.slug))
setSelected(prev => {
const kept = [...prev].filter(s => visible.has(s))
return kept.length === prev.size ? prev : new Set(kept)
})
})
.catch(() => { setRfcs([]); setFacets({}) })
.finally(() => setLoading(false))
}, [version, pid, cid, selections, malformedOnly])
+24
View File
@@ -90,6 +90,30 @@ describe('Catalog faceted pane', () => {
})
})
it('drops a selection when a filter change hides the row', async () => {
getCollection.mockResolvedValue({
fields: { priority: { type: 'enum', values: ['P0', 'P1'] } },
viewer: { can_contribute: true }, entry_noun: 'RFC',
})
// Content-driven: unfiltered → row "a"; once the P0 facet is selected the
// server response omits "a" (drives the prune). Robust to extra mount-time
// fetches the collection effect triggers.
listRFCs.mockImplementation((p, c, opts) => Promise.resolve({
items: opts?.selections?.priority?.includes('P0')
? [{ slug: 'b', title: 'B', state: 'active', tags: [], starred_by_me: false }]
: [{ slug: 'a', title: 'A', state: 'active', tags: [], starred_by_me: false }],
facets: { priority: { P0: 1 }, state: { active: 1 } },
}))
const { container } = renderCatalog()
fireEvent.click(await screen.findByLabelText(/select A/i))
expect(await screen.findByText(/1 selected/i)).toBeInTheDocument()
// Toggle the P0 facet checkbox → re-fetch returns a list without "a".
fireEvent.click(container.querySelector('.facet-group input[type="checkbox"]'))
await waitFor(() => {
expect(screen.queryByText(/1 selected/i)).not.toBeInTheDocument()
})
})
it('does not offer row selection for a non-contributor', async () => {
getCollection.mockResolvedValue({
fields: { priority: { type: 'enum', values: ['P0'] } },