tests.test_gh module

Tests for repomatic.github.gh.

tests.test_gh.test_401_fallback_also_fails()

When fallback also fails, original 401 error is raised.

tests.test_gh.test_401_no_fallback(env, clear)

401 does not retry when fallback is unavailable.

tests.test_gh.test_401_requires_authentication_retries_with_github_token()

401 Requires authentication also triggers the GITHUB_TOKEN fallback.

Surfaces during GitHub auth incidents and from fine-grained PAT scope mismatches that GitHub treats as anonymous for the targeted resource.

tests.test_gh.test_401_retries_with_github_token()

401 Bad credentials triggers retry with GITHUB_TOKEN.

tests.test_gh.test_401_transient_clears_on_same_token_retry()

A 401 that clears on the same token resolves without falling back.

tests.test_gh.test_401_transient_retry_disabled_when_schedule_empty()

An empty backoff schedule disables the retry loop entirely.

tests.test_gh.test_401_transient_retry_exhausts_then_falls_back()

When every same-token retry returns 401, the cross-token fallback fires.

tests.test_gh.test_api_headers_follows_token_precedence(env, expected_token)

Direct API calls authenticate with the same winner the gh CLI gets.

tests.test_gh.test_api_headers_unauthenticated_without_token()

No token means no Authorization header, not an empty one.

tests.test_gh.test_bad_credentials_raises_without_waiting()

A revoked token fails on the first call instead of paying the back-off.

Bad credentials is deterministic: the same token cannot stop being revoked, so the same-token retry can only add idle seconds and flood the log with warnings that bury the real cause.

tests.test_gh.test_bad_credentials_still_reaches_cross_token_fallback()

Skipping the same-token wait does not skip the second credential.

GITHUB_TOKEN is issued by Actions itself, so it can succeed where a revoked PAT cannot: only the pointless wait is dropped, not the recovery.

tests.test_gh.test_command_error_defaults_its_stderr_to_the_message()

An error built from a message alone still reads its status off it.

tests.test_gh.test_command_error_tells_a_transient_failure(stderr, transient)

A server error, a rate limit, a cancelled stream or a TLS timeout may clear.

tests.test_gh.test_each_call_gets_its_timeout(transfer, constant)

A transfer of release assets runs under the longer timeout.

tests.test_gh.test_failure_carries_the_http_status(stderr, status)

The raised error keeps what a caller branches on, parsed once.

tests.test_gh.test_failure_message_includes_github_status_annotation()

A live githubstatus.com incident is appended to the raised RuntimeError.

tests.test_gh.test_failure_message_omits_status_when_no_incident()

The healthy status annotation (empty string) leaves the error untouched.

tests.test_gh.test_gh_api_pages_flattens_every_page(pages, key, expected)

Every page’s items come back as one list, in API order.

tests.test_gh.test_gh_api_pages_raises_when_gh_cannot_reach_the_endpoint()

A paginated read fails loudly: a missing page would corrupt the result.

tests.test_gh.test_gh_executable_falls_back_to_path(failure, caplog)

A download failure degrades to $PATH loudly, never stranding the job.

tests.test_gh.test_gh_executable_prefers_the_pinned_registry_binary()

The pinned, checksum-verified gh wins over whatever $PATH holds.

tests.test_gh.test_gh_graphql_partial_keeps_the_resolved_data()

With partial, the data printed beside the errors is the answer.

tests.test_gh.test_gh_graphql_passes_a_numeric_repository_name_as_a_string()

A repository named 2048 reaches a String! variable as a string.

tests.test_gh.test_gh_graphql_raises_without_usable_data(stdout, partial)

A failure with nothing to keep, or without partial, still raises.

tests.test_gh.test_gh_json_parses_the_output(soft)

A command printing JSON hands back the parsed value, soft or not.

tests.test_gh.test_gh_json_raises_unless_soft(patch_kwargs, error)

Both failure modes raise, and soft turns both into None.

tests.test_gh.test_gh_receives_the_winning_token(env, expected_token)

The resolve_gh_token() winner reaches gh as an explicit GH_TOKEN.

tests.test_gh.test_graphql_args_types_each_variable(value, flag)

--field would read 2048 as a number, so a string rides --raw-field.

tests.test_gh.test_graphql_retries_a_query_and_sends_a_mutation_once(query, attempts)

A mutation can have run before the server failed.

tests.test_gh.test_iter_graphql_nodes_follows_cursor()

Pagination follows endCursor until hasNextPage goes false.

tests.test_gh.test_iter_graphql_nodes_missing_connection_yields_nothing()

A response missing the connection path yields nothing and stops.

tests.test_gh.test_iter_graphql_nodes_sends_the_page_size_on_every_request()

Each page asks for the same size, as a typed field.

tests.test_gh.test_iter_graphql_nodes_single_page()

A single page yields its nodes and stops without a cursor request.

tests.test_gh.test_iter_graphql_nodes_skips_null_nodes()

Null nodes (as the search connection can emit) are dropped.

tests.test_gh.test_iter_graphql_nodes_variable_flags()

String variables pass with -f, ints and bools with -F.

tests.test_gh.test_json_read_clears_on_retry(stderr)

A read runs again after a failure on GitHub’s side.

tests.test_gh.test_no_literal_gh_json_call_writes()

gh_json retries a server error by default, so a write must opt out.

Reads each literal argument list in the package. A list built elsewhere is not checked, and gh_graphql() clears the retry for a mutation itself.

tests.test_gh.test_non_401_error_no_fallback()

Non-401 errors raise immediately without retry.

tests.test_gh.test_non_401_skips_transient_retry()

Non-401 failures bypass the transient-retry loop and raise immediately.

tests.test_gh.test_parse_create_output(output, kind, expected)
tests.test_gh.test_parse_create_output_rejects_unparsable_output(output, kind)
tests.test_gh.test_repomatic_pat_401_falls_back_to_github_token()

Expired REPOMATIC_PAT falls back to GITHUB_TOKEN.

tests.test_gh.test_run_gh_command_reports_a_gh_that_cannot_start()

A missing binary raises the error every caller of gh already handles.

tests.test_gh.test_secondary_limit_clears_on_same_token_retry()

A throttled call that clears on the same token resolves without fallback.

tests.test_gh.test_secondary_limit_retry_exhausts_then_raises()

An exhausted throttle schedule raises, without the cross-token fallback.

A throttled token is not a wrong one: swapping credentials against an abuse-detection refusal would only spread the burst across two identities, so the fallback stays scoped to auth markers.

tests.test_gh.test_server_error_clears_on_retry_of_an_idempotent_command(stderr)

An idempotent command runs again after a failure on GitHub’s side.

tests.test_gh.test_server_error_is_not_retried_by_default(stderr)

A command not marked idempotent may have run, so it is not sent again.

tests.test_gh.test_stalled_call_is_stopped_at_its_timeout()

A call past its timeout is killed, and fails as a transient error.

A Python process that sleeps stands in for a stalled gh, so the real subprocess.run replaces the suite’s refusal stub.

tests.test_gh.test_success_no_fallback()

Successful commands never trigger fallback.

tests.test_gh.test_timed_out_command_error_is_transient()

A call stopped at its timeout may succeed on a new connection.