Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

test(engine): require an inventory mark to be reached through a library handle

Yudhi Armyndharis011f0a034ee0
diff --git a/docs/29-engine-capability-matrix.md b/docs/29-engine-capability-matrix.md
index 9b138f6e5..1383aa80d 100644
--- a/docs/29-engine-capability-matrix.md
+++ b/docs/29-engine-capability-matrix.md
@@ -570,20 +570,20 @@ with zero OpenWA surface. Baileys-only; whatsapp-web.js has no community API at
**Profile, contacts & presence** (12)
-| Library method | OpenWA exposure |
-| ------------------------ | ----------------------------------------------- |
-| `addOrEditContact` | ✅ `upsertContact` |
-| `createCallLink` | ✅ `createCallLink` |
-| `presenceSubscribe` | ✅ `subscribeToPresence` |
-| `removeContact` | ✅ `deleteContact` |
-| `removeCoverPhoto` | ❌ **not exposed** |
-| `removeProfilePicture` | ✅ `deleteGroupPicture`, `deleteProfilePicture` |
-| `star` | ✅ `starMessage` |
-| `updateCoverPhoto` | ❌ **not exposed** |
-| `updateProfileName` | ✅ `setProfileName` |
-| `updateProfilePicture` | ✅ `setProfilePicture`, `setGroupPicture` |
-| `updateProfileStatus` | ✅ `setProfileStatus` |
-| `updateServerTimeOffset` | 🔩 plumbing |
+| Library method | OpenWA exposure |
+| ------------------------ | ------------------------------------------------------------------------------------------------------ |
+| `addOrEditContact` | ✅ `upsertContact` |
+| `createCallLink` | ✅ `createCallLink` |
+| `presenceSubscribe` | ✅ `subscribeToPresence` |
+| `removeContact` | ✅ `deleteContact` |
+| `removeCoverPhoto` | ❌ **not exposed** |
+| `removeProfilePicture` | ✅ `deleteGroupPicture`, `deleteProfilePicture` |
+| `star` | ❌ **not exposed** — `starMessage` is implemented with `chatModify({ star })`, on the `chatModify` row |
+| `updateCoverPhoto` | ❌ **not exposed** |
+| `updateProfileName` | ✅ `setProfileName` |
+| `updateProfilePicture` | ✅ `setProfilePicture`, `setGroupPicture` |
+| `updateProfileStatus` | ✅ `setProfileStatus` |
+| `updateServerTimeOffset` | 🔩 plumbing |
**Socket, session & plumbing** (21)
@@ -645,7 +645,7 @@ with zero OpenWA surface. Baileys-only; whatsapp-web.js has no community API at
| `sendMessage` | ✅ `sendTextMessage`, `sendImageMessage`, `sendVideoMessage`, `sendAudioMessage`, `sendDocumentMessage`, `sendStickerMessage`, `sendLocationMessage`, `sendContactMessage`, `sendPollMessage`, `postTextStatus`, `postImageStatus`, `postVideoStatus`, `postVoiceStatus` |
| `sendReaction` | ❌ **not exposed** |
| `sendResponseToScheduledEvent` | ❌ **not exposed** |
-| `sendSeen` | ✅ `sendSeen`, `clearChatMessages` |
+| `sendSeen` | ❌ **not exposed** — the adapter reads the chat and calls `Chat.sendSeen()`, not the Client method |
**Chats** (9)
@@ -923,9 +923,9 @@ adapter sources — re-derive the same way when anything changes:
- REST caller's view: **90** engine-neutral (88 + 2 store-backed status reads), **12** Baileys-only,
**9** wwjs-only, **1** unavailable on both (`sendCatalog`).
- Full engine inventory (29.5), split by the exposure legend rather than lumped: Baileys **152**
- socket methods — 49 wired into interface methods, 5 internal wiring, 29 plumbing, **69 ❌ not
- exposed** (incl. the whole 23-method community cluster); wwjs **81** Client methods — 46 wired,
- 2 internal wiring, 1 class plumbing, **32 ❌ not exposed** (24 real capabilities + 8
+ socket methods — 48 wired into interface methods, 5 internal wiring, 29 plumbing, **70 ❌ not
+ exposed** (incl. the whole 23-method community cluster); wwjs **81** Client methods — 45 wired,
+ 2 internal wiring, 1 class plumbing, **33 ❌ not exposed** (25 real capabilities + 8
session/transport settings that are not WhatsApp capabilities). The backlog is the ❌ rows minus
those 8 settings; 🔩 plumbing is correctly never exposed.
- Events: Baileys **34** (15 consumed / 19 dropped), wwjs **31** (16 consumed / 15 dropped).
diff --git a/src/engine/engine-inventory-parity.spec.ts b/src/engine/engine-inventory-parity.spec.ts
index b39f13ada..72860ca2a 100644
--- a/src/engine/engine-inventory-parity.spec.ts
+++ b/src/engine/engine-inventory-parity.spec.ts
@@ -16,12 +16,17 @@ import { ENGINE_CAPABILITY_MATRIX } from './engine-capability-matrix';
* listener at all. Those are exactly the marks a reader triaging backlog work trusts most, so they
* get a gate.
*
- * What this gate CANNOT see, and why (do not read a green run as more than it is):
+ * The name-collision half of that is now closed: a second invariant requires the symbol to be
+ * reached THROUGH a library handle, so an adapter method of the same name no longer satisfies it.
+ * It found two rows that a name search had blessed for as long as they existed — Baileys `star`
+ * (`starMessage` goes through `chatModify`) and wwjs `sendSeen` (the `Chat` model method, not the
+ * `Client` one).
+ *
+ * What this gate still CANNOT see, and why (do not read a green run as more than it is):
* - Under-mapping. A ✅ row listing four interface methods when the symbol really serves eight
* still passes; the check is "the claim has code behind it", not "the claim is exhaustive".
- * - A library symbol whose name collides with an adapter method of the same name (`logout`,
- * `createGroup`, …). `this.lifecycle.logout()` is indistinguishable here from `sock.logout()`.
- * - Direction. Mapping symbol A to interface method B instead of C passes as long as both exist.
+ * - Direction. Mapping symbol A to interface method B instead of C passes as long as both exist,
+ * because nothing here resolves a call site back to the interface method enclosing it.
*/
const DOC = join(__dirname, '..', '..', 'docs', '29-engine-capability-matrix.md');
const ADAPTER_DIR = join(__dirname, 'adapters');
@@ -161,6 +166,39 @@ describe('engine inventory (docs/29 §29.5) — drift invariants', () => {
expect(unsupported).toEqual([]);
});
+ /**
+ * The check above asks whether the NAME occurs in adapter code, which our own identically-named
+ * methods satisfy: `getChatLabels` was marked used while `Client.getChatLabels` was never
+ * called, because the adapter defines a method of that name. Two rows were wrong for exactly
+ * that reason — Baileys `star` (starMessage goes through `chatModify({ star })`) and wwjs
+ * `sendSeen` (the adapter calls the `Chat` model method, not the `Client` one).
+ *
+ * So this asks the stronger question: is the symbol reached THROUGH a library handle? The
+ * handle shapes are taken from what the adapters actually do — `this.sock()`/`this.client()`,
+ * `getSocket()`, and any socket/client-shaped local (`sock`, `sourceSock`, `client`) — and a
+ * member may be a reference rather than a call, since `updateMediaMessage` is passed as one.
+ * Casts are tolerated: `(this.client() as unknown as BusinessClient).getLabels()` is a real
+ * call, and so is computed dispatch, `this.client()[op](…)` with the name supplied as a literal.
+ */
+ it('every ✅/⚙️ exposure mark is reached through a library handle, not just named', () => {
+ const code = adapterSourcesWithStrings().replace(/\s+/g, ' ');
+ const handle =
+ engine === 'wwjs'
+ ? String.raw`(?:\bthis\.client\(\)|\b\w*[Cc]lient\b)`
+ : String.raw`(?:\bthis\.sock\(\)|\bgetSocket\(\)|\b\w*[Ss]ock\b)`;
+ const reached = (symbol: string): boolean => {
+ const s = symbol.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
+ if (new RegExp(`${handle}[^;{}]{0,90}?\\.\\s*${s}\\s*[(<.,)\\]]`).test(code)) return true;
+ // computed dispatch through the handle, with the method name supplied as a literal
+ return new RegExp(`${handle}\\s*\\[`).test(code) && new RegExp(`['"\`]${s}['"\`]`).test(code);
+ };
+
+ const marked = readInventory(engine).filter(r => r.exposure.startsWith('✅') || r.exposure.startsWith('⚙️'));
+ // Guard the selector: an empty or tiny set would make the assertion vacuous.
+ expect(marked.length).toBeGreaterThan(30);
+ expect(marked.filter(r => !reached(r.symbol)).map(r => r.symbol)).toEqual([]);
+ });
+
it('every interface method named in a ✅ exposure cell is `supported` for this engine', () => {
const offenders: string[] = [];
for (const row of readInventory(engine)) {