@xrystal/core 3.55.64 → 3.55.66

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/README.md CHANGED
@@ -263,7 +263,7 @@ bun run dev
263
263
 
264
264
  **TR:** `x/environments/*` yalnızca lokal dev + Telepresence. Image'a gömme. Cluster'da Secret inject; runtime dosya okumaz.
265
265
 
266
- **Infra preflight:** Before Kafka/Redis/Mongo connect, parallel TCP (~500ms) from tmp.yml + env. **Default fail-fast** (structured report with UTC time, runtime, probe stats; exit 1 without stack). Lenient: `STRICT_INFRA_PREFLIGHT=0`. Disable TCP: `INFRA_PREFLIGHT_TCP=0`. Timeout: `INFRA_PREFLIGHT_TIMEOUT_MS`.
266
+ **Infra preflight:** Before Kafka/Redis/Mongo connect, TCP checks from tmp.yml + env. **Default fail-fast** in cluster and plain local dev. **Telepresence intercept** (pod env on laptop, no service-account token): lenient by default + 2s probe — override with `STRICT_INFRA_PREFLIGHT=1`.
267
267
 
268
268
  **Docker / Compose:** Image `CMD ["bun", "xry", "start"]` (dev: `xry dev`). Runtime skips `x/environments` when `/.dockerenv` or k8s is detected (optional override: `XRY_RUNTIME=container|docker|k8s`). Compose: `env_file:` on `x/docker/docker-compose*.yml` — not `COPY` env into the image.
269
269
  | `xry test` | Run `x/tests` | `x/tests` çalıştır |
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "Yusuf Yasir KAYGUSUZ",
3
3
  "name": "@xrystal/core",
4
- "version": "3.55.64",
4
+ "version": "3.55.66",
5
5
  "description": "Runtime framework and CLI for API services, frontends, and multi-repo workspaces",
