Skip to content

Commit 803cd5e

Browse files
committed
shell: use gh CLI auth for live scenarios, add auth command
Live scenarios no longer require GH_TOKEN to be explicitly exported. The binary's go-gh library resolves auth from gh CLI config automatically. The harness now only sets GH_TOKEN when the env var is present — otherwise it lets go-gh use 'gh auth token'. The 'auth' command shows current auth source: GH_TOKEN env, GITHUB_TOKEN env, or gh CLI credential.
1 parent 4c3d82f commit 803cd5e

2 files changed

Lines changed: 41 additions & 6 deletions

File tree

test/integration/harness.rb

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,10 +341,13 @@ def prepare_live(binary, profile_dir: nil)
341341

342342
# Batch mode: capture output, run assertions.
343343
def run(binary, profile_dir: nil)
344-
# Live repo scenarios need a token
344+
# Live repo scenarios need auth — explicit token or gh CLI
345345
if @live_repo
346-
token = ENV["GH_TOKEN"] || ENV["GITHUB_TOKEN"] || ""
347-
raise SkipScenario, "no GH_TOKEN" if token.empty?
346+
token = ENV["GH_TOKEN"] || ENV["GITHUB_TOKEN"]
347+
if token.nil? || token.empty?
348+
gh_token = `gh auth token 2>/dev/null`.strip
349+
raise SkipScenario, "no GH_TOKEN or gh auth" if gh_token.empty?
350+
end
348351
end
349352

350353
ctx = prepare(binary, profile_dir: profile_dir)
@@ -587,12 +590,13 @@ def shell
587590
puts " \e[36mcd <name>\e[0m Prepare scenario and drop into its dir"
588591
puts " \e[36mpause\e[0m Toggle pause between scenarios in run-all"
589592
puts " \e[36mprofile [dir|off]\e[0m Toggle profiling (default: ./profiles)"
593+
puts " \e[36mauth\e[0m Show current auth source"
590594
puts " \e[36mquit\e[0m Exit"
591595
puts
592596

593597
active_ctx = nil
594598
scenario_names = @scenarios.map { |s| s.name.to_s }
595-
commands = %w[list ls run test inspect diff cd rerun pause profile quit exit q]
599+
commands = %w[list ls run test inspect diff cd rerun pause profile auth quit exit q]
596600

597601
# Tab completion: commands first, then scenario names for run/test/inspect/cd
598602
Reline.completion_proc = proc do |input|
@@ -735,6 +739,24 @@ def shell
735739
puts "No scenario dir available. Run a scenario first."
736740
end
737741

742+
when "auth"
743+
gh_token = ENV["GH_TOKEN"]
744+
github_token = ENV["GITHUB_TOKEN"]
745+
gh_cli = `gh auth token 2>/dev/null`.strip
746+
gh_user = `gh auth status 2>&1`.lines.grep(/Logged in/).first&.strip
747+
748+
if gh_token && !gh_token.empty?
749+
puts " \e[32mGH_TOKEN\e[0m env var set (#{gh_token[0..7]}…)"
750+
elsif github_token && !github_token.empty?
751+
puts " \e[32mGITHUB_TOKEN\e[0m env var set (#{github_token[0..7]}…)"
752+
elsif !gh_cli.empty?
753+
puts " \e[32mgh CLI\e[0m auth (#{gh_cli[0..7]}…)"
754+
puts " #{gh_user}" if gh_user
755+
else
756+
puts " \e[31mno auth\e[0m — live scenarios will be skipped"
757+
puts " Set GH_TOKEN or run: gh auth login"
758+
end
759+
738760
else
739761
puts "Unknown command: #{verb}. Type \e[36mlist\e[0m for scenarios."
740762
end

test/integration/run.rb

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,22 @@ def hydrate_assertions(s, expect, needs_token: false)
353353
# CLI flags
354354
s.args(*flags) unless flags.empty?
355355

356-
# Token-required scenarios pass the real token (or skip)
356+
# Token-required scenarios: use explicit GH_TOKEN if set, otherwise
357+
# fall back to gh CLI auth (go-gh resolves this automatically).
358+
# Only skip if neither is available.
357359
if needs_token
358-
s.env("GH_TOKEN" => ENV["GH_TOKEN"] || ENV["GITHUB_TOKEN"] || "")
360+
token = ENV["GH_TOKEN"] || ENV["GITHUB_TOKEN"]
361+
if token
362+
s.env("GH_TOKEN" => token)
363+
else
364+
# Check gh CLI auth — the binary will use this automatically,
365+
# but we need to verify it exists so we can skip gracefully.
366+
gh_token = `gh auth token 2>/dev/null`.strip
367+
if gh_token.empty?
368+
# No auth at all — scenario will be skipped at run time
369+
end
370+
# Don't set GH_TOKEN — let go-gh resolve from gh CLI config
371+
end
359372
end
360373

361374
# Live repo scenarios clone and run against a real repo

0 commit comments

Comments
 (0)