chore: Move the shared runtime-credential getter into BaseExecuteContext (#39470)

Co-authored-by: n8n-cat-bot[bot] <n8n-cat-bot[bot]@users.noreply.github.com>
This commit is contained in:
n8n-cat-bot[bot] 2026-10-06 09:37:56 +00:00 committed by GitHub
parent 8b68b0fcdd
commit 05a992d4f2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 27 additions and 56 deletions

View File

@ -398,29 +398,6 @@ describe('ExecuteContext', () => {
});
});
describe('getRuntimeCredential', () => {
beforeEach(() => {
additionalData.getRuntimeCredential.mockReset();
});
it('forwards the alias to the additionalData callback and returns its value', async () => {
additionalData.getRuntimeCredential.mockResolvedValue('Bearer xyz');
const result = await executeContext.getRuntimeCredential('api_key');
expect(result).toBe('Bearer xyz');
expect(additionalData.getRuntimeCredential).toHaveBeenCalledWith(runExecutionData, 'api_key');
});
it('returns undefined when the underlying callback yields undefined', async () => {
additionalData.getRuntimeCredential.mockResolvedValue(undefined);
const result = await executeContext.getRuntimeCredential('missing');
expect(result).toBeUndefined();
});
});
describe('executeAgent', () => {
const webhookNode: INode = {
id: 'webhook-node-id',

View File

@ -199,27 +199,4 @@ describe('ExecuteSingleContext', () => {
]);
});
});
describe('getRuntimeCredential', () => {
beforeEach(() => {
additionalData.getRuntimeCredential.mockReset();
});
it('forwards the alias to the additionalData callback and returns its value', async () => {
additionalData.getRuntimeCredential.mockResolvedValue('Bearer xyz');
const result = await executeSingleContext.getRuntimeCredential('api_key');
expect(result).toBe('Bearer xyz');
expect(additionalData.getRuntimeCredential).toHaveBeenCalledWith(runExecutionData, 'api_key');
});
it('returns undefined when the underlying callback yields undefined', async () => {
additionalData.getRuntimeCredential.mockResolvedValue(undefined);
const result = await executeSingleContext.getRuntimeCredential('missing');
expect(result).toBeUndefined();
});
});
});

View File

@ -46,6 +46,29 @@ export const describeCommonTests = (
) => {
const additionalData = context.additionalData as MockProxy<IWorkflowExecuteAdditionalData>;
describe('getRuntimeCredential', () => {
beforeEach(() => {
additionalData.getRuntimeCredential.mockReset();
});
it('forwards the alias to the additionalData callback and returns its value', async () => {
additionalData.getRuntimeCredential.mockResolvedValue('Bearer xyz');
const result = await context.getRuntimeCredential('api_key');
expect(result).toBe('Bearer xyz');
expect(additionalData.getRuntimeCredential).toHaveBeenCalledWith(runExecutionData, 'api_key');
});
it('returns undefined when the underlying callback yields undefined', async () => {
additionalData.getRuntimeCredential.mockResolvedValue(undefined);
const result = await context.getRuntimeCredential('missing');
expect(result).toBeUndefined();
});
});
describe('getExecutionCancelSignal', () => {
it('should return the abort signal', () => {
expect(context.getExecutionCancelSignal()).toBe(abortSignal);

View File

@ -132,6 +132,10 @@ export class BaseExecuteContext extends NodeExecutionContext {
);
}
async getRuntimeCredential(alias: string): Promise<IDataObject[string] | undefined> {
return await this.additionalData.getRuntimeCredential(this.runExecutionData, alias);
}
async putExecutionToWait(
waitTill: Date,
options?: { acceptsResumeRequest?: boolean },

View File

@ -3,7 +3,6 @@ import type {
AINodeConnectionType,
CallbackManager,
CloseFunction,
IDataObject,
IExecuteData,
IExecuteFunctions,
IExecuteResponsePromiseData,
@ -126,10 +125,6 @@ export class ExecuteContext extends BaseExecuteContext implements IExecuteFuncti
)) as IExecuteFunctions['getNodeParameter'];
}
async getRuntimeCredential(alias: string): Promise<IDataObject[string] | undefined> {
return await this.additionalData.getRuntimeCredential(this.runExecutionData, alias);
}
async getInputConnectionData(
connectionType: AINodeConnectionType,
itemIndex: number,

View File

@ -11,7 +11,6 @@ import type {
WorkflowExecuteMode,
ITaskDataConnections,
IExecuteData,
IDataObject,
} from 'n8n-workflow';
import { UnexpectedError, NodeConnectionTypes } from 'n8n-workflow';
@ -87,10 +86,6 @@ export class ExecuteSingleContext extends BaseExecuteContext implements IExecute
};
}
async getRuntimeCredential(alias: string): Promise<IDataObject[string] | undefined> {
return await this.additionalData.getRuntimeCredential(this.runExecutionData, alias);
}
evaluateExpression(expression: string, itemIndex: number = this.itemIndex) {
return super.evaluateExpression(expression, itemIndex);
}