@biffo/cli 0.217.5 → 0.217.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -48,15 +48,59 @@
48
48
  #
49
49
  # Overridable: BIFFO_PG_HOST, BIFFO_PG_PORT, BIFFO_PG_USER, BIFFO_PG_PASSWORD,
50
50
  # BIFFO_PG_DB, BIFFO_PG_CONTAINER, BIFFO_PG_IMAGE.
51
+ #
52
+ # ## Concurrency: derived, not coordinated
53
+ #
54
+ # The port, database name, and container name below default to values DERIVED
55
+ # from this checkout's own path, not fixed constants. A fixed port
56
+ # (`BIFFO_PG_PORT` used to default to `55432` everywhere) meant any two
57
+ # checkouts running this script at the same time -- two worktrees of one repo,
58
+ # or two entirely different repos on one machine -- attached to the SAME
59
+ # Postgres cluster and raced on cluster-wide catalogs like `pg_shdepend`
60
+ # (#1114). A fixed database name (`biffo_test`) meant they then shared one
61
+ # database on top of that (#1120).
62
+ #
63
+ # The fix is not a lock: a machine-wide `flock` around this script would make
64
+ # concurrent runs correct by serializing them, but that is coordination, and
65
+ # this estate's shared-mutable-state defects have twice been solved instead by
66
+ # making the value itself unique per user rather than making users take turns.
67
+ # Deriving from `$REPO_ROOT` gets that for free -- it is already different for
68
+ # every worktree and every repo -- and deterministically, so repeat runs
69
+ # against the SAME checkout still land on the same port/db/container and reuse
70
+ # the fingerprinted schema (see step 2 below) instead of rebuilding it under a
71
+ # fresh identity every time. `BIFFO_PG_PORT`, `BIFFO_PG_DB`, and
72
+ # `BIFFO_PG_CONTAINER` remain explicit overrides; only the *default* changed.
51
73
 
52
74
  set -eu
53
75
 
76
+ REPO_ROOT=$(cd "$(dirname "$0")/.." && pwd)
77
+
78
+ # sha256sum is already a dependency of this script (see `fingerprint` below),
79
+ # so reusing it here for a deterministic, cheap per-checkout key adds nothing
80
+ # new to install. 12 hex chars is ample to keep collisions between checkouts
81
+ # on one machine practically impossible while staying short enough to read in
82
+ # `docker ps` output and a psql prompt.
83
+ _checkout_key=$(printf '%s' "$REPO_ROOT" | sha256sum | cut -c1-12)
84
+ _checkout_suffix=$(printf '%s' "$_checkout_key" | cut -c1-8)
85
+ # IANA's dynamic/private port range (49152-65535, 16384 ports) mapped from the
86
+ # next 4 hex chars of the same hash -- an ephemeral port picked deterministically
87
+ # rather than asked of the OS, because a freshly-random port on every invocation
88
+ # would break the reuse this key is for (a second run against the same checkout
89
+ # has to land back on the same container to find its existing database).
90
+ _checkout_port=$((49152 + (0x$(printf '%s' "$_checkout_key" | cut -c9-12) % 16384)))
91
+
54
92
  HOST="${BIFFO_PG_HOST:-localhost}"
55
- PORT="${BIFFO_PG_PORT:-55432}"
93
+ PORT="${BIFFO_PG_PORT:-$_checkout_port}"
56
94
  USER_="${BIFFO_PG_USER:-postgres}"
57
95
  PASS="${BIFFO_PG_PASSWORD:-postgres}"
58
- DB="${BIFFO_PG_DB:-biffo_test}"
59
- CONTAINER="${BIFFO_PG_CONTAINER:-biffo-pg-test}"
96
+ DB="${BIFFO_PG_DB:-biffo_test_$_checkout_suffix}"
97
+ # Keyed the same way as PORT and for the same reason: the container is where
98
+ # the port mapping actually lives (`docker run -p "$PORT:5432"`), so if the
99
+ # container name stayed fixed while the port became per-checkout, a second
100
+ # checkout would find the first checkout's container already occupying that
101
+ # name, "start" it rather than create its own, and then poll forever against a
102
+ # port that container was never bound to.
103
+ CONTAINER="${BIFFO_PG_CONTAINER:-biffo-pg-test-$_checkout_suffix}"
60
104
 
61
105
  RECREATE=0
62
106
  EXPORT=0
@@ -65,7 +109,7 @@ for arg in "$@"; do
65
109
  --recreate) RECREATE=1 ;;
66
110
  --export) EXPORT=1 ;;
67
111
  -h | --help)
68
- sed -n '2,48p' "$0" | sed 's/^#\{1,2\} \{0,1\}//'
112
+ sed -n '2,72p' "$0" | sed 's/^#\{1,2\} \{0,1\}//'
69
113
  exit 0
70
114
  ;;
71
115
  *)
@@ -77,7 +121,6 @@ done
77
121
 
78
122
  say() { echo "pg-test-db: $*" >&2; }
79
123
 
80
- REPO_ROOT=$(cd "$(dirname "$0")/.." && pwd)
81
124
  cd "$REPO_ROOT"
82
125
 
83
126
  # --- what this repo's schema is made of --------------------------------------
@@ -48,15 +48,59 @@
48
48
  #
