Add ActionsEnv support to ActionState

This commit is contained in:
Michael B. Gale
2026-07-01 17:35:46 +01:00
parent 26e9e9e932
commit b009eac559
2 changed files with 19 additions and 2 deletions

View File

@@ -1,3 +1,4 @@
import { ActionsEnv } from "./actions-util";
import { Env } from "./environment";
import { FeatureEnablement } from "./feature-flags";
import { Logger } from "./logging";
@@ -12,6 +13,10 @@ export interface FeatureState {
/** Information about environment variables. */
env: Env;
};
Actions: {
/** Access to Actions-related functionality. */
actions: ActionsEnv;
};
FeatureFlags: {
/** Information about enabled feature flags. */
features: FeatureEnablement;

View File

@@ -11,7 +11,12 @@ import nock from "nock";
import * as sinon from "sinon";
import { ActionState, StateFeature } from "./action-common";
import { ActionsEnv, ActionsEnvVars, getActionVersion } from "./actions-util";
import {
ActionsEnv,
ActionsEnvVars,
getActionsEnv,
getActionVersion,
} from "./actions-util";
import { AnalysisKind } from "./analyses";
import * as apiClient from "./api-client";
import { GitHubApiDetails } from "./api-client";
@@ -190,7 +195,7 @@ export function getTestActionsEnv(): ActionsEnv {
}
/** For testing purposes, we make all available state features accessible in `TestEnv`. */
type AllState = ["Logger", "Env", "FeatureFlags"];
type AllState = ["Logger", "Env", "Actions", "FeatureFlags"];
/**
* Wraps a function that accepts an `ActionState` for testing in different environments.
@@ -218,6 +223,7 @@ export class TestEnv<
: {
logger: new RecordingLogger(),
env: getTestEnv(),
actions: getActionsEnv(),
features: createFeatures([]),
};
}
@@ -256,6 +262,12 @@ export class TestEnv<
return result;
}
public withActions(actions: ActionsEnv): TestEnv<Args, R, Fs> {
const result = this.clone();
result.state.actions = actions;
return result;
}
call(): R {
if (!this.args) {
throw new Error("Trying to call function in TestEnv without arguments.");