@calltelemetry/fmix 2.7.22 → 2.7.24
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.
- package/bin/fmix +475 -19
- package/package.json +3 -3
package/bin/fmix
CHANGED
|
@@ -28,7 +28,7 @@ set -uo pipefail
|
|
|
28
28
|
# ---------------------------------------------------------------------------
|
|
29
29
|
# Constants & config
|
|
30
30
|
# ---------------------------------------------------------------------------
|
|
31
|
-
FMIX_VERSION="2.7.
|
|
31
|
+
FMIX_VERSION="2.7.24"
|
|
32
32
|
FMIX_HOME="${FMIX_HOME:-${HOME}/.ct-fmix}"
|
|
33
33
|
FMIX_OS="$(uname -s)"
|
|
34
34
|
FMIX_ARCH="$(uname -m)"
|
|
@@ -164,24 +164,184 @@ DB_USER="${FMIX_DB_USER:-calltelemetry}"
|
|
|
164
164
|
DB_PASSWORD="${FMIX_DB_PASSWORD:-calltelemetry_dev_password}"
|
|
165
165
|
NATS_PORT="${FMIX_NATS_PORT:-4222}"
|
|
166
166
|
FMIX_TAILNET_NATS_HOST="${FMIX_TAILNET_NATS_HOST:-nats-dev}"
|
|
167
|
+
# Upper bound, in seconds, for each JetStream round trip in the NATS probe.
|
|
168
|
+
FMIX_NATS_PROBE_TIMEOUT="${FMIX_NATS_PROBE_TIMEOUT:-3}"
|
|
169
|
+
|
|
170
|
+
# Bounded JetStream health probe. A TCP connect proves only that something
|
|
171
|
+
# listens on the port; a remote can accept TCP and still time out on JetStream,
|
|
172
|
+
# which is what breaks app boot (KV bucket creation). The probe speaks just
|
|
173
|
+
# enough NATS protocol to send two JetStream API requests on one inbox:
|
|
174
|
+
# $JS.API.INFO the JetStream control plane answers
|
|
175
|
+
# $JS.API.STREAM.INFO.KV_<probe> the KV stream namespace answers
|
|
176
|
+
# A "stream not found" (err_code 10059) reply still proves the KV namespace
|
|
177
|
+
# answered; the bucket need not exist. Any silence past the bound is a failure.
|
|
178
|
+
# Usage: fmix_nats_jetstream_probe HOST PORT
|
|
179
|
+
# Sets FMIX_NATS_PROBE_DETAIL to "<ms>ms" on success or a reason on failure.
|
|
180
|
+
# Returns 0 when healthy, 1 otherwise.
|
|
181
|
+
fmix_nats_jetstream_probe() {
|
|
182
|
+
local host="$1" port="$2" py
|
|
183
|
+
FMIX_NATS_PROBE_DETAIL=""
|
|
184
|
+
py="$(command -v python3 2>/dev/null || true)"
|
|
185
|
+
[[ -n "$py" ]] || py="/usr/bin/python3"
|
|
186
|
+
if [[ ! -x "$py" ]]; then
|
|
187
|
+
FMIX_NATS_PROBE_DETAIL="no python3 available for the JetStream probe"
|
|
188
|
+
return 1
|
|
189
|
+
fi
|
|
190
|
+
local out
|
|
191
|
+
out="$("$py" -I -B - "$host" "$port" "$FMIX_NATS_PROBE_TIMEOUT" 2>/dev/null <<'FMIX_NATS_PROBE_PY'
|
|
192
|
+
import socket, sys, time, uuid, json
|
|
193
|
+
|
|
194
|
+
host, port, bound = sys.argv[1], int(sys.argv[2]), float(sys.argv[3])
|
|
195
|
+
started = time.monotonic()
|
|
196
|
+
deadline = started + bound
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def fail(reason):
|
|
200
|
+
print("fail " + reason)
|
|
201
|
+
sys.exit(1)
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
def remaining():
|
|
205
|
+
left = deadline - time.monotonic()
|
|
206
|
+
if left <= 0:
|
|
207
|
+
fail("no JetStream answer within %gs" % bound)
|
|
208
|
+
return left
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
try:
|
|
212
|
+
sock = socket.create_connection((host, port), timeout=remaining())
|
|
213
|
+
except socket.timeout:
|
|
214
|
+
fail("tcp connect timed out")
|
|
215
|
+
except OSError as exc:
|
|
216
|
+
fail("tcp connect failed (%s)" % (exc.strerror or type(exc).__name__))
|
|
217
|
+
|
|
218
|
+
buf = bytearray()
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
def fill(size):
|
|
222
|
+
while len(buf) < size:
|
|
223
|
+
sock.settimeout(remaining())
|
|
224
|
+
try:
|
|
225
|
+
chunk = sock.recv(65536)
|
|
226
|
+
except socket.timeout:
|
|
227
|
+
fail("no JetStream answer within %gs" % bound)
|
|
228
|
+
if not chunk:
|
|
229
|
+
fail("connection closed by server")
|
|
230
|
+
buf.extend(chunk)
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
def readline():
|
|
234
|
+
while b"\r\n" not in buf:
|
|
235
|
+
fill(len(buf) + 1)
|
|
236
|
+
line, _, rest = bytes(buf).partition(b"\r\n")
|
|
237
|
+
buf[:] = rest
|
|
238
|
+
return line
|
|
239
|
+
|
|
167
240
|
|
|
241
|
+
def readn(count):
|
|
242
|
+
fill(count + 2)
|
|
243
|
+
data = bytes(buf[:count])
|
|
244
|
+
del buf[: count + 2]
|
|
245
|
+
return data
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
try:
|
|
249
|
+
if not readline().startswith(b"INFO "):
|
|
250
|
+
fail("peer did not speak the NATS protocol")
|
|
251
|
+
sock.sendall(b'CONNECT {"verbose":false,"pedantic":false,"headers":true,'
|
|
252
|
+
b'"no_responders":true,"protocol":1,"lang":"python",'
|
|
253
|
+
b'"version":"fmix-probe"}\r\nPING\r\n')
|
|
254
|
+
while True:
|
|
255
|
+
line = readline()
|
|
256
|
+
if line == b"PONG":
|
|
257
|
+
break
|
|
258
|
+
if line.startswith(b"-ERR"):
|
|
259
|
+
fail("server error " + line[4:].strip().decode("utf-8", "replace")[:120])
|
|
260
|
+
if line == b"PING":
|
|
261
|
+
sock.sendall(b"PONG\r\n")
|
|
262
|
+
|
|
263
|
+
inbox = ("_INBOX.fmixprobe." + uuid.uuid4().hex).encode()
|
|
264
|
+
sock.sendall(b"SUB " + inbox + b" 1\r\n")
|
|
265
|
+
|
|
266
|
+
def request(subject):
|
|
267
|
+
sock.sendall(b"PUB " + subject + b" " + inbox + b" 0\r\n\r\n")
|
|
268
|
+
while True:
|
|
269
|
+
line = readline()
|
|
270
|
+
if line == b"PING":
|
|
271
|
+
sock.sendall(b"PONG\r\n")
|
|
272
|
+
elif line.startswith(b"-ERR"):
|
|
273
|
+
fail("server error " + line[4:].strip().decode("utf-8", "replace")[:120])
|
|
274
|
+
elif line.startswith(b"MSG "):
|
|
275
|
+
return json.loads(readn(int(line.split()[-1])).decode("utf-8", "replace"))
|
|
276
|
+
elif line.startswith(b"HMSG "):
|
|
277
|
+
parts = line.split()
|
|
278
|
+
header_len, total_len = int(parts[-2]), int(parts[-1])
|
|
279
|
+
header = readn(total_len)[:header_len]
|
|
280
|
+
if b" 503" in header.split(b"\r\n", 1)[0]:
|
|
281
|
+
fail("no JetStream responders (503): JetStream is not enabled")
|
|
282
|
+
# +OK, INFO and other frames are ignored.
|
|
283
|
+
|
|
284
|
+
info = request(b"$JS.API.INFO")
|
|
285
|
+
if "error" in info:
|
|
286
|
+
fail("JetStream API error: " + str(info["error"].get("description", "unknown"))[:120])
|
|
287
|
+
|
|
288
|
+
kv = request(b"$JS.API.STREAM.INFO.KV_fmix-probe")
|
|
289
|
+
kv_error = kv.get("error") or {}
|
|
290
|
+
if "error" in kv and kv_error.get("err_code") != 10059:
|
|
291
|
+
fail("KV namespace error: " + str(kv_error.get("description", "unknown"))[:120])
|
|
292
|
+
except socket.timeout:
|
|
293
|
+
fail("no JetStream answer within %gs" % bound)
|
|
294
|
+
except (OSError, ValueError) as exc:
|
|
295
|
+
fail("protocol error (%s)" % type(exc).__name__)
|
|
296
|
+
|
|
297
|
+
print("ok %dms" % int((time.monotonic() - started) * 1000))
|
|
298
|
+
FMIX_NATS_PROBE_PY
|
|
299
|
+
)" || true
|
|
300
|
+
if [[ "$out" == ok\ * ]]; then
|
|
301
|
+
FMIX_NATS_PROBE_DETAIL="${out#ok }"
|
|
302
|
+
return 0
|
|
303
|
+
fi
|
|
304
|
+
FMIX_NATS_PROBE_DETAIL="${out#fail }"
|
|
305
|
+
[[ -n "$FMIX_NATS_PROBE_DETAIL" ]] || FMIX_NATS_PROBE_DETAIL="probe produced no result"
|
|
306
|
+
return 1
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
# Resolves NATS_HOST and records why in FMIX_NATS_HOST_REASON. Runs in the
|
|
310
|
+
# current shell (not a subshell) so the reason survives for the doctor.
|
|
311
|
+
# 1. An explicit FMIX_NATS_HOST always wins and is never probed.
|
|
312
|
+
# 2. CI, or FMIX_DISABLE_TAILNET_NATS=1, selects localhost without probing.
|
|
313
|
+
# 3. Otherwise the tailnet host must pass the JetStream probe.
|
|
314
|
+
# 4. If it fails or exceeds the bound, a local NATS that passes the same
|
|
315
|
+
# probe is preferred. If neither passes, localhost remains the default so
|
|
316
|
+
# the doctor reports the real state rather than a silent switch.
|
|
168
317
|
fmix_resolve_nats_host() {
|
|
169
318
|
if [[ "${FMIX_NATS_HOST+set}" == "set" ]]; then
|
|
170
|
-
|
|
319
|
+
NATS_HOST="$FMIX_NATS_HOST"
|
|
320
|
+
FMIX_NATS_HOST_REASON="explicit FMIX_NATS_HOST override (not probed)"
|
|
171
321
|
return 0
|
|
172
322
|
fi
|
|
173
323
|
if [[ "${GITHUB_ACTIONS:-}" == "true" || "${CI:-}" == "true" || "${FMIX_DISABLE_TAILNET_NATS:-}" == "1" ]]; then
|
|
174
|
-
|
|
324
|
+
NATS_HOST="localhost"
|
|
325
|
+
FMIX_NATS_HOST_REASON="CI or FMIX_DISABLE_TAILNET_NATS: localhost, tailnet not probed"
|
|
326
|
+
return 0
|
|
327
|
+
fi
|
|
328
|
+
if fmix_nats_jetstream_probe "$FMIX_TAILNET_NATS_HOST" "$NATS_PORT"; then
|
|
329
|
+
NATS_HOST="$FMIX_TAILNET_NATS_HOST"
|
|
330
|
+
FMIX_NATS_HOST_REASON="tailnet $FMIX_TAILNET_NATS_HOST JetStream healthy ($FMIX_NATS_PROBE_DETAIL)"
|
|
175
331
|
return 0
|
|
176
332
|
fi
|
|
177
|
-
|
|
178
|
-
|
|
333
|
+
local remote_detail="$FMIX_NATS_PROBE_DETAIL"
|
|
334
|
+
if fmix_nats_jetstream_probe localhost "$NATS_PORT"; then
|
|
335
|
+
NATS_HOST="localhost"
|
|
336
|
+
FMIX_NATS_HOST_REASON="tailnet $FMIX_TAILNET_NATS_HOST unhealthy ($remote_detail); local localhost JetStream healthy ($FMIX_NATS_PROBE_DETAIL)"
|
|
337
|
+
printf '[fmix] NATS: using localhost:%s; %s\n' "$NATS_PORT" "$FMIX_NATS_HOST_REASON" >&2
|
|
179
338
|
return 0
|
|
180
339
|
fi
|
|
181
|
-
|
|
340
|
+
NATS_HOST="localhost"
|
|
341
|
+
FMIX_NATS_HOST_REASON="tailnet $FMIX_TAILNET_NATS_HOST unhealthy ($remote_detail); local localhost also unhealthy ($FMIX_NATS_PROBE_DETAIL); defaulting to localhost"
|
|
182
342
|
return 0
|
|
183
343
|
}
|
|
184
|
-
|
|
344
|
+
fmix_resolve_nats_host
|
|
185
345
|
|
|
186
346
|
# Fixed dev constant SECRET_KEY_BASE (64 hex chars — only used in test env)
|
|
187
347
|
SECRET_KEY_BASE="${FMIX_SECRET_KEY_BASE:-dev0000000000000000000000000000000000000000000000000000000000000001}"
|
|
@@ -7901,10 +8061,195 @@ fmix_host_test_lock_enabled() {
|
|
|
7901
8061
|
# Worktree resolution: find nearest cisco-cdr checkout from CWD
|
|
7902
8062
|
# ---------------------------------------------------------------------------
|
|
7903
8063
|
|
|
8064
|
+
# REL-3297: fmix probes git as `git -C <worktree> ... 2>/dev/null` in well over
|
|
8065
|
+
# a hundred places. A checkout whose git metadata does not resolve back to the
|
|
8066
|
+
# checkout itself therefore failed far from its cause, most visibly as "Could
|
|
8067
|
+
# not capture a source-stability identity after acquiring the worktree lock".
|
|
8068
|
+
# The usual cause is a linked worktree of a submodule: once
|
|
8069
|
+
# extensions.worktreeConfig is true it inherits the submodule's shared,
|
|
8070
|
+
# relative core.worktree and resolves it against its own per-worktree gitdir.
|
|
8071
|
+
# That names a missing directory, or the module gitdir itself, where a
|
|
8072
|
+
# submodule bootstrap or checkout would write the tree into the git directory.
|
|
8073
|
+
#
|
|
8074
|
+
# Diagnose before any lock, session or submodule work and name the exact config
|
|
8075
|
+
# file and a one-line repair. Values are read with `git config --file` from `/`
|
|
8076
|
+
# because every repository-scoped git command run inside the broken checkout
|
|
8077
|
+
# dies during setup. fmix never rewrites git config itself.
|
|
8078
|
+
|
|
8079
|
+
# Collapse `.`, `..` and repeated slashes in an absolute path without touching
|
|
8080
|
+
# the filesystem, so a core.worktree that names a missing directory can still
|
|
8081
|
+
# be shown where it lands.
|
|
8082
|
+
fmix_lexical_abs_path() {
|
|
8083
|
+
local path="${1:-}" part out=""
|
|
8084
|
+
local -a parts=() kept=()
|
|
8085
|
+
[[ "$path" == /* ]] || return 1
|
|
8086
|
+
IFS='/' read -r -a parts <<<"$path"
|
|
8087
|
+
for part in "${parts[@]+"${parts[@]}"}"; do
|
|
8088
|
+
case "$part" in
|
|
8089
|
+
''|.) ;;
|
|
8090
|
+
..)
|
|
8091
|
+
if (( ${#kept[@]} > 0 )); then
|
|
8092
|
+
unset "kept[$(( ${#kept[@]} - 1 ))]"
|
|
8093
|
+
kept=("${kept[@]+"${kept[@]}"}")
|
|
8094
|
+
fi
|
|
8095
|
+
;;
|
|
8096
|
+
*) kept+=("$part") ;;
|
|
8097
|
+
esac
|
|
8098
|
+
done
|
|
8099
|
+
for part in "${kept[@]+"${kept[@]}"}"; do
|
|
8100
|
+
out="$out/$part"
|
|
8101
|
+
done
|
|
8102
|
+
printf '%s\n' "${out:-/}"
|
|
8103
|
+
}
|
|
8104
|
+
|
|
8105
|
+
# Read one key from one config file, outside any repository and ignoring any
|
|
8106
|
+
# GIT_* environment that would redirect git's own setup.
|
|
8107
|
+
fmix_git_config_file_get() {
|
|
8108
|
+
local file="${1:-}" key="${2:-}"
|
|
8109
|
+
shift 2 || return 1
|
|
8110
|
+
[[ -f "$file" ]] || return 1
|
|
8111
|
+
env -u GIT_DIR -u GIT_WORK_TREE -u GIT_COMMON_DIR -u GIT_CONFIG \
|
|
8112
|
+
git -C / config --file "$file" "$@" --get "$key" 2>/dev/null
|
|
8113
|
+
}
|
|
8114
|
+
|
|
8115
|
+
# Print a diagnosis and return 1 when `dir` is a git checkout whose metadata
|
|
8116
|
+
# does not resolve back to `dir`. Silent and 0 for a sound checkout and for a
|
|
8117
|
+
# directory without a `.git` entry (the non-git contract is unchanged).
|
|
8118
|
+
fmix_git_worktree_metadata_report() {
|
|
8119
|
+
local dir="${1:-}" real err_file toplevel="" real_toplevel="" git_err=""
|
|
8120
|
+
local gitfile_line="" gitdir="" commondir="" ext="" bare="" value="" origin=""
|
|
8121
|
+
local resolved="" real_resolved="" where="" fix_file=""
|
|
8122
|
+
[[ -n "$dir" ]] || return 0
|
|
8123
|
+
real="$(fmix_realpath "$dir" 2>/dev/null)" || return 0
|
|
8124
|
+
[[ -n "$real" ]] || return 0
|
|
8125
|
+
[[ -e "$real/.git" || -L "$real/.git" ]] || return 0
|
|
8126
|
+
|
|
8127
|
+
err_file="$(mktemp)" || return 1
|
|
8128
|
+
if toplevel="$(git -C "$real" rev-parse --show-toplevel 2>"$err_file")" && [[ -n "$toplevel" ]]; then
|
|
8129
|
+
real_toplevel="$(fmix_realpath "$toplevel" 2>/dev/null)" || real_toplevel="$toplevel"
|
|
8130
|
+
if [[ "$real_toplevel" == "$real" ]]; then
|
|
8131
|
+
rm -f "$err_file"
|
|
8132
|
+
return 0
|
|
8133
|
+
fi
|
|
8134
|
+
else
|
|
8135
|
+
toplevel=""
|
|
8136
|
+
fi
|
|
8137
|
+
git_err="$(head -n 1 "$err_file" 2>/dev/null)"
|
|
8138
|
+
rm -f "$err_file"
|
|
8139
|
+
|
|
8140
|
+
if [[ -f "$real/.git" ]]; then
|
|
8141
|
+
gitfile_line="$(head -n 1 "$real/.git" 2>/dev/null)"
|
|
8142
|
+
gitdir="${gitfile_line#gitdir: }"
|
|
8143
|
+
[[ "$gitdir" == /* ]] || gitdir="$real/$gitdir"
|
|
8144
|
+
else
|
|
8145
|
+
gitdir="$real/.git"
|
|
8146
|
+
fi
|
|
8147
|
+
if [[ -d "$gitdir" ]]; then
|
|
8148
|
+
gitdir="$(fmix_realpath "$gitdir" 2>/dev/null)" || gitdir="$(fmix_lexical_abs_path "$gitdir")"
|
|
8149
|
+
else
|
|
8150
|
+
gitdir="$(fmix_lexical_abs_path "$gitdir")"
|
|
8151
|
+
printf 'git_worktree_metadata_broken: %s/.git names gitdir %s, which does not exist.\n' "$real" "$gitdir"
|
|
8152
|
+
[[ -z "$git_err" ]] || printf 'git said: %s\n' "$git_err"
|
|
8153
|
+
printf 'fix: run `git worktree repair %s` from the main checkout of this repository, or recreate the worktree.\n' "$real"
|
|
8154
|
+
return 1
|
|
8155
|
+
fi
|
|
8156
|
+
commondir="$gitdir"
|
|
8157
|
+
if [[ -f "$gitdir/commondir" ]]; then
|
|
8158
|
+
commondir="$(head -n 1 "$gitdir/commondir" 2>/dev/null)"
|
|
8159
|
+
[[ "$commondir" == /* ]] || commondir="$gitdir/$commondir"
|
|
8160
|
+
commondir="$(fmix_realpath "$commondir" 2>/dev/null)" || commondir="$(fmix_lexical_abs_path "$commondir")"
|
|
8161
|
+
fi
|
|
8162
|
+
|
|
8163
|
+
ext="$(fmix_git_config_file_get "$commondir/config" extensions.worktreeConfig --bool)" || ext=""
|
|
8164
|
+
if [[ "$ext" == "true" ]] \
|
|
8165
|
+
&& value="$(fmix_git_config_file_get "$gitdir/config.worktree" core.worktree)"; then
|
|
8166
|
+
origin="$gitdir/config.worktree"
|
|
8167
|
+
elif value="$(fmix_git_config_file_get "$commondir/config" core.worktree)"; then
|
|
8168
|
+
origin="$commondir/config"
|
|
8169
|
+
# Without extensions.worktreeConfig git ignores the shared value in a
|
|
8170
|
+
# linked worktree, so it cannot be this worktree's cause.
|
|
8171
|
+
if [[ "$gitdir" != "$commondir" && "$ext" != "true" ]]; then
|
|
8172
|
+
value=""
|
|
8173
|
+
origin=""
|
|
8174
|
+
fi
|
|
8175
|
+
else
|
|
8176
|
+
value=""
|
|
8177
|
+
fi
|
|
8178
|
+
|
|
8179
|
+
if [[ -n "$value" ]]; then
|
|
8180
|
+
printf 'git_core_worktree_broken: git cannot resolve %s to itself, so no source identity, receipt or dirty-tree check can run there.\n' "$real"
|
|
8181
|
+
else
|
|
8182
|
+
printf 'git_worktree_metadata_broken: git cannot resolve %s to itself, so no source identity, receipt or dirty-tree check can run there.\n' "$real"
|
|
8183
|
+
fi
|
|
8184
|
+
if [[ -n "$toplevel" ]]; then
|
|
8185
|
+
printf 'git resolves it to %s\n' "${real_toplevel:-$toplevel}"
|
|
8186
|
+
elif [[ -n "$git_err" ]]; then
|
|
8187
|
+
printf 'git said: %s\n' "$git_err"
|
|
8188
|
+
fi
|
|
8189
|
+
printf 'gitdir: %s\n' "$gitdir"
|
|
8190
|
+
if [[ -n "${GIT_DIR:-}" || -n "${GIT_WORK_TREE:-}" ]]; then
|
|
8191
|
+
printf 'environment overrides discovery: GIT_DIR=%s GIT_WORK_TREE=%s\n' "${GIT_DIR:-}" "${GIT_WORK_TREE:-}"
|
|
8192
|
+
fi
|
|
8193
|
+
bare="$(fmix_git_config_file_get "$commondir/config" core.bare --bool)" || bare=""
|
|
8194
|
+
if [[ "$bare" == "true" ]]; then
|
|
8195
|
+
printf 'core.bare = true (set in %s): git treats this repository as having no work tree.\n' "$commondir/config"
|
|
8196
|
+
fi
|
|
8197
|
+
|
|
8198
|
+
if [[ -z "$value" ]]; then
|
|
8199
|
+
printf 'no core.worktree applies to this checkout; check `git -C %s rev-parse --show-toplevel` and the GIT_* environment.\n' "$real"
|
|
8200
|
+
return 1
|
|
8201
|
+
fi
|
|
8202
|
+
|
|
8203
|
+
case "$value" in
|
|
8204
|
+
/*) resolved="$(fmix_lexical_abs_path "$value")" ;;
|
|
8205
|
+
*) resolved="$(fmix_lexical_abs_path "$gitdir/$value")" ;;
|
|
8206
|
+
esac
|
|
8207
|
+
if [[ ! -d "$resolved" ]]; then
|
|
8208
|
+
where="a directory that does not exist"
|
|
8209
|
+
else
|
|
8210
|
+
real_resolved="$(fmix_realpath "$resolved" 2>/dev/null)" || real_resolved="$resolved"
|
|
8211
|
+
case "$real_resolved/" in
|
|
8212
|
+
"$gitdir"/*|"$commondir"/*)
|
|
8213
|
+
where="the git directory itself; a status, checkout or submodule update there acts on the gitdir"
|
|
8214
|
+
;;
|
|
8215
|
+
*) where="another directory, not this checkout" ;;
|
|
8216
|
+
esac
|
|
8217
|
+
fi
|
|
8218
|
+
printf 'core.worktree = %s (set in %s)\n' "$value" "$origin"
|
|
8219
|
+
printf 'it resolves against %s to %s: %s.\n' "$gitdir" "$resolved" "$where"
|
|
8220
|
+
if [[ "$origin" == "$commondir/config" && "$gitdir" != "$commondir" ]]; then
|
|
8221
|
+
printf 'cause: with extensions.worktreeConfig=true a linked worktree reads the shared core.worktree of %s unless its own config.worktree overrides it, and a relative value resolves against the linked gitdir.\n' "$commondir/config"
|
|
8222
|
+
fi
|
|
8223
|
+
fix_file="$gitdir/config.worktree"
|
|
8224
|
+
[[ "$ext" == "true" ]] || fix_file="$commondir/config"
|
|
8225
|
+
printf "fix (this worktree only): git config --file '%s' core.worktree '%s'\n" "$fix_file" "$real"
|
|
8226
|
+
printf "verify: git -C '%s' rev-parse --show-toplevel must print %s\n" "$real" "$real"
|
|
8227
|
+
return 1
|
|
8228
|
+
}
|
|
8229
|
+
|
|
8230
|
+
# Refuse a checkout whose git metadata is broken, naming the cause on stderr.
|
|
8231
|
+
fmix_require_git_worktree_metadata() {
|
|
8232
|
+
local report line
|
|
8233
|
+
report="$(fmix_git_worktree_metadata_report "${1:-}")" && return 0
|
|
8234
|
+
if [[ -z "$report" ]]; then
|
|
8235
|
+
fmix_error "git_worktree_metadata_broken: could not inspect the git metadata of ${1:-}."
|
|
8236
|
+
return 1
|
|
8237
|
+
fi
|
|
8238
|
+
while IFS= read -r line; do
|
|
8239
|
+
[[ -n "$line" ]] && fmix_error "$line"
|
|
8240
|
+
done <<<"$report"
|
|
8241
|
+
return 1
|
|
8242
|
+
}
|
|
8243
|
+
|
|
7904
8244
|
fmix_ensure_worktree_submodules() {
|
|
7905
8245
|
local target_dir="$1"
|
|
7906
8246
|
local selected_gitlink="${2:-}"
|
|
7907
8247
|
|
|
8248
|
+
# REL-3297: never run a submodule bootstrap through git metadata that
|
|
8249
|
+
# resolves to another tree (it could land in the module gitdir). The
|
|
8250
|
+
# caller's fmix_require_git_worktree_metadata names the cause.
|
|
8251
|
+
fmix_git_worktree_metadata_report "$target_dir" >/dev/null || return 0
|
|
8252
|
+
|
|
7908
8253
|
# Find top-level repo if inside a Git tree
|
|
7909
8254
|
local top_repo
|
|
7910
8255
|
top_repo="$(git -C "$target_dir" rev-parse --show-toplevel 2>/dev/null)" || return 0
|
|
@@ -8201,7 +8546,17 @@ fmix_worktree_is_cold_submodule() {
|
|
|
8201
8546
|
return 1
|
|
8202
8547
|
}
|
|
8203
8548
|
|
|
8549
|
+
# Resolve the cisco-cdr checkout, then refuse it when its git metadata does not
|
|
8550
|
+
# resolve back to it (REL-3297). Every verb that resolves a worktree goes through
|
|
8551
|
+
# here, so the named error replaces the unrelated failures further down.
|
|
8204
8552
|
fmix_find_worktree() {
|
|
8553
|
+
local found
|
|
8554
|
+
found="$(fmix_find_worktree_resolve "$@")" || return 1
|
|
8555
|
+
fmix_require_git_worktree_metadata "$found" || return 1
|
|
8556
|
+
printf '%s\n' "$found"
|
|
8557
|
+
}
|
|
8558
|
+
|
|
8559
|
+
fmix_find_worktree_resolve() {
|
|
8205
8560
|
local path="$1"
|
|
8206
8561
|
# Admission needs a verified candidate without initializing submodules.
|
|
8207
8562
|
# The default resolution still initializes and verifies the checkout.
|
|
@@ -8400,9 +8755,9 @@ fmix_preflight() {
|
|
|
8400
8755
|
fail=1
|
|
8401
8756
|
fi
|
|
8402
8757
|
|
|
8403
|
-
# NATS
|
|
8404
|
-
if !
|
|
8405
|
-
fmix_warn "NATS not
|
|
8758
|
+
# NATS JetStream check (warn only — tests stub NATS)
|
|
8759
|
+
if ! fmix_nats_jetstream_probe "$NATS_HOST" "$NATS_PORT"; then
|
|
8760
|
+
fmix_warn "NATS JetStream not answering at $NATS_HOST:$NATS_PORT: $FMIX_NATS_PROBE_DETAIL."
|
|
8406
8761
|
fmix_warn "Run: fmix ensure — some tests may fail without NATS."
|
|
8407
8762
|
fi
|
|
8408
8763
|
|
|
@@ -16895,6 +17250,8 @@ cmd_verify_push() {
|
|
|
16895
17250
|
local real_worktree
|
|
16896
17251
|
real_worktree="$(fmix_realpath "$worktree")"
|
|
16897
17252
|
|
|
17253
|
+
# REL-3297: name a broken core.worktree instead of "not a git worktree".
|
|
17254
|
+
fmix_require_git_worktree_metadata "$real_worktree" || return 1
|
|
16898
17255
|
if ! git -C "$real_worktree" rev-parse --is-inside-work-tree >/dev/null 2>&1; then
|
|
16899
17256
|
fmix_error "Path is not inside a git worktree: $real_worktree"
|
|
16900
17257
|
return 1
|
|
@@ -17088,6 +17445,8 @@ cmd_hook_install() {
|
|
|
17088
17445
|
fi
|
|
17089
17446
|
local real_worktree
|
|
17090
17447
|
real_worktree="$(fmix_realpath "$worktree")"
|
|
17448
|
+
# REL-3297: name a broken core.worktree instead of "not a git worktree".
|
|
17449
|
+
fmix_require_git_worktree_metadata "$real_worktree" || return 1
|
|
17091
17450
|
if ! git -C "$real_worktree" rev-parse --is-inside-work-tree >/dev/null 2>&1; then
|
|
17092
17451
|
fmix_error "Path is not inside a git worktree: $real_worktree"
|
|
17093
17452
|
return 1
|
|
@@ -18344,13 +18703,62 @@ fmix_infra_postgres_ready() {
|
|
|
18344
18703
|
}
|
|
18345
18704
|
|
|
18346
18705
|
fmix_infra_nats_ready() {
|
|
18347
|
-
|
|
18706
|
+
fmix_nats_jetstream_probe "$NATS_HOST" "$NATS_PORT" >/dev/null 2>&1
|
|
18348
18707
|
}
|
|
18349
18708
|
|
|
18350
18709
|
fmix_infra_ready() {
|
|
18351
18710
|
fmix_infra_postgres_ready && fmix_infra_nats_ready
|
|
18352
18711
|
}
|
|
18353
18712
|
|
|
18713
|
+
# True when the local NATS port is held by a listener fmix does not own: TCP
|
|
18714
|
+
# answers, JetStream does not, and neither the shared ct-infra container nor
|
|
18715
|
+
# the managed nats-server pid is the owner. Remote hosts are never "foreign".
|
|
18716
|
+
fmix_nats_port_foreign() {
|
|
18717
|
+
fmix_nats_host_is_local || return 1
|
|
18718
|
+
nc -z "$NATS_HOST" "$NATS_PORT" 2>/dev/null || return 1
|
|
18719
|
+
fmix_infra_nats_ready && return 1
|
|
18720
|
+
if docker inspect "${FMIX_INFRA_PROJECT}-nats-1" >/dev/null 2>&1; then
|
|
18721
|
+
return 1
|
|
18722
|
+
fi
|
|
18723
|
+
local pid_file="$FMIX_HOME/nats/nats-server.pid" pid=""
|
|
18724
|
+
if [[ -f "$pid_file" ]]; then
|
|
18725
|
+
pid="$(cat "$pid_file" 2>/dev/null || true)"
|
|
18726
|
+
if [[ -n "$pid" ]] && kill -0 "$pid" 2>/dev/null; then
|
|
18727
|
+
return 1
|
|
18728
|
+
fi
|
|
18729
|
+
fi
|
|
18730
|
+
return 0
|
|
18731
|
+
}
|
|
18732
|
+
|
|
18733
|
+
# Starts a managed JetStream nats-server on the local port, idempotently:
|
|
18734
|
+
# a live managed pid is waited on, never duplicated. Returns 0 only once the
|
|
18735
|
+
# JetStream probe passes. Data lives under FMIX_HOME, never in the repo.
|
|
18736
|
+
fmix_start_managed_nats() {
|
|
18737
|
+
local dir="$FMIX_HOME/nats" pid_file="$FMIX_HOME/nats/nats-server.pid" pid="" now deadline
|
|
18738
|
+
mkdir -p "$dir/store" || return 1
|
|
18739
|
+
if [[ -f "$pid_file" ]]; then
|
|
18740
|
+
pid="$(cat "$pid_file" 2>/dev/null || true)"
|
|
18741
|
+
fi
|
|
18742
|
+
if [[ -z "$pid" ]] || ! kill -0 "$pid" 2>/dev/null; then
|
|
18743
|
+
echo " starting managed nats-server -js on localhost:$NATS_PORT..."
|
|
18744
|
+
nohup nats-server -js -sd "$dir/store" -p "$NATS_PORT" -P "$pid_file" \
|
|
18745
|
+
>"$dir/nats-server.log" 2>&1 </dev/null &
|
|
18746
|
+
disown 2>/dev/null || true
|
|
18747
|
+
else
|
|
18748
|
+
echo " waiting on managed nats-server pid $pid..."
|
|
18749
|
+
fi
|
|
18750
|
+
now="$(fmix_epoch)"
|
|
18751
|
+
deadline=$(( now + FMIX_ENSURE_TIMEOUT ))
|
|
18752
|
+
while (( $(fmix_epoch) < deadline )); do
|
|
18753
|
+
if fmix_infra_nats_ready; then
|
|
18754
|
+
return 0
|
|
18755
|
+
fi
|
|
18756
|
+
sleep 1
|
|
18757
|
+
done
|
|
18758
|
+
fmix_error "managed nats-server did not answer JetStream on localhost:$NATS_PORT within ${FMIX_ENSURE_TIMEOUT}s (log: $dir/nats-server.log)"
|
|
18759
|
+
return 1
|
|
18760
|
+
}
|
|
18761
|
+
|
|
18354
18762
|
fmix_docker_usable() {
|
|
18355
18763
|
command -v docker >/dev/null 2>&1 && docker info >/dev/null 2>&1
|
|
18356
18764
|
}
|
|
@@ -18593,6 +19001,24 @@ fmix_ensure_infra() {
|
|
|
18593
19001
|
return 1
|
|
18594
19002
|
fi
|
|
18595
19003
|
|
|
19004
|
+
# Never start a second NATS on a port another listener owns (API-1460: a
|
|
19005
|
+
# non-JetStream pod answered localhost:4222). A listener counts as ours only
|
|
19006
|
+
# when it is the shared ct-infra container or the managed nats-server pid.
|
|
19007
|
+
if fmix_nats_port_foreign; then
|
|
19008
|
+
fmix_error "$NATS_HOST:$NATS_PORT answers TCP without JetStream and no ${FMIX_INFRA_PROJECT}-nats-1 container or managed nats-server owns it. Refusing to start a second NATS; free the port, or set FMIX_NATS_HOST to a healthy JetStream server."
|
|
19009
|
+
return 1
|
|
19010
|
+
fi
|
|
19011
|
+
|
|
19012
|
+
# No Docker, but Postgres is up and only NATS is missing: run a managed
|
|
19013
|
+
# nats-server -js when the binary exists, so fmix test needs no manual host.
|
|
19014
|
+
if ! fmix_docker_usable && fmix_infra_postgres_ready && ! fmix_infra_nats_ready && command -v nats-server >/dev/null 2>&1; then
|
|
19015
|
+
if fmix_start_managed_nats; then
|
|
19016
|
+
echo " [OK] infra ready postgres $DB_HOST:$DB_PORT nats $NATS_HOST:$NATS_PORT (managed nats-server -js)"
|
|
19017
|
+
return 0
|
|
19018
|
+
fi
|
|
19019
|
+
return 1
|
|
19020
|
+
fi
|
|
19021
|
+
|
|
18596
19022
|
if ! fmix_docker_usable; then
|
|
18597
19023
|
fmix_error "Shared postgres/NATS is down and Docker is not usable. Start OrbStack/Docker, then retry: fmix ensure"
|
|
18598
19024
|
return 1
|
|
@@ -18660,6 +19086,7 @@ cmd_ensure() {
|
|
|
18660
19086
|
echo "=== fmix ensure ==="
|
|
18661
19087
|
echo " target: postgres $DB_HOST:$DB_PORT user=$DB_USER ; nats $NATS_HOST:$NATS_PORT"
|
|
18662
19088
|
echo " project: $FMIX_INFRA_PROJECT (one host-wide plane; not a per-branch stack)"
|
|
19089
|
+
echo " nats selection: $FMIX_NATS_HOST_REASON"
|
|
18663
19090
|
fmix_ensure_infra
|
|
18664
19091
|
}
|
|
18665
19092
|
|
|
@@ -18690,6 +19117,23 @@ cmd_doctor() {
|
|
|
18690
19117
|
worktree="$(fmix_find_worktree "$PWD/cisco-cdr" 2>/dev/null)" || true
|
|
18691
19118
|
[[ -n "$worktree" ]] && echo " (auto-resolved worktree: $worktree — pass --worktree to be explicit)"
|
|
18692
19119
|
fi
|
|
19120
|
+
# REL-3297: the lookups above refuse a checkout with broken git metadata and
|
|
19121
|
+
# their stderr is discarded, which used to end in "all checks passed".
|
|
19122
|
+
# Re-resolve without the metadata check (readonly: no submodule bootstrap)
|
|
19123
|
+
# and report it as a failure.
|
|
19124
|
+
local git_metadata_candidate="" git_metadata_report=""
|
|
19125
|
+
if [[ -z "$worktree" ]]; then
|
|
19126
|
+
git_metadata_candidate="$(fmix_find_worktree_resolve "$worktree_arg" readonly 2>/dev/null)" \
|
|
19127
|
+
|| git_metadata_candidate=""
|
|
19128
|
+
if [[ -z "$git_metadata_candidate" && "$worktree_arg" == "auto" && -f "$PWD/cisco-cdr/mix.exs" ]]; then
|
|
19129
|
+
git_metadata_candidate="$(fmix_find_worktree_resolve "$PWD/cisco-cdr" readonly 2>/dev/null)" \
|
|
19130
|
+
|| git_metadata_candidate=""
|
|
19131
|
+
fi
|
|
19132
|
+
if [[ -n "$git_metadata_candidate" ]]; then
|
|
19133
|
+
git_metadata_report="$(fmix_git_worktree_metadata_report "$git_metadata_candidate")" \
|
|
19134
|
+
&& git_metadata_report=""
|
|
19135
|
+
fi
|
|
19136
|
+
fi
|
|
18693
19137
|
|
|
18694
19138
|
# OS detection
|
|
18695
19139
|
echo " OS: $FMIX_OS $FMIX_ARCH"
|
|
@@ -18785,13 +19229,17 @@ cmd_doctor() {
|
|
|
18785
19229
|
echo " [WARN] No complete content-indexed hot DB base found — run './fmix setup --cold-db' (falls back to --from-zero if structure.sql is unusable) for explicit bootstrap maintenance"
|
|
18786
19230
|
fi
|
|
18787
19231
|
|
|
18788
|
-
# NATS TCP
|
|
18789
|
-
|
|
18790
|
-
|
|
18791
|
-
|
|
18792
|
-
|
|
18793
|
-
|
|
18794
|
-
|
|
19232
|
+
# NATS JetStream round trip (bounded). TCP alone is not health: a remote can
|
|
19233
|
+
# accept the connection and never answer JetStream, which aborts app boot.
|
|
19234
|
+
local nats_where="remote/tailnet"
|
|
19235
|
+
fmix_nats_host_is_local && nats_where="local"
|
|
19236
|
+
if fmix_nats_jetstream_probe "$NATS_HOST" "$NATS_PORT"; then
|
|
19237
|
+
echo " [OK] nats: $NATS_HOST:$NATS_PORT ($nats_where) JetStream answered in $FMIX_NATS_PROBE_DETAIL"
|
|
19238
|
+
echo " selection: $FMIX_NATS_HOST_REASON"
|
|
19239
|
+
elif nc -z "$NATS_HOST" "$NATS_PORT" 2>/dev/null; then
|
|
19240
|
+
echo " [FAIL] nats: $NATS_HOST:$NATS_PORT ($nats_where) accepts TCP but JetStream did not answer: $FMIX_NATS_PROBE_DETAIL (bound ${FMIX_NATS_PROBE_TIMEOUT}s)"
|
|
19241
|
+
echo " app boot needs JetStream KV; set FMIX_NATS_HOST=localhost once a local JetStream NATS is up, or restore JetStream on $NATS_HOST"
|
|
19242
|
+
fail=1
|
|
18795
19243
|
else
|
|
18796
19244
|
if ! fmix_nats_host_is_local; then
|
|
18797
19245
|
echo " [WARN] NATS not reachable at $NATS_HOST:$NATS_PORT (remote/tailnet) — check Tailscale connectivity or set FMIX_NATS_HOST=localhost"
|
|
@@ -18907,6 +19355,13 @@ cmd_doctor() {
|
|
|
18907
19355
|
else
|
|
18908
19356
|
echo " [INFO] no state file yet — will be created on first run"
|
|
18909
19357
|
fi
|
|
19358
|
+
elif [[ -n "$git_metadata_report" ]]; then
|
|
19359
|
+
echo " [FAIL] git worktree metadata: $git_metadata_candidate"
|
|
19360
|
+
local git_metadata_line
|
|
19361
|
+
while IFS= read -r git_metadata_line; do
|
|
19362
|
+
[[ -n "$git_metadata_line" ]] && echo " $git_metadata_line"
|
|
19363
|
+
done <<<"$git_metadata_report"
|
|
19364
|
+
fail=$(( fail + 1 ))
|
|
18910
19365
|
fi
|
|
18911
19366
|
|
|
18912
19367
|
# fmix state dir
|
|
@@ -27172,8 +27627,9 @@ Environment overrides:
|
|
|
27172
27627
|
FMIX_DB_PORT Postgres port (default: 5432)
|
|
27173
27628
|
FMIX_DB_USER Postgres user (default: calltelemetry)
|
|
27174
27629
|
FMIX_DB_PASSWORD Postgres password (default: calltelemetry_dev_password)
|
|
27175
|
-
FMIX_NATS_HOST NATS host (default: nats-dev if
|
|
27630
|
+
FMIX_NATS_HOST NATS host (default: nats-dev if its JetStream answers, else a healthy localhost, else localhost)
|
|
27176
27631
|
FMIX_TAILNET_NATS_HOST Tailnet NATS host to probe (default: nats-dev)
|
|
27632
|
+
FMIX_NATS_PROBE_TIMEOUT Seconds allowed per JetStream probe round trip (default: 3)
|
|
27177
27633
|
FMIX_DISABLE_TAILNET_NATS Set to 1 to skip Tailnet probing (default: 1 on CI)
|
|
27178
27634
|
FMIX_NATS_PORT NATS port (default: 4222)
|
|
27179
27635
|
FMIX_COPY_MODE Set to 'full' to disable CoW clone
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@calltelemetry/fmix",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.24",
|
|
4
4
|
"description": "Verified native FMix runner for CallTelemetry workspaces",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"directory": "packages/npm"
|
|
27
27
|
},
|
|
28
28
|
"fmix": {
|
|
29
|
-
"runnerSha256": "
|
|
30
|
-
"sourceTag": "fmix-v2.7.
|
|
29
|
+
"runnerSha256": "0fbb2d612397cc1bbe434d7a6373b8c39fd309c20ce2ad0aebd91c7273d61702",
|
|
30
|
+
"sourceTag": "fmix-v2.7.24"
|
|
31
31
|
}
|
|
32
32
|
}
|