Skip to content

fix(dead-code): registry_dead false-positive — same-file calls inside asyncHandler-wrapped Express callbacks produce malformed graph edges #324

Description

@Wolfvin

Mengapa

Ditemukan dogfooding codelens audit di repo nyata (Coretax-Auto-Downloader,
vps-deploy-kaw81/api/, ~29K baris TS/Express). registry_dead mengklaim
verifyWebqrisSignature (routes/webhooks.ts:36) punya 0 referensi. Verifikasi
manual: fungsi itu DIPANGGIL di baris 194, 246, 563 (3 call site nyata, salah
satunya HMAC signature verifier untuk webhook pembayaran — false-positive di
sini kelas security-relevant, bukan cosmetic).

Bukti (SQL langsung ke .codelens/codelens.db, bukan asumsi)

SELECT source_id, target_id, edge_type, line FROM graph_edges
WHERE file LIKE '%webhooks.ts%' ORDER BY line LIMIT 10;
('routes\webhooks.ts:30', None, 'CALLS', 0)
('routes\webhooks.ts:30', None, 'CALLS', 0)
('routes\webhooks.ts:30', None, 'CALLS', 0)
('routes\webhooks.ts:30', None, 'CALLS', 0)
('routes\webhooks.ts:30', None, 'CALLS', 0)

5 baris identik, target_id selalu NULL, line selalu 0. source_id
= routes\webhooks.ts:30bukan format konvensi <file>:0:<module>
yang sudah mapan untuk synthetic module-level caller (issue #223, dipakai
is_module_level_source_id() di graph_model.py). Baris 30 di file asli
adalah const WEBQRIS_WEBHOOK_SECRET = process.env... — bukan lokasi call
apapun.

Konteks Kode

Call site persis:

webhookRouter.post('/qris', asyncHandler(
  async (req: Request, res: Response) => {
    // ...
    if (!verifyWebqrisSignature(rawBody, signature)) { ... }
  },
  'WEBHOOK_QRIS',
));

Call ke verifyWebqrisSignature ada di dalam arrow function yang jadi
argumen pertama dari asyncHandler(...), yang sendiri adalah argumen
kedua
dari webhookRouter.post(...).

Sudah Dicoba Repro (BELUM berhasil isolasi minimal)

2 percobaan repro minimal di fixture terisolasi — keduanya TIDAK
reproduce
bug ini (fungsi ter-resolve dengan benar, ref_count > 0):

  1. Pattern sederhana: router.post(path, async (req,res) => { fn() }).
  2. Pattern lebih dekat: router.post(path, asyncHandler(async (req,res) => { fn() }, 'LABEL')) dengan asyncHandler didefinisikan lokal di fixture.

Artinya bug butuh kondisi tambahan yang belum ke-isolasi — kemungkinan
terkait ukuran file (webhooks.ts asli 200+ baris, banyak import), atau
interaksi dengan fungsi/pattern lain di file yang sama, atau state parser
yang cuma muncul di scan workspace besar (bukan single-file scan). _find_module_level_calls
(ts_backend_parser.py:507) di baca sekilas — secara desain SEHARUSNYA
menangkap call ini (tidak skip subtree arrow_function yang bukan
registered variable_declarator value), jadi kemungkinan bug ada di tahap
SESUDAH ekstraksi call (edge resolution / graph_model.populate_graph_tables()),
bukan di ekstraksi call itu sendiri.

Beda dari Issue #220

Ini BUKAN kasus #220 (same_file_usages exemption) — itu untuk simbol yang
DIREFERENSI tapi tidak DIPANGGIL (const/static). verifyWebqrisSignature
genuinely DIPANGGIL dengan (), di file yang sama, harusnya kena jalur
_find_module_level_calls normal, bukan jalur exemption.

Definition of Done

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bug-fixRegression or broken behavior

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions