-
Notifications
You must be signed in to change notification settings - Fork 0
fix: use project-local .git-mem/logs/ for log directory (GIT-63) #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| import * as os from 'node:os'; | ||
| import * as path from 'node:path'; | ||
| import { execFileSync } from 'node:child_process'; | ||
| import { ILogger, ILoggerOptions, LogLevel } from '../../domain/interfaces/ILogger'; | ||
| import { Logger } from './Logger'; | ||
| import { NullLogger } from './NullLogger'; | ||
|
|
@@ -10,8 +10,20 @@ function isValidLogLevel(value: string): value is LogLevel { | |
| return VALID_LEVELS.includes(value as LogLevel); | ||
| } | ||
|
|
||
| function getGitRoot(): string | null { | ||
| try { | ||
| return execFileSync('git', ['rev-parse', '--show-toplevel'], { | ||
| encoding: 'utf8', | ||
| stdio: ['pipe', 'pipe', 'pipe'], | ||
| }).trim(); | ||
| } catch { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| export function defaultLogDir(): string { | ||
| return path.join(os.homedir(), '.git-mem', 'logs'); | ||
| const base = getGitRoot() ?? process.cwd(); | ||
| return path.join(base, '.git-mem', 'logs'); | ||
| } | ||
|
Comment on lines
24
to
27
|
||
|
|
||
| export function loadLoggerOptions(): ILoggerOptions { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| import { describe, it, before, after } from 'node:test'; | ||
| import assert from 'node:assert/strict'; | ||
| import { join } from 'path'; | ||
| import { execFileSync } from 'child_process'; | ||
| import { createLogger, createNullLogger, defaultLogDir, loadLoggerOptions } from '../../../../src/infrastructure/logging/factory'; | ||
| import { Logger } from '../../../../src/infrastructure/logging/Logger'; | ||
| import { NullLogger } from '../../../../src/infrastructure/logging/NullLogger'; | ||
|
|
@@ -27,6 +29,16 @@ describe('Logging factory', () => { | |
| } | ||
| }); | ||
|
|
||
| describe('defaultLogDir', () => { | ||
| it('should return .git-mem/logs under the git root', () => { | ||
| const gitRoot = execFileSync('git', ['rev-parse', '--show-toplevel'], { | ||
| encoding: 'utf8', | ||
| }).trim(); | ||
|
|
||
| assert.equal(defaultLogDir(), join(gitRoot, '.git-mem', 'logs')); | ||
| }); | ||
|
Comment on lines
+32
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Consider mocking git calls or moving this to integration tests. This unit test executes the real 🤖 Prompt for AI Agents |
||
| }); | ||
|
|
||
| describe('loadLoggerOptions', () => { | ||
| it('should return defaults when no env vars set', () => { | ||
| delete process.env['LOG_LEVEL']; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: TonyCasey/git-mem
Length of output: 1217
🏁 Script executed:
Repository: TonyCasey/git-mem
Length of output: 132
🏁 Script executed:
Repository: TonyCasey/git-mem
Length of output: 43814
Add timeout to prevent CLI startup hangs if git stalls.
Since
getGitRoot()runs during logger initialization, an unresponsivegitcommand would block CLI startup indefinitely. Add a 2-second timeout and optimize stdio to avoid unnecessary stream management.🔧 Suggested fix
function getGitRoot(): string | null { try { return execFileSync('git', ['rev-parse', '--show-toplevel'], { encoding: 'utf8', - stdio: ['pipe', 'pipe', 'pipe'], + stdio: ['ignore', 'pipe', 'ignore'], + timeout: 2000, }).trim(); } catch { return null; } }📝 Committable suggestion
🤖 Prompt for AI Agents