Testing Firestore History Feature
Testing Firestore History Feature
Quick guide to test the query history functionality.
Prerequisites
- GCP Authentication (if not already set):
gcloud auth application-default login - Firestore API (if not already enabled):
gcloud services enable firestore.googleapis.com --project=YOUR_PROJECT_ID - Firestore Database (if not already created):
- Go to Firestore Console
- Create a database (Native mode is fine)
- Choose a location (e.g.,
us-central)
Step 1: Install Backend Dependencies
cd web/backend
pip install -r requirements.txt
This will install google-cloud-firestore and other dependencies.
Step 2: Start Backend Server
cd web/backend
python main.py
✅ Backend should start on http://localhost:8000
You should see:
INFO: Started server process
INFO: Uvicorn running on http://0.0.0.0:8000
Note: If you see a warning about Firestore initialization, that’s okay - it will work once Firestore API is enabled.
Step 3: Start Frontend (New Terminal)
cd web/frontend
npm install # Only needed first time
npm run dev
✅ Frontend should start on http://localhost:3000 (or http://localhost:5173)
Step 4: Test History Features
Test 1: Send a Query
- Open
http://localhost:3000in your browser - Select an agent from the dropdown
- Send a query like: “What are the total costs by top 10 services?”
- Wait for the response
✅ Expected: Query and response should be saved to Firestore automatically
Test 2: View History
- Click the History button (📜 icon) in the header
- You should see a sidebar appear on the right
- Your recent query should appear in the list
✅ Expected: History sidebar shows your query with:
- Agent name
- Query message (truncated)
- Timestamp
Test 3: Load History Item
- In the history sidebar, click on any query item
- The conversation should load in the main chat area
✅ Expected: Main chat shows the full query and response
Test 4: Delete Individual Query
- In the history sidebar, click the trash icon (🗑️) on any query
- Confirm deletion
- The query should disappear from the list
✅ Expected: Query is removed from history
Test 5: Delete All History
- In the history sidebar, click the trash icon (🗑️) in the header
- Confirm deletion
- All queries should be removed
✅ Expected: All history cleared, sidebar shows “No query history yet”
Test 6: Reload History on Startup
- Refresh the browser page
- Click the History button
- Your queries should still be there
✅ Expected: History persists across page reloads
Verify in Firestore Console
- Go to Firestore Console
- Select your project
- Look for collection:
query_history - You should see documents with fields:
user_id: “web_user”agent_name: e.g., “bq_agent_mick”message: The user’s queryresponse: The agent’s responsetimestamp: When the query was made
Troubleshooting
“Firestore client not initialized”
- Enable Firestore API:
gcloud services enable firestore.googleapis.com - Check GCP authentication:
gcloud auth application-default login - Verify project ID in
.envorBQ_PROJECTenvironment variable
“Failed to save query to Firestore”
- Check backend logs for detailed error
- Verify Firestore database exists in your project
- Check IAM permissions for Firestore
History not loading
- Check browser console for errors
- Verify backend is running and accessible
- Check backend logs for API errors
History sidebar not appearing
- Check browser console for JavaScript errors
- Verify frontend dependencies are installed:
npm install - Try hard refresh:
Cmd+Shift+R(Mac) orCtrl+Shift+R(Windows)
API Testing (Optional)
You can also test the API endpoints directly:
# Get history
curl "http://localhost:8000/history?user_id=web_user&limit=10"
# Delete a specific query (replace QUERY_ID)
curl -X DELETE "http://localhost:8000/history/QUERY_ID?user_id=web_user"
# Delete all history
curl -X DELETE "http://localhost:8000/history?user_id=web_user"