Add fj/rg tool-detection helpers (rgAvailable, detectFjState) with unit tests #167
Labels
No labels
bug
chore
documentation
enhancement
feature
ready
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
david/pi-extensions-and-skills#167
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Add two small detection helpers to
scripts/local-install.mjs—rgAvailable()anddetectFjState()— that report whether the optionalrg(ripgrep) andfj(Forgejo CLI) binaries are usable, without aborting the process. These replace the current hard-fail probes as pure status-reporting functions that later steps (preflight refactor, settings.json filtering) will consume.Background
scripts/local-install.mjsis the repo'snpm run install:localinstaller (seedocs/IMPLEMENTATION_PLAN.mdfor the original script design). Itspreflight()function currently hard-aborts the entire install ifrgis missing from PATH, or iffj auth listfails/returns empty output. This is the first of a multi-step change to make the installer degrade gracefully instead: missingrgshould only disable thergextension, and missing/unauthenticatedfjshould only disable thepr-commentsextension andforgejo-cliskill — everything else should still install.This step only adds the detection functions themselves (no behavior change to
preflight()yet — that's a separate, dependent step).The existing
commandAvailable(cmd)helper (checkscmdis on PATH viacommand -v/where) is already implemented inscripts/local-install.mjsand should be reused, not reimplemented.Implementation Details
In
scripts/local-install.mjs, near the existingcommandAvailable()helper, add:Notes:
run()andok()are existing internal helpers in the file (runwrapsspawnSync;okchecks!result.error && result.status === 0) — reuse them exactly as today'sfj auth listpreflight check does.export function ...) so they're directly importable by the test file, matching the existing export style used forcommandAvailable-adjacent helpers likeisInsideManagedClone.preflight()in this step — it still calls its own inlinefj auth list/rgchecks and hard-fails exactly as today. That refactor is a separate, dependent step.Test harness change needed for
detectFjState()testsscripts/local-install.test.mjs'smakeShimDir()helper currently always writes anfjshim into the generated PATH directory (there is no way to omit it, unlikewithRg/withPiwhich already support this). Add awithFj = trueoption:When
withFj: false, the caller must also restrictPATHto the shim dir alone (mirroring howwithRg: false/withPi: falseare handled today inrunPreflightAndCaptureAbort), socommandAvailable("fj")actually returnsfalsein the test rather than falling through to a realfjon the developer's machine.Acceptance Criteria
rgAvailable()is exported fromscripts/local-install.mjsand returnstrue/falsebased oncommandAvailable("rg").detectFjState()is exported fromscripts/local-install.mjsand returns exactly one of"absent","unauthenticated", or"ok".makeShimDir()inscripts/local-install.test.mjssupports awithFjoption (defaulttrue) that, whenfalse, omits thefjshim and is included in the PATH-restriction condition.detectFjState()returns"absent"whenfjis not on PATH (viawithFj: false).detectFjState()returns"unauthenticated"whenfj auth listfails (via the existingfjAuthFails: trueshim flag).detectFjState()returns"unauthenticated"whenfj auth listreturns no accounts (via the existingfjAuthEmpty: trueshim flag).detectFjState()returns"ok"whenfjis present andfj auth listsucceeds with output (default shim).rgAvailable()returnsfalsewhenrgis absent (via the existingwithRg: falseshim flag) andtrueby default.preflight()'s existing behavior (hard-fail on missing rg/fj) is unchanged by this step — no existing tests should need to change.Test Plan
npm test(runsnode --test scripts/local-install.test.mjs) — all existing tests still pass unmodified, plus the new detection-helper tests pass.node --test scripts/local-install.test.mjsrun directly — same result.detectFjState()returns"ok"on a machine withfjinstalled and authenticated, by temporarily adding a one-offconsole.log(detectFjState())call (or a throwaway test) and removing it before commit.pi-loop opened and merged a pull request for this issue: #176