Files
streamline/scripts/probe_mr_comments.ts
2026-11-16 17:26:44 -08:00

59 lines
2.2 KiB
TypeScript

/**
* Dev probe: walk the Bits MR → Codebase comment chain for one MR and print
* every hop, so field-name drift on the Codebase side is diagnosable without
* redeploying the control plane.
*
* bun scripts/probe_mr_comments.ts <bitsMrId> [--raw]
*
* `--raw` dumps the ListThreads / MGetThreads payloads (truncated) — that's the
* one thing the normalizer in codebase.ts can't tell you when it comes back
* empty. Reads CODEBASE_PAT + BITS_TOKEN from .env.
*/
import { getMrCodebaseRef } from "../control-server/src/bits";
import { getMergeRequestId, listMrComments, renderMrCommentsBlock, codebaseConfigured } from "../control-server/src/codebase";
const mrId = Bun.argv[2];
const raw = Bun.argv.includes("--raw");
if (!mrId) {
console.error("usage: bun scripts/probe_mr_comments.ts <bitsMrId> [--raw]");
process.exit(2);
}
if (!codebaseConfigured()) {
console.error("CODEBASE_PAT is not set (see .env.example)");
process.exit(2);
}
const bridge = await getMrCodebaseRef(mrId);
console.log("① bits mr info →", JSON.stringify(bridge));
if (!bridge.ok || !bridge.ref) process.exit(1);
const resolved = await getMergeRequestId(bridge.ref.repoId, bridge.ref.changeId);
console.log("② codebase GetMergeRequest →", JSON.stringify(resolved));
if (raw) {
const res = await fetch(
`${process.env.CODEBASE_API_BASE || "https://codebase-api.byted.org"}/v2/?Action=ListThreads`,
{
method: "POST",
headers: { "Content-Type": "application/json", Authorization: `Bearer ${process.env.CODEBASE_PAT}` },
body: JSON.stringify({ CommentableType: "merge_request", CommentableId: resolved.mrId, RepoId: bridge.ref.repoId }),
},
);
console.log("③ raw ListThreads →", (await res.text()).slice(0, 4000));
}
const comments = await listMrComments({
repoId: bridge.ref.repoId,
mrId: resolved.mrId,
headCommitId: bridge.ref.headCommitId,
});
console.log("④ normalized →", JSON.stringify({
ok: comments.ok,
error: comments.error,
totalLive: comments.totalLive,
dropped: comments.dropped,
kept: comments.comments.length,
}, null, 1));
console.log("⑤ rendered block:\n");
console.log(renderMrCommentsBlock(comments, null) || "(empty)");