ADORSYS-GIS / ADORSYS-GIS/lightbridge-governance

[Ticket]: provideTokenCount is untested, and the stub makes its likely bug untestable

Ouverte
#231 1 commentaire 0 réactions 1 personne assignée Réclamée par @Guy-Ghis Voir sur GitHub
bug ticket
Langage dominant
Rust
Étoiles
1
Forks
2
Merge moyen
13 h 13 min
PR mergées (30 j)
110

Description

## 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.

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.