@calltelemetry/fmix 2.7.20 → 2.7.21

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 +249 -9
  2. 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.20"
31
+ FMIX_VERSION="2.7.21"
32
32
  FMIX_HOME="${FMIX_HOME:-${HOME}/.ct-fmix}"
33
33
  FMIX_OS="$(uname -s)"
34
34
  FMIX_ARCH="$(uname -m)"
@@ -7983,9 +7983,23 @@ def recognizes(source):
7983
7983
  words = [token[0] for token in tokens]
7984
7984
  require(len(words) >= 7 and words[0] == "defmodule")
7985
7985
 
7986
+ # Elixir atoms and keyword keys glue the colon to the word: `:end` and
7987
+ # `end:`. `: end` and `end :` are syntax errors. Requiring that adjacency
7988
+ # keeps a real block `end` followed on the next line by an atom-led
7989
+ # expression (for example `end` then `:code.add_patha(...)`) from being
7990
+ # mistaken for an `end:` keyword key. Adjacency matches Elixir's lexical
7991
+ # grammar without widening the literal project-identity checks.
7992
+ def atom(i):
7993
+ return (i > 0 and words[i - 1] == ":"
7994
+ and tokens[i - 1][2] == tokens[i][1])
7995
+
7996
+ def keyword_key(i):
7997
+ return (i + 1 < len(words) and words[i + 1] == ":"
7998
+ and tokens[i][2] == tokens[i + 1][1])
7999
+
7986
8000
  def codeword(i, word):
7987
- return (words[i] == word and (i == 0 or words[i - 1] not in (":", "."))
7988
- and (i + 1 == len(words) or words[i + 1] != ":"))
8001
+ return (words[i] == word and (i == 0 or words[i - 1] != ".")
8002
+ and not atom(i) and not keyword_key(i))
7989
8003
 
7990
8004
  # Never let a helper module or quoted/metaprogrammed definition become
7991
8005
  # authority. Even otherwise-valid multi-module mix.exs files fail closed.
@@ -7995,9 +8009,7 @@ def recognizes(source):
7995
8009
  # Do not infer ownership through aliases or imported macros. This also
7996
8010
  # excludes qualified Kernel.alias/import; literal atoms/keyword keys do
7997
8011
  # not change lexical resolution and remain opaque field values.
