@calltelemetry/fmix 2.7.4 → 2.7.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.
Files changed (2) hide show
  1. package/bin/fmix +181 -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>] [--dot-formatter <path>] [--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.6"
27
28
  FMIX_HOME="${FMIX_HOME:-${HOME}/.ct-fmix}"
28
29
  FMIX_OS="$(uname -s)"
29
30
  FMIX_ARCH="$(uname -m)"
@@ -11140,6 +11141,153 @@ 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 dot_formatter_arg=""
11160
+ local check_only=0
11161
+ local found_sep=0
11162
+ local -a fmt_args=()
11163
+ while (( $# > 0 )); do
11164
+ case "$1" in
11165
+ --worktree)
11166
+ [[ $# -ge 2 ]] || { fmix_error "--worktree requires a path argument."; return 2; }
11167
+ worktree_arg="$2"
11168
+ shift 2
11169
+ ;;
11170
+ --worktree=*) worktree_arg="${1#--worktree=}"; shift ;;
11171
+ --session)
11172
+ [[ $# -ge 2 ]] || { fmix_error "--session requires an identifier."; return 2; }
11173
+ session_arg="$2"
11174
+ shift 2
11175
+ ;;
11176
+ --session=*) session_arg="${1#--session=}"; shift ;;
11177
+ --mix-env)
11178
+ [[ $# -ge 2 ]] || { fmix_error "--mix-env requires an environment name."; return 2; }
11179
+ mix_env_arg="$2"
11180
+ shift 2
11181
+ ;;
11182
+ --mix-env=*) mix_env_arg="${1#--mix-env=}"; shift ;;
11183
+ --dot-formatter)
11184
+ [[ $# -ge 2 ]] || { fmix_error "--dot-formatter requires a path argument."; return 2; }
11185
+ dot_formatter_arg="$2"
11186
+ shift 2
11187
+ ;;
11188
+ --dot-formatter=*) dot_formatter_arg="${1#--dot-formatter=}"; shift ;;
11189
+ --check) check_only=1; shift ;;
11190
+ --) found_sep=1; shift; break ;;
11191
+ *)
11192
+ fmix_error "Unknown option: $1. Usage: fmix format [--worktree <path>] [--session <id>] [--mix-env <env>] [--dot-formatter <path>] [--check] -- <files...>"
11193
+ return 2
11194
+ ;;
11195
+ esac
11196
+ done
11197
+ (( found_sep == 1 )) || {
11198
+ fmix_error "'fmix format' requires -- before the file arguments."
11199
+ return 2
11200
+ }
11201
+ fmt_args=("$@")
11202
+ (( ${#fmt_args[@]} > 0 )) || {
11203
+ fmix_error "'fmix format' requires at least one file or glob argument after --."
11204
+ return 2
11205
+ }
11206
+ case "${fmt_args[0]}" in
11207
+ test.*)
11208
+ fmix_error "'fmix format' formats files; pass file paths, not a Mix task."
11209
+ return 2
11210
+ ;;
11211
+ esac
11212
+
11213
+ fmix_validate_mix_env "$mix_env_arg" || return 2
11214
+
11215
+ local worktree real_worktree template_key lock_name
11216
+ worktree="$(fmix_find_worktree "$worktree_arg")" || return 1
11217
+ real_worktree="$(fmix_realpath "$worktree")" || return 1
11218
+ fmix_activate_toolchain "$real_worktree" || return 1
11219
+ fmix_activate_session "$real_worktree" "$session_arg" || return 1
11220
+ template_key="$(fmix_compute_template_key "$real_worktree")" || return 1
11221
+ lock_name="$(fmix_execution_lock_name "$real_worktree")"
11222
+
11223
+ fmix_info "=== fmix format ==="
11224
+ fmix_info "Worktree: $real_worktree"
11225
+ fmix_info "Session root: $FMIX_ACTIVE_SESSION_ROOT"
11226
+ fmix_info "Template key: $template_key"
11227
+ fmix_info "Mix environment: $mix_env_arg"
11228
+ if (( check_only == 1 )); then
11229
+ fmix_info "Mode: --check-formatted (read-only; no files are rewritten)"
11230
+ fi
11231
+ fmix_info "Running with pinned toolchain + session deps: mix format ${fmt_args[*]}"
11232
+
11233
+ fmix_lock_acquire "$lock_name" "$FMIX_WORKTREE_LOCK_TIMEOUT" || return 1
11234
+ # Formatter plugins (e.g. .formatter.exs import_deps) require the pinned
11235
+ # deps to be present and compiled; reuse the same ensure path as task.
11236
+ if ! fmix_ensure_artifacts "$real_worktree" "$template_key" 1 ||
11237
+ ! fmix_ensure_compile "$real_worktree" "$(fmix_db_name_for_worktree "$real_worktree")" setup; then
11238
+ fmix_lock_release "$lock_name"
11239
+ return 1
11240
+ fi
11241
+
11242
+ local -a build_env=()
11243
+ [[ -n "${MIX_BUILD_PATH:-}" ]] && build_env+=("MIX_BUILD_PATH=$MIX_BUILD_PATH")
11244
+ [[ -n "${MIX_DEPS_PATH:-}" ]] && build_env+=("MIX_DEPS_PATH=$MIX_DEPS_PATH")
11245
+
11246
+ local -a mix_cmd=(format)
11247
+ if (( check_only == 1 )); then
11248
+ mix_cmd+=(--check-formatted)
11249
+ fi
11250
+ # Formatter-configuration scopes: repos with `subdirectories` entries in
11251
+ # .formatter.exs (e.g. Ecto migrations under priv/*/migrations) format
11252
+ # those files with a different import_deps/locals_without_parens set than
11253
+ # the root config. --dot-formatter selects that config explicitly while
11254
+ # deps still resolve from the project root.
11255
+ if [[ -n "$dot_formatter_arg" ]]; then
11256
+ mix_cmd+=(--dot-formatter "$dot_formatter_arg")
11257
+ fi
11258
+ mix_cmd+=("${fmt_args[@]}")
11259
+
11260
+ local fmt_rc=0
11261
+ (
11262
+ cd "$real_worktree" || exit 1
11263
+ exec env \
11264
+ -u DB_HOST_IPV4 \
11265
+ "${build_env[@]+"${build_env[@]}"}" \
11266
+ MIX_ENV="$mix_env_arg" \
11267
+ mix "${mix_cmd[@]}"
11268
+ ) || fmt_rc=$?
11269
+
11270
+ if (( fmt_rc == 0 && check_only == 0 )); then
11271
+ # Formatting rewrites sources, so refresh compile stamps and template
11272
+ # provenance while still holding the worktree lock.
11273
+ if ! fmix_ensure_compile "$real_worktree" "$(fmix_db_name_for_worktree "$real_worktree")" setup; then
11274
+ fmt_rc=1
11275
+ else
11276
+ template_key="$(fmix_compute_template_key "$real_worktree")" || fmt_rc=1
11277
+ fi
11278
+ if (( fmt_rc == 0 )); then
11279
+ fmix_update_template_last_used "$template_key"
11280
+ fi
11281
+ fi
11282
+ fmix_lock_release "$lock_name"
11283
+ if (( check_only == 1 && fmt_rc == 1 )); then
11284
+ fmix_error "Format check failed: files are not formatted per the pinned toolchain."
11285
+ return 1
11286
+ fi
11287
+ fmix_info "Format completed (rc=$fmt_rc)."
11288
+ return "$fmt_rc"
11289
+ }
11290
+
11143
11291
  # ---------------------------------------------------------------------------
