Skip to content

Commit 59c60b3

Browse files
committed
chore: wip
Revert "chore: wip" This reverts commit 3024439. chore: wip chore: wip
1 parent ce053ce commit 59c60b3

File tree

3 files changed

+93
-34
lines changed

3 files changed

+93
-34
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: 63 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,16 @@ describe('Integration Ecosystem & Plugin Architecture', () => {
99
let pluginManager: PluginManager
1010
let mockContext: SetupContext
1111
let originalEnv: Record<string, string | undefined>
12+
let originalCwd: string
1213

1314
beforeEach(() => {
15+
// Store original working directory
16+
originalCwd = process.cwd()
17+
18+
// Change to a temporary directory to avoid interference with project files
19+
const tempDir = fs.mkdtempSync(path.join(require('node:os').tmpdir(), 'plugin-test-'))
20+
process.chdir(tempDir)
21+
1422
pluginManager = new PluginManager()
1523
mockContext = {
1624
step: 'setup_complete',
@@ -58,18 +66,43 @@ describe('Integration Ecosystem & Plugin Architecture', () => {
5866
delete process.env.JIRA_TOKEN
5967
delete process.env.JIRA_URL
6068

61-
// Clean up any .buddy files that might exist
69+
// Clean up any .buddy files that might exist (critical for plugin detection)
6270
if (fs.existsSync('.buddy')) {
6371
fs.rmSync('.buddy', { recursive: true, force: true })
6472
}
73+
74+
// Also clean up specific plugin trigger files that might exist in the working directory
75+
const pluginFiles = ['.buddy/slack-webhook', '.buddy/jira-config.json', '.buddy/discord-webhook']
76+
pluginFiles.forEach((file) => {
77+
if (fs.existsSync(file)) {
78+
fs.rmSync(file, { force: true })
79+
}
80+
})
6581
})
6682

6783
afterEach(() => {
68-
// Clean up test files
84+
// Clean up test files in temp directory
6985
if (fs.existsSync('.buddy')) {
7086
fs.rmSync('.buddy', { recursive: true, force: true })
7187
}
7288

89+
// Clean up specific plugin trigger files
90+
const pluginFiles = ['.buddy/slack-webhook', '.buddy/jira-config.json', '.buddy/discord-webhook']
91+
pluginFiles.forEach((file) => {
92+
if (fs.existsSync(file)) {
93+
fs.rmSync(file, { force: true })
94+
}
95+
})
96+
97+
// Restore original working directory and clean up temp directory
98+
const tempDir = process.cwd()
99+
process.chdir(originalCwd)
100+
try {
101+
fs.rmSync(tempDir, { recursive: true, force: true })
102+
} catch {
103+
// Ignore cleanup errors
104+
}
105+
73106
// Restore original environment variables
74107
if (originalEnv.SLACK_WEBHOOK_URL !== undefined) {
75108
process.env.SLACK_WEBHOOK_URL = originalEnv.SLACK_WEBHOOK_URL
@@ -135,6 +168,9 @@ describe('Integration Ecosystem & Plugin Architecture', () => {
135168
console.log(` - JIRA_PROJECT_KEY: ${process.env.JIRA_PROJECT_KEY ? 'SET' : 'UNSET'}`)
136169
console.log('File system check:')
137170
console.log(` - .buddy exists: ${fs.existsSync('.buddy')}`)
171+
console.log(` - .buddy/slack-webhook exists: ${fs.existsSync('.buddy/slack-webhook')}`)
172+
console.log(` - .buddy/jira-config.json exists: ${fs.existsSync('.buddy/jira-config.json')}`)
173+
console.log(` - .buddy/discord-webhook exists: ${fs.existsSync('.buddy/discord-webhook')}`)
138174
if (fs.existsSync('.buddy')) {
139175
try {
140176
const buddyFiles = fs.readdirSync('.buddy', { recursive: true })
@@ -211,7 +247,7 @@ describe('Integration Ecosystem & Plugin Architecture', () => {
211247
expect(process.env.DISCORD_WEBHOOK_URL).toBeUndefined()
212248
expect(process.env.JIRA_API_TOKEN).toBeUndefined()
213249

214-
// Create custom plugin configuration
250+
// Create custom plugin configuration (without handler function since it can't be serialized)
215251
fs.mkdirSync('.buddy/plugins', { recursive: true })
216252
const customPlugin = {
217253
name: 'custom-integration',
@@ -223,18 +259,20 @@ describe('Integration Ecosystem & Plugin Architecture', () => {
223259
name: 'custom-hook',
224260
priority: 15,
225261
async: false,
226-
handler() {
227-
console.log('Custom hook executed')
228-
},
262+
// Note: handler function would be loaded dynamically in real usage
229263
},
230264
],
231265
configuration: { custom_setting: 'value' },
232266
}
233267

234-
fs.writeFileSync(
235-
path.join('.buddy/plugins', 'custom.json'),
236-
JSON.stringify(customPlugin),
237-
)
268+
const customPluginPath = path.join('.buddy/plugins', 'custom.json')
269+
fs.writeFileSync(customPluginPath, JSON.stringify(customPlugin))
270+
271+
// Verify the file was written correctly
272+
expect(fs.existsSync(customPluginPath)).toBe(true)
273+
const writtenContent = fs.readFileSync(customPluginPath, 'utf8')
274+
const parsedContent = JSON.parse(writtenContent)
275+
expect(parsedContent).toEqual(customPlugin)
238276

239277
// Create a fresh PluginManager instance to avoid state pollution
240278
const freshPluginManager = new PluginManager()
@@ -254,13 +292,25 @@ describe('Integration Ecosystem & Plugin Architecture', () => {
254292
const files = fs.readdirSync('.buddy/plugins')
255293
files.forEach(f => console.log(` - ${f}`))
256294

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)
295+
// Read the custom plugin file to verify its contents (use correct filename)
296+
const content = fs.readFileSync('.buddy/plugins/custom.json', 'utf8')
297+
console.log('Custom plugin file content:', content.substring(0, 200))
298+
const parsed = JSON.parse(content)
299+
console.log('Parsed plugin name:', parsed.name)
260300
}
261301
catch (err) {
262302
console.log('Error reading .buddy/plugins:', err)
263303
}
304+
305+
// Test the loadCustomPlugins method directly
306+
try {
307+
const directPlugins = await (freshPluginManager as any).loadCustomPlugins()
308+
console.log('Direct loadCustomPlugins result:', directPlugins.length)
309+
directPlugins.forEach((p: any) => console.log(` Direct: ${p.name}`))
310+
}
311+
catch (err) {
312+
console.log('Direct loadCustomPlugins error:', err)
313+
}
264314
}
265315

266316
expect(customPlugins).toHaveLength(1)

test/respect-latest.test.ts

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ describe('respectLatest functionality', () => {
1111
let testDir: string
1212

1313
beforeEach(() => {
14-
// Create temporary test directory
15-
testDir = fs.mkdtempSync('buddy-test-')
14+
// Create temporary test directory in a more isolated location
15+
// eslint-disable-next-line ts/no-require-imports
16+
testDir = fs.mkdtempSync(path.join(require('node:os').tmpdir(), 'buddy-test-'))
1617
})
1718

1819
afterEach(() => {
@@ -88,8 +89,15 @@ devDependencies:
8889
const depsPath = path.join(testDir, 'deps.yaml')
8990
fs.writeFileSync(depsPath, depsYaml)
9091

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

94102
// Create mock updates
95103
const updates = [
@@ -111,36 +119,29 @@ devDependencies:
111119
},
112120
]
113121

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-
124122
// Debug info for CI troubleshooting - Check before calling updateDependencyFile
125123
console.log('🔍 Test setup verification:')
126124
console.log(' - File path:', depsPath)
127125
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))
126+
console.log(' - Original content preview:', actualFileContent.substring(0, 100))
127+
console.log(' - isDependencyFile result:', isDependencyFile(depsPath))
128+
console.log(' - Content is YAML format:', !actualFileContent.trim().startsWith('{'))
131129

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

135134
// Debug info for CI troubleshooting
136135
if (!updatedContent.includes('python.org: "*"')) {
137136
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))
137+
console.log('Input content length:', actualFileContent.length)
138+
console.log('Input content preview:', actualFileContent.substring(0, 200))
139+
console.log('Output content length:', updatedContent.length)
140+
console.log('Output content preview:', updatedContent.substring(0, 500))
141+
console.log('Content types match:', typeof actualFileContent, typeof updatedContent)
140142

141143
// 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)
144+
const absolutePath = path.resolve(depsPath)
144145
console.log('Absolute path:', absolutePath)
145146
console.log('Working directory:', process.cwd())
146147

0 commit comments

Comments
 (0)