Repository navigation
fix(assets): cloud Generated tab uses /api/assets so deleted outputs disappear (FE-740) #12464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| import { describe, expect, it, vi } from 'vitest' | ||
| import { ref } from 'vue' | ||
| import type { Ref } from 'vue' | ||
|
|
||
| import type { AssetItem } from '@/platform/assets/schemas/assetSchema' | ||
|
|
||
| import { useFlatOutputAssetsGrouped } from './useFlatOutputAssetsGrouped' | ||
|
|
||
| const mediaRef: Ref<AssetItem[]> = ref([]) | ||
|
|
||
| vi.mock('./useFlatOutputAssets', () => ({ | ||
| useFlatOutputAssets: () => ({ | ||
| media: mediaRef, | ||
| loading: ref(false), | ||
| error: ref(null), | ||
| hasMore: ref(false), | ||
| isLoadingMore: ref(false), | ||
| fetchMediaList: vi.fn(), | ||
| refresh: vi.fn(), | ||
| loadMore: vi.fn() | ||
| }) | ||
| })) | ||
|
|
||
| function asset(overrides: Partial<AssetItem> = {}): AssetItem { | ||
| return { | ||
| id: 'asset-id', | ||
| name: 'output.png', | ||
| tags: ['output'], | ||
| ...overrides | ||
| } | ||
| } | ||
|
|
||
| describe('useFlatOutputAssetsGrouped', () => { | ||
| it('collapses rows with the same job_id into a single representative', () => { | ||
| mediaRef.value = [ | ||
| asset({ id: 'a', name: 'out1.png', job_id: 'job-1' }), | ||
| asset({ id: 'b', name: 'out2.png', job_id: 'job-1' }), | ||
| asset({ id: 'c', name: 'out3.png', job_id: 'job-1' }), | ||
| asset({ id: 'd', name: 'solo.png', job_id: 'job-2' }) | ||
| ] | ||
|
|
||
| const { media } = useFlatOutputAssetsGrouped() | ||
|
|
||
| expect(media.value.map((a) => a.id)).toEqual(['a', 'd']) | ||
| }) | ||
|
|
||
| it('exposes the group size as user_metadata.outputCount', () => { | ||
| mediaRef.value = [ | ||
| asset({ id: 'a', job_id: 'job-1' }), | ||
| asset({ id: 'b', job_id: 'job-1' }), | ||
| asset({ id: 'c', job_id: 'job-1' }), | ||
| asset({ id: 'd', job_id: 'job-2' }) | ||
| ] | ||
|
|
||
| const { media } = useFlatOutputAssetsGrouped() | ||
|
|
||
| expect(media.value[0].user_metadata?.outputCount).toBe(3) | ||
| expect(media.value[0].user_metadata?.jobId).toBe('job-1') | ||
| expect(media.value[1].user_metadata?.outputCount).toBe(1) | ||
| }) | ||
|
|
||
| it('falls back to prompt_id when job_id is absent (legacy)', () => { | ||
| mediaRef.value = [ | ||
| asset({ id: 'a', prompt_id: 'job-legacy' }), | ||
| asset({ id: 'b', prompt_id: 'job-legacy' }) | ||
| ] | ||
|
|
||
| const { media } = useFlatOutputAssetsGrouped() | ||
|
|
||
| expect(media.value).toHaveLength(1) | ||
| expect(media.value[0].user_metadata?.jobId).toBe('job-legacy') | ||
| expect(media.value[0].user_metadata?.outputCount).toBe(2) | ||
| }) | ||
|
|
||
| it('passes through rows that have neither job_id nor prompt_id', () => { | ||
| mediaRef.value = [asset({ id: 'orphan-a' }), asset({ id: 'orphan-b' })] | ||
|
|
||
| const { media } = useFlatOutputAssetsGrouped() | ||
|
|
||
| expect(media.value.map((a) => a.id)).toEqual(['orphan-a', 'orphan-b']) | ||
| }) | ||
|
|
||
| it('preserves the order of the first occurrence per job_id', () => { | ||
| mediaRef.value = [ | ||
| asset({ id: 'a', job_id: 'job-A' }), | ||
| asset({ id: 'b', job_id: 'job-B' }), | ||
| asset({ id: 'c', job_id: 'job-A' }), | ||
| asset({ id: 'd', job_id: 'job-C' }) | ||
| ] | ||
|
|
||
| const { media } = useFlatOutputAssetsGrouped() | ||
|
|
||
| expect(media.value.map((a) => a.id)).toEqual(['a', 'b', 'd']) | ||
| }) | ||
|
|
||
| it('does not mutate the underlying assets', () => { | ||
| const original = asset({ id: 'a', job_id: 'job-1' }) | ||
| mediaRef.value = [original, asset({ id: 'b', job_id: 'job-1' })] | ||
|
|
||
| const { media } = useFlatOutputAssetsGrouped() | ||
| void media.value | ||
|
|
||
| expect(original.user_metadata).toBeUndefined() | ||
| }) | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import { computed } from 'vue' | ||
|
|
||
| import type { AssetItem } from '@/platform/assets/schemas/assetSchema' | ||
|
|
||
| import type { IAssetsProvider } from './IAssetsProvider' | ||
| import { useFlatOutputAssets } from './useFlatOutputAssets' | ||
|
|
||
| /** | ||
| * Cloud `/api/assets?include_tags=output` returns one row per individual output | ||
| * file. The asset sidebar's stack UX expects one card per job with an | ||
| * `outputCount` badge, so collapse rows that share a `job_id` into a single | ||
| * representative (the first occurrence — assets are returned newest-first). | ||
| * | ||
| * The siblings remain reachable through the existing stack-expand path via | ||
| * `resolveOutputAssetItems(metadata)`. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue: Expansion restores Asset-API-deleted outputs. Full context for agent readersGrouping retains only the surviving Asset API rows, but these rows have no |
||
| */ | ||
| export function useFlatOutputAssetsGrouped(): IAssetsProvider { | ||
| const inner = useFlatOutputAssets() | ||
|
|
||
| const media = computed(() => groupByJobId(inner.media.value)) | ||
|
|
||
| return { | ||
| ...inner, | ||
| media | ||
| } | ||
| } | ||
|
|
||
| function groupByJobId(assets: AssetItem[]): AssetItem[] { | ||
| const countsByJobId = new Map<string, number>() | ||
| for (const asset of assets) { | ||
| const jobId = asset.job_id ?? asset.prompt_id | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟢 Low — |
||
| if (!jobId) continue | ||
| countsByJobId.set(jobId, (countsByJobId.get(jobId) ?? 0) + 1) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟢 Low — |
||
| } | ||
|
|
||
| const seenJobIds = new Set<string>() | ||
| const grouped: AssetItem[] = [] | ||
| for (const asset of assets) { | ||
| const jobId = asset.job_id ?? asset.prompt_id ?? null | ||
| if (!jobId) { | ||
| grouped.push(asset) | ||
| continue | ||
| } | ||
| if (seenJobIds.has(jobId)) continue | ||
| seenJobIds.add(jobId) | ||
|
|
||
| const outputCount = countsByJobId.get(jobId) ?? 1 | ||
| grouped.push({ | ||
| ...asset, | ||
| user_metadata: { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 High — The grouped representative's |
||
| ...asset.user_metadata, | ||
| jobId, | ||
| outputCount | ||
| } | ||
| }) | ||
| } | ||
| return grouped | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,7 +56,7 @@ export function useOutputStacks({ assets }: UseOutputStacksOptions) { | |
|
|
||
| function getStackJobId(asset: AssetItem): string | null { | ||
| const metadata = getOutputAssetMetadata(asset.user_metadata) | ||
| return metadata?.jobId ?? null | ||
| return metadata?.jobId ?? asset.job_id ?? null | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟢 Low — |
||
| } | ||
|
|
||
| function isStackExpanded(asset: AssetItem): boolean { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,31 +2,26 @@ import type { ComfyWorkflowJSON } from '@/platform/workflow/validation/schemas/w | |
| import type { ResultItemImpl } from '@/stores/queueStore' | ||
|
|
||
| /** | ||
| * Metadata for output assets from queue store | ||
| * Extends Record<string, unknown> for compatibility with AssetItem schema | ||
| * Metadata for output assets. Originates from the queue/history mapping but | ||
| * also surfaces on assets sourced directly from `/api/assets?include_tags=output`, | ||
| * which carry `jobId` only (no per-output `nodeId` / `subfolder`). | ||
| */ | ||
| export interface OutputAssetMetadata extends Record<string, unknown> { | ||
| jobId: string | ||
| nodeId: string | number | ||
| subfolder: string | ||
| nodeId?: string | number | ||
| subfolder?: string | ||
| executionTimeInSeconds?: number | ||
| format?: string | ||
| workflow?: ComfyWorkflowJSON | ||
| outputCount?: number | ||
| allOutputs?: ResultItemImpl[] | ||
| } | ||
|
|
||
| /** | ||
| * Type guard to check if metadata is OutputAssetMetadata | ||
| */ | ||
| function isOutputAssetMetadata( | ||
| metadata: Record<string, unknown> | undefined | ||
| ): metadata is OutputAssetMetadata { | ||
| if (!metadata) return false | ||
| return ( | ||
| typeof metadata.jobId === 'string' && | ||
| (typeof metadata.nodeId === 'string' || typeof metadata.nodeId === 'number') | ||
| ) | ||
| return typeof metadata.jobId === 'string' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium — |
||
| } | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟠 High — This swaps the output provider from
useAssetsApi('output')(backed byapi.getHistory(), which works in OSS) touseFlatOutputAssetsGrouped(), which readsflatOutputAssetspopulated viaassetService.getAssetsPageByTag(OUTPUT_TAG, ...)— a path the store explicitly comments as 'cloud-only'. In OSS/non-cloud runs the generated-outputs tab may stop loading and render empty; gate this onisCloud(falling back to the history provider) or confirm/api/assets?include_tags=outputis served in OSS. Raised by 1 of 8 reviewers (gpt-5.3-codex-xhigh edge-case).