11144
11292
  # cmd: fmix doctor
11145
11293
  # ---------------------------------------------------------------------------
@@ -16898,6 +17046,33 @@ Examples:
16898
17046
  fmix task --worktree ./cisco-cdr --database ct_dev --mix-env dev -- ecto.migrate
16899
17047
  fmix task --worktree . --mix-env test --allow-run -- cdrcisco.diff_coverage --staged \
16900
17048
  --staged-diff test-logs/coverage/diff/staged.patch --threshold 80
17049
+ VERB
17050
+ ;;
17051
+ format)
17052
+ cat <<'VERB'
17053
+ fmix format - format Elixir sources with the exact pinned toolchain.
17054
+
17055
+ Usage:
17056
+ fmix format [--worktree <path>] [--session <id>] [--mix-env <env>]
17057
+ [--dot-formatter <path>] [--check] -- <files...>
17058
+
17059
+ Notes:
17060
+ Uses the repo's .tool-versions pin and the same session deps/_build as
17061
+ fmix test, so formatter plugins (.formatter.exs import_deps) resolve the
17062
+ way CI compiles them. Never uses an ambient mise/asdf/global Elixir, which
17063
+ can silently rewrite unrelated hunks when its version differs from the
17064
+ pin. --check is read-only (--check-formatted) for CI and pre-push gates.
17065
+ --dot-formatter <path> formats the passed files with a specific formatter
17066
+ configuration (e.g. priv/repo/migrations/.formatter.exs) while deps still
17067
+ resolve from the project root — the equivalent of the `subdirectories`
17068
+ entries in a root .formatter.exs.
17069
+ Formatting is DB-free: no database is provisioned or contacted.
17070
+
17071
+ Examples:
17072
+ fmix format --worktree ./cisco-cdr -- lib/cdrcisco/pipeline_data.ex
17073
+ fmix format -- lib/**/*.ex
17074
+ fmix format --check -- lib/cdrcisco/pipeline_data.ex
17075
+ fmix format --dot-formatter priv/repo/migrations/.formatter.exs -- priv/repo/migrations/*.exs
16901
17076
  VERB
16902
17077
  ;;
16903
17078
  setup)
@@ -17009,7 +17184,7 @@ Example:
17009
17184
  VERB
17010
17185
  ;;
17011
17186
  *)
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"
17187
+ 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
17188
  return 1
17014
17189
  ;;
17015
17190
  esac
@@ -17023,6 +17198,7 @@ Usage:
17023
17198
  ./fmix test [--worktree <path>] [--session <id>] [--cache-base <N.N.N-stable>] [--event-fd <fd>] [--unit] -- <mix test args>
17024
17199
  ./fmix coverage [--worktree <path>] [--session <id>] --base <git-ref> [--source <lib/**/*.ex>] [--threshold 80] -- <test paths>
