Repository navigation
test: add credential-free tests for calls only covered by live tests - #231
Open
ffumero2003 wants to merge 25 commits into
Open
ffumero2003 wants to merge 25 commits into
ffumero2003 wants to merge 25 commits into
Conversation
…e tests Several tests pass while blazer sends the wrong request to B2, because each wire test builds its own fake server and most accept any body. Capture the problem and the outcome for a shared test helper before writing a spec. Refs #191
Spec R1-R12 define the internal/b2wiretest helper: recording, scripted responses, upload URLs and assertions, with no new dependencies and no public API. The plan orders the work, names a test per requirement and the break each test must catch. Refs #191
Assert that Stall returns before its duration when the request context ends. Align R5 with the separate ListKeys capabilities work in #220.
Treat scripted status zero as 200, reject empty JSON assertion paths consistently, and mark the server closed before draining HTTP handlers so late requests cannot report through a completed test. Document the path and header guarantees, the migrated test coverage, and the simulator contract NOT RUN rationale requested in PR #205.
serve and copyRequests both decoded a request body into a JSON map. Share one decodeJSON helper so the two paths cannot drift; a body that is not a JSON object still decodes to nil. The same change was reviewed on #211.
…server' into test-issue-203-credential-free-live-calls
Base automatically changed from
test-issue-191-shared-recording-server
to
main
October 29, 2026 21:22
…tial-free-live-calls
…tial-free-live-calls
…s on short bodies Script newest-first and older versions for Reveal, and ensure AfterNBytes does not trigger when a request body ends before its threshold. Part of #203
There was a problem hiding this comment.
🟡 Changes recommended
The AfterNBytes tests do not verify one-shot behavior across requests on the same transport or response-byte counting, allowing regressions in both behaviors to pass unnoticed.
2 open issues
What changed in this PR
2 Important, 0 Nit, 0 Pre-existing.
Adds credential-free coverage for previously live-only B2 calls and transport fault helpers, supporting #203 and the test-integrity audit in #97. Production code and live tests remain unchanged.
Changes:
- Adds wire tests for hide/reveal, download authorization, key listing/deletion, and large-file cancellation.
- Tests upload error classification, cancellation, deadlines, TLS rejection, and transport helpers.
- Records requirements, scope, and verification plans.
Checked the supplied changes against the requirements and transport implementation; tests were not run during this review. A human code owner must review the base-layer wire and authorization coverage.
| File | Description |
|---|---|
x/transport/transport_test.go |
Adds credential-free tests for transport fault helpers. |
intent/credential-free-live-calls/spec.md |
Defines behavior and coverage requirements. |
intent/credential-free-live-calls/plan.md |
Records implementation order and mutation checks. |
intent/credential-free-live-calls/intent.md |
Establishes the test-only scope and constraints. |
base/live_only_calls_test.go |
Covers upload faults, context errors, and untrusted certificates. |
b2/live_only_calls_wire_test.go |
Verifies public API requests and response mappings. |
Review effort: Balanced
Comment on lines
+115
to
+117
| if got := calls.Load(); got != 1 { | ||
| t.Errorf("effect calls = %d, want 1", got) | ||
| } |
Comment on lines
+120
to
+133
| func TestAfterNBytesDoesNotTriggerForShortBody(t *testing.T) { | ||
| srv := transportTestServer(t) | ||
| var calls atomic.Int32 | ||
| client := &http.Client{Transport: WithFailures(nil, AfterNBytes(3, func() { | ||
| calls.Add(1) | ||
| }))} | ||
| resp := transportRequest(t, client, context.Background(), srv.URL+"/upload", strings.NewReader("ab")) | ||
| if resp.StatusCode != http.StatusOK { | ||
| t.Errorf("status = %d, want %d", resp.StatusCode, http.StatusOK) | ||
| } | ||
| if got := calls.Load(); got != 0 { | ||
| t.Errorf("effect calls after short body = %d, want 0", got) | ||
| } | ||
| } |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Context
Part of the test-integrity audit (#97). Several calls were exercised only by live tests, which skip without B2 credentials, so
go test ./...and CI never ran them:b2ContentDisposition;base.Action.x/transport, whose fault helpers blazer's own tests and downstream users rely on, had no test file at all. Credential-free statement coverage was 75.3%.Changes
Test-only, plus the change's
intent/credential-free-live-calls/folder (intent, spec, plan). No production code changes.b2/live_only_calls_wire_test.go(recording server, #205)Object.Hidesends oneb2_hide_filewithbucketIdandfileName, and a scripted error is returnedBucket.Revealdeletes the newest version when it is ahidemarker, and sends no delete when it is an uploadBucket.AuthTokensendsfileNamePrefixandvalidDurationInSecondswith no disposition, and returns the tokenObject.AuthURLsendsb2ContentDispositionand returns a URL whoseAuthorizationandb2ContentDispositionquery values matchClient.ListKeyssendsmaxKeyCount, maps name, ID and expiry, returns the cursor, sends it back asstartApplicationKeyId, and returnsio.EOFon an empty pageKey.DeletesendsapplicationKeyIdObject.Cancelsendsb2_cancel_large_filefor an unfinished file, and refuses an uploaded one without a requestbase/live_only_calls_test.go(httptest)400, "more than one upload using auth token"). That maps toAttemptNewUpload, as does a connection reset before any response. A context the caller cancelled or let expire staysPunt.context.Canceled, and a deadline returnscontext.DeadlineExceededwith the server observing the cancellationerrors.Asx/transport/transport_test.go(new). One test per helper: pass-through,FailureRate(0)andFailureRate(1),MatchPathSubstring,ResponsewithBody,Stall(returns at its duration, or as soon as the request context ends), andAfterNBytes.All coordination uses channels and context deadlines, with no fixed sleeps.
Split out or left out
ListKeysdropped key capabilities. The capabilities assertion failed on current code, so it was split into its own fix (fix(base): return key capabilities from ListKeys #228); R5 does not assert capabilities here.transport.Triggertest reproduces that issue's data race under-race, so it is left out.Verification
Each break was applied on its own, the test run, and the code restored. Every test passes once restored.
HideFilesends an empty file namefileName got "", want "gone"Revealinverts thehidecheckno request for b2_delete_file_versionb2ContentDisposition missing;got "", want "attachment…"ListKeysdrops the cursorstartApplicationKeyId missing, want "k-3"Key.Deletesends an empty IDapplicationKeyId got "", want "k-1"Cancelinverts the status checkpending is not an unfinished large file: startActionAction(…more than one upload using auth token…) = 3, want AttemptNewUploadAction(b2_upload_file: 0: EOF) = 2, want AttemptNewUploadResponsedrops its bodygot "", want "retry later"Stallignores the request contextreturned after 1.0005s, want before 500ms when the request context endsgo test -race -count=5 -shuffle=on ./b2 ./base ./x/transportpasses withB2_APPLICATION_KEY_ID,B2_APPLICATION_KEY,B2_ACCOUNT_IDandB2_ACCOUNT_KEYunset.make cipasses.Stalltest passed even whenStallignored the context. That is fixed (theStallrow above) and re-verified. Its nit, that the spec claimed capabilities coverage, is corrected.Notes for reviewers
main.internal/b2wiretestis identical to test: add a shared recording B2 server for wire tests #205's.Closes #203