@danypops/pi-packed 0.28.0 → 0.28.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"smoke.d.ts","sourceRoot":"","sources":["../../service/src/adoption/smoke.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,WAAW,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,GAAG,mBAAmB,GAAG,cAAc,GAAG,qBAAqB,CAAC;AAEpH,MAAM,WAAW,kBAAkB;IAClC,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,SAAS,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,MAAM,WAAW,oBAAoB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,WAAW,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,kBAAkB,CAAC;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,YAAY;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB;AA2BD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAO7F;AA4ID,wBAAsB,iBAAiB,CACtC,WAAW,EAAE,MAAM,EACnB,aAAa,EAAE,MAAM,EACrB,OAAO,GAAE,YAAiB,GACxB,OAAO,CAAC,oBAAoB,CAAC,CAoF/B"}
1
+ {"version":3,"file":"smoke.d.ts","sourceRoot":"","sources":["../../service/src/adoption/smoke.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,WAAW,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,GAAG,mBAAmB,GAAG,cAAc,GAAG,qBAAqB,CAAC;AAEpH,MAAM,WAAW,kBAAkB;IAClC,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,SAAS,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,MAAM,WAAW,oBAAoB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,WAAW,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,kBAAkB,CAAC;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,YAAY;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB;AAuDD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAO7F;AAmJD,wBAAsB,iBAAiB,CACtC,WAAW,EAAE,MAAM,EACnB,aAAa,EAAE,MAAM,EACrB,OAAO,GAAE,YAAiB,GACxB,OAAO,CAAC,oBAAoB,CAAC,CAoF/B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danypops/pi-packed",
3
- "version": "0.28.0",
3
+ "version": "0.28.1",
4
4
  "description": "Pi package lifecycle, validation, daemon, tools, profiles, and TUI",
5
5
  "type": "module",
6
6
  "bin": {
@@ -54,6 +54,34 @@ function addReadOnlyBind(args: string[], path: string): void {
54
54
  if (existsSync(path)) args.push("--ro-bind", path, path);
55
55
  }
56
56
 
57
+ const MAX_ANCESTOR_WALK = 32;
58
+
59
+ /**
60
+ * Every ancestor directory's own node_modules from packageRoot's parent up to
61
+ * the filesystem root -- mirrors Node's real module-resolution walk
62
+ * (require.resolve checks <dir>/node_modules at every level up to /).
63
+ * Confirmed live: packed doctor's own widget reported real extensions
64
+ * (pi-lector, pi-pipes, pi-tickets, pi-jittor, pi-web-spider) as "crash" on a
65
+ * plain Cannot-find-module for a sibling dependency npm/bun hoisted to a
66
+ * shared ancestor node_modules, though Pi's own real, unsandboxed process
67
+ * resolves the exact same import fine -- the sandbox only ever bound the
68
+ * package's own root, never the hoisted siblings one or more levels above it.
69
+ * Bounded to MAX_ANCESTOR_WALK levels as a defensive cap; a real filesystem
70
+ * hierarchy never gets remotely close to that before reaching /.
71
+ */
72
+ function collectAncestorNodeModulesDirs(packageRoot: string): string[] {
73
+ const dirs: string[] = [];
74
+ let current = dirname(packageRoot);
75
+ for (let i = 0; i < MAX_ANCESTOR_WALK; i++) {
76
+ const candidate = join(current, "node_modules");
77
+ if (existsSync(candidate)) dirs.push(realpathSync(candidate));
78
+ const parent = dirname(current);
79
+ if (parent === current) break;
80
+ current = parent;
81
+ }
82
+ return dirs;
83
+ }
84
+
57
85
  /**
58
86
  * Resolves an installed dependency's real on-disk package directory via
59
87
  * Node's own module-resolution algorithm (require.resolve against its
@@ -85,7 +113,6 @@ function sandboxCommand(packageRoot: string, extensionPath: string, maxProcesses
85
113
  const jitiModules = resolveDependencyModulesDir(packageDirectory, "jiti");
86
114
  if (!jitiModules) return undefined;
87
115
  const bun = realpathSync(process.execPath);
88
- const relativeExtension = relative(packageRoot, extensionPath).split(sep).join("/");
89
116
  const args = [
90
117
  "/usr/bin/bwrap",
91
118
  "--unshare-user",
@@ -116,9 +143,6 @@ function sandboxCommand(packageRoot: string, extensionPath: string, maxProcesses
116
143
  jitiModules,
117
144
  "/runner/node_modules/jiti",
118
145
  "--ro-bind",
119
- packageRoot,
120
- "/package",
121
- "--ro-bind",
122
146
  bun,
123
147
  "/bun",
124
148
  "--dev",
@@ -131,6 +155,17 @@ function sandboxCommand(packageRoot: string, extensionPath: string, maxProcesses
131
155
  "/tmp",
132
156
  "--dir",
133
157
  "/tmp/home",
158
+ );
159
+ // Package-related identity binds go AFTER the virtual/tmpfs mounts above --
160
+ // bwrap applies mounts in argument order, so a bind whose real path happens
161
+ // to sit under one of those special mounts (e.g. a test fixture under
162
+ // /tmp, which --tmpfs /tmp would otherwise shadow) must come later to win.
163
+ addReadOnlyBind(args, packageRoot);
164
+ // Real-path identity binds so a hoisted sibling dependency resolves exactly
165
+ // as it would in Pi's own real, unsandboxed process -- see
166
+ // collectAncestorNodeModulesDirs's own doc comment for why this is needed.
167
+ for (const dir of collectAncestorNodeModulesDirs(packageRoot)) addReadOnlyBind(args, dir);
168
+ args.push(
134
169
  "--remount-ro",
135
170
  "/",
136
171
  "--clearenv",
@@ -147,7 +182,7 @@ function sandboxCommand(packageRoot: string, extensionPath: string, maxProcesses
147
182
  "NODE_PATH",
148
183
  "/runner/node_modules",
149
184
  "--chdir",
150
- "/package",
185
+ packageRoot,
151
186
  "--",
152
187
  "/usr/bin/prlimit",
153
188
  `--nproc=${maxProcesses}`,
@@ -158,7 +193,7 @@ function sandboxCommand(packageRoot: string, extensionPath: string, maxProcesses
158
193
  "--",
159
194
  "/bun",
160
195
  "/runner/src/smoke-child.ts",
161
- `/package/${relativeExtension}`,
196
+ extensionPath,
162
197
  );
163
198
  return args;
164
199
  }
@@ -151,6 +151,35 @@ describeIfSandboxed("isolated extension smoke runner", () => {
151
151
  expect((await runExtensionSmoke(output.root, output.path, { maxOutputBytes: 4_096 })).status).toBe("output-limit");
152
152
  });
153
153
 
154
+ it("resolves a dependency hoisted to a shared ancestor node_modules -- confirmed live bug: packed doctor's own widget reported 5/8 real extensions as crashing on a plain 'Cannot find module' for a sibling dependency npm/bun hoisted above the package's own node_modules, though Pi's own real, unsandboxed process resolves the exact same import fine", async () => {
155
+ const workspaceRoot = mkdtempSync(join(tmpdir(), "packed-smoke-hoisted-"));
156
+ roots.push(workspaceRoot);
157
+ const sharedNodeModules = join(workspaceRoot, "node_modules");
158
+ writeFakeDependency(sharedNodeModules, "hoisted-sibling");
159
+ const packageDir = join(sharedNodeModules, "@fixture", "pi-smoke-hoisted");
160
+ mkdirSync(join(packageDir, "extension"), { recursive: true });
161
+ const extensionPath = join(packageDir, "extension", "index.ts");
162
+ writeFileSync(
163
+ extensionPath,
164
+ 'import pkg from "hoisted-sibling/package.json" with { type: "json" };\nexport default function (pi: any) { pi.registerCommand(pkg.name, { handler() {} }); }\n',
165
+ );
166
+ writeFileSync(
167
+ join(packageDir, "package.json"),
168
+ JSON.stringify({
169
+ name: "@fixture/pi-smoke-hoisted",
170
+ version: "1.0.0",
171
+ keywords: ["pi-package"],
172
+ files: ["extension"],
173
+ pi: { extensions: ["extension/index.ts"] },
174
+ }),
175
+ );
176
+
177
+ const result = await runExtensionSmoke(packageDir, extensionPath);
178
+
179
+ expect(result.status).toBe("ok");
180
+ expect(result.registrations.commands).toEqual(["hoisted-sibling"]);
181
+ });
182
+
154
183
  it("keeps default package checks static and adds smoke results only when requested", async () => {
155
184
  const fixture = extension(
156
185
  'import { writeFileSync } from "node:fs"; export default function (pi: any) { writeFileSync("executed", "yes"); pi.registerCommand("x", { handler() {} }); }',