-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinputfile.test.ts
More file actions
270 lines (241 loc) Β· 7.76 KB
/
Copy pathinputfile.test.ts
File metadata and controls
270 lines (241 loc) Β· 7.76 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
import { describe, it, expect, beforeAll, afterAll } from "bun:test";
import { parseIssueFile } from "../src/inputfile.ts";
import { writeFileSync, mkdirSync, rmSync, existsSync } from "node:fs";
import { join } from "node:path";
const TMP = join(import.meta.dir, "__tmp__");
beforeAll(() => {
mkdirSync(TMP, { recursive: true });
});
afterAll(() => {
if (existsSync(TMP)) rmSync(TMP, { recursive: true });
});
function write(name: string, content: string): string {
const p = join(TMP, name);
writeFileSync(p, content);
return p;
}
// βββ Markdown tests βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
describe("parseIssueFile β markdown with frontmatter", () => {
it("parses all recognized frontmatter fields", () => {
const f = write(
"full.md",
`---
title: My Issue
labels: bug, feature
assignee: johndoe
weight: 5
estimate: 2h
start: 2026-07-01
due: 2026-07-31
status: In progress
confidential: true
type: Task
---
Body content here.
`
);
const result = parseIssueFile(f);
expect(result.title).toBe("My Issue");
expect(result.labels).toEqual(["bug", "feature"]);
expect(result.assignees).toEqual(["johndoe"]);
expect(result.weight).toBe(5);
expect(result.estimate).toBe("2h");
expect(result.start).toBe("2026-07-01");
expect(result.due).toBe("2026-07-31");
expect(result.status).toBe("In progress");
expect(result.confidential).toBe(true);
expect(result.type).toBe("Task");
expect(result.description).toBe("Body content here.");
});
it("uses # H1 as title when no frontmatter title", () => {
const f = write(
"h1title.md",
`---
labels: bug
---
# This Is The Title
Some description content.
`
);
const result = parseIssueFile(f);
expect(result.title).toBe("This Is The Title");
expect(result.labels).toEqual(["bug"]);
expect(result.description).toBe("Some description content.");
});
it("handles inline array labels in frontmatter", () => {
const f = write(
"inline-array.md",
`---
title: Test
labels: [alpha, beta, gamma]
---
desc
`
);
const result = parseIssueFile(f);
expect(result.labels).toEqual(["alpha", "beta", "gamma"]);
});
it("handles quoted string values", () => {
const f = write(
"quoted.md",
`---
title: "Quoted Title"
status: 'To do'
---
`
);
const result = parseIssueFile(f);
expect(result.title).toBe("Quoted Title");
expect(result.status).toBe("To do");
});
it("returns description as undefined when body is empty", () => {
const f = write(
"empty-body.md",
`---
title: No Body
---
`
);
const result = parseIssueFile(f);
expect(result.title).toBe("No Body");
expect(result.description).toBeUndefined();
});
it("no frontmatter β uses H1 as title", () => {
const f = write(
"no-fm.md",
`# Simple Title
Just a description.
`
);
const result = parseIssueFile(f);
expect(result.title).toBe("Simple Title");
expect(result.description).toBe("Just a description.");
});
});
// βββ GitLab issue-template edge case βββββββββββββββββββββββββββββββββββββββββ
describe("parseIssueFile β GitLab issue-template frontmatter (edge case)", () => {
it("treats unrecognized frontmatter as body (GitLab template metadata)", () => {
// This simulates a GitLab issue template that starts with ---name:...\n---
// which should NOT be treated as glw frontmatter
const f = write(
"gitlab-template.md",
`---
name: Bug Report
about: Report a reproducible bug
title: "[BUG] "
labels: bug
assignees: ""
---
## Describe the bug
A clear description.
`
);
// "name", "about" are not recognized keys.
// BUT "title" and "labels" ARE recognized β this block WILL be parsed as glw frontmatter.
// That's correct behavior per spec: "if it contains at least one recognized key"
const result = parseIssueFile(f);
expect(result.title).toBe("[BUG] ");
expect(result.labels).toEqual(["bug"]);
});
it("pure template metadata with NO recognized keys β full content becomes body, H1 still extracted", () => {
const f = write(
"pure-template.md",
`---
name: Feature Request
about: Suggest an idea
category: enhancement
---
# Feature: Something
Please describe the feature.
`
);
// "name", "about", "category" are not recognized β whole content treated as body
// H1 extraction then applies to that full content (including ---block)
const result = parseIssueFile(f);
// H1 "Feature: Something" is found inside the full-content body
expect(result.title).toBe("Feature: Something");
// description should not include the H1 heading itself
expect(result.description).toContain("Please describe the feature.");
// The --- block is part of the body content fed to H1 extraction, not a separate field
expect(result.labels).toBeUndefined();
});
it("pure template with H1 after: title extracted from H1 in body", () => {
const f = write(
"pure-template-h1.md",
`---
name: Feature Request
about: Suggest an idea
---
# My Feature Title
Feature body here.
`
);
// No recognized keys β whole content is body β H1 extraction happens on full content
const result = parseIssueFile(f);
// The full content passed to body extraction includes the ---block + H1
// H1 "My Feature Title" should be found
expect(result.title).toBe("My Feature Title");
expect(result.description).toContain("Feature body here.");
});
});
// βββ .txt tests βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
describe("parseIssueFile β .txt files", () => {
it("uses first line as title", () => {
const f = write("simple.txt", `First Line Is Title\n\nRest of the content.`);
const result = parseIssueFile(f);
expect(result.title).toBe("First Line Is Title");
expect(result.description).toBe("Rest of the content.");
});
it("parses txt with frontmatter", () => {
const f = write(
"fm.txt",
`---
title: Txt Issue
weight: 3
---
Description text.
`
);
const result = parseIssueFile(f);
expect(result.title).toBe("Txt Issue");
expect(result.weight).toBe(3);
expect(result.description).toBe("Description text.");
});
});
// βββ JSON tests βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
describe("parseIssueFile β JSON files", () => {
it("parses all fields", () => {
const f = write(
"issue.json",
JSON.stringify({
title: "JSON Issue",
description: "A description",
labels: ["a", "b"],
assignees: ["alice"],
weight: 8,
estimate: "3h",
start: "2026-07-01",
due: "2026-07-31",
status: "To do",
confidential: false,
type: "Issue",
})
);
const result = parseIssueFile(f);
expect(result.title).toBe("JSON Issue");
expect(result.description).toBe("A description");
expect(result.labels).toEqual(["a", "b"]);
expect(result.weight).toBe(8);
expect(result.estimate).toBe("3h");
expect(result.confidential).toBe(false);
expect(result.type).toBe("Issue");
});
it("accepts 'body' as alias for 'description'", () => {
const f = write(
"body-alias.json",
JSON.stringify({ title: "T", body: "Body text" })
);
const result = parseIssueFile(f);
expect(result.description).toBe("Body text");
});
});