Swadhin Biswas Feature/ai code reviewer (#79) · 8/16/2026
cfd400d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/**
* Contract: CI workflow trigger semantics (GitHub Actions compatibility)
*
* Guards `PipelineRunner.shouldTrigger` in `src/lib/pipeline.ts`.
* These semantics are what users' `.github/workflows/*.yml` files depend on.
*/
import { describe, expect, it } from "vitest";
import { PipelineRunner } from "@/lib/pipeline";
import { mkdtempSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
function parseWorkflow(yaml: string) {
const dir = mkdtempSync(join(tmpdir(), "och-workflow-contract-"));
const file = join(dir, "workflow.yml");
writeFileSync(file, yaml);
return new PipelineRunner({ workDir: dir }).parseWorkflow(file);
}
describe("workflow trigger contract", () => {
it("triggers push on matching branch", async () => {
const wf = await parseWorkflow(`
on:
push:
branches: [main, "release/*"]
jobs:
test:
runs-on: opencodehub
steps:
- run: echo ok
`);
const runner = new PipelineRunner({ workDir: "/tmp" });
expect(
runner.shouldTrigger(wf, "push", { ref: "refs/heads/main" }),
).toBe(true);
expect(
runner.shouldTrigger(wf, "push", { ref: "refs/heads/release/1.0" }),
).toBe(true);
expect(
runner.shouldTrigger(wf, "push", { ref: "refs/heads/dev" }),
).toBe(false);
});
it("respects branches-ignore", async () => {
const wf = await parseWorkflow(`
on:
push:
branches-ignore: [dev, "*.tmp"]
jobs:
test:
runs-on: opencodehub
steps:
- run: echo ok
`);
const runner = new PipelineRunner({ workDir: "/tmp" });
expect(
runner.shouldTrigger(wf, "push", { ref: "refs/heads/main" }),
).toBe(true);
expect(
runner.shouldTrigger(wf, "push", { ref: "refs/heads/dev" }),
).toBe(false);
expect(
runner.shouldTrigger(wf, "push", { ref: "refs/heads/foo.tmp" }),
).toBe(false);
});
it("triggers push on tag refs when tags filter present", async () => {
const wf = await parseWorkflow(`
on:
push:
tags: ["v*"]
jobs:
test:
runs-on: opencodehub
steps:
- run: echo ok
`);
const runner = new PipelineRunner({ workDir: "/tmp" });
expect(runner.shouldTrigger(wf, "push", { ref: "refs/tags/v1.0.0" })).toBe(
true,
);
expect(
runner.shouldTrigger(wf, "push", { ref: "refs/heads/v1.0.0" }),
).toBe(false);
});
it("applies path filters to changed files", async () => {
const wf = await parseWorkflow(`
on:
push:
paths: ["src/**", "!src/test/**"]
jobs:
test:
runs-on: opencodehub
steps:
- run: echo ok
`);
const runner = new PipelineRunner({ workDir: "/tmp" });
expect(
runner.shouldTrigger(wf, "push", {
ref: "refs/heads/main",
paths: ["src/lib/a.ts"],
}),
).toBe(true);
expect(
runner.shouldTrigger(wf, "push", {
ref: "refs/heads/main",
paths: ["README.md"],
}),
).toBe(false);
});
it("triggers pull_request only for listed activity types", async () => {
const wf = await parseWorkflow(`
on:
pull_request:
types: [opened, synchronize]
jobs:
test:
runs-on: opencodehub
steps:
- run: echo ok
`);
const runner = new PipelineRunner({ workDir: "/tmp" });
expect(
runner.shouldTrigger(wf, "pull_request", { action: "opened" }),
).toBe(true);
expect(
runner.shouldTrigger(wf, "pull_request", { action: "closed" }),
).toBe(false);
});
it("pull_request without types triggers on any action", async () => {
const wf = await parseWorkflow(`
on:
pull_request:
branches: [main]
jobs:
test:
runs-on: opencodehub
steps:
- run: echo ok
`);
const runner = new PipelineRunner({ workDir: "/tmp" });
expect(
runner.shouldTrigger(wf, "pull_request", {
action: "reopened",
ref: "refs/heads/main",
}),
).toBe(true);
expect(
runner.shouldTrigger(wf, "pull_request", {
action: "opened",
ref: "refs/heads/dev",
}),
).toBe(false);
});
it("workflow_dispatch always triggers", async () => {
const wf = await parseWorkflow(`
on: workflow_dispatch
jobs:
test:
runs-on: opencodehub
steps:
- run: echo ok
`);
const runner = new PipelineRunner({ workDir: "/tmp" });
expect(runner.shouldTrigger(wf, "workflow_dispatch", {})).toBe(true);
});
it("schedule trigger is recognized by the scheduler contract", async () => {
const wf = await parseWorkflow(`
on:
schedule:
- cron: "0 2 * * *"
jobs:
test:
runs-on: opencodehub
steps:
- run: echo ok
`);
const runner = new PipelineRunner({ workDir: "/tmp" });
expect(runner.shouldTrigger(wf, "schedule", {})).toBe(true);
expect(runner.shouldTrigger(wf, "push", { ref: "refs/heads/main" })).toBe(
false,
);
});
it("glob matching treats ** and * per GitHub semantics", async () => {
const wf = await parseWorkflow(`
on:
push:
branches: ["feature/**"]
jobs:
test:
runs-on: opencodehub
steps:
- run: echo ok
`);
const runner = new PipelineRunner({ workDir: "/tmp" });
expect(
runner.shouldTrigger(wf, "push", { ref: "refs/heads/feature/x" }),
).toBe(true);
expect(
runner.shouldTrigger(wf, "push", { ref: "refs/heads/feature/a/b" }),
).toBe(true);
expect(
runner.shouldTrigger(wf, "push", { ref: "refs/heads/features/x" }),
).toBe(false);
});
});