Implement buildPackageFilters() with exhaustive unit tests #169
Labels
No labels
bug
chore
documentation
enhancement
feature
ready
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
david/pi-extensions-and-skills#169
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 a pure function
buildPackageFilters({ rgOk, fjState })toscripts/local-install.mjsthat translates detected tool state into the pi settings.json package-filter shape (ornullwhen no filtering is needed). This is the core mapping logic that the settings.json rewrite step will apply.Background
pi's package system supports an object filter form in
settings.jsonfor narrowing what a registered package loads:!patternexcludes matching paths; omitting a key loads all of that type. This is documented in pi's packages documentation under "Package Filtering".Given the tool-state object
{ rgOk, fjState }(produced bypreflight()— see the fj/rg detection-helpers and preflight-refactor steps), the installer needs to build the exact filter object to apply to this repo's single local-path package registration:fjState === "absent"→ excludeextensions/pr-comments/src/index.tsandskills/forgejo-cli.!rgOk→ excludeextensions/rg/index.ts.fjState === "unauthenticated"or"ok"→ do NOT exclude pr-comments/forgejo-cli (unauthenticated is warn-only, not a skip trigger).Depends on: #167 (Add fj/rg tool-detection helpers (rgAvailable, detectFjState) with unit tests) and #168 (Refactor preflight() to skip/warn for missing fj/rg instead of hard-failing) — both establish the
{ rgOk, fjState }tool-state contract this function consumes. This function's own unit tests construct{ rgOk, fjState }objects directly (not viapreflight()), so implementation can proceed in parallel if needed, but the contract shape must match.Implementation Details
Add to
scripts/local-install.mjs:Notes:
pr-commentsexclusion is always pushed before thergexclusion in theextensionsarray when both apply.unauthenticatedandokare treated identically by this function (neither triggers exclusion) — only"absent"triggers the fj-related exclusions.Acceptance Criteria
buildPackageFilters({ rgOk: true, fjState: "ok" })returnsnull.buildPackageFilters({ rgOk: true, fjState: "unauthenticated" })returnsnull(unauthenticated is not a filter trigger).buildPackageFilters({ rgOk: false, fjState: "ok" })returns{ extensions: ["!extensions/rg/index.ts"], skills: [] }.buildPackageFilters({ rgOk: false, fjState: "unauthenticated" })returns{ extensions: ["!extensions/rg/index.ts"], skills: [] }.buildPackageFilters({ rgOk: true, fjState: "absent" })returns{ extensions: ["!extensions/pr-comments/src/index.ts"], skills: ["!skills/forgejo-cli"] }.buildPackageFilters({ rgOk: false, fjState: "absent" })returns{ extensions: ["!extensions/pr-comments/src/index.ts", "!extensions/rg/index.ts"], skills: ["!skills/forgejo-cli"] }(pr-comments exclusion listed before rg exclusion).Test Plan
assert.deepEqual.npm test— all green, including these new pure-function tests (no PATH shims or temp directories needed for this specific test group).pi-loop opened and merged a pull request for this issue: #178