|
| 1 | +// ABOUTME: AC-1/AC-2/AC-3 — the --team-name-on-claude stderr advisory fires on the |
| 2 | +// ABOUTME: legacy arm, is silent on the merged arm, and the --help docs the shape flags. |
| 3 | +package dispatch |
| 4 | + |
| 5 | +import ( |
| 6 | + "encoding/json" |
| 7 | + "strings" |
| 8 | + "testing" |
| 9 | +) |
| 10 | + |
| 11 | +// teamNameAdvisoryMarker is a stable fragment of the legacy --team-name advisory. |
| 12 | +// The gate keys on its presence/absence rather than the full sentence so a future |
| 13 | +// wording tweak in claudeteam.LegacyTeamNameAdvisory does not break the test |
| 14 | +// (matches the advisoryMarker convention in build_advisory_probe_test.go). |
| 15 | +const teamNameAdvisoryMarker = "legacy TeamCreate-registry dispatch shape" |
| 16 | + |
| 17 | +// TestBuildLegacyTeamNameAdvisory is AC-1's behavioral gate: on host=claude, a |
| 18 | +// build that passes team_name emits exactly the legacy advisory on stderr while |
| 19 | +// the same inputs WITHOUT team_name (the merged shape) emit none. The legacy arm |
| 20 | +// also re-asserts the legacy envelope shape on stdout (team_name present, |
| 21 | +// run_in_background absent) — AC-3 in the same arm: the advisory is stderr-only |
| 22 | +// and does not flip the emitted dispatch envelope. |
| 23 | +func TestBuildLegacyTeamNameAdvisory(t *testing.T) { |
| 24 | + home := t.TempDir() |
| 25 | + t.Setenv("HOME", home) |
| 26 | + root := t.TempDir() |
| 27 | + wd := writeGood(t, root) |
| 28 | + ep := writeFlatEntity(t, wd, "backlog", "") |
| 29 | + |
| 30 | + legacyStdin := mergeStdin(map[string]any{ |
| 31 | + "schema_version": 2, |
| 32 | + "entity_path": ep, |
| 33 | + "workflow_dir": wd, |
| 34 | + "stage": "backlog", |
| 35 | + "checklist": []string{"- a"}, |
| 36 | + "host": "claude", |
| 37 | + "team_name": "fixture-team", |
| 38 | + "bare_mode": false, |
| 39 | + }, nil) |
| 40 | + mergedStdin := mergeStdin(map[string]any{ |
| 41 | + "schema_version": 2, |
| 42 | + "entity_path": ep, |
| 43 | + "workflow_dir": wd, |
| 44 | + "stage": "backlog", |
| 45 | + "checklist": []string{"- a"}, |
| 46 | + "host": "claude", |
| 47 | + "bare_mode": false, |
| 48 | + // team_name intentionally absent: the merged .178+ shape. |
| 49 | + }, nil) |
| 50 | + |
| 51 | + legacy := runNative(legacyStdin, "build", "--workflow-dir", wd) |
| 52 | + if legacy.exit != 0 { |
| 53 | + t.Fatalf("legacy --team-name build exit=%d, want 0\nstderr:\n%s", legacy.exit, legacy.stderr) |
| 54 | + } |
| 55 | + merged := runNative(mergedStdin, "build", "--workflow-dir", wd) |
| 56 | + if merged.exit != 0 { |
| 57 | + t.Fatalf("merged build exit=%d, want 0\nstderr:\n%s", merged.exit, merged.stderr) |
| 58 | + } |
| 59 | + |
| 60 | + // AC-1: advisory PRESENT on the --team-name arm, ABSENT on the merged arm. |
| 61 | + if !strings.Contains(legacy.stderr, teamNameAdvisoryMarker) { |
| 62 | + t.Errorf("host=claude --team-name build must emit the legacy advisory; stderr=%q", legacy.stderr) |
| 63 | + } |
| 64 | + if strings.Contains(merged.stderr, teamNameAdvisoryMarker) { |
| 65 | + t.Errorf("merged build (no --team-name) must emit NO legacy advisory; stderr=%q", merged.stderr) |
| 66 | + } |
| 67 | + // Exactly one advisory line on the legacy arm (not one per nothing). |
| 68 | + if got := strings.Count(legacy.stderr, teamNameAdvisoryMarker); got != 1 { |
| 69 | + t.Errorf("legacy advisory must appear exactly once; got %d:\n%s", got, legacy.stderr) |
| 70 | + } |
| 71 | + |
| 72 | + // AC-3 (same arm): the legacy envelope shape is unchanged by the advisory — |
| 73 | + // team_name present, run_in_background absent on the --team-name arm; and the |
| 74 | + // merged arm keeps run_in_background present, team_name absent. |
| 75 | + var legacyOut mergedBuildOutput |
| 76 | + if err := json.Unmarshal([]byte(legacy.stdout), &legacyOut); err != nil { |
| 77 | + t.Fatalf("legacy stdout is not build JSON: %v\n%s", err, legacy.stdout) |
| 78 | + } |
| 79 | + if legacyOut.TeamName == nil || *legacyOut.TeamName != "fixture-team" { |
| 80 | + t.Errorf("legacy --team-name envelope must keep team_name=%q; got %v", "fixture-team", legacyOut.TeamName) |
| 81 | + } |
| 82 | + if legacyOut.RunInBackground != nil { |
| 83 | + t.Errorf("legacy --team-name envelope must NOT gain run_in_background; got %v", *legacyOut.RunInBackground) |
| 84 | + } |
| 85 | + var mergedOut mergedBuildOutput |
| 86 | + if err := json.Unmarshal([]byte(merged.stdout), &mergedOut); err != nil { |
| 87 | + t.Fatalf("merged stdout is not build JSON: %v\n%s", err, merged.stdout) |
| 88 | + } |
| 89 | + if mergedOut.TeamName != nil { |
| 90 | + t.Errorf("merged envelope must omit team_name; got %q", *mergedOut.TeamName) |
| 91 | + } |
| 92 | + if mergedOut.RunInBackground == nil || !*mergedOut.RunInBackground { |
| 93 | + t.Errorf("merged envelope must keep run_in_background=true; got %v", mergedOut.RunInBackground) |
| 94 | + } |
| 95 | +} |
| 96 | + |
| 97 | +// TestBuildHelpDocumentsShapeFlags is AC-2's golden: dispatch build --help stdout |
| 98 | +// documents the shape-selecting flags (--host, --team-name, --bare-mode), with the |
| 99 | +// --team-name line naming the legacy shape and the auto-team default. Behavioral: |
| 100 | +// it runs the command and reads stdout, not a source grep. |
| 101 | +func TestBuildHelpDocumentsShapeFlags(t *testing.T) { |
| 102 | + res := runNative("", "build", "--help") |
| 103 | + if res.exit != 0 { |
| 104 | + t.Fatalf("dispatch build --help exit=%d, want 0\nstderr=%q", res.exit, res.stderr) |
| 105 | + } |
| 106 | + if res.stderr != "" { |
| 107 | + t.Fatalf("dispatch build --help stderr=%q, want empty", res.stderr) |
| 108 | + } |
| 109 | + assertContainsAll(t, res.stdout, |
| 110 | + "--host", |
| 111 | + "--team-name", |
| 112 | + "--bare-mode", |
| 113 | + "legacy TeamCreate-registry dispatch shape", |
| 114 | + "auto-team is the default", |
| 115 | + ) |
| 116 | +} |
0 commit comments