Skip to content

devtools_shared: Use the file package for a file system abstraction for testing#9872

Open
srawlins wants to merge 4 commits into
flutter:masterfrom
srawlins:file-system
Open

devtools_shared: Use the file package for a file system abstraction for testing#9872
srawlins wants to merge 4 commits into
flutter:masterfrom
srawlins:file-system

Conversation

@srawlins

Copy link
Copy Markdown
Contributor

Mainly, the extension LocalFileSystem on Never is ripped out for an extension on the 'file' package's FileSystem. Production code can use a top-level fileSystem constant, which is the local file system. Test code can use a MemoryFileSystem. This avoids reading and writing files on devs' machines and CI machines. Better isolation. From the CHANGELOG:

  • Braking changes: LocalFileSystem, an extension which provided some handy
    helpers, has been refactored into an extension on the file package's
    FileSystem abstraction. In detail:
    • fileSystem is a new top-level constant which represents the local (real)
      file system.
    • LocalFileSystem.devToolsDir() is now a static getter,
      FileSystemExtension.devToolsDir.
    • LocalFileSystem.maybeMoveLegacyDevToolsStore() is now an instance method,
      FileSystemExtension.maybeMoveLegacyDevToolsStore().
    • LocalFileSystem.devToolsStoreLocation() is now a static getter,
      FileSystemExtension.devToolsStoreLocation.
    • LocalFileSystem.ensureDevToolsDirectory() is now private.
    • LocalFileSystem.devToolsFileFromPath() is now an instance method,
      FileSystemExtension.devToolsFileFromPath().
    • LocalFileSystem.devToolsFileAsJson() is now an instance method,
      FileSystemExtension.devToolsFileAsJson().
    • LocalFileSystem.flutterStoreExists() is now an instance getter,
      FileSystemExtension.flutterStoreExists.
    • IOPersistentProperties.new accepts a new optional FileSystem fs
      argument.
  • Update LocalFileSystem and IOPersistentProperties to use package:file
    instead of dart:io to allow mocking the file system.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors LocalFileSystem and IOPersistentProperties in packages/devtools_shared to use package:file instead of dart:io, enabling file system mocking in tests. Feedback on the changes includes a recommendation to allow passing a custom FileSystem to DevToolsUsage to prevent real disk writes during tests, a suggestion to defensively check the decoded JSON type in devToolsFileAsJson to avoid runtime type errors, and a minor correction for a typo in the changelog.

Comment thread packages/devtools_shared/lib/src/server/devtools_store.dart
Comment thread packages/devtools_shared/lib/src/server/file_system.dart
Comment thread packages/devtools_shared/CHANGELOG.md Outdated
@srawlins srawlins requested a review from a team as a code owner June 30, 2026 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant