Skip to content

Ghost Provider Tests #1336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

hassoncs
Copy link
Contributor

@hassoncs hassoncs commented Jul 16, 2025

Add tests- some don't pass but I think they have the right expectations!

cd $WORKSPACE_ROOT/src && npx vitest run services/ghost/__tests__/GhostProvider.spec.ts

@hassoncs hassoncs force-pushed the hassoncs/ghost-testing-framework branch 2 times, most recently from b8aad83 to d9a7766 Compare July 16, 2025 00:57
Copy link

changeset-bot bot commented Jul 16, 2025

⚠️ No Changeset found

Latest commit: 520d396

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@hassoncs hassoncs force-pushed the hassoncs/ghost-testing-framework branch 4 times, most recently from 8222db0 to 339529d Compare July 16, 2025 01:05
@hassoncs hassoncs changed the title Add GhostProvider tests and fix GhostWorkspaceEdit bug Fix GhostWorkspaceEdit diff bug Jul 16, 2025
@hassoncs hassoncs force-pushed the hassoncs/ghost-testing-framework branch 6 times, most recently from 00fb7eb to d244e8f Compare July 16, 2025 06:01
Introduce a comprehensive mock testing framework to simulate the VS Code
editor and workspace environments. This allows for isolated and
deterministic unit testing of services that rely on VS Code APIs.

The new framework includes:
- `MockTextDocument`: Simulates document content, line/range operations.
- `MockTextEditor`: Encapsulates a document with cursor position.
- `MockWorkspace`: Manages a collection of mock documents.
- `MockWorkspaceEdit`: Simulates applying edits to the workspace.

This infrastructure will be used to build out robust tests for Ghost,
autocomplete, and other editor-aware services.
@hassoncs hassoncs force-pushed the hassoncs/ghost-testing-framework branch from d244e8f to 469ab35 Compare July 16, 2025 06:01
@hassoncs hassoncs changed the title Fix GhostWorkspaceEdit diff bug Ghost Provider Tests Jul 16, 2025
This commit introduces a robust testing framework for the Ghost feature, centered around a new `MockWorkspace` that simulates the VS Code environment. This allows for isolated unit testing of the suggestion parsing and application logic.

The new test suite, `GhostProvider.spec.ts`, validates various scenarios:
- Simple line additions and deletions
- Mixed addition/deletion operations
- Complex diffs with multiple change hunks
- Sequential application of individual suggestions

A minor fix is also included in `GhostStrategy.ts` to handle file path URI parsing more robustly, ensuring that paths are correctly converted to URIs whether or not they already have a `file://` prefix.
@hassoncs hassoncs force-pushed the hassoncs/ghost-testing-framework branch from 469ab35 to a6735bd Compare July 16, 2025 06:09
@hassoncs hassoncs merged commit bef24be into hassoncs/ghost-i18n-and-rule-loading Jul 16, 2025
@hassoncs hassoncs deleted the hassoncs/ghost-testing-framework branch July 16, 2025 20:43
hassoncs added a commit that referenced this pull request Jul 17, 2025
* feat: enable Ghost Writer and add i18n for Ghost features

This commit enables the Ghost Writer feature by uncommenting its registration in `extension.ts`. It also introduces internationalization (i18n) support for all Ghost Writer related strings across multiple languages, including progress messages, input prompts, commands, and chat participant details.

The `package.json` is updated to include new commands, keybindings, code actions, and chat participant declarations for the Ghost Writer. The `GhostCodeActionProvider`, `GhostModel`, and `GhostProvider` classes are updated to use the new i18n strings and to properly initialize the `GhostProvider` with the extension context. The `GhostStrategy` is also updated to incorporate custom instructions into the system prompt.

* Ghost Suggestion Navigation (#1304)

* refactor: remove chat api definition

* feat: ghost navigation

* Update src/services/ghost/GhostProvider.ts

Co-authored-by: Copilot <[email protected]>

* feat: CodeLens indicator

* refactor: fix commands names

* refactor(ghost): rename haveSuggestions to hasSuggestions

Renames the `haveSuggestions` method and related context key to `hasSuggestions` for improved clarity and consistency. This change affects the GhostProvider, GhostSuggestions, and the `package.json` and `extension.json` files where the context key is used.

---------

Co-authored-by: Copilot <[email protected]>
Co-authored-by: Chris Hasson <[email protected]>

* Ghost fuzzy matching diff filenames (#1315)

* refactor: implement fuzzy matching

* refactor: implement fuzzy matching with relative path

* fix(ghost): update file names in patch to use matched URI string

* Ghost prevent race conditions (#1329)

* refactor: fix codelens ranges, lock workspaces edits, update commands

* refactor: add translations of the new cmds

* refactor: move the cursor to follow the suggestions

* refactor: update the pending suggestion when we applied a single op group

* refactor: update the pending suggestion when we applied a single op group

* refactor: ghost render when active editor change

* refactor: correct typo in compute operations offset method

* refactor: simplify GhostProvider method calls

Removed unnecessary explicit object destructuring in method calls for `provideCodeSuggestions` and `enhanceContext` to improve readability and conciseness. Also removed redundant progress report messages.

---------

Co-authored-by: Chris Hasson <[email protected]>

* refactor: fix delete lines recalculation

* Ghost Provider Tests (#1336)

* test(testing): add mock editor and workspace framework for services

Introduce a comprehensive mock testing framework to simulate the VS Code
editor and workspace environments. This allows for isolated and
deterministic unit testing of services that rely on VS Code APIs.

The new framework includes:
- `MockTextDocument`: Simulates document content, line/range operations.
- `MockTextEditor`: Encapsulates a document with cursor position.
- `MockWorkspace`: Manages a collection of mock documents.
- `MockWorkspaceEdit`: Simulates applying edits to the workspace.

This infrastructure will be used to build out robust tests for Ghost,
autocomplete, and other editor-aware services.

* test(ghost): add comprehensive test suite for ghost provider

This commit introduces a robust testing framework for the Ghost feature, centered around a new `MockWorkspace` that simulates the VS Code environment. This allows for isolated unit testing of the suggestion parsing and application logic.

The new test suite, `GhostProvider.spec.ts`, validates various scenarios:
- Simple line additions and deletions
- Mixed addition/deletion operations
- Complex diffs with multiple change hunks
- Sequential application of individual suggestions

A minor fix is also included in `GhostStrategy.ts` to handle file path URI parsing more robustly, ensuring that paths are correctly converted to URIs whether or not they already have a `file://` prefix.

* refactor: wip tests

* refactor: fix all existing tests

* refactor: fix random suggestion apply

* refactor(ghost): update default model to stable gemini-2.5-flash

* refactor: simplify the logic of apply changes

* refactor: fix triple slash

* fix: fix workspace edit lock

* Switch GhostProvider tests to be file based

---------

Co-authored-by: Chris Hasson <[email protected]>
Co-authored-by: Catriel Müller <[email protected]>

* refactor: fix tests

* refactor: fix tests tabs

* refactor: fix merge json format

* refactor: try to fix windows test errors

* Add changeset

---------

Co-authored-by: Chris Hasson <[email protected]>
Co-authored-by: Catriel Müller <[email protected]>
Co-authored-by: Copilot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants