Skip to content

feat(B-0581): decompose slice 1 (gh auth refresh wrapper basics)#3970

Closed
AceHack wants to merge 2 commits into
mainfrom
lior/decompose-b0581-slice1-v3
Closed

feat(B-0581): decompose slice 1 (gh auth refresh wrapper basics)#3970
AceHack wants to merge 2 commits into
mainfrom
lior/decompose-b0581-slice1-v3

Conversation

@AceHack
Copy link
Copy Markdown
Member

@AceHack AceHack commented May 16, 2026

Decomposes B-0581 into active slice 1: basic wrapper script to spawn gh auth refresh, pipe stdin to handle the Y/n prompt, and extract the one-time code via regex.

Copilot AI review requested due to automatic review settings May 16, 2026 23:22
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 83988bb21b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tools/auth/gh-auth-refresh-wrapper.ts Outdated
Comment on lines +32 to +33
if (text.includes("Authenticate Git with your GitHub credentials?")) {
console.log("\n[gh-auth-refresh-wrapper] Auto-answering 'Y' to auth prompt...");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Buffer stream text before matching auth prompt

The auto-confirm logic only checks each individual chunk with text.includes(...), but stream chunking is arbitrary and the prompt text can be split across adjacent reads. In that case the Y response is never sent, gh auth refresh stays blocked on confirmation, and the wrapper hangs instead of completing the refresh flow. Keep a rolling buffer (or line-based parser) so prompt detection works across chunk boundaries.

Useful? React with 👍 / 👎.

Comment thread tools/auth/gh-auth-refresh-wrapper.ts Outdated
Comment on lines +51 to +55
processStream().catch(console.error);

const exitCode = await proc.exited;
console.log(`[gh-auth-refresh-wrapper] gh process exited with code ${exitCode}`);
process.exit(exitCode);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Await stdout drain before exiting wrapper

processStream() is launched without awaiting completion, then the script exits immediately after proc.exited. If gh exits before all piped stdout bytes are consumed, the wrapper can terminate early and miss final output (including the one-time code line), making capture nondeterministic. Await the stream-processing task before calling process.exit.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds the first slice of B-0581: a Bun-based wrapper around gh auth refresh that auto-answers the GitHub auth prompt and extracts the one-time code from streamed output.

Changes:

  • Adds a new tools/auth/gh-auth-refresh-wrapper.ts script.
  • Spawns gh auth refresh with requested scopes and piped stdin/stdout.
  • Parses stdout for the auth prompt and one-time device code.
Comments suppressed due to low confidence (2)

tools/auth/gh-auth-refresh-wrapper.ts:55

  • The stdout reader is started but never awaited; after proc.exited resolves, process.exit can terminate the wrapper before buffered stdout has been drained and before the one-time code is printed. Await the stream-processing task (or coordinate it with the subprocess exit) before exiting so the captured code is not lost at the end of the gh run.
  processStream().catch(console.error);

  const exitCode = await proc.exited;
  console.log(`[gh-auth-refresh-wrapper] gh process exited with code ${exitCode}`);
  process.exit(exitCode);

tools/auth/gh-auth-refresh-wrapper.ts:39

  • The one-time-code regex only runs against a single stdout chunk, so a chunk boundary between one-time code: and the code (or within the code) causes the wrapper to miss the value entirely. Accumulate recent output and match against that buffer so extraction is reliable for streamed subprocess output.
      const codeMatch = text.match(/one-time code:\s*([A-Z0-9\-]+)/i);

process.exit(1);
}

const scopes = args[0];
Comment thread tools/auth/gh-auth-refresh-wrapper.ts Outdated
process.stdout.write(text);

// Look for the Yes/No prompt
if (text.includes("Authenticate Git with your GitHub credentials?")) {
@AceHack
Copy link
Copy Markdown
Member Author

AceHack commented May 22, 2026

I have fixed the TypeScript errors and other issues in this PR. The checks should now pass.

@AceHack
Copy link
Copy Markdown
Member Author

AceHack commented May 23, 2026

Substrate-honest close per stale-armed-PR resolution case 1. B-0581 was RE-LANDED via #4754 (2026-05-23) which supersedes the stale #3961 line entirely. The wrapper basics this PR ships are now in the merged RE-LAND. DIRTY since 2026-05-16.

@AceHack AceHack closed this May 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants