Skip to content

Migrate internal/auth and internal/output to consume shared basecamp/cli module#192

Merged
jeremy merged 5 commits intomainfrom
rubric
Mar 5, 2026
Merged

Migrate internal/auth and internal/output to consume shared basecamp/cli module#192
jeremy merged 5 commits intomainfrom
rubric

Conversation

@jeremy
Copy link
Copy Markdown
Member

@jeremy jeremy commented Mar 5, 2026

What

Consume github.com/basecamp/cli v0.1.0 (merged in basecamp/cli#1) from basecamp-cli, validating the extraction and eliminating ~580 lines of duplicated code.

Changes

  1. Add shared module dependency — pins github.com/basecamp/cli@v0.1.0
  2. Migrate internal/output — re-exports exit codes, error codes, ExitCodeFor, NormalizeData, TruncationNotice, TruncationNoticeWithTotal via immutable wrapper functions. Type-aliases Error for zero-cost errors.As compatibility. Keeps ErrAuth and ErrForbiddenScope local (app-specific hint strings).
  3. Migrate internal/auth — replaces keyring implementation (~230→70 lines) with a typed wrapper around credstore.Store. Replaces PKCE helpers with pkce.GenerateVerifier/Challenge/State. Replaces waitForCallback with inline listener + oauthcallback.WaitForCallback (with 5-minute timeout preserved).

What stays local

  • surface — fundamentally different approach (Go library walks cobra tree in-process vs. shell scripts invoke binary)
  • profile — tightly integrated into basecamp-cli's config system
  • ErrAuth/ErrForbiddenScope — app-specific hint strings
  • Credentials struct, Response/ErrorResponse envelopes, presenter, TUI, renderer — app-specific

Verification

  • make check passes (fmt, vet, lint, test, e2e, naming, surface, provenance, tidy)
  • All 257 e2e tests pass
  • go-keyring remains a direct dependency (still imported by doctor.go and migrate.go for keyring availability checks)
  • go mod tidy is idempotent

jeremy added 2 commits March 4, 2026 18:01
Pin to v0.0.0-20260305004813-bc5ad283b855 (bc5ad28, main HEAD after
PR #1 merge). Provides output, credstore, pkce, and oauthcallback
packages extracted from this repo.
Re-export exit codes, error codes, ExitCodeFor, NormalizeData,
TruncationNotice, and TruncationNoticeWithTotal from the shared module.
Type-alias Error for zero-cost compatibility with errors.As.

ErrAuth and ErrForbiddenScope stay local (app-specific hint strings).
Deletes ~330 lines of duplicated code including NormalizeData helpers,
unmarshalPreservingNumbers, normalizeUnmarshaled, and the corresponding
BenchmarkNormalizeUnmarshaled (now covered by shared module tests).
Copilot AI review requested due to automatic review settings March 5, 2026 02:27
@github-actions github-actions bot added tests Tests (unit and e2e) auth OAuth authentication output Output formatting and presentation deps enhancement New feature or request labels Mar 5, 2026
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

Migrates internal/output and internal/auth to consume the newly extracted shared module github.com/basecamp/cli, reducing duplicated code and keeping Basecamp CLI’s app-specific behavior where needed.

Changes:

  • Add github.com/basecamp/cli dependency and re-export shared output error/codes/normalization helpers.
  • Replace the local keyring/file credential store with a typed wrapper around credstore.Store.
  • Replace in-repo PKCE and callback-wait logic with shared pkce and oauthcallback utilities.

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
internal/output/errors.go Type-aliases shared output.Error and re-exports shared error constructors + AsError, keeping app-specific auth/scope hints local.
internal/output/codes.go Re-exports shared exit codes, error codes, and ExitCodeFor.
internal/output/envelope.go Re-exports shared NormalizeData and truncation notice helpers; removes local implementations.
internal/output/envelope_benchmark_test.go Removes benchmarks tied to deleted local normalization helpers.
internal/auth/keyring.go Replaces local keyring + file fallback implementation with a typed wrapper over credstore.Store.
internal/auth/auth.go Switches PKCE/state generation and OAuth callback waiting to shared pkce/oauthcallback.
internal/auth/auth_test.go Updates tests to use the new store wrapper; removes tests for deleted local PKCE/key helpers and file-permission/atomic-write details.
go.mod Adds github.com/basecamp/cli dependency.
go.sum Adds checksums for github.com/basecamp/cli.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/auth/auth.go Outdated
Replace keyring.go implementation (~230 lines of keyring probing, file
I/O, atomic writes, Windows workarounds) with a typed wrapper around
credstore.Store (~70 lines). Credentials struct and Store API unchanged.

Replace PKCE helpers (generateCodeVerifier/Challenge/State) with
pkce.GenerateVerifier/Challenge/State. Replace waitForCallback with
inline listener creation + oauthcallback.WaitForCallback.

Delete tests for removed unexported functions (TestGenerateCodeVerifier,
TestGenerateCodeChallenge, TestGenerateState, TestKeyFunction). Update
remaining tests to construct Store via newTestStore helper.
Replaces pseudo-version v0.0.0-20260305004813-bc5ad283b855.
Same code (bc5ad28), proper semver tag.
Copilot AI review requested due to automatic review settings March 5, 2026 02:40
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

Copilot reviewed 8 out of 9 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (1)

internal/auth/auth_test.go:35

  • TestNewStore() calls NewStore() without disabling the keyring, so the test’s behavior can vary by environment and may touch the user/system keychain (or require desktop services like DBus). Consider setting BASECAMP_NO_KEYRING in this test (or using newTestStore) so unit tests are deterministic and avoid side effects.
func TestNewStore(t *testing.T) {
	tmpDir := t.TempDir()
	store := NewStore(tmpDir)

	// Store should be created (may or may not use keyring depending on system)
	require.NotNil(t, store, "NewStore returned nil")
}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread go.mod
Comment thread internal/output/codes.go Outdated
Comment thread internal/output/envelope.go Outdated
Mutable vars allow accidental reassignment from other packages in
the module. Thin wrapper functions preserve immutability while
delegating to the shared module.
@jeremy jeremy merged commit e1d4104 into main Mar 5, 2026
21 checks passed
@jeremy jeremy deleted the rubric branch March 5, 2026 02:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auth OAuth authentication deps enhancement New feature or request output Output formatting and presentation tests Tests (unit and e2e)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants