From 522a6b2a2f0cdae532d03c6f6a9056d924f9ed2c Mon Sep 17 00:00:00 2001 From: juyua9 Date: Thu, 7 May 2026 19:54:12 +0800 Subject: [PATCH] test(group): tighten httpx consumer coverage --- .../group/extractors/http-patterns/python.ts | 4 ++- .../unit/group/http-route-extractor.test.ts | 28 ++++++++++++++----- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/gitnexus/src/core/group/extractors/http-patterns/python.ts b/gitnexus/src/core/group/extractors/http-patterns/python.ts index ccb7790b3..31361f8fc 100644 --- a/gitnexus/src/core/group/extractors/http-patterns/python.ts +++ b/gitnexus/src/core/group/extractors/http-patterns/python.ts @@ -79,8 +79,10 @@ const REQUESTS_GENERIC_PATTERNS = compilePatterns({ ], } satisfies LanguagePatterns>); - // ─── Consumer: httpx.AsyncClient assignments ──────────────────────── +// NOTE: This targeted detector only tracks explicit `httpx.AsyncClient(...)` +// construction. Direct imports (`from httpx import AsyncClient`) and module +// aliases (`import httpx as hx`) are intentionally left for a follow-up. const HTTPX_ASYNC_CLIENT_ASSIGN_PATTERNS = compilePatterns({ name: 'python-httpx-async-client-assign', language: Python, diff --git a/gitnexus/test/unit/group/http-route-extractor.test.ts b/gitnexus/test/unit/group/http-route-extractor.test.ts index 063d4768a..a575451b9 100644 --- a/gitnexus/test/unit/group/http-route-extractor.test.ts +++ b/gitnexus/test/unit/group/http-route-extractor.test.ts @@ -446,8 +446,14 @@ class TopicClient: async def publish(self): return await self._client.request("POST", "/questions/import") + async def delete_topic(self): + return await self._client.delete("/topic") + async def check_duplicate(): async with httpx.AsyncClient() as client: + data = {} + data.get("/nope") + service.request("POST", "/nope") return await client.post("https://svc.local/questions/duplicate-check") `, ); @@ -455,14 +461,22 @@ async def check_duplicate(): const contracts = await extractor.extract(null, dir, makeRepo(dir)); const consumers = contracts.filter((c) => c.role === 'consumer'); - expect(consumers.find((c) => c.contractId === 'http::GET::/topic')).toBeDefined(); - expect(consumers.find((c) => c.contractId === 'http::POST::/questions/import')).toBeDefined(); - expect( - consumers.find((c) => c.contractId === 'http::POST::/questions/duplicate-check'), - ).toBeDefined(); - expect(consumers.every((c) => c.meta.framework === 'python-httpx')).toBe(true); - }); + const expected = [ + 'http::GET::/topic', + 'http::POST::/questions/import', + 'http::DELETE::/topic', + 'http::POST::/questions/duplicate-check', + ]; + for (const contractId of expected) { + const consumer = consumers.find((c) => c.contractId === contractId); + expect(consumer).toBeDefined(); + expect(consumer?.meta.framework).toBe('python-httpx'); + } + + expect(consumers.find((c) => c.contractId === 'http::GET::/nope')).toBeUndefined(); + expect(consumers.find((c) => c.contractId === 'http::POST::/nope')).toBeUndefined(); + }); it('extracts Java RestTemplate, WebClient and OkHttp calls', async () => { const dir = path.join(tmpDir, 'java-consumer');