Skip to content

Commit ede2fe7

Browse files
leopu00claude
andcommitted
fix(desktop): test container-mode ermetico (fake child, no docker reale)
Secondo blocco scoperto: il job Release su macOS (runner SENZA docker) restava appeso/cancellato. Causa: il test container spawnava processi reali via spawnFn; in container detached runtime.js apre `docker logs -f` → `state.logChild.kill()` su un child ENOENT (docker assente) non terminava → stopRuntime non risolveva → `node --test` appeso. Il test ora usa un fake child (EventEmitter, exit 0 al primo tick, kill no-op): nessun binario reale, nessuna dipendenza dalla presenza di docker. Verificato in locale CON e SENZA docker (PATH ridotto = condizione runner macOS): suite desktop 135/135 pass, esce in ~50s. runtime.js non toccato. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 8c3e56e commit ede2fe7

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

desktop/runtime.test.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,26 @@ function writeFile(targetPath, contents) {
1414
fs.writeFileSync(targetPath, contents)
1515
}
1616

17+
// Fake child-process ERMETICO: niente binari reali. Serve al test container
18+
// (che altrimenti, via lo spawn reale, lancia `docker logs -f`: su una macchina
19+
// SENZA docker — es. il runner macOS della CI — la `.kill()` su quel child
20+
// ENOENT restava appesa → `node --test` non terminava mai). Emula `docker run
21+
// -d` che stampa l'ID ed ESCE subito: emette `exit 0` al primo tick. `.kill()`
22+
// è un no-op che non può bloccarsi.
23+
const { EventEmitter } = require('node:events')
24+
function makeFakeChild({ exitCode = 0 } = {}) {
25+
const child = new EventEmitter()
26+
child.stdout = new EventEmitter()
27+
child.stderr = new EventEmitter()
28+
child.pid = 4242
29+
child.kill = () => true
30+
setImmediate(() => {
31+
child.emit('exit', exitCode, null)
32+
child.emit('close', exitCode, null)
33+
})
34+
return child
35+
}
36+
1737
test('resolveRepoRoot prefers payloadDir when it contains a web/ entry', () => {
1838
const dir = makeTempRepo()
1939
const payloadDir = path.join(dir, 'app-payload')
@@ -259,9 +279,11 @@ test('runtime manager in container mode skips web setup and uses docker spawn sp
259279
ensureContainerFn: () => {
260280
containerEnsured = true
261281
},
262-
spawnFn: (command, args, options) => {
282+
spawnFn: () => {
263283
portOpen = true
264-
return require('node:child_process').spawn(command, args, options)
284+
// Fake child: il container è detached (docker run -d esce subito) e lo
285+
// stream `docker logs -f` non deve diventare un processo reale.
286+
return makeFakeChild()
265287
},
266288
containerSpawnSpecFactory: ({ port }) => {
267289
lastSpec = {

0 commit comments

Comments
 (0)