Problem

VS Code extensions are mostly TypeScript, and they’re rarely tested against unexpected input or overlapping async events. For a graduate research course (COMP 6970), I built a harness to property-test a whole dataset of open-source extensions with fast-check: first throwing random inputs at their functions, then hunting for race conditions.

Finding extensions that run

Of 430 extension repos in the dataset, 299 are at least 5% TypeScript. The harness copies each one, installs its dependencies and builds it with its own compile script (or a type check if it has none). 199 installed and built cleanly, and those are the ones tested. The full run takes a few hours.

Random-input testing

For every TypeScript file in those 199 repos, the harness picks one function, preferring ones with string, number or boolean parameters, and calls it with 100 fast-check inputs. It fails the test if the function throws a TypeError, RangeError, ReferenceError or SyntaxError, or doesn’t finish in time. Errors the code throws on purpose don’t count.

The hard part was running extension code outside VS Code. The vscode module only exists inside the editor, so I wrote a loader that swaps it, and any missing package, for a fake object, and stops the code from writing files or running commands.

6,457 of 12,271 files had a function that could be tested: 4,433 passed and 2,024 failed.

Horizontal bar chart of failed files by reason: null or undefined access 1,275; hang 263; TypeError 254; ReferenceError 150; invalid input not handled 63; RangeError 14; stack overflow 5.
fig_01 — failure_categories.pngWhy the 2,024 files failed.

Some failures were real input bugs, like a name dropped into a regular expression without escaping it (so "o~jG1ip?*" breaks it), a date parser throwing on odd strings, or a short string causing a stack overflow.

Race conditions

Extensions can get the same event twice before the first one is handled, like two “document changed” events. Following fast-check’s race condition approach, the harness:

  1. Finds async functions that read shared state (a field or a module variable) before an await and write it after.
  2. Routes every await on the fake VS Code API through fc.scheduler(), so fast-check controls the order calls finish in.
  3. Runs each function twice at the same time with the same input, tries different orders, and compares the result with running the two calls one after the other.

It flags a race if overlapping calls crash, never finish, or leave different state. From 348 candidate functions, it flagged 7 functions in 6 files. I checked every one against the source: 6 are real races in 5 files and 1 is a false positive (a timestamp that differed by a millisecond).

The real ones follow the same pattern. Both calls pass an “is it loaded yet?” check before the first one finishes, so the work runs twice: a debugger’s memory regions are reset while another call fills them, cached data is loaded and added twice, a file watcher is registered twice, a settings check runs twice, and an API request is sent twice.

Limits

  • No race found means none was confirmed, not that the file has none. Only functions the static pass picks are tested.
  • The fake vscode can’t build every object’s state, so some calls fail before they reach a race.
  • Inputs only come from fast-check; there is no concolic or symbolic testing.