ADR 0593 §7: the composer with its refusals leaves mesh-sdk, so mesh-sdk carries no composition rule. The catalogue functions only the node-engine's composition reaches (Resolve, Resolution's Compose, Declaration, DataItems, LeftOut, Rules and the rest, the settings, placeholder and template refusals, the rendering helpers) are copied with their tests into internal/compose/resolution; a method of a mesh-sdk shape becomes a function taking it first. The composition calls its own copies, and the captured catalogue its tests read lives here now, shared by mesh-compose's tests. Claude-Session: https://claude.ai/code/session_01NcbgfJ9Gum47zkFKWRaovL
78 lines
2.4 KiB
Go
78 lines
2.4 KiB
Go
package resolution
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
mcat "git.novox.be/novox/mesh-sdk/go/catalogue"
|
|
)
|
|
|
|
// derivedContributions is what a module's data section gives the backup holder: its backup lines and
|
|
// its items. Every item is listed, so a valuable one on a machine is measured whether or not it is
|
|
// copied; a cache is listed and not measured.
|
|
func manifestDerivedContributions(m mcat.Manifest) []mcat.SeatContribution {
|
|
items := m.DataItems()
|
|
if len(items) == 0 {
|
|
return nil
|
|
}
|
|
var lines []string
|
|
kept := map[string]bool{}
|
|
keep := func(path string) {
|
|
if !kept[path] {
|
|
kept[path] = true
|
|
lines = append(lines, "path "+path)
|
|
}
|
|
}
|
|
for _, it := range items {
|
|
if !it.BackedUp() {
|
|
continue
|
|
}
|
|
if it.Backup.IsDump() {
|
|
lines = append(lines, "run "+strings.TrimSpace(it.Backup.Dump))
|
|
if into, ok := m.DataItem(it.Backup.Into); ok {
|
|
keep(into.Path)
|
|
}
|
|
continue
|
|
}
|
|
keep(it.Path)
|
|
}
|
|
var described []string
|
|
for _, it := range items {
|
|
covered := "-"
|
|
switch {
|
|
case it.Backup.IsDump():
|
|
if into, ok := m.DataItem(it.Backup.Into); ok {
|
|
covered = into.Path
|
|
}
|
|
case it.BackedUp():
|
|
covered = it.Path
|
|
}
|
|
described = append(described, fmt.Sprintf("item %s %s %s %s %s %s", it.ID, it.Class, it.Path, covered,
|
|
it.Protection(), it.MeasuredBy()))
|
|
}
|
|
var out []mcat.SeatContribution
|
|
if len(lines) > 0 {
|
|
out = append(out, mcat.SeatContribution{Seat: mcat.BackupSeat, Kind: mcat.BackupKindBackup, Content: strings.Join(lines, "\n") + "\n"})
|
|
}
|
|
return append(out, mcat.SeatContribution{Seat: mcat.BackupSeat, Kind: mcat.BackupKindData, Content: strings.Join(described, "\n") + "\n"})
|
|
}
|
|
|
|
// allContributions is every contribution a module makes to a seat's holder: what it wrote, and what
|
|
// its data section derives. **One list**: a module that declares its data has its backup lines
|
|
// composed from it, and a backup line it still writes by hand is not placed — the catalogue check
|
|
// refuses it — so the holder never copies two lists that disagree.
|
|
func manifestAllContributions(m mcat.Manifest) []mcat.SeatContribution {
|
|
if m.Data == nil {
|
|
return m.Contributions
|
|
}
|
|
derived := manifestDerivedContributions(m)
|
|
out := make([]mcat.SeatContribution, 0, len(m.Contributions)+len(derived))
|
|
for _, c := range m.Contributions {
|
|
if s, known := mcat.SeatNamed(c.Seat); known && s.Name == mcat.BackupSeat {
|
|
continue
|
|
}
|
|
out = append(out, c)
|
|
}
|
|
return append(out, derived...)
|
|
}
|