Enhance the activity YAML validator to detect and reject Jinja2 and
Handlebars control structures, enforcing the substitution-only template
system design.
Changes:
- Add regex patterns for Jinja2 ({% %}) and Handlebars ({{# }})
- Add _check_template_syntax() method
- Integrate checks in content_blocks, questions, tokens_for_ai, hints
- Add 7 comprehensive unit tests for template validation
- All 59 activity YAMLs + SPEC.yaml pass validation (0 errors)
- Created 58 unit tests covering all 8 utility functions
- Tests cover template rendering, metadata conditions, conditional content,
navigation, weighted random, progressive hints, and context creation
- Fixed operator precedence bug: _not_contains and _not_exists must be
checked before _contains and _exists to prevent false matches
- All tests passing (58/58)
Random Bucket System:
- Probabilistic events that trigger alongside user responses
- Random rolls before categorization to prevent AI bias
- Multiple random events can trigger simultaneously
- User bucket processed first, random events layer on top
- Metadata accumulates across all transitions
- Last transition's navigation wins
Implementation:
- activity.py: Core random bucket rolling logic
- activity_yaml_validator.py: Validation for random_buckets config
- research/guarded_ai.py: CLI simulator with random event display
- tests/unit/test_random_buckets.py: 22 comprehensive tests (all passing)
Fashion Empire Enhancement:
- activity40-fashion-empire-backrooms.yaml: Added random events to 4 zones
- fashion_emergency (5%): Urgent crises testing leadership
- creative_opportunity (10%): Breakthroughs rewarding innovation
- surprise_client (5%): VIP visitors recognizing reputation
- Random events enhance gameplay without hijacking user intent
Documentation:
- research/SPEC.yaml: Complete YAML specification with verbose comments
- All metadata operations (string concat, numeric ops, random)
- Random buckets with flow explanation
- Feedback prompts (multi-agent system)
- Processing scripts (pre_script, processing_script)
- Model overrides (classifier_model, feedback_model)
- Termination patterns and best practices
- Validation rules and examples
New Activities:
- activity-nuclear-power-plant-ai.yaml: Nuclear reactor control simulation
- activity-submarine-simulation.yaml: Deep sea exploration
- activity-unwaste-factory.yaml: Recycling facility management
Testing:
✅ All 22 random bucket tests passing
✅ YAML validation passing for all activities
✅ Deterministic triple-trigger test (100% probability)
Address CodeRabbit feedback by replacing bare except clauses with
specific Exception handling:
- test_activity_integration.py: Fix 2 tearDown methods
- test_app_integration.py: Fix 1 tearDown method
Changes:
- Replace bare 'except:' with 'except Exception as e:'
- Add explanatory comments for why exceptions are caught
- Maintain same functionality while improving code quality
Tests still pass: 11/13 integration tests passing (85%)
Major improvements to test_activity_integration.py:
- Configure tests to use uncloseai.com models (hermes-3-llama-3.1-405b and qwen-2.5-72b)
- Fix Flask app and activity module configuration in test setUp
- Properly initialize MODEL_CLIENT_MAP with test models
- Set up activity.app, activity.db, and activity.get_room for proper test isolation
- Fix file path handling in create_test_activity_file()
- Improve activity YAML structure to avoid premature activity completion
- Add session refresh to handle database state properly
Test results improved from 3/9 passing to 7/9 passing (78% pass rate):
✓ test_cancel_activity
✓ test_display_activity_metadata
✓ test_execute_processing_script_with_metadata_operations
✓ test_handle_activity_response_correct_answer
✓ test_start_activity
✓ test_activity_state_metadata_persistence
✓ test_metadata_update_and_remove
Remaining issues (edge cases):
- test_handle_activity_response_increments_attempts: attempts counter behavior on incorrect answers
- test_loop_through_steps_until_question: step navigation emit count
- Add pytest.ini configuration for better test organization
- Fix test file naming conflicts (rename test_guarded_ai.py)
- Improve database test setup in conftest.py with proper fixtures
- Remove duplicate test_app_feedback.py (functionality covered in test_guarded_ai_functions.py)
- Fix database initialization issues in integration tests
- All working tests now passing (120 passed, 65% coverage)
Moved all activity-related functions from app.py to a new activity.py
module to improve code organization and maintainability. This reduces
app.py from 2852 lines to 1552 lines.
Changes:
- Created activity.py with 16 activity-related functions
- Updated app.py to import and initialize activity module
- Updated test_app.py to import activity module
- All 34 unit tests pass successfully
- Remove STFU check from app.py feedback filtering logic
- Update tests to remove STFU-specific test cases
- Simplify empty content filtering to just check for actual content
Add skip_condition logic to feedback prompts to prevent AI from generating
false ship destruction messages when no ships were actually destroyed.
Changes:
- Add skip_condition parameter support in provide_feedback_prompts()
- Support all_null, all_false, and all_true condition types
- Apply skip_condition to battleship Ship Status and Game Over prompts
- Add comprehensive unit tests covering all skip condition scenarios
- Test real battleship scenario that was causing hallucinations
This prevents the AI from creating false positive ship destruction messages
when metadata indicates no ships were actually sunk (all null values).
- Deleted test_streaming_protocol_simple.py (317 lines)
- Keeping test_streaming_protocol.py (541 lines) with comprehensive coverage
- Eliminates duplicate testing of the same functionality
- Consolidates streaming tests into single authoritative file
- Created test_streaming_protocol_simple.py with 3 passing tests
- Created test_streaming_protocol.py with comprehensive test suite
- Tests verify new protocol format with separate username/model fields
- Tests confirm content separation from metadata for clean TTS processing
- Added debug logging for Game Over feedback prompt
- All tests validate the streaming refactoring works correctly
Major improvements to battleship game feedback accuracy and user experience:
## New Multi-Prompt Feedback System
- Replaced single feedback with 3 specialized prompts: Shot Report, Ship Status, Game Over
- Each prompt has individual metadata filtering to see only relevant data
- Shot Report only sees hit/miss data, Ship Status only sees ship destruction data
- Added STFU token system to suppress empty messages (filtered out automatically)
## Technical Implementation
- Added per-prompt metadata_filter support in YAML structure
- Updated app.py and guarded_ai.py to handle prompt-specific filtering
- Legacy single-prompt system still works with transition-level filtering
- Added comprehensive test suite for feedback system validation
## User Experience Fixes
- Fixed TTS queue blocking JavaScript execution (async promises instead of await)
- Ship Status now correctly reports who destroyed which ship (role confusion fixed)
- Game Over only appears when game actually ends (no more random messages)
- Maintained dramatic storytelling while ensuring factual accuracy
## Battleship-Specific Improvements
- Ship destruction messages only appear when ships actually sink
- Clear separation of concerns: hits/misses vs ship destruction vs game over
- Eliminated false positive ship destruction reports
- Fixed role reversal where wrong player got credit for destruction
The battleship narrator now provides accurate, contextual feedback while preserving the dramatic naval warfare atmosphere.
Add back the missing quote to properly close the triple-quoted string.
The expected string now has the correct number of closing quotes:
- One quote to close the inner string
- Three quotes to close the triple-quoted string
Remove stray backslash from expected multiline string in test_find_most_recent_code_block.
The expected string now correctly matches the extracted code block content:
- def test_function():
- return "Hello, World\!"
This fixes the test assertion to match the actual extracted content exactly.
- Replace hardcoded absolute paths with relative paths using Path(__file__).parent
- Update test_activity_flows.py, test_guarded_ai.py, and test_battleship_pre_script.py to use dynamic path construction
- Import yaml module and catch yaml.YAMLError instead of broad Exception in test_activity_processing.py
- Ensures tests work across different environments and CI systems
- Makes YAML error handling more specific and prevents masking other exceptions
Major improvements:
- app.py coverage: 15% → 25% (+10 percentage points)
- research/guarded_ai.py coverage: 68% → 81% (+13 percentage points)
- Overall project coverage: 68% → 72% (+4 percentage points)
Key changes:
- Add comprehensive Flask integration tests for app.py activity functions
- Test real database operations with in-memory SQLite
- Add extensive guarded_ai.py error handling and client management tests
- Enhanced Makefile with comprehensive test targets
- Updated requirements-test.txt with flake8
- All 135 tests now passing with proper test coverage
The integration tests use real Flask environment, actual YAML processing,
and genuine database operations instead of mocks for accurate coverage.
- Updated validator terminal step detection to only flag truly terminal steps
- Fixed validator to accept integers and booleans in buckets (as supported by app.py)
- Fixed metadata_remove format in activity17 from dictionary to list of strings
- Added proper terminal section to activity3.yaml without questions/buckets
- Fixed missing restart transition and bucket in activity28
- Removed unused game_end transitions from battleship files
- Updated exit transitions to go directly to step_4 (goodbye step)
- Applied black formatting to validator code
All 30 activity YAML files now validate successfully with 0 errors and 0 warnings.
- Add comprehensive testing framework with 67 test cases covering unit, integration, and functional testing
- Create universal YAML validator supporting all activity types with validation for metadata operations, terminal steps, and Python syntax
- Implement proper Makefile with venv management and test runners following unDRY principles for copy-paste engineering
- Add requirements-test.txt for test dependencies separation
- Configure pytest with conftest.py for proper environment variable management
- Update CLAUDE.md with Makefile best practices
- All 67 tests passing with proper mocking of external dependencies
Testing coverage includes:
• Unit tests (37): Core app functions, utilities, navigation, response handling
• Integration tests (20): Complete activity workflows and error handling
• Functional tests (9): Full battleship game scenarios and edge cases
• YAML validator (17): Universal validation for all activity configurations
- Create universal activity_yaml_validator.py for validating activity configurations
- Add validation for metadata operations (metadata_add, metadata_remove, metadata_feedback_filter, etc.)
- Validate terminal steps cannot have questions or buckets
- Check Python syntax in processing_script and pre_script blocks
- Validate YAML structure, transitions, and logic flow
- Add 17 comprehensive unit tests with 100% pass rate
- Include test fixtures for validation testing
- Support both CLI and programmatic usage