-
Notifications
You must be signed in to change notification settings - Fork 404
feat(eve): add resumable registry setup with skip flags #1304
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
Open
OwenKephart
wants to merge
1
commit into
main
Choose a base branch
from
07-28-feat_eve_add_resumable_registry_setup
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+560
−55
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "eve": patch | ||
| --- | ||
|
|
||
| `eve add` now asks before running an official registry item's setup and prints a resumable command when setup is skipped or cancelled. Run `eve add <item> --skip-install` to launch setup later without reinstalling the item. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
164 changes: 164 additions & 0 deletions
164
packages/eve/src/cli/commands/registry-setup-command.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| import { EventEmitter } from "node:events"; | ||
|
|
||
| import { beforeEach, describe, expect, it, vi } from "vitest"; | ||
|
|
||
| import { runRegistrySetupCommand } from "./registry-setup-command.js"; | ||
|
|
||
| const { findPackageJSON, readFile, spawn } = vi.hoisted(() => ({ | ||
| findPackageJSON: vi.fn(), | ||
| readFile: vi.fn(), | ||
| spawn: vi.fn(), | ||
| })); | ||
|
|
||
| vi.mock("node:fs/promises", () => ({ readFile })); | ||
| vi.mock("node:module", () => ({ findPackageJSON })); | ||
| vi.mock("node:child_process", () => ({ spawn })); | ||
|
|
||
| function childThatCloses(code: number | null, signal: NodeJS.Signals | null = null) { | ||
| const child = new EventEmitter(); | ||
| setTimeout(() => child.emit("close", code, signal), 0); | ||
| return child; | ||
| } | ||
|
|
||
| describe("runRegistrySetupCommand", () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| findPackageJSON.mockReturnValue("/project/node_modules/@acme/slack/package.json"); | ||
| readFile.mockResolvedValue( | ||
| JSON.stringify({ | ||
| name: "@acme/slack", | ||
| bin: { "acme-slack": "./dist/cli.js", other: "./dist/other.js" }, | ||
| }), | ||
| ); | ||
| }); | ||
|
|
||
| it("runs a package's declared binary directly with Node", async () => { | ||
| spawn.mockReturnValue(childThatCloses(0)); | ||
|
|
||
| await expect( | ||
| runRegistrySetupCommand( | ||
| "/project", | ||
| { package: "@acme/slack", bin: "acme-slack", args: ["setup"] }, | ||
| "channel/slack", | ||
| ), | ||
| ).resolves.toBe("completed"); | ||
|
|
||
| expect(findPackageJSON).toHaveBeenCalledWith("@acme/slack", expect.any(URL)); | ||
| expect(spawn).toHaveBeenCalledWith( | ||
| process.execPath, | ||
| ["/project/node_modules/@acme/slack/dist/cli.js", "setup"], | ||
| expect.objectContaining({ | ||
| cwd: "/project", | ||
| env: expect.objectContaining({ EVE_SETUP: "1", EVE_SETUP_ITEM: "channel/slack" }), | ||
| stdio: "inherit", | ||
| }), | ||
| ); | ||
| }); | ||
|
|
||
| it("runs the declared eve binary without a package-manager shim", async () => { | ||
| findPackageJSON.mockReturnValue("/project/node_modules/eve/package.json"); | ||
| readFile.mockResolvedValue(JSON.stringify({ name: "eve", bin: { eve: "./bin/eve.js" } })); | ||
| spawn.mockReturnValue(childThatCloses(0)); | ||
|
|
||
| await runRegistrySetupCommand( | ||
| "/project", | ||
| { package: "eve", bin: "eve", args: ["integration", "setup", "slack"] }, | ||
| "channel/slack", | ||
| ); | ||
|
|
||
| expect(spawn).toHaveBeenCalledWith( | ||
| process.execPath, | ||
| ["/project/node_modules/eve/bin/eve.js", "integration", "setup", "slack"], | ||
| expect.any(Object), | ||
| ); | ||
| }); | ||
|
|
||
| it.each([ | ||
| [130, null], | ||
| [null, "SIGINT"], | ||
| ] as const)("maps exit %s and signal %s to cancellation", async (code, signal) => { | ||
| spawn.mockReturnValue(childThatCloses(code, signal)); | ||
|
|
||
| await expect( | ||
| runRegistrySetupCommand( | ||
| "/project", | ||
| { package: "@acme/slack", bin: "acme-slack", args: ["setup"] }, | ||
| "channel/slack", | ||
| ), | ||
| ).resolves.toBe("cancelled"); | ||
| }); | ||
|
|
||
| it("resolves string-form bin using the installed package's unscoped name", async () => { | ||
| readFile.mockResolvedValue( | ||
| JSON.stringify({ name: "@renamed/installed-slack", bin: "./dist/cli.js" }), | ||
| ); | ||
| spawn.mockReturnValue(childThatCloses(0)); | ||
|
|
||
| await runRegistrySetupCommand( | ||
| "/project", | ||
| { package: "registry-package-alias", bin: "installed-slack", args: [] }, | ||
| "channel/slack", | ||
| ); | ||
|
|
||
| expect(spawn).toHaveBeenCalledWith( | ||
| process.execPath, | ||
| ["/project/node_modules/@acme/slack/dist/cli.js"], | ||
| expect.any(Object), | ||
| ); | ||
| }); | ||
|
|
||
| it("rejects a binary the installed package does not declare", async () => { | ||
| await expect( | ||
| runRegistrySetupCommand( | ||
| "/project", | ||
| { package: "@acme/slack", bin: "something-else", args: [] }, | ||
| "channel/slack", | ||
| ), | ||
| ).rejects.toThrow('Package "@acme/slack" does not declare a "something-else" binary.'); | ||
| expect(spawn).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("rejects a declared binary outside the package directory", async () => { | ||
| readFile.mockResolvedValue( | ||
| JSON.stringify({ name: "@acme/slack", bin: { "acme-slack": "../escape.js" } }), | ||
| ); | ||
|
|
||
| await expect( | ||
| runRegistrySetupCommand( | ||
| "/project", | ||
| { package: "@acme/slack", bin: "acme-slack", args: [] }, | ||
| "channel/slack", | ||
| ), | ||
| ).rejects.toThrow( | ||
| 'Package "@acme/slack" declares its "acme-slack" binary outside the package directory.', | ||
| ); | ||
| expect(spawn).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("reports a package without binaries as not declaring the requested binary", async () => { | ||
| readFile.mockResolvedValue(JSON.stringify({ name: "@acme/slack" })); | ||
|
|
||
| await expect( | ||
| runRegistrySetupCommand( | ||
| "/project", | ||
| { package: "@acme/slack", bin: "acme-slack", args: [] }, | ||
| "channel/slack", | ||
| ), | ||
| ).rejects.toThrow('Package "@acme/slack" does not declare a "acme-slack" binary.'); | ||
| }); | ||
|
|
||
| it("does not download a missing setup package", async () => { | ||
| findPackageJSON.mockReturnValue(undefined); | ||
|
|
||
| await expect( | ||
| runRegistrySetupCommand( | ||
| "/project", | ||
| { package: "@acme/slack", bin: "acme-slack", args: ["setup"] }, | ||
| "channel/slack", | ||
| ), | ||
| ).rejects.toThrow( | ||
| 'Setup package "@acme/slack" is not installed. Run `eve add channel/slack` first.', | ||
| ); | ||
| expect(spawn).not.toHaveBeenCalled(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.