Index restore report action updates

This commit is contained in:
2026-12-02 21:50:22 +00:00
parent f7a7afe12f
commit f4a8488167
4 changed files with 41 additions and 21 deletions

View File

@@ -41,10 +41,10 @@ their scope. Unless assigned otherwise, a finding remains independent audit
remediation. Shared code does not make a refactoring a prerequisite or assign remediation. Shared code does not make a refactoring a prerequisite or assign
the whole finding to a roadmap. the whole finding to a roadmap.
Thirty-eight entries are closed by the safety, transfer, audio discovery, S3 Thirty-nine entries are closed by the safety, transfer, audio discovery, S3
planning, prerequisite-history, publication-import, CLI classification, planning, prerequisite-history, publication-import, CLI classification,
inspection aggregation, test maintenance, dead-code removal, and associated inspection aggregation, test maintenance, dead-code removal, and associated
documentation work; 5 remain open. **Planned** identifies documentation work; 4 remain open. **Planned** identifies
an agreed remedy awaiting implementation. **Potentially eliminated** requires verification that the offending an agreed remedy awaiting implementation. **Potentially eliminated** requires verification that the offending
lifecycle is removed. **Coordinate** identifies shared changes, not a commitment lifecycle is removed. **Coordinate** identifies shared changes, not a commitment
that a related feature implements the entire finding. Findings close only after their that a related feature implements the entire finding. Findings close only after their
@@ -798,7 +798,11 @@ verification. Index selection rather than caching payloads across invocations.
### CAT-28 — P3: Index restore report action updates ### CAT-28 — P3: Index restore report action updates
Status: Open Status: Closed
**Closure.** Restore reports index action identities privately while retaining
the first matching action, report order and counters. Restore execution tests
cover duplicate keys and unmatched updates as well as existing workflows.
**Disposition / owner.** Coordinate — [restore reporting](../../internal/command-restore.md#reporting-and-ownership) **Disposition / owner.** Coordinate — [restore reporting](../../internal/command-restore.md#reporting-and-ownership)
remains implemented. Carry or index action identity if that path is changed; remains implemented. Carry or index action identity if that path is changed;

View File

@@ -643,7 +643,7 @@ Validation: `go test ./internal/artifacts ./internal/stage ./internal/app`.
## Stage 24: Index Restore Report Updates ## Stage 24: Index Restore Report Updates
CAT IDs: CAT-28. Status: Pending. CAT IDs: CAT-28. Status: Complete.
Read [EF-04](audit/02-efficiency.md#ef-04--p3-restore-reporting-performs-a-full-search-after-each-install) Read [EF-04](audit/02-efficiency.md#ef-04--p3-restore-reporting-performs-a-full-search-after-each-install)
and `app/restore_report.go`/execution tests. and `app/restore_report.go`/execution tests.

View File

@@ -740,3 +740,20 @@ func TestExecuteRestoreInstallsOptionalPrerequisiteHistory(t *testing.T) {
root := artifacts.SessionWorkDirForCampaign(workspaceRoot, cfg.Session.Campaign, cfg.Session.SessionID) root := artifacts.SessionWorkDirForCampaign(workspaceRoot, cfg.Session.Campaign, cfg.Session.SessionID)
mustReadEquals(t, filepath.Join(root, "inputs", "previous", "artifacts", "session_recap.md"), "optional history\n") mustReadEquals(t, filepath.Join(root, "inputs", "previous", "artifacts", "session_recap.md"), "optional history\n")
} }
func TestRestoreReportUpdatesFirstDuplicateAndCountsUnmatched(t *testing.T) {
action := RestoreAction{Kind: RestoreActionDownload, LocalRelativePath: "inputs/a", RemoteKey: "remote/a"}
report, err := newRestoreReport(&RemoteCurrentState{}, &RestorePlan{Actions: []RestoreAction{action, action}}, RestorePlanOptions{})
if err != nil {
t.Fatal(err)
}
report.markDownloaded(action)
report.markFailed(RestoreAction{LocalRelativePath: "missing", RemoteKey: "missing"}, nil)
if report.Actions[0].Status != "downloaded" || report.Actions[1].Status != "planned_download" || report.Execution.Downloaded != 1 || report.Execution.Failed != 1 {
t.Fatalf("unexpected report: %+v", report)
}
data, err := json.Marshal(report)
if err != nil || strings.Contains(string(data), "actionIndices") {
t.Fatalf("serialized report = %s, error = %v", data, err)
}
}

View File

@@ -29,6 +29,12 @@ type RestoreReport struct {
Satisfied []string `json:"projected_satisfied,omitempty"` Satisfied []string `json:"projected_satisfied,omitempty"`
Remaining []string `json:"projected_remaining,omitempty"` Remaining []string `json:"projected_remaining,omitempty"`
reportPathRel string reportPathRel string
actionIndices map[restoreActionKey]int
}
type restoreActionKey struct {
localRelativePath string
remoteKey string
} }
type RestorePlanSummary struct { type RestorePlanSummary struct {
@@ -75,11 +81,16 @@ func newRestoreReport(current *RemoteCurrentState, plan *RestorePlan, opts Resto
SkipSame: plan.SkipSameCount, SkipSame: plan.SkipSameCount,
Conflicts: plan.ConflictCount, Conflicts: plan.ConflictCount,
}, },
Actions: make([]RestoreReportAction, 0, len(plan.Actions)), Actions: make([]RestoreReportAction, 0, len(plan.Actions)),
Satisfied: append([]string(nil), plan.Satisfied...), Satisfied: append([]string(nil), plan.Satisfied...),
Remaining: append([]string(nil), plan.Remaining...), Remaining: append([]string(nil), plan.Remaining...),
actionIndices: make(map[restoreActionKey]int, len(plan.Actions)),
} }
for _, action := range plan.Actions { for _, action := range plan.Actions {
key := restoreActionKey{action.LocalRelativePath, action.RemoteKey}
if _, exists := r.actionIndices[key]; !exists {
r.actionIndices[key] = len(r.Actions)
}
r.Actions = append(r.Actions, RestoreReportAction{ r.Actions = append(r.Actions, RestoreReportAction{
Kind: string(action.Kind), Kind: string(action.Kind),
SourceID: action.SourceID, SourceID: action.SourceID,
@@ -109,7 +120,7 @@ func (r *RestoreReport) markDownloaded(action RestoreAction) {
if r == nil { if r == nil {
return return
} }
if idx := r.findAction(action); idx >= 0 { if idx, ok := r.actionIndices[restoreActionKey{action.LocalRelativePath, action.RemoteKey}]; ok {
r.Actions[idx].Status = "downloaded" r.Actions[idx].Status = "downloaded"
r.Actions[idx].Error = "" r.Actions[idx].Error = ""
} }
@@ -120,7 +131,7 @@ func (r *RestoreReport) markFailed(action RestoreAction, err error) {
if r == nil { if r == nil {
return return
} }
if idx := r.findAction(action); idx >= 0 { if idx, ok := r.actionIndices[restoreActionKey{action.LocalRelativePath, action.RemoteKey}]; ok {
r.Actions[idx].Status = "failed" r.Actions[idx].Status = "failed"
if err != nil { if err != nil {
r.Actions[idx].Error = err.Error() r.Actions[idx].Error = err.Error()
@@ -147,18 +158,6 @@ func (r *RestoreReport) setSucceeded() {
r.Error = "" r.Error = ""
} }
func (r *RestoreReport) findAction(action RestoreAction) int {
if r == nil {
return -1
}
for i := range r.Actions {
if r.Actions[i].LocalRelativePath == action.LocalRelativePath && r.Actions[i].RemoteKey == action.RemoteKey {
return i
}
}
return -1
}
func persistRestoreReport(store artifacts.Store, cfg *config.Config, report *RestoreReport) (string, error) { func persistRestoreReport(store artifacts.Store, cfg *config.Config, report *RestoreReport) (string, error) {
if store == nil { if store == nil {
return "", fmt.Errorf("artifact store is required") return "", fmt.Errorf("artifact store is required")