-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathscoring.test.ts
More file actions
316 lines (272 loc) · 11.2 KB
/
scoring.test.ts
File metadata and controls
316 lines (272 loc) · 11.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
import test from 'node:test'
import assert from 'node:assert/strict'
import {
computeDeathIndex,
getDeathLabel,
determineCauseOfDeath,
generateLastWords,
computeAge,
formatDate,
} from './scoring'
import type { RepoData } from './types'
function buildRepo(overrides: Partial<RepoData> = {}): RepoData {
return {
fullName: 'example/dead-repo',
name: 'dead-repo',
description: 'old side project',
createdAt: '2017-01-01T00:00:00.000Z',
pushedAt: '2018-01-01T00:00:00.000Z',
lastCommitDate: '2018-01-01T00:00:00.000Z',
lastCommitMessage: 'final commit',
commitCount: 12,
language: 'TypeScript',
isArchived: false,
isFork: false,
openIssuesCount: 120,
stargazersCount: 42,
forksCount: 10,
topics: [],
...overrides,
}
}
// ── computeDeathIndex ──────────────────────────────────────────────
test('inactive repo with many issues gets high death index', () => {
const repo = buildRepo({
lastCommitDate: '2018-01-01T00:00:00.000Z',
openIssuesCount: 120,
isArchived: false,
})
const score = computeDeathIndex(repo)
assert.ok(score >= 5)
})
test('archived repo gets high score', () => {
const repo = buildRepo({ isArchived: true })
const score = computeDeathIndex(repo)
assert.ok(score >= 3, `expected >= 3, got ${score}`)
})
test('repo with last commit today returns 0', () => {
const repo = buildRepo({
lastCommitDate: new Date().toISOString(),
openIssuesCount: 0,
stargazersCount: 0,
isArchived: false,
})
const score = computeDeathIndex(repo)
assert.equal(score, 0)
})
test('repo with 1000+ open issues and no recent commits scores very high', () => {
const repo = buildRepo({
lastCommitDate: '2015-01-01T00:00:00.000Z',
openIssuesCount: 1500,
stargazersCount: 500,
isArchived: true,
})
const score = computeDeathIndex(repo)
assert.ok(score >= 9, `expected >= 9, got ${score}`)
})
test('commit 200 days ago with low issues scores modestly', () => {
const d = new Date()
d.setDate(d.getDate() - 200)
const repo = buildRepo({
lastCommitDate: d.toISOString(),
openIssuesCount: 5,
stargazersCount: 10,
isArchived: false,
})
const score = computeDeathIndex(repo)
assert.equal(score, 1)
})
// ── getDeathLabel ──────────────────────────────────────────────────
test('getDeathLabel returns correct labels at boundaries', () => {
assert.equal(getDeathLabel(0), 'too soon to tell')
assert.equal(getDeathLabel(2), 'too soon to tell')
assert.equal(getDeathLabel(3), 'struggling')
assert.equal(getDeathLabel(5), 'struggling')
assert.equal(getDeathLabel(6), 'dying')
assert.equal(getDeathLabel(8), 'dying')
assert.equal(getDeathLabel(9), 'dead dead')
assert.equal(getDeathLabel(10), 'dead dead')
})
// ── determineCauseOfDeath ──────────────────────────────────────────
test('known repo (atom/atom) returns exact known cause', () => {
const repo = buildRepo({ fullName: 'atom/atom' })
const cause = determineCauseOfDeath(repo)
assert.equal(cause, 'GitHub shipped VS Code, then sunset Atom in public')
})
test('fork repo returns "Forked but never understood"', () => {
const d = new Date()
d.setDate(d.getDate() - 100)
const repo = buildRepo({
isFork: true,
isArchived: false,
lastCommitDate: d.toISOString(),
openIssuesCount: 0,
stargazersCount: 0,
description: 'some fork',
})
const cause = determineCauseOfDeath(repo)
assert.equal(cause, 'Forked but never understood')
})
test('no description returns "No README. No hope."', () => {
const d = new Date()
d.setDate(d.getDate() - 100)
const repo = buildRepo({
description: null,
isFork: false,
isArchived: false,
lastCommitDate: d.toISOString(),
openIssuesCount: 0,
stargazersCount: 0,
})
const cause = determineCauseOfDeath(repo)
assert.equal(cause, 'No README. No hope.')
})
test('archived repo returns "Officially declared dead by author"', () => {
const repo = buildRepo({ isArchived: true })
const cause = determineCauseOfDeath(repo)
assert.equal(cause, 'Officially declared dead by author')
})
test('commitmentissues repo returns its own easter egg cause', () => {
const repo = buildRepo({ fullName: 'dotsystemsdevs/commitmentissues' })
const cause = determineCauseOfDeath(repo)
assert.equal(cause, 'Monetized before loved.')
})
// ── generateLastWords ──────────────────────────────────────────────
test('commit message with "fix typo" returns "pls work now"', () => {
const repo = buildRepo({ lastCommitMessage: 'fix typo in header' })
assert.equal(generateLastWords(repo), 'pls work now')
})
test('commit message with "update readme" returns docs quip', () => {
const repo = buildRepo({ lastCommitMessage: 'update readme with badges' })
assert.equal(generateLastWords(repo), 'at least the docs are good')
})
test('commit message with "wip" returns "i\'ll finish this later"', () => {
const repo = buildRepo({
lastCommitMessage: 'wip: refactor auth module',
lastCommitDate: new Date().toISOString(),
})
assert.equal(generateLastWords(repo), "i'll finish this later")
})
test('commit message with "merge" returns merge conflict quip', () => {
const repo = buildRepo({
lastCommitMessage: 'Merge pull request #42',
lastCommitDate: new Date().toISOString(),
})
assert.equal(generateLastWords(repo), 'dying in a merge conflict')
})
test('very long commit message is truncated to 80 chars', () => {
const longMsg = 'a'.repeat(120)
const repo = buildRepo({
lastCommitMessage: longMsg,
lastCommitDate: new Date().toISOString(),
})
const words = generateLastWords(repo)
assert.ok(words.length <= 80, `expected <= 80, got ${words.length}`)
assert.ok(words.endsWith('...'))
})
test('commitmentissues repo returns its own easter egg last words', () => {
const repo = buildRepo({ fullName: 'dotsystemsdevs/commitmentissues' })
assert.equal(generateLastWords(repo), "should've farmed laughs before revenue.")
})
// ── computeAge ─────────────────────────────────────────────────────
test('same month created and last commit returns "less than a month"', () => {
assert.equal(computeAge('2024-03-15T00:00:00Z', '2024-03-28T00:00:00Z'), 'less than a month')
})
test('exactly 1 year returns "1 year"', () => {
assert.equal(computeAge('2023-01-01T00:00:00Z', '2024-01-01T00:00:00Z'), '1 year')
})
test('2 years 3 months returns "2 years, 3 months"', () => {
assert.equal(computeAge('2020-01-01T00:00:00Z', '2022-04-01T00:00:00Z'), '2 years, 3 months')
})
test('11 months returns "11 months"', () => {
assert.equal(computeAge('2023-01-01T00:00:00Z', '2023-12-01T00:00:00Z'), '11 months')
})
test('1 month returns "1 month" (singular)', () => {
assert.equal(computeAge('2024-01-01T00:00:00Z', '2024-02-01T00:00:00Z'), '1 month')
})
// ── formatDate ─────────────────────────────────────────────────────
test('formatDate returns en-GB formatted date', () => {
const result = formatDate('2024-06-15T12:00:00Z')
assert.ok(result.includes('June'), `expected "June" in "${result}"`)
assert.ok(result.includes('2024'), `expected "2024" in "${result}"`)
})
// ── generateLastWords (expanded patterns) ─────────────────────────
test('"initial commit" returns beginning quote', () => {
const repo = buildRepo({ lastCommitMessage: 'initial commit', lastCommitDate: new Date().toISOString() })
assert.equal(generateLastWords(repo), 'it was only ever the beginning')
})
test('"revert" returns nevermind', () => {
const repo = buildRepo({ lastCommitMessage: 'revert: undo migration', lastCommitDate: new Date().toISOString() })
assert.equal(generateLastWords(repo), 'nevermind')
})
test('"hotfix" returns this is fine', () => {
const repo = buildRepo({ lastCommitMessage: 'hotfix: patch auth flow', lastCommitDate: new Date().toISOString() })
assert.equal(generateLastWords(repo), 'this is fine')
})
test('"cleanup" returns tidying quote', () => {
const repo = buildRepo({ lastCommitMessage: 'cleanup unused imports', lastCommitDate: new Date().toISOString() })
assert.equal(generateLastWords(repo), 'just tidying up before i go')
})
test('"bump version" returns release quote', () => {
const repo = buildRepo({ lastCommitMessage: 'bump version to 3.0.0', lastCommitDate: new Date().toISOString() })
assert.equal(generateLastWords(repo), 'one last release into the void')
})
test('"remove" returns burning the evidence', () => {
const repo = buildRepo({ lastCommitMessage: 'remove deprecated API', lastCommitDate: new Date().toISOString() })
assert.equal(generateLastWords(repo), 'burning the evidence')
})
test('"refactor" returns architecture quote', () => {
const repo = buildRepo({ lastCommitMessage: 'refactor auth module', lastCommitDate: new Date().toISOString() })
assert.equal(generateLastWords(repo), 'i swear this time the architecture is right')
})
test('"todo" returns someone else quote', () => {
const repo = buildRepo({ lastCommitMessage: 'add todo for error handling', lastCommitDate: new Date().toISOString() })
assert.equal(generateLastWords(repo), 'someone else will handle it')
})
test('"dependencies" returns dependency hell', () => {
const repo = buildRepo({ lastCommitMessage: 'update dependencies', lastCommitDate: new Date().toISOString() })
assert.equal(generateLastWords(repo), 'trapped in dependency hell')
})
// ── language-specific causes ───────────────────────────────────────
test('Ruby repo idle >365 days → Gemfile quip', () => {
const repo = buildRepo({
language: 'Ruby',
lastCommitDate: '2023-01-01T00:00:00.000Z',
isArchived: false,
isFork: false,
openIssuesCount: 2,
stargazersCount: 5,
forksCount: 0,
description: 'a gem that time forgot',
})
const cause = determineCauseOfDeath(repo)
assert.equal(cause, 'Gemfile.lock never unlocked')
})
test('Perl repo returns Perl-specific cause', () => {
const repo = buildRepo({
language: 'Perl',
lastCommitDate: '2024-01-01T00:00:00.000Z',
isArchived: false,
isFork: false,
openIssuesCount: 2,
stargazersCount: 5,
forksCount: 0,
description: 'a Perl tool',
})
const cause = determineCauseOfDeath(repo)
assert.equal(cause, 'Nobody could read it, including the author')
})
test('Objective-C repo idle >365 days returns Swift quip', () => {
const repo = buildRepo({
language: 'Objective-C',
lastCommitDate: '2022-01-01T00:00:00.000Z',
isArchived: false,
isFork: false,
openIssuesCount: 2,
stargazersCount: 5,
forksCount: 0,
description: 'an old iOS lib',
})
const cause = determineCauseOfDeath(repo)
assert.equal(cause, 'Swift happened')
})