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

Function TestFriendlyFormatDeterminism

pkg/workflow/schedule_preprocessing_test.go:1312–1415  ·  view source on GitHub ↗

TestFriendlyFormatDeterminism verifies that friendly format comments are generated deterministically and don't carry over between compilations

(t *testing.T)

Source from the content-addressed store, hash-verified

1310// TestFriendlyFormatDeterminism verifies that friendly format comments are generated
1311// deterministically and don't carry over between compilations
1312func TestFriendlyFormatDeterminism(t *testing.T) {
1313 // Create a compiler instance
1314 compiler := NewCompiler()
1315 compiler.SetWorkflowIdentifier("test-workflow.md")
1316
1317 // Frontmatter with daily schedule
1318 frontmatter1 := map[string]any{
1319 "on": map[string]any{
1320 "schedule": "daily",
1321 },
1322 }
1323
1324 // First compilation - preprocess schedule
1325 err := compiler.preprocessScheduleFields(frontmatter1, "test-workflow-1.md", "")
1326 if err != nil {
1327 t.Fatalf("failed to preprocess schedule: %v", err)
1328 }
1329
1330 // Verify friendly format was stored
1331 if len(compiler.scheduleFriendlyFormats) == 0 {
1332 t.Fatalf("expected friendly formats to be stored after preprocessing")
1333 }
1334
1335 firstFormat := compiler.scheduleFriendlyFormats[0]
1336 if !strings.Contains(firstFormat, "daily") {
1337 t.Errorf("expected friendly format to contain 'daily', got: %s", firstFormat)
1338 }
1339
1340 // Generate YAML for first compilation
1341 yamlStr1 := `"on":
1342 schedule:
1343 - cron: "30 13 * * *"
1344 workflow_dispatch:`
1345
1346 result1 := compiler.addFriendlyScheduleComments(yamlStr1, frontmatter1)
1347 if !strings.Contains(result1, "# Friendly format: daily (scattered)") {
1348 t.Errorf("expected friendly format comment in first compilation, got:\n%s", result1)
1349 }
1350
1351 // Second compilation with different frontmatter (weekly schedule)
1352 // Reset compiler state as would happen in a new compilation
1353 compiler.scheduleFriendlyFormats = nil
1354
1355 frontmatter2 := map[string]any{
1356 "on": map[string]any{
1357 "schedule": "weekly",
1358 },
1359 }
1360
1361 err = compiler.preprocessScheduleFields(frontmatter2, "test-workflow-2.md", "")
1362 if err != nil {
1363 t.Fatalf("failed to preprocess schedule: %v", err)
1364 }
1365
1366 // Verify friendly format was replaced, not appended
1367 if len(compiler.scheduleFriendlyFormats) == 0 {
1368 t.Fatalf("expected friendly formats to be stored after second preprocessing")
1369 }

Callers

nothing calls this directly

Calls 5

SetWorkflowIdentifierMethod · 0.95
NewCompilerFunction · 0.85
ErrorfMethod · 0.45

Tested by

no test coverage detected