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

Function TestAddWorkflowWithTracking_SourceFieldVariants

pkg/cli/add_command_test.go:397–491  ·  view source on GitHub ↗

TestAddWorkflowWithTracking_SourceFieldVariants covers the main combinations of local / remote specs and fallback-path resolution for the source: frontmatter field written by addWorkflowWithTracking.

(t *testing.T)

Source from the content-addressed store, hash-verified

395// remote specs and fallback-path resolution for the source: frontmatter field written by
396// addWorkflowWithTracking.
397func TestAddWorkflowWithTracking_SourceFieldVariants(t *testing.T) {
398 simpleContent := []byte("---\non: push\n---\n\n# Workflow\n")
399 const sha = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
400
401 tests := []struct {
402 name string
403 spec *WorkflowSpec
404 sourceInfo *FetchedWorkflow
405 wantContains string
406 wantNotContains string
407 }{
408 {
409 // Local workflows must NOT get a source: field — the code guards on !sourceInfo.IsLocal.
410 name: "local workflow — no source field written",
411 spec: &WorkflowSpec{
412 RepoSpec: RepoSpec{RepoSlug: ""},
413 WorkflowPath: "./local-workflow.md",
414 WorkflowName: "local-workflow",
415 },
416 sourceInfo: &FetchedWorkflow{
417 Content: simpleContent,
418 CommitSHA: "",
419 IsLocal: true,
420 SourcePath: "./local-workflow.md",
421 },
422 wantContains: "",
423 wantNotContains: "source:",
424 },
425 {
426 // Remote workflow where the parsed spec path already matches SourcePath
427 // (no fallback triggered). The source: field must use the original path.
428 name: "remote workflow — no fallback, path matches SourcePath",
429 spec: &WorkflowSpec{
430 RepoSpec: RepoSpec{RepoSlug: "owner/repo", Version: "main"},
431 WorkflowPath: ".github/workflows/my-workflow.md",
432 WorkflowName: "my-workflow",
433 },
434 sourceInfo: &FetchedWorkflow{
435 Content: simpleContent,
436 CommitSHA: sha,
437 IsLocal: false,
438 SourcePath: ".github/workflows/my-workflow.md", // identical — no fallback
439 },
440 wantContains: "source: owner/repo/.github/workflows/my-workflow.md@" + sha,
441 wantNotContains: "",
442 },
443 {
444 // Remote workflow from the *current* repository (self-referential) where
445 // the spec only carries the short name but the file lives under
446 // .github/workflows/. Fallback resolution must be reflected in source:.
447 name: "self-referential remote — fallback path resolution",
448 spec: &WorkflowSpec{
449 RepoSpec: RepoSpec{RepoSlug: "current-org/current-repo", Version: "main"},
450 WorkflowPath: "my-workflow.md", // short-form from parsed spec
451 WorkflowName: "my-workflow",
452 },
453 sourceInfo: &FetchedWorkflow{
454 Content: simpleContent,

Callers

nothing calls this directly

Calls 5

TempDirFunction · 0.92
setupMinimalGitRepoFunction · 0.85
addWorkflowWithTrackingFunction · 0.85
BackgroundMethod · 0.80
RunMethod · 0.45

Tested by

no test coverage detected