|
| 1 | +/* eslint-disable no-console */ |
| 2 | +import { describe, expect, it } from 'bun:test' |
| 3 | +import { PullRequestGenerator } from '../src/pr/pr-generator' |
| 4 | + |
| 5 | +describe('PR Body Regression - Stripe Issue', () => { |
| 6 | + it('should reproduce the exact stripe regression from PR #1453', async () => { |
| 7 | + // This test reproduces the exact regression where stripe major update |
| 8 | + // generates only summary table without detailed package information |
| 9 | + |
| 10 | + const config = { |
| 11 | + repository: { |
| 12 | + provider: 'github' as const, |
| 13 | + owner: 'stacksjs', |
| 14 | + name: 'stacks', |
| 15 | + }, |
| 16 | + } |
| 17 | + |
| 18 | + const generator = new PullRequestGenerator(config) |
| 19 | + |
| 20 | + // Exact same data structure that would generate PR #1453 |
| 21 | + const stripeUpdate = { |
| 22 | + name: 'Major Update - stripe', |
| 23 | + title: 'chore(deps): update dependency stripe to 18.4.0', |
| 24 | + body: '', |
| 25 | + updateType: 'major' as const, |
| 26 | + updates: [{ |
| 27 | + name: 'stripe', |
| 28 | + currentVersion: '17.7.0', |
| 29 | + newVersion: '18.4.0', |
| 30 | + updateType: 'major' as const, |
| 31 | + dependencyType: 'dependencies' as const, |
| 32 | + file: 'package.json', |
| 33 | + }], |
| 34 | + } |
| 35 | + |
| 36 | + const body = await generator.generateBody(stripeUpdate) |
| 37 | + |
| 38 | + console.log('🔍 Generated PR body for regression test:') |
| 39 | + console.log('='.repeat(60)) |
| 40 | + console.log(body) |
| 41 | + console.log('='.repeat(60)) |
| 42 | + |
| 43 | + // The regression: PR body should NOT be sparse like PR #1453 |
| 44 | + // It should include the detailed NPM table with badges and links |
| 45 | + |
| 46 | + // 1. Should have package summary table |
| 47 | + expect(body).toContain('## Package Updates Summary') |
| 48 | + expect(body).toContain('| 📦 NPM Packages | 1 |') |
| 49 | + expect(body).toContain('| **Total** | **1** |') |
| 50 | + |
| 51 | + // 2. CRITICAL: Should have detailed NPM dependencies section (this was missing in #1453) |
| 52 | + expect(body).toContain('## 📦 npm Dependencies') |
| 53 | + expect(body).toContain('') |
| 54 | + expect(body).toContain('*1 package will be updated*') |
| 55 | + |
| 56 | + // 3. Should have detailed package table with badges (missing in #1453) |
| 57 | + expect(body).toContain('| Package | Change | Age | Adoption | Passing | Confidence |') |
| 58 | + expect(body).toContain('stripe') |
| 59 | + expect(body).toContain('17.7.0') |
| 60 | + expect(body).toContain('18.4.0') |
| 61 | + expect(body).toContain('developer.mend.io/api/mc/badges') // Confidence badges |
| 62 | + expect(body).toContain('renovatebot.com/diffs/npm/stripe') // Diff link |
| 63 | + |
| 64 | + // 4. Should have release notes section (missing in #1453) |
| 65 | + expect(body).toContain('### Release Notes') |
| 66 | + expect(body).toContain('<details>') |
| 67 | + expect(body).toContain('stripe/stripe-node') |
| 68 | + |
| 69 | + // 5. Should have package statistics (missing in #1453) |
| 70 | + expect(body).toContain('### 📊 Package Statistics') |
| 71 | + expect(body).toContain('weekly downloads') |
| 72 | + |
| 73 | + // 6. Should NOT be the broken minimal version from PR #1453 |
| 74 | + expect(body).not.toMatch(/^This PR contains the following updates:\s*## Package Updates Summary\s*\| Type \| Count \|\s*\|------\|-------\|\s*\| \*\*Total\*\* \| \*\*1\*\* \|\s*---\s*### Release Notes\s*---/) |
| 75 | + |
| 76 | + // 7. Body should be substantial, not sparse like PR #1453 (which was ~500 chars) |
| 77 | + expect(body.length).toBeGreaterThan(2000) // Should have substantial content |
| 78 | + |
| 79 | + console.log(`✅ PR body length: ${body.length} characters (should be > 2000)`) |
| 80 | + console.log(`✅ Has detailed package table: ${body.includes('| Package | Change | Age |')}`) |
| 81 | + console.log(`✅ Has badges: ${body.includes('developer.mend.io')}`) |
| 82 | + console.log(`✅ Has release notes: ${body.includes('<details>')}`) |
| 83 | + }) |
| 84 | + |
| 85 | + it('should handle different file path formats correctly', async () => { |
| 86 | + // This test ensures we handle various file path formats that might come from the runtime |
| 87 | + |
| 88 | + const config = { |
| 89 | + repository: { |
| 90 | + provider: 'github' as const, |
| 91 | + owner: 'stacksjs', |
| 92 | + name: 'stacks', |
| 93 | + }, |
| 94 | + } |
| 95 | + |
| 96 | + const generator = new PullRequestGenerator(config) |
| 97 | + |
| 98 | + // Test relative path (likely cause of PR #1453 regression) |
| 99 | + const relativePathUpdate = { |
| 100 | + name: 'Major Update - stripe', |
| 101 | + title: 'chore(deps): update dependency stripe to 18.4.0', |
| 102 | + body: '', |
| 103 | + updateType: 'major' as const, |
| 104 | + updates: [{ |
| 105 | + name: 'stripe', |
| 106 | + currentVersion: '17.7.0', |
| 107 | + newVersion: '18.4.0', |
| 108 | + updateType: 'major' as const, |
| 109 | + dependencyType: 'dependencies' as const, |
| 110 | + file: './package.json', // This was likely the issue in PR #1453 |
| 111 | + }], |
| 112 | + } |
| 113 | + |
| 114 | + const body = await generator.generateBody(relativePathUpdate) |
| 115 | + |
| 116 | + // Should work correctly with relative path |
| 117 | + expect(body).toContain('| 📦 NPM Packages | 1 |') |
| 118 | + expect(body).toContain('## 📦 npm Dependencies') |
| 119 | + expect(body).toContain('| Package | Change | Age | Adoption | Passing | Confidence |') |
| 120 | + expect(body.length).toBeGreaterThan(2000) |
| 121 | + |
| 122 | + // Test absolute path (common in CI environments) |
| 123 | + const absolutePathUpdate = { |
| 124 | + name: 'Major Update - stripe', |
| 125 | + title: 'chore(deps): update dependency stripe to 18.4.0', |
| 126 | + body: '', |
| 127 | + updateType: 'major' as const, |
| 128 | + updates: [{ |
| 129 | + name: 'stripe', |
| 130 | + currentVersion: '17.7.0', |
| 131 | + newVersion: '18.4.0', |
| 132 | + updateType: 'major' as const, |
| 133 | + dependencyType: 'dependencies' as const, |
| 134 | + file: '/home/runner/work/stacks/stacks/package.json', // CI environment path |
| 135 | + }], |
| 136 | + } |
| 137 | + |
| 138 | + const bodyAbsolute = await generator.generateBody(absolutePathUpdate) |
| 139 | + |
| 140 | + // Should work correctly with absolute path |
| 141 | + expect(bodyAbsolute).toContain('| 📦 NPM Packages | 1 |') |
| 142 | + expect(bodyAbsolute).toContain('## 📦 npm Dependencies') |
| 143 | + expect(bodyAbsolute).toContain('| Package | Change | Age | Adoption | Passing | Confidence |') |
| 144 | + expect(bodyAbsolute.length).toBeGreaterThan(2000) |
| 145 | + }) |
| 146 | + |
| 147 | + it('should verify the minimal broken format does NOT match our output', async () => { |
| 148 | + // This test ensures we don't regress back to the broken format from PR #1453 |
| 149 | + |
| 150 | + const config = { |
| 151 | + repository: { |
| 152 | + provider: 'github' as const, |
| 153 | + owner: 'stacksjs', |
| 154 | + name: 'stacks', |
| 155 | + }, |
| 156 | + } |
| 157 | + |
| 158 | + const generator = new PullRequestGenerator(config) |
| 159 | + |
| 160 | + const stripeUpdate = { |
| 161 | + name: 'Major Update - stripe', |
| 162 | + title: 'chore(deps): update dependency stripe to 18.4.0', |
| 163 | + body: '', |
| 164 | + updateType: 'major' as const, |
| 165 | + updates: [{ |
| 166 | + name: 'stripe', |
| 167 | + currentVersion: '17.7.0', |
| 168 | + newVersion: '18.4.0', |
| 169 | + updateType: 'major' as const, |
| 170 | + dependencyType: 'dependencies' as const, |
| 171 | + file: 'package.json', |
| 172 | + }], |
| 173 | + } |
| 174 | + |
| 175 | + const body = await generator.generateBody(stripeUpdate) |
| 176 | + |
| 177 | + // The broken pattern from PR #1453 (minimal content without detailed table) |
| 178 | + const brokenPattern = `This PR contains the following updates: |
| 179 | +
|
| 180 | +## Package Updates Summary |
| 181 | +
|
| 182 | +| Type | Count | |
| 183 | +|------|-------| |
| 184 | +| **Total** | **1** | |
| 185 | +
|
| 186 | +
|
| 187 | +--- |
| 188 | +
|
| 189 | +### Release Notes |
| 190 | +
|
| 191 | +---` |
| 192 | + |
| 193 | + // Our output should NOT match this broken minimal pattern |
| 194 | + expect(body).not.toContain(brokenPattern) |
| 195 | + |
| 196 | + // Specifically check that we have content between summary and release notes |
| 197 | + const summaryToReleaseNotes = body.substring( |
| 198 | + body.indexOf('| **Total** | **1** |'), |
| 199 | + body.indexOf('### Release Notes'), |
| 200 | + ) |
| 201 | + |
| 202 | + // Should have substantial content (NPM section) between summary and release notes |
| 203 | + expect(summaryToReleaseNotes).toContain('## 📦 npm Dependencies') |
| 204 | + expect(summaryToReleaseNotes.length).toBeGreaterThan(500) // Should have substantial content |
| 205 | + }) |
| 206 | +}) |
0 commit comments