Skip to content

Commit 6e09f48

Browse files
committed
chore: wip
1 parent ce053ce commit 6e09f48

File tree

3 files changed

+72
-31
lines changed

3 files changed

+72
-31
lines changed

src/utils/dependency-file-parser.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,17 @@ async function parseSimpleYamlDependencies(content: string, filePath: string): P
129129
export async function updateDependencyFile(filePath: string, content: string, updates: PackageUpdate[]): Promise<string> {
130130
try {
131131
if (!isDependencyFile(filePath)) {
132+
console.log(`⚠️ updateDependencyFile: ${filePath} is not a dependency file, returning original content`)
132133
return content
133134
}
134135

136+
// Extra safety check: ensure we're not accidentally processing non-YAML content
137+
if (content.trim().startsWith('{') && content.includes('"require"')) {
138+
console.log(`⚠️ updateDependencyFile: Content appears to be JSON (composer.json), but file is ${filePath}`)
139+
console.log(`Content preview: ${content.substring(0, 200)}`)
140+
return content // Don't process JSON content in YAML function
141+
}
142+
135143
let updatedContent = content
136144

137145
// Apply updates using string replacement to preserve formatting

test/plugin-architecture.test.ts

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,18 @@ describe('Integration Ecosystem & Plugin Architecture', () => {
5858
delete process.env.JIRA_TOKEN
5959
delete process.env.JIRA_URL
6060

61-
// Clean up any .buddy files that might exist
61+
// Clean up any .buddy files that might exist (critical for plugin detection)
6262
if (fs.existsSync('.buddy')) {
6363
fs.rmSync('.buddy', { recursive: true, force: true })
6464
}
65+
66+
// Also clean up specific plugin trigger files that might exist in the working directory
67+
const pluginFiles = ['.buddy/slack-webhook', '.buddy/jira-config.json', '.buddy/discord-webhook']
68+
pluginFiles.forEach((file) => {
69+
if (fs.existsSync(file)) {
70+
fs.rmSync(file, { force: true })
71+
}
72+
})
6573
})
6674

6775
afterEach(() => {
@@ -70,6 +78,14 @@ describe('Integration Ecosystem & Plugin Architecture', () => {
7078
fs.rmSync('.buddy', { recursive: true, force: true })
7179
}
7280

81+
// Clean up specific plugin trigger files
82+
const pluginFiles = ['.buddy/slack-webhook', '.buddy/jira-config.json', '.buddy/discord-webhook']
83+
pluginFiles.forEach((file) => {
84+
if (fs.existsSync(file)) {
85+
fs.rmSync(file, { force: true })
86+
}
87+
})
88+
7389
// Restore original environment variables
7490
if (originalEnv.SLACK_WEBHOOK_URL !== undefined) {
7591
process.env.SLACK_WEBHOOK_URL = originalEnv.SLACK_WEBHOOK_URL
@@ -135,6 +151,9 @@ describe('Integration Ecosystem & Plugin Architecture', () => {
135151
console.log(` - JIRA_PROJECT_KEY: ${process.env.JIRA_PROJECT_KEY ? 'SET' : 'UNSET'}`)
136152
console.log('File system check:')
137153
console.log(` - .buddy exists: ${fs.existsSync('.buddy')}`)
154+
console.log(` - .buddy/slack-webhook exists: ${fs.existsSync('.buddy/slack-webhook')}`)
155+
console.log(` - .buddy/jira-config.json exists: ${fs.existsSync('.buddy/jira-config.json')}`)
156+
console.log(` - .buddy/discord-webhook exists: ${fs.existsSync('.buddy/discord-webhook')}`)
138157
if (fs.existsSync('.buddy')) {
139158
try {
140159
const buddyFiles = fs.readdirSync('.buddy', { recursive: true })
@@ -211,7 +230,7 @@ describe('Integration Ecosystem & Plugin Architecture', () => {
211230
expect(process.env.DISCORD_WEBHOOK_URL).toBeUndefined()
212231
expect(process.env.JIRA_API_TOKEN).toBeUndefined()
213232

214-
// Create custom plugin configuration
233+
// Create custom plugin configuration (without handler function since it can't be serialized)
215234
fs.mkdirSync('.buddy/plugins', { recursive: true })
216235
const customPlugin = {
217236
name: 'custom-integration',
@@ -223,18 +242,20 @@ describe('Integration Ecosystem & Plugin Architecture', () => {
223242
name: 'custom-hook',
224243
priority: 15,
225244
async: false,
226-
handler() {
227-
console.log('Custom hook executed')
228-
},
245+
// Note: handler function would be loaded dynamically in real usage
229246
},
230247
],
231248
configuration: { custom_setting: 'value' },
232249
}
233250

234-
fs.writeFileSync(
235-
path.join('.buddy/plugins', 'custom.json'),
236-
JSON.stringify(customPlugin),
237-
)
251+
const customPluginPath = path.join('.buddy/plugins', 'custom.json')
252+
fs.writeFileSync(customPluginPath, JSON.stringify(customPlugin))
253+
254+
// Verify the file was written correctly
255+
expect(fs.existsSync(customPluginPath)).toBe(true)
256+
const writtenContent = fs.readFileSync(customPluginPath, 'utf8')
257+
const parsedContent = JSON.parse(writtenContent)
258+
expect(parsedContent).toEqual(customPlugin)
238259

239260
// Create a fresh PluginManager instance to avoid state pollution
240261
const freshPluginManager = new PluginManager()
@@ -254,13 +275,25 @@ describe('Integration Ecosystem & Plugin Architecture', () => {
254275
const files = fs.readdirSync('.buddy/plugins')
255276
files.forEach(f => console.log(` - ${f}`))
256277

257-
// Read the custom plugin file to verify its contents
258-
const content = fs.readFileSync('.buddy/plugins/custom-integration.json', 'utf8')
259-
console.log('Custom plugin file content:', content)
278+
// Read the custom plugin file to verify its contents (use correct filename)
279+
const content = fs.readFileSync('.buddy/plugins/custom.json', 'utf8')
280+
console.log('Custom plugin file content:', content.substring(0, 200))
281+
const parsed = JSON.parse(content)
282+
console.log('Parsed plugin name:', parsed.name)
260283
}
261284
catch (err) {
262285
console.log('Error reading .buddy/plugins:', err)
263286
}
287+
288+
// Test the loadCustomPlugins method directly
289+
try {
290+
const directPlugins = await freshPluginManager.loadCustomPlugins()
291+
console.log('Direct loadCustomPlugins result:', directPlugins.length)
292+
directPlugins.forEach(p => console.log(` Direct: ${p.name}`))
293+
}
294+
catch (err) {
295+
console.log('Direct loadCustomPlugins error:', err)
296+
}
264297
}
265298

266299
expect(customPlugins).toHaveLength(1)

test/respect-latest.test.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,15 @@ devDependencies:
8888
const depsPath = path.join(testDir, 'deps.yaml')
8989
fs.writeFileSync(depsPath, depsYaml)
9090

91+
// Ensure the file was written correctly and verify content
92+
const actualFileContent = fs.readFileSync(depsPath, 'utf-8')
93+
expect(actualFileContent).toBe(depsYaml) // Verify file content is correct
94+
9195
// Test the dependency file respectLatest logic
92-
const { updateDependencyFile } = await import('../src/utils/dependency-file-parser')
96+
const { updateDependencyFile, isDependencyFile } = await import('../src/utils/dependency-file-parser')
97+
98+
// Verify file detection works correctly
99+
expect(isDependencyFile(depsPath)).toBe(true)
93100

94101
// Create mock updates
95102
const updates = [
@@ -111,36 +118,29 @@ devDependencies:
111118
},
112119
]
113120

114-
// Read the original content using a try-catch to handle potential mocking conflicts
115-
let originalContent: string
116-
try {
117-
originalContent = fs.readFileSync(depsPath, 'utf-8')
118-
}
119-
catch {
120-
// If there's a mocking conflict, use the content directly
121-
originalContent = depsYaml
122-
}
123-
124121
// Debug info for CI troubleshooting - Check before calling updateDependencyFile
125122
console.log('🔍 Test setup verification:')
126123
console.log(' - File path:', depsPath)
127124
console.log(' - File exists:', fs.existsSync(depsPath))
128-
console.log(' - Original content preview:', originalContent.substring(0, 100))
129-
// eslint-disable-next-line ts/no-require-imports
130-
console.log(' - isDependencyFile result:', require('../src/utils/dependency-file-parser').isDependencyFile(depsPath))
125+
console.log(' - Original content preview:', actualFileContent.substring(0, 100))
126+
console.log(' - isDependencyFile result:', isDependencyFile(depsPath))
127+
console.log(' - Content is YAML format:', !actualFileContent.trim().startsWith('{'))
131128

132129
// Test that dynamic versions are respected (not updated)
133-
const updatedContent = await updateDependencyFile(depsPath, originalContent, updates)
130+
// Use the verified file content directly to avoid any file reading issues
131+
const updatedContent = await updateDependencyFile(depsPath, actualFileContent, updates)
134132

135133
// Debug info for CI troubleshooting
136134
if (!updatedContent.includes('python.org: "*"')) {
137135
console.log('🚨 Expected deps.yaml format, but got different format:')
138-
console.log('Updated content length:', updatedContent.length)
139-
console.log('Updated content preview:', updatedContent.substring(0, 500))
136+
console.log('Input content length:', actualFileContent.length)
137+
console.log('Input content preview:', actualFileContent.substring(0, 200))
138+
console.log('Output content length:', updatedContent.length)
139+
console.log('Output content preview:', updatedContent.substring(0, 500))
140+
console.log('Content types match:', typeof actualFileContent, typeof updatedContent)
140141

141142
// Check if the file path is being resolved correctly
142-
// eslint-disable-next-line ts/no-require-imports
143-
const absolutePath = require('node:path').resolve(depsPath)
143+
const absolutePath = path.resolve(depsPath)
144144
console.log('Absolute path:', absolutePath)
145145
console.log('Working directory:', process.cwd())
146146

0 commit comments

Comments
 (0)