mirror of
https://github.com/lukaszraczylo/harness-sync.git
synced 2026-10-12 00:45:22 +00:00
Three robustness fixes for the apply pipeline:
1. Silent read errors on state/target files treated 'file absent' as
'file empty' and fast-forward-overwrote user edits. Add
common.ReadExistingFile that returns (nil,nil) only on
os.IsNotExist; other I/O errors propagate. Use it from apply.Run
and from every adapter's Render (claudecode, crush, kilo,
opencode, goose, zed).
2. apply.Run required callers to pre-construct *gitx.Repo; passing
nil silently skipped the commit. Run now auto-opens a repo from
Bundle.Root, gracefully no-ops when the root is not a git repo,
and uses a new gitx.HasStagedChanges() check to skip the no-op
'nothing to commit' that triggered the original silent-skip.
3. Each of 7 adapter packages re-implemented the same 25-line
Option/WithHome/New constructor. Hoist into adapter.Base +
adapter.BaseOption + NewBase. Each adapter embeds *Base and
reduces to a 9-line constructor. Public New(WithHome(h)) API
preserved; a.home becomes a.Home.
Tests:
- apply: 5 new (propagates-read-error, auto-opens-repo,
no-repo-skips-commit, skips-no-op-commit, commit-message-counts)
- gitx: 2 new (HasStagedChanges empty/after-add)
- adapter/common: 3 new (ReadExistingFile missing/content/perm)
- adapter: 4 new (NewBase default/WithHome/order/typed)
- existing adapter tests unchanged — verify a.Home still honoured.
30 lines
912 B
Go
30 lines
912 B
Go
package adapter
|
|
|
|
import "github.com/lukaszraczylo/harness-sync/internal/adapter/common"
|
|
|
|
// Base holds the cross-adapter defaults (currently just the home directory
|
|
// used to compute target paths). Embed it in each adapter struct to inherit
|
|
// the WithHome/New constructor pattern without re-implementing it.
|
|
type Base struct {
|
|
Home string
|
|
}
|
|
|
|
// BaseOption configures a Base. Returned by WithHome and consumed by NewBase.
|
|
type BaseOption func(*Base)
|
|
|
|
// WithHome overrides the home directory used for target paths. Defaults to
|
|
// common.DefaultHome() (current $HOME) when no option is supplied.
|
|
func WithHome(h string) BaseOption {
|
|
return func(b *Base) { b.Home = h }
|
|
}
|
|
|
|
// NewBase returns a Base populated from opts, with Home defaulting to the
|
|
// current user's home directory.
|
|
func NewBase(opts ...BaseOption) *Base {
|
|
b := &Base{Home: common.DefaultHome()}
|
|
for _, o := range opts {
|
|
o(b)
|
|
}
|
|
return b
|
|
}
|