@aaronshaf/ger 0.1.8 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,175 +0,0 @@
1
- import { describe, test, expect } from 'bun:test'
2
- import * as fs from 'node:fs'
3
- import * as os from 'node:os'
4
- import * as path from 'node:path'
5
-
6
- // Since the helper functions are private, we'll redefine them here for testing
7
- // This ensures they behave exactly like the ones in the review command
8
-
9
- // Helper to expand tilde in file paths
10
- const expandTilde = (filePath: string): string => {
11
- if (filePath.startsWith('~/')) {
12
- return path.join(os.homedir(), filePath.slice(2))
13
- }
14
- return filePath
15
- }
16
-
17
- // Helper to read prompt file
18
- const readPromptFile = (filePath: string): string | null => {
19
- try {
20
- const expanded = expandTilde(filePath)
21
- if (fs.existsSync(expanded)) {
22
- return fs.readFileSync(expanded, 'utf8')
23
- }
24
- } catch {
25
- // Ignore errors
26
- }
27
- return null
28
- }
29
-
30
- describe('Prompt Helper Functions', () => {
31
- describe('expandTilde', () => {
32
- test('should expand tilde (~/) to home directory', () => {
33
- const homeDir = os.homedir()
34
- const result = expandTilde('~/test/file.txt')
35
- expect(result).toBe(path.join(homeDir, 'test/file.txt'))
36
- })
37
-
38
- test('should handle tilde with no trailing slash', () => {
39
- const homeDir = os.homedir()
40
- const result = expandTilde('~/file.txt')
41
- expect(result).toBe(path.join(homeDir, 'file.txt'))
42
- })
43
-
44
- test('should return unchanged path when not starting with tilde', () => {
45
- const absolutePath = '/absolute/path/file.txt'
46
- const result = expandTilde(absolutePath)
47
- expect(result).toBe(absolutePath)
48
- })
49
-
50
- test('should return unchanged path for relative paths without tilde', () => {
51
- const relativePath = 'relative/path/file.txt'
52
- const result = expandTilde(relativePath)
53
- expect(result).toBe(relativePath)
54
- })
55
-
56
- test('should handle empty string', () => {
57
- const result = expandTilde('')
58
- expect(result).toBe('')
59
- })
60
-
61
- test('should handle just tilde', () => {
62
- const result = expandTilde('~')
63
- expect(result).toBe('~')
64
- })
65
-
66
- test('should handle tilde in middle of path', () => {
67
- const pathWithTildeInMiddle = '/path/~/file.txt'
68
- const result = expandTilde(pathWithTildeInMiddle)
69
- expect(result).toBe(pathWithTildeInMiddle)
70
- })
71
- })
72
-
73
- describe('readPromptFile', () => {
74
- test('should read existing file content', () => {
75
- const tempDir = os.tmpdir()
76
- const tempFile = path.join(tempDir, `test-read-${Date.now()}.md`)
77
- const testContent = 'Test prompt content\nWith multiple lines'
78
-
79
- try {
80
- fs.writeFileSync(tempFile, testContent, 'utf8')
81
- const result = readPromptFile(tempFile)
82
- expect(result).toBe(testContent)
83
- } finally {
84
- if (fs.existsSync(tempFile)) {
85
- fs.unlinkSync(tempFile)
86
- }
87
- }
88
- })
89
-
90
- test('should return null for non-existent file', () => {
91
- const nonExistentFile = '/tmp/does-not-exist-prompt.md'
92
- const result = readPromptFile(nonExistentFile)
93
- expect(result).toBeNull()
94
- })
95
-
96
- test('should expand tilde paths before reading', () => {
97
- const homeDir = os.homedir()
98
- const fileName = `.test-tilde-read-${Date.now()}.md`
99
- const absolutePath = path.join(homeDir, fileName)
100
- const tildePath = `~/${fileName}`
101
- const testContent = 'Tilde path test content'
102
-
103
- try {
104
- fs.writeFileSync(absolutePath, testContent, 'utf8')
105
- const result = readPromptFile(tildePath)
106
- expect(result).toBe(testContent)
107
- } finally {
108
- if (fs.existsSync(absolutePath)) {
109
- fs.unlinkSync(absolutePath)
110
- }
111
- }
112
- })
113
-
114
- test('should handle permission errors gracefully', () => {
115
- // Try to read from a restricted directory
116
- const restrictedFile = '/root/test-permission-error.md'
117
- const result = readPromptFile(restrictedFile)
118
- expect(result).toBeNull()
119
- })
120
-
121
- test('should handle directory instead of file', () => {
122
- const tempDir = os.tmpdir()
123
- const result = readPromptFile(tempDir)
124
- expect(result).toBeNull()
125
- })
126
-
127
- test('should handle empty file', () => {
128
- const tempDir = os.tmpdir()
129
- const tempFile = path.join(tempDir, `test-empty-${Date.now()}.md`)
130
-
131
- try {
132
- fs.writeFileSync(tempFile, '', 'utf8')
133
- const result = readPromptFile(tempFile)
134
- expect(result).toBe('')
135
- } finally {
136
- if (fs.existsSync(tempFile)) {
137
- fs.unlinkSync(tempFile)
138
- }
139
- }
140
- })
141
-
142
- test('should handle file with special characters', () => {
143
- const tempDir = os.tmpdir()
144
- const tempFile = path.join(tempDir, `test-special-${Date.now()}.md`)
145
- const specialContent =
146
- 'Content with special chars: ñáéíóú 中文 🚀 "quotes" \\backslashes\\ /slashes/'
147
-
148
- try {
149
- fs.writeFileSync(tempFile, specialContent, 'utf8')
150
- const result = readPromptFile(tempFile)
151
- expect(result).toBe(specialContent)
152
- } finally {
153
- if (fs.existsSync(tempFile)) {
154
- fs.unlinkSync(tempFile)
155
- }
156
- }
157
- })
158
-
159
- test('should handle very large file', () => {
160
- const tempDir = os.tmpdir()
161
- const tempFile = path.join(tempDir, `test-large-${Date.now()}.md`)
162
- const largeContent = 'Large content '.repeat(10000) // ~140KB
163
-
164
- try {
165
- fs.writeFileSync(tempFile, largeContent, 'utf8')
166
- const result = readPromptFile(tempFile)
167
- expect(result).toBe(largeContent)
168
- } finally {
169
- if (fs.existsSync(tempFile)) {
170
- fs.unlinkSync(tempFile)
171
- }
172
- }
173
- })
174
- })
175
- })