Browse Source

Merge pull request #516 from omar-mohamed-khallaf/master

Correct log directory path to include /log subdirectory
Alvin 2 months ago
parent
commit
bae7776431
4 changed files with 13 additions and 38 deletions
  1. 1 1
      AGENTS.md
  2. 10 35
      src/cli/cache.test.ts
  3. 1 1
      src/utils/logger.test.ts
  4. 1 1
      src/utils/logger.ts

+ 1 - 1
AGENTS.md

@@ -268,7 +268,7 @@ Windows: Press WIN+R and paste %USERPROFILE%\.local\share\opencode\log
 Log files are named with timestamps (e.g., 2025-01-09T123456.log) and the most recent 10 log files are kept.
 You can set the log level with the --log-level command-line option to get more detailed debug information. For example, opencode --log-level DEBUG.
 ### Plugin
-~/.local/share/opencode/oh-my-opencode-slim.<timestamp>.log
+~/.local/share/opencode/log/oh-my-opencode-slim.<timestamp>.log
 
 ## Cloned Dependency Source
 

+ 10 - 35
src/cli/cache.test.ts

@@ -18,6 +18,7 @@ import {
 } from 'node:fs';
 import { tmpdir } from 'node:os';
 import { join } from 'node:path';
+import * as pathsMod from './paths';
 
 type SpawnResult = {
   exited: Promise<number>;
@@ -41,25 +42,9 @@ mock.module('../utils/compat', () => ({
 }));
 
 const nonexistentPath = '/nonexistent/opencode.json';
-mock.module('./paths', () => ({
-  getConfigDir: () => '/nonexistent',
-  getConfigSearchDirs: () => ['/nonexistent'],
-  getOpenCodeConfigPaths: () => [],
-  getConfigJson: () => nonexistentPath,
-  getConfigJsonc: () => nonexistentPath,
-  getLiteConfig: () => nonexistentPath,
-  getLiteConfigJsonc: () => nonexistentPath,
-  getTuiConfig: () => nonexistentPath,
-  getTuiConfigJsonc: () => nonexistentPath,
-  getExistingLiteConfigPath: () => nonexistentPath,
-  getExistingTuiConfigPath: () => nonexistentPath,
-  getExistingConfigPath: () => nonexistentPath,
-  ensureConfigDir: () => {},
-  ensureTuiConfigDir: () => {},
-  ensureOpenCodeConfigDir: () => {},
-}));
 
 let importCounter = 0;
+let getExistingConfigPathSpy: ReturnType<typeof spyOn>;
 
 function createSpawnResult(exitCode = 0): SpawnResult {
   return {
@@ -89,6 +74,10 @@ describe('warmOpenCodePluginCache', () => {
       },
     );
     delete process.env.XDG_CACHE_HOME;
+    getExistingConfigPathSpy = spyOn(
+      pathsMod,
+      'getExistingConfigPath',
+    ).mockReturnValue(nonexistentPath);
   });
 
   afterEach(() => {
@@ -98,6 +87,7 @@ describe('warmOpenCodePluginCache', () => {
     } else {
       process.env.XDG_CACHE_HOME = originalXdgCacheHome;
     }
+    getExistingConfigPathSpy.mockRestore();
   });
 
   test('prewarms the OpenCode cache for bunx installs', async () => {
@@ -375,11 +365,7 @@ describe('warmOpenCodePluginCache', () => {
     );
 
     // Override getExistingConfigPath to return our test config
-    const pathsMod = await import('./paths');
-    const configPathSpy = spyOn(
-      pathsMod,
-      'getExistingConfigPath',
-    ).mockReturnValue(configPath);
+    getExistingConfigPathSpy.mockReturnValue(configPath);
 
     try {
       const packageRoot = join(
@@ -419,7 +405,6 @@ describe('warmOpenCodePluginCache', () => {
         },
       });
     } finally {
-      configPathSpy.mockRestore();
       rmSync(tmpDir, { recursive: true, force: true });
     }
   });
@@ -485,11 +470,7 @@ describe('warmOpenCodePluginCache', () => {
       }),
     );
 
-    const pathsMod = await import('./paths');
-    const configPathSpy = spyOn(
-      pathsMod,
-      'getExistingConfigPath',
-    ).mockReturnValue(configPath);
+    getExistingConfigPathSpy.mockReturnValue(configPath);
 
     try {
       const packageRoot = join(
@@ -529,7 +510,6 @@ describe('warmOpenCodePluginCache', () => {
         },
       });
     } finally {
-      configPathSpy.mockRestore();
       rmSync(tmpDir, { recursive: true, force: true });
     }
   });
@@ -564,11 +544,7 @@ describe('warmOpenCodePluginCache', () => {
       }),
     );
 
-    const pathsMod = await import('./paths');
-    const configPathSpy = spyOn(
-      pathsMod,
-      'getExistingConfigPath',
-    ).mockReturnValue(configPath);
+    getExistingConfigPathSpy.mockReturnValue(configPath);
 
     try {
       const { warmOpenCodePluginCache } = await importFreshConfigIo();
@@ -595,7 +571,6 @@ describe('warmOpenCodePluginCache', () => {
         },
       });
     } finally {
-      configPathSpy.mockRestore();
       rmSync(tmpDir, { recursive: true, force: true });
     }
   });

+ 1 - 1
src/utils/logger.test.ts

@@ -187,7 +187,7 @@ describe('logger', () => {
     delete process.env.OPENCODE_LOG_DIR;
     try {
       expect(getLogDir()).toBe(
-        path.join(os.homedir(), '.local/share/opencode'),
+        path.join(os.homedir(), '.local/share/opencode/log'),
       );
     } finally {
       if (origLogDir === undefined) {

+ 1 - 1
src/utils/logger.ts

@@ -13,7 +13,7 @@ let writeChain: Promise<void> = Promise.resolve();
 function getLogDir(): string {
   return (
     process.env.OPENCODE_LOG_DIR ??
-    path.join(os.homedir(), '.local/share/opencode')
+    path.join(os.homedir(), '.local/share/opencode/log')
   );
 }