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

Function TestCollectWorkflowFiles_AlwaysRecompiles

pkg/cli/run_push_test.go:499–559  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

497}
498
499func TestCollectWorkflowFiles_AlwaysRecompiles(t *testing.T) {
500 // Test that workflows are always recompiled, even when frontmatter hash matches
501 tmpDir := t.TempDir()
502
503 // Create a workflow file
504 workflowPath := filepath.Join(tmpDir, "test-workflow.md")
505 workflowContent := `---
506name: Test Workflow
507engine: copilot
508on: workflow_dispatch
509---
510# Test Workflow
511This is a test workflow.
512`
513 err := os.WriteFile(workflowPath, []byte(workflowContent), 0644)
514 require.NoError(t, err)
515
516 // Compute the correct hash for this workflow
517 cache := parser.NewImportCache("")
518 correctHash, err := parser.ComputeFrontmatterHashFromFile(workflowPath, cache)
519 require.NoError(t, err)
520 require.NotEmpty(t, correctHash)
521
522 // Create a lock file with the CORRECT hash (matching)
523 lockFilePath := filepath.Join(tmpDir, "test-workflow.lock.yml")
524 lockContent := fmt.Sprintf(`# frontmatter-hash: %s
525
526name: Test Workflow
527"on": workflow_dispatch
528jobs:
529 agent:
530 runs-on: ubuntu-latest
531 steps:
532 - name: Test
533 run: echo "test"
534`, correctHash)
535 err = os.WriteFile(lockFilePath, []byte(lockContent), 0644)
536 require.NoError(t, err)
537
538 // Record the modification time of the lock file before collection
539 lockStatBefore, err := os.Stat(lockFilePath)
540 require.NoError(t, err)
541 timeBefore := lockStatBefore.ModTime()
542
543 // Sleep to ensure modification time would change if file is rewritten
544 time.Sleep(100 * time.Millisecond)
545
546 // Collect workflow files (which should always trigger recompilation)
547 files, err := collectWorkflowFiles(context.Background(), workflowPath, false, false)
548 require.NoError(t, err)
549 assert.Len(t, files, 2, "Should collect workflow .md and .lock.yml files")
550
551 // Verify the lock file was recompiled (modification time should be newer)
552 lockStatAfter, err := os.Stat(lockFilePath)
553 require.NoError(t, err)
554 timeAfter := lockStatAfter.ModTime()
555
556 // The lock file should have been recompiled even though the hash matched

Callers

nothing calls this directly

Calls 4

NewImportCacheFunction · 0.92
collectWorkflowFilesFunction · 0.85
BackgroundMethod · 0.80

Tested by

no test coverage detected