Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b474d01
docs(acceptance-tests): specify the picker's file diff as @wip scenarios
DPassarelli Oct 20, 2026
c0d14e8
docs(acceptance-tests): reduce each When clause to a single, focused …
DPassarelli Oct 25, 2026
826762b
ci(gosec): bump gosec to v2.29.0 so it can load packages built by Go …
DPassarelli Oct 25, 2026
53d004a
chore: merge branch 'ci/gosec' into feat/diff
DPassarelli Oct 25, 2026
8be8b14
feat(diff): start building out the functionality (and create a PTY te…
DPassarelli Nov 3, 2026
27551f4
Merge branch 'main' into feat/diff
DPassarelli Nov 4, 2026
058c1d1
feat(diff): show a file's diff or a no-diff notice from the picker
DPassarelli Nov 4, 2026
13165c6
feat(picker): bold the newer "last updated" wording to make it stand out
DPassarelli Nov 4, 2026
da3ae28
feat(picker): bold both the direction and "last updated" phrase
DPassarelli Nov 4, 2026
40e7747
fix(acceptance-tests): isolate terminal scenarios from color environm…
DPassarelli Nov 4, 2026
721e46c
test(diff): ensure a file of exactly 200 KiB still gets a diff
DPassarelli Nov 4, 2026
cf0e4e9
feat(diff): close the diff with esc and ignore picker keys while it i…
DPassarelli Nov 5, 2026
12d1bef
fix(diff): report exact line counts and mark a missing final newline
DPassarelli Nov 5, 2026
07064f4
feat(diff): scroll the diff and clear a notice on the next keypress
DPassarelli Nov 5, 2026
66d393e
feat(diff): show the diff key in the picker and a hint under the diff
DPassarelli Nov 5, 2026
1926bb1
feat(diff): show a spinner while a slow diff is being fetched
DPassarelli Nov 5, 2026
2e4d818
test(diff): ensure that a failed fetch shows rsync's account in the o…
DPassarelli Nov 5, 2026
5235f6b
feat(diff): show tabs as a fixed-width arrow so wrapping measures them
DPassarelli Nov 5, 2026
19f9bb9
feat(diff): title the diff overlay and color-code each side
DPassarelli Nov 9, 2026
2360c8b
fix(acceptance-tests): join wrapped header rows before matching paths
DPassarelli Nov 10, 2026
1906be4
feat(diff): draw the diff overlay inside a box & create a specific di…
DPassarelli Nov 10, 2026
5eaa2b7
feat(version): add commit hash to "dev build" version string
DPassarelli Nov 10, 2026
a5c14be
feat(diff): add a scrollbar and blank top row to the diff overlay
DPassarelli Nov 10, 2026
127b5ef
fix(acceptance-tests): stop the emulator from dropping characters tha…
DPassarelli Nov 10, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),

## [Unreleased]

### Added

- Pressing `d` in the picker shows the highlighted file's diff, from the destination copy to the source, so you can see what syncing it would change. The diff is drawn inside a box, with a scrollbar on its right edge when it's taller than the screen, under a header that stays put while you scroll and names the file and both the source and the destination, and its lines are colored to match the diff's: red for the destination, green for the source. A new hint line says diffs are only available for text files of 200 KiB or less, and a file that can't be diffed (one side missing, too big, or binary) gets a short bold note on that line instead. The local copy is checked first, so one that can't be diffed never costs a trip to the remote. Long lines wrap behind `↪`, tabs show as `→`, and a fetch that fails repeats what rsync said. (#119)
- A build from source now names the commit it was built from in its version line, e.g. `cherry-sync (dev build: e608fd7)`, so two dev builds can be told apart.

### Changed

- The picker now shows the newer copy's name and "last updated" phrase in bold in the highlighted row's comparison, so you can see at a glance which copy is the live one. Nothing is bold when the timestamps match or can't be read.

## [1.3.0] - 2026-10-06

