Repository navigation
test: run the unit tests on b2-simulator by default, in every CI unit job - #801
Draft
sophiecarreras wants to merge 10 commits into
Draft
sophiecarreras wants to merge 10 commits into
sophiecarreras wants to merge 10 commits into
Conversation
Tests that use only the normal B2 API now pass on b2-simulator as well as on RawSimulator, at apiver v3, v2, v1 and v0. Each fix stays an exact check: - Retention dates are one day in the future, and tests that set retention or legal hold use a bucket with Object Lock (B2 refuses both otherwise). - test_update sends B2-valid CORS, lifecycle and replication settings (real keys and destination buckets) and derives account id, bucket id, name, revision and options from the server instead of RawSimulator's values. - Lifecycle rules carry an action, which B2 requires. - The resume helper and v1 test_started_large_file pass a content type: B2 refuses the null that content_type=None sends. - Expected content types for b2/x-auto uploads, part file ids and v1 download file ids come from the server's answers. - A refused governance delete is 401 access_denied on B2 (Unauthorized in the SDK), and a wrong SHA-1 is 400 bad_request "Sha1 did not match data received" (BadRequest); RawSimulator's AccessDenied and FileSha1Mismatch stay accepted until the default flips. The wrong-SHA-1 test now also checks that nothing was stored. - test_custom_timestamp enables custom upload timestamps on the simulator. - TestAuthorizeForBucket stays in-process at apiver v2: b2-simulator v0.6.0 refuses every bucket-restricted key at API v3. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-simulator Tests that reached into RawSimulator's state now use test/unit/simulator_hooks.py. Each hook uses RawSimulator's test methods in the default run and b2-simulator's control plane under --b2-simulator: - Upload errors: POST /faults on b2_upload_file (503, 408, 400). On RawSimulator the upload raises what the SDK's HTTP layer raises for that answer. The fatal-error tests now expect BadRequest (code bad_request) instead of a test-only exception. Tests that recover from an injected error also check that it fired. - Upload timeout: a stall wire fault longer than a shortened upload timeout; the SDK sees B2RequestTimeout, the exception requests' timeout becomes. - Token expiry: POST /clock past the token lifetime. The reauthorization test now also checks that a new token was issued for the same key. - Truncated downloads (parallel): a reset-mid-response wire fault on both download endpoints, with a check that a download was cut short. - Corrupted stored SHA-1: POST /files/content-sha1. - Notification rule suspension: POST /notification-rules/suspend. - Second account: @pytest.mark.b2_simulator_config(extraAccounts=1); the harness's second create_account() returns account 2's credentials. Rewritten without simulator state, valid on both: - The empty-page listings use a client-side raw API wrapper instead of a BucketSimulator subclass, and a new test checks that empty pages are served. - SSE-C downloads pass the key instead of bypassing the encryption check. - The retention upload enables file lock and uses a future date. - File lock state is read back with list_buckets. - The source-replication test uses an existing destination bucket and key. - The unverified-checksum test uploads with an "unverified:" SHA-1 on b2-simulator (RawSimulator refuses the prefix, so it keeps the old edit). - The c8 test bucket name is 6 characters or more, as B2 requires. The simple-downloader truncation tests and test_testing_api_helpers.py stay on RawSimulator. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- test_upload_bytes_progress uploads three parts, so the listener gets an update per part on any transport. It still requires several updates ending at the total; an 11-byte body is read once over HTTP, and only RawSimulator's forced chunked reads gave it several updates. - test_scan_source: the source bucket has Object Lock (for the retention file) and the large-metadata files use 1,900 bytes of file info. That fits b2_upload_file's documented limits (7,000 bytes for name plus info, 2,048 for SSE or Object Lock buckets); the old 7,000-byte value broke both. The upload headers stay over the 2,048 bytes has_large_header measures, so every category is still checked. - Mark the two dual-acceptance error checks (governance delete, wrong SHA-1) with a TODO naming the real-B2 error to assert once --b2-simulator is the default. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…o test/b2-simulator-default # Conflicts: # test/unit/bucket/test_bucket.py
The unit tests now use b2-simulator unless pytest gets --rawsimulator. B2_SIMULATOR_DIR and node are required; without them the run stops with a usage error that names the variable and the opt-out. The old --b2-simulator flag is gone. - @pytest.mark.rawsimulator(reason=..., from_ver=, to_ver=) keeps one test on the in-process RawSimulator at those apivers. The reason is required; a test cannot carry it together with needs_b2_simulator. - An unmarked unit test that builds any RawSimulator (or a subclass) fails, naming the marker, so every test left on RawSimulator is visible in the code. - --rawsimulator runs the whole suite on RawSimulator and deselects the needs_b2_simulator tests. - The unit conftest activates the plugin, so integration and static runs never need a checkout. - The part-size plugin tests read the server's authorize answer: at apiver v0 and v1 the account info reports the SDK's own minimum. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each test left on the in-process RawSimulator now carries @pytest.mark.rawsimulator with a reason; the reasons shared by several files live in test/unit/b2_simulator.py. - RawSimulator's own tests (test_raw_simulator.py, test_simulator_encryption_context.py) and the live-test helper tests that forbid HTTP (test_testing_api_helpers.py). - TestTruncatedDownloadSimple (both test_bucket.py files): #776. The TRUNCATE_ON_B2_SIMULATOR switch is replaced by the marker. - test_copy_encryption: #772. v1/v0 copy_file tests without a metadata directive: #773. The UNSET legal-hold case of the explicit-resume test: #774. test_cancel_large_file_v1/v2: #770. - Tests that authorize with a single-bucket key at apiver v0 to v2 (B2 API v3): b2-simulator v0.6.0 refuses those keys while real B2 accepts a key made by v3 b2_create_key. Marked to_ver=2; at v3 they run on b2-simulator. TestAuthorizeForBucket's in-process subclass is replaced by the same marker. The legacy-API regression tests only needed a raw API object; they now get it from raw_api_class() and run on b2-simulator. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…data With b2-simulator as the default, the tests that accepted either RawSimulator's error or real B2's now accept only real B2's: - governance-locked delete (test_bucket.py, test_file_version.py, test_api.py): Unauthorized with code access_denied (401), exact type. - wrong SHA-1 upload: BadRequest bad_request "Sha1 did not match data received" (400), exact type. - wrong key on authorize (test_reauth_drops_pooled_urls.py): Unauthorized with code unauthorized (401 unauthorized "", measured 2026-11-27). - HEAD of a hidden file by name (test_api.py): FileNotPresent, as for a missing file (404 not_found, measured 2026-11-27). RawSimulator gives other answers, so these tests are needs_b2_simulator (deselected only with --rawsimulator); the same goes for the v0/v1 tests that compare raw answers whole in real B2's shape (contentMd5, retainUntilTimestamp, options ['s3'], isFileLockEnabled false). Test data that only RawSimulator accepted, fixed as the G1 lane fixed the v1+ copies: retention dates in the future and Object Lock buckets for retention and legal hold, ids, timestamps, revisions and stored content types taken from the server, three-part progress upload, and b2/x-auto instead of a null contentType on raw b2_start_large_file calls (test_api.py, v0/test_bucket.py, test_regression_bucket.py). The C45 class turns on custom upload timestamps for its reset. Also kept on RawSimulator with a written reason (real B2 not measured): - SSE-C file read by get_file_info_by_name (HEAD without the key): TestListVersions::test_encryption, test_get_file_info_by_name_with_properties. - file lock on a replication source: test_is_file_lock_enabled_source_replication. - custom upload timestamp on b2_start_large_file: b2-simulator accepts only a string, the SDK sends a number (five C45 tests). - c55 failed-authorization tests at apiver v2: the single-bucket key gap. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The unit tests now need a b2-simulator checkout, so each job that runs `uv run nox -vs unit` gets one: the ci.yml test matrix (3 OS x 6 Python, unchanged) and the cd.yml release test job. The pattern is the one of simulator-integration.yml: - SIMULATOR_REVISION is stated once per workflow (4052c6f, b2-simulator v0.6.0); the checkout uses it, the read-only SIMULATOR_DEPLOY_KEY and persist-credentials: false, and a step verifies the revision. - A missing deploy key fails with a message naming the Actions and Dependabot secrets; the key itself never reaches a shell. - In ci.yml a pull request from a fork fails first, with a message: it cannot check out the private simulator. - Node.js 22 is set up; B2_SIMULATOR_DIR is given to the unit-test step through its env, never through GITHUB_ENV. The SDK moves to an `sdk` checkout path next to `simulator`. - Guard and verify steps use bash, so they also run on Windows. test/static/test_unit_tests_simulator.py checks all of this and runs the fork guard's script for a fork PR, a same-repository PR and a push. docs/testing.md and the contributing guide describe the new default, --rawsimulator and the rawsimulator marker. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With --rawsimulator and no B2_SIMULATOR_DIR, the subprocess that collects `test` ran in the default mode and stopped with the usage error. It now gets --rawsimulator when its parent run has it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
|
…ects
- v1/v0 copy_file without a metadata directive: real B2 accepts
fileInfo {} with COPY and copies the source metadata (measured
2026-11-27), so #773 is not an SDK defect. b2-simulator v0.6.0 is
stricter; the marker now says so and is removed once it matches.
- C45 custom upload timestamps on b2_start_large_file: B2 documents
customUploadTimestamp as a number, which the SDK sends; b2-simulator
v0.6.0 accepts only a string. Same wording.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ffumero2003
requested changes
Nov 29, 2026
ffumero2003
left a comment
Contributor
There was a problem hiding this comment.
Requesting changes to flag the blockers before this leaves draft — the test migration itself is careful and well-guarded; the concerns are the workflow side. No rush, you're out.
code/snykis failing ("2 new Code Analysis issues found"). Likely a false positive on the new simulator credential-shaped strings in test code (f'sim-master-secret-{count+1}'inb2_simulator.py~L1109,('sim-master-id-2','sim-master-secret-2')intest_b2_simulator_plugin.py~L2908 — loopback sim creds), but it needs resolving/dismissing with justification.- (decision) The new
ci.ymlfirst step "Require a pull request branch in this repository" makes every fork PR hard-fail the required unit matrix — b2-simulator is private, so external contributors can't get green CI on this public repo (documented indocs/testing.md). Plus Dependabot needs its ownSIMULATOR_DEPLOY_KEYsecret. This is a team policy call to settle before merge, and an admin should confirm the repo/Dependabot secrets exist. - (process) None of the new workflow steps have run — no GitHub Actions on the head SHA at all (stacked base isn't
main), so the pinned checkout / Node setup /nox -s unitand thecd.ymlrelease gate are unverified. Get a scoped branch run (ubuntu/macOS/Windows/pypy3.10) before merge, and check whether the required-checks list changes. - (non-blocking) Good: RawSimulator is kept as an explicit opt-in (
@pytest.mark.rawsimulator), an unmarked test building aRawSimulatorfails loudly (_refuse_raw_simulator), workflow hygiene is tight (SHA-pinned, simulator pinned+verified,persist-credentials: false, key only to the one checkout, enforced bytest_unit_tests_simulator.py). Several assertions are genuinely tightened (CanRetry→BadRequest+code, real B2 messages, seconds→ms retention fix). - (non-blocking) Same self-referential pattern as #769/#771:
b2/x-autoand fixed timestamps/ids replaced by values read from live state intest_api.py~L110 andtest_bucket.py~L555/623/1430 — consider also pinning the type B2 resolves (the changelog says it was measured). And a few*_GAP/*_UNMEASUREDmarkers have no linked issue — they'll rot without tracking.
Migration looks sound — mainly the Snyk finding, the fork-PR policy, and a real CI run before undraft. Happy to approve once those are settled.
Open
3 tasks
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.
Paused while the author is away (back Dec 16). Draft; based on #769 (
test/b2-simulator-harness), with #771 (test/migrate-unit-g1) and #775 (test/migrate-unit-internals) merged in. Review after those two.What
The unit tests now run against b2-simulator (
backblaze-labs/b2-simulator) by default, and every CI unit-test job checks out the pinned release. Test and CI code only; nothing underb2sdk/changes. No test is skipped, deleted, xfailed or loosened.test/unit/b2_simulator.py)B2_SIMULATOR_DIRandnode. Without them the run stops with a usage error that names the variable and the opt-out; it never skips. The old--b2-simulatorflag is gone.--rawsimulatorruns the whole suite on the in-processRawSimulatorand needs no checkout. It deselects theneeds_b2_simulatortests.@pytest.mark.rawsimulator(reason=..., from_ver=, to_ver=)keeps one test onRawSimulator. The reason is required.RawSimulator, or a subclass, fails and names the marker. So every test left onRawSimulatoris visible in the code (list below).Unauthorizedaccess_denied(test_bucket.py,test_file_version.py,test_api.py). A wrong SHA-1 isBadRequestbad_request"Sha1 did not match data received". Also changed to real B2's answer: a wrong key on authorize isUnauthorizedunauthorized, and a HEAD of a hidden file by name isFileNotPresent. Both were measured on B2 on 2026-11-27.RawSimulatoranswers differently, so these tests areneeds_b2_simulator. That marker also covers the v0/v1 tests that compare raw answers whole in B2's shape (contentMd5,retainUntilTimestamp,options: ["s3"],isFileLockEnabled: false).RawSimulatoraccepted. This applies the test: run G1 unit tests on b2-simulator (test data fixes) #771 fixes totest_api.py,v0/test_bucket.pyandtest_regression_bucket.py: future retention dates on Object Lock buckets, and ids, timestamps, revisions and stored content types taken from the server. It also uses a three-part progress upload andb2/x-autoinstead of a nullcontentTypeon rawb2_start_large_filecalls. The legacy-API regression tests now take their raw API fromraw_api_class().ci.ymltest(3 OS × 6 Python, 17 jobs, matrix unchanged) andcd.ymltest(the release gate) followsimulator-integration.ymlfrom ci: run pull-request integration against B2 Simulator; live B2 weekly #768:SIMULATOR_REVISION=4052c6f8f45350486460d19bc796866cbdcdd3bc(b2-simulator v0.6.0).SIMULATOR_DEPLOY_KEYwithpersist-credentials: false. A step verifies the revision.ci.yml, a pull request from a fork fails first with a message.B2_SIMULATOR_DIRgoes in the unit step'senv, with noGITHUB_ENVwrites.sdk/, next tosimulator/.test/static/test_unit_tests_simulator.pychecks all of this. It also runs the fork guard's script for a fork PR, a same-repository PR and a push.docs/testing.md,doc/source/contributing.rstand a changelog entry.Tests left on RawSimulator
Count = test runs per apiver (v3 / v2 / v1 / v0), including the plugin's own marker check.
RawSimulatoritselftest_raw_simulator.py,test_simulator_encryption_context.pytest_testing_api_helpers.pytest_b2_simulator_plugin.pySimpleDownloaderdoes not resume after a mid-body dropTestTruncatedDownloadSimple(bothtest_bucket.py)copy_fileasserts SSE-C sourcetest_copy_encryptionfileInfo {}with COPY, which v1copy_filesends. Real B2 accepts it and copies the source metadata (measured 2026-11-27; #773 was closed as not a bug). Remove the marker once the simulator matchestest_copy_without_optional_params,test_copy_with_range,test_copy_with_different_bucket(v1, v0)LegalHold.UNSETsent asofftest_explicit_resume_accepts_matching_protections[retention1-LegalHold.UNSET]contentTypeonstart_large_filetest_cancel_large_file_v1/_v2b2_create_keyat v3 authorize. Real B2 accepts that key (measured 2026-11-27). apiver v0–v2 authorize at v3test_api.pyrestriction tests,test_upload_large_file_with_restricted_api_key(2 classes),TestAuthorizeForBucket,test_c55_failed_authorization_preserves_session(v2)get_file_info_by_name(HEAD without the key, no key parameter). b2-simulator answers 400; real B2 not measuredTestListVersions::test_encryption(+TestEmptyListVersions),test_get_file_info_by_name_with_propertiesbad_requestwith a text the SDK does not map toSourceReplicationConflict; real B2 not measuredtest_is_file_lock_enabled_source_replicationcustomUploadTimestamponb2_start_large_file. B2's docs type it as a number, and the SDK sends a number; b2-simulator v0.6.0 accepts only a string (custom_timestamp_invalid). Remove the marker once the simulator matchestest_regression_bucket.pyThe two open questions were not in the planned list, and neither was the custom-timestamp gap. Each needs one measurement on real B2. The answer then decides whether the fix belongs in b2-simulator, in the SDK or in the test.
Numbers
b2-simulator v0.6.0 (
4052c6f), Python 3.13, macOS,pytest -n 8 test/unit:--rawsimulator--b2-simulator(merged #771 + #775)--rawsimulatorran with noB2_SIMULATOR_DIRand deselects 32needs_b2_simulatortests per apiver. The "before" failures count subtests as well.nox -s unit-3.13, the command CI runs (-n auto, doctests, coverage), also passed at all four apivers, with the same counts as the default column, andcoverpassed.How it was checked
--rawsimulator. Two mutations were each caught: removing the guard, and ignoring the marker.--rawsimulatorbeforeneeds_b2_simulatorwas added. They failed onRawSimulator'sAccessDenied/FileSha1Mismatch(5 failures at v3 and v1), so they tell the two answers apart. On b2-simulator they pass.--rawsimulatorrun had 1 failure per apiver. The plugin's whole-directory collection test ran its subprocess without--rawsimulator. That is fixed in the last commit; the run above is after the fix.nox -s lintandnox -s towncrier_checkpassed. actionlint was not available locally: NOT RUN.ci.ymlruns only for pull requests intomaster, so this PR (basetest/b2-simulator-harness) gets no unit-test run. Windows and PyPy were not run locally; the guard and verify steps usebash.test_bucket.pyconflicted only on one import that test: move RawSimulator-internals unit tests onto b2-simulator hooks #775 made unused; it was dropped.🤖 Generated with Claude Code