Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snapshot path problem on Linux build agent #196

Open
BalintBanyasz opened this issue Feb 27, 2024 · 6 comments
Open

Snapshot path problem on Linux build agent #196

BalintBanyasz opened this issue Feb 27, 2024 · 6 comments

Comments

@BalintBanyasz
Copy link

Describe the bug
Looks like the snapshot folder isn't resolved properly, so Snapshooter tries to create a directory it doesn't have permissions for.

To Reproduce
Using:

  • Snapshooter.Xunit 0.14.1
  • xunit 2.7.0
  • dotnet 8.0
  • Azure ubuntu-latest image

Test passes on development machine (Windows 11, VS2022) but fails on Linux CI run. Snapshot file is checked in to the repository, SNAPSHOOTER_STRICT_MODE is set to true.

Expected behavior
The existing snaphot should be resolved correctly.

Desktop (please complete the following information):

  • OS: Ubuntu 22.04.4 LTS (ubuntu-22.04 v20240225.1.0 image) Azure hosted agent

Additional context

  Error Message:
   System.UnauthorizedAccessException : Access to the path '/_' is denied.
---- System.IO.IOException : Permission denied
  Stack Trace:
     at System.IO.FileSystem.CreateParentsAndDirectory(String fullPath, UnixFileMode unixCreateMode)
   at System.IO.FileSystem.CreateDirectory(String fullPath, UnixFileMode unixCreateMode)
   at System.IO.Directory.CreateDirectory(String path)
   at Snapshooter.Core.SnapshotFileHandler.CreateFolderIfNotExist(String folderPath)
   at Snapshooter.Core.SnapshotFileHandler.EnsureSnapshotFolder(SnapshotFullName snapshotFullName)
   at Snapshooter.Core.SnapshotFileHandler.TryReadSnapshot(SnapshotFullName snapshotFullName, String& snapshotData)
   at Snapshooter.SnapshotAssert.AssertSnapshot(Object currentResult, SnapshotFullName snapshotFullName, MatchOptions matchOptions)
   at Snapshooter.Snapshooter.AssertSnapshot(Object currentResult, SnapshotFullName snapshotFullName, Func`2 matchOptionsSettings)
   at Snapshooter.Xunit.Snapshot.Match(Object currentResult, Func`2 matchOptions)
   at Snapshooter.Xunit.Snapshot.Match[T](T currentResult, Func`2 matchOptions)
@Jetski5822
Copy link

Were you able to fix this? I have hit this too

@tobias-tengler
Copy link

Running into a similar thing. Our paths start with /_/, but we don't get any permission exceptions (as far as we can see).

@mtsfoni
Copy link

mtsfoni commented Apr 20, 2024

I also ran into this problem.

Interestingly, it seemed to work until roughly 5 months ago, the last change to our codebase was 7 months ago.

So I can only assume that something regarding the OS or GitHub workflows caused the problem.

The /_/ seems pretty bogus, however. The actual path should rather be: /Users/runner/work/project-name/project-name/.... Maybe it has always been /_/ but it only started being a problem after an OS Update?

  Error Message:
   System.UnauthorizedAccessException : Access to the path '/_/tests/CycloneDX.Spdx.Interop.Tests/__snapshots__' is denied.
---- System.IO.IOException : Permission denied
  Stack Trace:
     at System.IO.FileSystem.CreateDirectory(String fullPath)
   at System.IO.Directory.CreateDirectory(String path)
   at Snapshooter.Core.SnapshotFileHandler.CreateFolderIfNotExist(String folderPath)
   at Snapshooter.Core.SnapshotFileHandler.EnsureSnapshotFolder(SnapshotFullName snapshotFullName)
   at Snapshooter.Core.SnapshotFileHandler.TryReadSnapshot(SnapshotFullName snapshotFullName, String& snapshotData)
   at Snapshooter.SnapshotAssert.AssertSnapshot(Object currentResult, SnapshotFullName snapshotFullName, MatchOptions matchOptions)
   at Snapshooter.Snapshooter.AssertSnapshot(Object currentResult, SnapshotFullName snapshotFullName, Func`2 matchOptionsSettings)
   at Snapshooter.Xunit.Snapshot.Match(Object currentResult, SnapshotFullName snapshotFullName, Func`2 matchOptions)
   at Snapshooter.Xunit.Snapshot.Match(Object currentResult, SnapshotNameExtension snapshotNameExtension, Func`2 matchOptions)
   at Snapshooter.Xunit.Snapshot.Match[T](T currentResult, SnapshotNameExtension snapshotNameExtension, Func`2 matchOptions)
...
----- Inner Stack Trace -----

@andreas-hilti
Copy link

@mtsfoni From what I can see the directory is determined here:

public SnapshotFullName ReadSnapshotFullName()

It fetches the stack frames
StackFrame[] stackFrames = new StackTrace(true).GetFrames();
and searches for methods that have the Theory or Fact attribute and gets the corresponding directory.
For me, this is working, and if I execute this manually, it results in something like this:
grafik
Don't know what goes wrong, but you see further down often the "/_/" start in the directory name.

@andreas-hilti
Copy link

Note the definition of StackFrame.GetFileName:

Gets the file name that contains the code that is executing. This information is typically extracted from the debugging symbols for the executable.

https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.stackframe.getfilename?view=net-6.0

i.e. it has to do with the debug information that is available while running the test.

@mtsfoni
Copy link

mtsfoni commented May 19, 2024

I assume something happens in the GitHub actions environment causing the .pdbs to come out with unexpected paths.

I found this work around, which currently is good enough for me.

andreas-hilti added a commit to andreas-hilti/cyclonedx-cli that referenced this issue May 20, 2024
Compare SwissLife-OSS/snapshooter#196

Signed-off-by: andreas hilti <[email protected]>
jkowalleck added a commit to CycloneDX/cyclonedx-cli that referenced this issue May 20, 2024
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

No branches or pull requests

5 participants