forked from keithah/multi-provider-code-review
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction-mode.test.ts
More file actions
80 lines (74 loc) · 2.4 KB
/
Copy pathaction-mode.test.ts
File metadata and controls
80 lines (74 loc) · 2.4 KB
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
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import {
CODEX_OAUTH_ROTATING_MODE,
readPullRequestEvent,
shouldEnterCodexOAuthRotatingAction,
} from '../../../src/codex-oauth/action';
describe('Codex OAuth rotating action mode', () => {
it('enters rotating bootstrap for the top-level rotating action', () => {
expect(
shouldEnterCodexOAuthRotatingAction({
requestedMode: CODEX_OAUTH_ROTATING_MODE,
env: {},
})
).toBe(true);
});
it('does not re-enter rotating bootstrap inside the static review runtime', () => {
expect(
shouldEnterCodexOAuthRotatingAction({
requestedMode: CODEX_OAUTH_ROTATING_MODE,
env: { REVIEWROUTER_RUNTIME_CONFIG_MODE: 'static' },
})
).toBe(false);
});
it('ignores non-rotating modes', () => {
expect(
shouldEnterCodexOAuthRotatingAction({
requestedMode: 'runtime-preflight',
env: {},
})
).toBe(false);
});
it('binds workflow_dispatch reviews to the server-selected PR and head', () => {
const directory = fs.mkdtempSync(path.join(os.tmpdir(), 'rr-dispatch-'));
const eventPath = path.join(directory, 'event.json');
fs.writeFileSync(
eventPath,
JSON.stringify({
repository: { full_name: '777genius/agent-teams-ai' },
inputs: {
pr_number: '252',
review_head_sha: 'a'.repeat(40),
},
})
);
const previous = {
eventPath: process.env.GITHUB_EVENT_PATH,
eventName: process.env.GITHUB_EVENT_NAME,
repository: process.env.GITHUB_REPOSITORY,
};
process.env.GITHUB_EVENT_PATH = eventPath;
process.env.GITHUB_EVENT_NAME = 'workflow_dispatch';
process.env.GITHUB_REPOSITORY = '777genius/agent-teams-ai';
try {
expect(readPullRequestEvent()).toEqual({
repository: '777genius/agent-teams-ai',
number: 252,
headSha: 'a'.repeat(40),
headRef: '',
eventName: 'workflow_dispatch',
});
} finally {
restoreEnv('GITHUB_EVENT_PATH', previous.eventPath);
restoreEnv('GITHUB_EVENT_NAME', previous.eventName);
restoreEnv('GITHUB_REPOSITORY', previous.repository);
fs.rmSync(directory, { recursive: true, force: true });
}
});
});
function restoreEnv(name: string, value: string | undefined): void {
if (value === undefined) delete process.env[name];
else process.env[name] = value;
}