@dooer/dooer-test-env 1.7.0 → 1.8.1

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.
@@ -5,6 +5,7 @@ const yaml = require('js-yaml')
5
5
  const chalk = require('chalk')
6
6
  const rt = require('../runtime')
7
7
  const discovery = require('../discovery/client')
8
+ const bankid = require('../bankid')
8
9
  const { imageFor } = require('../compose/manifests')
9
10
 
10
11
  // Per-service control in a running env. `local`/`unlocal`/`deploy` update the discovery router so peers
@@ -21,8 +22,17 @@ function localEnv(name, port) {
21
22
  } catch (_) {
22
23
  /* compose not generated yet — fall back to the minimum below */
23
24
  }
25
+ // Compose interpolates `${VAR:-default}` when it starts a container; a HOST process would otherwise get
26
+ // the literal string (service-accounts died with `Malformed boolean: "${DOOER_BANK_ID_IS_PRODUCTION:-false}"`).
27
+ // Resolve them the same way compose does, against the host env + the injected bankid values.
28
+ const injected = bankid.loadEnv()
29
+ const interpolate = (v) =>
30
+ String(v).replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)(?::-([^}]*))?\}/g, (_m, key, fallback) => {
31
+ const val = injected[key] !== undefined ? injected[key] : process.env[key]
32
+ return val !== undefined && val !== '' ? val : fallback || ''
33
+ })
24
34
  const rw = (v) =>
25
- String(v)
35
+ interpolate(v)
26
36
  .replace(/\bpostgres:/g, 'localhost:')
27
37
  .replace(/(^|@)postgres\b/g, `$1localhost`)
28
38
  .replace(/\bredis:/g, 'localhost:')
@@ -32,7 +42,9 @@ function localEnv(name, port) {
32
42
  for (const k of Object.keys(env)) env[k] = rw(env[k])
33
43
  // guaranteed minimum wiring (also covers the no-compose fallback)
34
44
  env.DOOER_SQL_HOST = 'localhost'
35
- env.DOOER_SQL_PORT = env.DOOER_SQL_PORT || '5432'
45
+ // Postgres is published on 55432, NOT 5432 — the compose value (5432) is the in-container port, and a
46
+ // dev's brew Postgres usually squats 5432, so a host process would silently talk to the wrong database.
47
+ env.DOOER_SQL_PORT = process.env.DOOER_TEST_ENV_PG_PORT || '55432'
36
48
  env.DOOER_SQL_DATABASE = env.DOOER_SQL_DATABASE || 'dooer'
37
49
  env.DOOER_IS_ONEPLATFORMER = 'false'
38
50
  env.CONSUL_HTTP_ADDR = 'localhost:8500'
@@ -40,6 +52,11 @@ function localEnv(name, port) {
40
52
  env.DOOER_SERVICE_NAME = env.DOOER_SERVICE_NAME || name
41
53
  env.DOOER_ENVIRONMENT_NAME = env.DOOER_ENVIRONMENT_NAME || 'local'
42
54
  env.NODE_ENV = env.NODE_ENV || 'development'
55
+ // SELF-calls: the router advertises this service as host.docker.internal:<port> so CONTAINERS can reach
56
+ // the host process — but that name does not resolve ON the host, so the process fails calling itself
57
+ // (service-accounts → /api/v1/token-invalidation/all → ENOTFOUND, which broke every HQ navigation query).
58
+ // @dooer/service checks DOOER_HOST_<NAME> before Consul, so point the service at its own localhost port.
59
+ env[`DOOER_HOST_${name.toUpperCase().replace(/-/g, '_')}`] = `localhost:${port}`
43
60
  return env
44
61
  }
45
62
 
@@ -133,7 +133,22 @@ Optional:
133
133
  function sh(file, args) {
134
134
  return execFileSync(file, args, { encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 }).trim()
135
135
  }
136
+ // The LOCAL test env is addressed as the pseudo-namespace `local`: the docker-compose Postgres published on
137
+ // 55432, and MinIO standing in for Ceph. Lets `customer copy --target-namespace local` pull a real org out
138
+ // of staging/production into the local stack. (Jimmy 2026-09-03.)
139
+ const LOCAL_NAMESPACE = 'local'
140
+ const isLocalNamespace = (namespace) => namespace === LOCAL_NAMESPACE
141
+
136
142
  function connInfo(namespace) {
143
+ if (isLocalNamespace(namespace)) {
144
+ return {
145
+ host: 'localhost',
146
+ port: Number(process.env.DOOER_TEST_ENV_PG_PORT || 55432),
147
+ user: 'dooer',
148
+ password: 'dooer',
149
+ database: 'dooer',
150
+ }
151
+ }
137
152
  const clusterIP = sh('kubectl', ['get', 'svc', 'dooer-database', '-n', namespace, '-o', 'jsonpath={.spec.clusterIP}'])
138
153
  const b64 = sh('kubectl', [
139
154
  'get',
@@ -236,6 +251,21 @@ async function withRetry(fn, { tries = 6, label = 'op' } = {}) {
236
251
  // from the SOURCE env bucket to the TARGET env bucket at its NEW key (= the copied fileData id), so the
237
252
  // copy owns its own files. Endpoint/bucket/credentials are read from the file-storage pod per namespace.
238
253
  function s3Config(namespace) {
254
+ if (isLocalNamespace(namespace)) {
255
+ // local MinIO — the bucket `minio-init` provisions (see lib/compose/generate.js S3_BUCKETS).
256
+ return {
257
+ primary: {
258
+ bucket: 'file-storage-bucket',
259
+ client: new S3Client({
260
+ endpoint: process.env.DOOER_TEST_ENV_S3 || 'http://localhost:9000',
261
+ region: 'us-east-1',
262
+ forcePathStyle: true,
263
+ credentials: { accessKeyId: 'minioadmin', secretAccessKey: 'minioadmin' },
264
+ }),
265
+ },
266
+ fallback: null,
267
+ }
268
+ }
239
269
  const pods = sh('kubectl', [
240
270
  'get',
241
271
  'pods',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dooer/dooer-test-env",
3
- "version": "1.7.0",
3
+ "version": "1.8.1",
4
4
  "description": "Run the whole Dooer backend locally (staging DB minus customers), copy/purge customers between environments, and shred — one CLI.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": "Dooer/cli-dooer-test-env",