fix(ci): preserve per-job findings and unavailable blob evidence

This commit is contained in:
morluto
2026-10-14 06:23:22 +08:00
parent 0161a593e5
commit 22552525d5
4 changed files with 170 additions and 27 deletions
+10 -4
View File
@@ -87,10 +87,13 @@ export function classifyFailure({
"unknown",
"main_run_does_not_contain_the_same_structured_diagnostic",
);
if (!sameBlobEvidence(diagnostics, blobs))
const blobStatus = blobIdentityStatus(diagnostics, blobs);
if (blobStatus !== "identical")
return outcome(
"unknown",
"diagnostic_source_content_not_identical_at_main_and_tested_base",
blobStatus === "different"
? "diagnostic_source_content_not_identical_at_main_and_tested_base"
: "diagnostic_source_blob_identity_unavailable",
);
return outcome(
"matching-main-diagnostics",
@@ -366,9 +369,12 @@ function diagnosticKey(item) {
return JSON.stringify([item.kind, ...[...item.paths].sort()]);
return null;
}
function sameBlobEvidence(diagnostics, blobs) {
function blobIdentityStatus(diagnostics, blobs) {
const paths = [...new Set(diagnostics.flatMap(diagnosticPaths))];
return paths.length > 0 && paths.every((path) => blobs?.[path] === true);
if (paths.some((path) => blobs?.[path] === false)) return "different";
return paths.length > 0 && paths.every((path) => blobs?.[path] === true)
? "identical"
: "unavailable";
}
function sameTaskHashes(diagnostics, left, right) {
return diagnostics.every((diagnostic) => {
+27 -23
View File
@@ -153,16 +153,21 @@ async function analyzeFailedRun({
];
const failures = [];
for (const job of failedJobs) {
const evidence = await api.getStaticEvidence(repository, run, job);
const classification = await attributeToMain({
repository,
defaultBranch,
run,
job,
evidence,
mainCandidates,
api,
});
let classification;
try {
const evidence = await api.getStaticEvidence(repository, run, job);
classification = await attributeToMain({
repository,
defaultBranch,
run,
job,
evidence,
mainCandidates,
api,
});
} catch (error) {
classification = outcome("unknown", errorCode(error));
}
failures.push({
runId: entry.id,
runAttempt: entry.runAttempt,
@@ -415,26 +420,25 @@ export function createGitHubApi({
for (const path of paths) {
if (!validRepoPath(path)) continue;
const [left, right] = await Promise.all([
getContent(repository, ancestor, path, request),
getContent(repository, descendant, path, request),
getContentBlobSha(repository, ancestor, path, request),
getContentBlobSha(repository, descendant, path, request),
]);
result[path] = left !== null && left === right;
result[path] = left === right;
}
return result;
},
};
}
async function getContent(repository, ref, path, request) {
try {
const encodedPath = path.split("/").map(encodeURIComponent).join("/");
const value = await request(
`repos/${repository}/contents/${encodedPath}?ref=${encodeURIComponent(ref)}`,
);
return typeof value.sha === "string" ? value.sha : null;
} catch {
return null;
}
async function getContentBlobSha(repository, ref, path, request) {
const encodedPath = path.split("/").map(encodeURIComponent).join("/");
const value = await request(
`repos/${repository}/contents/${encodedPath}?ref=${encodeURIComponent(ref)}`,
);
const sha = safeSha(value?.sha);
if (value?.type !== "file" || sha === null)
throw new Error("github_content_blob_identity_unavailable");
return sha;
}
function outcome(classification, reason) {