fix: support pinned attachment lookup arrays

This commit is contained in:
inman
2026-08-31 15:42:11 +08:00
parent 0da8b4f959
commit 4ba2d43710
3 changed files with 98 additions and 4 deletions

View File

@@ -4,6 +4,7 @@ import test from 'node:test';
import { sha256Bytes } from '../src/crypto.js';
import {
InputAttachmentError,
createPinnedAttachmentLookup,
decodeInlineInputAttachment,
downloadAgentBusInputAttachment,
parseAgentBusInputAttachment,
@@ -90,6 +91,35 @@ test('AgentBus attachment DNS accepts internal names and private literal address
assert.ok(localhost.every((entry) => entry.family === 4 || entry.family === 6));
});
test('AgentBus attachment DNS pinning follows the Node lookup callback shape', async () => {
const address = { address: '10.0.0.8', family: 4 };
const lookup = createPinnedAttachmentLookup(address);
await new Promise<void>((resolve, reject) => {
lookup('internal.example', { all: true }, (error, addresses, family) => {
try {
assert.ifError(error);
assert.deepEqual(addresses, [address]);
assert.equal(family, undefined);
resolve();
} catch (assertionError) {
reject(assertionError);
}
});
});
await new Promise<void>((resolve, reject) => {
lookup('internal.example', { all: false }, (error, resolvedAddress, family) => {
try {
assert.ifError(error);
assert.equal(resolvedAddress, address.address);
assert.equal(family, address.family);
resolve();
} catch (assertionError) {
reject(assertionError);
}
});
});
});
test('AgentBus attachment diagnostics expose stages and codes without URL data', async () => {
const events: Array<{ event: string; metadata: Record<string, unknown> }> = [];
await assert.rejects(