mirror of
https://github.com/langchain-ai/langsmith-self-hosted-workshops.git
synced 2026-07-01 20:44:14 -04:00
b0b424eabd
This commit adds comprehensive test coverage for Module 3 (Production
Operations & Scaling) and Module 4 (Troubleshooting & Incident Response)
notebooks, following the same pattern established for Modules 1 and 2.
Test Infrastructure:
- tests/test_notebook_execution.py:
- Added TestModule3Notebooks class with syntax and execution tests
for 01_ops_sanity_checks.ipynb
- Added TestModule4Notebooks class with:
- Syntax tests for all 6 Module 4 notebooks (00, 01, 10, 20, 30, 40)
- Execution tests for setup/baseline notebooks (00, 01) - read-only
- Execution tests for failure labs (10, 20, 30, 40) - with warnings
about failure injection and secret modification
CI/CD Integration:
- .github/workflows/test-notebooks.yml:
- Added Module 3 and Module 4 syntax tests to CI pipeline
- All syntax tests now run automatically on PRs and pushes
Test Features:
- Respects CI_SKIP_EXECUTION environment variable (same as Module 1)
- Uses environment variables for configuration (cloud provider, region, etc.)
- Appropriate timeouts: 600s for ops checks, 900s for failure labs
- Safety warnings for failure lab execution tests
- Syntax tests always run (including in CI)
- Execution tests skip in CI when CI_SKIP_EXECUTION=true
Module 4 Test Structure:
- Syntax tests: All 6 notebooks validated for structure
- Setup/Baseline execution: Read-only validation notebooks (00, 01)
- Failure lab execution: Separate test method with warnings about
secret modification and failure injection (10, 20, 30, 40)
This ensures all workshop notebooks are validated for syntax correctness
and can be execution-tested when infrastructure is available, maintaining
consistency with existing test patterns.
Tests for LangSmith Self-Hosted Workshops
This directory contains tests for validating notebook execution and syntax.
Test Structure
conftest.py: Pytest configuration and fixturestest_notebook_execution.py: Notebook execution testsrequirements.txt: Test dependenciesartifacts/: Directory for test artifacts (created automatically)
Running Tests Locally
Prerequisites
# Install test dependencies
pip install -r tests/requirements.txt
# Install system dependencies (if needed)
# macOS: brew install jq
# Ubuntu: sudo apt-get install jq
Run All Tests
# Run syntax tests only (fast, no infrastructure required)
CI_SKIP_EXECUTION=true pytest tests/ -v
# Run full execution tests (requires infrastructure)
pytest tests/ -v
Run Specific Test Suites
# Test Module 1 notebooks
pytest tests/test_notebook_execution.py::TestModule1Notebooks -v
# Test Module 2 notebooks
pytest tests/test_notebook_execution.py::TestModule2Notebooks -v
Run Individual Notebook Tests
# Test specific notebook syntax
pytest tests/test_notebook_execution.py::TestModule1Notebooks::test_module1_notebook_syntax -v
CI/CD Integration
Tests run automatically on:
- Pull requests to
main/master - Pushes to
main/master - Manual workflow dispatch
GitHub Actions Workflow
The .github/workflows/test-notebooks.yml workflow:
- Test Notebook Syntax: Validates JSON structure and code cells
- Test Module 1 Preflight: Validates preflight notebook structure
- Test Module 2 Syntax: Validates auth validation notebooks
- Lint Python Code: Runs flake8 and black checks
Environment Variables
The workflow uses test environment variables. For full execution tests, set:
# In GitHub Actions secrets/variables
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
AWS_REGION
CLUSTER_NAME
NAMESPACE
# ... etc
Test Strategy
Syntax Tests (Always Run)
- Validate notebook JSON structure
- Check for code cells
- Verify imports can be resolved
- No infrastructure required
Execution Tests (Conditional)
- Full notebook execution
- Requires actual infrastructure (cluster, IdP, etc.)
- Skipped in CI by default (
CI_SKIP_EXECUTION=true) - Can be enabled for integration testing environments
Adding New Tests
- Add notebook to appropriate test class in
test_notebook_execution.py - Update
pytest.parametrizedecorator with notebook name - Add any required environment variables to
conftest.py - Update GitHub Actions workflow if needed
Troubleshooting
Import Errors
If tests fail with import errors:
- Ensure
notebooks/shared/is in Python path - Check that
conftest.pyis setting up paths correctly - Verify all required packages are in
requirements.txt
Timeout Errors
If notebook execution times out:
- Increase timeout in
execute_notebook()function - Check for infinite loops or long-running operations
- Consider mocking external API calls
Environment Variable Issues
If tests fail due to missing env vars:
- Check
conftest.pyfor default values - Verify GitHub Actions workflow sets required variables
- Add variables to test fixtures if needed