Skip to content

Commit 4ef36e5

Browse files
committed
fix(tests): harden tickets and linear alias CI behavior
1 parent c8991f9 commit 4ef36e5

2 files changed

Lines changed: 92 additions & 3 deletions

File tree

src/control-plane/extensions/tickets/tickets-git-channel.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,13 +1125,45 @@ async function runGit(opts: {
11251125
stdout: "pipe",
11261126
stderr: "pipe",
11271127
stdin: "ignore",
1128+
env: {
1129+
...process.env,
1130+
...resolveTicketGitIdentityEnv(),
1131+
},
11281132
});
11291133
const stdout = await new Response(proc.stdout).text();
11301134
const stderr = await new Response(proc.stderr).text();
11311135
const exitCode = await proc.exited;
11321136
return { ok: exitCode === 0, stdout, stderr };
11331137
}
11341138

1139+
function resolveTicketGitIdentityEnv(): Record<string, string> {
1140+
const authorName =
1141+
readOptionalEnv("GIT_AUTHOR_NAME") ??
1142+
readOptionalEnv("GIT_COMMITTER_NAME") ??
1143+
"hack tickets";
1144+
const authorEmail =
1145+
readOptionalEnv("GIT_AUTHOR_EMAIL") ??
1146+
readOptionalEnv("GIT_COMMITTER_EMAIL") ??
1147+
"tickets@hack.local";
1148+
const committerName = readOptionalEnv("GIT_COMMITTER_NAME") ?? authorName;
1149+
const committerEmail = readOptionalEnv("GIT_COMMITTER_EMAIL") ?? authorEmail;
1150+
return {
1151+
GIT_AUTHOR_NAME: authorName,
1152+
GIT_AUTHOR_EMAIL: authorEmail,
1153+
GIT_COMMITTER_NAME: committerName,
1154+
GIT_COMMITTER_EMAIL: committerEmail,
1155+
};
1156+
}
1157+
1158+
function readOptionalEnv(key: string): string | null {
1159+
const value = process.env[key];
1160+
if (typeof value !== "string") {
1161+
return null;
1162+
}
1163+
const trimmed = value.trim();
1164+
return trimmed.length > 0 ? trimmed : null;
1165+
}
1166+
11351167
function safeJsonParse(text: string): unknown {
11361168
try {
11371169
return JSON.parse(text);

tests/linear-command-alias.test.ts

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,57 @@
1-
import { expect, test } from "bun:test";
1+
import { afterEach, beforeEach, expect, test } from "bun:test";
2+
import { mkdtemp, rm, writeFile } from "node:fs/promises";
3+
import { tmpdir } from "node:os";
24
import { resolve } from "node:path";
35

6+
let tempDir: string | null = null;
7+
let tempGlobalConfigPath: string | null = null;
8+
let previousGlobalConfigPath: string | undefined;
9+
let previousHome: string | undefined;
10+
let previousLogger: string | undefined;
11+
let previousSetupSyncMode: string | undefined;
12+
13+
beforeEach(async () => {
14+
tempDir = await mkdtemp(resolve(tmpdir(), "hack-linear-alias-"));
15+
tempGlobalConfigPath = resolve(tempDir, "hack.config.json");
16+
previousGlobalConfigPath = process.env.HACK_GLOBAL_CONFIG_PATH;
17+
previousHome = process.env.HOME;
18+
previousLogger = process.env.HACK_LOGGER;
19+
previousSetupSyncMode = process.env.HACK_SETUP_SYNC_MODE;
20+
process.env.HACK_GLOBAL_CONFIG_PATH = tempGlobalConfigPath;
21+
process.env.HOME = tempDir;
22+
process.env.HACK_LOGGER = "console";
23+
process.env.HACK_SETUP_SYNC_MODE = "off";
24+
await writeFile(tempGlobalConfigPath, "{}\n");
25+
});
26+
27+
afterEach(async () => {
28+
if (tempDir) {
29+
await rm(tempDir, { recursive: true, force: true });
30+
}
31+
tempDir = null;
32+
tempGlobalConfigPath = null;
33+
if (previousGlobalConfigPath === undefined) {
34+
process.env.HACK_GLOBAL_CONFIG_PATH = undefined;
35+
} else {
36+
process.env.HACK_GLOBAL_CONFIG_PATH = previousGlobalConfigPath;
37+
}
38+
if (previousHome === undefined) {
39+
process.env.HOME = undefined;
40+
} else {
41+
process.env.HOME = previousHome;
42+
}
43+
if (previousLogger === undefined) {
44+
process.env.HACK_LOGGER = undefined;
45+
} else {
46+
process.env.HACK_LOGGER = previousLogger;
47+
}
48+
if (previousSetupSyncMode === undefined) {
49+
process.env.HACK_SETUP_SYNC_MODE = undefined;
50+
} else {
51+
process.env.HACK_SETUP_SYNC_MODE = previousSetupSyncMode;
52+
}
53+
});
54+
455
test("hack linear alias forwards extension options like --json", async () => {
556
const proc = Bun.spawn(
657
[
@@ -11,8 +62,14 @@ test("hack linear alias forwards extension options like --json", async () => {
1162
"--json",
1263
],
1364
{
14-
cwd: resolve(import.meta.dir, ".."),
15-
env: process.env,
65+
cwd: tempDir ?? resolve(import.meta.dir, ".."),
66+
env: {
67+
...process.env,
68+
HACK_GLOBAL_CONFIG_PATH: tempGlobalConfigPath ?? "",
69+
HACK_LOGGER: "console",
70+
HACK_SETUP_SYNC_MODE: "off",
71+
HOME: tempDir ?? process.env.HOME ?? "",
72+
},
1673
stdin: "ignore",
1774
stdout: "pipe",
1875
stderr: "pipe",

0 commit comments

Comments
 (0)