A rename moves a module's own value with its trust (design 32): the old name is a value the trunk's manifest of the same module declares and the change does not, no secret and no key of the predefined list, and the old and new value have the same trust, declared or by the predefined key they take. Judged for a change over the trunk; each refusal names the module and the key. Claude-Session: https://claude.ai/code/session_01JG73KJNrH5EgFXMKKYSrig
53 lines
1.9 KiB
Go
53 lines
1.9 KiB
Go
package judge
|
|
|
|
import (
|
|
"fmt"
|
|
"maps"
|
|
"slices"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
|
)
|
|
|
|
// RenameProblems judge a change's `renamed-from` against the trunk's manifest of the same module (DLV-I15; ADR 0609 §4,
|
|
// design 32 *A config value renamed*): the old name is a config value the trunk declares and the head does not; it is
|
|
// no secret and no key of the predefined list; the old and the new value have the same trust (declared, or the trust of
|
|
// the predefined key it takes its definition from). Each refusal names the module and the key. A module the trunk does
|
|
// not hold yet renames nothing.
|
|
func RenameProblems(module string, head, trunk catalogue.Manifest, predefined catalogue.PredefinedList) []string {
|
|
trust := func(d catalogue.SettingDeclaration) bool {
|
|
if d.Predefined != "" {
|
|
return predefined[d.Predefined].Trusted
|
|
}
|
|
return d.Trusted
|
|
}
|
|
var problems []string
|
|
for _, key := range slices.Sorted(maps.Keys(head.Settings)) {
|
|
d := head.Settings[key]
|
|
old := d.RenamedFrom
|
|
if old == "" {
|
|
continue
|
|
}
|
|
say := func(f string, a ...any) {
|
|
problems = append(problems, fmt.Sprintf("%s: the config value %q is renamed from %q, ", module, key, old)+fmt.Sprintf(f, a...)+" (design 32)")
|
|
}
|
|
_, ownSecret := trunk.OwnSecrets[old]
|
|
_, secret := trunk.Secrets[old]
|
|
was, declared := trunk.Settings[old]
|
|
_, still := head.Settings[old]
|
|
_, isPredefined := predefined[old]
|
|
switch {
|
|
case ownSecret || secret:
|
|
say("which is a secret; a secret is never renamed")
|
|
case isPredefined:
|
|
say("which is a key of the predefined list, not this module's own value")
|
|
case !declared:
|
|
say("which the trunk's manifest of %s does not declare", module)
|
|
case still:
|
|
say("and the change declares %q still: the old and the new name are not both declared", old)
|
|
case trust(was) != trust(d):
|
|
say("and the rename would change its trust (trusted %v on the trunk, %v here); a rename keeps a value's trust", trust(was), trust(d))
|
|
}
|
|
}
|
|
return problems
|
|
}
|