Skip to content

Commit fc05d4e

Browse files
committed
test(service-automation): stub the host lookup in the http-nodes failed-call suite
The unknown-host and url-secrets cases resolved no-such-host.invalid through the real resolver; on a slow resolver the lookup outlasted the 5000 ms test timeout. The suite now hands the real egress guard a resolver that answers ENOTFOUND for that one host and fails on any other name, so the file makes no DNS query. Refusal text and the nothing-of-the-lookup assertion unchanged. Claude-Session: https://claude.ai/code/session_016WV4cxRDKprCtjpEdtiPFW Co-authored-by: Claude <noreply@anthropic.com>
1 parent 5b8ca36 commit fc05d4e

1 file changed

Lines changed: 25 additions & 3 deletions

File tree

‎packages/services/service-automation/src/builtin/http-nodes.test.ts‎

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { AutomationEngine } from '../engine.js';
55
import { registerHttpNodes } from './http-nodes.js';
66
import { registerTryCatchNode } from './index.js';
77
import { stubbedFetchEgress } from './stubbed-fetch-egress.testkit.js';
8-
import { egressRefusalText } from '@objectstack/core/egress';
8+
import { createEgressGuard, createEnvEgressPolicy, egressRefusalText, type EgressGuard } from '@objectstack/core/egress';
99

1010
function createTestLogger() {
1111
return {
@@ -261,15 +261,36 @@ describe('http (canonical node)', () => {
261261

262262
describe('http (canonical node) — a failed call names its host and cause', () => {
263263
// Real fetches against real failures: the cause shape is undici's, not a mock's.
264-
async function run(config: Record<string, unknown>, egress?: ReturnType<typeof stubbedFetchEgress>) {
264+
// Only the host lookup is stubbed. `.invalid` never resolves (RFC 6761), but a
265+
// real lookup of it is still a DNS round-trip, and on a slow resolver that
266+
// outlasts the test's timeout — so the guard is the real one, handed a resolver
267+
// that answers ENOTFOUND for the one unknown host this suite names. An IP
268+
// literal never reaches the resolver; any other name is a mistake here.
269+
const lookups: string[] = [];
270+
beforeEach(() => { lookups.length = 0; });
271+
function stubbedLookupEgress(): EgressGuard {
272+
return createEgressGuard({
273+
policy: createEnvEgressPolicy({ allowedTargets: '127.0.0.1' }),
274+
resolve: async (hostname) => {
275+
lookups.push(hostname);
276+
if (hostname === 'no-such-host.invalid') {
277+
throw Object.assign(new Error(`getaddrinfo ENOTFOUND ${hostname}`), { code: 'ENOTFOUND', hostname });
278+
}
279+
throw new Error(`unexpected lookup of ${hostname}: this suite resolves no real host name`);
280+
},
281+
});
282+
}
283+
284+
async function run(config: Record<string, unknown>, egress: EgressGuard = stubbedLookupEgress()) {
265285
const engine = new AutomationEngine(createTestLogger());
266-
registerHttpNodes(engine, createCtx(), egress ? { egress } : {});
286+
registerHttpNodes(engine, createCtx(), { egress });
267287
engine.registerFlow('http_flow', httpFlow('http', config));
268288
return engine.execute('http_flow');
269289
}
270290

271291
it('an unknown host reads the refusal a non-public target reads, naming the host and nothing of the lookup', async () => {
272292
const result = await run({ url: 'http://no-such-host.invalid/path' });
293+
expect(lookups, 'the stubbed resolver answered the lookup').toEqual(['no-such-host.invalid']);
273294
expect(result.success).toBe(false);
274295
expect(result.error).toMatch(/http: EGRESS_REFUSED: /);
275296
expect(result.error!.endsWith(`http: ${egressRefusalText('no-such-host.invalid')}`)).toBe(true);
@@ -291,6 +312,7 @@ describe('http (canonical node) — a failed call names its host and cause', ()
291312
it('never names the path, query secret or userinfo of the url', async () => {
292313
// A query secret on a url that fails to connect.
293314
const q = await run({ url: 'http://no-such-host.invalid/hook/PATHSECRET?token=QUERYSECRET' });
315+
expect(lookups, 'the stubbed resolver answered the lookup').toEqual(['no-such-host.invalid']);
294316
expect(q.error).toContain('no-such-host.invalid');
295317
expect(q.error).not.toContain('QUERYSECRET');
296318
expect(q.error).not.toContain('PATHSECRET');

0 commit comments

Comments
 (0)