7998
- require(not any(word in ("alias", "import")
7999
- and (i == 0 or words[i - 1] != ":")
8000
- and (i + 1 == len(words) or words[i + 1] != ":")
8012
+ require(not any(word in ("alias", "import") and not atom(i) and not keyword_key(i)
8001
8013
  for i, word in enumerate(words)))
8002
8014
  projects = [i for i, word in enumerate(words[:-1])
8003
8015
  if word in ("def", "defp") and codeword(i, word) and words[i + 1] == "project"]
@@ -12070,6 +12082,10 @@ fmix_run_migration_bounded() {
12070
12082
  timeout="$(fmix_positive_uint_or_default "${3:-$FMIX_MIGRATION_TIMEOUT}" 120 FMIX_MIGRATION_TIMEOUT)"
12071
12083
  log_file="$FMIX_HOME/logs/migrate-$(fmix_worktree_id "$worktree")-$(date +%Y%m%dT%H%M%S).log"
12072
12084
  mkdir -p "$(dirname "$log_file")"
12085
+ # A compile-stamp hit (or restored pool artifacts on a fresh pod) skips the
12086
+ # compile path's Hex bootstrap; `mix ecto.migrate` then dies with "Could
12087
+ # not find an SCM for dependency" before running a single migration.
12088
+ fmix_ensure_hex "$worktree" || fmix_warn "Hex bootstrap failed; ecto.migrate may fail to resolve dependency SCMs."
12073
12089
  local -a build_env=()
12074
12090
  [[ -n "${MIX_BUILD_PATH:-}" ]] && build_env+=("MIX_BUILD_PATH=$MIX_BUILD_PATH")
12075
12091
  [[ -n "${MIX_DEPS_PATH:-}" ]] && build_env+=("MIX_DEPS_PATH=$MIX_DEPS_PATH")
@@ -15117,13 +15133,192 @@ cmd_seed() {
15117
15133
  # cmd: fmix cache
15118
15134
  # ---------------------------------------------------------------------------
15119
15135
 
15136
+ # Cross-pod transport of the local v2 pools (dependency and app-compile): the
15137
+ # runner image ships pool entries to and from an object store as one packed
15138
+ # archive per entry. These verbs never talk to the network; they only read a
15139
+ # verified pool entry into an archive (export) or admit an archive into the
15140
+ # pool through the same staging, sealing, lease and verification discipline
15141
+ # as local publication (import). Any failure is an ordinary miss.
15142
+ fmix_cache_keys() {
15143
+ local real="${1:-}" lane dependency exact runner
15144
+ # Test and setup lanes build and publish inside an active session, whose
15145
+ # fingerprints hash the fmix-session-v1 marker in place of MIX_DEPS_PATH and
15146
+ # MIX_BUILD_PATH. Compute the same keys here without activating a session
15147
+ # (no session directories, no locks); otherwise every key misses.
15148
+ local FMIX_ACTIVE_SESSION_ROOT="${FMIX_ACTIVE_SESSION_ROOT:-fmix-cache-keys}"
15149
+ lane="$(fmix_dependency_lane_fingerprint "$real")" || return 1
15150
+ dependency="$(fmix_compute_dependency_fingerprint "$real")" || return 1
15151
+ exact="$(fmix_compute_compile_fingerprint "$real")" || return 1
15152
+ runner="$(fmix_hash_stdin <"$(fmix_realpath "${BASH_SOURCE[0]}")")" || return 1
15153
+ [[ "$lane" =~ ^[0-9a-f]{64}$ && "$dependency" =~ ^[0-9a-f]{64}$ \
15154
+ && "$exact" =~ ^[0-9a-f]{64}$ && "$runner" =~ ^[0-9a-f]{64}$ ]] || return 1
15155
+ printf '{"lane":"%s","dependency":"%s","exact":"%s","runner":"%s"}\n' \
15156
+ "$lane" "$dependency" "$exact" "$runner"
15157
+ }
15158
+
15159
+ fmix_cache_pool_artifact_dir() {
15160
+ local kind="${1:-}" lane="${2:-}" exact="${3:-}"
15161
+ case "$kind" in
15162
+ dependency) fmix_dependency_artifact_v2_dir "$lane" "$exact" ;;
15163
+ app) [[ "${FMIX_APP_CAS:-1}" != "0" ]] || return 1
15164
+ fmix_app_compile_artifact_v2_dir "$lane" "$exact" ;;
15165
+ *) return 1 ;;
15166
+ esac
15167
+ }
15168
+
15169
+ fmix_cache_pool_verify() {
15170
+ local kind="${1:-}"
15171
+ shift
15172
+ case "$kind" in
15173
+ dependency) fmix_dependency_artifact_verify_full "$@" ;;
15174
+ app) fmix_app_compile_artifact_verify_full "$@" ;;
15175
+ *) return 1 ;;
15176
+ esac
15177
+ }
15178
+
15179
+ fmix_cache_export() {
15180
+ local kind="${1:-}" lane="${2:-}" exact="${3:-}" output="${4:-}"
15181
+ local artifact tmp rc
15182
+ local -a entries=(_build meta.json manifest.tsv manifest.sha256)
15183
+ local -a pipe_rc=()
15184
+ [[ -n "$output" ]] || return 1
15185
+ artifact="$(fmix_cache_pool_artifact_dir "$kind" "$lane" "$exact")" || return 1
15186
+ [[ -d "$artifact" && ! -L "$artifact" ]] || return 1
15187
+ [[ "$artifact" == "$FMIX_HOME/artifacts/v2/"* ]] || return 1
15188
+ command -v zstd >/dev/null 2>&1 || { fmix_error "zstd is required for cache export."; return 1; }
15189
+ fmix_artifact_v2_managed_entrypoint || return 3
15190
+ # Export only what the full manifest verification just proved.
15191
+ fmix_cache_pool_verify "$kind" "$artifact" "$lane" "$exact" || return 1
15192
+ [[ "$kind" == "dependency" ]] && entries=(deps "${entries[@]}")
15193
+ mkdir -p "$(dirname "$output")" || return 1
15194
+ tmp="${output}.tmp.$$"
15195
+ rm -f "$tmp"
15196
+ tar -cf - -C "$artifact" "${entries[@]}" | zstd -T0 -3 -q -f -o "$tmp"
15197
+ pipe_rc=("${PIPESTATUS[@]}")
15198
+ if (( pipe_rc[0] != 0 || pipe_rc[1] != 0 )); then
15199
+ rm -f "$tmp"
15200
+ return 1
15201
+ fi
15202
+ mv "$tmp" "$output" || { rm -f "$tmp"; return 1; }
15203
+ }
15204
+
15205
+ fmix_cache_import() {
15206
+ local kind="${1:-}" lane="${2:-}" exact="${3:-}" archive="${4:-}"
15207
+ local artifact lock_name
15208
+ [[ -f "$archive" ]] || return 1
15209
+ artifact="$(fmix_cache_pool_artifact_dir "$kind" "$lane" "$exact")" || return 1
15210
+ command -v zstd >/dev/null 2>&1 || { fmix_error "zstd is required for cache import."; return 1; }
15211
+ fmix_artifact_v2_managed_entrypoint || return 3
15212
+ if [[ "$kind" == "dependency" ]]; then
15213
+ lock_name="dependency-artifact-${lane:0:16}-${exact:0:16}"
15214
+ else
15215
+ lock_name="app-compile-${lane:0:16}-${exact:0:16}"
15216
+ fi
15217
+ fmix_with_artifact_lease "$lock_name" _fmix_cache_import_locked \
15218
+ "$kind" "$lane" "$exact" "$archive" "$artifact"
15219
+ }
15220
+
15221
+ _fmix_cache_import_locked() {
15222
+ local kind="$1" lane="$2" exact="$3" archive="$4" artifact="$5"
15223
+ local tmp pool_rel expected actual writable pipe_rc_zstd pipe_rc_tar
15224
+ local -a pipe_rc=()
15225
+ if fmix_cache_pool_verify "$kind" "$artifact" "$lane" "$exact"; then
15226
+ return 0
15227
+ fi
15228
+ if [[ "$kind" == "dependency" ]]; then
15229
+ pool_rel="artifacts/v2/dependencies/$lane"
15230
+ else
15231
+ pool_rel="artifacts/v2/app-compiles/$lane"
15232
+ fi
15233
+ fmix_artifact_v2_prepare_directory "$pool_rel" || return 1
15234
+ tmp="${artifact}.tmp-$$-${RANDOM}"
15235
+ if [[ -e "$tmp" || -L "$tmp" ]] || ! mkdir "$tmp"; then
15236
+ return 1
15237
+ fi
15238
+ zstd -d -q -c "$archive" | tar -xf - -C "$tmp"
15239
+ pipe_rc=("${PIPESTATUS[@]}")
15240
+ pipe_rc_zstd="${pipe_rc[0]}"
15241
+ pipe_rc_tar="${pipe_rc[1]}"
15242
+ if (( pipe_rc_zstd != 0 || pipe_rc_tar != 0 )); then
15243
+ chmod -R u+w "$tmp" 2>/dev/null || true
15244
+ rm -rf "$tmp" 2>/dev/null || true
15245
+ return 1
15246
+ fi
15247
+ # Structure, schema, key identity and producer-runner proof first, then the
15248
+ # full manifest digest of the payload, all on the staged tree.
15249
+ chmod -R u+w "$tmp" 2>/dev/null || true
15250
+ if [[ "$kind" == "dependency" ]]; then
15251
+ fmix_dependency_artifact_is_complete "$tmp" "$lane" "$exact" 1 || {
15252
+ rm -rf "$tmp" 2>/dev/null || true
15253
+ return 1
15254
+ }
15255
+ actual="$(fmix_dependency_artifact_manifest_digest "$tmp")" || actual=""
15256
+ else
15257
+ fmix_app_compile_artifact_is_complete "$tmp" "$lane" "$exact" 1 || {
15258
+ rm -rf "$tmp" 2>/dev/null || true
15259
+ return 1
15260
+ }
15261
+ actual="$(fmix_app_compile_artifact_manifest_digest "$tmp")" || actual=""
15262
+ fi
15263
+ IFS= read -r expected <"$tmp/manifest.sha256"
15264
+ if [[ ! "$actual" =~ ^[0-9a-f]{64}$ || "$actual" != "$expected" ]]; then
15265
+ rm -rf "$tmp" 2>/dev/null || true
15266
+ return 1
15267
+ fi
15268
+ chmod -R a-w "$tmp" || { chmod -R u+w "$tmp" 2>/dev/null; rm -rf "$tmp" 2>/dev/null; return 1; }
15269
+ chmod u+w "$tmp" || { chmod -R u+w "$tmp" 2>/dev/null; rm -rf "$tmp" 2>/dev/null; return 1; }
15270
+ writable="$(find "$tmp" -mindepth 1 ! -type l -perm -u+w -print -quit 2>/dev/null)" \
15271
+ || writable=invalid
15272
+ if [[ -n "$writable" ]]; then
15273
+ chmod -R u+w "$tmp" 2>/dev/null || true
15274
+ rm -rf "$tmp" 2>/dev/null || true
15275
+ return 1
15276
+ fi
15277
+ if [[ -e "$artifact" || -L "$artifact" ]]; then
15278
+ # Present but failed verification above: the lease holder replaces it.
15279
+ if [[ "$kind" == "dependency" ]]; then
15280
+ fmix_dependency_artifact_quarantine "$artifact" \
15281
+ "failed exact integrity verification" || { chmod -R u+w "$tmp" 2>/dev/null; rm -rf "$tmp"; return 1; }
15282
+ else
15283
+ fmix_app_compile_artifact_quarantine "$artifact" \
15284
+ "failed exact integrity verification" || { chmod -R u+w "$tmp" 2>/dev/null; rm -rf "$tmp"; return 1; }
15285
+ fi
15286
+ fi
15287
+ if ! mv "$tmp" "$artifact"; then
15288
+ chmod -R u+w "$tmp" 2>/dev/null || true
15289
+ rm -rf "$tmp" 2>/dev/null || true
15290
+ return 1
15291
+ fi
15292
+ chmod a-w "$artifact" || return 1
15293
+ if ! fmix_cache_pool_verify "$kind" "$artifact" "$lane" "$exact"; then
15294
+ if [[ "$kind" == "dependency" ]]; then
15295
+ fmix_dependency_artifact_quarantine "$artifact" \
15296
+ "post-import verification failed" >/dev/null 2>&1 || true
15297
+ else
15298
+ fmix_app_compile_artifact_quarantine "$artifact" \
15299
+ "post-import verification failed" >/dev/null 2>&1 || true
15300
+ fi
15301
+ return 1
15302
+ fi
15303
+ if [[ "$kind" == "dependency" ]]; then
15304
+ fmix_touch_dependency_artifact_access "$lane" "$exact" >/dev/null 2>&1 || true
15305
+ else
15306
+ fmix_touch_app_compile_artifact_access "$lane" "$exact" >/dev/null 2>&1 || true
15307
+ fi
15308
+ fmix_info "Imported $kind pool artifact ${exact:0:12} from archive."
15309
+ }
15310
+
15120
15311
  cmd_cache() {
15121
15312
  local action="${1:-}" worktree_arg="auto" cache_base="" key=""
15313
+ local pool_kind="" pool_lane="" pool_exact="" pool_file=""
15122
15314
  case "$action" in
15123
- explain|verify) ;;
15315
+ explain|verify|keys|export|import) ;;
15124
15316
  *)
