5 Commits

Author SHA1 Message Date
Danny Kim ca619888b2 Drop Node override entries that repeat global rules
Check / check (pull_request) Successful in 39s
2026-10-20 01:53:33 +09:00
Danny Kim df09c9c741 Rewrap the testing module comment 2026-10-20 01:53:32 +09:00
Danny Kim 98138fc7a1 Read named capture groups by name 2026-10-20 01:53:32 +09:00
Danny Kim bcb0e0cc70 Accept lowercase profile types and anchor sides when reading 2026-10-20 01:53:32 +09:00
Danny Kim 13efaccb17 Show lowercase profile names in posted comments 2026-10-20 01:53:32 +09:00
10 changed files with 66 additions and 30 deletions
-6
View File
@@ -805,12 +805,6 @@ const rules: DummyRuleMap = {
const nodeRules: DummyRuleMap = { const nodeRules: DummyRuleMap = {
// Vite and the Oxlint plugin host read a default export. // Vite and the Oxlint plugin host read a default export.
"import/no-default-export": "off", "import/no-default-export": "off",
// Node code: tooling imports Node's built-ins.
"import/no-nodejs-modules": "off",
// Node code: a CLI exits with a status.
"unicorn/no-process-exit": "off",
// Node code: a CLI reports through the console.
"no-console": "off",
}; };
/** /**
+8 -8
View File
@@ -147,7 +147,7 @@ test("posts a successful issue result and removes runtime credentials", async ()
const [request] = requests; const [request] = requests;
expect(request?.url).toStrictEqual(`${context.apiUrl}/repos/owner/repo/issues/7/comments`); expect(request?.url).toStrictEqual(`${context.apiUrl}/repos/owner/repo/issues/7/comments`);
expect(requestBody(request?.init)).toStrictEqual({ expect(requestBody(request?.init)).toStrictEqual({
body: "done\n\n> Profile: `CODEX` · `gpt-test`", body: "done\n\n> Profile: `codex` · `gpt-test`",
}); });
expect(request?.init?.headers).toStrictEqual({ expect(request?.init?.headers).toStrictEqual({
Authorization: "token reviewer-secret", Authorization: "token reviewer-secret",
@@ -178,11 +178,11 @@ test("retries a rejected inline review without anchors", async () => {
); );
expect(bodies[0]).toMatchObject({ expect(bodies[0]).toMatchObject({
comments: [{ body: "Finding\n\n> Profile: `CODEX` · `gpt-test`" }], comments: [{ body: "Finding\n\n> Profile: `codex` · `gpt-test`" }],
}); });
expect(bodies[1]).toMatchObject({ expect(bodies[1]).toMatchObject({
comments: [], comments: [],
body: "✅ Approved\nReady\n\n> Profile: `CODEX` · `gpt-test`", body: "✅ Approved\nReady\n\n> Profile: `codex` · `gpt-test`",
}); });
assert(await missing(result.runtimeDir)); assert(await missing(result.runtimeDir));
}); });
@@ -205,9 +205,9 @@ test("reports each tried profile and keeps the action failed", async () => {
expect(bodies).toStrictEqual([ expect(bodies).toStrictEqual([
{ {
body: body:
"AI bot failed.\n\n> Tried: `CODEX` · `gpt-test` (sign-in failed), " + "AI bot failed.\n\n> Tried: `codex` · `gpt-test` (sign-in failed), " +
"`CLAUDE` · `claude-test` (usage exhausted), " + "`claude` · `claude-test` (usage exhausted), " +
"`OPENCODE` · `openrouter/test` (failed)", "`opencode` · `openrouter/test` (failed)",
}, },
]); ]);
assert(!JSON.stringify(bodies).includes("reviewer-secret")); assert(!JSON.stringify(bodies).includes("reviewer-secret"));
@@ -235,7 +235,7 @@ test("drops failure entries that are not known labels", async () => {
expect(bodies).toStrictEqual([ expect(bodies).toStrictEqual([
{ {
body: "AI bot failed.\n\n> Tried: `CLAUDE` · `claude-test` (sign-in failed)", body: "AI bot failed.\n\n> Tried: `claude` · `claude-test` (sign-in failed)",
}, },
]); ]);
}); });
@@ -315,7 +315,7 @@ test("reports an attributed failure when a pull request review is missing", asyn
expect(bodies).toStrictEqual([ expect(bodies).toStrictEqual([
{ {
body: "AI bot failed.\n\n> Tried: `CODEX` · `gpt-test` (failed)", body: "AI bot failed.\n\n> Tried: `codex` · `gpt-test` (failed)",
}, },
]); ]);
assert(await missing(result.runtimeDir)); assert(await missing(result.runtimeDir));
+6 -1
View File
@@ -28,6 +28,11 @@ const VERDICTS = new Map<string, [event: string, mark: string]>([
]); ]);
const PROFILE_TYPES = new Set<unknown>(["CLAUDE", "CODEX", "OPENCODE"]); const PROFILE_TYPES = new Set<unknown>(["CLAUDE", "CODEX", "OPENCODE"]);
const FAILURE_REASONS = new Set<unknown>(["SIGN_IN_FAILED", "USAGE_EXHAUSTED", "FAILED"]); const FAILURE_REASONS = new Set<unknown>(["SIGN_IN_FAILED", "USAGE_EXHAUSTED", "FAILED"]);
// Anchors written before the UPPER_SNAKE switch spell sides in lowercase.
const OLD_SIDES = new Map<unknown, Anchor["side"]>([
["new", "NEW"],
["old", "OLD"],
]);
const isProfileType = (value: unknown): value is ProfileFailure["type"] => PROFILE_TYPES.has(value); const isProfileType = (value: unknown): value is ProfileFailure["type"] => PROFILE_TYPES.has(value);
const isFailureReason = (value: unknown): value is FailureReason => FAILURE_REASONS.has(value); const isFailureReason = (value: unknown): value is FailureReason => FAILURE_REASONS.has(value);
const failureComment = (failures: ProfileFailure[]): string => const failureComment = (failures: ProfileFailure[]): string =>
@@ -56,7 +61,7 @@ function parseAnchors(text: string, sourcePath: string): Anchor[] {
const path = field(entry, "path"); const path = field(entry, "path");
const line = field(entry, "line"); const line = field(entry, "line");
const givenSide = field(entry, "side"); const givenSide = field(entry, "side");
const side = givenSide === undefined ? "NEW" : givenSide; const side = givenSide === undefined ? "NEW" : (OLD_SIDES.get(givenSide) ?? givenSide);
const body = field(entry, "body"); const body = field(entry, "body");
if (typeof path !== "string" || path === "") { if (typeof path !== "string" || path === "") {
throw new TypeError(`${at}.path: expected a repository path`); throw new TypeError(`${at}.path: expected a repository path`);
+2 -2
View File
@@ -6,8 +6,8 @@ import { isNotFound } from "#common";
import type { RuntimeProfile } from "#runtime"; import type { RuntimeProfile } from "#runtime";
export function isRunnableProfileProcess(status: string, uid: number): boolean { export function isRunnableProfileProcess(status: string, uid: number): boolean {
const owner = /^Uid:\s+(?<uid>\d+)/mu.exec(status)?.[1]; const owner = /^Uid:\s+(?<uid>\d+)/mu.exec(status)?.groups?.["uid"];
const state = /^State:\s+(?<state>\w)/mu.exec(status)?.[1]; const state = /^State:\s+(?<state>\w)/mu.exec(status)?.groups?.["state"];
return owner !== undefined && Number(owner) === uid && state !== "Z"; return owner !== undefined && Number(owner) === uid && state !== "Z";
} }
+3 -3
View File
@@ -12,7 +12,7 @@ import {
test("formats profile attribution as a Markdown quote", () => { test("formats profile attribution as a Markdown quote", () => {
expect(profileFooter({ type: "OPENCODE", model: "openrouter/qwen/qwen3.8-27b" })).toBe( expect(profileFooter({ type: "OPENCODE", model: "openrouter/qwen/qwen3.8-27b" })).toBe(
"> Profile: `OPENCODE` · `openrouter/qwen/qwen3.8-27b`", "> Profile: `opencode` · `openrouter/qwen/qwen3.8-27b`",
); );
}); });
@@ -105,8 +105,8 @@ test("falls through after a sign-in failure and records each try", async () => {
{ type: "CLAUDE", model: "claude-sonnet-5", reason: "USAGE_EXHAUSTED" }, { type: "CLAUDE", model: "claude-sonnet-5", reason: "USAGE_EXHAUSTED" },
]); ]);
expect(failureFooter(failures)).toStrictEqual( expect(failureFooter(failures)).toStrictEqual(
"> Tried: `CODEX` · `gpt-5.6-terra` (sign-in failed), " + "> Tried: `codex` · `gpt-5.6-terra` (sign-in failed), " +
"`CLAUDE` · `claude-sonnet-5` (usage exhausted)", "`claude` · `claude-sonnet-5` (usage exhausted)",
); );
}); });
+16 -2
View File
@@ -8,8 +8,20 @@ export interface BotProfile extends ProfileIdentity {
token?: string; token?: string;
} }
// The lowercase name a profile type reads as in posted comments.
function profileName(type: ProfileIdentity["type"]): string {
switch (type) {
case "CLAUDE":
return "claude";
case "CODEX":
return "codex";
case "OPENCODE":
return "opencode";
}
}
export function profileFooter(profile: ProfileIdentity): string { export function profileFooter(profile: ProfileIdentity): string {
return `> Profile: \`${profile.type}\` · \`${profile.model}\``; return `> Profile: \`${profileName(profile.type)}\` · \`${profile.model}\``;
} }
export function withProfile(body: string, profile: ProfileIdentity): string { export function withProfile(body: string, profile: ProfileIdentity): string {
@@ -66,7 +78,9 @@ export function failureFooter(failures: ProfileFailure[]): string {
return "> Profile: none"; return "> Profile: none";
} }
return `> Tried: ${failures return `> Tried: ${failures
.map(({ type, model, reason }) => `\`${type}\` · \`${model}\` (${toMessage(reason)})`) .map(
({ type, model, reason }) => `\`${profileName(type)}\` · \`${model}\` (${toMessage(reason)})`,
)
.join(", ")}`; .join(", ")}`;
} }
+5 -4
View File
@@ -211,10 +211,11 @@ async function renderPrompt(profile: RuntimeProfile): Promise<RenderedPrompt> {
]); ]);
const template = await readFile(new URL("../../prompt.md", import.meta.url), "utf8"); const template = await readFile(new URL("../../prompt.md", import.meta.url), "utf8");
return { return {
prompt: template.replaceAll( prompt: template.replaceAll(/\$\{(?<name>\w+)\}/gu, (match: string, ...args: unknown[]) => {
/\$\{(?<name>\w+)\}/gu, const groups = args.at(-1);
(match: string, name: string) => values.get(name) ?? match, const name = isObject(groups) ? field(groups, "name") : undefined;
), return typeof name === "string" ? (values.get(name) ?? match) : match;
}),
reviewPath, reviewPath,
anchorsPath, anchorsPath,
}; };
+11
View File
@@ -65,3 +65,14 @@ test("rejects malformed central credentials", async () => {
), ),
).rejects.toThrow("profiles[0].token"); ).rejects.toThrow("profiles[0].token");
}); });
test("reads lowercase profile types from older credentials", async () => {
const credentials = await parseCredentials(
JSON.stringify({
"reviewer-token": ENCRYPTED,
profiles: [{ type: "codex" }, { type: "claude", token: ENCRYPTED }],
}),
MASTER_KEY,
);
expect(credentials.profiles.map(({ type }) => type)).toStrictEqual(["CODEX", "CLAUDE"]);
});
+12 -1
View File
@@ -78,6 +78,17 @@ export async function encryptCredential(
return `v1:${encodeBase64Url(nonce)}:${encodeBase64Url(new Uint8Array(ciphertext))}`; return `v1:${encodeBase64Url(nonce)}:${encodeBase64Url(new Uint8Array(ciphertext))}`;
} }
// profiles.json files written before the UPPER_SNAKE switch spell types in lowercase.
const OLD_PROFILE_TYPES = new Map<unknown, BotProfile["type"]>([
["claude", "CLAUDE"],
["codex", "CODEX"],
["opencode", "OPENCODE"],
]);
function currentSpelling(type: unknown): unknown {
return OLD_PROFILE_TYPES.get(type) ?? type;
}
async function parseProfile(entry: unknown, index: number, masterKey: string): Promise<BotProfile> { async function parseProfile(entry: unknown, index: number, masterKey: string): Promise<BotProfile> {
const at = `profiles[${index}]`; const at = `profiles[${index}]`;
if (!isMapping(entry)) { if (!isMapping(entry)) {
@@ -88,7 +99,7 @@ async function parseProfile(entry: unknown, index: number, masterKey: string): P
throw new Error(`${at}.${key}: unknown field`); throw new Error(`${at}.${key}: unknown field`);
} }
} }
const type = field(entry, "type"); const type = currentSpelling(field(entry, "type"));
const model = field(entry, "model"); const model = field(entry, "model");
const token = field(entry, "token"); const token = field(entry, "token");
if (type !== "CLAUDE" && type !== "CODEX" && type !== "OPENCODE") { if (type !== "CLAUDE" && type !== "CODEX" && type !== "OPENCODE") {
+3 -3
View File
@@ -1,7 +1,7 @@
// Test support: the current user's IDs, a fresh temporary directory, the // Test support: the current user's IDs, a fresh temporary directory, the
// inherited environment, and a plain command runner. It imports no source module, so the repository-level // inherited environment, and a plain command runner. It imports no source
// tests in tests/, which reach src/ only through `#testing`, never touch // module, so the repository-level tests in tests/, which reach src/ only
// internals. // through `#testing`, never touch internals.
import { spawn } from "node:child_process"; import { spawn } from "node:child_process";
import { once } from "node:events"; import { once } from "node:events";
import { mkdtemp } from "node:fs/promises"; import { mkdtemp } from "node:fs/promises";