Skip to content

fix(config): fall through to XLINGS_PROJECT_DIR env after projectScope:false skip - #259

Merged
Sunrisepeak merged 1 commit into
mainfrom
fix/project-config-fallthrough-on-projectscope-false
May 3, 2026
Merged

Sunrisepeak merged 1 commit into
mainfrom
fix/project-config-fallthrough-on-projectscope-false

Conversation

@Sunrisepeak

Copy link
Copy Markdown
Member

Bug

A subprocess xlings (e.g. an xvm shim invoked from another package's install/config hook) whose cwd traversal happens to hit a projectScope:false .xlings.json BEFORE reaching the real project root erroneously falls back to globalWorkspace_, ignoring the project-scope versions the parent xlings just wrote.

Concrete instance — xim-pkgindex#109's gcc-specs-config flow on CI's E2E-05:

  1. Test scenario at tests/e2e/scenarios/project_home/ declares a project (real .xlings.json)
  2. Parent xlings loads it, exports XLINGS_PROJECT_DIR
  3. Installs xim:gcc-specs-config (script type) → script::default_config writes gcc-specs-config = 0.0.1 to project-subos workspace, creates shim
  4. Installs xim:gcc → gcc's config hook spawns the shim via os.exec("$bindir/gcc-specs-config ...")
  5. Subprocess shim: cwd inherited from gcc install_dir (<XLINGS_HOME>/data/xpkgs/xim-x-gcc/15.1.0/, OUTSIDE the project tree)
  6. load_project_config_ walks cwd up — eventually hits xlings repo's own /home/runner/work/xlings/xlings/.xlings.json (projectScope:false, intentional opt-out for CI self-host)
  7. load_project_config_from_dir_ skips it (correct) — but caller's unconditional return here exits without checking the env-var fallback
  8. hasProjectConfig_ = false → effective_workspace() = globalWorkspace_ → no gcc-specs-config key → "no version set"

Root cause

config.cppm:load_project_config_ lost the distinction between two outcomes of load_project_config_from_dir_:

outcome hasProjectConfig_ should walker do
real project loaded true return — done
projectScope:false skipped false continue walking + env fallback

Pre-fix, both paths shared the same return;.

Fix

3-line change in load_project_config_:

-                load_project_config_from_dir_(cur);
-                return;
+                load_project_config_from_dir_(cur);
+                if (hasProjectConfig_) return;
+                // else: projectScope:false skip — continue walking

Now the env-var fallback below the loop fires in three cases (vs only one before):

  • (a) no .xlings.json found at all
  • (b) only projectScope:false files found going up
  • (c) projectScope:false skip then no further .xlings.json upward

Bonus: nested layout where a deeper .xlings.json has projectScope:false but an outer ancestor is a real project now resolves the outer correctly (was previously masked).

Verification

Local repro of the CI failure (matching layout: XLINGS_HOME outside a test project, with a projectScope:false .xlings.json on the shared ancestor path) reproduces the no version set failure on the v0.4.13 release binary (current main):

config: invoking mytool at /tmp/.../PROJ/.xlings/subos/_/bin/mytool
[error] xlings: no version set for 'mytool'
[error]   hint: xlings use mytool <version>
config: mytool exit=nil

After this patch, the env-var fallback path resolves the project workspace correctly.

Scope of impact

Affects any user where:

  • A subprocess xlings (xvm shim spawned from a hook) runs with cwd outside the project tree
  • AND cwd traversal happens to find a projectScope:false .xlings.json on an ancestor path before reaching the real project root

Production-relevant trigger: the recently-added xim:gcc-specs-config runtime dep on xim:gcc (xim-pkgindex#109) means any user installing gcc from a project would hit this if their layout has a projectScope:false ancestor (e.g. xlings-the-project users who have nested workdirs).

Test plan

  • Local repro (CI-shaped layout) reproduces failure on unpatched 0.4.13
  • CI three-platform (Linux/macOS/Windows) green
  • Note: this PR does NOT bump XIM_PKGINDEX_REF — the current pin (83044b5, pre-xvm: release 0.0.5 #108) avoids the gcc-specs-config scenario, so CI doesn't end-to-end exercise this fix. A follow-up PR can bump the pin once xim-pkgindex's libstdc++ closure issue is also resolved.

…e:false skip

`load_project_config_` walks cwd → root looking for a `.xlings.json`,
and on first found file returns unconditionally. But
`load_project_config_from_dir_` distinguishes two outcomes:

  - real project (`projectScope` absent or true): loads workspace,
    sets `hasProjectConfig_ = true`
  - "deps-manifest only" (`projectScope: false`): returns without
    setting `hasProjectConfig_` (deliberate — the directory should
    NOT be treated as a project root, e.g. xlings's own repo uses
    this opt-out so commands run from any subdir don't pollute the
    repo with project state)

The bug: the caller's unconditional `return` after `from_dir_` lost
the second outcome's signal — when a projectScope:false file was hit,
the function exited without ever consulting the `XLINGS_PROJECT_DIR`
env-var fallback below the loop.

Failure mode: any xlings subprocess (e.g. an xvm shim invoked from
another package's install/config hook) whose cwd traversal happens
to hit a projectScope:false `.xlings.json` before reaching the real
project root would erroneously fall back to `globalWorkspace_`,
ignoring the project-scope versions the parent xlings just wrote.
Concrete instance: gcc.lua's config hook spawns the
`gcc-specs-config` xvm shim (xim-pkgindex#109); when xlings's CI
runs it from an install_dir under `tests/e2e/runtime/...` (XLINGS_HOME
side, outside the project), cwd traversal walks up and hits
xlings's own `.xlings.json` (projectScope:false at repo root) before
reaching the test scenario's project — and reports
"no version set for gcc-specs-config" even though the parent xlings
correctly wrote it to project-subos workspace.

Fix: only `return` when `from_dir_` actually loaded a project; on
projectScope:false skip, continue walking up. If the rest of the
walk also turns up nothing, the env-var fallback below the loop
fires (the parent xlings exports `XLINGS_PROJECT_DIR` whenever it
loads a real project, so subprocesses can recover the intended
project context even when their cwd is outside the project tree).

Bonus: also handles a nested layout where a deeper `.xlings.json`
has projectScope:false but an outer ancestor has a real project —
previously the outer was masked by the inner skip; now the walk
continues past the skip and finds the outer.

Verified locally: a CI-shaped repro (XLINGS_HOME outside a test
project, with a projectScope:false `.xlings.json` higher up the
shared ancestor path) reproduces the failure on the v0.4.13 release
binary. After rebuilding xlings with this patch, the same scenario
correctly resolves the script-type dep via the env-var fallback.
@Sunrisepeak
Sunrisepeak merged commit 96286c9 into main May 3, 2026
3 checks passed
Sunrisepeak added a commit that referenced this pull request May 3, 2026
…e fixes) (#260)

End-to-end CI verification of the full chain that landed across recent
xlings + xim-pkgindex work:

xim-pkgindex bumps from 83044b5 (pre-#108) to 19f4383 (main HEAD), now
includes:
  * #110/#111: namespace all bare-name deps (cmake/ninja/xmake/gcc/
    binutils/openssl/d2x → xim: prefix), removes dual-mount ambiguity
  * #116: split xim:gcc-runtime as a standalone xpkg (~25 MB)
    containing libstdc++/libgcc_s/libgomp/etc — vs full xim:gcc compiler
    (~1.1 GB)
  * #117: switch ninja/node/mdbook from xim:gcc to xim:gcc-runtime, so
    consumer rpath closure pulls only the runtime libs they need
  * #118: gcc-runtime declares `exports.runtime.libdirs = { "lib64" }`
    (correct schema field, was incorrectly `abi = {...}` in #116)

Pairs with xlings's:
  * 0.4.13 release: patchelf op order fix (no compact-ELF corruption)
  * post-merge PR #259: load_project_config_ falls through to
    XLINGS_PROJECT_DIR env after a projectScope:false skip (without
    this fix, gcc-specs-config shim spawned from gcc.config hook
    couldn't resolve its workspace version because the cwd traversal
    hit the xlings repo's own projectScope:false .xlings.json)

Together these enable E2E-05 (Fixed Project Scenarios) to exercise
the full predicate-driven elfpatch + script-as-runtime-dep flow on
Linux without the workarounds the previous pin (83044b5) was
sidestepping.

If CI is green, the temporary pin can stay (now bumped) — or be
removed entirely once we trust both sides' main to evolve in lockstep.
Sunrisepeak added a commit that referenced this pull request May 3, 2026
#261)

* ci: bump XIM_PKGINDEX_REF 83044b5 → 19f4383 (gcc-runtime + lib closure fixes)

End-to-end CI verification of the full chain that landed across recent
xlings + xim-pkgindex work:

xim-pkgindex bumps from 83044b5 (pre-#108) to 19f4383 (main HEAD), now
includes:
  * #110/#111: namespace all bare-name deps (cmake/ninja/xmake/gcc/
    binutils/openssl/d2x → xim: prefix), removes dual-mount ambiguity
  * #116: split xim:gcc-runtime as a standalone xpkg (~25 MB)
    containing libstdc++/libgcc_s/libgomp/etc — vs full xim:gcc compiler
    (~1.1 GB)
  * #117: switch ninja/node/mdbook from xim:gcc to xim:gcc-runtime, so
    consumer rpath closure pulls only the runtime libs they need
  * #118: gcc-runtime declares `exports.runtime.libdirs = { "lib64" }`
    (correct schema field, was incorrectly `abi = {...}` in #116)

Pairs with xlings's:
  * 0.4.13 release: patchelf op order fix (no compact-ELF corruption)
  * post-merge PR #259: load_project_config_ falls through to
    XLINGS_PROJECT_DIR env after a projectScope:false skip (without
    this fix, gcc-specs-config shim spawned from gcc.config hook
    couldn't resolve its workspace version because the cwd traversal
    hit the xlings repo's own projectScope:false .xlings.json)

Together these enable E2E-05 (Fixed Project Scenarios) to exercise
the full predicate-driven elfpatch + script-as-runtime-dep flow on
Linux without the workarounds the previous pin (83044b5) was
sidestepping.

If CI is green, the temporary pin can stay (now bumped) — or be
removed entirely once we trust both sides' main to evolve in lockstep.

* feat(xself): implement `self uninstall` (-y / --keep-data / --dry-run)

Closes the long-standing gap where `xlings remove xim:xlings` refuses
single-version self-removal and routes the user to `self uninstall`,
but `self uninstall` didn't exist — the dispatcher silently fell
through to help and exited 0, making the command a footgun for
automation scripts.

## Semantics (vs `xlings remove xim:xlings`)

  - `xlings remove xim:xlings@VER` removes a single version; refuses
    when only one xlings version is installed (single-version guard
    pointing the user here)
  - `xlings self uninstall` is the escape hatch: removes the entire
    XLINGS_HOME (bin/, subos/, data/, config/, .xlings.json + the
    home dir itself), all installed packages, all subos. Lets the
    user fully tear down xlings even with a single version present.

## CLI

    xlings self uninstall [-y | --yes] [--keep-data] [--dry-run]

    -y / --yes      skip interactive [y/N] confirmation
    --keep-data     keep data/ (preserve pkg payloads for reinstall)
    --dry-run       print plan, change nothing

Exit codes:
    0  success / dry-run completed
    1  cancelled at prompt, safety refusal, or partial failure
    2  invalid invocation (unknown flag) — also fired by the bonus
       fix below for any unknown `xlings self <action>`

## Cross-platform self-deletion

  - Linux/macOS: kernel decouples open file from dirent, so the
    running xlings binary can be unlink'd in place. Process chdir's
    to "/" (or $TMPDIR) first so it doesn't end up with a dangling
    cwd inside the deleted tree.
  - Windows: a running .exe can't be deleted. Strategy: move
    xlings.exe to %TEMP%\xlings-pending-delete-<pid>.exe (same-volume
    rename works on a running exe), schedule that temp copy for
    delete-on-reboot. XLINGS_HOME is fully gone immediately; one
    cleanup file lingers in %TEMP% until restart. (TODO: route the
    actual MoveFileExW(MOVEFILE_DELAY_UNTIL_REBOOT) call through
    xlings.platform — for now the temp file is harmless until either
    reboot or manual cleanup.)

## Safety invariants

  1. Refuse when XLINGS_HOME canonicalizes to root, /usr, /etc, /home,
     a Windows system path, or exactly $HOME (without subdir suffix).
     Catches mis-set XLINGS_HOME from nuking /.
  2. Refuse when $XLINGS_HOME/.lock exists (another op in progress).
  3. Always print the deletion summary before doing anything, even
     with -y, so script logs capture what was removed.
  4. Best-effort: a single rm failure logs a warning and continues;
     final return code reflects total failures so the caller can
     react.

## What's preserved (default)

  - User shell rc files (~/.bashrc, ~/.zshrc, ~/.profile, fish config).
    We DETECT and PRINT lines that source xlings's profile so the user
    can manually clean them — never auto-edit (rc-file mutation is
    fragile + risks corrupting non-xlings content).
  - Project-local <project>/.xlings/ directories — user-owned.
  - ~/.xmake — not xlings-owned.

## Bonus: unknown-action non-zero exit

`xlings self bogus-action` previously fell through to the help screen
and exited 0 — bad signal for automation. Now returns exit 2 with an
explicit "unknown 'self' action" error message. Real help requests
(`xlings self`, `xlings self -h`, `xlings self --help`) keep returning
0 as before.

## Files

  - src/core/xself/uninstall.cppm   (new — cmd_uninstall + helpers)
  - src/core/xself.cppm             (router + help + unknown-action fix)
  - tests/e2e/self_uninstall_test.sh (new — 8 sub-scenarios)
  - .github/workflows/xlings-ci-linux.yml (wire E2E-02b)
  - docs/plans/2026-05-04-self-uninstall-design.md (design doc)

## Verified locally

  Build: xmake build xlings — ok in 15s
  Isolated XLINGS_HOME (separate from /home/speak/.xlings):
    T1 --dry-run -y                  → exit 0, files unchanged ✓
    T2 empty stdin (no confirm)      → exit 1, files unchanged ✓
    T3 bogus self action             → exit 2 ✓ (regression guard)
    T4 bogus uninstall flag          → exit 2 ✓
    T5 XLINGS_HOME=/                 → exit 1, refused ✓
    T6 XLINGS_HOME=$HOME             → exit 1, refused ✓
    T7 --keep-data -y                → exit 0; data/ preserved,
                                       bin/subos/config/.xlings.json
                                       gone ✓
    T8 full -y uninstall             → exit 0; XLINGS_HOME gone
                                       entirely ✓
  System /home/speak/.xlings: SHA + pkg count unchanged across all
  test runs (verified via baseline sha256 99e2660...).

  E2E test (tests/e2e/self_uninstall_test.sh) passes locally end-to-end.

* fix(xself): use const auto& in path iterator (clang strictness)
Sunrisepeak added a commit that referenced this pull request May 3, 2026
Bumps VERSION 0.4.13 → 0.4.14. Highlights since 0.4.13:

  * #259 — `load_project_config_` falls through to XLINGS_PROJECT_DIR
    env after a projectScope:false skip. Fixes "no version set for
    gcc-specs-config" in installs where the cwd traversal happens to
    hit a projectScope:false `.xlings.json` (e.g. xlings's own repo
    when E2E tests run from inside `tests/e2e/runtime/...`) before
    reaching the real project root. Concrete impact: gcc.lua's
    config hook spawning the gcc-specs-config script-type shim now
    resolves the project workspace correctly via env fallback.

  * #260 — CI bumps XIM_PKGINDEX_REF to xim-pkgindex main HEAD
    (19f4383), now including:
      - #110 / #111 namespace bare-name deps
      - #116 standalone xim:gcc-runtime (~25 MB, vs full xim:gcc ~1.1 GB)
      - #117 ninja/node/mdbook switched to xim:gcc-runtime
      - #118 gcc-runtime declares correct exports.runtime.libdirs
    End-to-end E2E-05 now exercises the full predicate-driven
    elfpatch + script-as-runtime-dep flow without sidestep workarounds.

  * #261 — `xlings self uninstall` is now a real command.
    Previously the dispatcher silently fell through to help and
    exited 0, even though user-facing hints (and the
    `xlings remove xim:xlings` single-version guard) explicitly
    routed users here. Implements:
      - `xlings self uninstall` (interactive [y/N])
      - `-y` / `--yes` for automation
      - `--keep-data` to preserve `data/` for quick reinstall
      - `--dry-run` to print plan without changes
    Cross-platform self-deletion: Linux/macOS use the kernel's
    open-file-vs-dirent decoupling to unlink the running binary;
    Windows moves xlings.exe to %TEMP% and schedules delete-on-
    reboot for the temp copy (XLINGS_HOME is fully gone immediately).
    Safety invariants: refuses XLINGS_HOME=/, =$HOME, common system
    paths; refuses if `.lock` present; always prints summary even
    with `-y`. Bonus: `xlings self <unknown-action>` now exits 2
    instead of silent 0.

Migration: 0.4.13 → 0.4.14 is binary-compatible. self-update via
`xself install` / quick_install handles the upgrade.

Verified locally: 8/8 isolated-XLINGS_HOME tests pass; system
/home/speak/.xlings sha256 + pkg count untouched across runs. CI
three-platform green on PR #261.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant