adds nice git interface

This commit is contained in:
2026-10-30 13:21:45 +01:00
parent b9c03a7637
commit caec81e762
107 changed files with 6466 additions and 3992 deletions
@@ -26,26 +26,26 @@ private struct MemorySession: SessionStoring {
#expect(layout.widths.explorer == 520)
}
@Test func sourceControlDragsStayInsideTheirRange() {
@Test func explorerDragsStayInsideTheirRange() {
let layout = LayoutStore(session: MemorySession())
layout.dragSourceControl(by: -1000)
#expect(layout.widths.sourceControl == 160)
layout.dragSourceControl(by: 5000)
#expect(layout.widths.sourceControl == 460)
layout.dragExplorer(by: -1000)
#expect(layout.widths.explorer == 160)
layout.dragExplorer(by: 5000)
#expect(layout.widths.explorer == 520)
}
@Test func theAgentColumnNeverSqueezesTheEditorBelowItsMinimum() {
let layout = LayoutStore(session: MemorySession())
layout.windowResized(width: 1760)
layout.dragAgent(by: -5000)
let editor = 1760 - 3 - layout.widths.sourceControl - layout.widths.explorer - layout.widths.agent
let editor = 1760 - 2 - layout.widths.explorer - layout.widths.agent
#expect(editor >= ColumnLayout.minEditorWidth)
}
@Test func roomyWindowsUseTheDesignProportions() {
let layout = LayoutStore(session: MemorySession())
layout.windowResized(width: 1760)
#expect(layout.widths == ColumnWidths(sourceControl: 236, explorer: 289, agent: 480))
#expect(layout.widths == ColumnWidths(explorer: 289, agent: 480))
}
@Test func focusChangesTheFluidWidthsOnlyBelow1600() {
@@ -75,19 +75,44 @@ private struct MemorySession: SessionStoring {
layout.windowResized(width: 1760)
layout.dragExplorer(by: 0)
layout.windowResized(width: 1100)
let total = layout.widths.sourceControl + layout.widths.explorer + layout.widths.agent
#expect(total <= 1100 - 3 - ColumnLayout.minEditorWidth)
layout.windowResized(width: 900)
let total = layout.widths.explorer + layout.widths.agent
#expect(total <= 900 - 2 - ColumnLayout.minEditorWidth)
}
@Test func hidingGitDropsItsFocus() {
@Test func hidingTheExplorerDropsItsFocus() {
let layout = LayoutStore(session: MemorySession())
layout.focus(.sourceControl)
layout.togglePane(.sourceControl)
layout.focus(.explorer)
layout.togglePane(.explorer)
#expect(layout.activePanel == nil)
layout.focus(.sourceControl)
layout.focus(.explorer)
#expect(layout.activePanel == nil)
}
@Test func theGitViewOpensClosesAndToggles() {
let layout = LayoutStore(session: MemorySession())
#expect(!layout.isGitViewOpen)
layout.openGitView()
#expect(layout.isGitViewOpen)
layout.closeGitView()
#expect(!layout.isGitViewOpen)
layout.toggleGitView()
#expect(layout.isGitViewOpen)
layout.toggleGitView()
#expect(!layout.isGitViewOpen)
}
@Test func theGitViewIsNeitherSavedNorKeptAcrossAProjectSwitch() {
let store = FakeLayouts()
let layout = LayoutStore(session: MemorySession(), persistence: store)
layout.restore(root: "/p")
layout.openGitView()
#expect(store.saved["/p"] == nil)
layout.restore(root: "/q")
#expect(!layout.isGitViewOpen)
#expect(layout.visibility == .all)
}
@Test func aProjectsColumnsSurviveARestart() {
let store = FakeLayouts()
let first = LayoutStore(session: MemorySession(), persistence: store)
@@ -95,13 +120,13 @@ private struct MemorySession: SessionStoring {
first.windowResized(width: 1760)
first.dragExplorer(by: 40)
first.endDrag()
first.togglePane(.sourceControl)
first.togglePane(.terminal)
let second = LayoutStore(session: MemorySession(), persistence: store)
second.windowResized(width: 1760)
second.restore(root: "/p")
#expect(!second.fluid)
#expect(!second.isVisible(.sourceControl))
#expect(!second.isVisible(.terminal))
#expect(second.widths.explorer == first.widths.explorer)
#expect(second.widths.agent == first.widths.agent)
}
@@ -110,11 +135,11 @@ private struct MemorySession: SessionStoring {
let store = FakeLayouts()
let layout = LayoutStore(session: MemorySession(), persistence: store)
layout.restore(root: "/a")
layout.togglePane(.sourceControl)
layout.togglePane(.explorer)
layout.restore(root: "/b")
#expect(layout.isVisible(.sourceControl))
#expect(layout.isVisible(.explorer))
layout.restore(root: "/a")
#expect(!layout.isVisible(.sourceControl))
#expect(!layout.isVisible(.explorer))
}
@Test func dragsSaveOnlyWhenTheyEnd() {
@@ -140,22 +165,22 @@ private struct MemorySession: SessionStoring {
@Test func aWindowXMapsToTheColumnUnderIt() {
let layout = LayoutStore(session: MemorySession())
layout.windowResized(width: 1760)
#expect(layout.panel(atX: 10) == .sourceControl)
#expect(layout.panel(atX: 300) == .explorer)
#expect(layout.panel(atX: 10) == .explorer)
#expect(layout.panel(atX: 900) == .editor)
#expect(layout.panel(atX: 1700) == .terminal)
#expect(layout.panel(atX: 236, splitterMargin: 4) == nil)
layout.togglePane(.sourceControl)
#expect(layout.panel(atX: 10) == .explorer)
#expect(layout.panel(atX: 289, splitterMargin: 4) == nil)
layout.togglePane(.explorer)
#expect(layout.panel(atX: 10) == .editor)
}
@Test func neighbourColumnsClampAtTheEdgesAndSkipAHiddenGitColumn() {
@Test func neighbourColumnsClampAtTheEdgesAndSkipAHiddenColumn() {
let layout = LayoutStore(session: MemorySession())
#expect(layout.neighbour(of: nil, step: 1) == .terminal)
#expect(layout.neighbour(of: .terminal, step: 1) == .terminal)
#expect(layout.neighbour(of: .explorer, step: -1) == .sourceControl)
layout.togglePane(.sourceControl)
#expect(layout.neighbour(of: .explorer, step: -1) == .explorer)
#expect(layout.neighbour(of: .editor, step: -1) == .explorer)
layout.togglePane(.explorer)
#expect(layout.neighbour(of: .editor, step: -1) == .editor)
}
@Test func everyPaneStartsShownAndTogglesOnItsOwn() {
@@ -163,8 +188,8 @@ private struct MemorySession: SessionStoring {
#expect(layout.visibility == .all)
layout.togglePane(.explorer)
layout.togglePane(.terminal)
#expect(layout.visibility == ColumnVisibility(sourceControl: true, explorer: false, editor: true, agent: false))
#expect(layout.columns == [.sourceControl, .editor])
#expect(layout.visibility == ColumnVisibility(explorer: false, editor: true, agent: false))
#expect(layout.columns == [.editor])
layout.togglePane(.terminal)
#expect(layout.isVisible(.terminal))
}
@@ -181,7 +206,7 @@ private struct MemorySession: SessionStoring {
#expect(layout.activePanel == .editor)
}
@Test func allFourPaneFlagsSurviveARestart() {
@Test func allThreePaneFlagsSurviveARestart() {
let store = FakeLayouts()
let first = LayoutStore(session: MemorySession(), persistence: store)
first.restore(root: "/p")
@@ -191,20 +216,43 @@ private struct MemorySession: SessionStoring {
let second = LayoutStore(session: MemorySession(), persistence: store)
second.restore(root: "/p")
#expect(second.visibility == ColumnVisibility(sourceControl: true, explorer: false, editor: false, agent: false))
#expect(second.visibility == ColumnVisibility(explorer: false, editor: false, agent: false))
}
@Test func anOlderSnapshotWithOnlyTheGitFlagStillLoads() throws {
let json = #"{"sourceControlWidth":240,"explorerWidth":300,"agentWidth":500,"fluid":false,"gitVisible":false}"#
let snapshot = try JSONDecoder().decode(ColumnLayoutSnapshot.self, from: Data(json.utf8))
#expect(snapshot.visibility == ColumnVisibility(sourceControl: false, explorer: true, editor: true, agent: true))
#expect(snapshot.visibility == .all)
#expect(snapshot.explorerWidth == 300)
#expect(snapshot.agentWidth == 500)
#expect(!snapshot.fluid)
}
@Test func aSnapshotFromTheGitColumnDaysKeepsItsPaneFlags() throws {
let json = #"{"sourceControlWidth":240,"explorerWidth":300,"agentWidth":500,"fluid":true,"gitVisible":true,"#
+ #""explorerVisible":false,"fileVisible":true,"claudeVisible":false}"#
let snapshot = try JSONDecoder().decode(ColumnLayoutSnapshot.self, from: Data(json.utf8))
#expect(snapshot.visibility == ColumnVisibility(explorer: false, editor: true, agent: false))
#expect(snapshot.fluid)
}
@Test func aSnapshotWithoutTheGitKeysLoads() throws {
let json = #"{"explorerWidth":300,"agentWidth":500,"fluid":false,"explorerVisible":true,"fileVisible":false,"claudeVisible":true}"#
let snapshot = try JSONDecoder().decode(ColumnLayoutSnapshot.self, from: Data(json.utf8))
#expect(snapshot.visibility == ColumnVisibility(explorer: true, editor: false, agent: true))
#expect(snapshot.explorerWidth == 300)
}
@Test func aSavedSnapshotNoLongerWritesTheGitKeys() throws {
let data = try JSONEncoder().encode(ColumnLayoutSnapshot(explorerWidth: 288, agentWidth: 480, fluid: true))
let keys = try #require(try JSONSerialization.jsonObject(with: data) as? [String: Any]).keys
#expect(!keys.contains("sourceControlWidth"))
#expect(!keys.contains("gitVisible"))
}
@Test func aSnapshotRoundTripsItsPaneFlags() throws {
let visibility = ColumnVisibility(sourceControl: true, explorer: false, editor: true, agent: false)
let snapshot = ColumnLayoutSnapshot(sourceControlWidth: 236, explorerWidth: 288, agentWidth: 480, fluid: true, visibility: visibility)
let visibility = ColumnVisibility(explorer: false, editor: true, agent: false)
let snapshot = ColumnLayoutSnapshot(explorerWidth: 288, agentWidth: 480, fluid: true, visibility: visibility)
let decoded = try JSONDecoder().decode(ColumnLayoutSnapshot.self, from: JSONEncoder().encode(snapshot))
#expect(decoded == snapshot)
#expect(decoded.visibility == visibility)
@@ -214,9 +262,9 @@ private struct MemorySession: SessionStoring {
let layout = LayoutStore(session: MemorySession())
layout.windowResized(width: 1760)
layout.togglePane(.editor)
#expect(layout.columns == [.sourceControl, .explorer, .terminal])
#expect(layout.columns == [.explorer, .terminal])
#expect(layout.span(of: .editor) == nil)
let agentStart = layout.widths.sourceControl + 1 + layout.widths.explorer + 1
let agentStart = layout.widths.explorer + 1
#expect(layout.span(of: .terminal) == agentStart...1760)
#expect(layout.panel(atX: 1000) == .terminal)
}
@@ -225,7 +273,6 @@ private struct MemorySession: SessionStoring {
let layout = LayoutStore(session: MemorySession())
layout.windowResized(width: 1760)
layout.togglePane(.terminal)
layout.togglePane(.sourceControl)
#expect(layout.span(of: .explorer) == 0...layout.widths.explorer)
#expect(layout.span(of: .editor) == (layout.widths.explorer + 1)...1760)
#expect(layout.span(of: .terminal) == nil)
@@ -244,9 +291,8 @@ private struct MemorySession: SessionStoring {
@Test func neighboursSkipEveryHiddenPane() {
let layout = LayoutStore(session: MemorySession())
layout.togglePane(.editor)
layout.togglePane(.explorer)
#expect(layout.neighbour(of: .sourceControl, step: 1) == .terminal)
#expect(layout.neighbour(of: .terminal, step: -1) == .sourceControl)
#expect(layout.neighbour(of: .explorer, step: 1) == .terminal)
#expect(layout.neighbour(of: .terminal, step: -1) == .explorer)
}
@Test func theAgentMayGrowIntoTheRoomAHiddenExplorerLeaves() {
@@ -254,6 +300,6 @@ private struct MemorySession: SessionStoring {
layout.windowResized(width: 1760)
layout.togglePane(.explorer)
layout.dragAgent(by: -5000)
#expect(layout.widths.agent == 1760 - 2 - layout.widths.sourceControl - ColumnLayout.minEditorWidth)
#expect(layout.widths.agent == 1760 - 1 - ColumnLayout.minEditorWidth)
}
}
@@ -56,7 +56,7 @@ import Testing
await harness.model.settle()
let oldEditor = harness.model.editor
let gate = harness.files.holdNextRead("a.php")
harness.model.perform(.context(.discard("a.php")))
harness.model.perform(.context(.gitDiscard(["a.php"])))
harness.model.perform(.confirmPending)
#expect(await eventually { gate.isWaiting })
harness.model.perform(.openRecentProject("/fake/other"))
@@ -61,13 +61,13 @@ import Testing
await harness.start()
var changed = HelderConfig.defaults
changed.ai.command = "other-agent"
changed.git.confirmStage = true
changed.git.confirmDiscard = false
changed.editor.tabSize = 8
harness.config.set(changed)
await harness.model.handle(.config)
#expect(harness.model.config.ai.command == "other-agent")
#expect(harness.model.terminal.config.ai.command == "other-agent")
#expect(harness.model.sourceControl?.config.confirmStage == true)
#expect(harness.model.sourceControl?.config.confirmDiscard == false)
#expect(harness.model.editor?.editorConfig.tabSize == 8)
}
@@ -204,11 +204,11 @@ import Testing
#expect(harness.files.treeLoads == 2)
}
@Test func focusingSourceControlRefreshesGitOnce() async {
@Test func openingTheGitViewRefreshesGitOnce() async {
let harness = WorkspaceHarness()
await harness.start()
harness.model.pointerFocused(.sourceControl)
harness.model.pointerFocused(.sourceControl)
harness.model.perform(.toggleGit)
harness.model.perform(.focusCommitMessage)
await harness.model.settle()
#expect(harness.git.loads == 2)
}
@@ -277,36 +277,29 @@ import Testing
}
@Test func discardAsksUnderTheConfigThenReloadsTheFile() async {
let harness = WorkspaceHarness(contents: ["a.php": "edited"])
let harness = WorkspaceHarness(git: snapshot([("a.php", .modified, false)]), contents: ["a.php": "edited"])
await harness.start()
harness.model.open("a.php")
await harness.model.settle()
await harness.perform(.context(.discard("a.php")))
await harness.perform(.context(.gitDiscard(["a.php"])))
guard case let .confirm(request) = harness.model.overlay.current else {
Issue.record("expected a confirm overlay")
return
}
#expect(request.confirmLabel == "Discard")
#expect(harness.git.executed.isEmpty)
harness.files.set("a.php", "committed")
await harness.perform(.confirmPending)
#expect(harness.git.discarded == [["a.php"]])
#expect(harness.git.executed == [["restore", "--", "a.php"]])
#expect(harness.model.editor?.text(for: "a.php") == "committed")
#expect(harness.toastTitles == ["Discarded changes"])
}
@Test func stagingRunsStraightAwayUnlessTheConfigAsks() async {
let harness = WorkspaceHarness()
@Test func stagingRunsGitStraightAway() async {
let harness = WorkspaceHarness(git: snapshot([("a.php", .modified, false), ("b.php", .modified, false)]))
await harness.start()
await harness.perform(.context(.stage("a.php")))
#expect(harness.git.staged == [["a.php"]])
var config = HelderConfig.defaults
config.git.confirmStage = true
let asking = WorkspaceHarness(config: config)
await asking.start()
await asking.perform(.context(.stage("a.php")))
#expect(asking.git.staged.isEmpty)
#expect(asking.model.overlay.current != .none)
await harness.perform(.stage(["a.php"]))
#expect(harness.git.executed == [["add", "--", "a.php"]])
#expect(harness.model.overlay.current == .none)
}
@Test func revealInFinderResolvesAgainstTheProject() async {
@@ -354,17 +347,32 @@ import Testing
await harness.start()
harness.model.sourceControl?.setCommitMessage("fix it")
await harness.perform(.commit)
#expect(harness.git.commits == ["fix it"])
#expect(harness.git.executed == [["commit", "-m", "fix it"]])
await harness.perform(.push)
#expect(harness.git.pushes == 1)
#expect(harness.toastTitles == ["Committed 1 file", "Pushing…", "Pushed"])
#expect(harness.git.executed.last == ["push"])
#expect(harness.toastTitles == ["Committed 1 file", "Pushed to origin/main"])
}
@Test func commitWithoutAMessageDoesNothing() async {
@Test func commitWithoutAMessageStillAsksGitThenFocusesTheMessage() async {
let harness = WorkspaceHarness(git: snapshot([("a.php", .modified, true)]))
await harness.start()
harness.git.setRun(FakeGitRun(exitCode: 1, lines: [("Aborting commit due to empty commit message.", true)]), forCommand: "commit")
await harness.perform(.commit)
#expect(harness.git.commits.isEmpty)
#expect(harness.git.executed == [["commit", "-m", ""]])
#expect(harness.model.focusRequest?.target == .commitMessage)
#expect(harness.toastTitles == ["Commit failed"])
}
@Test func theRowMenuOpensTheFileAndClosesTheGitView() async {
let harness = WorkspaceHarness(git: snapshot([("a.php", .modified, false)]), contents: ["a.php": "<?php"])
await harness.start()
harness.model.perform(.toggleGit)
await harness.model.settle()
harness.model.perform(.showContextMenu(.gitRow(path: "a.php", isDeleted: false), anchor: CGPoint(x: 10, y: 20)))
await harness.perform(.context(.openFile("a.php")))
#expect(!harness.model.layout.isGitViewOpen)
#expect(harness.model.overlay.current == .none)
#expect(harness.model.editor?.activePath == "a.php")
}
@Test func thePassOnPromptInsertsIntoTheAgent() async {
@@ -466,14 +474,49 @@ import Testing
#expect(harness.model.focusRequest?.target == .panel(.editor))
}
@Test func commandCShowsAHiddenGitColumnAndFocusesTheCommitBox() async {
@Test func commandCOpensTheGitViewOnItsMessageField() async {
let harness = WorkspaceHarness()
await harness.start()
harness.model.perform(.focusCommitMessage)
#expect(harness.model.layout.isGitViewOpen)
#expect(harness.model.focusRequest?.target == .commitMessage)
harness.model.focusTaken(.commitMessage)
harness.model.perform(.focusCommitMessage)
#expect(harness.model.layout.isGitViewOpen)
#expect(harness.model.focusRequest?.target == .commitMessage)
}
@Test func commandGTogglesTheGitViewAndClosingGivesTheKeyboardBack() async {
let harness = WorkspaceHarness()
await harness.start()
harness.model.perform(.focus(.terminal))
harness.model.perform(.toggleGit)
#expect(harness.model.layout.isGitViewOpen)
#expect(harness.model.focusRequest?.target == .commitMessage)
#expect(harness.model.layout.visibility == .all)
harness.model.perform(.toggleGit)
#expect(!harness.model.layout.isGitViewOpen)
#expect(harness.model.focusRequest?.target == .panel(.terminal))
}
@Test func closingTheGitViewWithNoActiveColumnDropsTheFieldRequest() async {
let harness = WorkspaceHarness()
await harness.start()
harness.model.perform(.toggleGit)
#expect(!harness.model.layout.isVisible(.sourceControl))
harness.model.perform(.focusCommitMessage)
#expect(harness.model.layout.isVisible(.sourceControl))
#expect(harness.model.focusRequest?.target == .commitMessage)
harness.model.perform(.closeGitView)
#expect(!harness.model.layout.isGitViewOpen)
#expect(harness.model.focusRequest == nil)
harness.model.perform(.closeGitView)
#expect(!harness.model.layout.isGitViewOpen)
}
@Test func paneTogglesLeaveTheGitViewAlone() async {
let harness = WorkspaceHarness()
await harness.start()
harness.model.perform(.toggleGit)
harness.model.perform(.togglePane(.explorer))
#expect(!harness.model.layout.isVisible(.explorer))
#expect(harness.model.layout.isGitViewOpen)
}
@Test func aPaneToggleHidesItsColumnAndAHiddenColumnTakesNoFocus() async {
@@ -491,18 +534,19 @@ import Testing
#expect(harness.model.layout.isVisible(.terminal))
}
@Test func rowCursorKeysDriveTheFocusedList() async {
let harness = WorkspaceHarness(git: snapshot([("a.php", .modified, false), ("b.php", .added, true)]),
contents: ["a.php": "", "b.php": ""])
@Test func rowCursorKeysDriveOnlyTheExplorer() async {
let harness = WorkspaceHarness(contents: ["README.md": "# hi"])
await harness.start()
harness.model.perform(.focus(.sourceControl))
let before = harness.model.explorer?.selectedPath
harness.model.perform(.focus(.editor))
harness.model.perform(.moveRowCursor(1))
#expect(harness.model.sourceControl?.selectedRow?.path == "b.php")
harness.model.perform(.moveRowCursor(1))
#expect(harness.model.sourceControl?.selectedRow?.path == "a.php")
#expect(harness.model.explorer?.selectedPath == before)
harness.model.perform(.focus(.explorer))
harness.model.perform(.moveRowCursor(10))
harness.model.perform(.moveRowCursor(10))
#expect(harness.model.explorer?.selectedPath == "README.md")
await harness.perform(.openSelectedRow)
#expect(harness.model.editor?.activePath == "a.php")
#expect(harness.model.editor?.sides["a.php"] == .unstaged)
#expect(harness.model.editor?.activePath == "README.md")
}
@Test func commandRightOnARowOpensItsMenuBesideTheColumn() async {