Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
test(baileys): build the channel refusal from the shape the engine emits
Yudhi Armyndharisffbba1e6e7bf
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 43241a4cb..ceaab992a 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0### Fixed+- **The tests that lock the channel-refusal contract now use a shape the engine can actually produce** — they built the refusal with the numeric code an IQ error carries, which that code path never emits, so they exercised the wrong branch of the classifier and stayed green through a release in which channel refusals regressed from `403` to an opaque `500`.- **Four response schemas published values the API cannot emit** — search results documented `direction` as `inbound`/`outbound` while every hit carries `incoming`/`outgoing`, so a client validating against the contract would have rejected all of them; audit entries documented `warning` where the code writes `warn`; the search example named a provider id that does not exist; and the data export omitted `skippedTables` and `omittedInlineMedia` — the two fields that say the archive is truncated. Group detail also advertised a `participantsCount` and an `isAdmin` that only the group LIST returns.- **The published image now actually carries the app-state resync fix** — the patcher that bounds the loop was wired into the install hook but never added to the two hand-written lists in the Dockerfile, so it was absent from the production stage, the hook's existence check skipped it without a word, and every image shipped unpatched. It is copied and run fatally now, and a derived check fails the build if a patcher is ever added to one list and not the other.- **A channel refusal answers `403` again, not a bare `500`** — narrowing the refusal classifier in the same release fixed the IQ error channel and silently de-classified the other one: WhatsApp's `w:mex` surface reports a refusal as a GraphQL error inside a _successful_ IQ, so it never carries the numeric code the classifier now reads, and deleting or muting a channel the account does not own regressed from `403` to an opaque `500`. The two error channels are decoded separately now; a dead socket and an unanswered query still do not read as refusals.diff --git a/src/engine/adapters/baileys.adapter.spec.ts b/src/engine/adapters/baileys.adapter.spec.tsindex 3925c7dfd..b767cc10b 100644--- a/src/engine/adapters/baileys.adapter.spec.ts+++ b/src/engine/adapters/baileys.adapter.spec.ts@@ -4744,13 +4744,22 @@ describe('BaileysAdapter channel administration', () => {});// The raw Boom from executeWMexQuery used to escape as a 500 on every refused channel write.+ //+ // The fixture is the shape executeWMexQuery ACTUALLY builds — Boom(msg, { statusCode, data: the+ // GraphQL error OBJECT }) — not the numeric `data` an IQ refusal carries. These cases previously+ // used the numeric one, which this path can never produce: they passed through the IQ branch of+ // the classifier and stayed green straight through a release in which channel refusals regressed+ // from 403 to a bare 500.it.each([['createChannel', (a: BaileysAdapter) => a.createChannel('X'), 'newsletterCreate'],['deleteChannel', (a: BaileysAdapter) => a.deleteChannel(CHANNEL), 'newsletterDelete'],['muteChannel', (a: BaileysAdapter) => a.muteChannel(CHANNEL, true), 'newsletterMute'],])('%s maps a server refusal to EngineRefusedError (403)', async (_name, call, sockMethod) => {(fakeSock as unknown as Record<string, jest.Mock>)[sockMethod].mockRejectedValueOnce(- Object.assign(new Error('not-authorized'), { data: 401 }),+ new Boom('GraphQL server error: not authorized', {+ statusCode: 403,+ data: { message: 'not authorized', extensions: { error_code: 403 } },+ }),);const adapter = await readyAdapter();await expect(call(adapter)).rejects.toBeInstanceOf(EngineRefusedError);