Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,9 @@ components:
- null
format: int64
description: Total duration in milliseconds (null if still running)
waitingForInput:
type: boolean
description: Whether the stage is waiting for user input
children:
type: array
items:
Expand Down
17 changes: 17 additions & 0 deletions src/main/frontend/common/components/status-icon.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,23 @@ describe("StatusIcon", () => {
expect(result.current).to.equal(0);
unmount();
});
it("should continue progress when waitingForInput is true", async () => {
const { result, unmount } = renderHook(() => {
return useStageProgress({
...mockStage,
state: Result.running,
startTimeMillis: now - 2_000,
previousTotalDurationMillis: 20_000,
waitingForInput: true,
});
});
expect(result.current).to.equal(10);
await act(() => vi.advanceTimersByTime(1_000));
expect(result.current).to.equal(15);
await act(() => vi.advanceTimersByTime(1_000));
expect(result.current).to.equal(20);
unmount();
});
});
describe("other states", function () {
for (const state in Result) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/frontend/common/components/status-icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ export function resultToColor(result: Result, skeleton: boolean | undefined) {
return "jenkins-!-accent-color";
case "unstable":
return "jenkins-!-warning-color";
case "paused":
return "jenkins-!-accent-color";
default:
return "jenkins-!-skipped-color";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export interface StageInfo {

skeleton?: boolean;
pauseLiveTotal?: boolean;
waitingForInput?: boolean;
}

interface BaseNodeInfo {
Expand Down
23 changes: 23 additions & 0 deletions src/main/frontend/setupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,26 @@ const IntersectionObserverMock = vi.fn(() => ({
}));

vi.stubGlobal("IntersectionObserver", IntersectionObserverMock);

// Ensure a functional localStorage implementation for tests that persist user preferences.
if (
!("localStorage" in window) ||
typeof window.localStorage?.getItem !== "function" ||
typeof window.localStorage?.setItem !== "function"
) {
const store: Record<string, string> = {};
const localStoragePolyfill = {
getItem: (key: string) => (key in store ? store[key] : null),
setItem: (key: string, value: string) => {
store[key] = String(value);
},
removeItem: (key: string) => {
delete store[key];
},
clear: () => {
Object.keys(store).forEach((k) => delete store[k]);
},
};
// @ts-expect-error override for test environment
window.localStorage = localStoragePolyfill;
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@
// these are completely new representations.
List<PipelineStageInternal> stages = getPipelineNodes(builder);

// Set the builder on each stage so they can check for paused steps
if (builder instanceof PipelineStepBuilderApi) {

Check warning on line 71 in src/main/java/io/jenkins/plugins/pipelinegraphview/utils/PipelineGraphApi.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 71 is only partially covered, one branch is missing
PipelineStepBuilderApi stepBuilder = (PipelineStepBuilderApi) builder;
stages.forEach(stage -> stage.setBuilder(stepBuilder));
}

// id => stage
Map<String, PipelineStageInternal> stageMap = stages.stream()
.collect(Collectors.toMap(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class PipelineStage extends AbstractPipelineNode {
private final boolean placeholder;
final String agent;
private final String url;
public final boolean waitingForInput;

public PipelineStage(
String id,
Expand All @@ -32,8 +33,9 @@ public PipelineStage(
boolean placeholder,
TimingInfo timingInfo,
String agent,
String runUrl) {
super(id, name, state, type, title, timingInfo);
String runUrl,
boolean waitingForInput) {
super(id, name, waitingForInput ? PipelineState.PAUSED : state, type, title, timingInfo);
this.children = children;
this.seqContainerName = seqContainerName;
this.nextSibling = nextSibling;
Expand All @@ -42,6 +44,7 @@ public PipelineStage(
this.placeholder = placeholder;
this.agent = agent;
this.url = "/" + runUrl + URL_NAME + "?selected-node=" + id;
this.waitingForInput = waitingForInput;
}

public static class PipelineStageJsonProcessor extends AbstractPipelineNodeJsonProcessor {
Expand All @@ -64,6 +67,7 @@ public JSONObject processBean(Object bean, JsonConfig config) {
json.element("placeholder", stage.placeholder);
json.element("agent", stage.agent);
json.element("url", stage.url);
json.element("waitingForInput", stage.waitingForInput);
return json;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
private boolean synthetic;
private TimingInfo timingInfo;
private String agent;
private PipelineStepBuilderApi builder;

public PipelineStageInternal(
String id,
Expand Down Expand Up @@ -113,7 +114,43 @@
this.agent = aAgent;
}

public void setBuilder(PipelineStepBuilderApi builder) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be avoided by doing the refactoring mentioned in PipelineGraphApi comment and then you could just pass the builder in the constructor (or another constructor) as I'd prefer not to be mutating state

this.builder = builder;
}

/**
* Checks if this stage or any of its children are waiting for input.
* A stage is waiting for input if any of its steps have a non-null inputStep
* and the step state is PAUSED.
*/
private boolean isWaitingForInput(List<PipelineStage> children) {
// Check if any child stages are waiting for input
if (children != null && !children.isEmpty()) {

Check warning on line 128 in src/main/java/io/jenkins/plugins/pipelinegraphview/utils/PipelineStageInternal.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 128 is only partially covered, one branch is missing
for (PipelineStage child : children) {
if (child.waitingForInput) {

Check warning on line 130 in src/main/java/io/jenkins/plugins/pipelinegraphview/utils/PipelineStageInternal.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 130 is only partially covered, one branch is missing
return true;

Check warning on line 131 in src/main/java/io/jenkins/plugins/pipelinegraphview/utils/PipelineStageInternal.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 131 is not covered by tests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we get some test coverage for this please?

A pipeline that sets an input step on it and validates the stage is now paused.

}
}
}

// Check steps for this stage
if (builder != null && id != null) {

Check warning on line 137 in src/main/java/io/jenkins/plugins/pipelinegraphview/utils/PipelineStageInternal.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 137 is only partially covered, 2 branches are missing
List<FlowNodeWrapper> steps = builder.getStageSteps(id);
if (steps != null) {

Check warning on line 139 in src/main/java/io/jenkins/plugins/pipelinegraphview/utils/PipelineStageInternal.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 139 is only partially covered, one branch is missing
for (FlowNodeWrapper step : steps) {
// Check if step has an input and is paused
if (step.getInputStep() != null && step.getStatus().state == BlueRun.BlueRunState.PAUSED) {

Check warning on line 142 in src/main/java/io/jenkins/plugins/pipelinegraphview/utils/PipelineStageInternal.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 142 is only partially covered, one branch is missing
return true;
}
}
}
}

return false;
}

public PipelineStage toPipelineStage(List<PipelineStage> children, String runUrl) {
boolean waitingForInput = isWaitingForInput(children);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we only do this check if there is an InputAction attached to the WorkflowRun?

I think that should be optimisable so this check is only run over stages that could be waiting for input?

return new PipelineStage(
id,
name,
Expand All @@ -128,6 +165,7 @@
synthetic && name.equals(Messages.FlowNodeWrapper_noStage()),
timingInfo,
agent,
runUrl);
runUrl,
waitingForInput);
}
}
Loading