mirror of
https://github.com/kennethnym/aris.git
synced 2026-03-22 18:11:17 +00:00
fix: filter stale item IDs from groups after pipeline
Groups accumulated during the pipeline can reference items that a later processor suppressed. The engine now strips stale IDs and drops empty groups before returning. Co-authored-by: Ona <no-reply@ona.com>
This commit is contained in:
@@ -331,7 +331,16 @@ export class FeedEngine<TItems extends FeedItem = FeedItem> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return { items: currentItems, groupedItems: allGroupedItems, errors: allErrors }
|
// Remove stale item IDs from groups and drop empty groups
|
||||||
|
const itemIds = new Set(currentItems.map((item) => item.id))
|
||||||
|
const validGroups = allGroupedItems
|
||||||
|
.map((group) => ({
|
||||||
|
...group,
|
||||||
|
itemIds: group.itemIds.filter((id) => itemIds.has(id)),
|
||||||
|
}))
|
||||||
|
.filter((group) => group.itemIds.length > 0)
|
||||||
|
|
||||||
|
return { items: currentItems, groupedItems: validGroups, errors: allErrors }
|
||||||
}
|
}
|
||||||
|
|
||||||
private ensureGraph(): SourceGraph {
|
private ensureGraph(): SourceGraph {
|
||||||
|
|||||||
@@ -173,6 +173,32 @@ describe("FeedPostProcessor", () => {
|
|||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test("stale item IDs are removed from groups after suppression", async () => {
|
||||||
|
const engine = new FeedEngine()
|
||||||
|
.register(
|
||||||
|
createCalendarSource([calendarItem("c1", "Meeting A"), calendarItem("c2", "Meeting B")]),
|
||||||
|
)
|
||||||
|
.registerPostProcessor(async () => ({
|
||||||
|
groupedItems: [{ itemIds: ["c1", "c2"], summary: "Afternoon" }],
|
||||||
|
}))
|
||||||
|
.registerPostProcessor(async () => ({ suppress: ["c1"] }))
|
||||||
|
|
||||||
|
const result = await engine.refresh()
|
||||||
|
expect(result.groupedItems).toEqual([{ itemIds: ["c2"], summary: "Afternoon" }])
|
||||||
|
})
|
||||||
|
|
||||||
|
test("groups with all items suppressed are dropped", async () => {
|
||||||
|
const engine = new FeedEngine()
|
||||||
|
.register(createCalendarSource([calendarItem("c1", "Meeting A")]))
|
||||||
|
.registerPostProcessor(async () => ({
|
||||||
|
groupedItems: [{ itemIds: ["c1"], summary: "Solo" }],
|
||||||
|
}))
|
||||||
|
.registerPostProcessor(async () => ({ suppress: ["c1"] }))
|
||||||
|
|
||||||
|
const result = await engine.refresh()
|
||||||
|
expect(result.groupedItems).toBeUndefined()
|
||||||
|
})
|
||||||
|
|
||||||
test("groupedItems is omitted when no processors produce groups", async () => {
|
test("groupedItems is omitted when no processors produce groups", async () => {
|
||||||
const engine = new FeedEngine()
|
const engine = new FeedEngine()
|
||||||
.register(createWeatherSource([weatherItem("w1", 20)]))
|
.register(createWeatherSource([weatherItem("w1", 20)]))
|
||||||
|
|||||||
Reference in New Issue
Block a user