Skip to content

test: tests for the hosts, tools and cli - #1390

Closed
gewenyu99 wants to merge 1 commit into
posthog/functional-r9-16-tests-for-the-tui-layerfrom
posthog/functional-r9-17-tests-for-the-hosts-tools-and-cli
Closed

gewenyu99 wants to merge 1 commit into
posthog/functional-r9-16-tests-for-the-tui-layerfrom
posthog/functional-r9-17-tests-for-the-hosts-tools-and-cli

Conversation

@gewenyu99

@gewenyu99 gewenyu99 commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

Phase 2 of Release C (#1320), PR 14 of 16, after #1389. Tests only. PRs 1 to 14 of this phase split one change into reviewable pieces and compile only as a stack: review them one by one, then land the whole phase together.

Problem

The hosts, the tools' console runners and the CLI's signal handling are new in #1383 to #1385, and they decide every exit code. Each needs a test that fails when its code or order changes.

Changes

Tests only: 26 files, including the scripts/*.no-jest.ts test scripts and the e2e harness tests.

  • Headless: src/headless/__tests__/run.test.ts (a CI detection's lines print, the gateway's 401 guidance prints before the run ends, a failed analytics flush keeps a success, SIGTERM resolves 143) and renderers/__tests__/progress-log.test.ts.
  • CLI: runners/__tests__/signals.test.ts (SIGTERM aborts the host with the signal name, a host that rejects exits 1). cli.test.ts, mcp-cli.test.ts and provision-cli.test.ts follow the new handlers.
  • Host and tools: src/host/__tests__/wizard-abort.test.ts follows wizardAbort to the presenter and startHostExit, and checks it ends the exit of the host it is passed. report.test.ts and console.test.ts lock runDoctorReport and addMCPServerToClientsStep resolving 0 or 1.
  • Harness and scripts: wizard-ci-driver.test.ts, e2e-flow-snapshot.test.ts and scripts/tui-host.no-jest.ts drive the store and screens through the @tui entry. keyboard-equivalence.test.tsx and its snapshot move to e2e-harness/__tests__ from src/tui as a rename, beside the action registry they check.

Test plan

Created with PostHog Desktop

@github-actions

Copy link
Copy Markdown

🧙 Wizard CI

Run the Wizard CI and test your changes against wizard-workbench example apps by replying with a GitHub comment using one of the following commands:

Test all apps:

  • /wizard-ci all

Test all apps in a directory:

  • /wizard-ci ai-observability
  • /wizard-ci basic-integration
  • /wizard-ci feature-flags
  • /wizard-ci mcp-analytics
  • /wizard-ci replay-vision
  • /wizard-ci revenue
  • /wizard-ci self-driving
  • /wizard-ci warehouse
  • /wizard-ci warehouse-seeded

Test an individual app:

  • /wizard-ci ai-observability/anthropic
  • /wizard-ci ai-observability/google-adk
  • /wizard-ci ai-observability/groq
Show more apps
  • /wizard-ci ai-observability/manual-capture
  • /wizard-ci ai-observability/openai
  • /wizard-ci ai-observability/openai-agents
  • /wizard-ci ai-observability/opentelemetry
  • /wizard-ci ai-observability/vercel-ai
  • /wizard-ci basic-integration/android
  • /wizard-ci basic-integration/angular
  • /wizard-ci basic-integration/astro
  • /wizard-ci basic-integration/django
  • /wizard-ci basic-integration/fastapi
  • /wizard-ci basic-integration/flask
  • /wizard-ci basic-integration/flutter
  • /wizard-ci basic-integration/javascript-node
  • /wizard-ci basic-integration/javascript-web
  • /wizard-ci basic-integration/laravel
  • /wizard-ci basic-integration/next-js
  • /wizard-ci basic-integration/nuxt
  • /wizard-ci basic-integration/python
  • /wizard-ci basic-integration/rails
  • /wizard-ci basic-integration/react-native
  • /wizard-ci basic-integration/react-router
  • /wizard-ci basic-integration/sveltekit
  • /wizard-ci basic-integration/swift
  • /wizard-ci basic-integration/tanstack-router
  • /wizard-ci basic-integration/tanstack-start
  • /wizard-ci basic-integration/vue
  • /wizard-ci feature-flags/django
  • /wizard-ci feature-flags/next-js
  • /wizard-ci mcp-analytics/custom-dispatcher
  • /wizard-ci mcp-analytics/typescript-sdk
  • /wizard-ci replay-vision/javascript-node
  • /wizard-ci replay-vision/next-js
  • /wizard-ci replay-vision/react-vite
  • /wizard-ci revenue/stripe
  • /wizard-ci self-driving/astro
  • /wizard-ci self-driving/fastapi
  • /wizard-ci self-driving/nuxt
  • /wizard-ci self-driving/react-router
  • /wizard-ci self-driving/sveltekit
  • /wizard-ci warehouse/monorepo-env
  • /wizard-ci warehouse/multi-source-next
  • /wizard-ci warehouse/stripe-node
  • /wizard-ci warehouse/zero-source
  • /wizard-ci warehouse-seeded/next-stripe
  • /wizard-ci warehouse-seeded/next-stripe-declined

Test against a Context Mill branch:

  • /wizard-ci all context-mill:my-branch

Add context-mill:<branch> to any command above to pin the Context Mill branch. It defaults to main.

Results will be posted here when complete.

@gewenyu99
gewenyu99 added this pull request to stack #1394 September 29, 2026 09:41
@gewenyu99
gewenyu99 force-pushed the posthog/functional-r9-16-tests-for-the-tui-layer branch from fd543db to a6de02a Compare September 30, 2026 08:06
@gewenyu99
gewenyu99 force-pushed the posthog/functional-r9-17-tests-for-the-hosts-tools-and-cli branch from ba3a8b0 to 3cbc0d2 Compare September 30, 2026 08:06
@gewenyu99
gewenyu99 removed this pull request from stack #1394 September 30, 2026 08:07
@gewenyu99
gewenyu99 added this pull request to stack #1400 September 30, 2026 08:07
@gewenyu99
gewenyu99 force-pushed the posthog/functional-r9-16-tests-for-the-tui-layer branch from a6de02a to 912433f Compare September 30, 2026 08:44
@gewenyu99
gewenyu99 force-pushed the posthog/functional-r9-17-tests-for-the-hosts-tools-and-cli branch from 3cbc0d2 to 09c1e3e Compare September 30, 2026 08:44
@gewenyu99
gewenyu99 marked this pull request as ready for review September 30, 2026 09:14
@gewenyu99
gewenyu99 requested a review from a team as a code owner September 30, 2026 09:14
@gewenyu99
gewenyu99 force-pushed the posthog/functional-r9-17-tests-for-the-hosts-tools-and-cli branch from 09c1e3e to d118ae1 Compare September 30, 2026 14:11
@gewenyu99
gewenyu99 force-pushed the posthog/functional-r9-16-tests-for-the-tui-layer branch from 912433f to bb3b051 Compare September 30, 2026 14:11
@gewenyu99
gewenyu99 force-pushed the posthog/functional-r9-17-tests-for-the-hosts-tools-and-cli branch from d118ae1 to 94dbe58 Compare October 1, 2026 06:43
@gewenyu99
gewenyu99 force-pushed the posthog/functional-r9-16-tests-for-the-tui-layer branch from bb3b051 to 0f3e071 Compare October 1, 2026 06:43
@gewenyu99
gewenyu99 removed this pull request from stack #1400 October 1, 2026 06:47
@gewenyu99
gewenyu99 added this pull request to stack #1403 October 1, 2026 06:47

@johncwaters johncwaters left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Note

Automated review. Not written by a human.


expect(callOrder).toEqual(['shutdown', 'outroError']);
expect(process.exit).toHaveBeenCalledWith(1);
expect(callOrder).toEqual(['shutdown', 'outroError', 'exit']);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Note

Automated review. Not written by a human.

The test pushes 'exit' only after await ended() returns, and waitForOutroDismissed resolves at once, so the order is ['shutdown','outroError','exit'] even if wizardAbort called host.exit.end() before awaiting host.present(...). Nothing pins the contract in src/host/wizard-abort.ts that the host ends only after the presenter settles. Make waitForOutroDismissed a deferred promise and assert exit.ended stays false until it is released, as the shutdown test above does.

Comment thread src/headless/__tests__/run.test.ts Outdated
const store = stream.store.current as {
session: { outroData: { kind: string; errorCode?: string } | null };
};
expect(store.session.outroData).toMatchObject({

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Note

Automated review. Not written by a human.

This reads back the outroData that the test's own runProgram mock wrote at line 222; run.ts never touches outroData on this path, so the assertion only proves the stream and the run share a store, not that the failure reaches the stream. Assert the stream settled with the failure instead, e.g. expect(stream.shutdown).toHaveBeenCalledWith(2000, status === 'cancelled' ? 'cancelled' : 'failed').

Comment thread src/headless/__tests__/run.test.ts Outdated
it('keeps a run a success when its terminal analytics flush fails', async () => {
const flushError = new Error('flush timed out');
vi.mocked(analytics.shutdown).mockRejectedValueOnce(flushError);
await runHeadless(program(), launch());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Note

Automated review. Not written by a human.

nit: The name says the run stays a success, but the test never checks the exit code. Use await expect(runHeadless(program(), launch())).resolves.toBe(0) so a regression to exit 1 fails it.

},
);

it("prints the gateway's 401 guidance before it ends the run", async () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Note

Automated review. Not written by a human.

nit: The name says the 401 guidance prints before the run ends, but the test does not check order, and printAbortOutro also prints the 'Authentication failed (401)' line. Assert that the "Missing scope" line's index in lines is lower than the abort outro's line.

});
return Promise.resolve(settled(outcome, failure));
});
const stderr = vi

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Note

Automated review. Not written by a human.

nit: This process.stderr.write spy, and the one at line 264, are restored inline after assertions; if an assertion throws first the spy leaks into later tests, because afterEach only restores console.log. Call vi.restoreAllMocks() in afterEach, as signals.test.ts does.

process.env.POSTHOG_WIZARD_REGION = 'us';
process.env.POSTHOG_WIZARD_API_KEY = 'phx_env_key';
process.env.POSTHOG_WIZARD_INSTALL_DIR = '/tmp/test';
process.env.POSTHOG_WIZARD_LOG_FILE = '/tmp/wizard-cli-test.log';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Note

Automated review. Not written by a human.

nit: POSTHOG_WIZARD_LOG_FILE is not in WIZARD_ENV_KEYS, so clearWizardEnv() never resets it; this test overwrites the per-worker log path vitest.config.ts sets in test.env and the new value stays for the rest of the worker. Save the original value and restore it in a finally at the end of the test; adding it to WIZARD_ENV_KEYS would delete the per-worker value instead.

@gewenyu99
gewenyu99 force-pushed the posthog/functional-r9-17-tests-for-the-hosts-tools-and-cli branch from 94dbe58 to d48e5cd Compare October 2, 2026 16:47
@gewenyu99
gewenyu99 force-pushed the posthog/functional-r9-16-tests-for-the-tui-layer branch 2 times, most recently from 4430bae to f0141c7 Compare October 2, 2026 20:50
@gewenyu99
gewenyu99 force-pushed the posthog/functional-r9-17-tests-for-the-hosts-tools-and-cli branch from d48e5cd to 0d958e3 Compare October 2, 2026 20:50
Generated-By: PostHog Desktop
Task-Id: d14e92bb-6ee1-49b5-8502-39cb80079589
@gewenyu99
gewenyu99 force-pushed the posthog/functional-r9-16-tests-for-the-tui-layer branch from f0141c7 to fda54fc Compare October 3, 2026 20:40
@gewenyu99
gewenyu99 force-pushed the posthog/functional-r9-17-tests-for-the-hosts-tools-and-cli branch from 0d958e3 to d38f714 Compare October 3, 2026 20:40

@edwinyjlim edwinyjlim 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.

Review of #1390 at d38f7147. Items outside this PR's diff lines:

[P3] No CLI test for the slack tool command
src/cli/commands/slack.ts:23

Suggested fix: Add slack-cli.test.ts mirroring mcp-cli.test.ts: runTuiTool called with the Slack tool and the session args, then exit 0; a rejection exits 1 with the PHW line.

[P3] The command-tree conflict check covers 9 of the 17 registered commands
src/cli/__tests__/wizard.test.ts:83

An alias collision involving any of the eight omitted commands, the exact bug this test exists for, is invisible.

Suggested fix: Export the command list from src/cli/index.ts, the source of truth, and pass it to findConflicts.


Drafted with Claude Code from a review of the whole Release C stack, re-verified at the stack tip 2e31e438. Line numbers are at this PR's head.

stream.destinations(opts.destinations.map((d) => d.name));
stream.store.current = opts.store;
}
attach = vi.fn();

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.

[P3] The headless run test leaves three paths unasserted

attach is never checked, and without it nothing streams. The local-services-down abort and the Crashed outcome have no test, though the TUI twin tests its crash path.

Suggested fix: Assert attach in the destinations test; add a local-services-down case expecting 1 and the error line; add a Crashed case expecting 1 and the outro's error code.

@gewenyu99
gewenyu99 removed this pull request from stack #1403 October 5, 2026 09:47
@gewenyu99

Copy link
Copy Markdown
Collaborator Author

Folded into #1378 so the phase builds green PR by PR. This PR keeps its review; the code lands through #1378.

@gewenyu99 gewenyu99 closed this Oct 5, 2026
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.

3 participants