ADORSYS-GIS / ADORSYS-GIS/lightbridge-governance
[Ticket]: provideTokenCount is untested, and the stub makes its likely bug untestable
- Lingua principale
- Rust
- Stelle
- 1
- Fork
- 2
- Merge medio
- 14h 36m
- PR unite (30g)
- 107
Descrizione
## Summary
`provideTokenCount` in the VS Code extension ships with **zero test coverage**, and the test harness cannot detect its most likely failure by construction.
## Evidence
```
$ grep -c provideTokenCount ide/vscode/tests/integration.ts → 0
$ grep -c provideTokenCount ide/vscode/src/test/*.test.ts → 0
```
It is the only function in the extension shipped without a test behind it.
## The harness cannot catch the likely bug
`extractText` filters message parts with `part instanceof vscode.LanguageModelTextPart`. The integration harness aliases `vscode` to `tests/support/vscode-stub.mjs`, which defines its **own** `LanguageModelTextPart` class — so `instanceof` passes trivially there regardless of what the real extension host does. A test written against the stub would pass whether or not the production path works.
This is the same shape as two defects already found in this codebase: SSE tests that passed with a deliberate framing bug injected, and fail-closed tests that were actually asserting on the fake gateway's 401. A test that cannot fail for the reason that matters.
## Why it matters
VS Code calls `provideTokenCount` to budget prompts (`computeTokenLength` → `provideTokenCount`, confirmed in the shipped workbench). If it under-reports, VS Code packs a prompt the model then rejects; if `extractText` silently returns `''`, every message counts as zero tokens. Both fail quietly — a truncated conversation, not an error.
Note this is **not** the cause of the `0 / 1M tokens · 0%` Session Info panel; that is [microsoft/vscode#314722](https://github.com/microsoft/vscode/issues/314722), where usage is hard-coded to zero for extension-contributed endpoints.
## Scope
- Cover `provideTokenCount` for: a plain string, a message with text parts, a message with mixed/unknown parts, an empty message.
- Harden `extractText` against a part that is not an `instanceof` match but is structurally a text part (duck-typing on `value`), or document why `instanceof` is guaranteed to hold in-process.
- Prove the test catches the bug: break `extractText` to return `''`, watch the test fail, restore.
## AI Usage Declaration
AI-assisted. Gap found while diagnosing an unrelated symptom. A human owns intent, verification and consequences.
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Start with provideTokenCount and extractText, then inspect ide/vscode/tests/integration.ts and tests/support/vscode-stub.mjs to understand the harness limitation. Add coverage for the four listed message cases and verify that a deliberate empty-string extraction causes the test to fail before restoring the behavior.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript, vscode
- Ambito
- devtools, testing
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Attiva
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 35/100