import { buildRequest } from './event-outbox-operations.mjs' import test from 'node:test' import assert from 'node:assert/strict' const env = { CHONGCHONG_ENV: 'test', EVENT_OPERATIONS_TOKEN: 't'.repeat(40) } const args = ['--service', 'finance', '--base', 'http://127.0.0.1:9200', '--entry', 'event-123'] test('inspection stays on explicit internal producer origin without redirects', () => { const request = buildRequest(args, env) assert.equal(request.url.href, 'http://127.0.0.1:9200/internal/finance/event-operations/event-123') assert.equal(request.options.method, 'GET') assert.equal(request.options.redirect, 'error') assert.equal(request.options.body, undefined) }) test('retry requires stable identity, reason and expected payload hash', () => { assert.throws(() => buildRequest([...args, '--retry'], env), /UUID/) const request = buildRequest([...args, '--retry', '--request-id', '11111111-1111-4111-8111-111111111111', '--operator', 'operator-7', '--reason', 'dependency restored', '--hash', 'sha256:' + 'a'.repeat(64)], env) assert.equal(request.options.method, 'POST') assert.equal(JSON.parse(request.options.body).operator, 'operator-7') }) test('wrong environment, weak credential and unknown service fail before HTTP', () => { assert.throws(() => buildRequest(args, { ...env, CHONGCHONG_ENV: 'prod' }), /must be test/) assert.throws(() => buildRequest(args, { ...env, EVENT_OPERATIONS_TOKEN: '' }), /TOKEN/) assert.throws(() => buildRequest(['--service', 'bridge'], env), /Unknown/) })