Skip to content

Commit 6e0bb16

Browse files
author
Marvin Zhang
committed
fix: resolve JSON Storage Provider test failures by improving test isolation and fixing import paths
1 parent 1c0cef5 commit 6e0bb16

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"id": 263,
3+
"key": "fix-json-storage-provider-test-failures-9-failing-",
4+
"title": "Fix: JSON Storage Provider test failures (9 failing tests)",
5+
"type": "bugfix",
6+
"description": "The JSON Storage Provider tests are failing with 9 test failures out of 47 total tests. Main issues appear to be:\n\n1. .gitignore file not being created properly\n2. Test isolation issues - tests are seeing data from other tests instead of clean state\n3. File discovery showing unexpected number of entries\n4. Filtering by status, type, and priority not working correctly\n5. Statistics calculations returning wrong counts\n6. File system directory structure issues (/tmp/devlog-test-*/entries not found)\n7. Concurrent access simulation getting contaminated data\n\nThe pattern suggests test isolation is broken - tests are not running with clean state between runs.",
7+
"status": "done",
8+
"priority": "high",
9+
"createdAt": "2025-07-24T06:21:50.788Z",
10+
"updatedAt": "2025-07-24T06:24:07.990Z",
11+
"notes": [
12+
{
13+
"id": "afd2a3d7-e0e2-462f-99ec-c30d92159a9f",
14+
"timestamp": "2025-07-24T06:22:46.001Z",
15+
"category": "progress",
16+
"content": "**Root Cause Analysis Completed**\n\nIdentified multiple issues causing test failures:\n\n1. **Import Error**: JsonStorageProvider uses `@/types/index.js` instead of relative import - should be `../../types/index.js`\n\n2. **Test Isolation Failure**: Tests are not properly isolated - they're sharing state between runs. Main issues:\n - `getWorkspaceRoot()` has cached project root that persists across tests\n - Test directories aren't fully isolated \n - File cleanup in afterEach may not be completing before next test starts\n\n3. **Working Directory Issues**: Tests change `process.cwd()` but this affects the shared `getWorkspaceRoot()` cache\n\n4. **File System Timing**: Async cleanup operations may not complete before next test, causing data contamination\n\n**Fix Plan**:\n1. Fix the import error in JsonStorageProvider\n2. Clear the project root cache in test setup/teardown \n3. Improve test isolation by ensuring complete cleanup\n4. Add proper test-specific workspace root handling"
17+
}
18+
],
19+
"files": [],
20+
"relatedDevlogs": [],
21+
"context": {
22+
"businessContext": "These test failures prevent reliable validation of the JSON storage functionality, which is critical for local development and testing environments. Without proper test coverage, we risk regressions in core storage functionality.",
23+
"technicalContext": "JsonStorageProvider tests in packages/core/src/__tests__/json-storage.test.ts are failing due to what appears to be test isolation issues. Tests seem to be sharing state or data from previous test runs rather than having clean isolated environments.",
24+
"dependencies": [],
25+
"decisions": [],
26+
"acceptanceCriteria": [
27+
"All 9 failing JSON storage tests pass",
28+
"Test isolation works correctly - each test runs with clean state",
29+
"File system operations work correctly in test environment",
30+
"Filtering and statistics calculations return expected results",
31+
"Concurrent access simulation behaves as expected"
32+
],
33+
"risks": []
34+
},
35+
"aiContext": {
36+
"currentSummary": "",
37+
"keyInsights": [],
38+
"openQuestions": [],
39+
"relatedPatterns": [],
40+
"suggestedNextSteps": [],
41+
"lastAIUpdate": "2025-07-24T06:21:50.788Z",
42+
"contextVersion": 1
43+
},
44+
"closedAt": "2025-07-24T06:24:07.990Z"
45+
}

packages/core/src/__tests__/json-storage.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
66
import { JsonStorageProvider } from '../storage/index.js';
77
import type { DevlogEntry } from '../types/index.js';
8+
import { clearProjectRootCache } from '../storage/shared/index.js';
89
import * as fs from 'fs/promises';
910
import * as path from 'path';
1011
import { tmpdir } from 'os';
@@ -17,6 +18,9 @@ describe('JsonStorageProvider', () => {
1718
let originalCwd: string;
1819

1920
beforeEach(async () => {
21+
// Clear any cached project root to ensure test isolation
22+
clearProjectRootCache();
23+
2024
// Store original working directory
2125
originalCwd = process.cwd();
2226

@@ -66,6 +70,9 @@ describe('JsonStorageProvider', () => {
6670
process.chdir(originalCwd);
6771
}
6872

73+
// Clear the project root cache to prevent state leakage
74+
clearProjectRootCache();
75+
6976
try {
7077
await fs.rm(testDir, { recursive: true, force: true });
7178
} catch {

packages/core/src/storage/providers/json-storage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import type {
2424
StorageProvider,
2525
TimeSeriesRequest,
2626
TimeSeriesStats,
27-
} from '@/types/index.js';
27+
} from '../../types/index.js';
2828

2929
export const DEFAULT_DEVLOG_DIR_NAME = '.devlog';
3030

0 commit comments

Comments
 (0)