adds claude-generated commit messages and a recent commits panel to the git view - adds log tailing in the explorer, branch merging and a clean up button
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
import Foundation
|
||||
import HelderCore
|
||||
import Testing
|
||||
|
||||
@Suite struct CommitMessagePromptTests {
|
||||
private let diff = StagedDiff(stat: " src/a.php | 2 +-\n 1 file changed\n", patch: "diff --git a/src/a.php b/src/a.php\n-old\n+new\n")
|
||||
|
||||
@Test("the prompt holds the rules, the three examples verbatim, the stat and the diff")
|
||||
func promptContents() {
|
||||
let prompt = CommitMessagePrompt.make(diff)
|
||||
#expect(prompt.contains("Write ONE git commit message"))
|
||||
#expect(prompt.contains("\" - \""))
|
||||
#expect(prompt.contains("Adds a new button on the header to navigate to profile"))
|
||||
#expect(prompt.contains("Fixed security issue that made it possible to hack a file upload"))
|
||||
#expect(prompt.contains("Makes sure the register form does not accept R&B fans - Enforces password rules on login form (two things changed)"))
|
||||
#expect(prompt.contains(" src/a.php | 2 +-\n 1 file changed"))
|
||||
#expect(prompt.hasSuffix("+new"))
|
||||
#expect(!prompt.contains("is cut"))
|
||||
}
|
||||
|
||||
@Test("a long diff is cut at the limit and the prompt says so; the stat stays whole")
|
||||
func cutDiff() {
|
||||
let stat = (0..<50).map { " file\($0).txt | 1 +" }.joined(separator: "\n")
|
||||
let long = StagedDiff(stat: stat, patch: String(repeating: "a", count: 90) + "TAIL")
|
||||
let prompt = CommitMessagePrompt.make(long, limit: 90)
|
||||
#expect(prompt.contains("cut after 90 characters"))
|
||||
#expect(prompt.contains(stat))
|
||||
#expect(prompt.contains(String(repeating: "a", count: 90)))
|
||||
#expect(!prompt.contains("TAIL"))
|
||||
}
|
||||
|
||||
@Test("a diff exactly at the limit is not cut")
|
||||
func diffAtLimit() {
|
||||
let prompt = CommitMessagePrompt.make(StagedDiff(stat: "s", patch: String(repeating: "b", count: 10)), limit: 10)
|
||||
#expect(!prompt.contains("is cut"))
|
||||
}
|
||||
|
||||
@Test("cleaning takes the first non-empty line and trims it")
|
||||
func firstLine() {
|
||||
#expect(CommitMessagePrompt.clean("\n\n Adds a button \nSecond line\n") == "Adds a button")
|
||||
}
|
||||
|
||||
@Test("cleaning strips surrounding quotes and backticks, nested too")
|
||||
func wrappers() {
|
||||
#expect(CommitMessagePrompt.clean("\"Fixed the parser\"") == "Fixed the parser")
|
||||
#expect(CommitMessagePrompt.clean("`'Fixed the parser'`") == "Fixed the parser")
|
||||
#expect(CommitMessagePrompt.clean("“Fixed the parser”") == "Fixed the parser")
|
||||
#expect(CommitMessagePrompt.clean("Fixed the \"parser\" bug") == "Fixed the \"parser\" bug")
|
||||
}
|
||||
|
||||
@Test("cleaning skips Markdown fence lines")
|
||||
func fences() {
|
||||
#expect(CommitMessagePrompt.clean("```text\nAdds a button\n```") == "Adds a button")
|
||||
}
|
||||
|
||||
@Test("cleaning collapses runs of whitespace")
|
||||
func whitespace() {
|
||||
#expect(CommitMessagePrompt.clean("Adds\ta button") == "Adds a button")
|
||||
}
|
||||
|
||||
@Test("nothing usable cleans to nil")
|
||||
func empty() {
|
||||
#expect(CommitMessagePrompt.clean("") == nil)
|
||||
#expect(CommitMessagePrompt.clean(" \n\t\n") == nil)
|
||||
#expect(CommitMessagePrompt.clean("\"\"") == nil)
|
||||
}
|
||||
|
||||
@Test("an empty patch is an empty diff")
|
||||
func isEmpty() {
|
||||
#expect(StagedDiff(stat: "", patch: " \n").isEmpty)
|
||||
#expect(!diff.isEmpty)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
import Foundation
|
||||
import HelderCore
|
||||
import Testing
|
||||
|
||||
@Suite struct GitCommitLogTests {
|
||||
@Test("each record splits into hash, subject, author and date, newest first")
|
||||
func commits() {
|
||||
let raw = "a1b2c3d\0fix the parser\0Jonathan van Rij\01767225600\u{1e}\n0123abc\0first\0Zoë\01700000000\u{1e}\n"
|
||||
#expect(GitCommitLogParsing.commits(raw) == [
|
||||
GitCommitSummary(hash: "a1b2c3d", subject: "fix the parser", author: "Jonathan van Rij",
|
||||
date: Date(timeIntervalSince1970: 1_767_225_600)),
|
||||
GitCommitSummary(hash: "0123abc", subject: "first", author: "Zoë", date: Date(timeIntervalSince1970: 1_700_000_000)),
|
||||
])
|
||||
}
|
||||
|
||||
@Test("a subject with quotes, tabs, unicode and separators stays whole")
|
||||
func oddSubject() throws {
|
||||
let subject = "feat: \"quotes\" · tab\there | pipe %s %x00 — émoji 🚀"
|
||||
let commit = try #require(GitCommitLogParsing.commits("0123abc\0\(subject)\0Zoë\01700000000\u{1e}\n").first)
|
||||
#expect(commit.subject == subject)
|
||||
#expect(commit.author == "Zoë")
|
||||
}
|
||||
|
||||
@Test("an empty subject still parses")
|
||||
func emptySubject() {
|
||||
#expect(GitCommitLogParsing.commits("0123abc\0\0Zoë\01700000000\u{1e}\n").first?.subject == "")
|
||||
}
|
||||
|
||||
@Test("a malformed record is skipped, the rest stays")
|
||||
func malformedRecord() {
|
||||
let raw = "abc\0subject\0author\0soon\u{1e}\n0123abc\0ok\0Zoë\01700000000\u{1e}\n"
|
||||
#expect(GitCommitLogParsing.commits(raw).map(\.hash) == ["0123abc"])
|
||||
}
|
||||
|
||||
@Test("an empty repository prints nothing, which is no commits", arguments: ["", "\n", "garbage", "\u{1e}\n"])
|
||||
func noCommits(raw: String) {
|
||||
#expect(GitCommitLogParsing.commits(raw).isEmpty)
|
||||
}
|
||||
|
||||
@Test("relative time steps from seconds to years", arguments: [
|
||||
(0, "just now"),
|
||||
(59, "just now"),
|
||||
(60, "1 min ago"),
|
||||
(3_540, "59 min ago"),
|
||||
(10_800, "3 h ago"),
|
||||
(86_400, "1 d ago"),
|
||||
(518_400, "6 d ago"),
|
||||
(1_209_600, "2 w ago"),
|
||||
(5_184_000, "2 mo ago"),
|
||||
(69_120_000, "2 y ago"),
|
||||
(-120, "just now"),
|
||||
] as [(TimeInterval, String)])
|
||||
func relativeTime(age: TimeInterval, text: String) {
|
||||
let now = Date(timeIntervalSince1970: 1_800_000_000)
|
||||
#expect(RelativeTime.text(now.addingTimeInterval(-age), now: now) == text)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user