Skip to content

test: improve ci completion time#132

Merged
lorenzocorallo merged 4 commits into
mainfrom
test-time
May 29, 2026
Merged

test: improve ci completion time#132
lorenzocorallo merged 4 commits into
mainfrom
test-time

Conversation

@toto04
Copy link
Copy Markdown
Contributor

@toto04 toto04 commented Apr 26, 2026

Volevo eseguire i test un po' più veloci dato che avevo notato che throttle aspettava tutto sequenzialmente e mi sono fatto prendere la mano 🤭

  • I test sono stati velocizzati eseguendo throttle in concorrenza
  • typecheck è molto più veloce usando tsgo
  • la cache di docker è molto più aggressiva adesso (ho copiato molto sia del dockerfile che del workflow da polinet.cc)
  • bonus: nella build di docker viene attivato pnpm, così il container smette di scaricarlo con corepack ogni volta che si avvia il pod, che era una cosa che non aveva senso in primo luogo, il time-to-deploy su argocd dovrebbe in teoria essere migliorato di interi secondi

niente di lifechanging, ma è stato divertente

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 26, 2026

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3fc8ce36-ec25-485f-9429-a24f921dfef4

📥 Commits

Reviewing files that changed from the base of the PR and between 27bd450 and 9dada95.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (9)
  • .dockerignore
  • .github/workflows/docker.yaml
  • Dockerfile
  • package.json
  • src/middlewares/auto-moderation-stack/ai-moderation.ts
  • src/middlewares/auto-moderation-stack/constants.ts
  • src/middlewares/auto-moderation-stack/index.ts
  • src/middlewares/auto-moderation-stack/types.ts
  • tests/throttle.test.ts

Walkthrough

Deletes OpenAI-based moderation code and types from the auto-moderation stack. Updates package scripts and dependencies (removes openai), raises Node engine, adds Dockerignore, enhances GitHub Actions/pnpm caching and BuildKit support, updates the Dockerfile, and tweaks a concurrent test timing.

Changes

Auto-moderation Stack Cleanup

Layer / File(s) Summary
Remove AI moderation types & constants
src/middlewares/auto-moderation-stack/types.ts, src/middlewares/auto-moderation-stack/constants.ts, src/middlewares/auto-moderation-stack/index.ts
Deletes OpenAI type imports and moderation-related type exports (ModerationCandidate, ModerationResult, Category, FlaggedCategory), removes DELETION_THRESHOLDS, and strips commented AI harmful-content wiring from the stack.

Tooling, CI, Docker, and tests

Layer / File(s) Summary
GitHub Actions: pnpm store, cache, BuildKit
.github/workflows/docker.yaml
Adds step to resolve pnpm store path, reorders registry login, uses actions/cache@v4 for pnpm store, restores BuildKit cache mounts, and passes BUILDKIT_INLINE_CACHE=1 to the docker build action.
Dockerfile: base, prod-deps, build stages
Dockerfile
Switches base image to node:24-alpine, activates pnpm via corepack from package.json, copies only package manifests for prod deps install, and uses cached pnpm store across prod/dev install and build stages.
package.json: scripts & deps
package.json
Changes test to vitest run, typecheck to tsgo --noEmit; bumps dev deps (@types/node, TypeScript, Vitest), adds @typescript/native-preview, removes globals and openai, upgrades runtime croner/pino, and raises engines.node to >=24.0.0.
Tests: concurrent suite and timing tweak
tests/throttle.test.ts
Converts suite to describe.concurrent, renames tests to behavior-focused titles, and tightens one wait assertion from limitms + 20 to 1 ms.
Docker build context
.dockerignore
Adds .dockerignore to exclude node_modules, .env, dist, Dockerfile, .git, and .gitignore from Docker context.

Possibly related PRs

🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title focuses narrowly on test improvements and CI time reduction, but the changeset includes substantial removals of AI moderation functionality (deleted class, types, constants) and dependency updates (TypeScript, Vitest, OpenAI removal, etc.) that are not captured by the title. Revise the title to reflect the main changes: consider 'remove: AI moderation and clean up dependencies' or 'refactor: remove OpenAI moderation, update dependencies, improve test CI time' to accurately represent the scope of changes.
✅ Passed checks (3 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


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.

@toto04 toto04 changed the title test: halfed test wait time (concurrency) test: improve ci completion time Apr 26, 2026
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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tests/throttle.test.ts (1)

22-50: ⚠️ Potential issue | 🟠 Major

describe.concurrent + real timers makes these tests flaky.

Tests 1 and 2 assert on exact spy call counts that depend on real setTimeout firing within precise windows (10 ms call cadence vs. 100/50 ms throttle limits). With describe.concurrent, all tests share the same event loop and contend for timer dispatch. On a busy CI runner, a 100 ms throttle timeout can fire 10–30 ms late, shifting "exactly 3 calls" to 2 or 4 and producing intermittent failures.

To fix this deterministically, use vi.useFakeTimers() + vi.advanceTimersByTimeAsync() in each test. The throttle implementation only relies on setTimeout, which fake timers handle cleanly. However, note that vi.useFakeTimers is a global switch in the worker thread and does not isolate between concurrent tests in the same describe.concurrent block. Workarounds:

  • Run the suite with --pool=forks (isolates each test file in its own process), or
  • Move timer-mocked tests into their own non-concurrent describe block, or
  • Drop describe.concurrent entirely for this suite
Sketch using fake timers (deterministic, no real waits)
-import { describe, expect, it, vi } from "vitest"
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"
 import { throttle } from "@/utils/throttle"
-import { wait } from "@/utils/wait"
-
-async function callNTimes(n: number, ms: number, fn: () => void) {
-  for (let i = 0; i < n; i++) {
-    fn()
-    await wait(ms)
-  }
-}
+
+async function callNTimes(n: number, ms: number, fn: () => void) {
+  for (let i = 0; i < n; i++) {
+    fn()
+    await vi.advanceTimersByTimeAsync(ms)
+  }
+}
@@
 describe.concurrent("throttle function", () => {
+  beforeEach(() => vi.useFakeTimers())
+  afterEach(() => vi.useRealTimers())
@@
-    await wait(limitms + 20)
+    await vi.advanceTimersByTimeAsync(limitms + 20)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/throttle.test.ts` around lines 22 - 50, The tests inside
describe.concurrent are flaky because they rely on real timers; switch each test
that asserts exact call counts to use fake timers by invoking vi.useFakeTimers()
at test start and vi.restoreAllMocks()/vi.useRealTimers() at the end (or
afterEach), and advance timers deterministically with
vi.advanceTimersByTimeAsync(...) instead of awaiting real waits; update the
tests that call throttle(...) and wait(...) to replace real wait() delays with
vi.advanceTimersByTimeAsync(limitms + 20) or the appropriate advancement so the
throttle implementation (which uses setTimeout) fires deterministically;
alternatively remove describe.concurrent or move these timer-mocked tests into a
non-concurrent describe block if isolating fake timers is undesirable.
🧹 Nitpick comments (3)
tests/throttle.test.ts (1)

55-57: Nit: await wait(1) is unnecessary here.

throttle invokes func synchronously on the first call (func(...args) after setTimeout(handler, limit) in src/utils/throttle.ts), so the spy is already recorded by the time control reaches the expect. You can drop the await wait(1) entirely without weakening the assertion, which also makes the test fully resilient to any event-loop scheduling delays under describe.concurrent.

♻️ Proposed simplification
     throttled()
-    await wait(1)
     expect(spy).toHaveBeenCalledTimes(1)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/throttle.test.ts` around lines 55 - 57, The test calls throttled() and
then unnecessarily awaits wait(1) before asserting spy invocation; since
throttle calls func synchronously on the first call (see handler scheduling in
throttle and the call to func(...args) after setTimeout), remove the `await
wait(1)` line so the test simply calls `throttled()` then
`expect(spy).toHaveBeenCalledTimes(1)` to make the assertion immediate and
resilient under describe.concurrent.
package.json (2)

13-62: Nit: PR title doesn't reflect the scope of these changes.

The PR is titled "test: halfed test wait time (concurrency)", but this file also bumps the Node engine to >=24.0.0, swaps the typecheck toolchain (tsctsgo), upgrades several runtime deps to new majors (pino 10, redis 5, croner 10), and drops openai. Each of those is an independently risky change — Node 24-only dropping for users still on 22 LTS, redis v4→v5 and pino v9→v10 typically have breaking API/config changes, and removing openai couples this PR to whichever PR/feature deletes the AI moderation code.

Consider splitting into smaller PRs (or at least retitle to reflect the dep/toolchain bump) so reviewers can reason about each change independently and so a regression in, say, redis v5 doesn't get bisected back to "halve test wait time."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@package.json` around lines 13 - 62, The package.json changes bundle multiple
risky modifications (Node engine "node": ">=24.0.0", the typecheck script
switching to "typecheck": "tsgo --noEmit", major dependency bumps for "pino",
"redis", "croner", and removal of the "openai" dependency) under a PR titled
about test wait time; split these into separate PRs or at minimum retitle this
PR to reflect the broad scope (e.g., "chore(deps): bump node, switch typecheck
to tsgo, upgrade pino/redis/croner, remove openai") and move each logical change
into its own branch/PR so reviewers can evaluate Node engine bump, toolchain
change, each major dependency upgrade (pino, redis, croner) and the openai
removal independently; ensure each PR includes a short migration note calling
out possible breaking changes and tests exercising affected codepaths
(especially places using pino, redis, croner, and any AI moderation code that
referenced openai).

14-14: tsgo (@typescript/native-preview) is now highly stable, but still in beta.

As of April 2026 (TypeScript 7.0 Beta release), tsgo is officially described as "highly stable" and "ready to be put to the test in your daily workflows and CI pipelines today" with identical type-checking semantics to TypeScript 6.0. The false-positive/negative risk the original review outlined is substantially lower. However:

  • You're pinned to a specific daily dev build (7.0.0-dev.20260421.2). CI is coupled to a snapshot of a beta compiler. Plan to migrate to stable typescript@7 once it ships (expected late June 2026).
  • The official recommendation remains to keep stable TypeScript 6.x in production CI until TypeScript 7.0 stable releases. Using tsgo for experimentation alongside is reasonable for the ~10x speed gain.

Optionally, keep a typecheck:tsc fallback using the stable typescript package as a pre-release sanity check:

     "typecheck": "tsgo --noEmit",
+    "typecheck:tsc": "tsc --noEmit",
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@package.json` at line 14, The package.json currently uses the experimental
"tsgo" command in the "typecheck" script; add a stable fallback script and
document the intended migration: keep "typecheck" as is (using tsgo) and add
"typecheck:tsc": "tsc --noEmit" (or "npm run typecheck:tsc" alias) so CI or devs
can run the stable TypeScript 6.x check; also ensure package.json
devDependencies include a pinned "typescript" version for the fallback and add a
short comment in README/CI notes that the tsgo-based "typecheck" is experimental
and will be migrated to "typescript@7" when stable.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@tests/throttle.test.ts`:
- Around line 22-50: The tests inside describe.concurrent are flaky because they
rely on real timers; switch each test that asserts exact call counts to use fake
timers by invoking vi.useFakeTimers() at test start and
vi.restoreAllMocks()/vi.useRealTimers() at the end (or afterEach), and advance
timers deterministically with vi.advanceTimersByTimeAsync(...) instead of
awaiting real waits; update the tests that call throttle(...) and wait(...) to
replace real wait() delays with vi.advanceTimersByTimeAsync(limitms + 20) or the
appropriate advancement so the throttle implementation (which uses setTimeout)
fires deterministically; alternatively remove describe.concurrent or move these
timer-mocked tests into a non-concurrent describe block if isolating fake timers
is undesirable.

---

Nitpick comments:
In `@package.json`:
- Around line 13-62: The package.json changes bundle multiple risky
modifications (Node engine "node": ">=24.0.0", the typecheck script switching to
"typecheck": "tsgo --noEmit", major dependency bumps for "pino", "redis",
"croner", and removal of the "openai" dependency) under a PR titled about test
wait time; split these into separate PRs or at minimum retitle this PR to
reflect the broad scope (e.g., "chore(deps): bump node, switch typecheck to
tsgo, upgrade pino/redis/croner, remove openai") and move each logical change
into its own branch/PR so reviewers can evaluate Node engine bump, toolchain
change, each major dependency upgrade (pino, redis, croner) and the openai
removal independently; ensure each PR includes a short migration note calling
out possible breaking changes and tests exercising affected codepaths
(especially places using pino, redis, croner, and any AI moderation code that
referenced openai).
- Line 14: The package.json currently uses the experimental "tsgo" command in
the "typecheck" script; add a stable fallback script and document the intended
migration: keep "typecheck" as is (using tsgo) and add "typecheck:tsc": "tsc
--noEmit" (or "npm run typecheck:tsc" alias) so CI or devs can run the stable
TypeScript 6.x check; also ensure package.json devDependencies include a pinned
"typescript" version for the fallback and add a short comment in README/CI notes
that the tsgo-based "typecheck" is experimental and will be migrated to
"typescript@7" when stable.

In `@tests/throttle.test.ts`:
- Around line 55-57: The test calls throttled() and then unnecessarily awaits
wait(1) before asserting spy invocation; since throttle calls func synchronously
on the first call (see handler scheduling in throttle and the call to
func(...args) after setTimeout), remove the `await wait(1)` line so the test
simply calls `throttled()` then `expect(spy).toHaveBeenCalledTimes(1)` to make
the assertion immediate and resilient under describe.concurrent.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 91538267-24cb-40fd-8a12-6706520ce609

📥 Commits

Reviewing files that changed from the base of the PR and between c2fbe51 and 27bd450.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (6)
  • package.json
  • src/middlewares/auto-moderation-stack/ai-moderation.ts
  • src/middlewares/auto-moderation-stack/constants.ts
  • src/middlewares/auto-moderation-stack/index.ts
  • src/middlewares/auto-moderation-stack/types.ts
  • tests/throttle.test.ts
💤 Files with no reviewable changes (4)
  • src/middlewares/auto-moderation-stack/constants.ts
  • src/middlewares/auto-moderation-stack/index.ts
  • src/middlewares/auto-moderation-stack/types.ts
  • src/middlewares/auto-moderation-stack/ai-moderation.ts

@lorenzocorallo lorenzocorallo merged commit 56dd41a into main May 29, 2026
1 of 2 checks passed
@lorenzocorallo lorenzocorallo deleted the test-time branch May 29, 2026 19:15
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