@antelopejs/dms 0.25.1 → 0.25.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,37 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.25.3
4
+
5
+ [compare changes](https://github.com/AntelopeJS/dms/compare/v0.25.2...v0.25.3)
6
+
7
+ ### 🩹 Fixes
8
+
9
+ - **dms:** Start a journey backend outside the ephemeral range, and fail its wait when it falls back ([#1308](https://github.com/AntelopeJS/dms/pull/1308))
10
+
11
+ ### ❤️ Contributors
12
+
13
+ - Antony Rizzitelli
14
+
15
+ ## v0.25.2
16
+
17
+ [compare changes](https://github.com/AntelopeJS/dms/compare/v0.25.1...v0.25.2)
18
+
19
+ ### 🔥 Performance
20
+
21
+ - **dms:** Start the e2e kit's runs together ([#1306](https://github.com/AntelopeJS/dms/pull/1306))
22
+
23
+ ### 🩹 Fixes
24
+
25
+ - **dms:** Key a symlinked scope folder of the e2e build key entry by entry ([#1307](https://github.com/AntelopeJS/dms/pull/1307))
26
+
27
+ ### 🏡 Chore
28
+
29
+ - **deps:** Update @antelopejs/tooling-configs to 0.10.14 and sync ([#1305](https://github.com/AntelopeJS/dms/pull/1305))
30
+
31
+ ### ❤️ Contributors
32
+
33
+ - Antony Rizzitelli
34
+
3
35
  ## v0.25.1
4
36
 
5
37
  [compare changes](https://github.com/AntelopeJS/dms/compare/v0.25.0...v0.25.1)
@@ -1,5 +1,6 @@
1
1
  /**
2
- * Asks the kernel for a free loopback port outside `exclude`.
2
+ * Asks the kernel for a free loopback port outside `exclude` that this
3
+ * process has not given before.
3
4
  *
4
5
  * @param {Iterable<number>} [exclude] Skipped ports
5
6
  * @returns {Promise<number>} The port
@@ -14,11 +15,11 @@ export function freePort(exclude?: Iterable<number>): Promise<number>;
14
15
  */
15
16
  export function isRestartablePort(port: number): port is RestartablePort;
16
17
  /**
17
- * A free loopback port outside the ephemeral range and `exclude` for a server
18
- * that must listen on the same port again after it restarts. No outgoing
19
- * connection takes such a port as its source port, so none can hold it in
20
- * TIME_WAIT and make that listen fail with `EADDRINUSE`, as a port from
21
- * {@link freePort} can be held.
18
+ * A free loopback port outside the ephemeral range and `exclude`, which this
19
+ * process has not given before, for a server that must listen on the same
20
+ * port again after it restarts. No outgoing connection takes such a port as
21
+ * its source port, so none can hold it in TIME_WAIT and make that listen
22
+ * fail with `EADDRINUSE`, as a port from {@link freePort} can be held.
22
23
  *
23
24
  * @param {Iterable<number>} [exclude] Skipped ports
24
25
  * @returns {Promise<RestartablePort>} The port
@@ -47,7 +47,9 @@ export function ensureApi(state: import("./run-state.mjs").RunState): Promise<vo
47
47
  export function runBackendMode(state: RunState): BackendMode;
48
48
  /**
49
49
  * Starts a backend of the run on `database` and a free loopback port of its
50
- * own, from the run's build or `build`, without waiting for it, and records
50
+ * own outside the kernel's ephemeral range, where no other process's
51
+ * `listen(0)` or outgoing connection takes it, from the run's build or
52
+ * `build`, without waiting for it, and records
51
53
  * it in a file of its own. Its log is named after its database,
52
54
  * `backend_<suffix>.log`, so two backends that run at once write apart; the
53
55
  * first database's is `backend.log`.
@@ -24,28 +24,28 @@ export function targetOf(options: Pick<StartOptions, "playground" | "renderer" |
24
24
  renderer: string | undefined;
25
25
  }>;
26
26
  /**
27
- * Starts the stack of a run: with `prepare`, the journeys config's install
28
- * and build commands first, then the stack on its playground and renderer.
27
+ * Starts the stack of a run on its playground and renderer, the journeys
28
+ * config's commands already run.
29
29
  *
30
30
  * @param {StartOptions} options How to start it
31
+ * @param {import("./timing.mjs").TimingEntry[]} prepared The timings of the commands, which the run records
31
32
  * @param {string} cwd Where the run starts from, which finds the journeys config
32
33
  * @returns {Promise<import("./run-state.mjs").RunState>} The ready run
33
34
  */
34
- export function startStack(options: StartOptions, cwd: string): Promise<import("./run-state.mjs").RunState>;
35
+ export function startStack(options: StartOptions, prepared: import("./timing.mjs").TimingEntry[], cwd: string): Promise<import("./run-state.mjs").RunState>;
35
36
  /**
36
37
  * Starts `count` runs of the checkout's playground, each with its own
37
38
  * playground copy, ports, MongoDB, mail sink, backends and dashboard, for
38
- * the workers of one suite to drive one each. The first runs the journeys
39
- * config's prepare commands as `options` asks; the others start once it is
40
- * ready, together, without them, so their dashboards come from the build
41
- * cache the first one filled. `stop` stops them all, and from the moment
42
- * the first is ready a SIGINT or SIGTERM to this process stops every run
43
- * started so far, then ends the process by that signal.
39
+ * the workers of one suite to drive one each. The journeys config's prepare
40
+ * commands run first, once, as `options` asks; then every run starts at the
41
+ * same time. `stop` stops them all, and from the moment the runs start a
42
+ * SIGINT or SIGTERM to this process stops every run ready so far, then
43
+ * ends the process by that signal.
44
44
  *
45
45
  * @param {RunOptions} options How to start them
46
46
  * @param {number} count How many, at least 1
47
- * @returns {Promise<{ runs: import("./run-state.mjs").RunState[], stop: () => Promise<void> }>} The ready runs, and what stops them
48
- * @throws When a run fails to start; every run it started is stopped first
47
+ * @returns {Promise<{ runs: import("./run-state.mjs").RunState[], stop: () => Promise<void> }>} The ready runs, one per worker, and what stops them
48
+ * @throws When a run fails to start; every run that started is stopped first
49
49
  */
50
50
  export function startRuns(options: RunOptions, count: number): Promise<{
51
51
  runs: import("./run-state.mjs").RunState[];
@@ -6,18 +6,20 @@
6
6
  */
7
7
  export function probe(url: string): Promise<number | null>;
8
8
  /**
9
- * Polls `url` until it answers 200, the process exits or the timeout passes.
9
+ * Polls `url` until it answers 200, the process exits, `refused` tells why
10
+ * it never will, or the timeout passes.
10
11
  *
11
12
  * @param {string} url The readiness URL
12
13
  * @param {{ pid: number, log: string }} record The process that must serve it
13
14
  * @param {number} timeoutMs How long to wait
15
+ * @param {Refusal} [refused] Read at every poll
14
16
  * @returns {Promise<void>} Resolves once ready
15
- * @throws When the process exits first or the timeout passes, naming its log
17
+ * @throws When the process exits first, `refused` tells a reason or the timeout passes, naming its log
16
18
  */
17
19
  export function waitForOk(url: string, record: {
18
20
  pid: number;
19
21
  log: string;
20
- }, timeoutMs: number): Promise<void>;
22
+ }, timeoutMs: number, refused?: Refusal): Promise<void>;
21
23
  /**
22
24
  * Polls a loopback port until it accepts a connection, the process exits or
23
25
  * the timeout passes.
@@ -40,21 +42,22 @@ export function waitForPort(port: number, record: {
40
42
  * @param {number} port The port
41
43
  * @param {{ name: string, pid: number, log: string }} record The process that must listen
42
44
  * @param {number} timeoutMs How long to wait
45
+ * @param {Refusal} [refused] Read at every poll
43
46
  * @returns {Promise<void>} Resolves once the process listens
44
- * @throws When it exits first (the port was taken) or the timeout passes
47
+ * @throws When it exits first (the port was taken), `refused` tells a reason or the timeout passes
45
48
  */
46
49
  export function waitForOwnPort(port: number, record: {
47
50
  name: string;
48
51
  pid: number;
49
52
  log: string;
50
- }, timeoutMs: number): Promise<void>;
53
+ }, timeoutMs: number, refused?: Refusal): Promise<void>;
51
54
  /**
52
55
  * Waits until a backend listens on its own port and answers
53
56
  * `/api/onboarding/informations` there.
54
57
  *
55
58
  * @param {import("./run-state.mjs").ServerRecord} backend The backend
56
59
  * @returns {Promise<void>} Resolves once it answers 200
57
- * @throws When it exits first, another process holds its port or the timeout passes, naming its log
60
+ * @throws When it exits first, another process holds its port, its log says it listens on another port, or the timeout passes, naming its log
58
61
  */
59
62
  export function waitForBackend(backend: import("./run-state.mjs").ServerRecord): Promise<void>;
60
63
  /**
@@ -67,3 +70,7 @@ export function waitForBackend(backend: import("./run-state.mjs").ServerRecord):
67
70
  * @throws When it exits first, another process holds its port or the timeout passes, naming its log
68
71
  */
69
72
  export function waitForDashboard(state: Pick<import("./run-state.mjs").RunState, "webPort" | "webUrl">, frontend: import("./run-state.mjs").ProcessRecord): Promise<void>;
73
+ /**
74
+ * Why a wait cannot succeed any more, or `null` while it can
75
+ */
76
+ export type Refusal = () => string | null;
package/e2e/build-key.mjs CHANGED
@@ -6,6 +6,7 @@ import {
6
6
  readFileSync,
7
7
  readlinkSync,
8
8
  realpathSync,
9
+ statSync,
9
10
  } from "node:fs";
10
11
  import { basename, dirname, isAbsolute, join, relative, sep } from "node:path";
11
12
  import { isRecord } from "./json.mjs";
@@ -168,12 +169,12 @@ function hashFolder(folder, names, walk = SOURCES) {
168
169
 
169
170
  /**
170
171
  * Keys an entry at the top of a `node_modules` above the workspace, or in a
171
- * scope folder there. A scope folder is keyed entry by entry. A link is keyed
172
- * by its target, and, when the target is not a package of pnpm's virtual
173
- * store (a `link:` or `workspace:` package), by the content hash of the
174
- * folder it resolves to, its installs left out, read once however many links
175
- * reach it. A package copied in is keyed by its files, its own
176
- * `node_modules` included.
172
+ * scope folder there. A scope folder, or a link to one, is keyed entry by
173
+ * entry. Any other link is keyed by its target, and, when the target is not
174
+ * a package of pnpm's virtual store (a `link:` or `workspace:` package), by
175
+ * the content hash of the folder it resolves to, its installs left out,
176
+ * read once however many links reach it. A package copied in is keyed by
177
+ * its files, its own `node_modules` included.
177
178
  *
178
179
  * @param {import("node:crypto").Hash} hash
179
180
  * @param {string} path The entry
@@ -181,7 +182,7 @@ function hashFolder(folder, names, walk = SOURCES) {
181
182
  */
182
183
  function hashInstalled(hash, path, outside) {
183
184
  const stat = lstatSync(path, { throwIfNoEntry: false });
184
- if (stat?.isDirectory() && basename(path).startsWith("@")) {
185
+ if (isScope(path)) {
185
186
  hash.update("scope\0");
186
187
  for (const name of readdirSync(path).sort()) {
187
188
  hash.update(`${name}\0`);
@@ -208,6 +209,19 @@ function hashInstalled(hash, path, outside) {
208
209
  hash.update(`linked ${digest}\0`);
209
210
  }
210
211
 
212
+ /**
213
+ * @param {string} path An entry of a `node_modules`
214
+ * @returns {boolean} Whether it is a scope folder, or a link to one
215
+ */
216
+ function isScope(path) {
217
+ if (!basename(path).startsWith("@")) return false;
218
+ try {
219
+ return statSync(path).isDirectory();
220
+ } catch {
221
+ return false;
222
+ }
223
+ }
224
+
211
225
  /**
212
226
  * @param {string} path A real path
213
227
  * @returns {boolean}
@@ -228,7 +242,7 @@ function packagesIn(modules) {
228
242
  .filter((name) => !name.startsWith("."))
229
243
  .flatMap((name) => {
230
244
  const path = join(modules, name);
231
- return name.startsWith("@") && lstatSync(path).isDirectory()
245
+ return isScope(path)
232
246
  ? readdirSync(path).map((scoped) => join(path, scoped))
233
247
  : [path];
234
248
  });
package/e2e/processes.mjs CHANGED
@@ -41,8 +41,22 @@ function isTcpAddress(address) {
41
41
  return typeof address === "object" && address !== null;
42
42
  }
43
43
 
44
+ /** Every port {@link freePort} or {@link restartablePort} gave in this process, which neither gives again: runs that start at the same time each pick a port before any of them listens on it. */
45
+ const handedOut = new Set();
46
+
47
+ /**
48
+ * @template {number} P
49
+ * @param {P} port A port to give
50
+ * @returns {P} The port, never to be given again in this process
51
+ */
52
+ function handOut(port) {
53
+ handedOut.add(port);
54
+ return port;
55
+ }
56
+
44
57
  /**
45
- * Asks the kernel for a free loopback port outside `exclude`.
58
+ * Asks the kernel for a free loopback port outside `exclude` that this
59
+ * process has not given before.
46
60
  *
47
61
  * @param {Iterable<number>} [exclude] Skipped ports
48
62
  * @returns {Promise<number>} The port
@@ -51,7 +65,7 @@ export async function freePort(exclude = []) {
51
65
  const skip = new Set(exclude);
52
66
  for (let n = 0; n < RESTARTABLE_PORT_ATTEMPTS; n += 1) {
53
67
  const port = await kernelPort();
54
- if (!skip.has(port)) return port;
68
+ if (!skip.has(port) && !handedOut.has(port)) return handOut(port);
55
69
  }
56
70
  throw new Error("no free port");
57
71
  }
@@ -115,11 +129,11 @@ export function isRestartablePort(port) {
115
129
  }
116
130
 
117
131
  /**
118
- * A free loopback port outside the ephemeral range and `exclude` for a server
119
- * that must listen on the same port again after it restarts. No outgoing
120
- * connection takes such a port as its source port, so none can hold it in
121
- * TIME_WAIT and make that listen fail with `EADDRINUSE`, as a port from
122
- * {@link freePort} can be held.
132
+ * A free loopback port outside the ephemeral range and `exclude`, which this
133
+ * process has not given before, for a server that must listen on the same
134
+ * port again after it restarts. No outgoing connection takes such a port as
135
+ * its source port, so none can hold it in TIME_WAIT and make that listen
136
+ * fail with `EADDRINUSE`, as a port from {@link freePort} can be held.
123
137
  *
124
138
  * @param {Iterable<number>} [exclude] Skipped ports
125
139
  * @returns {Promise<RestartablePort>} The port
@@ -141,9 +155,10 @@ export async function restartablePort(exclude = []) {
141
155
  if (
142
156
  isRestartablePort(port) &&
143
157
  !excluded.has(port) &&
144
- (await canListen(port))
158
+ (await canListen(port)) &&
159
+ !handedOut.has(port)
145
160
  )
146
- return port;
161
+ return handOut(port);
147
162
  }
148
163
  throw new Error("no loopback port outside the ephemeral range is free");
149
164
  }
package/e2e/stack.mjs CHANGED
@@ -16,7 +16,6 @@ import { currentNamespaces, isSameProcess } from "./identity.mjs";
16
16
  import { reservedPorts } from "./reserved-ports.mjs";
17
17
  import { dropRunDatabases, startMongod } from "./mongo.mjs";
18
18
  import {
19
- freePort,
20
19
  restartablePort,
21
20
  runToEnd,
22
21
  startDetached,
@@ -265,7 +264,9 @@ const BACKEND_ARGS = {
265
264
 
266
265
  /**
267
266
  * Starts a backend of the run on `database` and a free loopback port of its
268
- * own, from the run's build or `build`, without waiting for it, and records
267
+ * own outside the kernel's ephemeral range, where no other process's
268
+ * `listen(0)` or outgoing connection takes it, from the run's build or
269
+ * `build`, without waiting for it, and records
269
270
  * it in a file of its own. Its log is named after its database,
270
271
  * `backend_<suffix>.log`, so two backends that run at once write apart; the
271
272
  * first database's is `backend.log`.
@@ -289,7 +290,7 @@ export async function launchBackend(
289
290
  mode = runBackendMode(state),
290
291
  ) {
291
292
  const { ajs } = cliPaths(build?.playground ?? state.playground);
292
- const port = await freePort(reservedPorts(state));
293
+ const port = await restartablePort(reservedPorts(state));
293
294
  const launch = spec(
294
295
  state,
295
296
  `backend${database.slice(state.databasePrefix.length)}`,
package/e2e/start.mjs CHANGED
@@ -49,21 +49,30 @@ export async function targetOf(options, cwd) {
49
49
  }
50
50
 
51
51
  /**
52
- * Starts the stack of a run: with `prepare`, the journeys config's install
53
- * and build commands first, then the stack on its playground and renderer.
52
+ * Runs the journeys config's install and build commands when `options`
53
+ * asks for them.
54
+ *
55
+ * @param {StartOptions} options How the runs start
56
+ * @param {string} cwd Where the runs start from, which finds the journeys config
57
+ * @returns {Promise<import("./timing.mjs").TimingEntry[]>} The timings of the commands, none when it ran nothing
58
+ */
59
+ async function prepareRuns(options, cwd) {
60
+ if (!options.prepare) return [];
61
+ const config = await loadSuiteConfig(cwd, options.config);
62
+ return runPrepare(config, config.repo);
63
+ }
64
+
65
+ /**
66
+ * Starts the stack of a run on its playground and renderer, the journeys
67
+ * config's commands already run.
54
68
  *
55
69
  * @param {StartOptions} options How to start it
70
+ * @param {import("./timing.mjs").TimingEntry[]} prepared The timings of the commands, which the run records
56
71
  * @param {string} cwd Where the run starts from, which finds the journeys config
57
72
  * @returns {Promise<import("./run-state.mjs").RunState>} The ready run
58
73
  */
59
- export async function startStack(options, cwd) {
60
- const { prepare, config: journeysConfig, ...upOptions } = options;
61
- /** @type {import("./timing.mjs").TimingEntry[]} */
62
- let prepared = [];
63
- if (prepare) {
64
- const config = await loadSuiteConfig(cwd, journeysConfig);
65
- prepared = runPrepare(config, config.repo);
66
- }
74
+ export async function startStack(options, prepared, cwd) {
75
+ const { prepare: _prepare, config: _journeysConfig, ...upOptions } = options;
67
76
  const state = await up({
68
77
  ...upOptions,
69
78
  ...(await targetOf(options, cwd)),
@@ -110,22 +119,23 @@ async function stopRuns(dirs) {
110
119
  /**
111
120
  * Starts `count` runs of the checkout's playground, each with its own
112
121
  * playground copy, ports, MongoDB, mail sink, backends and dashboard, for
113
- * the workers of one suite to drive one each. The first runs the journeys
114
- * config's prepare commands as `options` asks; the others start once it is
115
- * ready, together, without them, so their dashboards come from the build
116
- * cache the first one filled. `stop` stops them all, and from the moment
117
- * the first is ready a SIGINT or SIGTERM to this process stops every run
118
- * started so far, then ends the process by that signal.
122
+ * the workers of one suite to drive one each. The journeys config's prepare
123
+ * commands run first, once, as `options` asks; then every run starts at the
124
+ * same time. `stop` stops them all, and from the moment the runs start a
125
+ * SIGINT or SIGTERM to this process stops every run ready so far, then
126
+ * ends the process by that signal.
119
127
  *
120
128
  * @param {RunOptions} options How to start them
121
129
  * @param {number} count How many, at least 1
122
- * @returns {Promise<{ runs: import("./run-state.mjs").RunState[], stop: () => Promise<void> }>} The ready runs, and what stops them
123
- * @throws When a run fails to start; every run it started is stopped first
130
+ * @returns {Promise<{ runs: import("./run-state.mjs").RunState[], stop: () => Promise<void> }>} The ready runs, one per worker, and what stops them
131
+ * @throws When a run fails to start; every run that started is stopped first
124
132
  */
125
133
  export async function startRuns(options, count) {
126
134
  const cwd = process.cwd();
127
- const first = await startStack(startOptions(options, cwd), cwd);
128
- const dirs = [first.dir];
135
+ const start = startOptions(options, cwd);
136
+ const prepared = await prepareRuns(start, cwd);
137
+ /** @type {string[]} */
138
+ const dirs = [];
129
139
  const onSignal = (/** @type {NodeJS.Signals} */ signal) => {
130
140
  release();
131
141
  const reraise = () => process.kill(process.pid, signal);
@@ -135,29 +145,23 @@ export async function startRuns(options, count) {
135
145
  for (const signal of STOP_SIGNALS) process.off(signal, onSignal);
136
146
  };
137
147
  for (const signal of STOP_SIGNALS) process.on(signal, onSignal);
138
- const others = await Promise.allSettled(
139
- Array.from({ length: count - 1 }, async () => {
140
- const run = await startStack(
141
- startOptions({ ...options, prepare: false }, cwd),
142
- cwd,
143
- );
148
+ const started = await Promise.allSettled(
149
+ Array.from({ length: count }, async (_, index) => {
150
+ const run = await startStack(start, index === 0 ? prepared : [], cwd);
144
151
  dirs.push(run.dir);
145
152
  return run;
146
153
  }),
147
154
  );
148
- const failed = others.find((other) => other.status === "rejected");
155
+ const failed = started.find((run) => run.status === "rejected");
149
156
  if (failed) {
150
157
  release();
151
158
  await stopRuns(dirs);
152
159
  throw failed.reason;
153
160
  }
154
161
  return {
155
- runs: [
156
- first,
157
- ...others.flatMap((other) =>
158
- other.status === "fulfilled" ? [other.value] : [],
159
- ),
160
- ],
162
+ runs: started.flatMap((run) =>
163
+ run.status === "fulfilled" ? [run.value] : [],
164
+ ),
161
165
  stop: () => {
162
166
  release();
163
167
  return stopRuns(dirs);
package/e2e/waits.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ import { readFileSync } from "node:fs";
1
2
  import { createConnection } from "node:net";
2
3
  import { setTimeout as sleep } from "node:timers/promises";
3
4
  import { isAlive } from "./identity.mjs";
@@ -27,20 +28,31 @@ export async function probe(url) {
27
28
  }
28
29
 
29
30
  /**
30
- * Polls `url` until it answers 200, the process exits or the timeout passes.
31
+ * @typedef {() => string | null} Refusal Why a wait cannot succeed any more, or `null` while it can
32
+ */
33
+
34
+ /** @type {Refusal} */
35
+ const NEVER = () => null;
36
+
37
+ /**
38
+ * Polls `url` until it answers 200, the process exits, `refused` tells why
39
+ * it never will, or the timeout passes.
31
40
  *
32
41
  * @param {string} url The readiness URL
33
42
  * @param {{ pid: number, log: string }} record The process that must serve it
34
43
  * @param {number} timeoutMs How long to wait
44
+ * @param {Refusal} [refused] Read at every poll
35
45
  * @returns {Promise<void>} Resolves once ready
36
- * @throws When the process exits first or the timeout passes, naming its log
46
+ * @throws When the process exits first, `refused` tells a reason or the timeout passes, naming its log
37
47
  */
38
- export async function waitForOk(url, record, timeoutMs) {
48
+ export async function waitForOk(url, record, timeoutMs, refused = NEVER) {
39
49
  const deadline = Date.now() + timeoutMs;
40
50
  while (Date.now() < deadline) {
41
51
  if (!isAlive(record.pid)) {
42
52
  throw new Error(`${url}: the process exited first; see ${record.log}`);
43
53
  }
54
+ const reason = refused();
55
+ if (reason !== null) throw new Error(reason);
44
56
  if ((await probe(url)) === 200) return;
45
57
  await sleep(READY_POLL_MS);
46
58
  }
@@ -90,15 +102,18 @@ export async function waitForPort(port, record, timeoutMs) {
90
102
  * @param {number} port The port
91
103
  * @param {{ name: string, pid: number, log: string }} record The process that must listen
92
104
  * @param {number} timeoutMs How long to wait
105
+ * @param {Refusal} [refused] Read at every poll
93
106
  * @returns {Promise<void>} Resolves once the process listens
94
- * @throws When it exits first (the port was taken) or the timeout passes
107
+ * @throws When it exits first (the port was taken), `refused` tells a reason or the timeout passes
95
108
  */
96
- export async function waitForOwnPort(port, record, timeoutMs) {
109
+ export async function waitForOwnPort(port, record, timeoutMs, refused = NEVER) {
97
110
  if (listenersOf(port) === null) return waitForPort(port, record, timeoutMs);
98
111
  const deadline = Date.now() + timeoutMs;
99
112
  while (Date.now() < deadline && isAlive(record.pid)) {
100
113
  const own = new Set([record.pid, ...descendantsOf([record.pid])]);
101
114
  if (listenersOf(port)?.some((pid) => own.has(pid))) return;
115
+ const reason = refused();
116
+ if (reason !== null) throw new Error(reason);
102
117
  await sleep(READY_POLL_MS);
103
118
  }
104
119
  throw new Error(
@@ -106,20 +121,43 @@ export async function waitForOwnPort(port, record, timeoutMs) {
106
121
  );
107
122
  }
108
123
 
124
+ /**
125
+ * Why a backend never listens on its port: its log says the port was in use
126
+ * when it started, and it listens on another one instead.
127
+ *
128
+ * @param {import("./run-state.mjs").ServerRecord} backend The backend
129
+ * @returns {Refusal}
130
+ */
131
+ function movedOff(backend) {
132
+ const line = `Port ${backend.port} in use, listening on `;
133
+ return () => {
134
+ let log = "";
135
+ try {
136
+ log = readFileSync(backend.log, "utf8");
137
+ } catch {
138
+ return null;
139
+ }
140
+ if (!log.includes(line)) return null;
141
+ return `${backend.name} found port ${backend.port} in use when it started and listens on another one; see ${backend.log}`;
142
+ };
143
+ }
144
+
109
145
  /**
110
146
  * Waits until a backend listens on its own port and answers
111
147
  * `/api/onboarding/informations` there.
112
148
  *
113
149
  * @param {import("./run-state.mjs").ServerRecord} backend The backend
114
150
  * @returns {Promise<void>} Resolves once it answers 200
115
- * @throws When it exits first, another process holds its port or the timeout passes, naming its log
151
+ * @throws When it exits first, another process holds its port, its log says it listens on another port, or the timeout passes, naming its log
116
152
  */
117
153
  export async function waitForBackend(backend) {
118
- await waitForOwnPort(backend.port, backend, READY_TIMEOUT_MS);
154
+ const refused = movedOff(backend);
155
+ await waitForOwnPort(backend.port, backend, READY_TIMEOUT_MS, refused);
119
156
  await waitForOk(
120
157
  `http://127.0.0.1:${backend.port}/api/onboarding/informations`,
121
158
  backend,
122
159
  READY_TIMEOUT_MS,
160
+ refused,
123
161
  );
124
162
  }
125
163
 
@@ -80,7 +80,7 @@
80
80
  "devDependencies": {
81
81
  "@antelopejs/core": "~1.24.5",
82
82
  "@antelopejs/dms-frontend": ">=0.11.11 <0.12.0",
83
- "@antelopejs/tooling-configs": ">=0.10.12 <0.11.0",
83
+ "@antelopejs/tooling-configs": ">=0.10.14 <0.11.0",
84
84
  "@inertiajs/vue3": "^3.7.0",
85
85
  "@nuxt/eslint-config": "^1.17.0",
86
86
  "@nuxt/ui": "4.10.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antelopejs/dms",
3
- "version": "0.25.1",
3
+ "version": "0.25.3",
4
4
  "description": "AntelopeJS DMS. Plug in your PostgreSQL, MySQL, MariaDB, MongoDB or RethinkDB database and your coding agent builds a back office and analytics dashboard as typed TypeScript. Real-time updates on the data the DMS manages.",
5
5
  "keywords": [
6
6
  "antelopejs",
@@ -120,7 +120,7 @@
120
120
  "@antelopejs/mysql": ">=0.2.7 <0.3.0",
121
121
  "@antelopejs/postgres": ">=0.4.3 <0.5.0",
122
122
  "@antelopejs/rethinkdb": "~1.10.6",
123
- "@antelopejs/tooling-configs": ">=0.10.12 <0.11.0",
123
+ "@antelopejs/tooling-configs": ">=0.10.14 <0.11.0",
124
124
  "@playwright/test": "~1.65.0",
125
125
  "@types/archiver": "^6.0.4",
126
126
  "@types/chai": "^5.0.0",
@@ -211,7 +211,7 @@
211
211
  "optional": true
212
212
  }
213
213
  },
214
- "gitHead": "995c8f94cd4a82bbe533267ff8c0df690ffcfef0",
214
+ "gitHead": "b6ffce4fbccdbc5a77f1a0b3cab420abcaea0926",
215
215
  "scripts": {
216
216
  "build": "pnpm --filter @antelopejs/interface-dms --filter @antelopejs/interface-dms-builder build && rimraf dist && antelopejs-tsc && tsc-alias && tsc -p e2e/tsconfig.types.json",
217
217
  "dev": "ajs project run --inspect -w -p playground",