@calltelemetry/fmix 2.7.4 → 2.7.5

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.
Files changed (2) hide show
  1. package/bin/fmix +161 -4
  2. package/package.json +3 -3
package/bin/fmix CHANGED
@@ -6,6 +6,7 @@
6
6
  # ./fmix test [--worktree <path>] [--session <id>] [--isolate] [--cache-base <N.N.N-stable>] [--unit] -- <mix test args>
7
7
  # ./fmix coverage --worktree <path> [--session <id>] --base <git-ref> -- <test paths>
8
8
  # ./fmix task [--worktree <path>] [--session <id>] [--database <name>] [--mix-env <env>] [--allow-run] -- <mix task> [args]
9
+ # ./fmix format [--worktree <path>] [--session <id>] [--mix-env <env>] [--check] -- <files...>
9
10
  # ./fmix setup [--worktree <path>] [--session <id>] [--rebuild-db|--cold-db|--from-zero]
10
11
  # ./fmix seed publish --worktree <path> [--session <id>] --cache-base <N.N.N-stable>
11
12
  # ./fmix cache explain --worktree <path> --cache-base <N.N.N-stable>
@@ -23,7 +24,7 @@ set -uo pipefail
23
24
  # ---------------------------------------------------------------------------
24
25
  # Constants & config
25
26
  # ---------------------------------------------------------------------------
26
- FMIX_VERSION="2.7.4"
27
+ FMIX_VERSION="2.7.5"
27
28
  FMIX_HOME="${FMIX_HOME:-${HOME}/.ct-fmix}"
28
29
  FMIX_OS="$(uname -s)"
29
30
  FMIX_ARCH="$(uname -m)"
@@ -11140,6 +11141,138 @@ cmd_task() {
11140
11141
  return "$task_rc"
11141
11142
  }
11142
11143
 
