Skip to content

Commit 04bd483

Browse files
authored
fix: Prevent hanging on self-referential dependency loops (#1557)
1 parent efac182 commit 04bd483

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

src/executor.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export class Executor {
9898
if (j.when === "manual" && !manuals.includes(j.name)) {
9999
throw new AssertionError({message: chalk`{blueBright ${j.name}} is when:manual, its needed by {blueBright ${job.name}}, and not specified in --manual`});
100100
}
101+
assert(job.name !== j.name, chalk`This GitLab CI configuration is invalid: The pipeline has circular dependencies: self-dependency: {blueBright ${need.job}}.`);
101102
toWaitFor.push(j);
102103
}
103104
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
job:
3+
script:
4+
- echo
5+
needs:
6+
- job
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import {WriteStreamsMock} from "../../../src/write-streams.js";
2+
import {handler} from "../../../src/handler.js";
3+
import {initSpawnSpy} from "../../mocks/utils.mock.js";
4+
import {WhenStatics} from "../../mocks/when-statics.js";
5+
import {basename} from "node:path/posix";
6+
import {dirname} from "node:path";
7+
8+
const name = basename(dirname(import.meta.url));
9+
const cwd = `tests/test-cases/${name}`;
10+
11+
beforeAll(() => {
12+
initSpawnSpy(WhenStatics.all);
13+
});
14+
15+
it("should not hang the program", async () => {
16+
const writeStreams = new WriteStreamsMock();
17+
await expect(handler({cwd, noColor: true}, writeStreams)).rejects.toThrow("This GitLab CI configuration is invalid: The pipeline has circular dependencies: self-dependency: job.");
18+
});

0 commit comments

Comments
 (0)