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

Function TestUpdateCacheMemoryJobHasWorkflowIDEnv

pkg/workflow/compiler_jobs_test.go:2238–2283  ·  view source on GitHub ↗

TestUpdateCacheMemoryJobHasWorkflowIDEnv verifies that the update_cache_memory job includes GH_AW_WORKFLOW_ID_SANITIZED in its env block so cache keys match the agent job.

(t *testing.T)

Source from the content-addressed store, hash-verified

2236// TestUpdateCacheMemoryJobHasWorkflowIDEnv verifies that the update_cache_memory job
2237// includes GH_AW_WORKFLOW_ID_SANITIZED in its env block so cache keys match the agent job.
2238func TestUpdateCacheMemoryJobHasWorkflowIDEnv(t *testing.T) {
2239 compiler := NewCompiler()
2240 compiler.jobManager = NewJobManager()
2241
2242 data := &WorkflowData{
2243 Name: "Test Workflow",
2244 WorkflowID: "daily-repo-status",
2245 AI: "copilot",
2246 RunsOn: "runs-on: ubuntu-latest",
2247 CacheMemoryConfig: &CacheMemoryConfig{
2248 Caches: []CacheMemoryEntry{
2249 {ID: "default"},
2250 },
2251 },
2252 SafeOutputs: &SafeOutputsConfig{
2253 ThreatDetection: &ThreatDetectionConfig{},
2254 },
2255 }
2256
2257 compiler.stepOrderTracker = NewStepOrderTracker()
2258 activationJob, _ := compiler.buildActivationJob(data, false, "", "test.lock.yml")
2259 compiler.jobManager.AddJob(activationJob)
2260
2261 agentJob, _ := compiler.buildMainJob(data, true)
2262 compiler.jobManager.AddJob(agentJob)
2263
2264 compiler.buildSafeOutputsJobs(data, string(constants.AgentJobName), "test.md")
2265
2266 updateCacheMemoryJob, err := compiler.buildUpdateCacheMemoryJob(data, true)
2267 if err != nil {
2268 t.Fatalf("buildUpdateCacheMemoryJob() error: %v", err)
2269 }
2270 if updateCacheMemoryJob == nil {
2271 t.Fatal("Expected update_cache_memory job to be created")
2272 }
2273
2274 // GH_AW_WORKFLOW_ID_SANITIZED must be present so the save key matches the restore key
2275 sanitizedID, ok := updateCacheMemoryJob.Env["GH_AW_WORKFLOW_ID_SANITIZED"]
2276 if !ok {
2277 t.Error("update_cache_memory job is missing GH_AW_WORKFLOW_ID_SANITIZED env var; cache keys will not match")
2278 }
2279 // "daily-repo-status" -> lowercase + hyphens removed -> "dailyrepostatus"
2280 if sanitizedID != "dailyrepostatus" {
2281 t.Errorf("GH_AW_WORKFLOW_ID_SANITIZED = %q, want %q", sanitizedID, "dailyrepostatus")
2282 }
2283}
2284
2285// TestUpdateCacheMemoryJobConditionRequiresAgentSuccess verifies that the update_cache_memory
2286// job condition requires the agent job to have succeeded (not just not be skipped).

Callers

nothing calls this directly

Calls 10

buildActivationJobMethod · 0.95
buildMainJobMethod · 0.95
buildSafeOutputsJobsMethod · 0.95
NewCompilerFunction · 0.85
NewJobManagerFunction · 0.85
NewStepOrderTrackerFunction · 0.85
AddJobMethod · 0.80
ErrorMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected