* feat(mcp): add workspace root validation to prevent path traversal - Add workspaceRoot field to Service for restricting file operations - Add WithWorkspaceRoot() option for configuring the workspace directory - Add validatePath() helper to check paths are within workspace - Apply validation to all file operation handlers - Default to current working directory for security - Add comprehensive tests for path validation Closes #82 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: move CLI commands from pkg/ to internal/cmd/ - Move 18 CLI command packages to internal/cmd/ (not externally importable) - Keep 16 library packages in pkg/ (externally importable) - Update all import paths throughout codebase - Cleaner separation between CLI logic and reusable libraries CLI commands moved: ai, ci, dev, docs, doctor, gitcmd, go, monitor, php, pkgcmd, qa, sdk, security, setup, test, updater, vm, workspace Libraries remaining: agentic, build, cache, cli, container, devops, errors, framework, git, i18n, io, log, mcp, process, release, repos Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor(mcp): use pkg/io Medium for sandboxed file operations Replace manual path validation with pkg/io.Medium for all file operations. This delegates security (path traversal, symlink bypass) to the sandboxed local.Medium implementation. Changes: - Add io.NewSandboxed() for creating sandboxed Medium instances - Refactor MCP Service to use io.Medium instead of direct os.* calls - Remove validatePath and resolvePathWithSymlinks functions - Update tests to verify Medium-based behaviour Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: correct import path and workflow references - Fix pkg/io/io.go import from core-gui to core - Update CI workflows to use internal/cmd/updater path Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(security): address CodeRabbit review issues for path validation - pkg/io/local: add symlink resolution and boundary-aware containment - Reject absolute paths in sandboxed Medium - Use filepath.EvalSymlinks to prevent symlink bypass attacks - Fix prefix check to prevent /tmp/root matching /tmp/root2 - pkg/mcp: fix resolvePath to validate and return errors - Changed resolvePath from (string) to (string, error) - Update deleteFile, renameFile, listDirectory, fileExists to handle errors - Changed New() to return (*Service, error) instead of *Service - Properly propagate option errors instead of silently discarding - pkg/io: wrap errors with E() helper for consistent context - Copy() and MockMedium.Read() now use coreerr.E() - tests: rename to use _Good/_Bad/_Ugly suffixes per coding guidelines - Fix hardcoded /tmp in TestPath to use t.TempDir() - Add TestResolvePath_Bad_SymlinkTraversal test Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * style: fix gofmt formatting Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * style: fix gofmt formatting across all files Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
660 lines
17 KiB
Go
660 lines
17 KiB
Go
package php
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestIsLaravelProject_Good(t *testing.T) {
|
|
t.Run("valid Laravel project with artisan and composer.json", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
|
|
// Create artisan file
|
|
artisanPath := filepath.Join(dir, "artisan")
|
|
err := os.WriteFile(artisanPath, []byte("#!/usr/bin/env php\n"), 0755)
|
|
require.NoError(t, err)
|
|
|
|
// Create composer.json with laravel/framework
|
|
composerJSON := `{
|
|
"name": "test/laravel-project",
|
|
"require": {
|
|
"php": "^8.2",
|
|
"laravel/framework": "^11.0"
|
|
}
|
|
}`
|
|
composerPath := filepath.Join(dir, "composer.json")
|
|
err = os.WriteFile(composerPath, []byte(composerJSON), 0644)
|
|
require.NoError(t, err)
|
|
|
|
assert.True(t, IsLaravelProject(dir))
|
|
})
|
|
|
|
t.Run("Laravel in require-dev", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
|
|
// Create artisan file
|
|
artisanPath := filepath.Join(dir, "artisan")
|
|
err := os.WriteFile(artisanPath, []byte("#!/usr/bin/env php\n"), 0755)
|
|
require.NoError(t, err)
|
|
|
|
// Create composer.json with laravel/framework in require-dev
|
|
composerJSON := `{
|
|
"name": "test/laravel-project",
|
|
"require-dev": {
|
|
"laravel/framework": "^11.0"
|
|
}
|
|
}`
|
|
composerPath := filepath.Join(dir, "composer.json")
|
|
err = os.WriteFile(composerPath, []byte(composerJSON), 0644)
|
|
require.NoError(t, err)
|
|
|
|
assert.True(t, IsLaravelProject(dir))
|
|
})
|
|
}
|
|
|
|
func TestIsLaravelProject_Bad(t *testing.T) {
|
|
t.Run("missing artisan file", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
|
|
// Create composer.json but no artisan
|
|
composerJSON := `{
|
|
"name": "test/laravel-project",
|
|
"require": {
|
|
"laravel/framework": "^11.0"
|
|
}
|
|
}`
|
|
composerPath := filepath.Join(dir, "composer.json")
|
|
err := os.WriteFile(composerPath, []byte(composerJSON), 0644)
|
|
require.NoError(t, err)
|
|
|
|
assert.False(t, IsLaravelProject(dir))
|
|
})
|
|
|
|
t.Run("missing composer.json", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
|
|
// Create artisan but no composer.json
|
|
artisanPath := filepath.Join(dir, "artisan")
|
|
err := os.WriteFile(artisanPath, []byte("#!/usr/bin/env php\n"), 0755)
|
|
require.NoError(t, err)
|
|
|
|
assert.False(t, IsLaravelProject(dir))
|
|
})
|
|
|
|
t.Run("composer.json without Laravel", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
|
|
// Create artisan file
|
|
artisanPath := filepath.Join(dir, "artisan")
|
|
err := os.WriteFile(artisanPath, []byte("#!/usr/bin/env php\n"), 0755)
|
|
require.NoError(t, err)
|
|
|
|
// Create composer.json without laravel/framework
|
|
composerJSON := `{
|
|
"name": "test/symfony-project",
|
|
"require": {
|
|
"symfony/framework-bundle": "^7.0"
|
|
}
|
|
}`
|
|
composerPath := filepath.Join(dir, "composer.json")
|
|
err = os.WriteFile(composerPath, []byte(composerJSON), 0644)
|
|
require.NoError(t, err)
|
|
|
|
assert.False(t, IsLaravelProject(dir))
|
|
})
|
|
|
|
t.Run("invalid composer.json", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
|
|
// Create artisan file
|
|
artisanPath := filepath.Join(dir, "artisan")
|
|
err := os.WriteFile(artisanPath, []byte("#!/usr/bin/env php\n"), 0755)
|
|
require.NoError(t, err)
|
|
|
|
// Create invalid composer.json
|
|
composerPath := filepath.Join(dir, "composer.json")
|
|
err = os.WriteFile(composerPath, []byte("not valid json{"), 0644)
|
|
require.NoError(t, err)
|
|
|
|
assert.False(t, IsLaravelProject(dir))
|
|
})
|
|
|
|
t.Run("empty directory", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
assert.False(t, IsLaravelProject(dir))
|
|
})
|
|
|
|
t.Run("non-existent directory", func(t *testing.T) {
|
|
assert.False(t, IsLaravelProject("/non/existent/path"))
|
|
})
|
|
}
|
|
|
|
func TestIsFrankenPHPProject_Good(t *testing.T) {
|
|
t.Run("project with octane and frankenphp config", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
|
|
// Create composer.json with laravel/octane
|
|
composerJSON := `{
|
|
"require": {
|
|
"laravel/octane": "^2.0"
|
|
}
|
|
}`
|
|
err := os.WriteFile(filepath.Join(dir, "composer.json"), []byte(composerJSON), 0644)
|
|
require.NoError(t, err)
|
|
|
|
// Create config directory and octane.php
|
|
configDir := filepath.Join(dir, "config")
|
|
err = os.MkdirAll(configDir, 0755)
|
|
require.NoError(t, err)
|
|
|
|
octaneConfig := `<?php
|
|
return [
|
|
'server' => 'frankenphp',
|
|
];`
|
|
err = os.WriteFile(filepath.Join(configDir, "octane.php"), []byte(octaneConfig), 0644)
|
|
require.NoError(t, err)
|
|
|
|
assert.True(t, IsFrankenPHPProject(dir))
|
|
})
|
|
|
|
t.Run("project with octane but no config file", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
|
|
// Create composer.json with laravel/octane
|
|
composerJSON := `{
|
|
"require": {
|
|
"laravel/octane": "^2.0"
|
|
}
|
|
}`
|
|
err := os.WriteFile(filepath.Join(dir, "composer.json"), []byte(composerJSON), 0644)
|
|
require.NoError(t, err)
|
|
|
|
// No config file - should still return true (assume frankenphp)
|
|
assert.True(t, IsFrankenPHPProject(dir))
|
|
})
|
|
|
|
t.Run("project with octane but unreadable config file", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
|
|
// Create composer.json with laravel/octane
|
|
composerJSON := `{
|
|
"require": {
|
|
"laravel/octane": "^2.0"
|
|
}
|
|
}`
|
|
err := os.WriteFile(filepath.Join(dir, "composer.json"), []byte(composerJSON), 0644)
|
|
require.NoError(t, err)
|
|
|
|
// Create config directory and octane.php with no read permissions
|
|
configDir := filepath.Join(dir, "config")
|
|
err = os.MkdirAll(configDir, 0755)
|
|
require.NoError(t, err)
|
|
|
|
octanePath := filepath.Join(configDir, "octane.php")
|
|
err = os.WriteFile(octanePath, []byte("<?php return [];"), 0000)
|
|
require.NoError(t, err)
|
|
defer os.Chmod(octanePath, 0644) // Clean up
|
|
|
|
// Should return true (assume frankenphp if unreadable)
|
|
assert.True(t, IsFrankenPHPProject(dir))
|
|
})
|
|
}
|
|
|
|
func TestIsFrankenPHPProject_Bad(t *testing.T) {
|
|
t.Run("project without octane", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
|
|
composerJSON := `{
|
|
"require": {
|
|
"laravel/framework": "^11.0"
|
|
}
|
|
}`
|
|
err := os.WriteFile(filepath.Join(dir, "composer.json"), []byte(composerJSON), 0644)
|
|
require.NoError(t, err)
|
|
|
|
assert.False(t, IsFrankenPHPProject(dir))
|
|
})
|
|
|
|
t.Run("missing composer.json", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
assert.False(t, IsFrankenPHPProject(dir))
|
|
})
|
|
}
|
|
|
|
func TestDetectServices_Good(t *testing.T) {
|
|
t.Run("full Laravel project with all services", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
|
|
// Setup Laravel project
|
|
err := os.WriteFile(filepath.Join(dir, "artisan"), []byte("#!/usr/bin/env php\n"), 0755)
|
|
require.NoError(t, err)
|
|
|
|
composerJSON := `{
|
|
"require": {
|
|
"laravel/framework": "^11.0",
|
|
"laravel/octane": "^2.0"
|
|
}
|
|
}`
|
|
err = os.WriteFile(filepath.Join(dir, "composer.json"), []byte(composerJSON), 0644)
|
|
require.NoError(t, err)
|
|
|
|
// Add vite.config.js
|
|
err = os.WriteFile(filepath.Join(dir, "vite.config.js"), []byte("export default {}"), 0644)
|
|
require.NoError(t, err)
|
|
|
|
// Add config directory
|
|
configDir := filepath.Join(dir, "config")
|
|
err = os.MkdirAll(configDir, 0755)
|
|
require.NoError(t, err)
|
|
|
|
// Add horizon.php
|
|
err = os.WriteFile(filepath.Join(configDir, "horizon.php"), []byte("<?php return [];"), 0644)
|
|
require.NoError(t, err)
|
|
|
|
// Add reverb.php
|
|
err = os.WriteFile(filepath.Join(configDir, "reverb.php"), []byte("<?php return [];"), 0644)
|
|
require.NoError(t, err)
|
|
|
|
// Add .env with Redis
|
|
envContent := `APP_NAME=TestApp
|
|
CACHE_DRIVER=redis
|
|
REDIS_HOST=127.0.0.1`
|
|
err = os.WriteFile(filepath.Join(dir, ".env"), []byte(envContent), 0644)
|
|
require.NoError(t, err)
|
|
|
|
services := DetectServices(dir)
|
|
|
|
assert.Contains(t, services, ServiceFrankenPHP)
|
|
assert.Contains(t, services, ServiceVite)
|
|
assert.Contains(t, services, ServiceHorizon)
|
|
assert.Contains(t, services, ServiceReverb)
|
|
assert.Contains(t, services, ServiceRedis)
|
|
})
|
|
|
|
t.Run("minimal Laravel project", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
|
|
// Setup minimal Laravel project
|
|
err := os.WriteFile(filepath.Join(dir, "artisan"), []byte("#!/usr/bin/env php\n"), 0755)
|
|
require.NoError(t, err)
|
|
|
|
composerJSON := `{
|
|
"require": {
|
|
"laravel/framework": "^11.0"
|
|
}
|
|
}`
|
|
err = os.WriteFile(filepath.Join(dir, "composer.json"), []byte(composerJSON), 0644)
|
|
require.NoError(t, err)
|
|
|
|
services := DetectServices(dir)
|
|
|
|
assert.Contains(t, services, ServiceFrankenPHP)
|
|
assert.NotContains(t, services, ServiceVite)
|
|
assert.NotContains(t, services, ServiceHorizon)
|
|
assert.NotContains(t, services, ServiceReverb)
|
|
assert.NotContains(t, services, ServiceRedis)
|
|
})
|
|
}
|
|
|
|
func TestHasHorizon_Good(t *testing.T) {
|
|
t.Run("horizon config exists", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
configDir := filepath.Join(dir, "config")
|
|
err := os.MkdirAll(configDir, 0755)
|
|
require.NoError(t, err)
|
|
|
|
err = os.WriteFile(filepath.Join(configDir, "horizon.php"), []byte("<?php return [];"), 0644)
|
|
require.NoError(t, err)
|
|
|
|
assert.True(t, hasHorizon(dir))
|
|
})
|
|
}
|
|
|
|
func TestHasHorizon_Bad(t *testing.T) {
|
|
t.Run("horizon config missing", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
assert.False(t, hasHorizon(dir))
|
|
})
|
|
}
|
|
|
|
func TestHasReverb_Good(t *testing.T) {
|
|
t.Run("reverb config exists", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
configDir := filepath.Join(dir, "config")
|
|
err := os.MkdirAll(configDir, 0755)
|
|
require.NoError(t, err)
|
|
|
|
err = os.WriteFile(filepath.Join(configDir, "reverb.php"), []byte("<?php return [];"), 0644)
|
|
require.NoError(t, err)
|
|
|
|
assert.True(t, hasReverb(dir))
|
|
})
|
|
}
|
|
|
|
func TestHasReverb_Bad(t *testing.T) {
|
|
t.Run("reverb config missing", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
assert.False(t, hasReverb(dir))
|
|
})
|
|
}
|
|
|
|
func TestDetectServices_Bad(t *testing.T) {
|
|
t.Run("non-Laravel project", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
|
|
services := DetectServices(dir)
|
|
assert.Empty(t, services)
|
|
})
|
|
}
|
|
|
|
func TestDetectPackageManager_Good(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
lockFile string
|
|
expected string
|
|
}{
|
|
{"bun detected", "bun.lockb", "bun"},
|
|
{"pnpm detected", "pnpm-lock.yaml", "pnpm"},
|
|
{"yarn detected", "yarn.lock", "yarn"},
|
|
{"npm detected", "package-lock.json", "npm"},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
|
|
err := os.WriteFile(filepath.Join(dir, tt.lockFile), []byte(""), 0644)
|
|
require.NoError(t, err)
|
|
|
|
result := DetectPackageManager(dir)
|
|
assert.Equal(t, tt.expected, result)
|
|
})
|
|
}
|
|
|
|
t.Run("no lock file defaults to npm", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
|
|
result := DetectPackageManager(dir)
|
|
assert.Equal(t, "npm", result)
|
|
})
|
|
|
|
t.Run("bun takes priority over npm", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
|
|
// Create both lock files
|
|
err := os.WriteFile(filepath.Join(dir, "bun.lockb"), []byte(""), 0644)
|
|
require.NoError(t, err)
|
|
err = os.WriteFile(filepath.Join(dir, "package-lock.json"), []byte(""), 0644)
|
|
require.NoError(t, err)
|
|
|
|
result := DetectPackageManager(dir)
|
|
assert.Equal(t, "bun", result)
|
|
})
|
|
}
|
|
|
|
func TestGetLaravelAppName_Good(t *testing.T) {
|
|
t.Run("simple app name", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
|
|
envContent := `APP_NAME=MyApp
|
|
APP_ENV=local`
|
|
err := os.WriteFile(filepath.Join(dir, ".env"), []byte(envContent), 0644)
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, "MyApp", GetLaravelAppName(dir))
|
|
})
|
|
|
|
t.Run("quoted app name", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
|
|
envContent := `APP_NAME="My Awesome App"
|
|
APP_ENV=local`
|
|
err := os.WriteFile(filepath.Join(dir, ".env"), []byte(envContent), 0644)
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, "My Awesome App", GetLaravelAppName(dir))
|
|
})
|
|
|
|
t.Run("single quoted app name", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
|
|
envContent := `APP_NAME='My App'
|
|
APP_ENV=local`
|
|
err := os.WriteFile(filepath.Join(dir, ".env"), []byte(envContent), 0644)
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, "My App", GetLaravelAppName(dir))
|
|
})
|
|
}
|
|
|
|
func TestGetLaravelAppName_Bad(t *testing.T) {
|
|
t.Run("no .env file", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
assert.Equal(t, "", GetLaravelAppName(dir))
|
|
})
|
|
|
|
t.Run("no APP_NAME in .env", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
|
|
envContent := `APP_ENV=local
|
|
APP_DEBUG=true`
|
|
err := os.WriteFile(filepath.Join(dir, ".env"), []byte(envContent), 0644)
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, "", GetLaravelAppName(dir))
|
|
})
|
|
}
|
|
|
|
func TestGetLaravelAppURL_Good(t *testing.T) {
|
|
t.Run("standard URL", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
|
|
envContent := `APP_NAME=MyApp
|
|
APP_URL=https://myapp.test`
|
|
err := os.WriteFile(filepath.Join(dir, ".env"), []byte(envContent), 0644)
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, "https://myapp.test", GetLaravelAppURL(dir))
|
|
})
|
|
|
|
t.Run("quoted URL", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
|
|
envContent := `APP_URL="http://localhost:8000"`
|
|
err := os.WriteFile(filepath.Join(dir, ".env"), []byte(envContent), 0644)
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, "http://localhost:8000", GetLaravelAppURL(dir))
|
|
})
|
|
}
|
|
|
|
func TestExtractDomainFromURL_Good(t *testing.T) {
|
|
tests := []struct {
|
|
url string
|
|
expected string
|
|
}{
|
|
{"https://example.com", "example.com"},
|
|
{"http://example.com", "example.com"},
|
|
{"https://example.com:8080", "example.com"},
|
|
{"https://example.com/path/to/page", "example.com"},
|
|
{"https://example.com:443/path", "example.com"},
|
|
{"localhost", "localhost"},
|
|
{"localhost:8000", "localhost"},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.url, func(t *testing.T) {
|
|
result := ExtractDomainFromURL(tt.url)
|
|
assert.Equal(t, tt.expected, result)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestNeedsRedis_Good(t *testing.T) {
|
|
t.Run("CACHE_DRIVER=redis", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
|
|
envContent := `APP_NAME=Test
|
|
CACHE_DRIVER=redis`
|
|
err := os.WriteFile(filepath.Join(dir, ".env"), []byte(envContent), 0644)
|
|
require.NoError(t, err)
|
|
|
|
assert.True(t, needsRedis(dir))
|
|
})
|
|
|
|
t.Run("QUEUE_CONNECTION=redis", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
|
|
envContent := `APP_NAME=Test
|
|
QUEUE_CONNECTION=redis`
|
|
err := os.WriteFile(filepath.Join(dir, ".env"), []byte(envContent), 0644)
|
|
require.NoError(t, err)
|
|
|
|
assert.True(t, needsRedis(dir))
|
|
})
|
|
|
|
t.Run("REDIS_HOST localhost", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
|
|
envContent := `APP_NAME=Test
|
|
REDIS_HOST=localhost`
|
|
err := os.WriteFile(filepath.Join(dir, ".env"), []byte(envContent), 0644)
|
|
require.NoError(t, err)
|
|
|
|
assert.True(t, needsRedis(dir))
|
|
})
|
|
|
|
t.Run("REDIS_HOST 127.0.0.1", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
|
|
envContent := `APP_NAME=Test
|
|
REDIS_HOST=127.0.0.1`
|
|
err := os.WriteFile(filepath.Join(dir, ".env"), []byte(envContent), 0644)
|
|
require.NoError(t, err)
|
|
|
|
assert.True(t, needsRedis(dir))
|
|
})
|
|
|
|
t.Run("SESSION_DRIVER=redis", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
envContent := "SESSION_DRIVER=redis"
|
|
err := os.WriteFile(filepath.Join(dir, ".env"), []byte(envContent), 0644)
|
|
require.NoError(t, err)
|
|
assert.True(t, needsRedis(dir))
|
|
})
|
|
|
|
t.Run("BROADCAST_DRIVER=redis", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
envContent := "BROADCAST_DRIVER=redis"
|
|
err := os.WriteFile(filepath.Join(dir, ".env"), []byte(envContent), 0644)
|
|
require.NoError(t, err)
|
|
assert.True(t, needsRedis(dir))
|
|
})
|
|
|
|
t.Run("REDIS_HOST remote (should be false for local dev env)", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
envContent := "REDIS_HOST=redis.example.com"
|
|
err := os.WriteFile(filepath.Join(dir, ".env"), []byte(envContent), 0644)
|
|
require.NoError(t, err)
|
|
assert.False(t, needsRedis(dir))
|
|
})
|
|
}
|
|
|
|
func TestNeedsRedis_Bad(t *testing.T) {
|
|
t.Run("no .env file", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
assert.False(t, needsRedis(dir))
|
|
})
|
|
|
|
t.Run("no redis configuration", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
|
|
envContent := `APP_NAME=Test
|
|
CACHE_DRIVER=file
|
|
QUEUE_CONNECTION=sync`
|
|
err := os.WriteFile(filepath.Join(dir, ".env"), []byte(envContent), 0644)
|
|
require.NoError(t, err)
|
|
|
|
assert.False(t, needsRedis(dir))
|
|
})
|
|
|
|
t.Run("commented redis config", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
|
|
envContent := `APP_NAME=Test
|
|
# CACHE_DRIVER=redis`
|
|
err := os.WriteFile(filepath.Join(dir, ".env"), []byte(envContent), 0644)
|
|
require.NoError(t, err)
|
|
|
|
assert.False(t, needsRedis(dir))
|
|
})
|
|
}
|
|
|
|
func TestHasVite_Good(t *testing.T) {
|
|
viteFiles := []string{
|
|
"vite.config.js",
|
|
"vite.config.ts",
|
|
"vite.config.mjs",
|
|
"vite.config.mts",
|
|
}
|
|
|
|
for _, file := range viteFiles {
|
|
t.Run(file, func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
|
|
err := os.WriteFile(filepath.Join(dir, file), []byte("export default {}"), 0644)
|
|
require.NoError(t, err)
|
|
|
|
assert.True(t, hasVite(dir))
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestHasVite_Bad(t *testing.T) {
|
|
t.Run("no vite config", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
assert.False(t, hasVite(dir))
|
|
})
|
|
|
|
t.Run("wrong file name", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
|
|
err := os.WriteFile(filepath.Join(dir, "vite.config.json"), []byte("{}"), 0644)
|
|
require.NoError(t, err)
|
|
|
|
assert.False(t, hasVite(dir))
|
|
})
|
|
}
|
|
|
|
func TestIsFrankenPHPProject_ConfigWithoutFrankenPHP(t *testing.T) {
|
|
t.Run("octane config without frankenphp", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
|
|
// Create composer.json with laravel/octane
|
|
composerJSON := `{
|
|
"require": {
|
|
"laravel/octane": "^2.0"
|
|
}
|
|
}`
|
|
err := os.WriteFile(filepath.Join(dir, "composer.json"), []byte(composerJSON), 0644)
|
|
require.NoError(t, err)
|
|
|
|
// Create config directory and octane.php without frankenphp
|
|
configDir := filepath.Join(dir, "config")
|
|
err = os.MkdirAll(configDir, 0755)
|
|
require.NoError(t, err)
|
|
|
|
octaneConfig := `<?php
|
|
return [
|
|
'server' => 'swoole',
|
|
];`
|
|
err = os.WriteFile(filepath.Join(configDir, "octane.php"), []byte(octaneConfig), 0644)
|
|
require.NoError(t, err)
|
|
|
|
assert.False(t, IsFrankenPHPProject(dir))
|
|
})
|
|
}
|