Repository navigation
fix: resolve Pi npm installs for account imports #592
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
Merged
Merged
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from "node:fs"; | ||
| import os from "node:os"; | ||
| import path from "node:path"; | ||
| import { afterEach, describe, expect, it } from "vitest"; | ||
| import { findPiCliEntry, findPiPackageDirectory } from "../src/command.js"; | ||
|
|
||
| const roots: string[] = []; | ||
| afterEach(() => { | ||
| for (const root of roots.splice(0)) rmSync(root, { recursive: true, force: true }); | ||
| }); | ||
|
|
||
| function temporaryRoot(): string { | ||
| const root = mkdtempSync(path.join(os.tmpdir(), "pi-discovery-test-")); | ||
| roots.push(root); | ||
| return root; | ||
| } | ||
|
|
||
| function writePiPackage(directory: string): void { | ||
| mkdirSync(directory, { recursive: true }); | ||
| writeFileSync( | ||
| path.join(directory, "package.json"), | ||
| JSON.stringify({ name: "@earendil-works/pi-coding-agent", bin: { pi: "dist/bundle/cli.js" } }), | ||
| ); | ||
| } | ||
|
|
||
| describe("Pi package discovery", () => { | ||
| it("finds the package next to a version-manager npm shim", () => { | ||
| const versionRoot = path.join(temporaryRoot(), "nvm", "v24.13.1"); | ||
| mkdirSync(versionRoot, { recursive: true }); | ||
| const shim = path.join(versionRoot, "pi.cmd"); | ||
| writeFileSync(shim, "@echo off\r\n"); | ||
| const packageDirectory = path.join( | ||
| versionRoot, | ||
| "node_modules", | ||
| "@earendil-works", | ||
| "pi-coding-agent", | ||
| ); | ||
| writePiPackage(packageDirectory); | ||
|
|
||
| expect(findPiPackageDirectory(shim)).toBe(packageDirectory); | ||
| const cliEntry = path.join(packageDirectory, "dist", "bundle", "cli.js"); | ||
| mkdirSync(path.dirname(cliEntry), { recursive: true }); | ||
| writeFileSync(cliEntry, ""); | ||
| expect(findPiCliEntry(packageDirectory)).toBe(cliEntry); | ||
| }); | ||
|
|
||
| it("finds the package when the executable is inside its package directory", () => { | ||
| const packageDirectory = path.join( | ||
| temporaryRoot(), | ||
| "node_modules", | ||
| "@earendil-works", | ||
| "pi-coding-agent", | ||
| ); | ||
| const executable = path.join(packageDirectory, "dist", "cli.js"); | ||
| mkdirSync(path.dirname(executable), { recursive: true }); | ||
| writeFileSync(executable, ""); | ||
| writePiPackage(packageDirectory); | ||
|
|
||
| expect(findPiPackageDirectory(executable)).toBe(packageDirectory); | ||
| }); | ||
|
|
||
| it("rejects a CLI entry that escapes the Pi package directory", () => { | ||
| const packageDirectory = path.join(temporaryRoot(), "pi-package"); | ||
| mkdirSync(packageDirectory, { recursive: true }); | ||
| writeFileSync( | ||
| path.join(packageDirectory, "package.json"), | ||
| JSON.stringify({ name: "@earendil-works/pi-coding-agent", bin: { pi: "../outside.js" } }), | ||
| ); | ||
| writeFileSync(path.join(path.dirname(packageDirectory), "outside.js"), ""); | ||
|
|
||
| expect(findPiCliEntry(packageDirectory)).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("does not treat an unrelated npm package as Pi", () => { | ||
| const executable = path.join(temporaryRoot(), "bin", "pi.cmd"); | ||
| mkdirSync(path.dirname(executable), { recursive: true }); | ||
| writeFileSync(executable, "@echo off\r\n"); | ||
| writeFileSync( | ||
| path.join(path.dirname(executable), "package.json"), | ||
| JSON.stringify({ name: "some-other-package" }), | ||
| ); | ||
|
|
||
| expect(findPiPackageDirectory(executable)).toBeUndefined(); | ||
| }); | ||
| }); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the selected executable is a wrapper or non-npm Pi binary beneath any directory containing a separate
node_modules/@earendil-works/pi-coding-agent—for example, a custom wrapper inside a project with a stale Pi dependency—this loop accepts that unrelated package from any ancestor without establishing that the executable points to it.installation()then imports authentication modules, performs collision checks, and generates extension paths using a different Pi installation, contradicting its guarantee to reject unrelated installs; restrict the fallback to a verified npm shim layout or validate the shim's target.Useful? React with 👍 / 👎.