GitNexus/gitnexus/test/unit/group
luyua9 df2ed009ce
fix(group): detect httpx AsyncClient alias imports (#1687)
* fix(group): detect httpx AsyncClient alias imports

* fix(group): anchor httpx dotted imports and skip shadowed aliases

Addresses Findings 1-3 of the production-readiness review on PR #1687.

- F1: the `(dotted_name (identifier) @module)` capture matches every
  segment of a dotted module path, so `import package.httpx as hx` and
  `from package.httpx import AsyncClient` would falsely populate the
  alias sets. Anchor the check on `moduleNode.parent?.text === 'httpx'`
  so the full dotted_name must equal `httpx`.

- F2: `moduleAliases` and `asyncClientAliases` were file-global and
  unaware of Python scope. A function-local rebind like
  `AsyncClient = lambda: MockClient()` left the alias entry intact and
  any subsequent `client = AsyncClient(); client.get(...)` emitted a
  false-positive consumer contract. Walk every
  `(assignment left: (identifier) @name)` whose name matches an alias,
  record the enclosing function/class scope as poisoned, and skip
  direct- and module-attribute matches when the call site is inside
  that scope chain.

- F3: extend the existing fixture with dotted-package look-alikes and
  three local-shadow cases (`shadow_direct_alias`, `shadow_module_alias`,
  `shadow_direct_context`) and assert the would-be FP contractIds are
  not emitted.

- F6: refresh the module-level docstring to mention the supported
  import-alias forms and the shadow-exclusion behavior.

* refactor(group): tighten httpx alias shadow detection and broaden tests

Follow-up addressing the residual review findings on PR #1687.

- Replace inline scope-key construction in isAliasShadowed with a
  getScopeKey call so the two helpers cannot drift apart (M1).
- Collapse the double tree traversal in collectHttpxAsyncClients: build
  one combined alias set and pass it to a single
  collectAliasShadowScopes call (perf, P2).
- Add a `shadowScopeKey` helper that returns the scope a rebind actually
  shadows under Python LEGB rules: function scope for in-function
  rebinds, 'module' for top-level rebinds, and `null` for class-body
  rebinds (class attributes do not shadow bare-name lookups in methods).
  Removes the previous blanket `scopeKey === 'module'` skip and now
  correctly poisons module-level rebinds (correctness #1).
- Extend `ALIAS_SHADOW_PATTERNS` to cover tuple, list, and pattern_list
  destructuring targets (correctness #2).
- Rename `ALIAS_REBIND_PATTERNS` to `ALIAS_SHADOW_PATTERNS` and update
  the block comment to say "shadowed" rather than "poisoned" (M4).
- Collapse `callScopeKeys` to a single-line return; the dead Set wrap
  was misleading future readers (M2).

Tests:
- New negative fixtures for 3-segment dotted import
  (`import a.b.c.httpx as deep_evil`), relative import
  (`from .httpx import AsyncClient as rel_evil_async`), tuple
  destructuring rebind, and an isolated file exercising the module-level
  rebind path (T1, correctness #2, expanded F2).
- New positive fixture confirming that a class-body assignment of
  `AsyncClient` does NOT poison the surrounding methods.
- Add a positive control assertion for `module_direct_client` so the
  dotted-package negative assertions cannot pass vacuously (T3).

---------

Co-authored-by: Gergő Magyar <gergomagyar@icloud.com>
Co-authored-by: Test <test@example.com>
2026-05-21 18:24:27 +01:00
..
bridge-db-edge.test.ts fix(deps): upgrade @ladybugdb/core to 0.16.0 to resolve native segfaults (#1235) 2026-04-30 17:40:39 +01:00
bridge-db.test.ts fix(deps): upgrade @ladybugdb/core to 0.16.0 to resolve native segfaults (#1235) 2026-04-30 17:40:39 +01:00
bridge-storage-tempfile.test.ts fix(security): close URL/regex/tag-filter sanitization cluster (U7) (#1330) 2026-05-08 07:11:29 +01:00
config-parser.test.ts feat: add IncludeExtractor for C++ cross-repo include tracking (group) (#1156) 2026-05-09 09:31:59 +01:00
cross-impact-phase2-timeout.test.ts fix(ingestion): close ReDoS in cobol-preprocessor + rust-workspace + resource-exhaustion in cross-impact (U8) (#1331) 2026-05-08 09:10:07 +01:00
cross-impact.test.ts fix(group): bubble local-impact phase errors in groupImpact (#1004) (#1007) 2026-04-21 11:44:16 +01:00
elixir-workspace-extractor.test.ts feat(group): workspace extractors for Node, Python, Go, Java, Elixir (#1260) 2026-05-04 09:43:21 +01:00
fixtures.ts feat(group): bridge.lbug storage + contract matching expansion (1/4 of #606 split) (#795) 2026-04-11 19:46:12 +01:00
go-workspace-extractor.test.ts feat(group): workspace extractors for Node, Python, Go, Java, Elixir (#1260) 2026-05-04 09:43:21 +01:00
group-path-utils.test.ts feat: cross-repo impact analysis (#794) — @repo MCP routing + group resources (#984) 2026-04-20 11:55:07 +01:00
group-service-group-mode.test.ts feat: cross-repo impact analysis (#794) — @repo MCP routing + group resources (#984) 2026-04-20 11:55:07 +01:00
group-tools.test.ts feat: cross-repo impact analysis (#794) — @repo MCP routing + group resources (#984) 2026-04-20 11:55:07 +01:00
grpc-extractor.test.ts fix(windows): 32767-char tree-sitter crash + VECTOR extension SIGSEGV (#1433) 2026-05-10 16:00:36 +01:00
http-route-extractor.test.ts fix(group): detect httpx AsyncClient alias imports (#1687) 2026-05-21 18:24:27 +01:00
http-route-multi-verb.test.ts fix(extractors): resolve 3 silent contract mis-resolution bugs (#793) (#817) 2026-04-14 08:03:02 +01:00
impact-by-uid.test.ts feat(group): add sync pipeline, CLI, MCP tools, and monorepo fixture 2026-04-02 00:40:31 +03:00
include-extractor.test.ts fix(windows): 32767-char tree-sitter crash + VECTOR extension SIGSEGV (#1433) 2026-05-10 16:00:36 +01:00
insecure-tempfile.test.ts fix(security): close URL/regex/tag-filter sanitization cluster (U7) (#1330) 2026-05-08 07:11:29 +01:00
java-workspace-extractor.test.ts feat(group): workspace extractors for Node, Python, Go, Java, Elixir (#1260) 2026-05-04 09:43:21 +01:00
manifest-extractor.test.ts feat(ingestion): add thrift contracts impl (#1234) 2026-05-06 09:19:10 +01:00
matching.test.ts feat(ingestion): add thrift contracts impl (#1234) 2026-05-06 09:19:10 +01:00
node-workspace-extractor.test.ts feat(group): workspace extractors for Node, Python, Go, Java, Elixir (#1260) 2026-05-04 09:43:21 +01:00
python-workspace-extractor.test.ts feat(group): workspace extractors for Node, Python, Go, Java, Elixir (#1260) 2026-05-04 09:43:21 +01:00
rust-workspace-extractor.test.ts feat(core): adopt pino structured logger (#1336) 2026-05-07 20:56:25 +01:00
service-boundary-detector.test.ts fix(group): address 4 HIGH-priority issues from PR #626 review 2026-04-02 12:55:33 +03:00
service.test.ts feat: cross-repo impact analysis (#794) — @repo MCP routing + group resources (#984) 2026-04-20 11:55:07 +01:00
storage.test.ts fix(group): address 4 HIGH-priority issues from PR #626 review 2026-04-02 12:55:33 +03:00
sync.test.ts feat: add IncludeExtractor for C++ cross-repo include tracking (group) (#1156) 2026-05-09 09:31:59 +01:00
thrift-extractor.test.ts fix(windows): 32767-char tree-sitter crash + VECTOR extension SIGSEGV (#1433) 2026-05-10 16:00:36 +01:00
topic-extractor.test.ts fix(group): contract extractors honour .gitnexusignore via shared IgnoreService (#1185) (#1247) 2026-05-01 16:42:21 +01:00
types.test.ts feat(ingestion): add thrift contracts impl (#1234) 2026-05-06 09:19:10 +01:00