Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

ci: run the unit and piece tests the repo already has, and fix the ones that were red (#15653)

Hazem Adel0dafe6db5be3
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 3ceca4b720b..0a7943960b9 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -64,6 +64,24 @@ jobs:
main:
runs-on: ubuntu-latest
if: github.repository == 'activepieces/activepieces'
+ services:
+ redis:
+ image: redis:7-alpine
+ options: >-
+ --health-cmd "redis-cli ping"
+ --health-interval 10s
+ --health-timeout 5s
+ --health-retries 5
+ ports:
+ - 6379:6379
+ env:
+ # packages/server/api/.env.tests pins AP_REDIS_HOST=redis, the alias the service container
+ # answers to inside the job's docker network, which a non-container job is not on. dotenv
+ # (vitest.setup.ts) does not override values already in the environment, so this wins and
+ # the tests reach the published port. AP_REDIS_HOST/PORT are in turbo.json
+ # globalPassThroughEnv; without that turbo's strict env mode would drop them.
+ AP_REDIS_HOST: localhost
+ AP_REDIS_PORT: "6379"
steps:
- uses: actions/checkout@v5
with:
@@ -152,10 +170,10 @@ jobs:
set -euo pipefail
pids=()
- npx turbo run test --filter=@activepieces/engine --filter=@activepieces/shared --filter=@activepieces/sandbox --filter=@activepieces/ai-providers --filter=@activepieces/core-execution --filter=@activepieces/core-piece-types --filter=@activepieces/server-utils --filter=@activepieces/pieces-framework --filter=@activepieces/piece-subflows --filter=web --filter=worker &
+ npx turbo run test $(npx tsx tools/scripts/test-filters.ts) &
pids+=($!)
- npx turbo run test-ce test-ee test-cloud check-migrations --filter=api &
+ npx turbo run test-unit test-ce test-ee test-cloud check-migrations --filter=api &
pids+=($!)
npx tsx tools/scripts/check-migration-rollback.ts &
diff --git a/brain/knowledge/engineering/ci-pr-review-hygiene.md b/brain/knowledge/engineering/ci-pr-review-hygiene.md
index cfa81955d6e..93ae61d793b 100644
--- a/brain/knowledge/engineering/ci-pr-review-hygiene.md
+++ b/brain/knowledge/engineering/ci-pr-review-hygiene.md
@@ -20,6 +20,8 @@ Which team gets asked to review comes entirely from `.github/CODEOWNERS` — the
Enforcement is the **`Codeowners review` repository ruleset** (active on the default branch), not classic branch protection: `require_code_owner_review: true` plus `required_approving_review_count: 1` and `required_review_thread_resolution: true`. Eight bypass actors are configured, which is why an owner-team request can look non-blocking on some PRs.
## Gotchas
+- **A job-level `env:` in `ci.yml` does not reach anything turbo runs.** Turbo 2.x defaults to `--env-mode=strict`: a task's process only receives variables named in `globalPassThroughEnv` / `passThroughEnv` / `env`, plus turbo's own system list. Everything else is dropped silently, so the task falls back to whatever `packages/server/api/.env.tests` set (dotenv there runs without `override`, so a real env var would otherwise win). Symptom: the workflow clearly sets the variable and the test still uses the old value. Add the name to `globalPassThroughEnv` in `turbo.json` — that is why `AP_DB_TYPE` and `AP_POSTGRES_*` are already listed. Jobs that call `npx vitest` directly, like `tool-search-postgres`, are unaffected, which is what makes the difference easy to miss. Verify with a throwaway test that `console.log`s the variable through `npx turbo run <task> --filter=<pkg>`.
+- **A GitHub service container is not reachable by its name from a non-container job.** `services:` attaches the container to a docker network with a `--network-alias`, but the runner itself is on the host, so the alias does not resolve (`getaddrinfo EAI_AGAIN redis`) and only the published `ports:` mapping on `localhost` works. `.env.tests` pins `AP_REDIS_HOST=redis` for `docker-compose`, so any test that opens a real connection needs `localhost` forced past it.
- **Never use `git stash` to prove a new test fails without its fix. Use `git checkout <base> -- <file>` instead.** `git stash push -- <path>` on a path with no uncommitted changes saves nothing and creates no entry, so a following `git stash pop` silently pops whoever's stash is at `stash@{0}` instead. This repo carries long-lived stashes from other branches, so the pop conflicts, is kept, and still writes that stash's untracked files into the working tree, which then look like your own new files. It has happened at least twice, and `stash@{1}` is literally named *"recovered: AGENTS.md agent-skills section (accidentally popped by claude)"*. Reverting one committed file to its base version and running the test there is the same proof with no shared state: `git checkout <merge-base> -- <file>`, run, then `git checkout HEAD -- <file>`. If a stash pop does go wrong, the entry survives the conflict, so the recovery is to delete the stray untracked files after confirming they belong to it with `git stash show --include-untracked --name-only stash@{0}`.
- **Engine tests that call a live host are flakes waiting to happen, and the SSRF guard is off in tests so loopback is the fix.** `flow-rerun.test.ts` was the repo's top CI flake for months — two live calls to `cloud.activepieces.com` (a 404 plus `GET /api/v1/pieces`, the full catalog) inside a self-imposed 10s budget. It timed out 3× in one night on [#14966](https://github.com/activepieces/activepieces/pull/14966), a pieces-metadata-only PR, and 3 runs straight on [#14987](https://github.com/activepieces/activepieces/pull/14987), always within ~35ms of the limit; on a good day it merely *passed* at 8,163ms of 10,000ms. It was finally fixed by serving both responses from a `node:http` server on an ephemeral loopback port (8,163ms → 846ms), not by a bigger timeout — mid-investigation the host went fully unreachable, and no timeout value fixes a host that does not answer. Three facts that generalise: **(1)** `ssrfGuard`'s `isGuardEnabled` keys off `AP_NETWORK_MODE === STRICT`, which `packages/server/engine/vitest.config.ts` never sets, so the guard is inert in engine tests and a loopback server needs no config change — and `ssrf-guard.test.ts` passes explicit `allowList`s, so it is unaffected either way. **(2)** The engine's vitest default is already `testTimeout: 20000`; `flow-rerun` was the only file overriding it *downward*, which is why `flow-piece.test.ts` survived a 10,262ms call in the same run (it overrides *up* to 30s). Never override below the project default. **(3)** `piecePath.resolve` → `findInDistFolder` scans every dist `package.json` under `packages/pieces` (400+) on **every** call — only `pieceRunner.describe` results are cached, not the path — so the cold cost lands entirely in whichever test in a file runs first. That still applies to every other piece-loading engine test.
- **Repo-wide regenerators sweep `main`'s pending drift into your PR — run them, then keep only your own lines.** `npm run i18n:extract` reorders all of `en/translation.json` and rewrites nine locale files (130 moved lines for six new keys), and `bun install` after a version bump writes back every community-piece version that was bumped without a lockfile sync (103 lines for four intended bumps). Both diffs are indistinguishable from real work in review, and both bury the change you actually made. Revert the file and hand-apply your own entries instead — then prove parity by running the generator into a scratch copy and diffing just your keys against it, so you keep byte-identical output without the churn. Provider setup markdown in `features/agents/ai-providers.ts` is extracted as translation keys in **source order**, so new entries go beside their neighbours in `SUPPORTED_AI_PROVIDERS`, not at the end.
diff --git a/bun.lock b/bun.lock
index 0f60df6ba37..76502ff8cdd 100644
--- a/bun.lock
+++ b/bun.lock
@@ -3510,7 +3510,7 @@
},
"packages/pieces/community/front": {
"name": "@activepieces/piece-front",
- "version": "0.2.0",
+ "version": "0.2.1",
"dependencies": {
"@activepieces/core-piece-types": "workspace:*",
"@activepieces/core-utils": "workspace:*",
@@ -3615,7 +3615,6 @@
"devDependencies": {
"@types/jsonwebtoken": "9.0.10",
"tslib": "2.6.2",
- "vitest": "3.2.6",
},
},
"packages/pieces/community/giftbit": {
@@ -6970,7 +6969,7 @@
},
"packages/pieces/community/pinterest": {
"name": "@activepieces/piece-pinterest",
- "version": "0.1.9",
+ "version": "0.2.0",
"dependencies": {
"@activepieces/core-piece-types": "workspace:*",
"@activepieces/core-utils": "workspace:*",
@@ -9172,7 +9171,7 @@
},
"packages/pieces/community/trello": {
"name": "@activepieces/piece-trello",
- "version": "0.6.0",
+ "version": "0.7.0",
"dependencies": {
"@activepieces/core-piece-types": "workspace:*",
"@activepieces/core-utils": "workspace:*",
@@ -10442,7 +10441,7 @@
},
"packages/pieces/core/http": {
"name": "@activepieces/piece-http",
- "version": "0.12.0",
+ "version": "0.12.1",
"dependencies": {
"@activepieces/core-piece-types": "workspace:*",
"@activepieces/core-utils": "workspace:*",
diff --git a/package.json b/package.json
index 9ff188019ff..70746eba204 100644
--- a/package.json
+++ b/package.json
@@ -33,7 +33,7 @@
"lint-pieces": "turbo run lint --filter='@activepieces/piece-*'",
"lint-affected": "turbo run lint --affected",
"lint-dev": "turbo run lint --filter='!@activepieces/piece-*' --force -- --fix",
- "test-unit": "turbo run test --filter=@activepieces/engine --filter=@activepieces/shared --filter=@activepieces/sandbox --filter=@activepieces/core-utils --filter=@activepieces/core-execution --filter=@activepieces/server-utils --filter=@activepieces/pieces-framework --filter=web --filter=worker --filter=ee-embed-sdk",
+ "test-unit": "turbo run test $(npx tsx tools/scripts/test-filters.ts) && turbo run test-unit --filter=api",
"test-api": "turbo run check-migrations test-ce test-ee test-cloud --filter=api --concurrency=1",
"agent-evals": "set -a && . ./.env.dev && set +a && tsx --tsconfig packages/server/worker/test/lib/agent-eval/cli/tsconfig.json packages/server/worker/test/lib/agent-eval/cli/index.ts",
"agent-evals:ci": "if [ -f ./.env.dev ]; then set -a && . ./.env.dev && set +a; fi && vitest run --dir packages/server/worker/test/lib/agent-eval",
diff --git a/packages/cli/src/lib/utils/bundle-piece-utils.test.ts b/packages/cli/src/lib/utils/bundle-piece-utils.test.ts
index 3e5daa2f776..9a5d8a7de94 100644
--- a/packages/cli/src/lib/utils/bundle-piece-utils.test.ts
+++ b/packages/cli/src/lib/utils/bundle-piece-utils.test.ts
@@ -1,4 +1,4 @@
-import { mkdtempSync, mkdirSync, writeFileSync, rmSync, readFileSync } from 'node:fs'
+import { mkdtempSync, mkdirSync, writeFileSync, rmSync, readFileSync, realpathSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { afterEach, describe, expect, it } from 'vitest'
@@ -15,7 +15,7 @@ describe('bundlePiece — external dependency capture', () => {
})
it('captures a native dep reached transitively through an inlined package', async () => {
- root = mkdtempSync(join(tmpdir(), 'ap-bundle-'))
+ root = realpathSync(mkdtempSync(join(tmpdir(), 'ap-bundle-')))
const sdkDir = join(root, 'node_modules', 'fake-sdk')
mkdirSync(sdkDir, { recursive: true })
@@ -37,7 +37,7 @@ describe('bundlePiece — external dependency capture', () => {
})
it('keeps wasm/native asset packages (tiktoken, sharp) external so their runtime-loaded assets resolve', async () => {
- root = mkdtempSync(join(tmpdir(), 'ap-bundle-'))
+ root = realpathSync(mkdtempSync(join(tmpdir(), 'ap-bundle-')))
for (const [name, version] of [['tiktoken', '1.0.11'], ['sharp', '0.35.2']]) {
const depDir = join(root, 'node_modules', name)
@@ -62,7 +62,7 @@ describe('bundlePiece — external dependency capture', () => {
})
it('externalizes an inlined package that relies on import.meta', async () => {
- root = mkdtempSync(join(tmpdir(), 'ap-bundle-'))
+ root = realpathSync(mkdtempSync(join(tmpdir(), 'ap-bundle-')))
const esmDir = join(root, 'node_modules', 'esm-dep')
mkdirSync(esmDir, { recursive: true })
@@ -94,7 +94,7 @@ describe('bundlePiece — forked sibling entries (GIT-1772)', () => {
})
function setupForkingPiece({ declareEntry }: { declareEntry: boolean }): string {
- root = mkdtempSync(join(tmpdir(), 'ap-bundle-'))
+ root = realpathSync(mkdtempSync(join(tmpdir(), 'ap-bundle-')))
const dbDir = join(root, 'node_modules', 'oracledb')
mkdirSync(dbDir, { recursive: true })
diff --git a/packages/pieces/community/front/package.json b/packages/pieces/community/front/package.json
index a47c732a6cc..d94b05a279f 100644
--- a/packages/pieces/community/front/package.json
+++ b/packages/pieces/community/front/package.json
@@ -1,6 +1,6 @@
{
"name": "@activepieces/piece-front",
- "version": "0.2.0",
+ "version": "0.2.1",
"type": "commonjs",
"main": "./dist/src/index.js",
"types": "./dist/src/index.d.ts",
diff --git a/packages/pieces/community/front/test/attachments.test.ts b/packages/pieces/community/front/test/attachments.test.ts
index 3dabf69d6cf..7ed19943d6f 100644
--- a/packages/pieces/community/front/test/attachments.test.ts
+++ b/packages/pieces/community/front/test/attachments.test.ts
@@ -39,10 +39,11 @@ let sent: Captured[] = [];
beforeEach(() => {
sent = [];
vi.stubGlobal('fetch', async (url: string, init: FetchInit) => {
+ const headers = new Headers(init.headers);
sent.push({
url: String(url),
- contentType: init.headers['content-type'] ?? '',
- authorization: init.headers['authorization'] ?? '',
+ contentType: headers.get('content-type') ?? '',
+ authorization: headers.get('authorization') ?? '',
body: await readBody(init.body),
});
return new Response(JSON.stringify({ id: 'msg_1' }), {
@@ -289,6 +290,6 @@ function actionContext(propsValue: Record<string, unknown>) {
}
type FetchInit = {
- headers: Record<string, string>;
+ headers: HeadersInit;
body: unknown;
};
diff --git a/packages/pieces/community/ghostcms/package.json b/packages/pieces/community/ghostcms/package.json
index afc53b11892..28db78e9d47 100644
--- a/packages/pieces/community/ghostcms/package.json
+++ b/packages/pieces/community/ghostcms/package.json
@@ -6,8 +6,7 @@
"scripts": {
"build": "tsc -p tsconfig.lib.json && cp package.json dist/",
"bundle": "node ../../../../dist/packages/cli/src/index.js pieces bundle",
- "lint": "eslint 'src/**/*.ts'",
- "test": "vitest run"
+ "lint": "eslint 'src/**/*.ts'"
},
"dependencies": {
"@activepieces/pieces-common": "workspace:*",
@@ -18,7 +17,6 @@
},
"devDependencies": {
"@types/jsonwebtoken": "9.0.10",
- "tslib": "2.6.2",
- "vitest": "3.2.6"
+ "tslib": "2.6.2"
}
}
diff --git a/packages/pieces/community/ghostcms/vitest.config.ts b/packages/pieces/community/ghostcms/vitest.config.ts
deleted file mode 100644
index 2b1c323fe22..00000000000
--- a/packages/pieces/community/ghostcms/vitest.config.ts
+++ /dev/null
@@ -1,7 +0,0 @@
-import { defineConfig } from 'vitest/config'
-
-export default defineConfig({
- test: {
- environment: 'node',
- },
-})
diff --git a/packages/pieces/core/http/package.json b/packages/pieces/core/http/package.json
index 69a99b0c903..1e702522d0a 100644
--- a/packages/pieces/core/http/package.json
+++ b/packages/pieces/core/http/package.json
@@ -1,6 +1,6 @@
{
"name": "@activepieces/piece-http",
- "version": "0.12.0",
+ "version": "0.12.1",
"main": "./dist/src/index.js",
"types": "./dist/src/index.d.ts",
"dependencies": {
diff --git a/packages/pieces/core/http/test/http.test.ts b/packages/pieces/core/http/test/http.test.ts
deleted file mode 100644
index ac0bf2a3a63..00000000000
--- a/packages/pieces/core/http/test/http.test.ts
+++ /dev/null
@@ -1,63 +0,0 @@
-/// <reference types="vitest/globals" />
-
-import { describe, it, expect, vi, afterEach, beforeEach } from 'vitest';
-import { AxiosHttpClient, HttpMethod } from '@activepieces/pieces-common';
-import type { AxiosInstance } from 'axios';
-
-describe('AxiosHttpClient', () => {
- beforeEach(() => {
- delete process.env['HTTP_PROXY'];
- delete process.env['HTTPS_PROXY'];
- delete process.env['http_proxy'];
- delete process.env['https_proxy'];
- });
-
- afterEach(() => {
- delete process.env['HTTP_PROXY'];
- delete process.env['HTTPS_PROXY'];
- delete process.env['http_proxy'];
- delete process.env['https_proxy'];
- });
-
- it('does not attach a proxy agent when HTTP_PROXY / HTTPS_PROXY are unset', async () => {
- const requestSpy = vi.fn().mockResolvedValue({ status: 200, headers: {}, data: {} });
- const fakeAxios = { request: requestSpy } as unknown as AxiosInstance;
-
- const client = new AxiosHttpClient();
- await client.sendRequest({ method: HttpMethod.GET, url: 'https://api.example.com/data' }, fakeAxios);
-
- const calledConfig = requestSpy.mock.calls[0][0];
- expect(calledConfig.httpAgent).toBeUndefined();
- expect(calledConfig.httpsAgent).toBeUndefined();
- expect(calledConfig.proxy).toBeUndefined();
- });
-
- it('attaches proxy agents when HTTPS_PROXY is set (and disables axios built-in proxy detection)', async () => {
- process.env['HTTPS_PROXY'] = 'http://127.0.0.1:4444';
- process.env['HTTP_PROXY'] = 'http://127.0.0.1:4444';
-
- const requestSpy = vi.fn().mockResolvedValue({ status: 200, headers: {}, data: {} });
- const fakeAxios = { request: requestSpy } as unknown as AxiosInstance;
-
- const client = new AxiosHttpClient();
- await client.sendRequest({ method: HttpMethod.GET, url: 'https://api.example.com/data' }, fakeAxios);
-
- const calledConfig = requestSpy.mock.calls[0][0];
- expect(calledConfig.httpAgent?.constructor?.name).toBe('HttpProxyAgent');
- expect(calledConfig.httpsAgent?.constructor?.name).toBe('HttpsProxyAgent');
- expect(calledConfig.proxy).toBe(false);
- });
-
- it('honours lowercase http_proxy / https_proxy (curl-style env)', async () => {
- process.env['https_proxy'] = 'http://127.0.0.1:4444';
-
- const requestSpy = vi.fn().mockResolvedValue({ status: 200, headers: {}, data: {} });
- const fakeAxios = { request: requestSpy } as unknown as AxiosInstance;
-
- const client = new AxiosHttpClient();
- await client.sendRequest({ method: HttpMethod.GET, url: 'https://api.example.com/data' }, fakeAxios);
-
- const calledConfig = requestSpy.mock.calls[0][0];
- expect(calledConfig.httpsAgent?.constructor?.name).toBe('HttpsProxyAgent');
- });
-});
diff --git a/packages/server/api/test/unit/app/ai/ai-usage-conversation-credits.test.ts b/packages/server/api/test/unit/app/ai/ai-usage-conversation-credits.test.ts
index 5cd10230053..fc05492bd72 100644
--- a/packages/server/api/test/unit/app/ai/ai-usage-conversation-credits.test.ts
+++ b/packages/server/api/test/unit/app/ai/ai-usage-conversation-credits.test.ts
@@ -1,4 +1,4 @@
-import { ActivepiecesAiBillingScope, AIProviderName, apId } from '@activepieces/core-utils'
+import { ActivepiecesAiConsumerSource, AiChargeBasis, AIProviderName, apId } from '@activepieces/core-utils'
import { ReportAiUsageRequest } from '@activepieces/shared'
import { beforeEach, describe, expect, it, vi } from 'vitest'
@@ -33,7 +33,7 @@ function reportOf(billing: ReportAiUsageRequest['billing']): ReportAiUsageReques
provider: AIProviderName.ACTIVEPIECES,
modelId: 'anthropic/claude-sonnet-4.6',
idempotencyKey: apId(),
- usage: { type: 'observed-cost', costUsd: 0.005 },
+ usage: { type: AiChargeBasis.PROVIDER_REPORTED_COST, costUsd: 0.005 },
}
}
@@ -48,7 +48,7 @@ describe('aiUsageService.report — the conversation credit total', () => {
it('adds what a conversation-scoped call cost to that conversation, so a run shows its own total', async () => {
await aiUsageService(noopLogger as never).report(reportOf({
- scope: ActivepiecesAiBillingScope.CONVERSATION,
+ source: ActivepiecesAiConsumerSource.CHAT,
platformId: 'platform-1',
projectId: 'project-1',
conversationId: 'conversation-1',
@@ -59,7 +59,7 @@ describe('aiUsageService.report — the conversation credit total', () => {
it('accumulates rather than replaces, so several calls in one turn all count', async () => {
const billing = {
- scope: ActivepiecesAiBillingScope.CONVERSATION,
+ source: ActivepiecesAiConsumerSource.CHAT,
platformId: 'platform-1',
projectId: 'project-1',
conversationId: 'conversation-1',
@@ -71,11 +71,12 @@ describe('aiUsageService.report — the conversation credit total', () => {
expect(addConversationCredits).toHaveBeenLastCalledWith({ conversationId: 'conversation-1', credits: 10 })
})
- it('leaves a flow run alone, since the total belongs to a conversation', async () => {
+ it('leaves an ai step in a flow alone, since the total belongs to a conversation', async () => {
await aiUsageService(noopLogger as never).report(reportOf({
- scope: ActivepiecesAiBillingScope.PROJECT,
+ source: ActivepiecesAiConsumerSource.AI_STEP_IN_FLOW,
platformId: 'platform-1',
projectId: 'project-1',
+ flowRun: { flowId: 'flow-1', flowRunId: 'run-1' },
}))
expect(addConversationCredits).not.toHaveBeenCalled()
@@ -85,7 +86,7 @@ describe('aiUsageService.report — the conversation credit total', () => {
addConversationCredits.mockRejectedValue(new Error('conversation is gone'))
await aiUsageService(noopLogger as never).report(reportOf({
- scope: ActivepiecesAiBillingScope.CONVERSATION,
+ source: ActivepiecesAiConsumerSource.CHAT,
platformId: 'platform-1',
projectId: 'project-1',
conversationId: 'conversation-1',
diff --git a/packages/server/api/test/unit/app/core/canary/worker-group.service.test.ts b/packages/server/api/test/unit/app/core/canary/worker-group.service.test.ts
index 4f0ae98c6e3..9bc80a48d9e 100644
--- a/packages/server/api/test/unit/app/core/canary/worker-group.service.test.ts
+++ b/packages/server/api/test/unit/app/core/canary/worker-group.service.test.ts
@@ -1,23 +1,27 @@
import { FastifyBaseLogger } from 'fastify'
import { beforeEach, describe, expect, it, vi } from 'vitest'
-const mockFind = vi.fn()
const mockFindOne = vi.fn()
const mockUpdate = vi.fn()
vi.mock('../../../../../src/app/ee/platform/platform-plan/platform-plan.service', () => ({
platformPlanRepo: () => ({
- find: mockFind,
findOne: mockFindOne,
update: mockUpdate,
}),
}))
-const mockDistributedStoreGet = vi.fn()
-const mockDistributedStorePut = vi.fn()
-const mockDistributedStoreDelete = vi.fn()
+const cache = new Map<string, unknown>()
+const mockDistributedStoreGet = vi.fn(async (key: string) => cache.get(key) ?? null)
+const mockDistributedStorePut = vi.fn(async (key: string, value: unknown) => {
+ cache.set(key, value)
+})
+const mockDistributedStoreDelete = vi.fn(async (key: string) => {
+ cache.delete(key)
+})
vi.mock('../../../../../src/app/database/redis-connections', () => ({
+ redisConnections: { getRedisType: vi.fn().mockReturnValue('MEMORY') },
distributedStore: {
get: (...args: unknown[]) => mockDistributedStoreGet(...args),
put: (...args: unknown[]) => mockDistributedStorePut(...args),
@@ -39,6 +43,8 @@ const mockLog: FastifyBaseLogger = {
type WorkerGroupService = ReturnType<typeof import('../../../../../src/app/ee/platform/platform-plan/worker-group.service').workerGroupService>
+const CANARY_WORKER_GROUP_ID = 'canary'
+
async function loadService(): Promise<WorkerGroupService> {
const mod = await import('../../../../../src/app/ee/platform/platform-plan/worker-group.service')
return mod.workerGroupService(mockLog)
@@ -50,12 +56,12 @@ describe('workerGroupService', () => {
beforeEach(async () => {
vi.clearAllMocks()
vi.resetModules()
+ cache.clear()
service = await loadService()
})
describe('getWorkerGroupId', () => {
it('returns groupId from DB when not cached', async () => {
- mockDistributedStoreGet.mockResolvedValue(null)
mockFindOne.mockResolvedValue({ workerGroupId: 'canary' })
const result = await service.getWorkerGroupId({ platformId: 'p1' })
@@ -65,7 +71,6 @@ describe('workerGroupService', () => {
})
it('returns null and caches sentinel when platform has no worker group', async () => {
- mockDistributedStoreGet.mockResolvedValue(null)
mockFindOne.mockResolvedValue({ workerGroupId: null })
const result = await service.getWorkerGroupId({ platformId: 'p2' })
@@ -75,7 +80,7 @@ describe('workerGroupService', () => {
})
it('returns null without hitting DB when sentinel is cached', async () => {
- mockDistributedStoreGet.mockResolvedValue('__none__')
+ cache.set('platform:p3:worker_group_id:v2', '__none__')
const result = await service.getWorkerGroupId({ platformId: 'p3' })
@@ -84,7 +89,7 @@ describe('workerGroupService', () => {
})
it('returns cached value without hitting DB', async () => {
- mockDistributedStoreGet.mockResolvedValue('my-group')
+ cache.set('platform:p1:worker_group_id:v2', 'my-group')
const result = await service.getWorkerGroupId({ platformId: 'p1' })
@@ -94,83 +99,59 @@ describe('workerGroupService', () => {
})
describe('isCanaryPlatform', () => {
- it('returns true for canary platform', async () => {
- mockFind.mockResolvedValue([{ platformId: 'p1' }])
+ it('is true when the platform runs on the canary worker group', async () => {
+ mockFindOne.mockResolvedValue({ workerGroupId: CANARY_WORKER_GROUP_ID })
- const result = await service.isCanaryPlatform({ platformId: 'p1' })
-
- expect(result).toBe(true)
+ expect(await service.isCanaryPlatform({ platformId: 'p1' })).toBe(true)
})
- it('returns false for non-canary platform', async () => {
- mockFind.mockResolvedValue([{ platformId: 'p1' }])
-
- const result = await service.isCanaryPlatform({ platformId: 'p2' })
+ it('is false when the platform runs on another worker group', async () => {
+ mockFindOne.mockResolvedValue({ workerGroupId: 'not-canary' })
- expect(result).toBe(false)
+ expect(await service.isCanaryPlatform({ platformId: 'p1' })).toBe(false)
})
- it('caches after first call', async () => {
- mockFind.mockResolvedValue([{ platformId: 'p1' }])
-
- await service.isCanaryPlatform({ platformId: 'p1' })
- await service.isCanaryPlatform({ platformId: 'p1' })
+ it('is false when the platform has no worker group', async () => {
+ mockFindOne.mockResolvedValue({ workerGroupId: null })
- expect(mockFind).toHaveBeenCalledTimes(1)
+ expect(await service.isCanaryPlatform({ platformId: 'p1' })).toBe(false)
})
- it('concurrent calls only hit DB once', async () => {
- let resolveFind!: (value: { platformId: string }[]) => void
- mockFind.mockReturnValue(new Promise((resolve) => {
- resolveFind = resolve
- }))
-
- const promises = Array.from({ length: 10 }, () =>
- service.isCanaryPlatform({ platformId: 'p1' }),
- )
-
- await new Promise((r) => setTimeout(r, 50))
- resolveFind([{ platformId: 'p1' }])
+ it('answers from the cache on a repeat call, so the platform is read once', async () => {
+ mockFindOne.mockResolvedValue({ workerGroupId: CANARY_WORKER_GROUP_ID })
- const results = await Promise.all(promises)
+ await service.isCanaryPlatform({ platformId: 'p1' })
+ await service.isCanaryPlatform({ platformId: 'p1' })
- expect(mockFind).toHaveBeenCalledTimes(1)
- expect(results.every((r) => r === true)).toBe(true)
+ expect(mockFindOne).toHaveBeenCalledTimes(1)
})
})
describe('updateWorkerGroup', () => {
- it('invalidates cache', async () => {
- mockFind.mockResolvedValue([{ platformId: 'p1' }])
+ it('drops the cached group, so the next read sees the new one', async () => {
mockUpdate.mockResolvedValue(undefined)
- mockDistributedStoreGet.mockResolvedValue(null)
- mockDistributedStoreDelete.mockResolvedValue(undefined)
-
- await service.isCanaryPlatform({ platformId: 'p1' })
- expect(mockFind).toHaveBeenCalledTimes(1)
+ mockFindOne.mockResolvedValue({ workerGroupId: CANARY_WORKER_GROUP_ID })
+ expect(await service.getWorkerGroupId({ platformId: 'p1' })).toBe(CANARY_WORKER_GROUP_ID)
await service.updateWorkerGroup({ platformId: 'p1', workerGroupId: null })
- mockFind.mockResolvedValue([])
- await service.isCanaryPlatform({ platformId: 'p1' })
- expect(mockFind).toHaveBeenCalledTimes(2)
+ mockFindOne.mockResolvedValue({ workerGroupId: null })
+ expect(await service.getWorkerGroupId({ platformId: 'p1' })).toBeNull()
+ expect(mockFindOne).toHaveBeenCalledTimes(2)
})
})
- describe('disableAllCanary', () => {
- it('invalidates cache', async () => {
- mockFind.mockResolvedValue([{ platformId: 'p1' }])
+ describe('updateCanary', () => {
+ it('moves the platform onto the canary group and drops the cached value', async () => {
mockUpdate.mockResolvedValue(undefined)
- mockDistributedStoreDelete.mockResolvedValue(undefined)
-
- await service.isCanaryPlatform({ platformId: 'p1' })
- expect(mockFind).toHaveBeenCalledTimes(1)
+ mockFindOne.mockResolvedValue({ workerGroupId: null })
+ expect(await service.isCanaryPlatform({ platformId: 'p1' })).toBe(false)
- await service.disableAllCanary()
+ await service.updateCanary({ platformId: 'p1', canary: true })
- mockFind.mockResolvedValue([])
- await service.isCanaryPlatform({ platformId: 'p1' })
- expect(mockFind).toHaveBeenCalledTimes(3)
+ expect(mockUpdate).toHaveBeenCalledWith({ platformId: 'p1' }, { workerGroupId: CANARY_WORKER_GROUP_ID })
+ mockFindOne.mockResolvedValue({ workerGroupId: CANARY_WORKER_GROUP_ID })
+ expect(await service.isCanaryPlatform({ platformId: 'p1' })).toBe(true)
})
})
})
diff --git a/packages/server/api/test/unit/app/ee/agent/agent-rpc-handlers.test.ts b/packages/server/api/test/unit/app/ee/agent/agent-rpc-handlers.test.ts
index 91b2a348c72..15878e67757 100644
--- a/packages/server/api/test/unit/app/ee/agent/agent-rpc-handlers.test.ts
+++ b/packages/server/api/test/unit/app/ee/agent/agent-rpc-handlers.test.ts
@@ -1,5 +1,5 @@
import { ActivepiecesError, ErrorCode } from '@activepieces/core-utils'
-import { beforeEach, describe, expect, it, vi } from 'vitest'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
const { mockGetFlowRun, mockResumeFromWaitpoint } = vi.hoisted(() => ({
mockGetFlowRun: vi.fn(),
@@ -139,10 +139,11 @@ vi.mock('../../../../../src/app/ee/agent/chat-tool-billing', () => ({
chatToolBilling: { chargeForLatestTurn: mockTrack },
}))
+const { agentRpcHandlers } = await import('../../../../../src/app/ee/agent/agent-rpc-handlers')
+
const noopLogger = { info: vi.fn(), warn: vi.fn(), error: vi.fn(), debug: vi.fn() }
async function callUpdateChatProgress(input: { conversationId: string, runId?: string, uiMessages: unknown[], messages?: unknown[] }): Promise<void> {
- const { agentRpcHandlers } = await import('../../../../../src/app/ee/agent/agent-rpc-handlers')
await agentRpcHandlers(noopLogger as never).updateAgentProgress(input)
}
@@ -182,7 +183,6 @@ describe('agentRpcHandlers.updateAgentProgress — incremental LLM message persi
})
async function callSaveChatMessages(input: { conversationId: string, runId?: string, messages: unknown[], uiMessages: unknown[] }): Promise<void> {
- const { agentRpcHandlers } = await import('../../../../../src/app/ee/agent/agent-rpc-handlers')
await agentRpcHandlers(noopLogger as never).saveAgentMessages(input as never)
}
@@ -270,7 +270,6 @@ describe('agentRpcHandlers.saveAgentMessages — billing a row the run no longer
})
async function callExecuteAgentTool(input: { toolName: string, source: string }): Promise<unknown> {
- const { agentRpcHandlers } = await import('../../../../../src/app/ee/agent/agent-rpc-handlers')
return agentRpcHandlers(noopLogger as never).executeAgentTool({
toolName: input.toolName,
toolInput: {},
@@ -298,7 +297,6 @@ describe('agentRpcHandlers.executeAgentTool — chat-only tools are refused off
})
async function callUpdateProjectContext(input: { conversationId: string, runId?: string, projectId: string | null }): Promise<void> {
- const { agentRpcHandlers } = await import('../../../../../src/app/ee/agent/agent-rpc-handlers')
await agentRpcHandlers(noopLogger as never).updateProjectContext(input as never)
}
@@ -342,7 +340,6 @@ describe('agentRpcHandlers.updateProjectContext — a flow-step run stays in its
})
async function callGetAgentConfigFor(input: Record<string, unknown>): Promise<unknown> {
- const { agentRpcHandlers } = await import('../../../../../src/app/ee/agent/agent-rpc-handlers')
return agentRpcHandlers(noopLogger as never).getAgentConfig(input as never)
}
@@ -371,7 +368,7 @@ describe('agentRpcHandlers.getAgentConfig — a flow-step run creates its conver
})
it('does not create a second row when the run is retried', async () => {
- mockFindOneBy.mockResolvedValue({ id: 'conv-1', source: 'FLOW_STEP', projectId: 'proj-1', messages: [] })
+ mockFindOneBy.mockResolvedValue({ id: 'conv-1', source: 'FLOW_STEP', projectId: 'proj-1', platformId: 'plat-1', userId: 'owner-1', messages: [] })
await callGetAgentConfigFor({
conversationId: 'conv-1', platformId: 'plat-1', userId: 'owner-1',
@@ -385,7 +382,6 @@ describe('agentRpcHandlers.getAgentConfig — a flow-step run creates its conver
describe('agentRpcHandlers.executeAgentTool — the owner\'s own memory is not a flow-step target', () => {
it('refuses ap_remember for a flow-step run', async () => {
- const { agentRpcHandlers } = await import('../../../../../src/app/ee/agent/agent-rpc-handlers')
await expect(agentRpcHandlers(noopLogger as never).executeAgentTool({
toolName: 'ap_remember',
@@ -406,7 +402,6 @@ describe('agentRpcHandlers.executePieceTool — a configured action runs in its
mockResolveInput.mockClear()
mockFindOne.mockResolvedValue(conversation)
mockGetOneWithoutValue.mockResolvedValue({ id: 'ac-1', externalId: 'conn-1', displayName: 'Sales Inbox' })
- const { agentRpcHandlers } = await import('../../../../../src/app/ee/agent/agent-rpc-handlers')
return agentRpcHandlers(noopLogger as never).executePieceTool({
conversationId: 'conv-1',
toolName: 'send_email',
@@ -442,11 +437,18 @@ describe('agentRpcHandlers.executePieceTool — a configured action runs in its
})
describe('agentRpcHandlers.executeFlowTool — only a flow-step run may call a flow tool, scoped to its own project', () => {
+ // runFlowTool primes the conversation lookups for the whole describe; without this the
+ // primed value outlives it and a later describe resolves someone else's conversation.
+ afterEach(() => {
+ mockFindOne.mockResolvedValue(null)
+ mockFindOneBy.mockResolvedValue(null)
+ })
+
async function runFlowTool(conversation: unknown, flowId = 'flow-1', flowVersionId?: string) {
mockRunFlowAsTool.mockClear()
mockGetOnePopulated.mockClear()
mockFindOneBy.mockResolvedValue(conversation)
- const { agentRpcHandlers } = await import('../../../../../src/app/ee/agent/agent-rpc-handlers')
+ mockFindOne.mockResolvedValue(conversation)
return agentRpcHandlers(noopLogger as never).executeFlowTool({
conversationId: 'conv-1',
toolName: 'run_subflow',
@@ -555,7 +557,6 @@ describe('agentRpcHandlers.updateFlowStepProgress — only a flow-step run may r
mockGetFlowRun.mockClear()
mockGetFlowRun.mockResolvedValue({ id: 'run-1' })
mockFindOne.mockResolvedValue(conversation)
- const { agentRpcHandlers } = await import('../../../../../src/app/ee/agent/agent-rpc-handlers')
return agentRpcHandlers(noopLogger as never).updateFlowStepProgress({ conversationId: `conv-${++progressConversation}`, flowRunId: 'run-1', output: { steps: [] }, sequence: 1 })
}
@@ -588,7 +589,6 @@ describe('agentRpcHandlers.resumeFlowStep — only a flow-step run may release a
mockGetFlowRun.mockClear()
mockGetFlowRun.mockResolvedValue({ id: 'run-1' })
mockFindOneBy.mockResolvedValue(conversation)
- const { agentRpcHandlers } = await import('../../../../../src/app/ee/agent/agent-rpc-handlers')
return agentRpcHandlers(noopLogger as never).resumeFlowStep({
conversationId: 'conv-1', flowRunId: 'run-1', waitpointId: 'wp-1', output: { success: true },
})
@@ -610,7 +610,6 @@ describe('agentRpcHandlers.resumeFlowStep — only a flow-step run may release a
mockGetFlowRun.mockClear()
mockGetFlowRun.mockResolvedValue(null)
mockFindOneBy.mockResolvedValue({ id: 'conv-1', source: 'FLOW_STEP', projectId: 'proj-1' })
- const { agentRpcHandlers } = await import('../../../../../src/app/ee/agent/agent-rpc-handlers')
await expect(agentRpcHandlers(noopLogger as never).resumeFlowStep({
conversationId: 'conv-1', flowRunId: 'run-gone', waitpointId: 'wp-1', output: { success: true },
@@ -623,7 +622,6 @@ describe('agentRpcHandlers.resumeFlowStep — only a flow-step run may release a
mockGetFlowRun.mockClear()
mockGetFlowRun.mockResolvedValue(null)
mockFindOneBy.mockResolvedValue({ id: 'conv-1', source: 'FLOW_STEP', projectId: 'proj-own' })
- const { agentRpcHandlers } = await import('../../../../../src/app/ee/agent/agent-rpc-handlers')
await agentRpcHandlers(noopLogger as never).resumeFlowStep({
conversationId: 'conv-1', flowRunId: 'run-elsewhere', waitpointId: 'wp-1', output: {},
@@ -639,7 +637,6 @@ describe('agentRpcHandlers.resumeFlowStep — only a flow-step run may release a
code: ErrorCode.ENTITY_NOT_FOUND,
params: { entityType: 'flow_run', entityId: 'run-1', message: 'Flow run not found' },
}))
- const { agentRpcHandlers } = await import('../../../../../src/app/ee/agent/agent-rpc-handlers')
await expect(agentRpcHandlers(noopLogger as never).resumeFlowStep({
conversationId: 'conv-1', flowRunId: 'run-1', waitpointId: 'wp-1', output: {},
@@ -653,7 +650,6 @@ describe('agentRpcHandlers.resumeFlowStep — only a flow-step run may release a
code: ErrorCode.ENTITY_NOT_FOUND,
params: { entityType: 'waitpoint', entityId: 'wp-1', message: 'Waitpoint not found' },
}))
- const { agentRpcHandlers } = await import('../../../../../src/app/ee/agent/agent-rpc-handlers')
await expect(agentRpcHandlers(noopLogger as never).resumeFlowStep({
conversationId: 'conv-1', flowRunId: 'run-1', waitpointId: 'wp-1', output: {},
@@ -664,7 +660,6 @@ describe('agentRpcHandlers.resumeFlowStep — only a flow-step run may release a
mockGetFlowRun.mockResolvedValue({ id: 'run-1' })
mockFindOneBy.mockResolvedValue({ id: 'conv-1', source: 'FLOW_STEP', projectId: 'proj-1' })
mockResumeFromWaitpoint.mockRejectedValueOnce(new Error('lock timed out'))
- const { agentRpcHandlers } = await import('../../../../../src/app/ee/agent/agent-rpc-handlers')
await expect(agentRpcHandlers(noopLogger as never).resumeFlowStep({
conversationId: 'conv-1', flowRunId: 'run-1', waitpointId: 'wp-1', output: {},
@@ -703,7 +698,6 @@ describe('agentRpcHandlers.executeKnowledgeBaseTool — only a flow-step run may
mockGetFileOrThrow.mockClear().mockResolvedValue({ id: 'kb-1' })
mockKbSearch.mockClear().mockResolvedValue([])
mockFindOneBy.mockResolvedValue(conversation)
- const { agentRpcHandlers } = await import('../../../../../src/app/ee/agent/agent-rpc-handlers')
return agentRpcHandlers(noopLogger as never).executeKnowledgeBaseTool({
conversationId: 'conv-1', toolName: 'search_kb', knowledgeBaseFileId: 'kb-1', query: 'anything',
})
@@ -737,7 +731,6 @@ describe('agentRpcHandlers.executeKnowledgeBaseTool — an oversized embedding i
mockGetFileOrThrow.mockClear().mockResolvedValue({ id: 'kb-1' })
mockKbSearch.mockClear().mockResolvedValue([])
mockFindOneBy.mockResolvedValue({ id: 'conv-1', source: 'FLOW_STEP', projectId: 'proj-own', platformId: 'plat-1' })
- const { agentRpcHandlers } = await import('../../../../../src/app/ee/agent/agent-rpc-handlers')
await agentRpcHandlers(noopLogger as never).executeKnowledgeBaseTool({
conversationId: 'conv-1', toolName: 'search_kb', knowledgeBaseFileId: 'kb-1', query: 'anything',
@@ -756,7 +749,6 @@ describe('agentRpcHandlers.executePieceTool — which account a configured actio
mockGetOneWithoutValue.mockClear()
mockFindOne.mockResolvedValue(AGENT_CHAT)
mockGetOneWithoutValue.mockResolvedValue(pinnedExists ? { id: 'ac-1', externalId: PINNED, displayName: 'Sales Inbox' } : null)
- const { agentRpcHandlers } = await import('../../../../../src/app/ee/agent/agent-rpc-handlers')
const response = await agentRpcHandlers(noopLogger as never).executePieceTool({
conversationId: 'conv-1',
toolName: 'gmail-send_email',
diff --git a/packages/server/api/test/unit/app/workers/job-queue/active-invariant.test.ts b/packages/server/api/test/unit/app/workers/job-queue/active-invariant.test.ts
index ca866af0ecb..4014b88aa76 100644
--- a/packages/server/api/test/unit/app/workers/job-queue/active-invariant.test.ts
+++ b/packages/server/api/test/unit/app/workers/job-queue/active-invariant.test.ts
@@ -134,7 +134,9 @@ async function runSimulation(params: { queueName: string, workers: number, jobs:
}
}
+ const releaseBlockedPolls = setTimeout(() => dispatcher.close(), durationMs)
await Promise.all(Array.from({ length: workers }, (_, i) => workerLoop(`w${i + 1}`, i + 1)))
+ clearTimeout(releaseBlockedPolls)
stop = true
await sampler
@@ -168,6 +170,7 @@ describe('BullMQ active-list invariant: active <= total worker concurrency', ()
const res = await runSimulation({ queueName: 'repro-bug', workers: 4, jobs: 5000, reclaimOnStop: false, durationMs: 5000 })
// eslint-disable-next-line no-console
console.log('[abandon-on-stop] maxActive=%d totalConcurrency=%d completed=%d stops=%d', res.maxActive, res.totalConcurrency, res.completed, res.stops)
+ expect(res.stops).toBeGreaterThan(0)
expect(res.maxActive).toBeGreaterThan(res.totalConcurrency)
}, 60_000)
@@ -175,6 +178,8 @@ describe('BullMQ active-list invariant: active <= total worker concurrency', ()
const res = await runSimulation({ queueName: 'repro-fix', workers: 4, jobs: 5000, reclaimOnStop: true, durationMs: 5000 })
// eslint-disable-next-line no-console
console.log('[reclaim-on-stop] maxActive=%d totalConcurrency=%d completed=%d stops=%d', res.maxActive, res.totalConcurrency, res.completed, res.stops)
+ expect(res.completed).toBeGreaterThan(0)
+ expect(res.stops).toBeGreaterThan(0)
expect(res.maxActive).toBeLessThanOrEqual(res.totalConcurrency)
}, 60_000)
})
diff --git a/packages/server/api/test/unit/app/workers/job-queue/job-broker.test.ts b/packages/server/api/test/unit/app/workers/job-queue/job-broker.test.ts
index b555e290242..b247816b4e0 100644
--- a/packages/server/api/test/unit/app/workers/job-queue/job-broker.test.ts
+++ b/packages/server/api/test/unit/app/workers/job-queue/job-broker.test.ts
@@ -1,3 +1,4 @@
+import { ExecutionType, LATEST_JOB_DATA_SCHEMA_VERSION, RunEnvironment, StreamStepProgress, WorkerJobType } from '@activepieces/shared'
import { InterceptorVerdict } from '../../../../../src/app/workers/job-queue/job-interceptor'
import { Worker as BullMQWorker, Job } from 'bullmq'
import { FastifyBaseLogger } from 'fastify'
@@ -41,12 +42,30 @@ const mockLog: FastifyBaseLogger = {
level: 'info',
} as unknown as FastifyBaseLogger
+// tryDequeue zod-parses job data and fails anything that does not match, so the fixture
+// has to be a real job shape rather than two loose fields.
+const validExecuteFlowJobData = {
+ projectId: 'proj-1',
+ platformId: 'plat-1',
+ jobType: WorkerJobType.EXECUTE_FLOW,
+ executionType: ExecutionType.BEGIN,
+ environment: RunEnvironment.PRODUCTION,
+ schemaVersion: LATEST_JOB_DATA_SCHEMA_VERSION,
+ flowId: 'flow-1',
+ flowVersionId: 'flow-version-1',
+ runId: 'run-1',
+ payload: { type: 'inline' as const, value: null },
+ streamStepProgress: StreamStepProgress.NONE,
+ logsFileId: 'logs-1',
+}
+
function createMockJob(id: string, data?: Record<string, unknown>, deferredFailure?: string): Job {
return {
id,
name: `job-name-${id}`,
- data: { projectId: 'proj-1', platformId: 'plat-1', ...data },
+ data: { ...validExecuteFlowJobData, ...data },
attemptsMade: 0,
+ opts: { attempts: 2 },
deferredFailure,
moveToDelayed: vi.fn().mockResolvedValue(undefined),
moveToFailed: vi.fn().mockResolvedValue(undefined),
@@ -75,13 +94,30 @@ describe('tryDequeue', () => {
expect(result).not.toBeNull()
expect(result!.jobId).toBe('job-1')
expect(result!.engineToken).toBe('engine-token')
- expect(result!.timeoutInSeconds).toBe(600)
expect(result!.token).toMatch(/^token-/)
expect(result!.queueName).toBe('test-queue')
expect(job.updateData).not.toHaveBeenCalled()
expect(mockWorker.getNextJob).toHaveBeenCalledTimes(1)
})
+ it('should mark lastAttempt only once no retry remains', async () => {
+ const retryable = createMockJob('job-retryable')
+ vi.mocked(mockWorker.getNextJob).mockResolvedValueOnce(retryable)
+ mockPreDispatch.mockResolvedValueOnce({ verdict: InterceptorVerdict.ALLOW })
+
+ const firstAttempt = await tryDequeue(mockWorker, 'test-queue', mockLog)
+
+ expect(firstAttempt!.lastAttempt).toBe(false)
+
+ const exhausted = { ...createMockJob('job-exhausted'), attemptsMade: 1 } as unknown as Job
+ vi.mocked(mockWorker.getNextJob).mockResolvedValueOnce(exhausted)
+ mockPreDispatch.mockResolvedValueOnce({ verdict: InterceptorVerdict.ALLOW })
+
+ const finalAttempt = await tryDequeue(mockWorker, 'test-queue', mockLog)
+
+ expect(finalAttempt!.lastAttempt).toBe(true)
+ })
+
it('should retry when interceptor rejects then return next allowed job', async () => {
const jobA = createMockJob('job-a')
const jobB = createMockJob('job-b')
diff --git a/packages/server/api/test/unit/app/workers/machine/machine-service.test.ts b/packages/server/api/test/unit/app/workers/machine/machine-service.test.ts
index 2450946d95e..44ad7af3bd8 100644
--- a/packages/server/api/test/unit/app/workers/machine/machine-service.test.ts
+++ b/packages/server/api/test/unit/app/workers/machine/machine-service.test.ts
@@ -1,4 +1,4 @@
-import { ExecutionMode } from '@activepieces/shared'
+import { ApEdition, ExecutionMode } from '@activepieces/shared'
import { beforeEach, describe, expect, it, vi } from 'vitest'
vi.mock('../../../../../src/app/workers/machine/machine-cache', () => ({
@@ -12,10 +12,24 @@ vi.mock('../../../../../src/app/helper/system/system', () => ({
system: {
getOrThrow: vi.fn().mockReturnValue('test-value'),
getNumberOrThrow: vi.fn().mockReturnValue(60),
+ globalLogger: vi.fn(() => ({ info: vi.fn(), warn: vi.fn(), error: vi.fn(), debug: vi.fn() })),
+ getEdition: vi.fn().mockReturnValue(ApEdition.COMMUNITY),
+ getBoolean: vi.fn().mockReturnValue(undefined),
get: vi.fn().mockReturnValue(undefined),
},
}))
+vi.mock('../../../../../src/app/helper/pubsub', () => ({
+ pubsub: {
+ publish: vi.fn().mockResolvedValue(undefined),
+ subscribe: vi.fn().mockResolvedValue(undefined),
+ },
+}))
+
+vi.mock('../../../../../src/app/database/redis-connections', () => ({
+ redisConnections: { getRedisType: vi.fn().mockReturnValue('MEMORY') },
+}))
+
vi.mock('../../../../../src/app/helper/domain-helper', () => ({
domainHelper: {
getPublicUrl: vi.fn().mockResolvedValue('https://example.com'),
diff --git a/tools/scripts/test-filters.ts b/tools/scripts/test-filters.ts
new file mode 100644
index 00000000000..148be62ff83
--- /dev/null
+++ b/tools/scripts/test-filters.ts
@@ -0,0 +1,16 @@
+import { execSync } from 'node:child_process'
+import { readFileSync } from 'node:fs'
+import { join } from 'node:path'
+
+function packagesDefiningTest(): string[] {
+ const listed = execSync('npx turbo ls --filter=!api --output=json', { encoding: 'utf-8', stdio: ['ignore', 'pipe', 'ignore'] })
+ const { packages }: { packages: { items: { name: string, path: string }[] } } = JSON.parse(listed)
+ return packages.items
+ .filter(({ path }) => {
+ const { scripts }: { scripts?: Record<string, string> } = JSON.parse(readFileSync(join(path, 'package.json'), 'utf-8'))
+ return scripts?.test !== undefined
+ })
+ .map(({ name }) => name)
+}
+
+console.log(packagesDefiningTest().map((name) => `--filter=${name}`).join(' '))
diff --git a/turbo.json b/turbo.json
index 44111d9b577..6d17453a330 100644
--- a/turbo.json
+++ b/turbo.json
@@ -3,6 +3,8 @@
"globalPassThroughEnv": [
"AP_EDITION",
"AP_DB_TYPE",
+ "AP_REDIS_HOST",
+ "AP_REDIS_PORT",
"AP_POSTGRES_HOST",
"AP_POSTGRES_PORT",
"AP_POSTGRES_USERNAME",
@@ -113,6 +115,10 @@
"inputs": ["src/**", "test/**", "tsconfig*.json", "vitest.config.*"],
"outputs": ["coverage/**"]
},
+ "test-unit": {
+ "dependsOn": ["build"],
+ "cache": false
+ },
"test-ce": {
"dependsOn": ["build"],
"cache": false