feat(instances): spawn a host-capable nvim without the user's config
Opening a project from the console needed `:PiWebStart` first because the
managed spawn loaded the *user's* nvim config and ran with `stdio:"ignore"`.
When that config did not resolve pi2.nvim (lazy.nvim, a dev worktree behind
`PI_DEV_DIR`, a service with a frozen PATH) or the checkout lacked
`lua/pi/host.lua`, nvim stayed alive and silent and `instance.ensure` could only
report a bare 5 s timeout: nothing to read, nothing to fix.
- `core/plugin`: discover the plugin (`PI2_PLUGIN_DIR`, lazy.nvim,
`site/pack/*/{start,opt}`, system dirs) and require both `lua/pi/host.lua` and
`lua/pi/web/bridge.lua`; name a misconfigured `PI2_PLUGIN_DIR` first.
- `instances/host-init`: generate a minimal init (prepend the plugin, prepend
nothing else, `cquit 1` when `pi.host` is missing) so a spawn fails with a real
exit code instead of silence. `PI2_NVIM_INIT` keeps `user` (the old
behaviour) and any explicit path.
- supervisor: refuse to spawn when no host-capable plugin exists, route the
child's stdout/stderr into `instances/<id>.log`, and fold the log tail into
`instance_state.reason` and the thrown error. `PI2_ENSURE_TIMEOUT_MS`
(default 10000) replaces the fixed 5 s.
- `core/paths`: one shared `expandTilde` for the plugin probe, the workspace
allowlist and `pi2 doctor`.
This commit is contained in:
1 parent
c933eb39ad
commit
db387ae248
9 files changed
+1162
-40
No files matched your search
@@ -31,7 +31,15 @@ export interface TempEnv {
|
||||
cleanup(): void;
|
||||
}
|
||||
|
||||
const ENV_KEYS = ["PI2_RUNTIME_DIR", "PI2_DATA_DIR", "PI2_STATE_DIR", "PI2_NVIM_BIN", "PI2_NVIM_INIT"] as const;
|
||||
const ENV_KEYS = [
|
||||
"PI2_RUNTIME_DIR",
|
||||
"PI2_DATA_DIR",
|
||||
"PI2_STATE_DIR",
|
||||
"PI2_NVIM_BIN",
|
||||
"PI2_NVIM_INIT",
|
||||
"PI2_PLUGIN_DIR",
|
||||
"PI2_ENSURE_TIMEOUT_MS",
|
||||
] as const;
|
||||
|
||||
export function makeTempEnv(prefix = "pi2-daemon-instances-"): TempEnv {
|
||||
const dir = mkdtempSync(join(tmpdir(), prefix));
|
||||
@@ -42,6 +50,11 @@ export function makeTempEnv(prefix = "pi2-daemon-instances-"): TempEnv {
|
||||
|
||||
const saved = new Map<string, string | undefined>();
|
||||
for (const key of ENV_KEYS) saved.set(key, process.env[key]);
|
||||
// The developer's own spawn knobs must not decide which init a test spawns
|
||||
// with: clear them so the default (generated host init) is what runs.
|
||||
for (const key of ["PI2_NVIM_BIN", "PI2_NVIM_INIT", "PI2_PLUGIN_DIR", "PI2_ENSURE_TIMEOUT_MS"] as const) {
|
||||
delete process.env[key];
|
||||
}
|
||||
process.env.PI2_RUNTIME_DIR = runtime;
|
||||
process.env.PI2_DATA_DIR = data;
|
||||
process.env.PI2_STATE_DIR = state;
|
||||
|
||||
Reference in new issue
Block a user