Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(skills): treat a body-less skills list response as an empty page (#107535)

posthog[bot]0b3602478134
diff --git a/products/skills/frontend/llmSkillsLogic.test.ts b/products/skills/frontend/llmSkillsLogic.test.ts
new file mode 100644
index 000000000000..26255a8ad899
--- /dev/null
+++ b/products/skills/frontend/llmSkillsLogic.test.ts
@@ -0,0 +1,43 @@
+import { expectLogic } from 'kea-test-utils'
+
+import { initKeaTests } from '~/test/init'
+
+import { llmSkillsList } from 'products/skills/frontend/generated/api'
+
+import { llmSkillsLogic } from './llmSkillsLogic'
+
+jest.mock('products/skills/frontend/generated/api', () => ({
+ llmSkillsList: jest.fn(),
+}))
+
+const mockList = llmSkillsList as jest.MockedFunction<typeof llmSkillsList>
+
+describe('llmSkillsLogic', () => {
+ let logic: ReturnType<typeof llmSkillsLogic.build>
+
+ beforeEach(() => {
+ jest.clearAllMocks()
+ initKeaTests()
+ })
+
+ afterEach(() => {
+ logic?.unmount()
+ })
+
+ it.each([
+ ['flat list', false],
+ ['grouped list', true],
+ ])('renders an empty %s when the list response has no body', async (_desc, groupByPrefix) => {
+ // The API layer resolves a 204 or an empty body to null, although the generated type says otherwise.
+ mockList.mockResolvedValue(null as unknown as Awaited<ReturnType<typeof llmSkillsList>>)
+ logic = llmSkillsLogic()
+ logic.mount()
+ logic.actions.setFilters({ group_by_prefix: groupByPrefix }, true, false)
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(logic.values.skills).toEqual({ results: [], count: 0 })
+ expect(logic.values.count).toBe(0)
+ expect(logic.values.skillCountLabel).toBe('0 skills')
+ expect(logic.values.groupedSkills === null).toBe(!groupByPrefix)
+ })
+})
diff --git a/products/skills/frontend/llmSkillsLogic.ts b/products/skills/frontend/llmSkillsLogic.ts
index b0b225fc5ea4..9860ca35d380 100644
--- a/products/skills/frontend/llmSkillsLogic.ts
+++ b/products/skills/frontend/llmSkillsLogic.ts
@@ -501,7 +501,9 @@ export const llmSkillsLogic = kea<llmSkillsLogicType>([
window.scrollTo(0, 0)
}
- return await llmSkillsList(String(ApiConfig.getCurrentTeamId()), params)
+ // The API layer returns null for a body-less response, which would crash every selector here.
+ const response = await llmSkillsList(String(ApiConfig.getCurrentTeamId()), params)
+ return response ?? { results: [], count: 0 }
},
},
],