clarify checkpoint policy satisfaction · Entire

clarify checkpoint policy satisfaction

65d3736→main·

pfleidi·2w ago·4 files·+77 added/-9 removed

Add one predicate for unsupported checkpoint policy and centralize the user-facing upgrade details.

Remove the exported upgrade-warning helper now that callers use the diagnostic message helper directly.

Sessions

90243197507fView transcript

[?
Enforce Checkpoint Policies in CLICodex·GPT-5.5·26 steps](/content/gh/entireio/cli/session/019f05ad-eea0-7202-a508-ec34d069a2d2#timeline-90243197507f/index.html)

Changes

4

42 unmodified lines

43
44
45
46
46
47
48
49
50
50
51
52
53
54

42 unmodified lines

if err != nil {
        return
    }
    if !checkpointpolicy.RequiresUpgrade(state.Policy) && !checkpointpolicy.UnsupportedWrite(state.Policy) {
    if checkpointpolicy.CanSatisfyPolicy(state.Policy) {
        return
    }

fmt.Fprint(w, checkpointpolicy.UpgradeWarning(versioncheck.UpdateCommandForCurrentBinary(currentVersion)))
    fmt.Fprint(w, checkpointpolicy.UnsupportedPolicyMessage(
        state.Policy,
        versioncheck.UpdateCommandForCurrentBinary(currentVersion),
    ))
}

Mcmd/entire/cli/checkpoint_policy_warning.go+5/-2

1 unmodified line

2
3
4
5
6
7
8
76 unmodified lines

85
86
87
87
88
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129

1 unmodified line

import (
    "fmt"
    "strings"

"github.com/entireio/cli/cmd/entire/cli/checkpoint"
)
76 unmodified lines

return !CanWrite(version)
}

func UpgradeWarning(updateCommand string) string {
    return fmt.Sprintf("[entire] This repository requires checkpoint support newer than this Entire CLI.\n[entire] Upgrade Entire, then rerun the command:\n[entire]   %%s\n", updateCommand)
func CanSatisfyPolicy(policy Policy) bool {
    return !UnsupportedWrite(policy) && !RequiresUpgrade(policy)
}

func UnsupportedPolicyMessage(policy Policy, updateCommand string) string {
    if CanSatisfyPolicy(policy) {
        return ""
    }

var b strings.Builder
    fmt.Fprintf(&b, "[entire] This repository requires checkpoint support newer than this Entire CLI.\n[entire] Upgrade Entire, then rerun the command:\n[entire]   %%s\n", updateCommand)
    details := unsupportedPolicyDetails(policy)
    if len(details) == 0 {
        return b.String()
    }
    b.WriteString("[entire] Details:\n")
    for _, detail := range details {
        fmt.Fprintf(&b, "[entire]   %%s\n", detail)
    }
    return b.String()
}

func unsupportedPolicyDetails(policy Policy) []string {
    policy = Normalize(policy)
    var details []string

version, err := ParseFormat(policy.CheckpointVersion)
    if err != nil {
        details = append(details, fmt.Sprintf("checkpoint_version %%q is invalid: %%v.", policy.CheckpointVersion, err))
    } else if !CanWrite(version) {
        details = append(details, fmt.Sprintf("checkpoint_version %%q is not writable by this Entire CLI; this CLI defaults to %%q.", policy.CheckpointVersion, DefaultCheckpointVersion()))
    }

minVersion, err := ParseFormat(policy.CheckpointMinVersion)
    if err != nil {
        details = append(details, fmt.Sprintf("checkpoint_min_version %%q is invalid: %%v.", policy.CheckpointMinVersion, err))
    } else if !CanRead(minVersion) {
        details = append(details, fmt.Sprintf("checkpoint_min_version %%q is not readable by this Entire CLI; this CLI can read %%q.", policy.CheckpointMinVersion, DefaultCheckpointVersion()))
    }

return details
}

Mcmd/entire/cli/checkpointpolicy/policy.go+42/-2

35 unmodified lines

36
37
38
39
39
40
41
42
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
45
63
64
65
66
67
68
69
70
71
72

35 unmodified lines

}))
}

func TestUpgradeWarning(t *testing.T) {
func TestCanSatisfyPolicy(t *testing.T) {
    t.Parallel()

got := checkpointpolicy.UpgradeWarning("brew upgrade entire")
    require.True(t, checkpointpolicy.CanSatisfyPolicy(checkpointpolicy.DefaultPolicy()))
    require.True(t, checkpointpolicy.CanSatisfyPolicy(checkpointpolicy.Policy{}))
    require.False(t, checkpointpolicy.CanSatisfyPolicy(checkpointpolicy.Policy{
        CheckpointVersion:    "refs-v1",
        CheckpointMinVersion: checkpoint.CheckpointVersionBranchV1,
    }))
    require.False(t, checkpointpolicy.CanSatisfyPolicy(checkpointpolicy.Policy{
        CheckpointVersion:    checkpoint.CheckpointVersionBranchV1,
        CheckpointMinVersion: "refs-v1",
    }))
}

func TestUnsupportedPolicyMessageIncludesSettingDetails(t *testing.T) {
    t.Parallel()

got := checkpointpolicy.UnsupportedPolicyMessage(checkpointpolicy.Policy{
        CheckpointVersion:    "refs-v1",
        CheckpointMinVersion: "refs-v1",
    }, "brew upgrade entire")

require.Contains(t, got, "[entire] This repository requires checkpoint support newer than this Entire CLI.")
    require.Contains(t, got, "[entire] Upgrade Entire, then rerun the command:")
    require.Contains(t, got, "[entire]   brew upgrade entire")
    require.Contains(t, got, `checkpoint_version "refs-v1" is not writable by this Entire CLI`)
    require.Contains(t, got, `checkpoint_min_version "refs-v1" is not readable by this Entire CLI`)
}

func TestUnsupportedPolicyMessageEmptyForSatisfiedPolicy(t *testing.T) {
    t.Parallel()

require.Empty(t, checkpointpolicy.UnsupportedPolicyMessage(checkpointpolicy.DefaultPolicy(), "brew upgrade entire"))
}

Mcmd/entire/cli/checkpointpolicy/warning_test.go+28/-3

85 unmodified lines

86
87
88
89
89
90
91
92
93
94
95
96
96
97
98
99

85 unmodified lines

}

func warnIfCheckpointPolicyNeedsUpgrade(ctx context.Context, policy checkpointpolicy.Policy) {
    if !checkpointpolicy.UnsupportedWrite(policy) && !checkpointpolicy.RequiresUpgrade(policy) {
    if checkpointpolicy.CanSatisfyPolicy(policy) {
        return
    }
    warnOrLogCheckpointPolicyUpgrade(ctx, policy, checkpointpolicy.CheckpointVersion(policy))
}

func warnOrLogCheckpointPolicyUpgrade(ctx context.Context, policy checkpointpolicy.Policy, version string) {
    warning := checkpointpolicy.UpgradeWarning(versioncheck.UpdateCommandForCurrentBinary(versioninfo.Version))
    warning := checkpointpolicy.UnsupportedPolicyMessage(policy, versioncheck.UpdateCommandForCurrentBinary(versioninfo.Version))
    if interactive.CanPromptInteractively() {
        fmt.Fprint(stderrWriter, warning)
        return