15125
15317
  fmix_error "Usage: fmix cache explain --worktree <path> --cache-base <N.N.N-stable>"
15126
15318
  fmix_error " or: fmix cache verify [--key <16-hex-template-key>]"
15319
+ fmix_error " or: fmix cache keys --worktree <path>"
15320
+ fmix_error " or: fmix cache export --kind dependency|app --lane <64-hex> --exact <64-hex> --archive <file.tar.zst>"
15321
+ fmix_error " or: fmix cache import --kind dependency|app --lane <64-hex> --exact <64-hex> --archive <file.tar.zst>"
15127
15322
  return 2
15128
15323
  ;;
15129
15324
  esac
@@ -15148,6 +15343,16 @@ cmd_cache() {
15148
15343
  shift 2
15149
15344
  ;;
15150
15345
  --key=*) key="${1#--key=}"; shift ;;
15346
+ --kind|--lane|--exact|--archive)
15347
+ [[ $# -ge 2 ]] || { fmix_error "$1 requires a value."; return 2; }
15348
+ case "$1" in
15349
+ --kind) pool_kind="$2" ;;
15350
+ --lane) pool_lane="$2" ;;
15351
+ --exact) pool_exact="$2" ;;
15352
+ --archive) pool_file="$2" ;;
15353
+ esac
15354
+ shift 2
15355
+ ;;
15151
15356
  *)