11144
+ cmd_format() {
11145
+ # Format Elixir sources with the exact pinned toolchain (.tool-versions)
11146
+ # and the same session deps/_build state fmix test compiles against.
11147
+ #
11148
+ # Formatting with an ambient manager shim (mise/asdf/global) whose Elixir
11149
+ # differs from the repo pin is a known hazard: a newer formatter silently
11150
+ # rewrites unrelated hunks and formatter plugins can fail to resolve
11151
+ # (".formatter.exs import_deps" needs the pinned deps compiled). This is
11152
+ # the supported alternative to bare `mix format`.
11153
+ #
11154
+ # Formatting is DB-free: no database is provisioned or contacted, and no
11155
+ # MIX_ENV database variables are injected.
11156
+ local worktree_arg="auto"
11157
+ local session_arg=""
11158
+ local mix_env_arg="test"
11159
+ local check_only=0
11160
+ local found_sep=0
11161
+ local -a fmt_args=()
11162
+ while (( $# > 0 )); do
11163
+ case "$1" in
11164
+ --worktree)
11165
+ [[ $# -ge 2 ]] || { fmix_error "--worktree requires a path argument."; return 2; }
11166
+ worktree_arg="$2"
11167
+ shift 2
11168
+ ;;
11169
+ --worktree=*) worktree_arg="${1#--worktree=}"; shift ;;
11170
+ --session)
11171
+ [[ $# -ge 2 ]] || { fmix_error "--session requires an identifier."; return 2; }
11172
+ session_arg="$2"
11173
+ shift 2
11174
+ ;;
11175
+ --session=*) session_arg="${1#--session=}"; shift ;;
11176
+ --mix-env)
11177
+ [[ $# -ge 2 ]] || { fmix_error "--mix-env requires an environment name."; return 2; }
11178
+ mix_env_arg="$2"
11179
+ shift 2
11180
+ ;;
11181
+ --mix-env=*) mix_env_arg="${1#--mix-env=}"; shift ;;
11182
+ --check) check_only=1; shift ;;
11183
+ --) found_sep=1; shift; break ;;
11184
+ *)
11185
+ fmix_error "Unknown option: $1. Usage: fmix format [--worktree <path>] [--session <id>] [--mix-env <env>] [--check] -- <files...>"
11186
+ return 2
11187
+ ;;
11188
+ esac
11189
+ done
11190
+ (( found_sep == 1 )) || {
11191
+ fmix_error "'fmix format' requires -- before the file arguments."
11192
+ return 2
11193
+ }
11194
+ fmt_args=("$@")
11195
+ (( ${#fmt_args[@]} > 0 )) || {
11196
+ fmix_error "'fmix format' requires at least one file or glob argument after --."
11197
+ return 2
11198
+ }
11199
+ case "${fmt_args[0]}" in
11200
+ test.*)
11201
+ fmix_error "'fmix format' formats files; pass file paths, not a Mix task."
11202
+ return 2
11203
+ ;;
11204
+ esac
11205
+
11206
+ fmix_validate_mix_env "$mix_env_arg" || return 2
11207
+
11208
+ local worktree real_worktree template_key lock_name
11209
+ worktree="$(fmix_find_worktree "$worktree_arg")" || return 1
11210
+ real_worktree="$(fmix_realpath "$worktree")" || return 1
11211
+ fmix_activate_toolchain "$real_worktree" || return 1
11212
+ fmix_activate_session "$real_worktree" "$session_arg" || return 1
11213
+ template_key="$(fmix_compute_template_key "$real_worktree")" || return 1
11214
+ lock_name="$(fmix_execution_lock_name "$real_worktree")"
11215
+
11216
+ fmix_info "=== fmix format ==="
11217
+ fmix_info "Worktree: $real_worktree"
11218
+ fmix_info "Session root: $FMIX_ACTIVE_SESSION_ROOT"
11219
+ fmix_info "Template key: $template_key"
11220
+ fmix_info "Mix environment: $mix_env_arg"
11221
+ if (( check_only == 1 )); then
11222
+ fmix_info "Mode: --check-formatted (read-only; no files are rewritten)"
11223
+ fi
11224
+ fmix_info "Running with pinned toolchain + session deps: mix format ${fmt_args[*]}"
11225
+
11226
+ fmix_lock_acquire "$lock_name" "$FMIX_WORKTREE_LOCK_TIMEOUT" || return 1
11227
+ # Formatter plugins (e.g. .formatter.exs import_deps) require the pinned
11228
+ # deps to be present and compiled; reuse the same ensure path as task.
11229
+ if ! fmix_ensure_artifacts "$real_worktree" "$template_key" 1 ||
11230
+ ! fmix_ensure_compile "$real_worktree" "$(fmix_db_name_for_worktree "$real_worktree")" setup; then
11231
+ fmix_lock_release "$lock_name"
11232
+ return 1
11233
+ fi
11234
+
11235
+ local -a build_env=()
11236
+ [[ -n "${MIX_BUILD_PATH:-}" ]] && build_env+=("MIX_BUILD_PATH=$MIX_BUILD_PATH")
11237
+ [[ -n "${MIX_DEPS_PATH:-}" ]] && build_env+=("MIX_DEPS_PATH=$MIX_DEPS_PATH")
11238
+
11239
+ local -a mix_cmd=(format)
11240
+ if (( check_only == 1 )); then
11241
+ mix_cmd+=(--check-formatted)
11242
+ fi
11243
+ mix_cmd+=("${fmt_args[@]}")
11244
+
11245
+ local fmt_rc=0
11246
+ (
11247
+ cd "$real_worktree" || exit 1
11248
+ exec env \
11249
+ -u DB_HOST_IPV4 \
11250
+ "${build_env[@]+"${build_env[@]}"}" \
11251
+ MIX_ENV="$mix_env_arg" \
11252
+ mix "${mix_cmd[@]}"
11253
+ ) || fmt_rc=$?
11254
+
11255
+ if (( fmt_rc == 0 && check_only == 0 )); then
11256
+ # Formatting rewrites sources, so refresh compile stamps and template
11257
+ # provenance while still holding the worktree lock.
11258
+ if ! fmix_ensure_compile "$real_worktree" "$(fmix_db_name_for_worktree "$real_worktree")" setup; then
11259
+ fmt_rc=1
11260
+ else
11261
+ template_key="$(fmix_compute_template_key "$real_worktree")" || fmt_rc=1
11262
+ fi
11263
+ if (( fmt_rc == 0 )); then
11264
+ fmix_update_template_last_used "$template_key"
11265
+ fi
11266
+ fi
11267
+ fmix_lock_release "$lock_name"
11268
+ if (( check_only == 1 && fmt_rc == 1 )); then
11269
+ fmix_error "Format check failed: files are not formatted per the pinned toolchain."
11270
+ return 1
11271
+ fi
11272
+ fmix_info "Format completed (rc=$fmt_rc)."
11273
+ return "$fmt_rc"
11274
+ }
11275
+
11143
11276
  # ---------------------------------------------------------------------------
11144
11277
  # cmd: fmix doctor
11145
11278
  # ---------------------------------------------------------------------------
@@ -16898,6 +17031,28 @@ Examples:
16898
17031
  fmix task --worktree ./cisco-cdr --database ct_dev --mix-env dev -- ecto.migrate
16899
17032
  fmix task --worktree . --mix-env test --allow-run -- cdrcisco.diff_coverage --staged \
16900
17033
  --staged-diff test-logs/coverage/diff/staged.patch --threshold 80
