n8n/packages/testing/playwright/utils/benchmark/webhook-driver.ts
Declan Carroll 3a33a448b0
Some checks failed
CI: Master (Build, Test, Lint) / Build for Github Cache (push) Has been cancelled
CI: Master (Build, Test, Lint) / Unit tests (22.x) (push) Has been cancelled
CI: Master (Build, Test, Lint) / Unit tests (24.14.1) (push) Has been cancelled
CI: Master (Build, Test, Lint) / Unit tests (25.x) (push) Has been cancelled
CI: Master (Build, Test, Lint) / Lint (push) Has been cancelled
CI: Master (Build, Test, Lint) / Performance (push) Has been cancelled
CI: Master (Build, Test, Lint) / Notify Slack on failure (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Prepare Docker (coverage) (push) Has been cancelled
Util: Update Node Popularity / approve-and-automerge (push) Has been cancelled
Test: E2E Coverage Weekly / E2E (coverage) (push) Has been cancelled
Test: E2E Coverage Weekly / Aggregate Coverage (push) Has been cancelled
Release: Schedule Patch Release PRs / Create patch release PR (${{ matrix.track }}) (beta) (push) Has been cancelled
Release: Schedule Patch Release PRs / Create patch release PR (${{ matrix.track }}) (stable) (push) Has been cancelled
Release: Schedule Patch Release PRs / Create patch release PR (${{ matrix.track }}) (v1) (push) Has been cancelled
test(benchmark): Question-driven Playwright benchmark suite with tiered topology and rich diagnostics (#29024)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 21:14:08 +00:00

74 lines
1.7 KiB
TypeScript

import { trigger } from '@n8n/workflow-sdk';
import type { IWorkflowBase } from 'n8n-workflow';
import { nanoid } from 'nanoid';
import type { PayloadSize, NodeOutputSize, TriggerScenario } from './types';
import { PAYLOAD_PROFILES, generatePayload } from './types';
import { buildChainedWorkflow } from './workflow-builder';
type WebhookResponseMode = 'onReceived' | 'lastNode';
export interface WebhookSetupContext {
scenario: {
nodeCount: number;
payloadSize: PayloadSize;
nodeOutputSize?: NodeOutputSize;
responseMode?: WebhookResponseMode;
};
}
export interface WebhookHandle {
workflow: Partial<IWorkflowBase>;
payload: object;
/** Scenario shape — surfaced for harness reporting. */
scenario: TriggerScenario;
}
/**
* Sets up a webhook-triggered benchmark workflow.
* Returns a handle with the workflow definition and payload to send.
*/
export function setupWebhook(ctx: WebhookSetupContext): WebhookHandle {
const path = `bench-${nanoid()}`;
const {
nodeCount,
payloadSize,
nodeOutputSize = 'noop',
responseMode = 'onReceived',
} = ctx.scenario;
const webhookTrigger = trigger({
type: 'n8n-nodes-base.webhook',
version: 2,
config: {
name: 'Webhook',
parameters: {
httpMethod: 'POST',
path,
responseMode,
options: {},
},
},
});
const label = nodeOutputSize === 'noop' ? 'noop' : `${nodeOutputSize}/node`;
const workflow = buildChainedWorkflow(
`Webhook Bench (${nodeCount} nodes, ${label}, ${responseMode})`,
webhookTrigger,
nodeCount,
nodeOutputSize,
);
const payload = generatePayload(PAYLOAD_PROFILES[payloadSize]);
return {
workflow,
payload,
scenario: {
nodeCount,
nodeOutputSize,
payloadSize,
},
};
}