Skip to content

Add live tests for gaps in what CI checks on real Drive - #457

Draft
shcheklein wants to merge 6 commits into
mainfrom
live-gap-tests
Draft

shcheklein wants to merge 6 commits into
mainfrom
live-gap-tests

Conversation

@shcheklein

@shcheklein shcheklein commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

The first set of live tests for behaviour that CI never ran against real Drive. A review of the suite before 2.0 listed what users rely on but only mocks, or nothing at all, checked. These are the ones about data and paths.

Filesystem on a folder ID

A new module, test_fs_folder_id.py, mounts the filesystem on a folder ID, the form DVC remotes use (gdrive://FOLDER_ID/...). No live test wrote under a folder ID before. Each test makes its own folder and checks the result with a new filesystem instance, so the directory cache cannot hide a mistake.

  • Names Drive treats specially. Drive matches names without regard to case and has its own quoting. The tests cover:

    • Report.txt and report.txt side by side: each reads its own bytes, and removing one leaves the other;
    • names with a quote, a backslash, two spaces, an accent in the composed form and in the decomposed form that macOS hands to put(), and Japanese, all in one folder.
  • Checksums and sizes. The MD5 and size that info(), ls(detail=True) and find(detail=True) report equal those of the bytes written. DVC compares these.

  • What a folder-ID root changes: writes under the ID, fsspec.open(..., "rt").readline() on a gdrive:// URL with the ID, and info, ls and find of the root. The other operations have their own tests in test_fs.py.

  • rmdir with trash_only=False on a folder whose file is in the trash. It raises ENOTEMPTY, and the trashed file can still be restored. The guide promises this.

  • Uploads in several parts. Large files are uploaded in parts, which Drive acknowledges with 308 answers. PyDrive2 has no option for the part size (100 MiB), so the tests patch pydrive2.files.MediaIoBaseUpload to 256 KiB parts, and each test asserts that its uploads were built that way. A file of 1 MiB + 1 byte then needs five parts:

    • put_file with a progress callback;
    • an update of an existing file's content through GoogleDriveFile (in test_file.py).

    Each is compared with the data byte for byte.

  • A write through open("wb") larger than the writer's 1 MiB memory buffer (fs.blocksize) arrives intact.

  • Moves:

    • a folder with contents, to another folder under a new name;
    • a file onto a folder path, which moves it into the folder;
    • a folder into its own subfolder, which raises and changes nothing.

Elsewhere

  • test_drive.py: a request after the service account token expired, and one after Drive rejected the token. Both succeed after a refresh, and the credentials are no longer expired. A long DVC job meets this after an hour; CI runs are shorter.
  • test_filelist.py: the paging test now selects only files(id,name) and still pages through all ten files, in more than one page. Drive returns the page token only when the field mask names it.
  • test_oauth.py: three service account tests only got a token and slept a second. One test now signs in with each key form and reads the account from Drive: a JSON file named in a settings file, a JSON string, a dict, and a PKCS12 file built from the CI key. PKCS12 had never been run against Google.
  • test_fs.py: the two filesystem sign-in tests now make a real Drive call through the new login: info("root"). They do not read the module's base folder, which may not exist yet when they run.

Validation

These tests describe what should already work, so they are expected to pass on main. Where one fails, it has found a bug, and the fix goes in its own PR.

The offline suite is unchanged (536 passed, also with google-auth 2.15.0). The new tests ran against the local fake Drive as a smoke check, apart from the multi-part uploads and the token tests, which the fake cannot do.

🤖 Generated with Claude Code

shcheklein and others added 3 commits December 2, 2026 19:41
A filesystem mounted on a folder ID, as DVC uses it: names that differ
only in case, names with quotes, backslashes, spaces, accents (also in
the decomposed form macOS uses) and non-Latin scripts, checksums and
sizes against the bytes, files and folders under the folder ID, rmdir
for good with trashed files inside, uploads and updates in several
parts, a write that spills to a temporary file, and moves of folders,
onto folders and into themselves.

Also: a request after the service account token expired or was
rejected, and a listing with a field mask across pages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Three live tests only got a token and slept a second. One test now
signs in with each key form, a JSON file named in a settings file, a
JSON string, a dict and a PKCS12 file made from the CI key, and reads
the account's name from Drive. The two filesystem sign-in tests check
that the base folder exists.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Drive lists a folder in its own order. The filesystem sign-in tests
read the root, since the module's base folder may not exist yet when
they run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread pydrive2/test/test_filelist.py Resolved
Comment thread pydrive2/test/test_fs_folder_id.py Resolved
Comment thread pydrive2/test/test_fs_folder_id.py Resolved
Comment thread pydrive2/test/test_fs_folder_id.py Resolved
Comment thread pydrive2/test/test_drive.py Resolved

@shcheklein shcheklein left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

[AI generated — Copilot]

5-pass review summary: valuable real-Drive coverage (PKCS12, Unicode/case sensitivity, multi-part uploads, folder moves, field-mask pagination). Main concerns: yet another standalone live test file duplicating fixtures across #457/#460/#462/#463, unverified multi-part monkeypatching, unnecessary monkeypatch on a local fs, and 6 separate Drive folders for NAMES.

Comment thread pydrive2/test/test_fs_folder_id.py Resolved
Comment thread pydrive2/test/test_fs_folder_id.py Resolved
Comment thread pydrive2/test/test_fs_folder_id.py Resolved
Comment thread pydrive2/test/test_fs_folder_id.py Resolved
Comment thread pydrive2/test/test_fs_folder_id.py Resolved
Comment thread pydrive2/test/test_filelist.py Resolved
Comment thread pydrive2/test/test_oauth.py Resolved
Comment thread pydrive2/test/test_fs_folder_id.py Resolved
@shcheklein shcheklein mentioned this pull request Dec 3, 2026
1 of 2 tasks
All names go into one folder, the folder-ID test keeps what only a
folder-ID root shows, uploads assert their 256 KiB parts, and the
writer test sets the public blocksize. The core-API update moves to
test_file.py, the field-mask listing replaces the plain paging test,
and the token test checks the renewed expiry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread pydrive2/test/test_util.py Fixed
# Conflicts:
#	pydrive2/test/test_file.py

Copilot AI 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.

🟡 Changes recommended

Immediate post-write and post-move lookups risk flaky live CI, and downloading a trashed child by ID does not verify that it can be restored.

2 open issues
What changed in this PR

Adds live Google Drive tests for filesystem and authentication behavior previously covered only by mocks or not tested.

Changes:

  • Covers folder-ID filesystem paths, special names, metadata, trash handling, moves, and large writes.
  • Exercises token refresh and service-account key formats against Drive.
  • Strengthens multipart-upload and field-mask pagination checks.
File Description
pydrive2/​test/​test_util.py Adds a helper to force and record multipart uploads.
pydrive2/​test/​test_oauth.py Verifies four service-account key formats through Drive requests.
pydrive2/​test/​test_fs.py Adds Drive root queries to filesystem sign-in tests.
pydrive2/​test/​test_fs_folder_id.py Adds live filesystem coverage using folder-ID roots.
pydrive2/​test/​test_filelist.py Checks pagination with restricted response fields.
pydrive2/​test/​test_file.py Verifies byte-for-byte multipart content updates.
pydrive2/​test/​test_drive.py Tests refresh after token expiration and rejection.

Review effort: Balanced

Comment thread pydrive2/test/test_fs_folder_id.py Resolved
Comment thread pydrive2/test/test_fs_folder_id.py Resolved
…util

Downloading by ID also works for a trashed file, so the test untrashes it
and checks its metadata.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI 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.

🔵 Needs a closer look

The credential tests read the Drive root instead of the configured base folder, allowing them to pass even when that folder is missing.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Test the configured base folder instead of Drive root

pydrive2/​test/​test_fs.py:82

This reads the account's Drive root rather than base_remote_dir, so it passes even when the configured base folder is missing and does not exercise the base-folder read described in the PR. Call the existing fs_factory fixture to create the base folder, then assert fs.info(base_remote_dir). The inline-JSON test at line 92 needs the same change.

2 resolved since last review

Review effort: Balanced

@shcheklein

Copy link
Copy Markdown
Member Author

AI generated · Claude · On the review's note about test_fs.py:82: the sign-in tests read the Drive root on purpose. They check that a login from a service-account JSON works against Drive. The module's base folder is created by fs_factory and may not exist yet when they run. I corrected the PR description, which still said they read the base folder.

This branch has not been deployed

No deployments
Sign up for free to 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