Skip to content

do a round of refactoring & cleanup - #200

Merged
theodore-s-beers merged 15 commits into
mainfrom
tsb_cleanup
Jul 29, 2026
Merged

do a round of refactoring & cleanup#200
theodore-s-beers merged 15 commits into
mainfrom
tsb_cleanup

Conversation

@theodore-s-beers

Copy link
Copy Markdown
Member

No description provided.

CopilotAI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR performs a refactor/cleanup pass across the CLI to improve reliability and safety: adding timeouts and output/body caps for external calls, tightening the local login HTTP handler, and persisting rotated credentials more consistently.

Changes:

  • Add timeouts and size limits around network requests, go-based version checks, and executed CLI commands (including capturing stderr separately).
  • Harden authentication/config handling (secure config file permissions, persist rotated tokens, make logout best-effort but still clear local credentials).
  • Improve local verification/rendering (render stderr, validate captured HTTP response variables, safer JSON interpolation).

Reviewed changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 2 comments.

Show a summary per file
FileDescription
version/version.goSwitch latest-version lookup to go list -m -json with a hard timeout.
version/version_test.goAdds tests for GOPROXY/timeout behavior of version lookup.
render/view.goDisplay CLI command stderr in verbose step rendering.
render/view_test.goExtends verbose view test expectations to include stderr output.
cmd/status.goUse shared credential refresh helper when validating auth status.
cmd/root.goDefer version lookup to a persistent pre-run, lock down config permissions, and centralize credential refresh/persistence.
cmd/root_test.goAdds coverage for config file permission hardening, version lookup timing, and credential persistence.
cmd/logout.goMake logout return errors on local write failures; best-effort server logout; remove auth prerequisite.
cmd/logout_test.goAdds coverage for logout clearing local creds even when server logout fails, and for write errors.
cmd/login.goHarden local login HTTP server: stricter CORS, body size limits, handler muxing, and clean shutdown.
cmd/login_test.goAdds unit tests for login handler origin checks and code-size limits.
client/lessons.goTrack stderr locally (omit from JSON) and serialize HTTP fetch errors via FetchErr.
client/lessons_test.goAdds JSON serialization tests for stderr omission and FetchErr behavior.
client/auth.goIntroduce a shared API HTTP client with timeout; add Logout() API helper.
client/auth_test.goAdds timeout behavior test for FetchAccessToken and client timeout config assertion.
checks/runner.goUse an HTTP client with an explicit timeout for lesson checks.
checks/local.goValidate that captured HTTP response variables/headers match the response content.
checks/local_test.goAdds coverage for rejecting stale/mismatched HTTP capture variables and allowing empty captures.
checks/http.goSafer JSON interpolation before marshalling; cap response-body reads; reuse truncation for parsing.
checks/http_test.goAdds tests for nested JSON interpolation safety, response-body cap, and timeout/client config.
checks/cli.goAdd execution timeout/output caps, separate stdout/stderr capture, and cancellation on excessive output.
checks/cli_test.goAdds tests for CLI timeouts, output caps, bounded buffer behavior, and stderr isolation.

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

Comment threadversion/version_test.go
Comment threadchecks/cli.go
@theodore-s-beers
theodore-s-beers merged commit dfe1d2a into mainJul 29, 2026
1 check passed
@theodore-s-beers
theodore-s-beers deleted the tsb_cleanup branch July 29, 2026 01:47
Sign up for freeto 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

@theodore-s-beers