mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Move non-tool logic out of tool file.
This commit is contained in:
1 parent
945c4209e8
commit
23c3cead89
10 files changed
+345
-250
No files matched your search
@@ -3,7 +3,7 @@ import { renderHook, act, waitFor } from '@testing-library/react';
|
||||
import { ReactNode } from 'react';
|
||||
import { ConsoleErrorProvider } from './ConsoleErrorProvider';
|
||||
import { useConsoleError } from '@/hooks/useConsoleError';
|
||||
import { addConsoleMessage, clearConsoleMessages, ProjectPreviewConsoleError } from '@/lib/tools/ReadConsoleMessagesTool';
|
||||
import { addConsoleMessage, clearConsoleMessages, ProjectPreviewConsoleError } from '@/lib/consoleMessages';
|
||||
|
||||
// Wrapper component for testing
|
||||
function TestWrapper({ children }: { children: ReactNode }) {
|
||||
@@ -23,7 +23,7 @@ describe('ConsoleErrorProvider', () => {
|
||||
const { result } = renderHook(() => useConsoleError(), {
|
||||
wrapper: TestWrapper,
|
||||
});
|
||||
|
||||
|
||||
expect(result.current.hasErrors).toBe(false);
|
||||
expect(result.current.consoleError).toBeNull();
|
||||
});
|
||||
@@ -32,14 +32,14 @@ describe('ConsoleErrorProvider', () => {
|
||||
const { result } = renderHook(() => useConsoleError(), {
|
||||
wrapper: TestWrapper,
|
||||
});
|
||||
|
||||
|
||||
expect(result.current.hasErrors).toBe(false);
|
||||
|
||||
|
||||
// Add an error message
|
||||
act(() => {
|
||||
addConsoleMessage('error', 'Test error message');
|
||||
});
|
||||
|
||||
|
||||
expect(result.current.hasErrors).toBe(true);
|
||||
expect(result.current.consoleError).toBeInstanceOf(ProjectPreviewConsoleError);
|
||||
expect(result.current.consoleError?.message).toBe('Console error detected: Test error message');
|
||||
@@ -49,14 +49,14 @@ describe('ConsoleErrorProvider', () => {
|
||||
const { result } = renderHook(() => useConsoleError(), {
|
||||
wrapper: TestWrapper,
|
||||
});
|
||||
|
||||
|
||||
// Add non-error messages
|
||||
act(() => {
|
||||
addConsoleMessage('log', 'Test log message');
|
||||
addConsoleMessage('warn', 'Test warning message');
|
||||
addConsoleMessage('info', 'Test info message');
|
||||
});
|
||||
|
||||
|
||||
expect(result.current.hasErrors).toBe(false);
|
||||
expect(result.current.consoleError).toBeNull();
|
||||
});
|
||||
@@ -65,24 +65,24 @@ describe('ConsoleErrorProvider', () => {
|
||||
const { result } = renderHook(() => useConsoleError(), {
|
||||
wrapper: TestWrapper,
|
||||
});
|
||||
|
||||
|
||||
// Add first error
|
||||
act(() => {
|
||||
addConsoleMessage('error', 'First error');
|
||||
});
|
||||
|
||||
|
||||
expect(result.current.consoleError?.message).toBe('Console error detected: First error');
|
||||
|
||||
|
||||
// Add second error - should update to show latest error
|
||||
act(() => {
|
||||
addConsoleMessage('error', 'Second error');
|
||||
});
|
||||
|
||||
|
||||
// Wait for polling to detect the new error
|
||||
await waitFor(() => {
|
||||
expect(result.current.consoleError?.message).toBe('Console error detected: Second error');
|
||||
});
|
||||
|
||||
|
||||
expect(result.current.consoleError?.logs).toHaveLength(2);
|
||||
});
|
||||
|
||||
@@ -90,20 +90,20 @@ describe('ConsoleErrorProvider', () => {
|
||||
const { result } = renderHook(() => useConsoleError(), {
|
||||
wrapper: TestWrapper,
|
||||
});
|
||||
|
||||
|
||||
// Add error to set state
|
||||
act(() => {
|
||||
addConsoleMessage('error', 'Test error message');
|
||||
});
|
||||
|
||||
|
||||
expect(result.current.hasErrors).toBe(true);
|
||||
expect(result.current.consoleError).not.toBeNull();
|
||||
|
||||
|
||||
// Clear errors
|
||||
act(() => {
|
||||
result.current.clearErrors();
|
||||
});
|
||||
|
||||
|
||||
expect(result.current.hasErrors).toBe(false);
|
||||
expect(result.current.consoleError).toBeNull();
|
||||
});
|
||||
@@ -112,19 +112,19 @@ describe('ConsoleErrorProvider', () => {
|
||||
const { result } = renderHook(() => useConsoleError(), {
|
||||
wrapper: TestWrapper,
|
||||
});
|
||||
|
||||
|
||||
// Add error to create console error
|
||||
act(() => {
|
||||
addConsoleMessage('error', 'Test error message');
|
||||
});
|
||||
|
||||
|
||||
expect(result.current.consoleError).not.toBeNull();
|
||||
|
||||
|
||||
// Dismiss console error (this only clears the Quilly error, not the global state)
|
||||
act(() => {
|
||||
result.current.dismissConsoleError();
|
||||
});
|
||||
|
||||
|
||||
expect(result.current.consoleError).toBeNull();
|
||||
// hasErrors should still be true since we only dismissed the Quilly display
|
||||
expect(result.current.hasErrors).toBe(true);
|
||||
@@ -134,7 +134,7 @@ describe('ConsoleErrorProvider', () => {
|
||||
const { result } = renderHook(() => useConsoleError(), {
|
||||
wrapper: TestWrapper,
|
||||
});
|
||||
|
||||
|
||||
// Add multiple errors and non-errors
|
||||
act(() => {
|
||||
addConsoleMessage('log', 'Log message');
|
||||
@@ -144,16 +144,16 @@ describe('ConsoleErrorProvider', () => {
|
||||
addConsoleMessage('info', 'Info message');
|
||||
addConsoleMessage('error', 'Third error');
|
||||
});
|
||||
|
||||
|
||||
// Wait for polling to detect all the new errors
|
||||
await waitFor(() => {
|
||||
expect(result.current.consoleError?.message).toBe('Console error detected: Third error');
|
||||
});
|
||||
|
||||
|
||||
expect(result.current.consoleError?.logs).toHaveLength(3);
|
||||
expect(result.current.consoleError?.logs.map(log => log.message)).toEqual([
|
||||
'First error',
|
||||
'Second error',
|
||||
'Second error',
|
||||
'Third error'
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { useState, useEffect, useRef, useCallback, ReactNode } from 'react';
|
||||
import {
|
||||
addErrorStateListener,
|
||||
import {
|
||||
addErrorStateListener,
|
||||
removeErrorStateListener,
|
||||
getHasConsoleErrors,
|
||||
getConsoleMessages,
|
||||
clearConsoleMessages,
|
||||
ProjectPreviewConsoleError
|
||||
} from '@/lib/tools/ReadConsoleMessagesTool';
|
||||
} from '@/lib/consoleMessages';
|
||||
import { ConsoleErrorContext } from '@/contexts/ConsoleErrorContext';
|
||||
|
||||
interface ConsoleErrorProviderProps {
|
||||
@@ -22,7 +22,7 @@ export function ConsoleErrorProvider({ children }: ConsoleErrorProviderProps) {
|
||||
const updateConsoleError = useCallback(() => {
|
||||
const messages = getConsoleMessages();
|
||||
const errorMessages = messages.filter(msg => msg.level === 'error');
|
||||
|
||||
|
||||
if (errorMessages.length > 0) {
|
||||
const error = new ProjectPreviewConsoleError(
|
||||
`Console error detected: ${errorMessages[errorMessages.length - 1].message}`,
|
||||
@@ -40,7 +40,7 @@ export function ConsoleErrorProvider({ children }: ConsoleErrorProviderProps) {
|
||||
useEffect(() => {
|
||||
const handleErrorStateChange = (hasErrors: boolean) => {
|
||||
setHasErrors(hasErrors);
|
||||
|
||||
|
||||
if (hasErrors) {
|
||||
// Always update when we get an error state change
|
||||
updateConsoleError();
|
||||
@@ -55,7 +55,7 @@ export function ConsoleErrorProvider({ children }: ConsoleErrorProviderProps) {
|
||||
const checkForNewErrors = () => {
|
||||
const messages = getConsoleMessages();
|
||||
const errorMessages = messages.filter(msg => msg.level === 'error');
|
||||
|
||||
|
||||
if (errorMessages.length > lastErrorCountRef.current) {
|
||||
// New errors detected - update the console error
|
||||
updateConsoleError();
|
||||
@@ -64,11 +64,11 @@ export function ConsoleErrorProvider({ children }: ConsoleErrorProviderProps) {
|
||||
|
||||
// Listen for error state changes
|
||||
addErrorStateListener(handleErrorStateChange);
|
||||
|
||||
|
||||
// Initial sync
|
||||
setHasErrors(getHasConsoleErrors());
|
||||
updateConsoleError();
|
||||
|
||||
|
||||
// Poll for new errors (handles multiple errors being added)
|
||||
const interval = setInterval(checkForNewErrors, 100);
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import { useAISettings } from '@/hooks/useAISettings';
|
||||
import { parseProviderModel } from '@/lib/parseProviderModel';
|
||||
import { useAICredits } from '@/hooks/useAICredits';
|
||||
import { CreditsDialog } from './CreditsDialog';
|
||||
import { ProjectPreviewConsoleError } from '@/lib/tools/ReadConsoleMessagesTool';
|
||||
import { ProjectPreviewConsoleError } from '@/lib/consoleMessages';
|
||||
import { useState } from 'react';
|
||||
|
||||
export interface QuillyProps {
|
||||
|
||||
@@ -34,7 +34,8 @@ import { NostrReadNipsIndexTool } from '@/lib/tools/NostrReadNipsIndexTool';
|
||||
import { NostrGenerateKindTool } from '@/lib/tools/NostrGenerateKindTool';
|
||||
import { ShellTool } from '@/lib/tools/ShellTool';
|
||||
import { TypecheckTool } from '@/lib/tools/TypecheckTool';
|
||||
import { ReadConsoleMessagesTool, ProjectPreviewConsoleError } from '@/lib/tools/ReadConsoleMessagesTool';
|
||||
import { ReadConsoleMessagesTool } from '@/lib/tools/ReadConsoleMessagesTool';
|
||||
import { ProjectPreviewConsoleError } from '@/lib/consoleMessages';
|
||||
import { toolToOpenAI } from '@/lib/tools/openai-adapter';
|
||||
import { Tool } from '@/lib/tools/Tool';
|
||||
import OpenAI from 'openai';
|
||||
|
||||
@@ -3,7 +3,7 @@ import { useState, useEffect, useCallback, useRef } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useProjectsManager } from '@/hooks/useProjectsManager';
|
||||
import { useFS } from '@/hooks/useFS';
|
||||
import { addConsoleMessage, getConsoleMessages, type ConsoleMessage } from '@/lib/tools/ReadConsoleMessagesTool';
|
||||
import { addConsoleMessage, getConsoleMessages, type ConsoleMessage } from '@/lib/consoleMessages';
|
||||
import { useConsoleError } from '@/hooks/useConsoleError';
|
||||
import { useBuildProject } from '@/hooks/useBuildProject';
|
||||
import { Tabs, TabsContent } from '@/components/ui/tabs';
|
||||
|
||||
Reference in new issue
Block a user