Skip to content

Fix doc-pipeline test repo lookup across worktrees - #1607

Open
PaperHammer (PaperHammer) wants to merge 2 commits into
microsoft:mainfrom
PaperHammer:fix/issue1031-source-snippet-repo-root
Open

PaperHammer (PaperHammer) wants to merge 2 commits into
microsoft:mainfrom
PaperHammer:fix/issue1031-source-snippet-repo-root

Conversation

@PaperHammer

Copy link
Copy Markdown
Contributor

Summary

SourceSnippetSanityTests can pass while reading UseMemoCells.cs from a sibling worktree. This happens when the test assembly is built in one checkout and the process working directory points into another. A valid snippet in the second checkout can hide a broken snippet in the checkout under test.

This PR makes the doc-pipeline tests share the existing repository finder so they resolve source files from the worktree that built the test assembly.

Changes

  • Route repository lookup in 12 doc-pipeline test classes through TestRepo.Root and remove their duplicate directory walks.
  • Link the existing RepoRootFinder.cs into Reactor.DocPipeline.Tests so the tests can reuse the finder without adding a CLI project dependency.
  • Document the lookup and cross-worktree verification in the doc-pipeline contributor guide, link it from TESTING.md, and record the fix in CHANGELOG.md.

Repository lookup scope

RepoRootFinder walks up from AppContext.BaseDirectory until it finds src/Reactor/Reactor.csproj. Snippet and documentation checks then resolve their paths relative to that checkout.

Linked issue / spec

Fixes #1031.

Test plan

  • Built the test assembly in worktree A and invoked the snippet test in a separate .NET process with its working directory in worktree B. The probe recorded both paths at test execution.
  • Removed SnapshotItems from A's snippet while leaving B's snippet valid. The original test incorrectly passed. The fixed test failed at the expected assertion and passed after restoring A's snippet.
  • Passed SourceSnippetSanityTests through the standard test runner.
  • Ran the full doc-pipeline suite. 495 passed and 1 failed. The same junction assertion failed on unmodified main at 7e3d0254.
  • Built the full solution in Release with 0 errors.
  • Ran the full x64 Release Reactor.Tests suite. 15,967 passed, 18 skipped, and 2 failed. Both CS1503 suggestion failures were previously reproduced on clean main at 4cd63979 and documented in Deflake reconcile highlight lifecycle selftests #1503.
  • Checked the updated documentation links and passed git diff --check.

Commands used for validation

dotnet restore Reactor.slnx
dotnet build Reactor.slnx --no-restore -c Release

dotnet test tests/Reactor.DocPipeline.Tests -p:Platform=x64 -c Release

dotnet test tests/Reactor.Tests -p:Platform=x64 -c Release `
  -p:SkipSignaturesGen=true -p:SkipReactorApiGen=true

git diff --check

Risk / breaking changes

The code change is scoped to repository lookup in the doc-pipeline test project. Repository-backed tests expect their output directory to sit under a checkout containing src/Reactor/Reactor.csproj, which is the standard local and CI layout.

@PaperHammer

Copy link
Copy Markdown
Contributor Author

While verifying the fix, I noticed a gap in the existing test coverage. The test checks whether the returned directory contains Reactor.csproj, but both worktrees satisfy that check. If the lookup ever falls back to the process working directory, the existing test could still pass.

I verified the fix with two worktrees by breaking only the snippet in the checkout that built the test assembly. The fixed test failed as expected and passed again after I restored the snippet.

Would you consider it worth adding a process-isolated regression test in this PR, or would you prefer to track it as a follow-up?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice cleanup. Reusing RepoRootFinder is the right call and it also gets rid of the race with the FakeRepo fixtures that change the working directory. Two small notes inline.


internal static class TestRepo
{
public static string Root => RepoRootFinder.FindRepoRoot()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nothing in CI would catch a regression back to a working-directory-first lookup, since CI runs from the same checkout it builds in. The CLI does FindRepoRoot(Directory.GetCurrentDirectory()) ?? FindRepoRoot() in PackLocalCommand, so it's an easy copy-paste to undo this.

Could you add a small test that points the working directory at a temp folder containing src/Reactor/Reactor.csproj and checks that TestRepo.Root still resolves to the checkout around AppContext.BaseDirectory? It needs a non-parallel collection because the working directory is process-wide. Then the manual two-worktree steps in doc-pipeline.md could just point at the test.

Comment thread CHANGELOG.md Outdated
Comment on lines +227 to +229
- Doc-pipeline tests locate the repository from their test output directory, so
snippet and documentation checks read the worktree that built them even when
the process working directory points into a sibling checkout (issue #1031).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Minor, this only covers test infra and the file asks for significant changes, so I'd drop it.

@PaperHammer

Copy link
Copy Markdown
Contributor Author

Thanks for the review and for suggesting the temporary-directory approach. I’ve addressed both comments in ef9391e. The new test runs in a non-parallel collection, points the process working directory at a temporary directory containing src/Reactor/Reactor.csproj, and checks that TestRepo.Root still resolves to the checkout that built the test assembly. I confirmed that it fails with CWD-first lookup and passes with the fix. I also replaced the manual two-worktree steps with a link to the test and removed the changelog entry.

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.

[Bug] SourceSnippetSanityTests anchors repo-root on CWD, not AppContext.BaseDirectory — can validate a sibling worktree

2 participants