Skip to content

Add type inference test for router context variables#106

Merged
jhaynie merged 4 commits intomainfrom
task/thread-on-hono-context-is-any
Dec 11, 2025
Merged

Add type inference test for router context variables#106
jhaynie merged 4 commits intomainfrom
task/thread-on-hono-context-is-any

Conversation

@jhaynie
Copy link
Copy Markdown
Member

@jhaynie jhaynie commented Dec 11, 2025

Purpose

Validates that createRouter() properly types context variables like thread, session, and sessionId - ensuring they're not typed as any.

Changes

  • packages/runtime/test/router-type-inference.test.ts: New test file with type safety validations

Testing

  • ✅ All tests pass
  • ✅ Validates Thread, Session, and string types
  • ✅ Confirms no any types in context variables

Related PR

Summary by CodeRabbit

  • Tests
    • Added comprehensive test suite validating compile-time type inference for router context variables, ensuring proper type safety across logger, tracer, meter, session management, and other core context properties.

✏️ Tip: You can customize this high-level summary in your review settings.

- Test validates thread, session, sessionId are typed correctly
- Ensures context variables are not typed as 'any'
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Dec 11, 2025

Warning

Rate limit exceeded

@jhaynie has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 12 minutes and 7 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 4209923 and b95cba9.

📒 Files selected for processing (2)
  • packages/runtime/test/router-type-inference.test.ts (1 hunks)
  • packages/runtime/test/type-validation.test.ts (1 hunks)

Walkthrough

A new test suite is added to validate compile-time type inference for router context variables, verifying that context properties like thread, session, sessionId, and infrastructure variables (logger, tracer, meter, etc.) maintain their expected types during router operations.

Changes

Cohort / File(s) Summary
Router Type Inference Tests
packages/runtime/test/router-type-inference.test.ts
New test suite validating compile-time type inference for router context variables across GET/POST routes, including assertions for Thread, Session, string, and infrastructure variable types.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Reviewer should verify that type assertions align with actual router context interface definitions
  • Confirm that all tested context variables (logger, tracer, meter, sessionId, thread, session, kv, stream, vector, app) are correctly typed in the router implementation
  • Ensure Bun test syntax and import paths are correct

Poem

🐰 Types now dance in tests so bright,
Context whispers, all feels right,
Thread and Session, strings aligned,
Inference checked, no bugs to find!
TypeScript's magic, compiler blessed. ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: adding a new test file for type inference validation of router context variables, which directly aligns with the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 19a8ed2 and 4209923.

📒 Files selected for processing (1)
  • packages/runtime/test/router-type-inference.test.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
**/*.{ts,tsx,js,jsx,json}

📄 CodeRabbit inference engine (AGENTS.md)

Format code with Prettier using tabs (width 3), single quotes, semicolons, and 100 character line width

Files:

  • packages/runtime/test/router-type-inference.test.ts
packages/*/test/**/*.test.ts

📄 CodeRabbit inference engine (AGENTS.md)

packages/*/test/**/*.test.ts: Place all tests in test/ folder parallel to src/ folder, never use __tests__/, __test__/, or *.test.ts files in src/ folder
Tests in test/ folder must import from ../src/ relative path, not from package distribution
Use @agentuity/test-utils package for reusable test helpers like createMockLogger(), mockFetch(), and createMockAdapter()

Files:

  • packages/runtime/test/router-type-inference.test.ts
packages/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

packages/**/*.{ts,tsx}: Always use InferInput and InferOutput from @agentuity/core for schema type inference, not StandardSchemaV1.InferOutput
StructuredError properties are directly on the error instance, not under a .data property

Files:

  • packages/runtime/test/router-type-inference.test.ts
packages/runtime/test/**/*.test.ts

📄 CodeRabbit inference engine (AGENTS.md)

packages/runtime/test/**/*.test.ts: When testing agents and routes, do NOT add type annotations to handler parameters; let TypeScript infer types from agent schema
For route testing in @agentuity/runtime, use app.request() instead of Hono's testClient() to avoid type inference issues

packages/runtime/test/**/*.test.ts: Use app.request() for testing routes, NOT testClient() due to Hono's type inference limitations
Do NOT add type annotations to agent handler parameters in tests - let TypeScript infer types
Import test helpers from ../src/ not ../
Use TestAgentContext from test/helpers/test-context.ts for mocking agent contexts
Use mock storage interfaces (kv, stream, vector) for testing instead of real implementations

Files:

  • packages/runtime/test/router-type-inference.test.ts
packages/runtime/**/*.{ts,tsx}

📄 CodeRabbit inference engine (packages/runtime/AGENTS.md)

Use extensive TypeScript generics for type safety

Files:

  • packages/runtime/test/router-type-inference.test.ts
🧬 Code graph analysis (1)
packages/runtime/test/router-type-inference.test.ts (1)
apps/testing/integration-suite/src/test/suite.ts (1)
  • test (155-157)
🔇 Additional comments (3)
packages/runtime/test/router-type-inference.test.ts (3)

1-9: LGTM! Clean imports and appropriate test structure.

The imports follow the coding guidelines correctly, using relative paths from ../src/ and importing type definitions needed for compile-time type validation.


11-34: LGTM! Effective compile-time type validation.

This test correctly validates that c.var.thread is typed as Thread through type assertions and property access. The approach of using expect(true).toBe(true) is appropriate for compile-time type checks where the value is in successful TypeScript compilation.


36-72: LGTM! Consistent type validation approach.

Tests 2 and 3 follow the same effective pattern as test 1, validating Session and sessionId types through compile-time type assertions and property/method access.

Comment thread packages/runtime/test/router-type-inference.test.ts
- Add type-validation.test.ts with 12 comprehensive tests
- Validate Thread, Session, Variables, and Env types
- Confirm proper type inference in route handlers
- Add TYPE_VALIDATION_REPORT.md documenting type correctness
- All 191 tests passing, 0 type errors, 0 lint errors
@jhaynie jhaynie linked an issue Dec 11, 2025 that may be closed by this pull request
@jhaynie jhaynie merged commit a53ac73 into main Dec 11, 2025
5 checks passed
@jhaynie jhaynie deleted the task/thread-on-hono-context-is-any branch December 11, 2025 17:07
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.

Thread on hono context is any

1 participant