Wire settings.json filter rewrite into dedupeAndRegister() #170
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#170
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
After
dedupeAndRegister()runspi install <repo-path>, rewrite the resulting settings.json package entry into the object filter form (usingbuildPackageFilters()) wheneverfjorrgis unusable, so this single local-path registration actually excludes the affected extensions/skills. When both tools are fully available, leave the entry as the plain string sourcepi installalready wrote.Background
scripts/local-install.mjs'sdedupeAndRegister(cwd, options)currently:pi install <absRepoPath>, which registers the whole checkout with a plain string source — no filtering.With
preflight()now returning{ rgOk, fjState }(see "Refactor preflight() to skip/warn for missing fj/rg instead of hard-failing") andmain()already threading atoolStateoption through todedupeAndRegister(cwd, { ...options, toolState }), this step makesdedupeAndRegister()actually usetoolStateto apply the correct filter, viabuildPackageFilters()(see "Implement buildPackageFilters() with exhaustive unit tests").dedupeAndRegister()already reads/writes the settings.json file for the removal step (see its existing BOM-stripping JSON read logic and warn-and-continue behavior on unreadable/missing files) — this step extends that same responsibility rather than introducing a new I/O path.Depends on: "Implement buildPackageFilters() with exhaustive unit tests" (provides the filter-building logic this step applies) and "Refactor preflight() to skip/warn for missing fj/rg instead of hard-failing" (provides the
toolStatevalue threaded throughmain()intodedupeAndRegister()'soptions).Implementation Details
In
dedupeAndRegister(), after the successfulpi install <absRepoPath>call, add a new step:Add the new
rewritePackageEntry(file, absRepoPath, filters)helper:Notes:
existsSync,readFileSync,writeFileSyncare already imported inscripts/local-install.mjs(used by the existing removal logic) — reuse them, do not re-import.{ source, ...filters }(never merges with a prior filtered state). BecausededupeAndRegister()already removes-then-reinstalls on every run, callingrewritePackageEntryfresh each time naturally adds the exclusion when a tool disappears, and naturally drops it (sincefiltersisnulland no rewrite happens, leavingpi install's plain string entry) when the tool reappears on a later run.filtersisnull(both tools fully available, or fj merely unauthenticated),rewritePackageEntryis not called at all — the plain string entrypi installwrote stands unchanged.dedupeAndRegister()'s existingoptions.globalSettingsFileoverride (used by tests to point at a temp file) applies to this new rewrite step too — do not introduce a second settings-file parameter.Acceptance Criteria
toolStateindicates both tools fully available (or is omitted, defaulting to fully-available), the settings.json package entry for this repo remains a plain string afterdedupeAndRegister()runs (no rewrite).toolState.rgOk === false(and fj is ok), the entry becomes{ source: <absRepoPath>, extensions: ["!extensions/rg/index.ts"], skills: [] }.toolState.fjState === "absent"(and rg is ok), the entry becomes{ source: <absRepoPath>, extensions: ["!extensions/pr-comments/src/index.ts"], skills: ["!skills/forgejo-cli"] }.rgOk === falseandfjState === "absent", the entry becomes the combined filter shape with both extension exclusions and the skill exclusion.toolState.fjState === "unauthenticated", the entry remains a plain string (unauthenticated must not trigger a filter rewrite).dedupeAndRegister()twice in sequence against the same settings file with differenttoolStatevalues on each call produces the settings entry matching the second call'stoolState— no stale filter persists from the first call (re-derive-fresh, no accumulation).pi install,dedupeAndRegister()logs a warning and does not abort or throw.dedupeAndRegister()tests (URL-entry removal/dedupe, BOM stripping, unreadable-settings warn-and-continue,pi remove/pi installfailure abort paths) continue to pass unmodified — none of them pass atoolStateoption, so they exercise the default fully-available path and see no filter rewrite.Test Plan
dedupeAndRegisterwith notoolState(or{ rgOk: true, fjState: "ok" }) → resulting settings entry is the plain stringresolve(cwd).dedupeAndRegisterwith{ rgOk: false, fjState: "ok" }→ entry matches the rg-only filter shape.dedupeAndRegisterwith{ rgOk: true, fjState: "absent" }→ entry matches the fj-only filter shape.dedupeAndRegisterwith{ rgOk: false, fjState: "absent" }→ entry matches the combined filter shape.dedupeAndRegisterwith{ rgOk: true, fjState: "unauthenticated" }→ entry stays a plain string.dedupeAndRegistercalls against the same settings file with{ rgOk: false, fjState: "ok" }then{ rgOk: true, fjState: "ok" }→ final entry is the plain string (rg exclusion removed, not retained).globalSettingssuch that the just-installed entry can't be found (e.g. directly exerciserewritePackageEntryagainst a settings object lacking the expected source) → no throw, warning logged,aborted === false.dedupeAndRegistertest suite — all pass unmodified.npm test— all green.pi-loop opened and merged a pull request for this issue: #179