feat: add CI/CD workflows, persistent chat, shell completions, and testing
- Add Gitea CI workflow for testing, linting, and building
- Add release workflow for multi-platform builds and GitHub releases
- Implement persistent chat history with JSON storage
- Add shell completion generation for bash, zsh, fish, powershell
- Introduce custom error types and logging system
- Add interfaces for git and AI client for better testability
- Enhance config with temperature and timeout settings
- Add comprehensive unit tests for config, errors, git, grok, and logger
- Update README with installation, features, and development instructions
- Make model flag persistent across commands
- Add context timeouts to API requests
2026-03-01 12:17:22 +00:00
|
|
|
package logger
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"os"
|
|
|
|
|
"path/filepath"
|
2026-03-01 12:35:21 +00:00
|
|
|
"strings"
|
feat: add CI/CD workflows, persistent chat, shell completions, and testing
- Add Gitea CI workflow for testing, linting, and building
- Add release workflow for multi-platform builds and GitHub releases
- Implement persistent chat history with JSON storage
- Add shell completion generation for bash, zsh, fish, powershell
- Introduce custom error types and logging system
- Add interfaces for git and AI client for better testability
- Enhance config with temperature and timeout settings
- Add comprehensive unit tests for config, errors, git, grok, and logger
- Update README with installation, features, and development instructions
- Make model flag persistent across commands
- Add context timeouts to API requests
2026-03-01 12:17:22 +00:00
|
|
|
"testing"
|
|
|
|
|
)
|
|
|
|
|
|
2026-03-02 21:33:11 +00:00
|
|
|
func setHome(t *testing.T, dir string) {
|
|
|
|
|
t.Helper()
|
|
|
|
|
if err := os.Setenv("HOME", dir); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
feat: add CI/CD workflows, persistent chat, shell completions, and testing
- Add Gitea CI workflow for testing, linting, and building
- Add release workflow for multi-platform builds and GitHub releases
- Implement persistent chat history with JSON storage
- Add shell completion generation for bash, zsh, fish, powershell
- Introduce custom error types and logging system
- Add interfaces for git and AI client for better testability
- Enhance config with temperature and timeout settings
- Add comprehensive unit tests for config, errors, git, grok, and logger
- Update README with installation, features, and development instructions
- Make model flag persistent across commands
- Add context timeouts to API requests
2026-03-01 12:17:22 +00:00
|
|
|
func TestInit(t *testing.T) {
|
|
|
|
|
tmpDir := t.TempDir()
|
|
|
|
|
oldHome := os.Getenv("HOME")
|
2026-03-02 21:33:11 +00:00
|
|
|
setHome(t, tmpDir)
|
|
|
|
|
defer func() { _ = os.Setenv("HOME", oldHome) }()
|
feat: add CI/CD workflows, persistent chat, shell completions, and testing
- Add Gitea CI workflow for testing, linting, and building
- Add release workflow for multi-platform builds and GitHub releases
- Implement persistent chat history with JSON storage
- Add shell completion generation for bash, zsh, fish, powershell
- Introduce custom error types and logging system
- Add interfaces for git and AI client for better testability
- Enhance config with temperature and timeout settings
- Add comprehensive unit tests for config, errors, git, grok, and logger
- Update README with installation, features, and development instructions
- Make model flag persistent across commands
- Add context timeouts to API requests
2026-03-01 12:17:22 +00:00
|
|
|
|
2026-03-01 12:35:21 +00:00
|
|
|
tests := []struct {
|
|
|
|
|
name string
|
|
|
|
|
logLevel string
|
|
|
|
|
}{
|
|
|
|
|
{"default level", "info"},
|
|
|
|
|
{"debug level", "debug"},
|
|
|
|
|
{"warn level", "warn"},
|
|
|
|
|
{"error level", "error"},
|
|
|
|
|
{"invalid level defaults to info", "invalid"},
|
feat: add CI/CD workflows, persistent chat, shell completions, and testing
- Add Gitea CI workflow for testing, linting, and building
- Add release workflow for multi-platform builds and GitHub releases
- Implement persistent chat history with JSON storage
- Add shell completion generation for bash, zsh, fish, powershell
- Introduce custom error types and logging system
- Add interfaces for git and AI client for better testability
- Enhance config with temperature and timeout settings
- Add comprehensive unit tests for config, errors, git, grok, and logger
- Update README with installation, features, and development instructions
- Make model flag persistent across commands
- Add context timeouts to API requests
2026-03-01 12:17:22 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-01 12:35:21 +00:00
|
|
|
for _, tt := range tests {
|
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
|
err := Init(tt.logLevel)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Errorf("Init(%q) unexpected error: %v", tt.logLevel, err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logFile := filepath.Join(tmpDir, ".config", "grokkit", "grokkit.log")
|
|
|
|
|
if _, err := os.Stat(logFile); os.IsNotExist(err) {
|
|
|
|
|
t.Errorf("Log file not created at %s", logFile)
|
|
|
|
|
}
|
|
|
|
|
})
|
feat: add CI/CD workflows, persistent chat, shell completions, and testing
- Add Gitea CI workflow for testing, linting, and building
- Add release workflow for multi-platform builds and GitHub releases
- Implement persistent chat history with JSON storage
- Add shell completion generation for bash, zsh, fish, powershell
- Introduce custom error types and logging system
- Add interfaces for git and AI client for better testability
- Enhance config with temperature and timeout settings
- Add comprehensive unit tests for config, errors, git, grok, and logger
- Update README with installation, features, and development instructions
- Make model flag persistent across commands
- Add context timeouts to API requests
2026-03-01 12:17:22 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestLogging(t *testing.T) {
|
|
|
|
|
tmpDir := t.TempDir()
|
|
|
|
|
oldHome := os.Getenv("HOME")
|
2026-03-02 21:33:11 +00:00
|
|
|
setHome(t, tmpDir)
|
|
|
|
|
defer func() { _ = os.Setenv("HOME", oldHome) }()
|
feat: add CI/CD workflows, persistent chat, shell completions, and testing
- Add Gitea CI workflow for testing, linting, and building
- Add release workflow for multi-platform builds and GitHub releases
- Implement persistent chat history with JSON storage
- Add shell completion generation for bash, zsh, fish, powershell
- Introduce custom error types and logging system
- Add interfaces for git and AI client for better testability
- Enhance config with temperature and timeout settings
- Add comprehensive unit tests for config, errors, git, grok, and logger
- Update README with installation, features, and development instructions
- Make model flag persistent across commands
- Add context timeouts to API requests
2026-03-01 12:17:22 +00:00
|
|
|
|
2026-03-01 12:35:21 +00:00
|
|
|
if err := Init("debug"); err != nil {
|
feat: add CI/CD workflows, persistent chat, shell completions, and testing
- Add Gitea CI workflow for testing, linting, and building
- Add release workflow for multi-platform builds and GitHub releases
- Implement persistent chat history with JSON storage
- Add shell completion generation for bash, zsh, fish, powershell
- Introduce custom error types and logging system
- Add interfaces for git and AI client for better testability
- Enhance config with temperature and timeout settings
- Add comprehensive unit tests for config, errors, git, grok, and logger
- Update README with installation, features, and development instructions
- Make model flag persistent across commands
- Add context timeouts to API requests
2026-03-01 12:17:22 +00:00
|
|
|
t.Fatalf("Init() failed: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-01 12:35:21 +00:00
|
|
|
Debug("test debug message", "key", "value")
|
|
|
|
|
Info("test info message", "count", 42)
|
|
|
|
|
Warn("test warn message", "enabled", true)
|
|
|
|
|
Error("test error message", "error", "something went wrong")
|
feat: add CI/CD workflows, persistent chat, shell completions, and testing
- Add Gitea CI workflow for testing, linting, and building
- Add release workflow for multi-platform builds and GitHub releases
- Implement persistent chat history with JSON storage
- Add shell completion generation for bash, zsh, fish, powershell
- Introduce custom error types and logging system
- Add interfaces for git and AI client for better testability
- Enhance config with temperature and timeout settings
- Add comprehensive unit tests for config, errors, git, grok, and logger
- Update README with installation, features, and development instructions
- Make model flag persistent across commands
- Add context timeouts to API requests
2026-03-01 12:17:22 +00:00
|
|
|
|
|
|
|
|
logFile := filepath.Join(tmpDir, ".config", "grokkit", "grokkit.log")
|
|
|
|
|
content, err := os.ReadFile(logFile)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Errorf("Failed to read log file: %v", err)
|
|
|
|
|
}
|
|
|
|
|
if len(content) == 0 {
|
|
|
|
|
t.Errorf("Log file is empty")
|
|
|
|
|
}
|
2026-03-01 12:35:21 +00:00
|
|
|
|
|
|
|
|
contentStr := string(content)
|
|
|
|
|
if !strings.Contains(contentStr, `"level"`) {
|
|
|
|
|
t.Errorf("Log content doesn't contain JSON level field")
|
|
|
|
|
}
|
|
|
|
|
if !strings.Contains(contentStr, `"msg"`) {
|
|
|
|
|
t.Errorf("Log content doesn't contain JSON msg field")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestSetLevel(t *testing.T) {
|
|
|
|
|
tmpDir := t.TempDir()
|
|
|
|
|
oldHome := os.Getenv("HOME")
|
2026-03-02 21:33:11 +00:00
|
|
|
setHome(t, tmpDir)
|
|
|
|
|
defer func() { _ = os.Setenv("HOME", oldHome) }()
|
2026-03-01 12:35:21 +00:00
|
|
|
|
|
|
|
|
if err := Init("info"); err != nil {
|
|
|
|
|
t.Fatalf("Init() failed: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SetLevel("debug")
|
|
|
|
|
Debug("debug after level change", "test", true)
|
|
|
|
|
|
|
|
|
|
logFile := filepath.Join(tmpDir, ".config", "grokkit", "grokkit.log")
|
|
|
|
|
content, err := os.ReadFile(logFile)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Errorf("Failed to read log file: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !strings.Contains(string(content), "debug after level change") {
|
|
|
|
|
t.Errorf("Debug message not found after level change")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestWith(t *testing.T) {
|
|
|
|
|
tmpDir := t.TempDir()
|
|
|
|
|
oldHome := os.Getenv("HOME")
|
2026-03-02 21:33:11 +00:00
|
|
|
setHome(t, tmpDir)
|
|
|
|
|
defer func() { _ = os.Setenv("HOME", oldHome) }()
|
2026-03-01 12:35:21 +00:00
|
|
|
|
|
|
|
|
if err := Init("info"); err != nil {
|
|
|
|
|
t.Fatalf("Init() failed: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
contextLogger := With("request_id", "123", "user", "testuser")
|
|
|
|
|
if contextLogger == nil {
|
|
|
|
|
t.Errorf("With() returned nil logger")
|
|
|
|
|
}
|
feat: add CI/CD workflows, persistent chat, shell completions, and testing
- Add Gitea CI workflow for testing, linting, and building
- Add release workflow for multi-platform builds and GitHub releases
- Implement persistent chat history with JSON storage
- Add shell completion generation for bash, zsh, fish, powershell
- Introduce custom error types and logging system
- Add interfaces for git and AI client for better testability
- Enhance config with temperature and timeout settings
- Add comprehensive unit tests for config, errors, git, grok, and logger
- Update README with installation, features, and development instructions
- Make model flag persistent across commands
- Add context timeouts to API requests
2026-03-01 12:17:22 +00:00
|
|
|
}
|