Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions products/skills/frontend/LLMSkillScene.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ const SKILL: LLMSkillApi = {
allowed_tools: ['read', 'shell'],
metadata: {},
category: '',
is_global: false,
team_id: 1,
Comment on lines +70 to +71

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Story mock's team_id doesn't match the mocked current team, silently hiding Edit/Archive actions

Priority: should_fix | Category: testing | Lines: 70-71, 108-109

Issue description

The new team_id: 1 field hardcoded on the SKILL mock (and copied onto SKILL_LIST_ENTRY) does not match the team the Storybook App actually bootstraps as the current team. mswDecorator only overrides the llm_skills list/resolve endpoints here; the bootstrap endpoints /api/environments/@current/ and /api/projects/@current/ fall through to the default handler in frontend/src/mocks/handlers.ts, which returns MOCK_DEFAULT_TEAM (id: 997, from frontend/src/lib/api.mock.ts). Since LLMSkillScene.tsx now derives isOwnedByCurrentTeam = isSkill(skill) && skill.team_id === currentTeamId, and 1 !== 997, both SkillDetailStackedBelow2xlBreakpoint and SkillDetailSideBySideAbove2xlBreakpoint will render this PR's new 'read-only, consumed-global-skill' code path: 'Edit latest'/'Use as latest' and 'Archive' will no longer render even though these stories are meant to depict an ordinary owned skill (they exist specifically to test the action-bar/sidebar layout at different breakpoints). This silently changes what the stories exercise and is likely to break any existing visual-regression baselines for these two stories, since they'll suddenly render with fewer action buttons than before this PR.

Suggested fix

Set team_id on the SKILL/SKILL_LIST_ENTRY mocks to the same team ID the Storybook bootstrap mocks resolve to (e.g. import and use MOCK_TEAM_ID from frontend/src/lib/api.mock, or explicitly override the /api/environments/@current/ and /api/projects/@current/ handlers in this story's mswDecorator to return a team with id: 1), so isOwnedByCurrentTeam evaluates true and the stories keep exercising the full owned-skill action bar as intended.

Why we think it's a valid issue

Confirmed against the codebase. In LLMSkillScene.tsx:97, isOwnedByCurrentTeam = isSkill(skill) && skill.team_id === currentTeamId, and the Edit/Use-as-latest (line 129) and Archive (line 208) actions are gated on it; only Download (gated on isSkill, line 172) survives. The story sets SKILL.team_id = 1 (line 71, copied to SKILL_LIST_ENTRY line 109) and its mswDecorator overrides only the llm_skills list/resolve endpoints. The bootstrap endpoints /api/environments/@current/ and /api/projects/@current/ fall through to the default handler (handlers.ts:204-205) which returns MOCK_DEFAULT_TEAM, whose id is MOCK_TEAM_ID = 997 (api.mock.ts:32,48). teamLogic loads currentTeam from api/environments/@current and exposes currentTeamId = currentTeam.id = 997. Therefore 1 !== 997, isOwnedByCurrentTeam is false, and both SkillDetailStackedBelow2xlBreakpoint and SkillDetailSideBySideAbove2xlBreakpoint render the new read-only consumer path with Edit/Archive hidden — not the owned-skill action bar these breakpoint stories were built to depict. This silently changes what the stories exercise and shifts the visual-regression baselines. The mock is also internally incoherent: is_global: false (private) combined with not-owned is a state that can't occur in production, since only global skills surface across teams. Fix is trivial (use MOCK_TEAM_ID / 997). Impact is confined to Storybook/VRT with no production effect, but it degrades the only visual coverage for this scene in the very PR that introduces the ownership gating, so should_fix is appropriate.

Prompt to fix with AI (copy-paste)
## Context
@products/skills/frontend/LLMSkillScene.stories.tsx#L70-71
@products/skills/frontend/LLMSkillScene.stories.tsx#L108-109

<issue_description>
The new `team_id: 1` field hardcoded on the `SKILL` mock (and copied onto `SKILL_LIST_ENTRY`) does not match the team the Storybook `App` actually bootstraps as the current team. `mswDecorator` only overrides the `llm_skills` list/resolve endpoints here; the bootstrap endpoints `/api/environments/@current/` and `/api/projects/@current/` fall through to the default handler in `frontend/src/mocks/handlers.ts`, which returns `MOCK_DEFAULT_TEAM` (`id: 997`, from `frontend/src/lib/api.mock.ts`). Since `LLMSkillScene.tsx` now derives `isOwnedByCurrentTeam = isSkill(skill) && skill.team_id === currentTeamId`, and `1 !== 997`, both `SkillDetailStackedBelow2xlBreakpoint` and `SkillDetailSideBySideAbove2xlBreakpoint` will render this PR's new 'read-only, consumed-global-skill' code path: 'Edit latest'/'Use as latest' and 'Archive' will no longer render even though these stories are meant to depict an ordinary owned skill (they exist specifically to test the action-bar/sidebar layout at different breakpoints). This silently changes what the stories exercise and is likely to break any existing visual-regression baselines for these two stories, since they'll suddenly render with fewer action buttons than before this PR.
</issue_description>

<issue_validation>
Confirmed against the codebase. In LLMSkillScene.tsx:97, isOwnedByCurrentTeam = isSkill(skill) && skill.team_id === currentTeamId, and the Edit/Use-as-latest (line 129) and Archive (line 208) actions are gated on it; only Download (gated on isSkill, line 172) survives. The story sets SKILL.team_id = 1 (line 71, copied to SKILL_LIST_ENTRY line 109) and its mswDecorator overrides only the llm_skills list/resolve endpoints. The bootstrap endpoints /api/environments/@current/ and /api/projects/@current/ fall through to the default handler (handlers.ts:204-205) which returns MOCK_DEFAULT_TEAM, whose id is MOCK_TEAM_ID = 997 (api.mock.ts:32,48). teamLogic loads currentTeam from api/environments/@current and exposes currentTeamId = currentTeam.id = 997. Therefore 1 !== 997, isOwnedByCurrentTeam is false, and both SkillDetailStackedBelow2xlBreakpoint and SkillDetailSideBySideAbove2xlBreakpoint render the new read-only consumer path with Edit/Archive hidden — not the owned-skill action bar these breakpoint stories were built to depict. This silently changes what the stories exercise and shifts the visual-regression baselines. The mock is also internally incoherent: is_global: false (private) combined with not-owned is a state that can't occur in production, since only global skills surface across teams. Fix is trivial (use MOCK_TEAM_ID / 997). Impact is confined to Storybook/VRT with no production effect, but it degrades the only visual coverage for this scene in the very PR that introduces the ownership gating, so should_fix is appropriate.
</issue_validation>

## Task
Investigate the issue and solve it

<potential_solution>
Set `team_id` on the `SKILL`/`SKILL_LIST_ENTRY` mocks to the same team ID the Storybook bootstrap mocks resolve to (e.g. import and use `MOCK_TEAM_ID` from `frontend/src/lib/api.mock`, or explicitly override the `/api/environments/@current/` and `/api/projects/@current/` handlers in this story's `mswDecorator` to return a team with `id: 1`), so `isOwnedByCurrentTeam` evaluates true and the stories keep exercising the full owned-skill action bar as intended.
</potential_solution>

files: [
{ path: 'scripts/extract.sh', content_type: 'text/x-shellscript' },
{ path: 'references/pdf-spec.md', content_type: 'text/markdown' },
Expand Down Expand Up @@ -103,6 +105,8 @@ const SKILL_LIST_ENTRY: LLMSkillListApi = {
allowed_tools: SKILL.allowed_tools,
metadata: {},
category: SKILL.category,
is_global: SKILL.is_global,
team_id: SKILL.team_id,
outline: SKILL.outline,
version: SKILL.version,
created_by: SKILL.created_by,
Expand Down
154 changes: 102 additions & 52 deletions products/skills/frontend/LLMSkillScene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
IconColumns,
IconDocument,
IconDownload,
IconGlobe,
IconPencil,
IconPlus,
IconTrash,
Expand All @@ -27,7 +28,9 @@ import { LemonSkeleton } from 'lib/lemon-ui/LemonSkeleton'
import { copyToClipboard } from 'lib/utils/copyToClipboard'
import { lazyWithRetry } from 'lib/utils/retryImport'
import { SceneExport } from 'scenes/sceneTypes'
import { teamLogic } from 'scenes/teamLogic'
import { urls } from 'scenes/urls'
import { userLogic } from 'scenes/userLogic'

import { themeLogic } from '~/layout/navigation-3000/themeLogic'
import { SceneContent } from '~/layout/scenes/components/SceneContent'
Expand All @@ -42,7 +45,7 @@ import type { SkillFormFileValues } from './llmSkillLogic'
import { SkillLogicProps, SkillMode, isSkill, llmSkillLogic } from './llmSkillLogic'
import { SKILL_NAME_MAX_LENGTH, SKILL_DESCRIPTION_MAX_LENGTH } from './skillConstants'
import { skillFileLogic } from './skillFileLogic'
import { openArchiveSkillDialog } from './skillSceneComponents'
import { openArchiveSkillDialog, openSkillVisibilityDialog } from './skillSceneComponents'

const MonacoDiffEditor = lazyWithRetry(() => import('lib/components/MonacoDiffEditor'))

Expand Down Expand Up @@ -73,11 +76,26 @@ export function LLMSkillScene(): JSX.Element {
canLoadMoreVersions,
fileContentsLoading,
downloadingZip,
settingVisibility,
} = useValues(llmSkillLogic)
const { searchParams } = useValues(router)
const { user } = useValues(userLogic)
const { currentTeamId } = useValues(teamLogic)

const { submitSkillForm, deleteSkill, setMode, setSkillFormValues, loadMoreVersions, downloadSkill } =
useActions(llmSkillLogic)
const {
submitSkillForm,
deleteSkill,
setMode,
setSkillFormValues,
loadMoreVersions,
downloadSkill,
setGlobalVisibility,
} = useActions(llmSkillLogic)

// A global skill surfaced from another team is read-only here — only its owning project can
// edit it, and only staff can change its visibility (and only from the owning project).
const isOwnedByCurrentTeam = isSkill(skill) && skill.team_id === currentTeamId
const canManageVisibility = !!user?.is_staff && isOwnedByCurrentTeam

if (isSkillMissing) {
return <NotFound object="skill" />
Expand All @@ -99,49 +117,57 @@ export function LLMSkillScene(): JSX.Element {
name={skill && 'name' in skill ? skill.name : 'Skill'}
resourceType={{ type: 'llm_analytics' }}
isLoading={skillLoading}
nameSuffix={
isSkill(skill) && skill.is_global ? (
<LemonTag type="highlight" icon={<IconGlobe />} size="medium">
Global
</LemonTag>
) : undefined
}
actions={
<>
{isSkill(skill) && skill.is_latest ? (
<AccessControlAction
resourceType={AccessControlResourceType.LlmAnalytics}
minAccessLevel={AccessControlLevel.Editor}
>
<LemonButton
type="primary"
icon={<IconPencil />}
onClick={() => setMode(SkillMode.Edit)}
size="small"
data-attr="llma-skill-edit-button"
{isOwnedByCurrentTeam &&
(isSkill(skill) && skill.is_latest ? (
<AccessControlAction
resourceType={AccessControlResourceType.LlmAnalytics}
minAccessLevel={AccessControlLevel.Editor}
>
Edit latest
</LemonButton>
</AccessControlAction>
) : (
<AccessControlAction
resourceType={AccessControlResourceType.LlmAnalytics}
minAccessLevel={AccessControlLevel.Editor}
>
<LemonButton
type="primary"
onClick={() => {
if (isSkill(skill)) {
setSkillFormValues({
name: skill.name,
description: skill.description,
body: skill.body,
license: skill.license || '',
compatibility: skill.compatibility || '',
})
setMode(SkillMode.Edit)
}
}}
size="small"
data-attr="llma-skill-use-as-latest-button"
<LemonButton
type="primary"
icon={<IconPencil />}
onClick={() => setMode(SkillMode.Edit)}
size="small"
data-attr="llma-skill-edit-button"
>
Edit latest
</LemonButton>
</AccessControlAction>
) : (
<AccessControlAction
resourceType={AccessControlResourceType.LlmAnalytics}
minAccessLevel={AccessControlLevel.Editor}
>
Use as latest
</LemonButton>
</AccessControlAction>
)}
<LemonButton
type="primary"
onClick={() => {
if (isSkill(skill)) {
setSkillFormValues({
name: skill.name,
description: skill.description,
body: skill.body,
license: skill.license || '',
compatibility: skill.compatibility || '',
})
setMode(SkillMode.Edit)
}
}}
size="small"
data-attr="llma-skill-use-as-latest-button"
>
Use as latest
</LemonButton>
</AccessControlAction>
))}

{isSkill(skill) && (
<LemonButton
Expand All @@ -157,21 +183,45 @@ export function LLMSkillScene(): JSX.Element {
</LemonButton>
)}

<AccessControlAction
resourceType={AccessControlResourceType.LlmAnalytics}
minAccessLevel={AccessControlLevel.Editor}
>
{canManageVisibility && isSkill(skill) && (
<LemonButton
type="secondary"
status="danger"
icon={<IconTrash />}
onClick={() => openArchiveSkillDialog(deleteSkill)}
icon={<IconGlobe />}
onClick={() =>
openSkillVisibilityDialog(!skill.is_global, () =>
setGlobalVisibility(!skill.is_global)
)
}
loading={settingVisibility}
size="small"
data-attr="llma-skill-delete-button"
tooltip={
skill.is_global
? 'Restrict this skill to this project'
: 'Make this skill visible to every PostHog customer'
}
data-attr="llma-skill-visibility-button"
>
Archive
{skill.is_global ? 'Make private' : 'Make visible to everyone'}
</LemonButton>
</AccessControlAction>
)}

{isOwnedByCurrentTeam && (
<AccessControlAction
resourceType={AccessControlResourceType.LlmAnalytics}
minAccessLevel={AccessControlLevel.Editor}
>
<LemonButton
type="secondary"
status="danger"
icon={<IconTrash />}
onClick={() => openArchiveSkillDialog(deleteSkill)}
size="small"
data-attr="llma-skill-delete-button"
>
Archive
</LemonButton>
</AccessControlAction>
)}
</>
}
/>
Expand Down
Loading
Loading