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(xsnap): Verify npm install build process #11051

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kriskowal
Copy link
Member

refs: #9674

Description

In support of #9674, this change adds a regression test for npm install to increase our confidence that changes to build.js support both local development and eventual installation from npm.

Security Considerations

None.

Scaling Considerations

A design question for this is whether to use a temporary directory for the extracted package. I chose to use the default package since this speeds up non-initial test runs. Since tar xf overlays the package over the previous version, there’s a small chance that the deletion of a sensitive file might go unnoticed locally, but not in CI.

Documentation Considerations

None.

Testing Considerations

It’s a test, Bob.

Upgrade Considerations

None.

@kriskowal kriskowal requested a review from a team as a code owner February 25, 2025 19:56
Copy link

Deploying agoric-sdk with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3035728
Status: ✅  Deploy successful!
Preview URL: https://d5d85289.agoric-sdk.pages.dev
Branch Preview URL: https://kriskowal-xsnap-install-test.agoric-sdk.pages.dev

View logs

@@ -29,7 +29,7 @@ const ModdableSDK = {
* spawn: typeof import('child_process').spawn,
* }} io
*/
function makeCLI(command, { spawn }) {
export function makeCLI(command, { spawn }) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is an unabashèd shortcut, punting on the effort and thought that should go into extracting a utility for use in other packages or committing to a shared dependency that replaces the functionality. Whatever form that takes, we need to consider that the dependency will be a full dependency, not a devDependency, and assess risk accordingly. Given that there are intersecting changes in concurrent PRs, punt punt punt.

Copy link
Member

@gibson042 gibson042 left a comment

Choose a reason for hiding this comment

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

I'm not worried about the speed of this test; following good practices (including cleanup) is more important. So 👍 to using a temp dir.

Comment on lines +11 to +18
const npm = makeCLI('npm', { spawn });
const tar = makeCLI('tar', { spawn });
const npmRes = await npm.pipe(['pack', '--json']);
const {
0: { filename },
} = JSON.parse(npmRes);
await tar.run(['xf', filename]);
await npm.run(['install'], { cwd: 'package' });
Copy link
Member

Choose a reason for hiding this comment

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

Rather than extracting makeCLI, I recommend following userland's use of execa for testing as seen in e.g. fast-usdc.

Suggested change
const npm = makeCLI('npm', { spawn });
const tar = makeCLI('tar', { spawn });
const npmRes = await npm.pipe(['pack', '--json']);
const {
0: { filename },
} = JSON.parse(npmRes);
await tar.run(['xf', filename]);
await npm.run(['install'], { cwd: 'package' });
const { stdout: npmRes } = await execa`npm pack --json`;
const {
0: { filename },
} = JSON.parse(npmRes);
await execa`tar xf ${filename}`;
await execa({ cwd: 'package' })`npm install`;

Comment on lines +14 to +16
const {
0: { filename },
} = JSON.parse(npmRes);
Copy link
Member

Choose a reason for hiding this comment

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

Making this more idiomatic would improve readability.

Suggested change
const {
0: { filename },
} = JSON.parse(npmRes);
const [{ filename }] = JSON.parse(npmRes);

Copy link
Member

@mhofman mhofman left a comment

Choose a reason for hiding this comment

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

I'm confused how this test does not leave junk behind that the "clean worktree" CI test would trip on.

@kriskowal
Copy link
Member Author

I'm confused how this test does not leave junk behind that the "clean worktree" CI test would trip on.

The clean worktree CI test occurs before this test generates the junk. Unless I’m confused. But, I will be moving the junk to a temporary directory for idempotence.

@mhofman
Copy link
Member

mhofman commented Feb 27, 2025

The clean worktree CI test occurs before this test generates the junk. Unless I’m confused. But, I will be moving the junk to a temporary directory for idempotence.

#9804 was supposed to have fixed #5140. If that's not the case, I'd like to understand how it failed.

The test in which cd packages/xsnap && yarn test ran show it didn't find any dirty files. Maybe we're git ignoring the junk already?

@kriskowal
Copy link
Member Author

#9804 was supposed to have fixed #5140. If that's not the case, I'd like to understand how it failed.

I see. I did not know we did our dirty check after running tests. The reason it succeeded is that this change, for unrelated reasons, adds package to packages/xsnap/.gitignore, which is the conventional name of the directory inside the tarball that npm pack generates, and the build script in there only creates files inside that package directory tree.

@mhofman
Copy link
Member

mhofman commented Feb 28, 2025

adds package to packages/xsnap/.gitignore

Ah and the tgz is excluded in the root gitignore:

agoric-sdk/.gitignore

Lines 42 to 43 in a27f724

# Output of 'npm pack'
*.tgz

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