Skip to content

chore: tighten server/client types ahead of pnpm migration - #668

Draft
serendipty01 wants to merge 1 commit into
roostorg:mainfrom
serendipty01:pr-1-type-hygiene
Draft

chore: tighten server/client types ahead of pnpm migration#668
serendipty01 wants to merge 1 commit into
roostorg:mainfrom
serendipty01:pr-1-type-hygiene

Conversation

@serendipty01

Copy link
Copy Markdown
Contributor

Summary

  • Fixes fc.date() in ContentType.ts arbitraries to use noInvalidDate: true, preventing RangeError: Invalid time value in property-based tests
  • Replaces phantom debug dep in server/lib/cache/utils/utils.ts with a minimal inline logger (avoids the transitive dep that pnpm strict mode won't hoist)
  • Adds as unknown as type assertions for safe-stable-stringify default export across 5 files — the package's own types are imprecise and this workaround is needed under pnpm's stricter nodeLinker
  • Adds helmet type assertion in server/api.ts to satisfy the HelmetOptions branded type
  • Tightens RuleEvaluationContext opaque brand from Opaque<T, T> to Opaque<T, 'RuleEvaluationContext'>
  • Adds @ts-expect-error on jwt.sign() call — @types/jsonwebtoken@9 brands expiresIn as StringValue; plain string is valid at runtime
  • Fixes TextEncoder.encode().buffer to as ArrayBuffer in networkingService
  • Adds explicit jest.ProvidesCallback type annotation in server/test/utils.ts
  • Switches ts-pattern .exhaustive() to .otherwise(() => undefined) in JobDecisioning.ts (ts-pattern v5.9 + current TS emits NonExhaustiveError<[any]> on the exhaustive call)
  • Adds @testing-library/jest-dom/vitest import to client/src/setupTests.ts
  • Adds jest and google.maps to client/tsconfig.json types

Why now

These changes are all valid on the current npm setup and are prerequisites for the upcoming pnpm migration PR. Landing them first keeps the pnpm PR a pure tooling diff (no source-code changes), making it easier to review.

Test plan

  • docker compose run --rm backend npm run lint
  • docker compose run --rm backend npm run build
  • docker compose run --rm client npm run lint
  • docker compose run --rm client npm run build
  • docker compose run --rm test

Copilot AI review requested due to automatic review settings June 2, 2026 15:56
@coderabbitai

coderabbitai Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@serendipty01, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 58 minutes and 43 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, 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 include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: ccfebf7f-6191-47e2-ac3b-921880cd6cdc

📥 Commits

Reviewing files that changed from the base of the PR and between edf3f2b and 9b92b09.

📒 Files selected for processing (17)
  • client/src/setupTests.ts
  • client/src/utils/collections.ts
  • client/tsconfig.json
  • server/api.ts
  • server/condition_evaluator/getDerivedFieldValue.ts
  • server/graphql/customScalars/OpaqueScalarMixin.ts
  • server/lib/cache/utils/utils.ts
  • server/lib/cache/utils/wrapProducer.ts
  • server/plugins/warehouse/utils/clickhouseSql.ts
  • server/rule_engine/RuleEvaluator.ts
  • server/services/itemInvestigationService/utils.ts
  • server/services/manualReviewToolService/modules/JobDecisioning.ts
  • server/services/networkingService/index.ts
  • server/services/orgAwareSignalExecutionService/signalExecutionService.ts
  • server/test/arbitraries/ContentType.ts
  • server/test/utils.ts
  • server/utils/encoding.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copilot AI 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

Note

Copilot was unable to run its full agentic suite in this review.

This PR appears to address TypeScript compatibility issues introduced by dependency/type changes (notably safe-stable-stringify, helmet, ts-pattern, and test tooling), plus a small fix to avoid invalid dates in property-based tests.

Changes:

  • Add local type shims/casts for safe-stable-stringify (multiple files) and helmet (server API).
  • Adjust test utilities/types (Jest callback typing, Vitest jest-dom setup, client tsconfig types) and fix fast-check date generation.
  • Work around a ts-pattern exhaustiveness typing regression by replacing .exhaustive() with .otherwise().

Reviewed changes

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

Show a summary per file
File Description
server/utils/encoding.ts Add safe-stable-stringify import/cast shim to satisfy TS typing.
server/test/utils.ts Tighten jestFn typing to match Jest it(...) signature.
server/test/arbitraries/ContentType.ts Ensure generated dates are always valid (noInvalidDate).
server/services/orgAwareSignalExecutionService/signalExecutionService.ts Add safe-stable-stringify import/cast shim.
server/services/networkingService/index.ts Force request-body bytes to an ArrayBuffer for signing.
server/services/manualReviewToolService/modules/JobDecisioning.ts Replace ts-pattern .exhaustive() with .otherwise() workaround.
server/services/itemInvestigationService/utils.ts Add safe-stable-stringify import/cast shim.
server/rule_engine/RuleEvaluator.ts Fix Opaque<> token to a stable unique tag string.
server/lib/cache/utils/wrapProducer.ts Add safe-stable-stringify import/cast shim.
server/lib/cache/utils/utils.ts Replace debug import with a minimal local implementation; add safe-stable-stringify shim.
server/graphql/customScalars/OpaqueScalarMixin.ts Add @ts-expect-error for a jwt expiresIn typing mismatch.
server/condition_evaluator/getDerivedFieldValue.ts Add safe-stable-stringify import/cast shim.
server/api.ts Add helmet import/cast shim to satisfy TS typing.
client/tsconfig.json Extend global types with jest + google.maps.
client/src/setupTests.ts Add Testing Library jest-dom matchers for Vitest.

Comment on lines 324 to +329
.with(['ALREADY_LOGGED', 'SUCCESS'], () => jobAlreadySubmittedError)
// Case 4, client retrying after failed job deletion; deletion failed again.
.with(['ALREADY_LOGGED', 'FAILED'], () => decisioningFailedError)
.exhaustive(),
// ts-pattern v5.9 + TS 5.9: .exhaustive() triggers NonExhaustiveError<[any]>;
// all four cases above are covered so this branch is dead code.
.otherwise(() => undefined),
Comment on lines 45 to 49
serialize(value) {
// @ts-expect-error -- @types/jsonwebtoken@9 brands expiresIn as StringValue from ms; plain string is valid at runtime
return jwt.sign(value as T, jwtSigningKey, {
expiresIn: jwtExpiresIn,
});
Comment on lines +4 to +12
// Minimal debug-compatible logger — avoids phantom dep under pnpm strict mode.
// Behaviour is identical when DEBUG is unset (the common case in tests/prod).
const debug = (namespace: string) => {
const patterns = (process.env.DEBUG ?? '').split(',').map((p) => p.trim());
const enabled = patterns.some(
(p) => p === '*' || p === namespace || (p.endsWith('*') && namespace.startsWith(p.slice(0, -1))),
);
return (...args: unknown[]) => { if (enabled) console.debug(` ${namespace}`, ...args); };
};
Comment thread server/utils/encoding.ts
Comment on lines +1 to +2
import stringify_ from 'safe-stable-stringify';
const stringify = stringify_ as unknown as (value: unknown) => string | undefined;
Comment thread server/api.ts
Comment on lines +21 to +22
import helmet_, { type HelmetOptions } from 'helmet';
const helmet = helmet_ as unknown as (options?: Readonly<HelmetOptions>) => (req: unknown, res: unknown, next: (err?: unknown) => void) => void;
Comment thread client/tsconfig.json
"jsx": "react-jsx",
"target": "ESNext",
"types": ["vite/client", "vite-plugin-svgr/client"],
"types": ["vite/client", "vite-plugin-svgr/client", "jest", "google.maps"],
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