Image Pipeline Playground
feat(frontend): enhance custom Python scripting with logging and UI improvements
Mohammad Rajaeie66aa6983be0
diff --git a/frontend/public/examples/custom_python_sepia.json b/frontend/public/examples/custom_python_sepia.jsonindex 8797b34..23e6796 100644--- a/frontend/public/examples/custom_python_sepia.json+++ b/frontend/public/examples/custom_python_sepia.json@@ -16,7 +16,7 @@"id": "custom-1","type": "custom_python","params": {- "code": "def process(image, seed=0):\n # Simple sepia tone (BGR uint8)\n import numpy as np\n b = image[:, :, 0].astype(np.float32)\n g = image[:, :, 1].astype(np.float32)\n r = image[:, :, 2].astype(np.float32)\n tr = 0.393 * r + 0.769 * g + 0.189 * b\n tg = 0.349 * r + 0.686 * g + 0.168 * b\n tb = 0.272 * r + 0.534 * g + 0.131 * b\n out = image.copy()\n out[:, :, 0] = np.clip(tb, 0, 255).astype(np.uint8)\n out[:, :, 1] = np.clip(tg, 0, 255).astype(np.uint8)\n out[:, :, 2] = np.clip(tr, 0, 255).astype(np.uint8)\n return out\n"+ "code": "def process(image, seed=0):\n # Simple sepia tone (BGR uint8).\n # log(...) lines show up in the Script log panel below.\n log(\"sepia start\", \"seed=\", seed)\n log(\"input\", image)\n\n b = image[:, :, 0].astype(np.float32)\n g = image[:, :, 1].astype(np.float32)\n r = image[:, :, 2].astype(np.float32)\n tr = 0.393 * r + 0.769 * g + 0.189 * b\n tg = 0.349 * r + 0.686 * g + 0.168 * b\n tb = 0.272 * r + 0.534 * g + 0.131 * b\n out = image.copy()\n out[:, :, 0] = np.clip(tb, 0, 255).astype(np.uint8)\n out[:, :, 1] = np.clip(tg, 0, 255).astype(np.uint8)\n out[:, :, 2] = np.clip(tr, 0, 255).astype(np.uint8)\n\n log(\"sepia done\", out)\n return out\n"},"position": { "x": 220, "y": 0 }}diff --git a/frontend/src/features/inspector/CustomPythonParams.test.tsx b/frontend/src/features/inspector/CustomPythonParams.test.tsxindex 9fddf6b..dbfdda8 100644--- a/frontend/src/features/inspector/CustomPythonParams.test.tsx+++ b/frontend/src/features/inspector/CustomPythonParams.test.tsx@@ -116,4 +116,16 @@ describe('CustomPythonParams', () => {await waitFor(() => expect(invalidate).toHaveBeenCalledWith({ queryKey: ['nodes'] }))fetchSpy.mockRestore()})++ it('shows helpers button and script log box', async () => {+ renderParams()+ const user = userEvent.setup()+ expect(screen.getByRole('button', { name: /Script helpers/i })).toBeInTheDocument()+ expect(screen.getByText(/^Script log$/i)).toBeInTheDocument()+ expect(screen.getByText(/No script logs yet/i)).toBeInTheDocument()++ await user.click(screen.getByRole('button', { name: /Script helpers/i }))+ expect(await screen.findByText('Script helpers')).toBeInTheDocument()+ expect(screen.getByText('log(*args)')).toBeInTheDocument()+ })})diff --git a/frontend/src/features/inspector/CustomPythonParams.tsx b/frontend/src/features/inspector/CustomPythonParams.tsxindex c1e1596..dbfb5fd 100644--- a/frontend/src/features/inspector/CustomPythonParams.tsx+++ b/frontend/src/features/inspector/CustomPythonParams.tsx@@ -14,6 +14,8 @@ import { useQueryClient } from '@tanstack/react-query'import { createUserScript } from '../../api/userScripts'import { notifyError } from '../../notify'import { useGraphStore } from '../../store/graphStore'+import { ScriptLogBox } from './ScriptLogBox'+import { ScriptHelpersButton } from './ScriptHelpersButton'type CustomPythonParamsProps = {nodeId: string@@ -149,7 +151,8 @@ export function CustomPythonParams({ nodeId, code, onCodeChange }: CustomPythonP<Typography sx={{ fontSize: 12, fontWeight: 650, color: 'rgba(244,241,234,0.7)' }}>Code</Typography>- <Box sx={{ display: 'flex', gap: 1 }}>+ <Box sx={{ display: 'flex', gap: 1, flexWrap: 'wrap' }}>+ <ScriptHelpersButton /><Buttonsize="small"variant="outlined"@@ -213,6 +216,8 @@ export function CustomPythonParams({ nodeId, code, onCodeChange }: CustomPythonP/></Box>+ <ScriptLogBox nodeId={nodeId} />+<Dialogopen={editing}onClose={() => closeEditor(true)}@@ -255,6 +260,7 @@ export function CustomPythonParams({ nodeId, code, onCodeChange }: CustomPythonP>Edit Custom Python</Typography>+ <ScriptHelpersButton compact /><Buttonsize="small"onClick={() => closeEditor(false)}diff --git a/frontend/src/features/inspector/NodeInspector.tsx b/frontend/src/features/inspector/NodeInspector.tsxindex 50429ec..3589a31 100644--- a/frontend/src/features/inspector/NodeInspector.tsx+++ b/frontend/src/features/inspector/NodeInspector.tsx@@ -144,6 +144,7 @@ export function NodeInspector() {) : isUserScript ? (<UserScriptParamskey={selected.id}+ nodeId={selected.id}nodeType={selected.data.type}label={selected.data.label}version={Number(selected.data.params.version ?? 1)}diff --git a/frontend/src/features/inspector/ScriptHelpersButton.tsx b/frontend/src/features/inspector/ScriptHelpersButton.tsxnew file mode 100644index 0000000..b114508--- /dev/null+++ b/frontend/src/features/inspector/ScriptHelpersButton.tsx@@ -0,0 +1,42 @@+import { useState } from 'react'+import { Button } from '@mui/material'+import { ScriptHelpersModal } from './ScriptHelpersModal'++const ICON_COLOR = '#f0ebe3'++type ScriptHelpersButtonProps = {+ /** Compact icon-style control for dense toolbars. */+ compact?: boolean+}++export function ScriptHelpersButton({ compact = false }: ScriptHelpersButtonProps) {+ const [open, setOpen] = useState(false)++ return (+ <>+ <Button+ size="small"+ variant="outlined"+ aria-label="Script helpers"+ onClick={() => setOpen(true)}+ sx={{+ textTransform: 'none',+ fontWeight: 650,+ fontSize: compact ? 12 : 12,+ minWidth: compact ? 32 : undefined,+ px: compact ? 1 : 1.25,+ color: ICON_COLOR,+ borderColor: 'rgba(255,255,255,0.16)',+ '&:hover': {+ borderColor: 'rgba(93,173,226,0.45)',+ bgcolor: 'rgba(93,173,226,0.08)',+ color: '#5dade2',+ },+ }}+ >+ {compact ? '?' : 'Helpers'}+ </Button>+ <ScriptHelpersModal open={open} onClose={() => setOpen(false)} />+ </>+ )+}diff --git a/frontend/src/features/inspector/ScriptHelpersModal.test.tsx b/frontend/src/features/inspector/ScriptHelpersModal.test.tsxnew file mode 100644index 0000000..d06706e--- /dev/null+++ b/frontend/src/features/inspector/ScriptHelpersModal.test.tsx@@ -0,0 +1,24 @@+import { render, screen } from '@testing-library/react'+import userEvent from '@testing-library/user-event'+import { describe, expect, it, vi } from 'vitest'+import { ScriptHelpersModal } from './ScriptHelpersModal'+import { SCRIPT_HELPERS, SCRIPT_HELPERS_TAGLINE } from './scriptHelpersHint'++describe('ScriptHelpersModal', () => {+ it('lists helpers with signatures and future-helpers note', () => {+ render(<ScriptHelpersModal open onClose={() => {}} />)+ expect(screen.getByText('Script helpers')).toBeInTheDocument()+ expect(screen.getByText(SCRIPT_HELPERS_TAGLINE)).toBeInTheDocument()+ expect(screen.getByText(SCRIPT_HELPERS[0]!.signature)).toBeInTheDocument()+ expect(screen.getByText(SCRIPT_HELPERS[0]!.summary)).toBeInTheDocument()+ expect(screen.getByText(/More helpers will appear/i)).toBeInTheDocument()+ })++ it('closes from the Close button', async () => {+ const onClose = vi.fn()+ const user = userEvent.setup()+ render(<ScriptHelpersModal open onClose={onClose} />)+ await user.click(screen.getByRole('button', { name: /^Close$/i }))+ expect(onClose).toHaveBeenCalled()+ })+})diff --git a/frontend/src/features/inspector/ScriptHelpersModal.tsx b/frontend/src/features/inspector/ScriptHelpersModal.tsxnew file mode 100644index 0000000..12172c6--- /dev/null+++ b/frontend/src/features/inspector/ScriptHelpersModal.tsx@@ -0,0 +1,120 @@+import {+ Box,+ Button,+ Dialog,+ DialogActions,+ DialogContent,+ DialogTitle,+ Stack,+ Typography,+} from '@mui/material'+import {+ SCRIPT_HELPERS,+ SCRIPT_HELPERS_FOOTNOTE,+ SCRIPT_HELPERS_TAGLINE,+} from './scriptHelpersHint'++type ScriptHelpersModalProps = {+ open: boolean+ onClose: () => void+}++export function ScriptHelpersModal({ open, onClose }: ScriptHelpersModalProps) {+ return (+ <Dialog+ open={open}+ onClose={onClose}+ maxWidth="sm"+ fullWidth+ className="nokey"+ slotProps={{+ paper: {+ className: 'nokey',+ sx: {+ bgcolor: '#161616',+ color: '#f4f1ea',+ borderRadius: 2,+ border: '1px solid rgba(255,255,255,0.1)',+ backgroundImage:+ 'radial-gradient(ellipse 80% 60% at 0% 0%, rgba(93,173,226,0.12), transparent 55%)',+ },+ },+ }}+ >+ <DialogTitle+ sx={{+ fontFamily: '"Fraunces", Georgia, serif',+ fontWeight: 700,+ letterSpacing: '-0.02em',+ pb: 0.5,+ }}+ >+ Script helpers+ </DialogTitle>+ <DialogContent>+ <Typography sx={{ color: 'rgba(244,241,234,0.55)', fontSize: 13, mb: 2 }}>+ {SCRIPT_HELPERS_TAGLINE}+ </Typography>++ <Stack spacing={1.75} sx={{ mb: 2.5 }}>+ {SCRIPT_HELPERS.map((helper) => (+ <Box+ key={helper.signature}+ sx={{+ p: 1.5,+ borderRadius: 1.5,+ border: '1px solid rgba(255,255,255,0.08)',+ bgcolor: 'rgba(255,255,255,0.03)',+ }}+ >+ <Typography+ component="code"+ sx={{+ display: 'block',+ fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Consolas, monospace',+ fontSize: 13,+ fontWeight: 650,+ color: '#5dade2',+ mb: 0.5,+ }}+ >+ {helper.signature}+ </Typography>+ <Typography sx={{ fontSize: 14, fontWeight: 600, mb: 0.5 }}>+ {helper.summary}+ </Typography>+ <Typography sx={{ fontSize: 13, lineHeight: 1.55, color: 'rgba(244,241,234,0.6)' }}>+ {helper.detail}+ </Typography>+ </Box>+ ))}+ </Stack>++ <Typography+ sx={{+ fontSize: 12,+ color: 'rgba(244,241,234,0.4)',+ lineHeight: 1.5,+ }}+ >+ {SCRIPT_HELPERS_FOOTNOTE}+ </Typography>+ </DialogContent>+ <DialogActions sx={{ px: 3, pb: 2 }}>+ <Button+ onClick={onClose}+ variant="contained"+ sx={{+ textTransform: 'none',+ fontWeight: 700,+ bgcolor: '#e67e22',+ color: '#0f0f0f',+ '&:hover': { bgcolor: '#f39c12' },+ }}+ >+ Close+ </Button>+ </DialogActions>+ </Dialog>+ )+}diff --git a/frontend/src/features/inspector/ScriptLogBox.test.tsx b/frontend/src/features/inspector/ScriptLogBox.test.tsxnew file mode 100644index 0000000..0971d58--- /dev/null+++ b/frontend/src/features/inspector/ScriptLogBox.test.tsx@@ -0,0 +1,36 @@+import { render, screen } from '@testing-library/react'+import { beforeEach, describe, expect, it } from 'vitest'+import { useGraphStore } from '../../store/graphStore'+import { ScriptLogBox } from './ScriptLogBox'+import { SCRIPT_HELPERS } from './scriptHelpersHint'++describe('ScriptLogBox', () => {+ beforeEach(() => {+ useGraphStore.setState({ scriptLogsByNodeId: {} })+ })++ it('shows empty state when there are no lines', () => {+ render(<ScriptLogBox nodeId="custom-1" />)+ expect(screen.getByText(/No script logs yet/i)).toBeInTheDocument()+ expect(screen.getByText(/log\(\.\.\.\)/i)).toBeInTheDocument()+ })++ it('renders lines for the given node id only', () => {+ useGraphStore.setState({+ scriptLogsByNodeId: {+ 'custom-1': ['hello', 'ndarray(shape=(2, 2, 3), dtype=uint8)'],+ other: ['ignore me'],+ },+ })+ render(<ScriptLogBox nodeId="custom-1" />)+ expect(screen.getByText('hello')).toBeInTheDocument()+ expect(screen.getByText(/ndarray\(shape=\(2, 2, 3\)/)).toBeInTheDocument()+ expect(screen.queryByText('ignore me')).not.toBeInTheDocument()+ })+})++describe('scriptHelpers catalog', () => {+ it('documents log for the helpers modal', () => {+ expect(SCRIPT_HELPERS.some((item) => item.signature.startsWith('log('))).toBe(true)+ })+})diff --git a/frontend/src/features/inspector/ScriptLogBox.tsx b/frontend/src/features/inspector/ScriptLogBox.tsxnew file mode 100644index 0000000..f7dd6f1--- /dev/null+++ b/frontend/src/features/inspector/ScriptLogBox.tsx@@ -0,0 +1,60 @@+import { useEffect, useRef } from 'react'+import { Box, Typography } from '@mui/material'+import { useGraphStore } from '../../store/graphStore'++type ScriptLogBoxProps = {+ nodeId: string+}++const EMPTY_LINES: string[] = []++export function ScriptLogBox({ nodeId }: ScriptLogBoxProps) {+ const lines = useGraphStore((s) => s.scriptLogsByNodeId[nodeId] ?? EMPTY_LINES)+ const listRef = useRef<HTMLDivElement>(null)++ useEffect(() => {+ const el = listRef.current+ if (!el) return+ el.scrollTop = el.scrollHeight+ }, [lines])++ return (+ <Box sx={{ display: 'grid', gap: 0.75 }}>+ <Typography sx={{ fontSize: 12, fontWeight: 650, color: 'rgba(244,241,234,0.7)' }}>+ Script log+ </Typography>+ <Box+ ref={listRef}+ sx={{+ height: 140,+ overflow: 'auto',+ border: '1px solid rgba(255,255,255,0.12)',+ borderRadius: 1,+ bgcolor: '#0c0c0c',+ px: 1.25,+ py: 1,+ fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Consolas, monospace',+ fontSize: 11,+ lineHeight: 1.45,+ color: 'rgba(244,241,234,0.72)',+ }}+ >+ {lines.length === 0 ? (+ <Typography sx={{ fontSize: 11, color: 'rgba(244,241,234,0.4)', fontFamily: 'inherit' }}>+ No script logs yet — call <code>log(...)</code> in process().+ </Typography>+ ) : (+ lines.map((line, index) => (+ <Box+ key={`${index}-${line.slice(0, 24)}`}+ component="div"+ sx={{ whiteSpace: 'pre-wrap', wordBreak: 'break-word' }}+ >+ {line}+ </Box>+ ))+ )}+ </Box>+ </Box>+ )+}diff --git a/frontend/src/features/inspector/UserScriptParams.test.tsx b/frontend/src/features/inspector/UserScriptParams.test.tsxindex f82c19d..ede3858 100644--- a/frontend/src/features/inspector/UserScriptParams.test.tsx+++ b/frontend/src/features/inspector/UserScriptParams.test.tsx@@ -22,6 +22,7 @@ function renderUserScript(onVersionChange = vi.fn()) {render(<QueryClientProvider client={client}><UserScriptParams+ nodeId="user-1"nodeType="user_script.script_001"label="Sepia Tone"version={1}diff --git a/frontend/src/features/inspector/UserScriptParams.tsx b/frontend/src/features/inspector/UserScriptParams.tsxindex b045025..2a44e04 100644--- a/frontend/src/features/inspector/UserScriptParams.tsx+++ b/frontend/src/features/inspector/UserScriptParams.tsx@@ -18,8 +18,11 @@ import {import { notifyError } from '../../notify'import { useGraphStore } from '../../store/graphStore'import { scriptIdFromType, userScriptCodeKey } from '../../workflow/customCodeTrust'+import { ScriptLogBox } from './ScriptLogBox'+import { ScriptHelpersButton } from './ScriptHelpersButton'type UserScriptParamsProps = {+ nodeId: stringnodeType: stringlabel: stringversion: number@@ -79,6 +82,7 @@ function EditIcon({ color = ICON_COLOR }: { color?: string }) {}export function UserScriptParams({+ nodeId,nodeType,label,version,@@ -201,27 +205,30 @@ export function UserScriptParams({<Typography sx={{ fontSize: 12, fontWeight: 650, color: 'rgba(244,241,234,0.7)' }}>Code (v{version})</Typography>- <Button- size="small"- variant="outlined"- startIcon={<EditIcon />}- onClick={openEditor}- disabled={!cached || !code}- sx={{- textTransform: 'none',- fontWeight: 650,- fontSize: 12,- color: ICON_COLOR,- borderColor: 'rgba(255,255,255,0.16)',- '& .MuiButton-startIcon': { color: ICON_COLOR },- '&:hover': {- borderColor: 'rgba(125,206,160,0.45)',- bgcolor: 'rgba(125,206,160,0.08)',- },- }}- >- Edit code- </Button>+ <Box sx={{ display: 'flex', gap: 1 }}>+ <ScriptHelpersButton />+ <Button+ size="small"+ variant="outlined"+ startIcon={<EditIcon />}+ onClick={openEditor}+ disabled={!cached || !code}+ sx={{+ textTransform: 'none',+ fontWeight: 650,+ fontSize: 12,+ color: ICON_COLOR,+ borderColor: 'rgba(255,255,255,0.16)',+ '& .MuiButton-startIcon': { color: ICON_COLOR },+ '&:hover': {+ borderColor: 'rgba(125,206,160,0.45)',+ bgcolor: 'rgba(125,206,160,0.08)',+ },+ }}+ >+ Edit code+ </Button>+ </Box></Box><Box@@ -249,6 +256,8 @@ export function UserScriptParams({)}</Box>+ <ScriptLogBox nodeId={nodeId} />+<Dialogopen={editing}onClose={() => {@@ -292,6 +301,7 @@ export function UserScriptParams({>Edit {label} (new version)</Typography>+ <ScriptHelpersButton compact /><Buttonsize="small"disabled={saving}diff --git a/frontend/src/features/inspector/scriptHelpersHint.ts b/frontend/src/features/inspector/scriptHelpersHint.tsnew file mode 100644index 0000000..08f7d5f--- /dev/null+++ b/frontend/src/features/inspector/scriptHelpersHint.ts@@ -0,0 +1,23 @@+/** Catalog of Image Pipes helpers available inside custom / user scripts. */++export type ScriptHelperDoc = {+ signature: string+ summary: string+ detail: string+}++export const SCRIPT_HELPERS: ScriptHelperDoc[] = [+ {+ signature: 'log(*args)',+ summary: 'Write a line to the Script log panel',+ detail:+ 'Arguments are joined with spaces. NumPy arrays render as shape and dtype ' ++ '(e.g. ndarray(shape=(H, W, C), dtype=uint8)). Long strings are truncated.',+ },+]++export const SCRIPT_HELPERS_TAGLINE =+ 'Debug helpers you can call from process(image, seed=0)'++export const SCRIPT_HELPERS_FOOTNOTE =+ 'More helpers will appear here as we expand the script runtime.'diff --git a/frontend/src/hooks/useExecutionSocket.ts b/frontend/src/hooks/useExecutionSocket.tsindex 334284b..2a9424f 100644--- a/frontend/src/hooks/useExecutionSocket.ts+++ b/frontend/src/hooks/useExecutionSocket.ts@@ -33,6 +33,7 @@ export function useExecutionSocket() {const setActiveNodeId = useGraphStore((s) => s.setActiveNodeId)const addPreview = useGraphStore((s) => s.addPreview)const appendLog = useGraphStore((s) => s.appendLog)+ const appendScriptLog = useGraphStore((s) => s.appendScriptLog)const setNodeTiming = useGraphStore((s) => s.setNodeTiming)const toGraphPayload = useGraphStore((s) => s.toGraphPayload)const seed = useGraphStore((s) => s.seed)@@ -111,7 +112,13 @@ export function useExecutionSocket() {})}}- if (event.type === 'log' && event.message) appendLog(event.message)+ if (event.type === 'log' && event.message) {+ if (event.node_id) {+ appendScriptLog(event.node_id, event.message)+ } else {+ appendLog(event.message)+ }+ }if (event.type === 'error') {const detail = event.message ?? 'Execution failed'appendLog(detail)@@ -174,6 +181,7 @@ export function useExecutionSocket() {[addPreview,appendLog,+ appendScriptLog,clearExecution,iterationCount,seed,diff --git a/frontend/src/store/graphStore.ts b/frontend/src/store/graphStore.tsindex 1e1f520..e780b70 100644--- a/frontend/src/store/graphStore.ts+++ b/frontend/src/store/graphStore.ts@@ -65,6 +65,8 @@ interface GraphState {previews: ExecutionPreview[]nodeImages: Record<string, NodeImageState>logs: string[]+ /** Per-node lines from custom/user-script log() helpers (cleared each run). */+ scriptLogsByNodeId: Record<string, string[]>nodeTimings: Record<string, NodeTiming>generatedCode: stringisExecuting: boolean@@ -114,6 +116,7 @@ interface GraphState {addPreview: (preview: ExecutionPreview) => voidclearExecution: () => voidappendLog: (message: string) => void+ appendScriptLog: (nodeId: string, message: string) => voidsetNodeTiming: (nodeId: string, timing: NodeTiming) => voidsetGeneratedCode: (code: string) => voidsetIsExecuting: (value: boolean) => void@@ -198,6 +201,7 @@ export const useGraphStore = create<GraphState>((set, get) => ({previews: [],nodeImages: {},logs: [],+ scriptLogsByNodeId: {},nodeTimings: {},generatedCode: '# Run codegen to export a Python script\n',isExecuting: false,@@ -628,6 +632,7 @@ export const useGraphStore = create<GraphState>((set, get) => ({previews: [],nodeImages: {},logs: [],+ scriptLogsByNodeId: {},nodeTimings: {},activeNodeId: null,nodes: get().nodes.map((node) => ({@@ -637,6 +642,13 @@ export const useGraphStore = create<GraphState>((set, get) => ({}),appendLog: (message) => set({ logs: [...get().logs, message] }),+ appendScriptLog: (nodeId, message) =>+ set({+ scriptLogsByNodeId: {+ ...get().scriptLogsByNodeId,+ [nodeId]: [...(get().scriptLogsByNodeId[nodeId] ?? []), message],+ },+ }),setNodeTiming: (nodeId, timing) =>set({nodeTimings: { ...get().nodeTimings, [nodeId]: timing },@@ -682,6 +694,7 @@ export const useGraphStore = create<GraphState>((set, get) => ({previews: [],nodeImages: {},logs: [],+ scriptLogsByNodeId: {},nodeTimings: {},isExecuting: false,generatedCode: '# Run codegen to export a Python script\n',@@ -856,6 +869,7 @@ export const useGraphStore = create<GraphState>((set, get) => ({previews: [],nodeImages: {},logs: [],+ scriptLogsByNodeId: {},nodeTimings: {},isExecuting: false,generatedCode: '# Run codegen to export a Python script\n',diff --git a/frontend/src/store/scriptLogs.store.test.ts b/frontend/src/store/scriptLogs.store.test.tsnew file mode 100644index 0000000..8fb5f65--- /dev/null+++ b/frontend/src/store/scriptLogs.store.test.ts@@ -0,0 +1,25 @@+import { beforeEach, describe, expect, it } from 'vitest'+import { useGraphStore } from '../store/graphStore'++describe('scriptLogsByNodeId store', () => {+ beforeEach(() => {+ useGraphStore.setState({+ logs: [],+ scriptLogsByNodeId: {},+ })+ })++ it('appends per-node script logs and clears them on clearExecution', () => {+ const store = useGraphStore.getState()+ store.appendScriptLog('a', 'one')+ store.appendScriptLog('a', 'two')+ store.appendScriptLog('b', 'other')+ expect(useGraphStore.getState().scriptLogsByNodeId).toEqual({+ a: ['one', 'two'],+ b: ['other'],+ })++ useGraphStore.getState().clearExecution()+ expect(useGraphStore.getState().scriptLogsByNodeId).toEqual({})+ })+})diff --git a/frontend/src/test/customPythonFixtures.ts b/frontend/src/test/customPythonFixtures.tsindex e6c02fd..f818919 100644--- a/frontend/src/test/customPythonFixtures.ts+++ b/frontend/src/test/customPythonFixtures.ts@@ -3,7 +3,13 @@ import { useGraphStore } from '../store/graphStore'import type { GraphNodeData, NodeMetadata } from '../types'import type { CustomCodeNodeLike } from '../workflow/customCodeTrust'-export const IDENTITY_CODE = 'def process(image, seed=0):\n return image\n'+export const IDENTITY_CODE = `def process(image, seed=0):+ # image: BGR uint8 numpy array (H, W, C)+ # log(...) writes to the Script log panel in the inspector.+ log("running custom script", "seed=", seed)+ log("input image", image)+ return image+`export const customPythonMeta: NodeMetadata = {type: 'custom_python',diff --git a/frontend/src/workflow/templates.customPython.test.ts b/frontend/src/workflow/templates.customPython.test.tsindex e8c7174..16a9d98 100644--- a/frontend/src/workflow/templates.customPython.test.ts+++ b/frontend/src/workflow/templates.customPython.test.ts@@ -26,5 +26,7 @@ describe('Custom Python template', () => {const custom = doc.graph.nodes.find((node) => node.type === 'custom_python')expect(custom?.params?.code).toMatch(/def process\s*\(/)+ expect(custom?.params?.code).toMatch(/log\(/)+ expect(custom?.params?.code).toMatch(/Script log/)})})