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

test: giving steroids to the test suite 💪 #122

Merged
merged 9 commits into from
Feb 19, 2025

Conversation

mmaietta
Copy link
Contributor

@mmaietta mmaietta commented Feb 8, 2025

This is purely a test suite upgrade except for code change: asar.listPackage was missing a 2nd argument. I checked with electron/asar and its default behavior is isPack: false, so functionally it is the same.

Purpose:
There are some bugs I'd like to fix (#117 #116), but I wanted to beef up the test suite to be more robust first to prep for the fix PRs.
I added some fun helper test utils and resolved 2 it.todo test cases.

Test Cases added:

  • should not inject ElectronAsarIntegrity into 'infoPlistsToIgnore'
  • should shim two different app folders

Functionally, this PR adds:

  • verifyApp helper function does all the below:
    • executes ensureUniversal (consolidating existing logic)
    • verifyHeader - parses out unstable properties ("offset" varies per build machine?) and stores a snapshot
    • verifyFileTree - Traverses for app dirs (both merged and shimmed) and snapshots the tree hierarchy and plain text files (also used for unpacked dir snapshots)
    • extractAsarIntegrity - a loop verifies the ElectronAsarIntegrity entry in the Info.plist in all non-Framework Info.plists in a path=>integrity map for easier readability of the snapshot
  • createTestApp - Creates a new app at runtime from the app template, adds folders, symlinks, and allows you to pass in additionalFiles that you can use to customize each app's directory
    • This was used for the test to mock two .bin snapshot files to trigger electron/universal shimming logic flow
    • It will be used for upcoming unit tests for universal app merging w/ unpacked asar assets

@mmaietta mmaietta marked this pull request as ready for review February 10, 2025 18:10
@mmaietta mmaietta requested a review from a team as a code owner February 10, 2025 18:10
test/util.ts Outdated
@@ -0,0 +1,179 @@
import { readArchiveHeaderSync } from '@electron/asar/lib/disk';
Copy link
Member

Choose a reason for hiding this comment

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

We shouldn't reach into @electron/asar internals here. Looks like this is already exposed via the public API as getRawHeader, and that should handle the typings for us as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the feedback! Updated the PR to use the exposed public method

Remove warnings by adding transform regex to `ts-jest` and `testMatch`.
Copy link
Member

Choose a reason for hiding this comment

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

I believe the changes in this file can also be dropped now that the typings directory has been removed from the PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh derp, my apologies. Yep! I will push the change.

test/util.ts Outdated
Comment on lines 36 to 38
!path.basename(p).endsWith('.asar') &&
path.basename(p).includes('app') && // it's an app dir
!p.endsWith('.app'), // but we don't want any sub-apps (Something.app)
Copy link
Member

Choose a reason for hiding this comment

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

Make the logic here clearer.

Suggested change
!path.basename(p).endsWith('.asar') &&
path.basename(p).includes('app') && // it's an app dir
!p.endsWith('.app'), // but we don't want any sub-apps (Something.app)
['app', 'app.asar.unpacked'].includes(path.basename(p))

Copy link
Contributor Author

@mmaietta mmaietta Feb 11, 2025

Choose a reason for hiding this comment

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

I think that would exclude shimmed app directories, right? We should also include app-x64.asar.unpacked and app-arm64.asar.unpacked? I can push a commit updating the logic

Copy link
Member

@BlackHole1 BlackHole1 Feb 11, 2025

Choose a reason for hiding this comment

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

Oh. Good catch!

path.basename(p) === 'app' || path.basename(p).endsWith('.asar.unpacked')

Copy link
Contributor Author

@mmaietta mmaietta Feb 11, 2025

Choose a reason for hiding this comment

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

Ahh, just realized from the test snapshots, it also needs to include app-x64 and app-arm64 to include shimmed no-asar universal apps so that there's coverage for test case should shim two different app folders

Pushing a change:

  // check all app and unpacked dirs (incl. shimmed)
  const dirsToSnapshot = [
    'app',
    'app.asar.unpacked',
    'app-x64',
    'app-x64.asar.unpacked',
    'app-arm64',
    'app-arm64.asar.unpacked',
  ];
  const appDirs = resourcesDirContents
    .filter((p) => dirsToSnapshot.includes(path.basename(p)))
    .sort();

test/util.ts Outdated
.filter(
(appFile) =>
appFile.type === fileUtils.AppFileType.INFO_PLIST &&
!appFile.relativePath.includes('Framework'),
Copy link
Member

Choose a reason for hiding this comment

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

Is this a spelling mistake? Maybe it should be framework or Frameworks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was intentional for filtering out Framework, but looks like .framework and Frameworks would also work. Which would you prefer?

/test/fixtures/apps/Arm64-1.app
└── Contents
    ├── Frameworks
    │   ├── Electron Framework.framework
    │   │   ├── Electron Framework -> Versions/Current/Electron Framework
    │   │   ├── Helpers -> Versions/Current/Helpers
    │   │   ├── Libraries -> Versions/Current/Libraries
    │   │   ├── Resources -> Versions/Current/Resources
    │   │   └── Versions
    │   │       ├── A
    │   │       │   ├── Electron Framework
    │   │       │   ├── Helpers
    │   │       │   │   └── chrome_crashpad_handler
    │   │       │   ├── Libraries
    │   │       │   │   ├── libEGL.dylib
    │   │       │   │   ├── libGLESv2.dylib
    │   │       │   │   ├── libffmpeg.dylib
    │   │       │   │   ├── libvk_swiftshader.dylib
    │   │       │   │   └── vk_swiftshader_icd.json
    │   │       │   └── Resources
    │   │       │       ├── Info.plist

Copy link
Member

Choose a reason for hiding this comment

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

CleanShot 2025-02-11 at 14 37 02@2x

It seems that Frameworks is the best option?

To make the logic here stronger and clearer, maybe !appFile.relativePath.includes(path.join('Contents', 'Frameworks')) would be better?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Love it!

Copy link
Member

@BlackHole1 BlackHole1 left a comment

Choose a reason for hiding this comment

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

Code LGTM. It's just a few issues with the code formatting. But it shouldn't be a reason to block the PR merge.

@BlackHole1 BlackHole1 merged commit 7c0ad6c into electron:main Feb 19, 2025
5 checks passed
@mmaietta mmaietta deleted the snapshot-files-2 branch February 19, 2025 16:35
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.

3 participants