@danhachuel/jobfinder 0.1.14 → 0.1.15
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 +11 -0
- package/README.md +7 -6
- package/package.json +1 -1
- package/scripts/cli.mjs +22 -3
- package/scripts/manual-tests/fase4-npx-start.mjs +164 -0
- package/src/server/index.mjs +53 -3
- package/src/ui/dist/assets/{index-DQO-z4ME.js → index-DtY7qbQR.js} +1 -1
- package/src/ui/dist/index.html +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,17 @@ All notable changes to JobFinder are documented in this file.
|
|
|
6
6
|
|
|
7
7
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
8
8
|
|
|
9
|
+
## [0.1.15] — 2026-11-21
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
- **Versão `0.0.00` ao rodar via `npx`**: `readPkgVersion()` em `src/server/index.mjs` lia `package.json` com `path.resolve(process.cwd(), 'package.json')`. Sob `npx` o cwd é o diretório do usuário (home do MobaXterm, um path qualquer do PowerShell), a leitura falhava em silêncio e o servidor imprimia `JobFinder v0.0.00 (npm 0.0.0)`. Agora a versão vem de `JOBFINDER_VERSION` (definida pelo launcher, que lê o `package.json` a partir da própria localização do arquivo) ou, na ausência dela, de `createRequire(import.meta.url)` + `require('../../package.json')` — resolvido a partir **deste módulo**, nunca do cwd. O fallback ruidoso (`console.error`) substitui o silencioso.
|
|
14
|
+
- **Retenção do event loop com rastro forense**: `beforeExit` no launcher **e** no servidor registra os handles ativos antes de qualquer saída natural e re-arma um timer de keep-alive **referenciado** (sem `unref()`) quando o socket do servidor não está entre eles — a saída silenciosa agora é impossível sem deixar `[jobfinder] launcher: event loop esvaziando (beforeExit code=…) — handles: …` no terminal. `exit` registra o código final nos dois processos. Nenhum `server.unref()` e nenhum `process.exit(0)` no caminho de startup.
|
|
15
|
+
|
|
16
|
+
### Tests
|
|
17
|
+
|
|
18
|
+
- Nova suíte `scripts/manual-tests/fase4-npx-start.mjs` — **12 verificações, 0 falhas**, rodando o binário de um **diretório estranho** (reprodução do ambiente `npx`/MobaXterm): versão correta na linha do `listen`, processo vivo depois do banner, HTTP 200, caminho `node src/server/index.mjs` direto sem `JOBFINDER_VERSION` (valida o `createRequire`) e caminho completo com worker ativo.
|
|
19
|
+
|
|
9
20
|
## [0.1.14] — 2026-11-20
|
|
10
21
|
|
|
11
22
|
### Security
|
package/README.md
CHANGED
|
@@ -31,15 +31,15 @@ A **background worker** (separate Node process) keeps the queues moving even wit
|
|
|
31
31
|
Windows / CMD / MobaXterm:
|
|
32
32
|
|
|
33
33
|
```bash
|
|
34
|
-
npx.cmd --yes --prefer-online @danhachuel/jobfinder@0.1.
|
|
35
|
-
npx.cmd --yes --prefer-online @danhachuel/jobfinder@0.1.
|
|
34
|
+
npx.cmd --yes --prefer-online @danhachuel/jobfinder@0.1.15 install
|
|
35
|
+
npx.cmd --yes --prefer-online @danhachuel/jobfinder@0.1.15
|
|
36
36
|
```
|
|
37
37
|
|
|
38
38
|
Normal terminal:
|
|
39
39
|
|
|
40
40
|
```bash
|
|
41
|
-
npx --yes @danhachuel/jobfinder@0.1.
|
|
42
|
-
npx --yes @danhachuel/jobfinder@0.1.
|
|
41
|
+
npx --yes @danhachuel/jobfinder@0.1.15 install
|
|
42
|
+
npx --yes @danhachuel/jobfinder@0.1.15
|
|
43
43
|
```
|
|
44
44
|
|
|
45
45
|
`install` creates `~/.jobfinder/` (config, auth, channels, topics, posts, connections, dm-cascades, jobs, applications, resume, logs). It is safe to re-run: existing data is never overwritten.
|
|
@@ -54,12 +54,12 @@ The single first-run account is created in `~/.jobfinder/auth.json` on the first
|
|
|
54
54
|
# Windows (PowerShell)
|
|
55
55
|
$env:JOBFINDER_INITIAL_EMAIL = "voce@exemplo.com"
|
|
56
56
|
$env:JOBFINDER_INITIAL_PASSWORD = "sua-senha-forte"
|
|
57
|
-
npx --yes @danhachuel/jobfinder@0.1.
|
|
57
|
+
npx --yes @danhachuel/jobfinder@0.1.15
|
|
58
58
|
|
|
59
59
|
# Linux / macOS
|
|
60
60
|
JOBFINDER_INITIAL_EMAIL="voce@exemplo.com" \
|
|
61
61
|
JOBFINDER_INITIAL_PASSWORD="sua-senha-forte" \
|
|
62
|
-
npx --yes @danhachuel/jobfinder@0.1.
|
|
62
|
+
npx --yes @danhachuel/jobfinder@0.1.15
|
|
63
63
|
```
|
|
64
64
|
|
|
65
65
|
Alternative: create the account directly in `~/.jobfinder/auth.json` (see the `user` object) before starting the app.
|
|
@@ -130,6 +130,7 @@ node scripts/manual-tests/fase1-dryrun-services.mjs # API: flag dry-run aplic
|
|
|
130
130
|
node scripts/manual-tests/fase1-ui-e2e.mjs # UI (Playwright): login, badges, configurações, logout
|
|
131
131
|
node scripts/manual-tests/fase2-worker.mjs # worker: spawn, filas, limite de DMs, órfãos, estresse
|
|
132
132
|
node scripts/manual-tests/fase3-seed-env.mjs # segurança: seed por env, nenhuma credencial exposta
|
|
133
|
+
node scripts/manual-tests/fase4-npx-start.mjs # npx/cwd estranho: versão correta, processo vivo, HTTP 200
|
|
133
134
|
node scripts/manual-tests/startup-keepalive.mjs # runtime: boot, unhandledRejection, EPIPE, sinais
|
|
134
135
|
node --test tests/*.js # contratos/concorrência/UI (stubs por enquanto)
|
|
135
136
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@danhachuel/jobfinder",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.15",
|
|
4
4
|
"description": "JobFinder — LinkedIn automation platform (posts, connections/DMs, job matching) with a React + Vite UI. Intelligent workflows, JSON storage.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"linkedin",
|
package/scripts/cli.mjs
CHANGED
|
@@ -200,6 +200,10 @@ async function commandStart({ port, host, dataDir, dryRun }) {
|
|
|
200
200
|
process.env.JOBFINDER_DATA_DIR = resolved;
|
|
201
201
|
process.env.JOBFINDER_PORT = String(listenPort);
|
|
202
202
|
process.env.JOBFINDER_HOST = listenHost;
|
|
203
|
+
// Version: read from THIS file's package.json (never cwd) and handed to the
|
|
204
|
+
// server via env. Under npx the cwd is the user's directory, so a server
|
|
205
|
+
// that read its own version from cwd would print 0.0.00.
|
|
206
|
+
process.env.JOBFINDER_VERSION = VISUAL_VERSION;
|
|
203
207
|
if (dryRun) process.env.JOBFINDER_DRY_RUN = '1';
|
|
204
208
|
|
|
205
209
|
// Supervisão do worker. O CLI NUNCA depende do worker para viver: ele
|
|
@@ -243,10 +247,25 @@ async function commandStart({ port, host, dataDir, dryRun }) {
|
|
|
243
247
|
};
|
|
244
248
|
|
|
245
249
|
// Keep-alive inquebrável: timer de 24h SEM unref. Segurança extra — o
|
|
246
|
-
// socket do servidor (abaixo) já é a garantia principal.
|
|
247
|
-
|
|
250
|
+
// socket do servidor (abaixo) já é a garantia principal. Nunca use unref()
|
|
251
|
+
// aqui: um timer solto é o que permite o loop esvaziar e o processo sumir.
|
|
252
|
+
const keepAliveTimer = setInterval(() => {}, 24 * 60 * 60 * 1000);
|
|
248
253
|
|
|
249
|
-
// Forensic trail: se o launcher morrer, o motivo fica visível.
|
|
254
|
+
// Forensic trail: se o launcher morrer, o motivo fica visível. `beforeExit`
|
|
255
|
+
// avisa ANTES de o loop esvaziar (com os handles ativos) e permite re-armar
|
|
256
|
+
// o keep-alive; `exit` registra o código final.
|
|
257
|
+
process.on('beforeExit', (code) => {
|
|
258
|
+
const handles = process.getActiveResourcesInfo?.() ?? [];
|
|
259
|
+
console.error(
|
|
260
|
+
`[jobfinder] launcher: event loop esvaziando (beforeExit code=${code}) — ` +
|
|
261
|
+
`handles: ${handles.join(', ') || 'NENHUM'}`
|
|
262
|
+
);
|
|
263
|
+
if (!stopping) {
|
|
264
|
+
console.error('[jobfinder] launcher: re-armando o keep-alive para nao voltar ao prompt.');
|
|
265
|
+
clearInterval(keepAliveTimer);
|
|
266
|
+
setInterval(() => {}, 24 * 60 * 60 * 1000);
|
|
267
|
+
}
|
|
268
|
+
});
|
|
250
269
|
process.on('exit', (code) => {
|
|
251
270
|
console.error(`[jobfinder] launcher exiting with code ${code}.`);
|
|
252
271
|
});
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reprodução do cenário real: `npx @danhachuel/jobfinder@<versão>` rodando a
|
|
3
|
+
* partir de um diretório ESTRANHO (fora do repo), como o usuário faz no
|
|
4
|
+
* MobaXterm / PowerShell.
|
|
5
|
+
*
|
|
6
|
+
* Verifica:
|
|
7
|
+
* 1. a versão impressa é a correta (não 0.0.00)
|
|
8
|
+
* 2. o processo continua vivo depois do banner (event loop retido)
|
|
9
|
+
* 3. o servidor responde HTTP 200
|
|
10
|
+
* 4. o terminal não volta ao prompt sozinho
|
|
11
|
+
*
|
|
12
|
+
* Uso: node scripts/manual-tests/fase4-npx-start.mjs [versao]
|
|
13
|
+
*/
|
|
14
|
+
import { spawn } from 'node:child_process';
|
|
15
|
+
import fs from 'node:fs';
|
|
16
|
+
import os from 'node:os';
|
|
17
|
+
import path from 'node:path';
|
|
18
|
+
import process from 'node:process';
|
|
19
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
20
|
+
|
|
21
|
+
const VERSION = process.argv[2] ?? '0.1.14';
|
|
22
|
+
const PORT = 4366;
|
|
23
|
+
const HOME = path.join(os.tmpdir(), `jobfinder-npx-${Date.now()}`);
|
|
24
|
+
// Diretório "estranho": fora do repositório, como a home do MobaXterm.
|
|
25
|
+
const FOREIGN_CWD = path.join(os.tmpdir(), `mobaXterm-home-${Date.now()}`);
|
|
26
|
+
fs.mkdirSync(FOREIGN_CWD, { recursive: true });
|
|
27
|
+
|
|
28
|
+
let passed = 0;
|
|
29
|
+
let failed = 0;
|
|
30
|
+
function check(name, condition, extra = '') {
|
|
31
|
+
if (condition) {
|
|
32
|
+
passed += 1;
|
|
33
|
+
console.log(` OK ${name}${extra ? ` — ${extra}` : ''}`);
|
|
34
|
+
} else {
|
|
35
|
+
failed += 1;
|
|
36
|
+
console.log(` FAIL ${name}${extra ? ` — ${extra}` : ''}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
console.log(`\n== JobFinder (build local) em ${FOREIGN_CWD} ==`);
|
|
41
|
+
console.log('(equivalente ao `npx @danhachuel/jobfinder@<versao>`: mesmo cwd estranho, mesmo binário)');
|
|
42
|
+
|
|
43
|
+
// Roda o CLI LOCAL a partir de um diretório estranho — reproduz o ambiente do
|
|
44
|
+
// npx (cwd != raiz do pacote) sem depender de publicação prévia.
|
|
45
|
+
const REPO_ROOT = path.resolve(path.dirname(new URL(import.meta.url).pathname.slice(1)), '..', '..');
|
|
46
|
+
const cli = spawn(process.execPath, [path.join(REPO_ROOT, 'scripts', 'cli.mjs'), 'start', '--port', String(PORT)], {
|
|
47
|
+
cwd: FOREIGN_CWD,
|
|
48
|
+
env: { ...process.env, JOBFINDER_HOME: HOME, JOBFINDER_NO_WORKER: '1' },
|
|
49
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
50
|
+
});
|
|
51
|
+
const npx = cli;
|
|
52
|
+
|
|
53
|
+
let out = '';
|
|
54
|
+
let err = '';
|
|
55
|
+
npx.stdout.on('data', (d) => { out += String(d); });
|
|
56
|
+
npx.stderr.on('data', (d) => { err += String(d); });
|
|
57
|
+
|
|
58
|
+
const alive = async () => new Promise((resolve) => {
|
|
59
|
+
if (npx.exitCode !== null || npx.signalCode !== null) return resolve(false);
|
|
60
|
+
npx.kill(0);
|
|
61
|
+
resolve(true);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// 1. espera o servidor subir
|
|
65
|
+
let httpOk = false;
|
|
66
|
+
for (let i = 0; i < 60; i += 1) {
|
|
67
|
+
try {
|
|
68
|
+
if ((await fetch(`http://127.0.0.1:${PORT}/api/health`)).ok) { httpOk = true; break; }
|
|
69
|
+
} catch { /* ainda subindo */ }
|
|
70
|
+
await delay(1000);
|
|
71
|
+
}
|
|
72
|
+
check('servidor respondeu HTTP na porta', httpOk);
|
|
73
|
+
|
|
74
|
+
// 2. versão correta no output (a linha do servidor, não só o banner do CLI)
|
|
75
|
+
const serverLine = out.split('\n').find((l) => l.includes('listening on')) ?? '';
|
|
76
|
+
const versionLine = out.split('\n').find((l) => /^JobFinder\s+v?\d/.test(l.trim())) ?? '';
|
|
77
|
+
check('versão correta (não 0.0.00)', /v0\.1\.\d+/.test(versionLine) && !versionLine.includes('0.0.00'), versionLine.trim());
|
|
78
|
+
check('linha do listen traz a versão correta', /0\.1\.\d+/.test(serverLine) && !serverLine.includes('0.0.00'), serverLine.trim());
|
|
79
|
+
|
|
80
|
+
// 3. o processo PRECISA continuar vivo (não voltar ao prompt)
|
|
81
|
+
await delay(8000);
|
|
82
|
+
const stillAlive = await alive();
|
|
83
|
+
check('processo npx continua vivo após 8s do listen', stillAlive, `exitCode=${npx.exitCode} signal=${npx.signalCode}`);
|
|
84
|
+
|
|
85
|
+
// 4. HTTP continua respondendo depois (prova que não morreu)
|
|
86
|
+
const httpAfter = await fetch(`http://127.0.0.1:${PORT}/api/health`).then((r) => r.ok).catch(() => false);
|
|
87
|
+
check('HTTP 200 depois da espera', httpAfter);
|
|
88
|
+
|
|
89
|
+
// 5. rastro forense: se morreu, o motivo tem que estar visível
|
|
90
|
+
if (!stillAlive) {
|
|
91
|
+
console.log('--- stdout ---'); console.log(out);
|
|
92
|
+
console.log('--- stderr ---'); console.log(err);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
check('nenhum "launcher exiting" prematuro no log', !err.includes('launcher exiting') && !out.includes('launcher exiting'), err.split('\n').filter((l) => l.includes('launcher exiting')).slice(0, 1).join(''));
|
|
96
|
+
|
|
97
|
+
try { npx.kill('SIGTERM'); } catch { /* já morreu */ }
|
|
98
|
+
await delay(500);
|
|
99
|
+
try { npx.kill('SIGKILL'); } catch { /* já morreu */ }
|
|
100
|
+
|
|
101
|
+
// ------------------------------------------------------------------ *
|
|
102
|
+
// Caminho 2: `node src/server/index.mjs` DIRETO, de um cwd estranho e SEM
|
|
103
|
+
// JOBFINDER_VERSION — valida o createRequire(import.meta.url) puro.
|
|
104
|
+
// ------------------------------------------------------------------ *
|
|
105
|
+
console.log('\n== node src/server/index.mjs direto (sem JOBFINDER_VERSION) ==');
|
|
106
|
+
const direct = spawn(process.execPath, [path.join(REPO_ROOT, 'src', 'server', 'index.mjs')], {
|
|
107
|
+
cwd: FOREIGN_CWD,
|
|
108
|
+
env: { ...process.env, JOBFINDER_HOME: HOME, JOBFINDER_PORT: String(PORT + 1), JOBFINDER_NO_WORKER: '1' },
|
|
109
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
110
|
+
});
|
|
111
|
+
let directOut = '';
|
|
112
|
+
direct.stdout.on('data', (d) => { directOut += String(d); });
|
|
113
|
+
direct.stderr.on('data', (d) => { directOut += String(d); });
|
|
114
|
+
let directHttp = false;
|
|
115
|
+
for (let i = 0; i < 40; i += 1) {
|
|
116
|
+
try {
|
|
117
|
+
if ((await fetch(`http://127.0.0.1:${PORT + 1}/api/health`)).ok) { directHttp = true; break; }
|
|
118
|
+
} catch { /* subindo */ }
|
|
119
|
+
await delay(500);
|
|
120
|
+
}
|
|
121
|
+
check('servidor direto respondeu HTTP', directHttp);
|
|
122
|
+
const directLine = directOut.split('\n').find((l) => l.includes('listening on')) ?? '';
|
|
123
|
+
check('versão correta sem env override (createRequire)', /0\.1\.\d+/.test(directLine) && !directLine.includes('0.0.00'), directLine.trim());
|
|
124
|
+
await delay(3000);
|
|
125
|
+
check('servidor direto continua vivo', direct.exitCode === null && direct.signalCode === null, `exitCode=${direct.exitCode}`);
|
|
126
|
+
try { direct.kill('SIGTERM'); } catch { /* já morreu */ }
|
|
127
|
+
await delay(500);
|
|
128
|
+
try { direct.kill('SIGKILL'); } catch { /* já morreu */ }
|
|
129
|
+
|
|
130
|
+
// ------------------------------------------------------------------ *
|
|
131
|
+
// Caminho 3: caminho padrão COMPLETO, com o worker ativo (como o usuário
|
|
132
|
+
// really roda) — o worker não pode derrubar o launcher.
|
|
133
|
+
// ------------------------------------------------------------------ *
|
|
134
|
+
console.log('\n== caminho padrão com worker ativo ==');
|
|
135
|
+
const full = spawn(process.execPath, [path.join(REPO_ROOT, 'scripts', 'cli.mjs'), 'start', '--port', String(PORT + 2)], {
|
|
136
|
+
cwd: FOREIGN_CWD,
|
|
137
|
+
env: { ...process.env, JOBFINDER_HOME: HOME },
|
|
138
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
139
|
+
});
|
|
140
|
+
let fullOut = '';
|
|
141
|
+
full.stdout.on('data', (d) => { fullOut += String(d); });
|
|
142
|
+
full.stderr.on('data', (d) => { fullOut += String(d); });
|
|
143
|
+
let fullHttp = false;
|
|
144
|
+
for (let i = 0; i < 40; i += 1) {
|
|
145
|
+
try {
|
|
146
|
+
if ((await fetch(`http://127.0.0.1:${PORT + 2}/api/health`)).ok) { fullHttp = true; break; }
|
|
147
|
+
} catch { /* subindo */ }
|
|
148
|
+
await delay(500);
|
|
149
|
+
}
|
|
150
|
+
check('app completo (com worker) respondeu HTTP', fullHttp);
|
|
151
|
+
await delay(6000);
|
|
152
|
+
check('app completo continua vivo', full.exitCode === null && full.signalCode === null, `exitCode=${full.exitCode} signal=${full.signalCode}`);
|
|
153
|
+
const workerPids = fullOut.split('\n').filter((l) => l.includes('Worker')).slice(0, 1).join('');
|
|
154
|
+
check('worker foi anunciado', /Worker\s+:/.test(fullOut), workerPids.trim());
|
|
155
|
+
try { full.kill('SIGTERM'); } catch { /* já morreu */ }
|
|
156
|
+
await delay(3000);
|
|
157
|
+
try { full.kill('SIGKILL'); } catch { /* já morreu */ }
|
|
158
|
+
|
|
159
|
+
console.log('\n--- saída capturada ---');
|
|
160
|
+
console.log(out.split('\n').filter(Boolean).slice(0, 20).join('\n'));
|
|
161
|
+
if (err.trim()) { console.log('--- stderr ---'); console.log(err.split('\n').filter(Boolean).slice(0, 10).join('\n')); }
|
|
162
|
+
|
|
163
|
+
console.log(`\nResultado: ${passed} passaram, ${failed} falharam.`);
|
|
164
|
+
process.exit(failed ? 1 : 0);
|
package/src/server/index.mjs
CHANGED
|
@@ -13,11 +13,15 @@
|
|
|
13
13
|
import fs from 'node:fs';
|
|
14
14
|
import path from 'node:path';
|
|
15
15
|
import { fileURLToPath } from 'node:url';
|
|
16
|
+
import { createRequire } from 'node:module';
|
|
16
17
|
|
|
17
18
|
import { createApp } from './app.mjs';
|
|
18
19
|
import { createContext } from './context.mjs';
|
|
19
20
|
import { resolveDataDir, UI_DIST } from './paths.mjs';
|
|
20
21
|
|
|
22
|
+
/** ESM-safe package.json reader: resolved from THIS file, never from cwd. */
|
|
23
|
+
const require = createRequire(import.meta.url);
|
|
24
|
+
|
|
21
25
|
/**
|
|
22
26
|
* Logger used by the global process handlers below. Assigned by start():
|
|
23
27
|
* the handlers are registered before the context exists, but they only
|
|
@@ -78,12 +82,27 @@ function installProcessResilience() {
|
|
|
78
82
|
}
|
|
79
83
|
}
|
|
80
84
|
|
|
85
|
+
/**
|
|
86
|
+
* Version source, in order:
|
|
87
|
+
* 1. JOBFINDER_VERSION (set by the launcher, which reads package.json from
|
|
88
|
+
* its own location — always correct)
|
|
89
|
+
* 2. package.json resolved relative to THIS module
|
|
90
|
+
*
|
|
91
|
+
* `process.cwd()` is NEVER used: under `npx` the cwd is the user's directory
|
|
92
|
+
* (MobaXterm home, a random PowerShell path), so a cwd-relative read fails and
|
|
93
|
+
* the server silently reports 0.0.00.
|
|
94
|
+
*/
|
|
81
95
|
function readPkgVersion() {
|
|
96
|
+
const fromEnv = process.env.JOBFINDER_VERSION;
|
|
82
97
|
try {
|
|
83
|
-
const pkg =
|
|
84
|
-
|
|
98
|
+
const pkg = fromEnv ? { version: fromEnv } : require('../../package.json');
|
|
99
|
+
const resolved = pkg.version;
|
|
100
|
+
if (!resolved || resolved === '0.0.00') throw new Error('versao vazia');
|
|
101
|
+
return { visual: resolved, npm: resolved.split('.').map((p) => String(Number(p))).join('.') };
|
|
85
102
|
} catch {
|
|
86
|
-
|
|
103
|
+
const fallback = '0.0.00';
|
|
104
|
+
console.error(`[jobfinder] nao foi possivel ler a versao do package.json (env=${fromEnv ? 'set' : 'unset'}) — usando ${fallback}`);
|
|
105
|
+
return { visual: fallback, npm: '0.0.0' };
|
|
87
106
|
}
|
|
88
107
|
}
|
|
89
108
|
|
|
@@ -155,6 +174,37 @@ export async function start() {
|
|
|
155
174
|
// this process means closing the browser never pauses the automations.
|
|
156
175
|
|
|
157
176
|
let shuttingDown = false;
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* ULTIMATE keep-alive guard (0.1.15).
|
|
180
|
+
*
|
|
181
|
+
* The listening socket is the primary guarantee. This is the backstop for
|
|
182
|
+
* the case where something empties the event loop without closing the
|
|
183
|
+
* server: Node fires `beforeExit` right before exiting naturally, and
|
|
184
|
+
* scheduling new work there CANCELS the exit. If that ever happens we now
|
|
185
|
+
* (a) leave a loud forensic trail with the active handles and (b) re-arm a
|
|
186
|
+
* referenced timer so the process cannot vanish silently.
|
|
187
|
+
*/
|
|
188
|
+
const armKeepAlive = () => setInterval(() => {}, 60_000);
|
|
189
|
+
let keepAlive = armKeepAlive();
|
|
190
|
+
process.on('beforeExit', (code) => {
|
|
191
|
+
const handles = process.getActiveResourcesInfo?.() ?? [];
|
|
192
|
+
const socketAlive = handles.some((handle) => /server|tcp|socket|pipe/i.test(handle));
|
|
193
|
+
if (shuttingDown) return;
|
|
194
|
+
console.error(
|
|
195
|
+
`[jobfinder] event loop esvaziando (beforeExit code=${code}) — ` +
|
|
196
|
+
`socket do servidor ativo: ${socketAlive}; handles: ${handles.join(', ') || 'NENHUM'}`
|
|
197
|
+
);
|
|
198
|
+
if (!socketAlive && server.listening) {
|
|
199
|
+
console.error('[jobfinder] re-armando o keep-alive para evitar encerramento prematuro.');
|
|
200
|
+
clearInterval(keepAlive);
|
|
201
|
+
keepAlive = armKeepAlive();
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
process.on('exit', (code) => {
|
|
205
|
+
console.error(`[jobfinder] processo do servidor encerrando (code=${code}).`);
|
|
206
|
+
});
|
|
207
|
+
|
|
158
208
|
const shutdown = (signal) => {
|
|
159
209
|
if (shuttingDown) return;
|
|
160
210
|
shuttingDown = true;
|