17034
+ VERB
17035
+ ;;
17036
+ format)
17037
+ cat <<'VERB'
17038
+ fmix format - format Elixir sources with the exact pinned toolchain.
17039
+
17040
+ Usage:
17041
+ fmix format [--worktree <path>] [--session <id>] [--mix-env <env>]
17042
+ [--check] -- <files...>
17043
+
17044
+ Notes:
17045
+ Uses the repo's .tool-versions pin and the same session deps/_build as
17046
+ fmix test, so formatter plugins (.formatter.exs import_deps) resolve the
17047
+ way CI compiles them. Never uses an ambient mise/asdf/global Elixir, which
17048
+ can silently rewrite unrelated hunks when its version differs from the
17049
+ pin. --check is read-only (--check-formatted) for CI and pre-push gates.
17050
+ Formatting is DB-free: no database is provisioned or contacted.
17051
+
17052
+ Examples:
17053
+ fmix format --worktree ./cisco-cdr -- lib/cdrcisco/pipeline_data.ex
17054
+ fmix format -- lib/**/*.ex
17055
+ fmix format --check -- lib/cdrcisco/pipeline_data.ex
16901
17056
  VERB
16902
17057
  ;;
16903
17058
  setup)
@@ -17009,7 +17164,7 @@ Example:
17009
17164
  VERB
17010
17165
  ;;
17011
17166
  *)
17012
- fmix_error "No focused help for '$verb'. Valid commands: test, coverage, task, setup, seed publish, cache explain, cache verify, ensure, doctor, status, timing, gc, install, self-test, version, help"
17167
+ fmix_error "No focused help for '$verb'. Valid commands: test, coverage, task, format, setup, seed publish, cache explain, cache verify, ensure, doctor, status, timing, gc, install, self-test, version, help"
17013
17168
  return 1
17014
17169
  ;;
17015
17170
  esac
@@ -17023,6 +17178,7 @@ Usage:
17023
17178
  ./fmix test [--worktree <path>] [--session <id>] [--cache-base <N.N.N-stable>] [--event-fd <fd>] [--unit] -- <mix test args>
17024
17179
  ./fmix coverage [--worktree <path>] [--session <id>] --base <git-ref> [--source <lib/**/*.ex>] [--threshold 80] -- <test paths>
17025
17180
  ./fmix task [--worktree <path>] [--session <id>] [--database <name>] [--mix-env <env>] [--allow-run] -- <mix task> [args]
17181
+ ./fmix format [--worktree <path>] [--session <id>] [--mix-env <env>] [--check] -- <files...>
17026
17182
  ./fmix setup [--worktree <path>] [--session <id>] [--rebuild-db|--cold-db|--from-zero]
17027
17183
  ./fmix seed publish --worktree <path> [--session <id>] --cache-base <N.N.N-stable>
17028
17184
  ./fmix cache explain --worktree <path> --cache-base <N.N.N-stable>
@@ -19320,7 +19476,7 @@ main() {
19320
19476
  fi
19321
19477
 
19322
19478
  case "$cmd" in
19323
- test|coverage|task|setup|seed|cache|ensure|doctor|status|timing|gc|install|self-test)
19479
+ test|coverage|task|format|setup|seed|cache|ensure|doctor|status|timing|gc|install|self-test)
19324
19480
  if [[ "${1:-}" == "--help" || "${1:-}" == "-h" ]]; then
19325
19481
  fmix_verb_help "$cmd"
19326
19482
  return 0
@@ -19332,6 +19488,7 @@ main() {
19332
19488
  test) cmd_test "$@" ;;
19333
19489
  coverage) cmd_coverage "$@" ;;
19334
19490
  task) cmd_task "$@" ;;
19491
+ format) cmd_format "$@" ;;
19335
19492
  setup) cmd_setup "$@" ;;
19336
19493
  seed) cmd_seed "$@" ;;
19337
19494
  cache) cmd_cache "$@" ;;
@@ -19344,7 +19501,7 @@ main() {
19344
19501
  self-test) cmd_self_test "$@" ;;
19345
19502
  *)
19346
19503
  fmix_error "Unknown command: $cmd"
19347
- fmix_error "Valid commands: test, coverage, task, setup, seed publish, cache explain, cache verify, ensure, doctor, status, timing, gc, install, self-test, version, help"
19504
+ fmix_error "Valid commands: test, coverage, task, format, setup, seed publish, cache explain, cache verify, ensure, doctor, status, timing, gc, install, self-test, version, help"
19348
19505
  fmix_error "Run 'fmix --help' for the full manual or 'fmix help <command>' for focused usage."
19349
19506
  return 1
19350
19507
  ;;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@calltelemetry/fmix",
3
- "version": "2.7.4",
3
+ "version": "2.7.5",
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": "439d402d08194acfd0c50c33221c5e7569a71b5ecaebd8d303cbc8ecdc6524bb",
30
- "sourceTag": "fmix-v2.7.4"
29
+ "runnerSha256": "d3bef245d8cf96a02a660a9009fc35aff58442b0932f29fe071d5b76d70b939f",
30
+ "sourceTag": "fmix-v2.7.5"
31
31
  }
32
32
  }