Skip to content

fix(test): stabilise examples - #90

Merged
ryoppippi merged 3 commits into
mainfrom
test/stabilize-examples
Sep 4, 2025
Merged

fix(test): stabilise examples#90
ryoppippi merged 3 commits into
mainfrom
test/stabilize-examples

Conversation

@ryoppippi

@ryoppippiryoppippi commented Sep 2, 2025

Copy link
Copy Markdown
Contributor

Stabilize example tests to run without network and prefer nullish operations.

Changes

  • Examples: run with preload + .env; skip LLM-heavy files via SKIP_LLM_EXAMPLES.
  • Test setup: load dotenv; use ??= defaults for OPENAI_API_KEY/STACKONE_API_KEY/SKIP_LLM_EXAMPLES.
  • MSW mocks: add HRIS endpoints used by examples.
  • RequestBuilder: replace null/undefined checks with == null / != null where appropriate.
  • Snapshots: update to match current generated specs.

Results

  • bun test: 135 pass, 0 fail.

Summary by cubic

Stabilizes example tests to run offline and reduces flakiness in CI. Also adopts nullish operations for env defaults and RequestBuilder checks, and updates snapshots to current specs.

  • New Features

    • Run examples with Bun preload and .env to activate MSW and env loading.
    • Mock StackOne HRIS endpoints in MSW for deterministic example runs.
    • Skip LLM-heavy examples via SKIP_LLM_EXAMPLES (default 1).
  • Refactors

    • Use dotenv and ??= for OPENAI_API_KEY, STACKONE_API_KEY, and SKIP_LLM_EXAMPLES in test setup.
    • Replace explicit null/undefined checks with == null / != null in RequestBuilder.
    • Refresh OpenAPI and toolset snapshots.
    • Result: 135 passing tests, 0 failing.

- Load .env and provide safe fallbacks in bun.test.setup.ts
- Default SKIP_LLM_EXAMPLES=1 to avoid LLM-dependent examples in CI
- Run examples with preload + .env; allow skipping openai/ai-sdk/human-in-the-loop
- MSW: mock StackOne HRIS endpoints used by examples for deterministic behavior
All tests passing locally: 135 pass, 0 fail.
- Use ??= for env fallbacks in test setup
- Replace null/undefined unions with checks in RequestBuilder
- Update snapshots to match current generated specs
CopilotAI review requested due to automatic review settings September 2, 2025 13:02
@pkg-pr-new

pkg-pr-newBot commented Sep 2, 2025

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/StackOneHQ/stackone-ai-node/@stackone/ai@90

commit: f17566c

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

Pull Request Overview

This PR stabilizes example tests by adding MSW mocks for network dependencies and improving null/undefined checks with nullish coalescing operators.

Key changes:

  • Enhanced test setup with environment variable defaults and LLM example skipping
  • Added MSW mocks for StackOne HRIS endpoints to eliminate network dependencies
  • Replaced explicit null/undefined checks with nullish coalescing in RequestBuilder

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
FileDescription
examples/examples.spec.tsAdded LLM example filtering and MSW preloading for isolated test runs
bun.test.setup.tsAdded dotenv loading and safe environment variable defaults using nullish assignment
mocks/handlers.tsAdded StackOne HRIS endpoint mocks for employee data
src/modules/requestBuilder.tsReplaced explicit null/undefined checks with nullish equality operators
src/toolsets/tests/snapshots/stackone.spec.ts.snapUpdated snapshots with new date-time format and description changes
src/openapi/tests/snapshots/openapi-parser.spec.ts.snapUpdated snapshots with new date-time format and description changes

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@ryoppippiryoppippi changed the title chore(test): stabilize examples and prefer nullish opsfix(test): stabilize examples and prefer nullish opsSep 2, 2025
@ryoppippiryoppippi changed the title fix(test): stabilize examples and prefer nullish opsfix(test): stabilise examplesfSep 2, 2025
@ryoppippiryoppippi changed the title fix(test): stabilise examplesffix(test): stabilise examplesSep 2, 2025

@cubic-dev-aicubic-dev-aiBot 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.

1 issue found across 6 files

React with 👍 or 👎 to teach cubic. You can also tag @cubic-dev-ai to give feedback, ask questions, or re-run the review.

Comment threadmocks/handlers.ts
return HttpResponse.json({
id: params.id,
name: 'Michael Scott',
phone_numbers: ['+1-555-0100'],

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.

Inconsistent field naming/type between list and detail responses ('phone_number' string vs 'phone_numbers' array). Align the property for consistency to avoid downstream confusion.

Prompt for AI agents
Address the following comment on mocks/handlers.ts at line 23:
<comment>Inconsistent field naming/type between list and detail responses (&#39;phone_number&#39; string vs &#39;phone_numbers&#39; array). Align the property for consistency to avoid downstream confusion.</comment>
<file context>
@@ -1,6 +1,30 @@
+ return HttpResponse.json({
+ id: params.id,
+ name: &#39;Michael Scott&#39;,
+ phone_numbers: [&#39;+1-555-0100&#39;],
+ });
+ }
</file context>
Suggested change
phone_numbers: ['+1-555-0100'],
phone_number: '+1-555-0100',

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

LGTM

@ryoppippi
ryoppippi merged commit 015660d into mainSep 4, 2025
14 checks passed
@ryoppippi
ryoppippi deleted the test/stabilize-examples branch September 4, 2025 14:54
@github-actionsgithub-actionsBot mentioned this pull request Sep 4, 2025
Sign up for freeto 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

@ryoppippi@glebedel