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:
@@ -51,4 +51,14 @@ import Testing
|
||||
#expect(launch.workingDirectory == "/p")
|
||||
#expect(TerminalLaunch.make(kind: .shell, config: .defaults, projectRoot: nil, environment: [:]).arguments.isEmpty)
|
||||
}
|
||||
|
||||
@Test func theTailRunsTailDirectlyOnTheProjectRelativePathInTheProject() {
|
||||
let launch = TerminalLaunch.tail(path: "storage/logs/laravel.log", projectRoot: "/p",
|
||||
environment: ["SHELL": "/bin/zsh", "TERM_PROGRAM": "Apple_Terminal"])
|
||||
#expect(launch.executable == "/usr/bin/tail")
|
||||
#expect(launch.arguments == ["-f", "storage/logs/laravel.log"])
|
||||
#expect(launch.workingDirectory == "/p")
|
||||
#expect(launch.environment["TERM_PROGRAM"] == "Helder")
|
||||
#expect(TerminalLaunch.tail(path: "a.log", projectRoot: nil, environment: ["HOME": "/Users/me"]).workingDirectory == "/Users/me")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,11 @@ import Testing
|
||||
#expect(!labels(.terminal(.shell, hasSelection: false)).contains("Read aloud selection"))
|
||||
}
|
||||
|
||||
@Test func theTailPaneOffersCopyButNoPasteOrWaitWhat() {
|
||||
#expect(labels(.terminal(.tail, hasSelection: true)) == ["Copy", "Read aloud selection", "Plak"])
|
||||
#expect(ContextActions.entries(for: .terminal(.tail, hasSelection: false)).isEmpty)
|
||||
}
|
||||
|
||||
@Test func theMenuHasNoHeader() {
|
||||
#expect(ContextActions.header(for: .terminal(.agent, hasSelection: false), projectName: "app").isEmpty)
|
||||
#expect(ContextActions.header(for: .directory(path: "src"), projectName: "app").isEmpty)
|
||||
@@ -143,16 +148,6 @@ import Testing
|
||||
#expect(ContextAction.openFile("src/a.php").isEmphasized)
|
||||
}
|
||||
|
||||
@Test func theCommitMenuOffersCommitAndABoldCommitAndPush() {
|
||||
#expect(ContextActions.header(for: .commitMenu, projectName: "app") == "")
|
||||
#expect(ContextActions.entries(for: .commitMenu) == [
|
||||
.action(.commit(andPush: false), label: "Commit"),
|
||||
.action(.commit(andPush: true), label: "Commit and push"),
|
||||
])
|
||||
#expect(ContextAction.commit(andPush: true).isEmphasized)
|
||||
#expect(!ContextAction.commit(andPush: false).isEmphasized)
|
||||
}
|
||||
|
||||
@Test func aSelectionCanBeReadAloudAfterCopyReference() {
|
||||
let reference = AgentReference(path: "src/a.php", startLine: 3, endLine: 4)
|
||||
#expect(ContextActions.entries(for: .editor(reference: reference, code: "$a = 1;", showDiffLine: 3)) == [
|
||||
@@ -204,3 +199,59 @@ import Testing
|
||||
#expect(plak(.editor(reference: reference, code: "")).isEmpty)
|
||||
}
|
||||
}
|
||||
|
||||
@Suite struct BranchContextMenuTests {
|
||||
@Test func aCleanTreeOffersTheMergeIntoTheCurrentBranch() {
|
||||
#expect(ContextActions.entries(for: .branch(name: "feature", remote: false, current: "dev", isDirty: false)) == [
|
||||
.action(.mergeBranch("feature"), label: "Merge into dev"),
|
||||
])
|
||||
#expect(ContextActions.entries(for: .branch(name: "origin/feature", remote: true, current: "dev", isDirty: false)) == [
|
||||
.action(.mergeBranch("origin/feature"), label: "Merge into dev"),
|
||||
])
|
||||
}
|
||||
|
||||
@Test func aDirtyTreeShowsTheMergeDisabled() {
|
||||
let entries = ContextActions.entries(for: .branch(name: "feature", remote: false, current: "dev", isDirty: true))
|
||||
#expect(entries == [
|
||||
.disabled(.mergeBranch("feature"), label: "Merge into dev", hint: "Commit or discard your changes first"),
|
||||
])
|
||||
#expect(!entries[0].isSelectable)
|
||||
}
|
||||
|
||||
@Test func theCurrentBranchHasNoMenuButItsUpstreamHas() {
|
||||
#expect(ContextActions.entries(for: .branch(name: "dev", remote: false, current: "dev", isDirty: false)).isEmpty)
|
||||
#expect(ContextActions.entries(for: .branch(name: "origin/dev", remote: true, current: "dev", isDirty: false)).count == 1)
|
||||
}
|
||||
|
||||
@Test func theHeaderIsTheBranchName() {
|
||||
#expect(ContextActions.header(for: .branch(name: "origin/feature", remote: true, current: "dev", isDirty: false),
|
||||
projectName: "app") == "origin/feature")
|
||||
}
|
||||
}
|
||||
|
||||
@Suite struct TailLogContextMenuTests {
|
||||
private func hasTailLog(_ target: ContextTarget) -> Bool {
|
||||
ContextActions.entries(for: target).contains { entry in
|
||||
guard case .action(.tailLog, _) = entry else { return false }
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@Test func aLogFileOffersTailLogInItsOwnGroupAfterTheCopyItems() {
|
||||
let entries = ContextActions.entries(for: .file(path: "storage/logs/laravel.log"))
|
||||
#expect(Array(entries[4...6]) == [
|
||||
.separator,
|
||||
.action(.tailLog("storage/logs/laravel.log"), label: "Tail log"),
|
||||
.separator,
|
||||
])
|
||||
#expect(hasTailLog(.file(path: "LOGS/Error.LOG")))
|
||||
}
|
||||
|
||||
@Test func otherFilesAndFoldersDoNot() {
|
||||
#expect(!hasTailLog(.file(path: "src/app.php")))
|
||||
#expect(!hasTailLog(.file(path: "notes.md")))
|
||||
#expect(!hasTailLog(.file(path: "catalog")))
|
||||
#expect(!hasTailLog(.directory(path: "storage/logs.log")))
|
||||
#expect(!hasTailLog(.gitRow(path: "laravel.log", isDeleted: false)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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