17025
17200
  ./fmix task [--worktree <path>] [--session <id>] [--database <name>] [--mix-env <env>] [--allow-run] -- <mix task> [args]
17201
+ ./fmix format [--worktree <path>] [--session <id>] [--mix-env <env>] [--dot-formatter <path>] [--check] -- <files...>
17026
17202
  ./fmix setup [--worktree <path>] [--session <id>] [--rebuild-db|--cold-db|--from-zero]
17027
17203
  ./fmix seed publish --worktree <path> [--session <id>] --cache-base <N.N.N-stable>
17028
17204
  ./fmix cache explain --worktree <path> --cache-base <N.N.N-stable>
@@ -19320,7 +19496,7 @@ main() {
19320
19496
  fi
19321
19497
 
19322
19498
  case "$cmd" in
19323
- test|coverage|task|setup|seed|cache|ensure|doctor|status|timing|gc|install|self-test)
19499
+ test|coverage|task|format|setup|seed|cache|ensure|doctor|status|timing|gc|install|self-test)
19324
19500
  if [[ "${1:-}" == "--help" || "${1:-}" == "-h" ]]; then
19325
19501
  fmix_verb_help "$cmd"
19326
19502
  return 0
@@ -19332,6 +19508,7 @@ main() {
19332
19508
  test) cmd_test "$@" ;;
19333
19509
  coverage) cmd_coverage "$@" ;;
19334
19510
  task) cmd_task "$@" ;;
19511
+ format) cmd_format "$@" ;;
19335
19512
  setup) cmd_setup "$@" ;;
19336
19513
  seed) cmd_seed "$@" ;;
19337
19514
  cache) cmd_cache "$@" ;;
@@ -19344,7 +19521,7 @@ main() {
19344
19521
  self-test) cmd_self_test "$@" ;;
19345
19522
  *)
19346
19523
  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"
19524
+ 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
19525
  fmix_error "Run 'fmix --help' for the full manual or 'fmix help <command>' for focused usage."
19349
19526
  return 1
19350
19527
  ;;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@calltelemetry/fmix",
3
- "version": "2.7.4",
3
+ "version": "2.7.6",
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": "0c6ea7a977b0748c46f2aca082a398bc642ccbb07da2c29d14649144494b2388",
30
+ "sourceTag": "fmix-v2.7.6"
31
31
  }
32
32
  }