fix(context): Improve context building, caching and test robustness
This commit is contained in:
		@@ -41,7 +41,7 @@ tap.test('ContextCache.init should create cache directory', async () => {
 | 
			
		||||
 | 
			
		||||
  // Check that cache directory was created
 | 
			
		||||
  const exists = await fs.promises.access(testCacheDir).then(() => true).catch(() => false);
 | 
			
		||||
  expect(exists).toBe(true);
 | 
			
		||||
  expect(exists).toEqual(true);
 | 
			
		||||
 | 
			
		||||
  await cleanupTestCache();
 | 
			
		||||
});
 | 
			
		||||
@@ -56,11 +56,15 @@ tap.test('ContextCache.set should store cache entry', async () => {
 | 
			
		||||
  await cache.init();
 | 
			
		||||
 | 
			
		||||
  const testPath = path.join(testProjectRoot, 'package.json');
 | 
			
		||||
  // Get actual file mtime for validation to work
 | 
			
		||||
  const stats = await fs.promises.stat(testPath);
 | 
			
		||||
  const fileMtime = Math.floor(stats.mtimeMs);
 | 
			
		||||
 | 
			
		||||
  const entry: ICacheEntry = {
 | 
			
		||||
    path: testPath,
 | 
			
		||||
    contents: 'test content',
 | 
			
		||||
    tokenCount: 100,
 | 
			
		||||
    mtime: Date.now(),
 | 
			
		||||
    mtime: fileMtime,
 | 
			
		||||
    cachedAt: Date.now()
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
@@ -171,10 +175,10 @@ tap.test('ContextCache.has should check if file is cached and valid', async () =
 | 
			
		||||
  await cache.set(entry);
 | 
			
		||||
 | 
			
		||||
  const hasIt = await cache.has(testPath);
 | 
			
		||||
  expect(hasIt).toBe(true);
 | 
			
		||||
  expect(hasIt).toEqual(true);
 | 
			
		||||
 | 
			
		||||
  const doesNotHaveIt = await cache.has('/non/existent/path.ts');
 | 
			
		||||
  expect(doesNotHaveIt).toBe(false);
 | 
			
		||||
  expect(doesNotHaveIt).toEqual(false);
 | 
			
		||||
 | 
			
		||||
  await cleanupTestCache();
 | 
			
		||||
});
 | 
			
		||||
@@ -384,11 +388,16 @@ tap.test('ContextCache should persist to disk and reload', async () => {
 | 
			
		||||
  });
 | 
			
		||||
  await cache1.init();
 | 
			
		||||
 | 
			
		||||
  // Use a real file that exists so validation passes
 | 
			
		||||
  const testPath = path.join(testProjectRoot, 'package.json');
 | 
			
		||||
  const stats = await fs.promises.stat(testPath);
 | 
			
		||||
  const fileMtime = Math.floor(stats.mtimeMs);
 | 
			
		||||
 | 
			
		||||
  const entry: ICacheEntry = {
 | 
			
		||||
    path: '/test/persistent-file.ts',
 | 
			
		||||
    path: testPath,
 | 
			
		||||
    contents: 'persistent content',
 | 
			
		||||
    tokenCount: 150,
 | 
			
		||||
    mtime: Date.now(),
 | 
			
		||||
    mtime: fileMtime,
 | 
			
		||||
    cachedAt: Date.now()
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
@@ -404,8 +413,8 @@ tap.test('ContextCache should persist to disk and reload', async () => {
 | 
			
		||||
  });
 | 
			
		||||
  await cache2.init();
 | 
			
		||||
 | 
			
		||||
  const stats = cache2.getStats();
 | 
			
		||||
  expect(stats.entries).toBeGreaterThan(0);
 | 
			
		||||
  const cacheStats = cache2.getStats();
 | 
			
		||||
  expect(cacheStats.entries).toBeGreaterThan(0);
 | 
			
		||||
 | 
			
		||||
  await cleanupTestCache();
 | 
			
		||||
});
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user