feat(agent): add package history store#293
Conversation
📝 WalkthroughWalkthroughAdds a new Go package, Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@agent/go/internal/history/history_test.go`:
- Line 24: The Store logger dependency is using slog directly instead of the
project-standard logr.Logger from log.FromContext(ctx). Update the
Store/NewStore logging API and the related history_test setup to use logr-based
logging rather than constructing a *slog.Logger, and make sure any logger calls
in history.go (including load() and s.logger.Warn) are compatible with that
interface. Keep the implementation aligned with controller-runtime logging
conventions and remove the direct slog dependency from the Store path.
In `@agent/go/internal/history/history.go`:
- Around line 90-92: Several passthroughs in history.go return underlying errors
without adding local context, which violates the error-wrapping guideline.
Update the error returns in Read, load, and the other affected history methods
to use fmt.Errorf with %w and include a function-specific message (for example,
mentioning Read, load, or the relevant operation) instead of returning bare err
or Versions{}, err. Use the existing function names as anchors so each failure
path clearly identifies where it originated.
- Line 26: Replace the `slog` dependency in `Store` with controller-runtime’s
`logr.Logger` obtained from `log.FromContext(ctx)` so the package matches the
project logging convention. Update the `Store` field and constructor/setup in
`history.go` to hold a `logr.Logger` instead of `*slog.Logger`, and adjust every
`s.logger.Info`/`Warn` call in the affected methods to logr’s key/value style
(including any error logging via `Error`). Keep the existing log messages and
context, but remove any `log/slog` imports and ensure no stdlib logging is
introduced.
- Around line 110-120: The Record path in history.go unconditionally prepends to
ledger.Entries, so the ledger grows forever; add a retention cap when updating
the ledger in Record. Use the existing history types/functions like Record,
load, ledger.Entries, and entry to keep only the most recent N entries (or
another clear policy) before saving, while still preserving the current version
update and newest entry at the front.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Enterprise
Run ID: 3e6e0892-cfd4-4eff-ac38-184a1f081a51
📒 Files selected for processing (2)
agent/go/internal/history/history.goagent/go/internal/history/history_test.go
2d69731 to
ad37b2e
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@agent/go/internal/history/history_test.go`:
- Around line 181-191: Add test coverage in the existing invalid-input case to
verify the empty PackageVersion validation in both history.Read and
history.Record. Use the existing store.Record and store.Read paths with
cfg.PackageVersion set to empty, and assert the returned errors match the
package-version validation messages before any write/read proceeds. Keep the new
checks alongside the current invalid stage, zero timestamp, and invalid package
name assertions so the history.go guards are covered.
In `@agent/go/internal/history/history.go`:
- Around line 153-188: Normalize empty or missing current-version values in
Store.load so syntactically valid ledgers still fall back to UnknownVersion.
After json.Unmarshal in load, check the ledger’s CurrentVersion and, if it is
empty, treat it the same as an unknown history by setting it to UnknownVersion
(and ensure Entries remains initialized). Keep the existing handling in load and
Read-compatible behavior aligned so callers like upgrade/ env-var paths see the
unknown sentinel instead of an empty string.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Enterprise
Run ID: 43f0f2e1-b8a4-4ed3-813c-48e04f690339
📒 Files selected for processing (2)
agent/go/internal/history/history.goagent/go/internal/history/history_test.go
Signed-off-by: Riley Rice <riceriley59@gmail.com>
ad37b2e to
1b87335
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@agent/go/internal/history/history_test.go`:
- Around line 210-215: The history tests only cover invalid package-name
rejection through Read; update history_test.go to also assert the write path
rejects the same invalid package name before persisting. Add a Record-based
assertion alongside the existing Read checks, using the existing store and cfg
setup in the history test suite, so the behavior is covered via both the Record
and Read flows.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Enterprise
Run ID: 8ee4bd63-938a-4c43-bed9-f2ef3e305fa9
📒 Files selected for processing (2)
agent/go/internal/history/history.goagent/go/internal/history/history_test.go
Description
This PR adds the Go agent's package-history store. The store gives lifecycle steps a consistent view of the package version requested by the current config and the version most recently recorded on the host, without mutating step definitions or keeping process-local state.
Closes #215
What changed
Version inputs
Versionsvalue containing the current configured version and thepreviously recorded host version
CURRENT_VERSIONandPREVIOUS_VERSIONenvironment values
[previous, current]orderunknownwhen no usable prior history exists anduninstalledafter acompleted uninstall check
History persistence
ledger's current version while older entries are preserved
then atomically replace the ledger
0600permissions and history directories with0755permissionsValidation and recovery
zero timestamps before writing
.backupfile and continue from an unknownprevious version so corrupt host state does not permanently block package
execution
Test coverage
The history suite covers missing and existing ledgers, ordered version updates, uninstall state, corrupt-history recovery, atomic-write cleanup, file permissions, input validation, and filesystem error propagation.
Testing
make unit-testsmake lintChecklist
git commit -s) per the DCO.