49
49
  # Overridable: BIFFO_PG_HOST, BIFFO_PG_PORT, BIFFO_PG_USER, BIFFO_PG_PASSWORD,
50
50
  # BIFFO_PG_DB, BIFFO_PG_CONTAINER, BIFFO_PG_IMAGE.
51
+ #
52
+ # ## Concurrency: derived, not coordinated
53
+ #
54
+ # The port, database name, and container name below default to values DERIVED
55
+ # from this checkout's own path, not fixed constants. A fixed port
56
+ # (`BIFFO_PG_PORT` used to default to `55432` everywhere) meant any two
57
+ # checkouts running this script at the same time -- two worktrees of one repo,
58
+ # or two entirely different repos on one machine -- attached to the SAME
59
+ # Postgres cluster and raced on cluster-wide catalogs like `pg_shdepend`
60
+ # (#1114). A fixed database name (`biffo_test`) meant they then shared one
61
+ # database on top of that (#1120).
62
+ #
63
+ # The fix is not a lock: a machine-wide `flock` around this script would make
64
+ # concurrent runs correct by serializing them, but that is coordination, and
65
+ # this estate's shared-mutable-state defects have twice been solved instead by
66
+ # making the value itself unique per user rather than making users take turns.
67
+ # Deriving from `$REPO_ROOT` gets that for free -- it is already different for
68
+ # every worktree and every repo -- and deterministically, so repeat runs
69
+ # against the SAME checkout still land on the same port/db/container and reuse
70
+ # the fingerprinted schema (see step 2 below) instead of rebuilding it under a
71
+ # fresh identity every time. `BIFFO_PG_PORT`, `BIFFO_PG_DB`, and
72
+ # `BIFFO_PG_CONTAINER` remain explicit overrides; only the *default* changed.
51
73
 
52
74
  set -eu
53
75
 
76
+ REPO_ROOT=$(cd "$(dirname "$0")/.." && pwd)
77
+
78
+ # sha256sum is already a dependency of this script (see `fingerprint` below),
79
+ # so reusing it here for a deterministic, cheap per-checkout key adds nothing
80
+ # new to install. 12 hex chars is ample to keep collisions between checkouts
81
+ # on one machine practically impossible while staying short enough to read in
82
+ # `docker ps` output and a psql prompt.
83
+ _checkout_key=$(printf '%s' "$REPO_ROOT" | sha256sum | cut -c1-12)
84
+ _checkout_suffix=$(printf '%s' "$_checkout_key" | cut -c1-8)
85
+ # IANA's dynamic/private port range (49152-65535, 16384 ports) mapped from the
86
+ # next 4 hex chars of the same hash -- an ephemeral port picked deterministically
87
+ # rather than asked of the OS, because a freshly-random port on every invocation
88
+ # would break the reuse this key is for (a second run against the same checkout
89
+ # has to land back on the same container to find its existing database).
90
+ _checkout_port=$((49152 + (0x$(printf '%s' "$_checkout_key" | cut -c9-12) % 16384)))
91
+
54
92
  HOST="${BIFFO_PG_HOST:-localhost}"
55
- PORT="${BIFFO_PG_PORT:-55432}"
93
+ PORT="${BIFFO_PG_PORT:-$_checkout_port}"
56
94
  USER_="${BIFFO_PG_USER:-postgres}"
57
95
  PASS="${BIFFO_PG_PASSWORD:-postgres}"
58
- DB="${BIFFO_PG_DB:-biffo_test}"
59
- CONTAINER="${BIFFO_PG_CONTAINER:-biffo-pg-test}"
96
+ DB="${BIFFO_PG_DB:-biffo_test_$_checkout_suffix}"
97
+ # Keyed the same way as PORT and for the same reason: the container is where
98
+ # the port mapping actually lives (`docker run -p "$PORT:5432"`), so if the
99
+ # container name stayed fixed while the port became per-checkout, a second
100
+ # checkout would find the first checkout's container already occupying that
101
+ # name, "start" it rather than create its own, and then poll forever against a
102
+ # port that container was never bound to.
103
+ CONTAINER="${BIFFO_PG_CONTAINER:-biffo-pg-test-$_checkout_suffix}"
60
104
 
61
105
  RECREATE=0
62
106
  EXPORT=0
@@ -65,7 +109,7 @@ for arg in "$@"; do
65
109
  --recreate) RECREATE=1 ;;
66
110
  --export) EXPORT=1 ;;
67
111
  -h | --help)
68
- sed -n '2,48p' "$0" | sed 's/^#\{1,2\} \{0,1\}//'
112
+ sed -n '2,72p' "$0" | sed 's/^#\{1,2\} \{0,1\}//'
69
113
  exit 0
70
114
  ;;
71
115
  *)
@@ -77,7 +121,6 @@ done
77
121
 
78
122
  say() { echo "pg-test-db: $*" >&2; }
79
123
 
80
- REPO_ROOT=$(cd "$(dirname "$0")/.." && pwd)
81
124
  cd "$REPO_ROOT"
82
125
 
83
126
  # --- what this repo's schema is made of --------------------------------------
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@biffo/cli",
3
- "version": "0.217.5",
3
+ "version": "0.217.6",
4
4
  "description": "Biffo project scaffolding CLI",
5
5
  "license": "MIT",
6
6
  "type": "module",