### Added
Expand Down
2 changes: 1 addition & 1 deletion acceptance_tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The `.feature` files in this folder are csync's specification. This page puts th
- [explained](explain-differences.feature) by how the two copies differ,
- free of [files git ignores](honor-gitignore.feature) and of [tooling metadata](withhold-tooling-metadata.feature) such as `.git`,
- followed by a note of [what was held back](disclose-withheld-changes.feature).
3. [Select and sync](select-and-sync.feature) some or all of the changes, including deletions.
3. [Select and sync](select-and-sync.feature) some or all of the changes, including deletions, after [viewing a file's diff](show-file-diff.feature) if needed. The diff is specified but not yet implemented.
4. [Log the run](log-each-run.feature) to a file, and [prune old logs](prune-run-logs.feature).

## Sync with a saved remote
Expand Down
37 changes: 37 additions & 0 deletions acceptance_tests/explain-differences.feature
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,40 @@ Feature: Explain how each file differs
| action | path |
| update | README.md |
And the reported detail for "README.md" should be "size and mtime"

Scenario Outline: The newer copy's name and "last updated" phrase stand out in the picker
# Bold answers "which copy is the live one?" at a glance. The last row's ages both
# read "2d ago", so there the bold is the only thing that says which is newer.
Given that the two copies of "README.md" differ in content but not in size
And that the local copy of "README.md" was last modified <local> ago
And that the remote copy of "README.md" was last modified <remote> ago
And that I have run "csync ./project user@host:/project" in a terminal
Then the bold text in the detail should be "<bold>"

Examples:
| local | remote | bold |
| 3 hours | 17 days | source last updated 3h ago |
| 17 days | 3 hours | dest last updated 3h ago |
| 49 hours | 50 hours | source last updated 2d ago |

Scenario: A newer source's size comparison stays out of the bold
# The size gap says nothing about which copy is newer, so bold skips over it.
Given that the local copy of "README.md" is 2 KB larger than the remote copy
And that the local copy of "README.md" was last modified 3 hours ago
And that the remote copy of "README.md" was last modified 17 days ago
And that I have run "csync ./project user@host:/project" in a terminal
Then the bold text in the detail should be "source" and "last updated 3h ago"

Scenario: Copies with the same timestamp have nothing to highlight
# The sizes differ so that both copies are measured: copies agreeing on size and
# time fall back to "contents only" and would never reach the comparison.
Given that the local copy of "README.md" is 2 KB larger than the remote copy
And that both copies of "README.md" carry the same modification time
And that I have run "csync ./project user@host:/project" in a terminal
Then no part of the detail should be bold

Scenario: A destination that cannot be measured has nothing to highlight
Given that the file "README.md" has been changed locally
And a remote that answers the comparison but fails the measurement
And that I have run "csync ./project user@host:/project" in a terminal
Then no part of the detail should be bold
42 changes: 34 additions & 8 deletions acceptance_tests/harness/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,23 @@ func csyncEnv(ctx context.Context) []string {
if failMeasure {
rsh = failMeasureRsh
}
slowSend, _ := ctx.Value(slowSendModeKey{}).(bool)
if slowSend {
rsh = slowSendRsh
}
sendLog, _ := ctx.Value(sendLogKey{}).(string)
if sendLog != "" {
rsh = recordSendRsh
env = append(env, "SEND_LOG="+sendLog)
}
failSend, _ := ctx.Value(failSendModeKey{}).(bool)
if failSend {
rsh = failSendRsh
}
message, _ := ctx.Value(failSendMessageKey{}).(string)
if message != "" {
env = append(env, "FAIL_SEND_MESSAGE="+message)
}
stallMode, _ := ctx.Value(stallModeKey{}).(bool)
if stallMode {
// Swap in the shell that stops answering after the comparison, and shorten
Expand Down Expand Up @@ -161,23 +178,22 @@ func withoutVars(env []string, names ...string) []string {
return kept
}

// runCsync splits the command, substitutes the Gherkin placeholders
// (`./project`, `user@host:/project`, `<empty>`) with the scenario's real
// tempdir paths, runs the csync binary with the given stdin, and stashes the
// captured streams and exit code in the context.
func runCsync(ctx context.Context, command string, stdin io.Reader, dir string) (context.Context, error) {
// resolveCsyncArgs splits a scenario's command and substitutes the Gherkin
// placeholders (`./project`, `user@host:/project`, `<empty>`) with the scenario's
// real tempdir paths, returning the arguments for the csync binary.
func resolveCsyncArgs(ctx context.Context, command string) (context.Context, []string, error) {
parts := strings.Fields(command)
if len(parts) == 0 {
return ctx, fmt.Errorf("empty command")
return ctx, nil, fmt.Errorf("empty command")
}
if parts[0] != "csync" {
return ctx, fmt.Errorf("expected command to start with %q, got %q", "csync", parts[0])
return ctx, nil, fmt.Errorf("expected command to start with %q, got %q", "csync", parts[0])
}

args := parts[1:]
ctx, err := mirrorRemote(ctx)
if err != nil {
return ctx, err
return ctx, nil, err
}

// <empty> is a sentinel for an empty-string argument: the step regex and
Expand All @@ -198,6 +214,16 @@ func runCsync(ctx context.Context, command string, stdin io.Reader, dir string)
args[i] = replacement
}
}
return ctx, args, nil
}

// runCsync runs the csync binary for a scenario's command with the given stdin, and
// stashes the captured streams and exit code in the context.
func runCsync(ctx context.Context, command string, stdin io.Reader, dir string) (context.Context, error) {
ctx, args, err := resolveCsyncArgs(ctx, command)
if err != nil {
return ctx, err
}

runCtx, cancelRun := context.WithTimeout(ctx, runWait)
defer cancelRun()
Expand Down
117 changes: 117 additions & 0 deletions acceptance_tests/harness/harness_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,86 @@ shift
exec "$@"
`

// failSendRsh is the path to a test-only remote shell that answers the comparison
// and refuses to send a file. See failSendRshScript.
var failSendRsh string

// failSendMessage is what the refusing remote writes, so a scenario can check that
// csync passed rsync's account of the failure on rather than a bare exit status.
const failSendMessage = "send refused by the test remote"

// failSendRshScript is the body of the refusing remote shell. As with the slow
// remote, a real send is the one pass running --sender without -n.
const failSendRshScript = `#!/bin/sh
if [ "$1" = "-l" ]; then shift 2; fi
shift
sender=no
dry=no
for a in "$@"; do
case "$a" in
--sender) sender=yes ;;
--*) ;;
-*) case "$a" in *n*) dry=yes ;; esac ;;
esac
done
if [ "$sender" = yes ] && [ "$dry" = no ]; then
echo "${FAIL_SEND_MESSAGE:-` + failSendMessage + `}" >&2
exit 13
fi
if [ -n "$FAKE_REMOTE_HOME" ]; then cd "$FAKE_REMOTE_HOME" || exit 1; fi
exec "$@"
`

// recordSendRsh is the path to a test-only remote shell that notes each time it is
// asked to send a file. See recordSendRshScript.
var recordSendRsh string

// recordSendRshScript is the body of the recording remote shell. As with the slow
// remote, a real send is the one pass running --sender without -n; each appends a
// line to SEND_LOG and then runs as the plain fake remote does. The file names
// travel over rsync's own protocol rather than its arguments, so only the send
// itself can be recorded.
const recordSendRshScript = `#!/bin/sh
if [ "$1" = "-l" ]; then shift 2; fi
shift
sender=no
dry=no
for a in "$@"; do
case "$a" in
--sender) sender=yes ;;
--*) ;;
-*) case "$a" in *n*) dry=yes ;; esac ;;
esac
done
if [ "$sender" = yes ] && [ "$dry" = no ]; then echo send >> "$SEND_LOG"; fi
if [ -n "$FAKE_REMOTE_HOME" ]; then cd "$FAKE_REMOTE_HOME" || exit 1; fi
exec "$@"
`

// slowSendRsh is the path to a test-only remote shell that answers the comparison
// promptly and is slow to send a file. See slowSendRshScript.
var slowSendRsh string

// slowSendRshScript is the body of the slow remote shell. A real file is sent by an
// rsync running with --sender and without -n; the comparison's passes are all dry
// runs, so only fetching a copy is delayed, and long enough for an indicator to show.
const slowSendRshScript = `#!/bin/sh
if [ "$1" = "-l" ]; then shift 2; fi
shift
sender=no
dry=no
for a in "$@"; do
case "$a" in
--sender) sender=yes ;;
--*) ;;
-*) case "$a" in *n*) dry=yes ;; esac ;;
esac
done
if [ "$sender" = yes ] && [ "$dry" = no ]; then sleep 2; fi
if [ -n "$FAKE_REMOTE_HOME" ]; then cd "$FAKE_REMOTE_HOME" || exit 1; fi
exec "$@"
`

// stallRsh is the path to a test-only remote shell that answers every rsync the
// comparison runs and goes silent once the transfer starts. Scenarios that need a
// stalled transfer point RSYNC_RSH here instead of at fakeRsh. See stallRshScript.
Expand Down Expand Up @@ -178,6 +258,22 @@ type stallModeKey struct{}
// rather than the plain one.
type failMeasureModeKey struct{}

// slowSendModeKey flags a scenario as needing the remote that is slow to send files,
// so csyncEnv points RSYNC_RSH at slowSendRsh.
type slowSendModeKey struct{}

// sendLogKey stashes the file the recording remote appends to for each send, and so
// also flags a scenario as needing that remote.
type sendLogKey struct{}

// failSendModeKey flags a scenario as needing the remote that refuses to send files,
// so csyncEnv points RSYNC_RSH at failSendRsh.
type failSendModeKey struct{}

// failSendMessageKey holds the sentence the refusing remote should write in place of
// failSendMessage, for a scenario that needs a particular one.
type failSendMessageKey struct{}

// homeKey stashes a per-scenario throwaway home directory, created by the Before
// hook and removed by the After hook. runCsync points the csync child's HOME and
// XDG_STATE_HOME into it so a run log lands inside the scenario's own tempdir
Expand Down Expand Up @@ -321,6 +417,27 @@ func TestMain(m *testing.M) {
os.Exit(2)
}

failSendRsh = filepath.Join(tmpDir, "failsendrsh")
err = os.WriteFile(failSendRsh, []byte(failSendRshScript), 0o755)
if err != nil {
fmt.Fprintln(os.Stderr, "failsendrsh:", err)
os.Exit(2)
}

recordSendRsh = filepath.Join(tmpDir, "recordsendrsh")
err = os.WriteFile(recordSendRsh, []byte(recordSendRshScript), 0o755)
if err != nil {
fmt.Fprintln(os.Stderr, "recordsendrsh:", err)
os.Exit(2)
}

slowSendRsh = filepath.Join(tmpDir, "slowsendrsh")
err = os.WriteFile(slowSendRsh, []byte(slowSendRshScript), 0o755)
if err != nil {
fmt.Fprintln(os.Stderr, "slowsendrsh:", err)
os.Exit(2)
}

stallRsh = filepath.Join(tmpDir, "stallrsh")
err = os.WriteFile(stallRsh, []byte(stallRshScript), 0o755)
if err != nil {
Expand Down
9 changes: 5 additions & 4 deletions acceptance_tests/harness/output_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,11 @@ var (
// applied no deletions and the header stays in its plain "(N files)" form.
removedRE = regexp.MustCompile(`(\d+) of which (?:was|were) removed`)
// versionLineRE captures the first line `csync --version` prints — either
// "cherry-sync v<semver>" for a release build or "cherry-sync (dev build)"
// for an un-injected one. The description and URL follow on their own lines;
// this matches only the version line.
versionLineRE = regexp.MustCompile(`(?m)^(cherry-sync (?:v.+|\(dev build\)))\s*$`)
// "cherry-sync v<semver>" for a release build or "cherry-sync (dev build)" for
// an un-injected one, optionally naming its commit ("(dev build: e608fd7)").
// The description and URL follow on their own lines; this matches only the
// version line.
versionLineRE = regexp.MustCompile(`(?m)^(cherry-sync (?:v.+|\(dev build(?:: [0-9a-f]+)?\)))\s*$`)
// logPathRE captures the path of the run log csync wrote. It is matched against
// both whole streams rather than the report region, so where csync chooses to
// disclose the path is not something the scenarios depend on: a clean run reports
Expand Down
65 changes: 65 additions & 0 deletions acceptance_tests/harness/steps_color_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Step definitions for the colors the diff overlay draws its lines in, which only
// the emulated screen's cell attributes can show.

package acceptance_test

import (
"context"
"fmt"
"strings"

"github.com/hinshun/vt10x"
)

// namedColors are the colors a scenario can name, as the emulator records them.
var namedColors = map[string]vt10x.Color{
"red": vt10x.Red,
"green": vt10x.Green,
}

// theLinesBeginningShouldBe asserts that every visible character of the rows opening
// with each prefix is drawn in the named color.
func theLinesBeginningShouldBe(ctx context.Context, first, second, color string) error {
session, err := runningTerminal(ctx)
if err != nil {
return err
}
_, err = session.waitFor("the lines beginning "+first+" and "+second, func(s TerminalScreen) bool {
return s.HasOverlay() && hasLineBeginning(s, first) && hasLineBeginning(s, second)
})
if err != nil {
return err
}
for _, prefix := range []string{first, second} {
err = assertRowColor(session, prefix, namedColors[color])
if err != nil {
return err
}
}
return nil
}

// hasLineBeginning reports whether a line on screen opens with prefix.
func hasLineBeginning(s TerminalScreen, prefix string) bool {
for _, line := range s.Lines {
if strings.HasPrefix(line, prefix) {
return true
}
}
return false
}

// assertRowColor checks that the row opening with prefix draws every non-blank
// character in want, apart from the overlay's box and scrollbar around it.
func assertRowColor(session *terminalSession, prefix string, want vt10x.Color) error {
row := session.rowBeginning(prefix)
if row == nil {
return fmt.Errorf("no row begins with %q", prefix)
}
for _, cell := range row {
if cell.Char != ' ' && cell.Char != 0 && string(cell.Char) != frameSide && string(cell.Char) != frameThumb && cell.FG != want {
return fmt.Errorf("in the row beginning %q, %q is color %d, want %d", prefix, cell.Char, cell.FG, want)
}
}
return nil
}
Loading
Loading