Skip to content

test(cli): add reusable Vitest e2e helpers#217

Open
yada wants to merge 2 commits into
reshaprio:mainfrom
yada:cli-e2e-helpers
Open

test(cli): add reusable Vitest e2e helpers#217
yada wants to merge 2 commits into
reshaprio:mainfrom
yada:cli-e2e-helpers

Conversation

@yada

@yada yada commented Jun 18, 2026

Copy link
Copy Markdown
Member

Summary:

This PR prepares the CLI Vitest e2e suite for broader coverage by extracting reusable helper utilities.

Changes:

  • add typed CLI JSON execution helper that appends -o json
  • add reusable e2e login helper
  • add cleanup helpers for services and secrets
  • add MCP JSON-RPC helpers for initialization, tool listing, and tool calls

Validation:

cd cli
npm run build
npm exec tsc -- --noEmit --target es2022 --module es2022 --moduleResolution node --strict --esModuleInterop --skipLibCheck e2e/global-setup.ts e2e/helpers/*.ts e2e/scenarios/*.ts
npm run test:e2e

Closes #216

Signed-off-by: Yacine Kheddache <yacine@microcks.io>
@yada yada force-pushed the cli-e2e-helpers branch from 8cde05a to d1384a1 Compare June 18, 2026 13:37
@yada yada added enhancement New feature or request github_actions Pull requests that update GitHub Actions code labels Jun 18, 2026
@lbroudoux lbroudoux added theme/cli theme/build chore and removed github_actions Pull requests that update GitHub Actions code enhancement New feature or request labels Jun 18, 2026
@lbroudoux lbroudoux marked this pull request as ready for review June 18, 2026 21:16
@lbroudoux lbroudoux self-requested a review as a code owner June 18, 2026 21:16

@lbroudoux lbroudoux left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some new stuff like cleanup, mcp-client or cli-runner makes sense, but I don't get the point of some other changes like the global fixtures that are not gloabl and the ability to restore infrastructure. Please review my comments.

Comment thread cli/e2e/helpers/fixtures.ts Outdated
Comment on lines +20 to +25
export const OPEN_METEO_SPEC = path.resolve(import.meta.dirname, '../../../dev/open-meteo-openapi.yml');
export const OPEN_METEO_SERVICE_NAME = 'Open-Meteo APIs';
export const OPEN_METEO_SERVICE_VERSION = '1.0';
export const OPEN_METEO_BACKEND = 'https://api.open-meteo.com';
export const OPEN_METEO_EXPECTED_TOOLS = 1;
export const OPEN_METEO_TOOL_NAME = 'get_v1_forecast';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a global helper file but contains fixtures elements that are specific to one or more scenarios. This doesn't seem the right place to hold this kind of elements. I would have put this in a local fixture definition, next tot the scenarios.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. The intent was to avoid duplicating constants across the planned follow-up e2e scenarios, but the Open-Meteo and (soon/next) GitHub values are scenario fixtures, not generic helper infrastructure. I’ll move those next to the scenario tests that need them and keep only truly shared e2e plumbing in helpers.

Comment thread cli/e2e/helpers/setup.ts Outdated

export async function startInfrastructure(): Promise<void> {
console.log('🚀 Starting infrastructure via Docker Compose...');
await recreateStackIfRequested();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get why we should recreate the stack here. startInfrastructure() is expected to be called once on an empty runner/environment. If the concern is to be able to run on a local development machine where the infra may be already there, then we should instead fail gracefully and require the developer to do some cleanup before launching the tests.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was added to make interrupted local reruns easier, but it changes the expected behavior of startInfrastructure() and is too implicit for this helper PR. CI should start from a clean runner, and local stale infrastructure should fail clearly so the developer can clean it up explicitly. I’ll remove the automatic stack recreation from this PR.

return result;
}

export async function runCliJson<T = unknown>(...args: string[]): Promise<T> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it an helper to run the CLI command with -o json flag? If yes, then we should add it explicitly and not set expectations on the caller to have added -o json to the method args.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 The helper name implies that it runs a JSON-producing CLI command, so callers should not have to remember to pass -o json. I’ll update it so runCliJson() appends -o json itself and only accepts the logical CLI command arguments.

@yada

yada commented Jun 19, 2026

Copy link
Copy Markdown
Member Author

Some new stuff like cleanup, mcp-client or cli-runner makes sense, but I don't get the point of some other changes like the global fixtures that are not gloabl and the ability to restore infrastructure. Please review my comments.

Thanks, that makes sense. I’ll keep the helper pieces that are genuinely reusable (cleanup, mcp-client, and the CLI runner improvements), and adjust the two broader changes: scenario-specific fixtures will move next to their scenarios, and stack recreation will be removed from the default infrastructure startup.

Signed-off-by: Yacine Kheddache <yacine@microcks.io>
@yada

yada commented Jun 19, 2026

Copy link
Copy Markdown
Member Author

@lbroudoux : PR updated, and I have also updated the Summary accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add reusable helpers for CLI Vitest e2e tests

2 participants