fix(aiui): mock libraries drop out of the production bundle (W1.4)
Every mock consumer is now gated on the demo flag inline (canonical Vite DCE idiom — the cross-module DEMO_CONTENT_ENABLED const defeated folding). But the real leak was films.ts's module-level allGenres/allSources exports: [...new Set(mockFilms.flatMap(...))] is unprovably pure, so the treeshaker kept the whole module — array, plex:// and cloud.example.com hosts and all — even with zero live references. The mocks directory is now declared side-effect-free in vite.config (they are pure data by design), so unneeded mock modules actually drop. Verified: clean dist build → entry bundle AND dist-wide grep show zero mock hosts (spotify/track/example, cloud.example.com, plex://, tmdb image host). Demo/dev builds (VITE_DEMO_CONTENT=true or import.meta.env.DEV) keep the full pack. Tests: 353/356, failures are the three documented pre-existing ones. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,11 @@ import { mockFilms } from '@/mocks/films'
|
||||
import { mockSongs } from '@/mocks/songs'
|
||||
import { mockPodcasts } from '@/mocks/podcasts'
|
||||
|
||||
// Demo-site content pack (operator decision 2026-08-07): demo/dev only.
|
||||
const demoFilms = (import.meta.env.DEV || import.meta.env.VITE_DEMO_CONTENT === 'true') ? mockFilms : []
|
||||
const demoSongs = (import.meta.env.DEV || import.meta.env.VITE_DEMO_CONTENT === 'true') ? mockSongs : []
|
||||
const demoPodcasts = (import.meta.env.DEV || import.meta.env.VITE_DEMO_CONTENT === 'true') ? mockPodcasts : []
|
||||
|
||||
export interface MCPTool {
|
||||
name: string
|
||||
description: string
|
||||
@@ -97,7 +102,7 @@ type ToolHandler = (input: Record<string, unknown>) => unknown
|
||||
const toolHandlers: Record<string, ToolHandler> = {
|
||||
search_films(input) {
|
||||
const query = (input.query as string ?? '').toLowerCase()
|
||||
const results = mockFilms.filter(f =>
|
||||
const results = demoFilms.filter(f =>
|
||||
f.title.toLowerCase().includes(query) ||
|
||||
f.director.toLowerCase().includes(query) ||
|
||||
f.genres.some(g => g.toLowerCase().includes(query)),
|
||||
@@ -117,7 +122,7 @@ const toolHandlers: Record<string, ToolHandler> = {
|
||||
|
||||
search_songs(input) {
|
||||
const query = (input.query as string ?? '').toLowerCase()
|
||||
const results = mockSongs.filter(s =>
|
||||
const results = demoSongs.filter(s =>
|
||||
s.title.toLowerCase().includes(query) ||
|
||||
s.artist.toLowerCase().includes(query) ||
|
||||
(s.genres ?? []).some(g => g.toLowerCase().includes(query)),
|
||||
@@ -137,7 +142,7 @@ const toolHandlers: Record<string, ToolHandler> = {
|
||||
|
||||
search_podcasts(input) {
|
||||
const query = (input.query as string ?? '').toLowerCase()
|
||||
const results = mockPodcasts.filter(p =>
|
||||
const results = demoPodcasts.filter(p =>
|
||||
p.title.toLowerCase().includes(query) ||
|
||||
(p.host ?? '').toLowerCase().includes(query) ||
|
||||
(p.genres ?? []).some(g => g.toLowerCase().includes(query)),
|
||||
@@ -156,13 +161,13 @@ const toolHandlers: Record<string, ToolHandler> = {
|
||||
|
||||
get_library_stats() {
|
||||
return {
|
||||
films: mockFilms.length,
|
||||
songs: mockSongs.length,
|
||||
podcasts: mockPodcasts.length,
|
||||
films: demoFilms.length,
|
||||
songs: demoSongs.length,
|
||||
podcasts: demoPodcasts.length,
|
||||
genres: {
|
||||
film: [...new Set(mockFilms.flatMap(f => f.genres))].sort(),
|
||||
song: [...new Set(mockSongs.flatMap(s => s.genres ?? []))].sort(),
|
||||
podcast: [...new Set(mockPodcasts.flatMap(p => p.genres ?? []))].sort(),
|
||||
film: [...new Set(demoFilms.flatMap(f => f.genres))].sort(),
|
||||
song: [...new Set(demoSongs.flatMap(s => s.genres ?? []))].sort(),
|
||||
podcast: [...new Set(demoPodcasts.flatMap(p => p.genres ?? []))].sort(),
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user