MCPcopy Create free account
hub / github.com/github/gh-aw / TestActionKeyVersionConsistencyInJSON

Function TestActionKeyVersionConsistencyInJSON

pkg/cli/update_actions_test.go:75–112  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

73}
74
75func TestActionKeyVersionConsistencyInJSON(t *testing.T) {
76 // This test ensures that when actions-lock.json is saved to disk and reloaded,
77 // there are no key/version mismatches between the map key and the entry's Version field.
78
79 tmpDir := testutil.TempDir(t, "test-*")
80 cache := workflow.NewActionCache(tmpDir)
81 cache.Set("actions/checkout", "v5.0.1", "93cb6efe18208431cddfb8368fd83d5badbf9bfd")
82 cache.Set("actions/setup-node", "v6.1.0", "395ad3262231945c25e8478fd5baf05154b1d79f")
83
84 // Save to disk and reload to exercise the JSON round-trip.
85 if err := cache.Save(); err != nil {
86 t.Fatalf("Failed to save cache: %v", err)
87 }
88 reloaded := workflow.NewActionCache(tmpDir)
89 if err := reloaded.Load(); err != nil {
90 t.Fatalf("Failed to reload cache: %v", err)
91 }
92
93 // Verify all entries have matching key and version after a round-trip.
94 for key, entry := range reloaded.Entries {
95 // Extract version from key (format: "repo@version")
96 atIndex := len(key)
97 for i := len(key) - 1; i >= 0; i-- {
98 if key[i] == '@' {
99 atIndex = i
100 break
101 }
102 }
103
104 if atIndex < len(key) {
105 keyVersion := key[atIndex+1:]
106 if keyVersion != entry.Version {
107 t.Errorf("Key %q has version in key %q but entry version is %q - this mismatch causes version comments to change on each build",
108 key, keyVersion, entry.Version)
109 }
110 }
111 }
112}
113
114// TestUpdateActions_SafeOutputsInputsPreserved verifies that cached inputs and descriptions
115// for safe-outputs.actions entries are preserved in actions-lock.json when other (unrelated)

Callers

nothing calls this directly

Calls 6

SetMethod · 0.95
SaveMethod · 0.95
LoadMethod · 0.95
TempDirFunction · 0.92
NewActionCacheFunction · 0.92
ErrorfMethod · 0.45

Tested by

no test coverage detected