meld
Version:
Meld: A template language for LLM prompts
103 lines (82 loc) • 3.77 kB
Markdown
# State ID Handling Issue Investigation
## Issue Description
The test `should handle execution directives correctly` in `api/api.test.ts` is failing with the error "Failed to get state snapshot: Failed to retrieve state data for ID: test.meld". This occurs because the test is incorrectly using the file path as a fallback for the state ID when the state ID should be a UUID.
## Related Code
### Code Files
- `api/api.test.ts`: Contains the failing test
- `services/StateService/StateService.ts`: Core state management implementation
- `services/StateDebuggerService/StateDebuggerService.ts`: Debug service implementation
- `tests/utils/TestContext.ts`: Test setup and utilities
### Test Files
```typescript
// api/api.test.ts
it('should handle execution directives correctly', async () => {
// ... debug session setup ...
// Problematic line:
const initialStateId = context.services.state.getStateId() || context.services.state.getCurrentFilePath() || 'unknown';
// ... rest of test ...
});
```
## Evidence
### Test Expectations
1. The test should be able to:
- Create a new state with a file path "test.meld"
- Enable transformation mode
- Process a run directive
- Track and visualize the state changes
### Current Behavior
1. The test fails when trying to get a state snapshot
2. The error indicates it's trying to use "test.meld" as a state ID
3. This fails because the state tracking service expects UUIDs, not file paths
### Code Analysis
#### Test Structure
1. Test setup in TestContext:
```typescript
const state = new StateService();
state.setCurrentFilePath('test.meld'); // Set initial file path
state.enableTransformation(true);
state.setTrackingService(tracking);
state.setEventService(eventService);
```
2. State initialization in StateService:
```typescript
constructor(parentState?: IStateService) {
this.stateFactory = new StateFactory();
this.currentState = this.stateFactory.createState({
source: 'new',
parentState: parentState ? (parentState as StateService).currentState : undefined
});
// Initialize state ID first
this.currentState.stateId = crypto.randomUUID();
// ... service setup and state registration ...
}
```
#### Related Tests
- Other tests in `api/api.test.ts` that deal with state management
- State tracking tests in `services/StateService/StateService.test.ts`
### Debug Output
```
Failed to get state snapshot: Failed to retrieve state data for ID: test.meld
```
#### Visualization
The state visualization fails because it cannot find a state with ID "test.meld" in the tracking service.
#### Instrumentation Analysis
1. The StateService correctly generates a UUID for the state ID
2. The test incorrectly falls back to using the file path when it should use the UUID
3. The tracking service cannot find the state because it's looking for a file path instead of the UUID
## Attempted Solutions
No solutions attempted yet, but the fix should involve:
1. Removing the file path fallback in the test
2. Using the proper state ID from getStateId()
3. Adding validation to prevent using non-UUID state IDs
## Additional Notes
1. The state ID and file path serve different purposes:
- State ID: Unique identifier for tracking state changes (UUID)
- File Path: Location of the file being processed (string)
2. The test's fallback mechanism conflates these two concepts
## Next Steps
1. Modify the test to use only getStateId() without fallbacks
2. Add validation in the tracking service to ensure state IDs are valid UUIDs
3. Update documentation to clarify the distinction between state IDs and file paths
4. Add tests specifically for state ID validation
5. Consider adding a debug message when getStateId() returns undefined to help diagnose similar issues