15152
15357
  fmix_error "Unknown cache $action option: $1."
15153
15358
  return 2
@@ -15155,6 +15360,36 @@ cmd_cache() {
15155
15360
  esac
15156
15361
  done
15157
15362
 
15363
+ if [[ "$action" == "keys" ]]; then
15364
+ local keys_worktree keys_real
15365
+ keys_worktree="$(fmix_find_worktree "$worktree_arg")" || return 1
15366
+ keys_real="$(fmix_realpath "$keys_worktree")" || return 1
15367
+ fmix_activate_toolchain "$keys_real" || return 1
15368
+ fmix_cache_keys "$keys_real" || {
15369
+ fmix_error "Could not compute cache keys for $keys_real."
15370
+ return 1
15371
+ }
15372
+ return 0
15373
+ fi
15374
+
15375
+ if [[ "$action" == "export" || "$action" == "import" ]]; then
15376
+ [[ "$pool_kind" == "dependency" || "$pool_kind" == "app" ]] || {
15377
+ fmix_error "--kind must be dependency or app."
15378
+ return 2
15379
+ }
15380
+ [[ "$pool_lane" =~ ^[0-9a-f]{64}$ && "$pool_exact" =~ ^[0-9a-f]{64}$ ]] || {
15381
+ fmix_error "--lane and --exact must be 64-hex fingerprints."
15382
+ return 2
15383
+ }
15384
+ [[ -n "$pool_file" ]] || { fmix_error "--archive is required."; return 2; }
15385
+ if [[ "$action" == "export" ]]; then
15386
+ fmix_cache_export "$pool_kind" "$pool_lane" "$pool_exact" "$pool_file"
15387
+ else
15388
+ fmix_cache_import "$pool_kind" "$pool_lane" "$pool_exact" "$pool_file"
15389
+ fi
15390
+ return $?
15391
+ fi
15392
+
15158
15393
  if [[ "$action" == "verify" ]]; then
15159
15394
  [[ -z "$worktree_arg" || "$worktree_arg" == "auto" ]] || {
15160
15395
  fmix_error "--worktree is not valid with 'fmix cache verify'."
@@ -26536,11 +26771,14 @@ VERB
26536
26771
  ;;
26537
26772
  cache)
26538
26773
  cat <<'VERB'
26539
- fmix cache — explain or verify the template cache.
26774
+ fmix cache — explain or verify the template cache; key and move pool entries.
26540
26775
 
26541
26776
  Usage:
26542
26777
  fmix cache explain --worktree <path> --cache-base <N.N.N-stable> # read-only
26543
26778
  fmix cache verify [--key <16-hex-template-key>]
26779
+ fmix cache keys --worktree <path> # JSON {lane, dependency, exact, runner}; read-only
26780
+ fmix cache export --kind dependency|app --lane <64-hex> --exact <64-hex> --archive <file.tar.zst>
26781
+ fmix cache import --kind dependency|app --lane <64-hex> --exact <64-hex> --archive <file.tar.zst>
26544
26782
 
26545
26783
  Example:
26546
26784
  fmix cache explain --worktree ./cisco-cdr --cache-base 0.8.7-stable
@@ -30050,7 +30288,9 @@ main() {
30050
30288
  return $?
30051
30289
  fi
30052
30290
 
30053
- if [[ "$cmd" == "cache" ]]; then
30291
+ if [[ "$cmd" == "cache" && ( "${1:-}" == "import" || "${1:-}" == "export" ) ]]; then
30292
+ fmix_prepare_command_home || return 1
30293
+ elif [[ "$cmd" == "cache" ]]; then
30054
30294
  fmix_prepare_home_readonly || return 1
30055
30295
  elif [[ "$cmd" != "test" && "$cmd" != "coverage" && "$cmd" != "verify-push" && "$cmd" != "hook" && "$cmd" != "runner" ]]; then
30056
30296
  fmix_prepare_command_home || return 1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@calltelemetry/fmix",
3
- "version": "2.7.20",
3
+ "version": "2.7.21",
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": "00f4fd8bf2cb8a13588525d1ea0dae26db495ff0c6fe8a1877455f2253fea8d4",
30
- "sourceTag": "fmix-v2.7.20"
29
+ "runnerSha256": "01c0f1e7edcf572df64d6fa9735fd3396ffc7f703c89da2b26081a88d91f813f",
30
+ "sourceTag": "fmix-v2.7.21"
31
31
  }
32
32
  }