Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 21 additions & 16 deletions bin/xcind-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -806,24 +806,29 @@ __xcind-workspace-list() {
echo "Error: jq is required for --json output." >&2
exit 1
fi
local parts=() idx
# Stream one TSV row per workspace into a single jq on stdin. Passing
# the assembled array through --argjson fails once it exceeds the
# kernel's per-argument limit (MAX_ARG_STRLEN, 128 KiB on Linux) —
# reachable with a couple thousand registry entries — and one jq
# spawn per row is slow at that size. Registry paths cannot contain
# tabs or newlines (the registry is itself TSV).
local idx
for idx in "${sorted_indices[@]+"${sorted_indices[@]}"}"; do
parts+=("$(jq -n \
--arg name "${names[$idx]}" \
--arg path "${paths[$idx]}" \
--arg domain "${domains[$idx]}" \
--argjson apps "${apps_counts[$idx]}" \
--argjson stale "${stale_flags[$idx]}" \
'{name: $name, path: $path, domain: $domain, apps: $apps, stale: $stale}')")
done
local workspaces_json="[]"
if [[ ${#parts[@]} -gt 0 ]]; then
workspaces_json=$(printf '%s\n' "${parts[@]}" | jq -s .)
fi
jq -n \
--argjson workspaces "$workspaces_json" \
printf '%s\t%s\t%s\t%s\t%s\n' \
"${names[$idx]}" "${paths[$idx]}" "${domains[$idx]}" \
"${apps_counts[$idx]}" "${stale_flags[$idx]}"
done | jq -nR \
--argjson stale_count "$stale_count" \
'{workspaces: $workspaces, stale_count: $stale_count}'
'{
workspaces: [inputs | split("\t") | {
name: .[0],
path: .[1],
domain: .[2],
apps: (.[3] | tonumber),
stale: (.[4] == "true")
}],
stale_count: $stale_count
}'
return 0
fi

Expand Down
13 changes: 13 additions & 0 deletions test/lib/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@
_XCIND_TEST_TMPROOT=$(mktemp -d)
export _XCIND_TEST_TMPROOT

# Isolate the workspace registry. Workspace discovery auto-registers
# every workspace it finds, so without this each test run appends its
# tempdir fixtures to the developer's real
# ~/.local/state/xcind/workspaces.tsv. Exporting XDG_STATE_HOME covers
# child bin/xcind-* processes; the registry globals are rebound because
# xcind-lib.bash is sourced (and computes them) before this file. Tests
# that need their own registry still override XDG_STATE_HOME per call.
export XDG_STATE_HOME="$_XCIND_TEST_TMPROOT/state"
XCIND_REGISTRY_DIR="$XDG_STATE_HOME/xcind"
XCIND_REGISTRY_FILE="$XCIND_REGISTRY_DIR/workspaces.tsv"
XCIND_REGISTRY_LOCK="$XCIND_REGISTRY_DIR/workspaces.lock"
export XCIND_REGISTRY_DIR XCIND_REGISTRY_FILE XCIND_REGISTRY_LOCK

mktemp_d() {
# Use the explicit-template form so we work on BSD mktemp (macOS) as
# well as GNU coreutils; BSD mktemp has no `-p` / `--tmpdir` flag.
Expand Down
7 changes: 5 additions & 2 deletions test/test-xcind-proxy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ echo "=== Test: xcind-proxy init (mock HOME) ==="
# write to the real ~/.config/xcind/proxy, clobbering live state.
unset XDG_CONFIG_HOME XDG_STATE_HOME XDG_DATA_HOME

# Use a temp dir as HOME to avoid touching real config
REAL_HOME="$HOME"
# Use a temp dir as HOME to avoid touching real config. REAL_HOME is a
# sandbox too, not the developer's HOME: later blocks "restore" HOME to
# it, and with XDG_STATE_HOME unset above, workspace discovery under the
# real HOME would append test fixtures to the real workspace registry.
REAL_HOME=$(mktemp_d)
MOCK_HOME=$(mktemp_d)
export HOME="$MOCK_HOME"

Expand Down
Loading