test: setup unit and integration testing (Fixes #305)#377
Conversation
|
@Ixotic27 is attempting to deploy a commit to the aditthyass' projects Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Introduces app-wide providers/hooks for lazy-loading agent registry data and centralizing API key management, and adds a Vitest test setup.
Changes:
- Added
AgentsProvider/useAgentsto lazy-load agent definitions viaimport.meta.globand provide them through context. - Added
ApiKeyProvider/useApiKeyto centralize provider selection and per-provider API keys with optional session persistence. - Added Vitest + Testing Library setup and initial unit tests for
useApiKeyandllmAdapter.
Reviewed changes
Copilot reviewed 22 out of 23 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| vite.config.js | Configures Vitest (jsdom, globals, setup file). |
| src/setupTests.js | Adds jest-dom matchers for RTL assertions. |
| src/pages/WorkflowRunner.jsx | Switches agent source to useAgents and relies on context-driven API key bar. |
| src/pages/WorkflowLibrary.jsx | Uses useAgents inside AgentPill to resolve agent display info. |
| src/pages/WorkflowDetail.jsx | Uses useAgents and passes agent list into AgentRow. |
| src/pages/WorkflowBuilder.jsx | Uses useAgents instead of eager registry import. |
| src/pages/HomePage.jsx | Uses useAgents and recalculates derived lists with correct memo deps. |
| src/pages/BattleModeSetup.jsx | Switches agent source to useAgents and API key state to useApiKey. |
| src/pages/BattleModeArena.jsx | Reads API keys from global context instead of router state. |
| src/pages/AgentPage.jsx | Uses useAgents and adds loading UI while agents load. |
| src/main.jsx | Wraps app with AgentsProvider and ApiKeyProvider. |
| src/lib/useApiKey.test.jsx | Adds unit tests for new API key context/hook. |
| src/lib/useApiKey.jsx | New API key context/provider with sessionStorage sync. |
| src/lib/useApiKey.js | Removes previous single-provider hook implementation. |
| src/lib/useAgents.jsx | New agents context/provider loading agents via registry loader. |
| src/lib/llmAdapter.test.js | Adds unit tests for runAgent and fetchGeminiModels. |
| src/components/SuggestedChainPills.jsx | Uses useAgents for resolving suggested chain metadata. |
| src/components/Sidebar.jsx | Uses useAgents for sidebar agent list/filtering. |
| src/components/ApiKeyBar.jsx | Refactors to read/update API key state from useApiKey internally. |
| src/components/AgentRunner.jsx | Uses context-derived API key/provider and context-driven API key bar. |
| src/agents/registry.js | Makes agent registry lazy-loaded and adds loadAllAgents() caching. |
| package.json | Adds Vitest + Testing Library deps and npm test script. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const AgentsContext = createContext({ | ||
| agents: [], | ||
| loading: true, | ||
| }) |
| export function useAgents() { | ||
| return useContext(AgentsContext) | ||
| } |
| .catch((err) => { | ||
| console.error('Failed to load agents:', err) | ||
| setLoading(false) | ||
| }) |
| const [selectedAgentId, setSelectedAgentId] = useState('') | ||
| const [inputs, setInputs] = useState({}) | ||
| const [apiKeys, setApiKeys] = useState({ openai: '', anthropic: '', gemini: '' }) | ||
| const { apiKeys, setApiKeys, saveForSession, setSaveForSession } = useApiKey() |
| const handleKeyChange = (providerId, value) => { | ||
| setApiKeys((prev) => ({ ...prev, [providerId]: value })) | ||
| } |
| it('saves to sessionStorage when saveForSession is true', () => { | ||
| const { result } = renderHook(() => useApiKey(), { wrapper }) | ||
|
|
||
| act(() => { | ||
| result.current.setSaveForSession(true) | ||
| }) | ||
|
|
||
| act(() => { | ||
| result.current.setApiKeyForProvider('openai', 'sk-session') | ||
| }) | ||
|
|
||
| const savedKeys = JSON.parse(sessionStorage.getItem('ila_apikeys') || '{}') | ||
| expect(savedKeys.openai).toBe('sk-session') | ||
| expect(sessionStorage.getItem('ila_save_session')).toBe('true') | ||
| }) |
| const mockFetch = vi.fn() | ||
| global.fetch = mockFetch |
| const STORAGE_KEYS_PREFIX = 'ila_apikeys' | ||
| const STORAGE_PROVIDER_PREFIX = 'ila_active_provider' | ||
| const STORAGE_SAVE_PREFIX = 'ila_save_session' |
|
I have implemented the Copilot suggestions on PR #377:
|
ac53ccc to
f2f7156
Compare
|
Hey @Ixotic27! 👋
|
|
hi @AditthyaSS please check this pr |
|
|
f2f7156 to
ac2950b
Compare
|
hey @Ixotic27! 👋 |
|
hey @Ixotic27! 👋 |
|
|
There was a problem hiding this comment.
❌ Build is failing on this PR.
Please fix before merging:
- Run
npm run buildlocally - Fix any errors shown
- Push your fix — the check will re-run automatically
Most common issue: broken registry import.
Replace:
import agents from '../agents/registry'
With:
import { useAgents } from '../lib/useAgents'
const { agents } = useAgents()
See CONTRIBUTING.md for help. 🙏
|
|
Fixes #305.
Description
Configured the application for robust unit testing to ensure scalability and reliability.
Baseline Tests Provided
Testing and Proof
Tests ran locally successfully with all 7 unit assertions passing gracefully.