policy: update unknown keys normalization

Make the code more unified between validation and
test command. Normalize to key without the input prefix.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
Tonis Tiigi
2026-02-09 18:27:35 -08:00
parent df542b3f80
commit 4e16277937
4 changed files with 104 additions and 29 deletions
+9 -1
View File
@@ -84,7 +84,7 @@ func runTest(ctx context.Context, out io.Writer, path string, opts policy.TestOp
_, _ = fmt.Fprintln(out, "decision: <nil>")
}
if len(result.MissingInput) > 0 {
_, _ = fmt.Fprintf(out, "missing_input: %s\n", strings.Join(result.MissingInput, ", "))
_, _ = fmt.Fprintf(out, "missing_input: %s\n", strings.Join(withInputPrefix(result.MissingInput), ", "))
}
if len(result.MetadataNeeded) > 0 {
_, _ = fmt.Fprintf(out, "metadata_resolve: %s\n", strings.Join(result.MetadataNeeded, ", "))
@@ -106,6 +106,14 @@ func writeJSON(out io.Writer, label string, v any) {
_, _ = fmt.Fprintf(out, "%s:\n%s\n", label, string(dt))
}
func withInputPrefix(keys []string) []string {
out := make([]string, len(keys))
for i, k := range keys {
out[i] = "input." + k
}
return out
}
type policyTestResolver struct {
dockerCli command.Cli
builderName *string