6
6
  "publishConfig": {
7
7
  "access": "public",
@@ -6,6 +6,11 @@ import { printCommandFooter, printCommandHeader } from '../helpers/banner.mjs'
6
6
  import { CLI_PRIMARY_NAME } from '../helpers/cli-identity.mjs'
7
7
  import { readCliPackageJson } from '../helpers/project-root.mjs'
8
8
  import { formatInfraResolveHint, resolveInfraHelperScript } from '../helpers/resolve-infra-helper.mjs'
9
+ import {
10
+ connectTelepresence,
11
+ quitTelepresence,
12
+ runTelepresenceIntercept,
13
+ } from '../helpers/telepresence-runtime.mjs'
9
14
  import {
10
15
  ensureServiceTelepresenceEnv,
11
16
  resolveTelepresenceServiceDir,
@@ -13,14 +18,6 @@ import {
13
18
  } from '../helpers/telepresence-layout.mjs'
14
19
  import { findWorkspaceRoot } from '../helpers/workspace-resolve.mjs'
15
20
 
16
- function runHelper(scriptPath, args, { cwd } = {}) {
17
- execSync(`bash "${scriptPath}" ${args.map((a) => JSON.stringify(a)).join(' ')}`, {
18
- cwd: cwd ?? process.cwd(),
19
- stdio: 'inherit',
20
- env: process.env,
21
- })
22
- }
23
-
24
21
  function requireInfraScript(name, { cliName } = {}) {
25
22
  const script = resolveInfraHelperScript(name, { cwd: process.cwd() })
26
23
  if (!script) {
@@ -53,47 +50,51 @@ export function registerTelepresenceCommand(cli, { cliName = CLI_PRIMARY_NAME }
53
50
  ${chalk.gray('intercept/dev')} = local intercept + run process (NOT the k8s namespace)
54
51
  ${chalk.gray('--ns')} = Kubernetes namespace (default: dev)
55
52
  ${chalk.gray('<deploy>')} = ${TELEPRESENCE_DEPLOYMENTS.join(', ')}
56
- ${chalk.gray('Infra scripts:')} XRYSTAL_INFRA_DIR ${chalk.gray('or sibling')} ../-infrastructure-
53
+ ${chalk.gray('kubeconfig:')} workspace tmp.yml, KUBECONFIG, data/k3s/cluster.kubeconfig
57
54
  `,
58
55
  )
59
56
 
60
- tp
61
- .command('connect')
57
+ tp.command('connect')
62
58
  .description('Connect local machine to cluster namespace')
63
59
  .option('--ns <namespace>', 'Kubernetes namespace', 'dev')
64
60
  .action((options) => {
65
61
  const version = readCliPackageJson().version
66
62
  printCommandHeader({ cliName, command: 'telepresence connect', version })
67
- const script = requireInfraScript('telepresence-connect.sh', { cliName })
68
- process.env.NS = options.ns
69
- runHelper(script, [`NS=${options.ns}`])
63
+ try {
64
+ const code = connectTelepresence({ ns: options.ns, cwd: process.cwd() })
65
+ if (code !== 0) process.exit(code)
66
+ } catch (err) {
67
+ console.error(chalk.red(`\n✗ ${err.message}\n`))
68
+ process.exit(1)
69
+ }
70
70
  printCommandFooter({ version })
71
71
  })
72
72
 
73
- tp
74
- .command('quit')
73
+ tp.command('quit')
75
74
  .description('Disconnect Telepresence')
76
75
  .action(() => {
77
76
  const version = readCliPackageJson().version
78
77
  printCommandHeader({ cliName, command: 'telepresence quit', version })
79
- const script = requireInfraScript('telepresence-quit.sh', { cliName })
80
- runHelper(script, [])
78
+ try {
79
+ quitTelepresence()
80
+ } catch (err) {
81
+ console.error(chalk.red(`\n✗ ${err.message}\n`))
82
+ process.exit(1)
83
+ }
81
84
  printCommandFooter({ version })
82
85
  })
83
86
 
84
- tp
85
- .command('install')
87
+ tp.command('install')
86
88
  .description('Install Telepresence OSS client (~2.31.x, matches cluster chart)')
87
89
  .action(() => {
88
90
  const version = readCliPackageJson().version
89
91
  printCommandHeader({ cliName, command: 'telepresence install', version })
90
92
  const script = requireInfraScript('telepresence-client-install.sh', { cliName })
91
- runHelper(script, [])
93
+ execSync(`bash "${script}"`, { stdio: 'inherit', env: process.env })
92
94
  printCommandFooter({ version })
93
95
  })
94
96
 
95
- const intercept = tp
96
- .command('intercept')
97
+ tp.command('intercept')
97
98
  .alias('dev')
98
99
  .description('Intercept cluster deployment and run local process (--ns = k8s namespace, not this subcommand name)')
99
100
  .argument('<deploy>', `Deployment name (${TELEPRESENCE_DEPLOYMENTS.join(', ')})`)
@@ -124,7 +125,6 @@ export function registerTelepresenceCommand(cli, { cliName = CLI_PRIMARY_NAME }
124
125
  }
125
126
 
126
127
  const env = ensureServiceTelepresenceEnv(svcDir)
127
- process.env.TELEPRESENCE_ENV_FILE = env.envRel
128
128
  process.env.NS = ns
129
129
  if (workspaceRoot) process.env.XRYSTAL_WORKSPACE = workspaceRoot
130
130
 
@@ -133,17 +133,24 @@ export function registerTelepresenceCommand(cli, { cliName = CLI_PRIMARY_NAME }
133
133
  console.log(chalk.gray(` service: ${svcDir}`))
134
134
  console.log(chalk.gray(` env: ${env.envRel}${env.created ? chalk.green(' (created)') : ''}\n`))
135
135
 
136
- const interceptScript = requireInfraScript('telepresence-intercept.sh', { cliName })
137
-
138
136
  const portArg = parsePort(port)
139
- process.env.PORT = portArg
140
137
  const rest = command.args.slice(/^\d+$/.test(String(port ?? '')) ? 2 : 1)
141
138
  const localCmd = rest.length ? rest : ['xry', 'dev']
142
- const args = [`NS=${ns}`, deployName, portArg, '--', ...localCmd]
143
139
 
144
140
  console.log(chalk.gray(` local port: ${portArg} (pod container :3000)`))
145
141
 
146
- runHelper(interceptScript, args, { cwd: svcDir })
147
- printCommandFooter({ version })
142
+ try {
143
+ runTelepresenceIntercept({
144
+ deploy: deployName,
145
+ ns,
146
+ port: portArg,
147
+ envFile: env.envPath,
148
+ localCmd,
149
+ cwd: svcDir,
150
+ })
151
+ } catch (err) {
152
+ console.error(chalk.red(`\n✗ ${err.message}\n`))
153
+ process.exit(1)
154
+ }
148
155
  })
149
156
  }
@@ -0,0 +1,349 @@
1
+ import { execSync, spawnSync } from 'node:child_process'
2
+ import fs from 'node:fs'
3
+ import os from 'node:os'
4
+ import path from 'node:path'
5
+
6
+ import { listInfraRootCandidates } from './resolve-infra-helper.mjs'
7
+ import { getCliConfigInfraDir } from './xrystal-config.mjs'
8
+ import { findWorkspaceRoot, resolveWorkspaceOuterTmp } from './workspace-resolve.mjs'
9
+
10
+ const ALLOWED_NS = new Set(['dev', 'test'])
11
+ const DEFAULT_MANAGER_NS = 'telepresence'
12
+
13
+ function expandHome(filePath) {
14
+ const raw = String(filePath ?? '').trim()
15
+ if (!raw) return raw
16
+ if (raw.startsWith('~/')) return path.join(os.homedir(), raw.slice(2))
17
+ if (raw === '~') return os.homedir()
18
+ return raw
19
+ }
20
+
21
+ function parseKubeconfigLine(tmpPath) {
22
+ const text = fs.readFileSync(tmpPath, 'utf8')
23
+ const match = text.match(/^kubeconfig:\s*(.+?)\s*(?:#.*)?$/m)
24
+ if (!match) return null
25
+ let value = match[1].trim()
26
+ if (
27
+ (value.startsWith('"') && value.endsWith('"')) ||
28
+ (value.startsWith("'") && value.endsWith("'"))
29
+ ) {
30
+ value = value.slice(1, -1)
31
+ }
32
+ return expandHome(value)
33
+ }
34
+
35
+ /** Laptop kubeconfig — no ansible-var; optional infra data/k3s path only as file fallback. */
36
+ export function resolveKubeconfig(cwd = process.cwd()) {
37
+ const fromEnv = process.env.KUBECONFIG
38
+ if (fromEnv) {
39
+ for (const part of fromEnv.split(path.delimiter)) {
40
+ const candidate = expandHome(part.trim())
41
+ if (candidate && fs.existsSync(candidate)) return candidate
42
+ }
43
+ }
44
+
45
+ const workspaceRoot = findWorkspaceRoot(cwd)
46
+ if (workspaceRoot) {
47
+ const tmpPath = resolveWorkspaceOuterTmp(workspaceRoot)
48
+ if (tmpPath && fs.existsSync(tmpPath)) {
49
+ const fromTmp = parseKubeconfigLine(tmpPath)
50
+ if (fromTmp && fs.existsSync(fromTmp)) return fromTmp
51
+ }
52
+ }
53
+
54
+ const configuredInfra = getCliConfigInfraDir()
55
+ if (configuredInfra) {
56
+ const candidate = path.join(configuredInfra, 'data', 'k3s', 'cluster.kubeconfig')
57
+ if (fs.existsSync(candidate)) return candidate
58
+ }
59
+
60
+ for (const root of listInfraRootCandidates(cwd)) {
61
+ const candidate = path.join(root, 'data', 'k3s', 'cluster.kubeconfig')
62
+ if (fs.existsSync(candidate)) return candidate
63
+ }
64
+
65
+ const defaultPath = path.join(os.homedir(), '.kube', 'config')
66
+ if (fs.existsSync(defaultPath)) return defaultPath
67
+
68
+ return null
69
+ }
70
+
71
+ export function ensureTelepresenceOnPath() {
72
+ if (commandExists('telepresence')) return
73
+ const localBin = path.join(os.homedir(), '.local', 'bin', 'telepresence')
74
+ if (fs.existsSync(localBin)) {
75
+ process.env.PATH = `${path.dirname(localBin)}${path.delimiter}${process.env.PATH ?? ''}`
76
+ }
77
+ if (!commandExists('telepresence')) {
78
+ throw new Error(
79
+ 'Install Telepresence client (match cluster chart ~2.31.x): xry tp install — https://telepresence.io/docs/install/client',
80
+ )
81
+ }
82
+ }
83
+
84
+ function commandExists(name) {
85
+ try {
86
+ execSync(`command -v ${name}`, { stdio: 'ignore', shell: true })
87
+ return true
88
+ } catch {
89
+ return false
90
+ }
91
+ }
92
+
93
+ export function assertNamespaceAllowed(ns) {
94
+ if (ns === 'prod') {
95
+ throw new Error('Refusing prod namespace — Telepresence is scoped to dev/staging only')
96
+ }
97
+ if (!ALLOWED_NS.has(ns)) {
98
+ throw new Error(`Unknown NS=${ns} (use dev or test)`)
99
+ }
100
+ }
101
+
102
+ function telepresenceStatusText() {
103
+ try {
104
+ return execSync('telepresence status 2>&1', { encoding: 'utf8' })
105
+ } catch (err) {
106
+ return `${err.stdout ?? ''}${err.stderr ?? ''}${err.message ?? ''}`
107
+ }
108
+ }
109
+
110
+ export function isTelepresenceConnected(ns) {
111
+ const status = telepresenceStatusText()
112
+ if (!/Traffic Manager.*Connected/i.test(status)) return false
113
+ return new RegExp(`Namespace\\s*:\\s*${ns}([\\s]|$)`).test(status)
114
+ }
115
+
116
+ function resetDaemonIfExecutableMismatch() {
117
+ try {
118
+ if (!commandExists('telepresence')) return
119
+ const status = telepresenceStatusText()
120
+ if (/executable mismatch/i.test(status)) {
121
+ console.error('Resetting Telepresence daemon (executable path changed)...')
122
+ execSync('telepresence quit -s', { stdio: 'ignore', shell: true })
123
+ execSync('sleep 1', { stdio: 'ignore', shell: true })
124
+ }
125
+ } catch {
126
+ /* ignore */
127
+ }
128
+ }
129
+
130
+ export function connectTelepresence({
131
+ ns = 'dev',
132
+ managerNs = process.env.TELEPRESENCE_MANAGER_NS || DEFAULT_MANAGER_NS,
133
+ cwd = process.cwd(),
134
+ extraArgs = [],
135
+ } = {}) {
136
+ assertNamespaceAllowed(ns)
137
+ ensureTelepresenceOnPath()
138
+ const kubeconfig = resolveKubeconfig(cwd)
139
+ if (!kubeconfig) {
140
+ throw new Error(
141
+ 'Kubeconfig not found — set KUBECONFIG, workspace tmp kubeconfig:, make kubeconfig-sync, or ~/.kube/config',
142
+ )
143
+ }
144
+ resetDaemonIfExecutableMismatch()
145
+ console.log(`Connecting to cluster (namespace=${ns}, kubeconfig=${kubeconfig})...`)
146
+ console.log(`Traffic manager namespace: ${managerNs}`)
147
+ const env = { ...process.env, KUBECONFIG: kubeconfig }
148
+ const result = spawnSync(
149
+ 'telepresence',
150
+ ['connect', '--namespace', ns, '--manager-namespace', managerNs, ...extraArgs],
151
+ { stdio: 'inherit', env },
152
+ )
153
+ if (result.error) throw result.error
154
+ return result.status ?? 1
155
+ }
156
+
157
+ export function quitTelepresence() {
158
+ ensureTelepresenceOnPath()
159
+ try {
160
+ const json = execSync('telepresence list --output json 2>/dev/null', {
161
+ encoding: 'utf8',
162
+ shell: true,
163
+ })
164
+ let items = []
165
+ try {
166
+ items = JSON.parse(json)
167
+ } catch {
168
+ items = []
169
+ }
170
+ if (!Array.isArray(items)) items = []
171
+ for (const it of items) {
172
+ const name = it?.name || it?.workload
173
+ const itemNs = it?.namespace || 'dev'
174
+ if (!name) continue
175
+ try {
176
+ execSync(`telepresence detach "${name}" --namespace "${itemNs}"`, {
177
+ stdio: 'ignore',
178
+ shell: true,
179
+ })
180
+ } catch {
181
+ /* ignore */
182
+ }
183
+ }
184
+ } catch {
185
+ /* no active intercepts */
186
+ }
187
+ try {
188
+ execSync('telepresence quit -s', { stdio: 'ignore', shell: true })
189
+ } catch {
190
+ try {
191
+ execSync('telepresence quit', { stdio: 'ignore', shell: true })
192
+ } catch {
193
+ /* ignore */
194
+ }
195
+ }
196
+ console.log('Telepresence stopped.')
197
+ }
198
+
199
+ function resolveCertificatesRoot(cwd) {
200
+ if (process.env.TELEPRESENCE_CERT_ROOT) {
201
+ const root = expandHome(process.env.TELEPRESENCE_CERT_ROOT)
202
+ if (fs.existsSync(root)) return root
203
+ }
204
+ const configuredInfra = getCliConfigInfraDir()
205
+ if (configuredInfra) {
206
+ const candidate = path.join(configuredInfra, 'data', 'certificates')
207
+ if (fs.existsSync(candidate)) return candidate
208
+ }
209
+ for (const root of listInfraRootCandidates(cwd)) {
210
+ const candidate = path.join(root, 'data', 'certificates')
211
+ if (fs.existsSync(candidate)) return candidate
212
+ }
213
+ return null
214
+ }
215
+
216
+ function syncTlsForLocalIntercept(cwd) {
217
+ const certRoot = resolveCertificatesRoot(cwd)
218
+ if (!certRoot) {
219
+ console.error('Skipping local TLS sync (set TELEPRESENCE_CERT_ROOT or xry config infra for make tls-copy-from-host)')
220
+ return
221
+ }
222
+ const services = path.join(certRoot, 'services')
223
+ const rootCa = path.join(certRoot, 'root')
224
+ if (!fs.existsSync(rootCa) || !fs.existsSync(services)) {
225
+ console.error(`Missing ${certRoot} — run: make tls-copy-from-host (infra repo)`)
226
+ process.exit(1)
227
+ }
228
+ const dest = process.env.TELEPRESENCE_TLS_DIR || '/etc/tls/infra'
229
+ if (!fs.existsSync(dest)) {
230
+ console.error(`Ensuring ${dest} (may ask sudo once)...`)
231
+ execSync(`sudo mkdir -p "${dest}" && sudo chown "$(id -u):$(id -g)" "${dest}" && chmod 755 "${dest}"`, {
232
+ shell: true,
233
+ stdio: 'inherit',
234
+ })
235
+ }
236
+ const copy = (destName, src) => {
237
+ if (!fs.existsSync(src)) {
238
+ console.error(`Missing: ${src} — run: make tls-copy-from-host`)
239
+ process.exit(1)
240
+ }
241
+ fs.copyFileSync(src, path.join(dest, destName))
242
+ console.log(` ${path.join(dest, destName)} ← ${src}`)
243
+ }
244
+ console.log(`TLS from ${certRoot} → ${dest}`)
245
+ copy('ca.crt', path.join(rootCa, 'ca.crt'))
246
+ copy('mongodb.pem', path.join(services, 'mongodb', 'mongodb.pem'))
247
+ copy('mongodb.crt', path.join(services, 'mongodb', 'mongodb.crt'))
248
+ copy('redis.pem', path.join(services, 'redis', 'redis.pem'))
249
+ copy('redis.crt', path.join(services, 'redis', 'redis.crt'))
250
+ copy('kafka.crt', path.join(services, 'kafka', 'kafka.crt'))
251
+ copy('truststore.jks', path.join(services, 'kafka', 'truststore.jks'))
252
+ console.log(`TLS ready at ${dest}`)
253
+ }
254
+
255
+ function preflightReadyDeployment({ deploy, ns, cwd }) {
256
+ if (!commandExists('kubectl')) {
257
+ console.error('Warning: kubectl not in PATH — skipping Ready pod preflight.')
258
+ return
259
+ }
260
+ const kubeconfig = resolveKubeconfig(cwd)
261
+ if (!kubeconfig) {
262
+ console.error('Warning: kubeconfig not found — skipping Ready pod preflight.')
263
+ return
264
+ }
265
+ const env = { ...process.env, KUBECONFIG: kubeconfig }
266
+ let ready = '0'
267
+ try {
268
+ ready = execSync(`kubectl get deployment "${deploy}" -n "${ns}" -o jsonpath='{.status.readyReplicas}'`, {
269
+ encoding: 'utf8',
270
+ env,
271
+ }).trim()
272
+ } catch {
273
+ ready = '0'
274
+ }
275
+ const readyNum = /^\d+$/.test(ready) ? Number(ready) : 0
276
+ if (readyNum >= 1) return
277
+ console.error(
278
+ `Intercept blocked: Deployment "${deploy}" in namespace "${ns}" has no Ready pod (readyReplicas=${readyNum}).`,
279
+ )
280
+ console.error('Telepresence HTTP intercept needs a healthy cluster pod to host the node-agent.')
281
+ try {
282
+ execSync(`kubectl get deployment "${deploy}" -n "${ns}"`, { stdio: 'inherit', env })
283
+ execSync(`kubectl get pods -n "${ns}" -l app=${deploy}`, { stdio: 'inherit', env })
284
+ } catch {
285
+ /* ignore */
286
+ }
287
+ process.exit(1)
288
+ }
289
+
290
+ export function runTelepresenceIntercept({
291
+ deploy,
292
+ ns = 'dev',
293
+ port = '3000',
294
+ containerPort = process.env.TELEPRESENCE_CONTAINER_PORT || '3000',
295
+ envFile,
296
+ localCmd,
297
+ cwd = process.cwd(),
298
+ }) {
299
+ assertNamespaceAllowed(ns)
300
+ ensureTelepresenceOnPath()
301
+
302
+ if (!isTelepresenceConnected(ns)) {
303
+ console.log(`Telepresence not connected — connecting (namespace=${ns})...`)
304
+ const code = connectTelepresence({ ns, cwd })
305
+ if (code !== 0) process.exit(code)
306
+ if (!isTelepresenceConnected(ns)) {
307
+ console.error(`Connect failed. Run: xry tp connect --ns ${ns}`)
308
+ process.exit(1)
309
+ }
310
+ console.log('Connected.')
311
+ }
312
+
313
+ preflightReadyDeployment({ deploy, ns, cwd })
314
+ syncTlsForLocalIntercept(cwd)
315
+
316
+ const rawId = process.env.TELEPRESENCE_DEV_ID || process.env.USER || 'dev'
317
+ const devId = process.env.TELEPRESENCE_DEV_ID ? rawId : rawId.replace(/\./g, '-')
318
+ const header = process.env.TELEPRESENCE_INTERCEPT_HEADER || process.env.TELEPRESENCE_DEV_HEADER || 'x-intercept-who'
319
+ const absEnvFile = path.resolve(cwd, envFile)
320
+
321
+ console.log(
322
+ `Intercept ${deploy} (ns=${ns}) — local :${port} <- pod :${containerPort} | header ${header}: ${devId}`,
323
+ )
324
+ console.log('Cluster pod keeps running for traffic without this header.')
325
+ console.log(`Test: curl -H "${header}: ${devId}" http://${deploy}-service.${ns}:${port}/health`)
326
+
327
+ const tpArgs = [
328
+ 'intercept',
329
+ deploy,
330
+ '--namespace',
331
+ ns,
332
+ '--mount',
333
+ 'false',
334
+ '--http-header',
335
+ `${header}=${devId}`,
336
+ '--port',
337
+ `${port}:${containerPort}`,
338
+ '--env-file',
339
+ absEnvFile,
340
+ ]
341
+
342
+ if (localCmd?.length) {
343
+ const result = spawnSync('telepresence', [...tpArgs, '--', ...localCmd], { stdio: 'inherit', cwd, env: process.env })
344
+ process.exit(result.status ?? 1)
345
+ }
346
+
347
+ const result = spawnSync('telepresence', tpArgs, { stdio: 'inherit', cwd, env: process.env })
348
+ process.exit(result.status ?? 1)
349
+ }
@@ -19,6 +19,8 @@ type PreflightRow = {
19
19
  result: 'OK' | 'UNREACHABLE' | 'CONFIG' | 'INVALID';
20
20
  detail?: string;
21
21
  };
22
+ /** True only inside a real pod (not Telepresence env dump on the laptop). */
23
+ export declare function isInKubernetesPod(): boolean;
22
24
  export type PreflightReportMeta = {
23
25
  atUtc: string;
24
26
  runtime: string;
@@ -43,7 +45,7 @@ export declare class InfraPreflightFailed extends Error {
43
45
  /** Strict fail: one report on stderr, then InfraPreflightFailed (no duplicate stack). */
44
46
  export declare function abortInfraPreflight(report: string): never;
45
47
  export declare function resolveProbeTimeoutMs(): number;
46
- /** Default: fail-fast. Set STRICT_INFRA_PREFLIGHT=0|false|no|off to warn only (local edge cases). */
48
+ /** Default: fail-fast in cluster and plain local dev; lenient for Telepresence intercept env on laptop. */
47
49
  export declare function isStrictInfraPreflight(): boolean;
48
50
  /** Default: same fast TCP probe everywhere (local, Docker, Kubernetes). Opt out: INFRA_PREFLIGHT_TCP=0. */
49
51
  export declare function shouldTcpProbeInfraPreflight(): boolean;
@@ -8,7 +8,22 @@ import { isInfraLoaderEnabled, resolveLoaderBootPlan, } from '../../../utils/hel
8
8
  import { resolveTmpRuntimeConfigs } from '../../../utils/helpers/tmp/tmp-schema.js';
9
9
  import { getTmpSnapshot } from '../../../utils/helpers/tmp/tmp-loader.js';
10
10
  const DEFAULT_PROBE_TIMEOUT_MS = 500;
11
+ const TELEPRESENCE_LOCAL_PROBE_TIMEOUT_MS = 2000;
11
12
  const RULE = '─'.repeat(72);
13
+ /** True only inside a real pod (not Telepresence env dump on the laptop). */
14
+ export function isInKubernetesPod() {
15
+ if (!(process.env.KUBERNETES_SERVICE_HOST ?? '').trim())
16
+ return false;
17
+ try {
18
+ return fs.existsSync('/var/run/secrets/kubernetes.io/serviceaccount/token');
19
+ }
20
+ catch {
21
+ return false;
22
+ }
23
+ }
24
+ function isTelepresenceLocalEnv() {
25
+ return Boolean((process.env.KUBERNETES_SERVICE_HOST ?? '').trim()) && !isInKubernetesPod();
26
+ }
12
27
  function resolveInstalledCoreVersion() {
13
28
  try {
14
29
  const pkgPath = require.resolve('@xrystal/core/package.json');
@@ -20,12 +35,18 @@ function resolveInstalledCoreVersion() {
20
35
  }
21
36
  }
22
37
  function resolveRuntimeLabel() {
23
- if (process.env.KUBERNETES_SERVICE_HOST) {
38
+ if (isInKubernetesPod()) {
24
39
  return {
25
40
  label: 'kubernetes',
26
41
  detect: 'KUBERNETES_SERVICE_HOST (kubelet-injected)',
27
42
  };
28
43
  }
44
+ if (isTelepresenceLocalEnv()) {
45
+ return {
46
+ label: 'local-telepresence',
47
+ detect: 'KUBERNETES_SERVICE_HOST from intercept env-file (not in pod)',
48
+ };
49
+ }
29
50
  try {
30
51
  if (fs.existsSync('/.dockerenv')) {
31
52
  return { label: 'docker', detect: '/.dockerenv' };
@@ -68,20 +89,27 @@ export function abortInfraPreflight(report) {
68
89
  }
69
90
  export function resolveProbeTimeoutMs() {
70
91
  const raw = (process.env.INFRA_PREFLIGHT_TIMEOUT_MS ?? '').trim();
71
- if (!raw)
92
+ if (!raw) {
93
+ if (isTelepresenceLocalEnv())
94
+ return TELEPRESENCE_LOCAL_PROBE_TIMEOUT_MS;
72
95
  return DEFAULT_PROBE_TIMEOUT_MS;
96
+ }
73
97
  const n = Number.parseInt(raw, 10);
74
98
  if (!Number.isFinite(n) || n < 100)
75
99
  return DEFAULT_PROBE_TIMEOUT_MS;
76
100
  return Math.min(n, 5000);
77
101
  }
78
- /** Default: fail-fast. Set STRICT_INFRA_PREFLIGHT=0|false|no|off to warn only (local edge cases). */
102
+ /** Default: fail-fast in cluster and plain local dev; lenient for Telepresence intercept env on laptop. */
79
103
  export function isStrictInfraPreflight() {
80
104
  const raw = (process.env.STRICT_INFRA_PREFLIGHT ?? '').trim().toLowerCase();
81
- if (!raw)
105
+ if (raw === '1' || raw === 'true' || raw === 'yes' || raw === 'on')
82
106
  return true;
83
107
  if (raw === '0' || raw === 'false' || raw === 'no' || raw === 'off')
84
108
  return false;
109
+ if (isInKubernetesPod())
110
+ return true;
111
+ if (isTelepresenceLocalEnv())
112
+ return false;
85
113
  return true;
86
114
  }
87
115
  /** Default: same fast TCP probe everywhere (local, Docker, Kubernetes). Opt out: INFRA_PREFLIGHT_TCP=0. */
@@ -92,7 +120,10 @@ export function shouldTcpProbeInfraPreflight() {
92
120
  return true;
93
121
  }
94
122
  function runtimeContextHint() {
95
- if (process.env.KUBERNETES_SERVICE_HOST) {
123
+ if (isTelepresenceLocalEnv()) {
124
+ return 'Telepresence local: env from pod; TCP from laptop (Tailscale/VPN). Lenient preflight default — set STRICT_INFRA_PREFLIGHT=1 to fail-fast.';
125
+ }
126
+ if (isInKubernetesPod()) {
96
127
  if (!shouldTcpProbeInfraPreflight()) {
97
128
  return 'Kubernetes: TCP preflight disabled (INFRA_PREFLIGHT_TCP=0). Config-only check.';
98
129
  }