Repository navigation
Commit 2d95781
test(service-automation): stub the host lookup in the http-nodes failed-call suite (#38147)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} -->
_Requested by **Elon** · [project
thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9DDypKu7B9nwbu5WuV7AEio8)_
Fixes #38126
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 用户无感:只改了自动化服务里一个测试文件,产品代码与线上行为都不变。
- 为什么做:消除一个偶发失败的测试,它依赖真实域名解析,CI 上解析慢时会超时变红。
- 出错会怎样:最坏是这个测试本身再变红,不影响任何用户,可以直接撤回。
- 要你做什么:无。
## What changes
`packages/services/service-automation/src/builtin/http-nodes.test.ts`
only (+25 / -3). In the describe `http (canonical node) — a failed call
names its host and cause`, `run()` no longer falls back to
`defaultEgressGuard()` (whose resolver is the real
`dns.promises.lookup`). It hands the node the **real** egress guard,
`createEgressGuard({ policy: createEnvEgressPolicy({ allowedTargets:
'127.0.0.1' }), resolve })`, through the existing
`registerHttpNodes(..., { egress })` seam and the guard's own `resolve`
option (documented "DNS override (tests)"; same pattern as
`http-node-egress-guard.test.ts`). The stub resolver answers an
ENOTFOUND-shaped error for `no-such-host.invalid` and throws on any
other name; it records every name asked.
- The refusal text assertion and the "nothing of the lookup" assertion
(`not.toContain('ENOTFOUND')`) are unchanged.
- The two cases that name `no-such-host.invalid` (unknown host;
path/query/userinfo secrets) now also assert the stub answered the
lookup (`lookups` equals `['no-such-host.invalid']`).
- ECONNREFUSED and timeout cases stay real undici against a real
loopback socket: an IP literal never reaches the resolver.
- No product change: `http-nodes.ts` and the egress guard are untouched.
Every other case in the file was checked for a host lookup:
`example.test` / `api.test` cases use `stubbedFetchEgress()` or the
durable outbox (no fetch); `example.invalid` in the missing-url case
never sends. The DNS-off run below records zero lookups for the whole
file.
## Tests
- `http-nodes.test.ts`: 19/19 passed, normally and with DNS disabled.
- Control on `origin/main`'s version with every name lookup made to hang
(the CI shape): the two cases time out at 5000 ms, two lookups of
`no-such-host.invalid` recorded.
- Ablation: stub resolving `no-such-host.invalid` to a public address
(93.184.215.14) turns both cases red; restored byte-identical.
- Package: `@objectstack/service-automation` typecheck (incl.
`check:test-typecheck`) green; full vitest 297/297 files, 4342/4342
tests.
<details><summary>DNS-off evidence (a preload hook records and then
hangs or fails every non-IP lookup)</summary>
```
# origin/main version, DNS_HOOK=hang
× an unknown host reads the refusal ... 5003ms Error: Test timed out in 5000ms.
× never names the path, query secret or userinfo of the url 5002ms
Tests 2 failed | 17 passed (19)
lookups: dns.promises.lookup no-such-host.invalid (x2)
# this branch, DNS_HOOK=hang and DNS_HOOK=fail
Test Files 1 passed (1) Tests 19 passed (19)
lookups recorded: 0
```
</details>
<details><summary>Ablation (scripts/ablation-replace.mjs, anchor x1 ->
x0, restored blob == HEAD blob)</summary>
```
× an unknown host reads the refusal ... 23ms
AssertionError: expected 'Node \'http\' failed: HTTP 403' to match /http: EGRESS_REFUSED: /
× never names the path, query secret or userinfo of the url 14ms
AssertionError: expected 'Node \'http\' failed: HTTP 403' to contain 'no-such-host.invalid'
Tests 2 failed | 17 passed (19)
restore: blob a5bbfa6 == HEAD
```
</details>
## Acceptance notes
- `skip-changeset`: test-only diff. `files[]` is `dist`, `README.md`,
`CHANGELOG.md`; after a build, the new test symbols have zero hits in
`dist/`, and the positive control (`defaultEgressGuard`) has hits.
## Verification
Read first: `http-nodes.test.ts` around the `stubbedLookupEgress()`
helper (the only risky hunk: the default egress for `run()` changed).
Two-minute check: `pnpm --filter @objectstack/service-automation exec
vitest run --maxWorkers=2 src/builtin/http-nodes.test.ts` with
networking off; expect 19 passed.
<details><summary>Local gates at fc05d4e (derived list,
dispatch-gates --ran: 53 derived, 52 run, 1 NOT MEASURED)</summary>
- 52 derived families exit 0 (incl. `check:nul-bytes`,
`check:cross-package-test-inputs`, `check:test-source-alias`,
`check:type-check-coverage`, `check:type-check-debt`,
`check:issue-citations`).
- NOT MEASURED: `check:dual-build-cjs-loads`, exit 3 PREREQUISITE NOT
MET (needs a whole-workspace `dist/`; this diff changes no built
output). CI runs it.
- `overlap-check.mjs`: VERDICT clean exit 0 (origin/main merges cleanly,
0 overlapping PR heads).
- Everything else (repo-wide `check:*`, Test Core, Build Core,
type-check lanes): CI's.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_016WV4cxRDKprCtjpEdtiPFW)_
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_016WV4cxRDKprCtjpEdtiPFW
Co-authored-by: Claude <noreply@anthropic.com>1 parent e3bdc74 commit 2d95781
1 file changed
Lines changed: 25 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
261 | 261 | | |
262 | 262 | | |
263 | 263 | | |
264 | | - | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
265 | 285 | | |
266 | | - | |
| 286 | + | |
267 | 287 | | |
268 | 288 | | |
269 | 289 | | |
270 | 290 | | |
271 | 291 | | |
272 | 292 | | |
| 293 | + | |
273 | 294 | | |
274 | 295 | | |
275 | 296 | | |
| |||
291 | 312 | | |
292 | 313 | | |
293 | 314 | | |
| 315 | + | |
294 | 316 | | |
295 | 317 | | |
296 | 318 | | |
| |||
0 commit comments