Skip to content

feat: emit parent CreateDirectory in dictionary-ctor fix#20

Merged
vbreuss merged 2 commits into
mainfrom
feat/files-ctor-emit-parent-create-directory
May 15, 2026
Merged

feat: emit parent CreateDirectory in dictionary-ctor fix#20
vbreuss merged 2 commits into
mainfrom
feat/files-ctor-emit-parent-create-directory

Conversation

@vbreuss
Copy link
Copy Markdown
Member

@vbreuss vbreuss commented May 15, 2026

This pull request enhances the migration analyzer's code fixer for MockFileSystem constructors and drive migration, ensuring more accurate code transformations and improved test coverage. The main improvements are the addition of logic to emit parent directory creation statements when migrating file system entries, expanded unit tests for various migration scenarios, and cleanup of unused code.

Enhancements to migration logic:

  • The code fixer now emits a CreateDirectory call for each unique non-root parent directory when migrating from the Dictionary<string, MockFileData> constructor, preserving the original behavior of auto-creating parent directories. Non-literal keys are skipped, and only one call is emitted per shared parent.

Expanded and improved unit tests:

  • Added new tests to verify that the fixer emits correct CreateDirectory calls for non-root parents, shared parents, and skips them for non-literal keys in file constructor scenarios.
  • Added new tests for drive migration, ensuring the fixer correctly rewrites AddDrive to WithDrive for various receiver types (local variable, property, method return, nullable property).

Codebase cleanup:

  • Removed the unused TypeExtensions helper file, as its logic is no longer required.

vbreuss added 2 commits May 15, 2026 16:16
The MockFileSystem dictionary constructor auto-creates each entry's
parent directory. Testably's File.WriteAllText does not, so the
rewritten code threw DirectoryNotFoundException at runtime whenever a
seeded path had a non-root parent. The code fix now emits one
Directory.CreateDirectory call per unique non-root parent before the
WriteAll* follow-ups. Literal-string keys only; non-literal keys are
left to the user. Root paths ("/file") and Windows drive roots ("C:")
are suppressed.
Removes unused TypeExtensions.GloballyQualified helpers — they were 0%
covered because nothing referenced them.

Adds four AddDrive code-fix tests that exercise the previously-untested
receiver-declaration branches in IsRetargetableMockFileSystemReceiver:
local variable (VariableDeclarator), property (PropertyDeclaration),
method-return (MethodDeclaration), and nullable property (NullableType).
The existing tests only covered parameter-declared receivers.
@vbreuss vbreuss self-assigned this May 15, 2026
Copilot AI review requested due to automatic review settings May 15, 2026 14:29
@vbreuss vbreuss enabled auto-merge (squash) May 15, 2026 14:30
@vbreuss vbreuss added the enhancement New feature or request label May 15, 2026
@sonarqubecloud
Copy link
Copy Markdown

@github-actions
Copy link
Copy Markdown

Test Results

  6 files  ± 0    6 suites  ±0   1m 22s ⏱️ -20s
161 tests + 7  161 ✅ + 7  0 💤 ±0  0 ❌ ±0 
483 runs  +21  481 ✅ +21  2 💤 ±0  0 ❌ ±0 

Results for commit a8beb6c. ± Comparison against base commit 931c487.

@vbreuss vbreuss merged commit de79ccb into main May 15, 2026
11 checks passed
@vbreuss vbreuss deleted the feat/files-ctor-emit-parent-create-directory branch May 15, 2026 14:32
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the migration code fix so dictionary-seeded MockFileSystem rewrites preserve parent-directory creation before file writes.

Changes:

  • Adds parent directory creation for literal dictionary keys with non-root parents.
  • Adds tests for parent creation and additional AddDrive receiver shapes.
  • Updates example migration comments and removes unused type-extension helpers.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
SystemIOAbstractionsCodeFixProvider.cs Adds parent-directory follow-up generation and path-parent helper logic.
ConstructorTests.cs Adds constructor rewrite tests for parent directories and non-literal keys.
AccessorMethodTests.cs Adds AddDrive rewrite tests for local, property, method, and nullable receivers.
SystemIOAbstractionsMigrationExamples.cs Updates example comments to reflect emitted parent directory creation.
TypeExtensions.cs Deletes unused symbol display extension helpers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +773 to +774
public MockFileSystem? Fs { get; set; }
public void Run() => {|#0:Fs!.AddDrive("D:", new MockDriveData())|};
seeded.File.WriteAllText("/work/readonly.txt", "readonly");
seeded.File.SetAttributes("/work/readonly.txt", FileAttributes.ReadOnly);


Comment on lines +1014 to +1018
// Windows drive root ("C:" or "C:\" already collapsed to "C:") — skip.
if (parent.Length == 2 && parent[1] == ':' && IsAsciiLetter(parent[0]))
{
return null;
}
Comment on lines +662 to +664
// Local-variable receiver: declarator syntax is VariableDeclaratorSyntax.
// The `var` type annotation parses to an unqualified IdentifierName, so the
// using-swap can safely retarget the inferred MockFileSystem.
@github-actions
Copy link
Copy Markdown

This is addressed in release v0.2.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request state: released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants