teqo/tests/unit/localHosts.unit.spec.ts
Francisco Solla ee31aeee4f fix(OPS62): services por nome na rede do job — Forgejo 9 não expande expressões em ports
Achado ao vivo (run 730): a expressão ${{ 5433 + (github.run_id % 100) }} no
ports do service não é avaliada pelo Forgejo 9 — o literal ia ao runner e o
job falhava em 1s. E portas fixas colidiriam entre runs concorrentes (o job
único segura os services pelo run inteiro). Correção: services sem publish
host, alcançados por nome na rede do job (postgres-int/postgres-build:5432)
— solução canônica do Actions, mata a colisão de raiz. Guards fail-closed
(LOCAL_HOSTS + assertTestDatabase) admitem os nomes dos services (hosts
internos do runner; hosts remotos continuam rejeitados); pins novos em
localHosts.unit.spec.ts e ciSkipInvariants (sem ports:, URLs por nome).
2026-08-18 23:26:13 +00:00

34 lines
1.3 KiB
TypeScript

// @vitest-environment node
import { describe, expect, it } from 'vitest'
import { defaultGatewayHost, LOCAL_HOSTS } from '../../scripts/lib/cli.mjs'
describe('LOCAL_HOSTS (OPS50/OPS62 — self-hosted runner services by name, legacy gateway)', () => {
it('still contains the canonical static hosts', () => {
for (const host of ['localhost', '127.0.0.1', '0.0.0.0', '::1', 'postgres']) {
expect(LOCAL_HOSTS.has(host)).toBe(true)
}
})
it('admits the job-network service names (OPS62 X1: no host publish)', () => {
expect(LOCAL_HOSTS.has('postgres-int')).toBe(true)
expect(LOCAL_HOSTS.has('postgres-build')).toBe(true)
})
it('admits the machine default gateway when it is RFC1918 (Linux CI bridge)', () => {
const gateway = defaultGatewayHost()
if (gateway) {
// The Forgejo runner published the job's postgres service on the bridge
// gateway IP before OPS62; assertLocalDatabase must still accept it.
expect(LOCAL_HOSTS.has(gateway)).toBe(true)
}
})
it('never admits public or loopback hosts', () => {
expect(LOCAL_HOSTS.has('8.8.8.8')).toBe(false)
expect(LOCAL_HOSTS.has('127.0.0.2')).toBe(false)
expect(LOCAL_HOSTS.has('203.0.113.1')).toBe(false)
expect(LOCAL_HOSTS.has('postgres-prod')).toBe(false)
})
})