Merge remote-tracking branch 'origin/main' into fix/issue-2671

This commit is contained in:
Kaoru0822
2026-10-14 00:22:25 +00:00
558 changed files with 102097 additions and 35189 deletions
+67
View File
@@ -0,0 +1,67 @@
import type { NormalizedWorkflowRun } from "./workflow-run.mjs";
import type { StaticTaskContext } from "./static-task-context.mjs";
export type { StaticTaskContext } from "./static-task-context.mjs";
export interface StaticDiagnostic {
readonly kind: "lint" | "jscpd";
readonly path?: string;
readonly paths?: readonly string[];
readonly code?: string;
readonly message?: string;
readonly severity?: string;
}
export function classifyFailure(input: {
repository: string;
defaultBranch: string;
run: Record<string, unknown> & NormalizedWorkflowRun;
job: Record<string, unknown>;
diagnostics: readonly StaticDiagnostic[];
context: StaticTaskContext;
mainRun: Record<string, unknown> & NormalizedWorkflowRun;
mainJob: Record<string, unknown>;
mainDiagnostics: readonly StaticDiagnostic[];
mainContext: StaticTaskContext;
executionSourcesVerified: boolean;
ancestry: { status: string; mergeBaseSha: string | null };
blobs: Readonly<Record<string, boolean>>;
}): {
classification: "matching-main-diagnostics" | "unknown";
reason: string;
};
export function diagnosticPaths(item: StaticDiagnostic): readonly string[];
export function isFailedConclusion(
value: unknown,
): value is "failure" | "timed_out";
export function isEligibleMainRun(
run: Record<string, unknown>,
defaultBranch: string,
repository: string,
): boolean;
export function pullRequestBaseSha(
run: Record<string, unknown>,
repository: string,
): string | null;
export function safeSha(value: unknown): string | null;
export function validRepoPath(value: unknown): value is string;
export function selectStaticCheckArtifact(
page: unknown,
run: { id?: string | number; head_sha?: string },
runAttempt: number,
): unknown | null;
export function readStaticCheckArtifact(options: {
repository: string;
artifactId: number | string;
token: string;
fetchImpl?: typeof fetch;
}): Promise<{
context: StaticTaskContext;
diagnostics: readonly StaticDiagnostic[];
}>;
export function parseStaticArchive(archivePath: string): Promise<{
context: StaticTaskContext;
diagnostics: readonly StaticDiagnostic[];
}>;
+442
View File
@@ -0,0 +1,442 @@
import { execFile } from "node:child_process";
import { mkdtemp, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { isAbsolute, join } from "node:path";
import { promisify } from "node:util";
import { parseStaticTaskContext } from "./static-task-context.mjs";
const execute = promisify(execFile);
const MAX_ARCHIVE_BYTES = 32 * 1024 * 1024;
const MAX_MEMBER_BYTES = 4 * 1024 * 1024;
const MAX_DIAGNOSTICS = 10_000;
const API_ROOT = "https://api.github.com/repos";
const SHA = /^[0-9a-f]{40}$/iu;
const TASK_HASH = /^[a-f0-9]{16}$/u;
/** Compare parsed static diagnostics only after source, task, host, and ancestry proof. */
export function classifyFailure({
repository,
defaultBranch,
run,
job,
diagnostics,
context,
mainRun,
mainJob,
mainDiagnostics,
mainContext,
executionSourcesVerified,
ancestry,
blobs,
}) {
const failedGate = firstFailure([
() => [
!isCompletedFailure(run) ||
job?.status !== "completed" ||
!isFailedConclusion(job?.conclusion),
"run_or_job_not_a_completed_failure",
],
() => [
!isEligiblePullRun(run, repository) ||
!isEligibleMainRun(mainRun, defaultBranch, repository),
"run_event_or_repository_identity_unverified",
],
() => [
job?.name !== mainJob?.name || job?.name !== "Static checks",
"failed_job_not_the_same_static_gate",
],
() => [
!Array.isArray(diagnostics) ||
diagnostics.length === 0 ||
!Array.isArray(mainDiagnostics),
"structured_diagnostics_missing_or_invalid",
],
() => [
!validContext(context) || !validContext(mainContext),
"static_task_context_missing_or_invalid",
],
() => [
executionSourcesVerified !== true,
"checkout_sources_not_verified_against_api_commits",
],
() => [
!sameExecutionContext(context, mainContext),
"task_or_toolchain_identity_differs",
],
() => [
ancestry?.status !== "ahead" && ancestry?.status !== "identical",
"main_head_not_proven_ancestor_of_tested_base",
],
() => [
ancestry?.mergeBaseSha !== mainRun?.head_sha,
"main_head_is_not_the_verified_merge_base",
],
() => [
!sameTaskHashes(diagnostics, context, mainContext),
"owning_task_hash_differs",
],
]);
if (failedGate) return outcome("unknown", failedGate.reason);
const keys = diagnostics.map(diagnosticKey);
const mainKeys = new Set(mainDiagnostics.map(diagnosticKey).filter(Boolean));
if (keys.some((key) => key === null))
return outcome("unknown", "diagnostic_shape_not_supported");
if (!keys.every((key) => mainKeys.has(key)))
return outcome(
"unknown",
"main_run_does_not_contain_the_same_structured_diagnostic",
);
const blobStatus = blobIdentityStatus(diagnostics, blobs);
if (blobStatus !== "identical")
return outcome(
"unknown",
blobStatus === "different"
? "diagnostic_source_content_not_identical_at_main_and_tested_base"
: "diagnostic_source_blob_identity_unavailable",
);
return outcome(
"matching-main-diagnostics",
"supported_diagnostics_match_failed_task_and_source_on_verified_main_ancestor",
);
}
export function diagnosticPaths(item) {
return item.kind === "jscpd" ? item.paths : [item.path];
}
export function isFailedConclusion(value) {
return value === "failure" || value === "timed_out";
}
export function isEligibleMainRun(run, defaultBranch, repository) {
return (
isEligibleStaticRun(run) &&
run.repository.full_name === repository &&
run.head_branch === defaultBranch &&
["push", "schedule", "workflow_dispatch"].includes(run.event)
);
}
export function pullRequestBaseSha(run, repository) {
if (
run?.event !== "pull_request" ||
run.repository?.full_name !== repository ||
!Array.isArray(run.pull_requests) ||
run.pull_requests.length !== 1
)
return null;
const base = run.pull_requests[0].base;
return base?.repo?.full_name === repository && SHA.test(base?.sha ?? "")
? base.sha
: null;
}
export function safeSha(value) {
return typeof value === "string" && SHA.test(value)
? value.toLowerCase()
: null;
}
export function selectStaticCheckArtifact(page, run, runAttempt) {
if (runAttempt !== 1) return null;
if (
!Array.isArray(page?.artifacts) ||
!Number.isSafeInteger(page.total_count) ||
page.total_count !== page.artifacts.length ||
page.artifacts.length >= 100
)
return null;
const matches = page.artifacts.filter(
(artifact) => artifact.name === "static-check-reports",
);
if (matches.length !== 1) return null;
const [artifact] = matches;
if (
artifact.expired !== false ||
String(artifact.workflow_run?.id) !== String(run.id) ||
artifact.workflow_run?.head_sha !== run.head_sha
)
return null;
return artifact;
}
export function validRepoPath(value) {
return (
typeof value === "string" &&
value.length > 0 &&
!isAbsolute(value) &&
!value.includes("\\") &&
value
.split("/")
.every((part) => part !== "" && part !== "." && part !== "..") &&
!value.startsWith("/")
);
}
/** Download one named static report archive and parse only whitelisted JSON members. */
export async function readStaticCheckArtifact({
repository,
artifactId,
token,
fetchImpl = fetch,
}) {
if (!/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/u.test(repository ?? ""))
throw new Error("artifact repository identity is invalid");
if (!token) throw new Error("artifact download requires a GitHub token");
const url = `${API_ROOT}/${repository}/actions/artifacts/${positiveId(artifactId)}/zip`;
let response = await fetchImpl(url, {
headers: {
Accept: "application/vnd.github+json",
Authorization: `Bearer ${token}`,
"X-GitHub-Api-Version": "2022-11-28",
},
signal: AbortSignal.timeout(10_000),
redirect: "manual",
});
if ([301, 302, 303, 307, 308].includes(response.status)) {
const location = response.headers.get("location");
if (!location || new URL(location).protocol !== "https:")
throw new Error("static_artifact_redirect_invalid");
response = await fetchImpl(location, {
signal: AbortSignal.timeout(10_000),
redirect: "error",
});
}
if (!response.ok) throw new Error(`github_http_${response.status}`);
const bytes = await readLimitedBytes(response, MAX_ARCHIVE_BYTES);
const directory = await mkdtemp(join(tmpdir(), "rea-ci-static-artifact-"));
const archive = join(directory, "artifact.zip");
try {
await writeFile(archive, bytes, { flag: "wx" });
return await parseStaticArchive(archive);
} finally {
await rm(directory, { recursive: true, force: true });
}
}
/** Accept only the three named producer outputs; no archive paths are written to disk. */
export async function parseStaticArchive(archivePath) {
const { stdout: listing } = await execute("unzip", ["-Z1", archivePath], {
encoding: "utf8",
maxBuffer: 128 * 1024,
timeout: 5_000,
});
const allowed = new Set([
"oxlint.json",
"jscpd/jscpd-report.json",
"static-task-context.json",
]);
const members = new Map();
for (const name of listing.split(/\r?\n/u).filter(Boolean)) {
const prefix = ".cache/static-checks/";
const member = name.startsWith(prefix) ? name.slice(prefix.length) : name;
if (!allowed.has(member)) continue;
if (members.has(member))
throw new Error("static artifact contains duplicate report members");
const { stdout } = await execute("unzip", ["-p", archivePath, name], {
encoding: "buffer",
maxBuffer: MAX_MEMBER_BYTES,
timeout: 5_000,
});
members.set(member, JSON.parse(stdout.toString("utf8")));
}
const context = parseStaticTaskContext(
members.get("static-task-context.json"),
);
const diagnostics = normalizeDiagnostics(
members.get("oxlint.json"),
members.get("jscpd/jscpd-report.json"),
);
if (diagnostics.length > MAX_DIAGNOSTICS)
throw new Error("static diagnostic count exceeds the reporting limit");
return { context, diagnostics };
}
function normalizeDiagnostics(lint, duplicate) {
return [...normalizeLint(lint), ...normalizeDuplicates(duplicate)];
}
function normalizeLint(report) {
if (report === undefined) return [];
if (!Array.isArray(report?.diagnostics))
throw new Error("oxlint diagnostics are malformed");
return report.diagnostics
.filter((item) => item.severity === "error")
.map((item) => {
if (
typeof item.filename !== "string" ||
!repoPath(item.filename) ||
typeof item.code !== "string" ||
typeof item.message !== "string"
)
throw new Error("oxlint error diagnostic is malformed");
return {
kind: "lint",
path: item.filename,
code: item.code,
message: item.message,
severity: "error",
};
});
}
function normalizeDuplicates(report) {
if (report === undefined) return [];
if (
!Array.isArray(report?.duplicates) ||
!Number.isFinite(report.statistics?.total?.percentage) ||
report.statistics.total.percentage < 0
)
throw new Error("jscpd report is malformed");
// The producer owns the checker outcome; do not copy or infer its threshold.
const exitCode = report.reaCheck?.exitCode;
if (exitCode === undefined || exitCode === 0) return [];
if (!Number.isSafeInteger(exitCode) || exitCode < 0)
throw new Error("jscpd checker outcome is malformed");
if (exitCode !== 1) return [];
return report.duplicates.map((item) => {
const paths = [item.firstFile?.name, item.secondFile?.name].sort();
if (paths.some((path) => !repoPath(path)))
throw new Error("jscpd duplicate paths are malformed");
return { kind: "jscpd", paths };
});
}
async function readLimitedBytes(response, limit) {
const reader = response.body?.getReader();
if (!reader) throw new Error("static artifact response has no body");
const chunks = [];
let size = 0;
try {
for (;;) {
const { done, value } = await reader.read();
if (done) break;
size += value.byteLength;
if (size > limit) {
await reader.cancel();
throw new Error("static artifact exceeds the download limit");
}
chunks.push(value);
}
} finally {
reader.releaseLock();
}
const result = new Uint8Array(size);
let offset = 0;
for (const chunk of chunks) {
result.set(chunk, offset);
offset += chunk.byteLength;
}
return result;
}
function repoPath(value) {
return (
typeof value === "string" &&
value.length > 0 &&
!value.startsWith("/") &&
!value.includes("\\") &&
value
.split("/")
.every((part) => part !== "" && part !== "." && part !== "..")
);
}
function positiveId(value) {
const id = Number(value);
if (!Number.isSafeInteger(id) || id < 1)
throw new Error("artifact ID must be a positive integer");
return String(id);
}
function diagnosticKey(item) {
if (
item?.kind === "lint" &&
validRepoPath(item.path) &&
typeof item.code === "string" &&
typeof item.message === "string" &&
item.severity === "error"
)
return JSON.stringify([
item.kind,
item.path,
item.code,
item.message,
item.severity,
]);
if (
item?.kind === "jscpd" &&
Array.isArray(item.paths) &&
item.paths.length === 2 &&
item.paths.every(validRepoPath)
)
return JSON.stringify([item.kind, ...[...item.paths].sort()]);
return null;
}
function blobIdentityStatus(diagnostics, blobs) {
const paths = [...new Set(diagnostics.flatMap(diagnosticPaths))];
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) => {
const task = diagnostic.kind === "jscpd" ? "jscpd" : "lint:built";
return (
TASK_HASH.test(left.taskHashes[task] ?? "") &&
left.taskHashes[task] === right.taskHashes[task]
);
});
}
function validContext(value) {
return (
value?.version === 1 &&
SHA.test(value.sourceSha ?? "") &&
value.sourceClean === true &&
typeof value.nodeVersion === "string" &&
typeof value.npmVersion === "string" &&
typeof value.turboVersion === "string" &&
typeof value.platform === "string" &&
typeof value.architecture === "string" &&
value.taskHashes &&
typeof value.taskHashes === "object" &&
!Array.isArray(value.taskHashes)
);
}
function sameExecutionContext(left, right) {
return [
"nodeVersion",
"npmVersion",
"turboVersion",
"platform",
"architecture",
].every((key) => left[key] === right[key]);
}
function isEligiblePullRun(run, repository) {
return (
isEligibleStaticRun(run) && pullRequestBaseSha(run, repository) !== null
);
}
function isEligibleStaticRun(run) {
return (
isRecord(run) &&
run.status === "completed" &&
isFailedConclusion(run.conclusion) &&
SHA.test(run.head_sha ?? "") &&
typeof run.repository?.full_name === "string" &&
run.workflowPath?.file === ".github/workflows/ci.yml"
);
}
function isCompletedFailure(run) {
return run?.status === "completed" && isFailedConclusion(run.conclusion);
}
function isRecord(value) {
return typeof value === "object" && value !== null && !Array.isArray(value);
}
function firstFailure(checks) {
for (const check of checks) {
const [failed, reason] = check();
if (failed) return { reason };
}
return null;
}
function outcome(classification, reason) {
return { classification, reason };
}
+159
View File
@@ -0,0 +1,159 @@
import type { NormalizedWorkflowRun } from "./workflow-run.mjs";
import type { StaticDiagnostic } from "./artifacts.mjs";
export type { StaticDiagnostic } from "./artifacts.mjs";
import type { StaticTaskContext } from "./static-task-context.mjs";
export type { StaticTaskContext } from "./static-task-context.mjs";
export interface CiRun {
readonly id?: string | number;
readonly run_attempt?: number;
readonly status?: string;
readonly conclusion?: string | null;
readonly event?: string;
readonly path?: string;
readonly head_sha?: string;
readonly head_branch?: string;
readonly repository?: { readonly full_name?: string };
readonly pull_requests?: readonly {
readonly base?: {
readonly sha?: string;
readonly repo?: { readonly full_name?: string };
};
}[];
}
export interface CiJob {
readonly name?: string;
readonly status?: string;
readonly conclusion?: string | null;
readonly run_id?: number;
readonly run_attempt?: number;
}
export interface StaticEvidence {
readonly context: StaticTaskContext;
readonly diagnostics: readonly StaticDiagnostic[];
}
export interface CiFailureReport {
readonly version: 1;
readonly observedAt: string;
readonly repository: string;
readonly defaultBranch: string;
readonly informationalOnly: true;
readonly gateEffect: string;
readonly boundedInput: {
readonly candidateRuns: number;
readonly limit: number;
readonly mainCandidateLimit: number;
readonly mainCandidateRuns: number;
readonly mainRunLookupLimit: number;
readonly manifestTruncated: boolean;
};
readonly counts: Readonly<
Record<"matching-main-diagnostics" | "unknown", number>
>;
readonly failures: readonly {
readonly runId: number | string;
readonly runAttempt: number;
readonly classification: "matching-main-diagnostics" | "unknown";
readonly reason: string;
readonly candidateFailures?: readonly {
readonly runId: number | string;
readonly runAttempt: number;
readonly reason: string;
}[];
readonly runHead?: string | null;
readonly event?: string | null;
readonly job?: string;
readonly conclusion?: string | null;
}[];
}
export interface FailureReportApi {
getRun(repository: string, id: string | number): Promise<CiRun>;
getJobs(
repository: string,
id: string | number,
attempt: number,
): Promise<readonly CiJob[]>;
getStaticEvidence(
repository: string,
run: CiRun,
job: CiJob,
): Promise<StaticEvidence | null>;
getAncestry(
repository: string,
ancestor: string,
descendant: string,
): Promise<{ status: string; mergeBaseSha: string | null }>;
verifyExecutionSource(
repository: string,
run: CiRun,
context: StaticTaskContext,
): Promise<boolean>;
getBlobIdentity(
repository: string,
ancestor: string,
descendant: string,
paths: readonly string[],
): Promise<Readonly<Record<string, boolean>>>;
}
export function classifyFailure(input: {
repository: string;
defaultBranch: string;
run: CiRun & NormalizedWorkflowRun;
job: CiJob;
diagnostics: readonly StaticDiagnostic[];
context: StaticTaskContext;
mainRun: CiRun & NormalizedWorkflowRun;
mainJob: CiJob;
mainDiagnostics: readonly StaticDiagnostic[];
mainContext: StaticTaskContext;
executionSourcesVerified: boolean;
ancestry: { status: string; mergeBaseSha: string | null };
blobs: Readonly<Record<string, boolean>>;
}): {
classification: "matching-main-diagnostics" | "unknown";
reason: string;
};
export function reportCiFailures(options: {
repository: string;
defaultBranch: string;
batchManifest: {
readonly repository: string;
readonly runs: readonly {
readonly id: number | string;
readonly runAttempt: number;
readonly workflow: string;
readonly event?: string | null;
readonly headBranch?: string | null;
readonly conclusion: string | null;
readonly status: string;
}[];
readonly truncation?: readonly unknown[];
readonly coverage?: { readonly exhaustive?: boolean };
readonly selection?: { readonly exhaustive?: boolean };
};
api: FailureReportApi;
outputDirectory?: string;
summaryPath?: string;
observedAt?: string;
}): Promise<CiFailureReport>;
export function createGitHubApi(options?: {
token?: string;
fetchImpl?: typeof fetch;
apiRequest?: (
method: string,
endpoint: string,
budget: { requests: number; startedAt: number; limitMs: number },
) => Promise<unknown>;
}): FailureReportApi;
export function writeFailureReport(
report: CiFailureReport,
outputDirectory?: string,
summaryPath?: string,
): Promise<{ jsonPath: string; markdownPath: string }>;
+533
View File
@@ -0,0 +1,533 @@
import { appendFile, mkdir, readFile, writeFile } from "node:fs/promises";
import { join, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import {
classifyFailure,
diagnosticPaths,
isEligibleMainRun,
isFailedConclusion,
pullRequestBaseSha,
readStaticCheckArtifact,
safeSha,
selectStaticCheckArtifact,
validRepoPath,
} from "./artifacts.mjs";
import { createGhApiRequest } from "./github-api.mjs";
import { normalizeWorkflowRun } from "./workflow-run.mjs";
const OUTPUT_DIRECTORY = join(".cache", "ci-failures");
const BATCH_DIRECTORY = join(".cache", "ci-job-timings");
const MAX_JSON_BYTES = 8 * 1024 * 1024;
const MAX_FAILED_RUNS = 20;
const MAX_MAIN_CANDIDATES = 5;
const MAX_MAIN_RUN_LOOKUPS = 100;
const MAX_PATHS_PER_COMPARISON = 50;
const MAX_API_REQUESTS = 250;
export { classifyFailure } from "./artifacts.mjs";
/** Uses only failed CI candidates present in the supplied bounded timing manifest. */
export async function reportCiFailures({
repository,
defaultBranch,
batchManifest,
api,
outputDirectory = OUTPUT_DIRECTORY,
summaryPath,
observedAt = new Date().toISOString(),
}) {
validateRepository(repository);
if (typeof defaultBranch !== "string" || defaultBranch.length === 0)
throw new Error("defaultBranch is required");
if (
!batchManifest ||
batchManifest.repository !== repository ||
!Array.isArray(batchManifest.runs)
)
throw new Error("timing manifest repository or runs are invalid");
const failedRuns = batchManifest.runs.filter(
(entry) =>
entry.workflow === "CI" &&
entry.status === "collected" &&
isFailedConclusion(entry.conclusion),
);
const prRuns = failedRuns.filter((entry) => entry.event === "pull_request");
const candidates = prRuns.slice(0, MAX_FAILED_RUNS);
const mainEntries = failedRuns.filter(
(entry) =>
entry.headBranch === defaultBranch &&
["push", "schedule", "workflow_dispatch"].includes(entry.event),
);
const lookupRun = verifiedRunLookup(repository, api);
const mainCandidates = [];
for (const entry of mainEntries.slice(0, MAX_MAIN_RUN_LOOKUPS)) {
try {
const run = await lookupRun(entry);
if (isEligibleMainRun(run, defaultBranch, repository))
mainCandidates.push({
run,
getEvidence: mainEvidenceLookup(repository, api, entry, run),
});
if (mainCandidates.length === MAX_MAIN_CANDIDATES) break;
} catch {
// Unverified metadata cannot consume the eligible-main candidate budget.
}
}
const entries = [];
for (const entry of candidates) {
try {
entries.push(
...(await analyzeFailedRun({
repository,
defaultBranch,
entry,
run: await lookupRun(entry),
mainCandidates,
api,
})),
);
} catch (error) {
entries.push({
runId: entry.id,
runAttempt: entry.runAttempt,
classification: "unknown",
reason: errorCode(error),
});
}
}
const report = {
version: 1,
observedAt,
repository,
defaultBranch,
informationalOnly: true,
gateEffect: "none; this report never changes CI conclusions",
boundedInput: {
candidateRuns: candidates.length,
limit: MAX_FAILED_RUNS,
mainCandidateLimit: MAX_MAIN_CANDIDATES,
mainCandidateRuns: mainCandidates.length,
mainRunLookupLimit: MAX_MAIN_RUN_LOOKUPS,
manifestTruncated:
prRuns.length > MAX_FAILED_RUNS ||
batchManifest.truncation?.length > 0 ||
batchManifest.selection?.exhaustive === false ||
batchManifest.coverage?.exhaustive === false,
},
counts: Object.fromEntries(
["matching-main-diagnostics", "unknown"].map((category) => [
category,
entries.filter((item) => item.classification === category).length,
]),
),
failures: entries,
};
await writeFailureReport(report, outputDirectory, summaryPath);
return report;
}
async function analyzeFailedRun({
repository,
defaultBranch,
entry,
run,
mainCandidates,
api,
}) {
const jobs = await api.getJobs(repository, entry.id, entry.runAttempt);
if (jobs.some((job) => !hasJobIdentity(job, entry)))
throw new Error("workflow_job_identity_mismatch");
const failedJobs = jobs.filter(
(job) => job.status === "completed" && isFailedConclusion(job.conclusion),
);
if (failedJobs.length === 0)
return [
{
runId: entry.id,
runAttempt: entry.runAttempt,
classification: "unknown",
reason: "failed_jobs_not_present_in_api_snapshot",
},
];
const failures = [];
for (const job of failedJobs) {
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,
runHead: safeSha(run.head_sha),
event: run.event ?? null,
job: job.name,
conclusion: job.conclusion,
...classification,
});
}
return failures;
}
async function attributeToMain({
repository,
defaultBranch,
run,
job,
evidence,
mainCandidates,
api,
}) {
const baseSha = pullRequestBaseSha(run, repository);
if (baseSha === null || evidence === null)
return outcome("unknown", "no_matching_verified_main_failure");
let result = outcome("unknown", "no_matching_verified_main_failure");
const candidateFailures = [];
for (const candidate of mainCandidates) {
try {
const main = await compareCandidate({
repository,
defaultBranch,
run,
job,
evidence,
baseSha,
candidate,
api,
});
if (main !== null) result = main;
if (main?.classification === "matching-main-diagnostics") break;
} catch (error) {
candidateFailures.push({
runId: candidate.run.id,
runAttempt: candidate.run.run_attempt,
reason: errorCode(error),
});
}
}
return {
...result,
...(candidateFailures.length > 0 ? { candidateFailures } : {}),
};
}
async function compareCandidate({
repository,
defaultBranch,
run,
job,
evidence,
baseSha,
candidate,
api,
}) {
const mainRun = candidate.run;
const main = await candidate.getEvidence(job.name);
if (!main?.evidence) return null;
const { job: mainJob, evidence: mainEvidence } = main;
const ancestry = await api.getAncestry(repository, mainRun.head_sha, baseSha);
const paths = [
...new Set(evidence.diagnostics.flatMap(diagnosticPaths)),
].slice(0, MAX_PATHS_PER_COMPARISON);
const blobs = await api.getBlobIdentity(
repository,
mainRun.head_sha,
baseSha,
paths,
);
const executionSourcesVerified =
(await api.verifyExecutionSource(repository, run, evidence.context)) &&
(await api.verifyExecutionSource(
repository,
mainRun,
mainEvidence.context,
));
return classifyFailure({
repository,
defaultBranch,
run,
job,
diagnostics: evidence.diagnostics,
context: evidence.context,
mainRun,
mainJob,
mainDiagnostics: mainEvidence.diagnostics,
mainContext: mainEvidence.context,
executionSourcesVerified,
ancestry,
blobs,
});
}
// Each verified main run/attempt owns its lazy jobs and parsed evidence for this
// report only. Cache nulls and rejected reads too; retries cannot spend the budget
// repeatedly on an immutable observation that was unavailable or invalid.
function mainEvidenceLookup(repository, api, entry, run) {
let jobs;
const evidence = new Map();
return (name) => {
jobs ??= Promise.resolve().then(async () => {
const items = await api.getJobs(repository, entry.id, entry.runAttempt);
return items.some((item) => !hasJobIdentity(item, entry)) ? [] : items;
});
if (!evidence.has(name))
evidence.set(
name,
jobs.then(async (items) => {
const job = items.find(
(item) =>
item.name === name &&
item.status === "completed" &&
isFailedConclusion(item.conclusion),
);
if (!job) return null;
return {
job,
evidence: await api.getStaticEvidence(repository, run, job),
};
}),
);
return evidence.get(name);
};
}
// Selection and attribution share one immutable API observation per run/attempt.
function verifiedRunLookup(repository, api) {
const runs = new Map();
return (entry) => {
const key = `${positiveId(entry.id)}:${positiveId(entry.runAttempt)}`;
if (!runs.has(key))
runs.set(
key,
Promise.resolve().then(async () => {
const run = normalizeWorkflowRun(
await api.getRun(repository, entry.id),
);
if (!hasRunIdentity(run, entry))
throw new Error("workflow_run_identity_mismatch");
return run;
}),
);
return runs.get(key);
};
}
function hasRunIdentity(run, entry) {
return (
String(run?.id) === String(entry.id) &&
Number(run.run_attempt) === Number(entry.runAttempt) &&
run.workflowPath?.file === ".github/workflows/ci.yml"
);
}
function hasJobIdentity(job, entry) {
return (
String(job.run_id) === String(entry.id) &&
Number(job.run_attempt) === Number(entry.runAttempt)
);
}
export function createGitHubApi({
token = process.env.GH_TOKEN,
fetchImpl = fetch,
apiRequest = createGhApiRequest(),
} = {}) {
if (!token) throw new Error("GH_TOKEN is required");
const budget = { requests: 0, startedAt: Date.now(), limitMs: 60_000 };
const request = async (endpoint) => {
if (budget.requests >= MAX_API_REQUESTS)
throw new Error("github_api_request_budget_exhausted");
budget.requests += 1;
return await apiRequest("GET", endpoint, budget);
};
return {
async getRun(repository, id) {
return await request(
`repos/${repository}/actions/runs/${positiveId(id)}`,
);
},
async getJobs(repository, id, attempt) {
const page = await request(
`repos/${repository}/actions/runs/${positiveId(id)}/attempts/${positiveId(attempt)}/jobs?per_page=100&page=1`,
);
if (!Array.isArray(page.jobs) || page.jobs.length >= 100)
throw new Error("job_list_incomplete_or_malformed");
return page.jobs;
},
async getStaticEvidence(repository, run, job) {
if (job.name !== "Static checks") return null;
if (run.run_attempt !== 1) return null;
const page = await request(
`repos/${repository}/actions/runs/${positiveId(run.id)}/artifacts?per_page=100&page=1`,
);
const artifact = selectStaticCheckArtifact(page, run, run.run_attempt);
if (!artifact) return null;
return await readStaticCheckArtifact({
repository,
artifactId: artifact.id,
token,
fetchImpl,
});
},
async getAncestry(repository, ancestor, descendant) {
const comparison = await request(
`repos/${repository}/compare/${safeSha(ancestor)}...${safeSha(descendant)}`,
);
return {
status: comparison.status,
mergeBaseSha: safeSha(comparison.merge_base_commit?.sha),
};
},
async verifyExecutionSource(repository, run, context) {
const sourceSha = safeSha(context.sourceSha);
if (!sourceSha) return false;
const pr =
run.event === "pull_request"
? pullRequestBaseSha(run, repository)
: null;
if (
run.event === "pull_request" &&
(pr === null || context.prHeadSha !== run.head_sha)
)
return false;
const commit = await request(`repos/${repository}/commits/${sourceSha}`);
if (safeSha(commit.sha) !== sourceSha) return false;
if (sourceSha === run.head_sha) return true;
if (
pr === null ||
!Array.isArray(commit.parents) ||
commit.parents.length !== 2
)
return false;
return (
safeSha(commit.parents[0]?.sha) === pr &&
safeSha(commit.parents[1]?.sha) === run.head_sha
);
},
async getBlobIdentity(repository, ancestor, descendant, paths) {
const result = {};
for (const path of paths) {
if (!validRepoPath(path)) continue;
const [left, right] = await Promise.all([
getContentBlobSha(repository, ancestor, path, request),
getContentBlobSha(repository, descendant, path, request),
]);
result[path] = left === right;
}
return result;
},
};
}
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) {
return { classification, reason };
}
function validateRepository(value) {
if (
typeof value !== "string" ||
!/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/u.test(value)
)
throw new Error("repository must be owner/name");
}
function positiveId(value) {
if (!Number.isSafeInteger(Number(value)) || Number(value) < 1)
throw new Error(
"GitHub run and attempt IDs must be positive safe integers",
);
return String(Number(value));
}
function errorCode(error) {
return error instanceof Error ? error.message.slice(0, 160) : "unknown_error";
}
export async function writeFailureReport(
report,
outputDirectory = OUTPUT_DIRECTORY,
summaryPath,
) {
await mkdir(outputDirectory, { recursive: true });
const jsonPath = join(outputDirectory, "report.json");
const markdownPath = join(outputDirectory, "report.md");
const matchedDiagnostics = report.failures.filter(
(item) => item.classification === "matching-main-diagnostics",
);
const lines = [
"# CI failure attribution",
"",
"Informational only. This report never changes a CI conclusion or required gate.",
"",
`Observed ${report.observedAt}; ${String(matchedDiagnostics.length)} of ${String(report.failures.length)} failure reports contain supported diagnostics matching a failed static task on an ancestor main revision. This does not attribute other failures in the same job. Unknown means evidence was incomplete or did not match.`,
"",
];
for (const item of report.failures)
lines.push(
`- Run ${item.runId} attempt ${item.runAttempt}${item.job ? `, ${item.job}` : ""}: **${item.classification}** — ${item.reason}.`,
);
if (report.failures.length === 0)
lines.push(
"- No completed failed CI attempts were present in the supplied timing snapshot.",
);
await writeFile(jsonPath, `${JSON.stringify(report, null, 2)}\n`, "utf8");
await writeFile(markdownPath, `${lines.join("\n")}\n`, "utf8");
if (summaryPath)
await appendFile(summaryPath, `${lines.join("\n")}\n`, "utf8");
return { jsonPath, markdownPath };
}
async function main() {
const repository = process.env.CI_REPOSITORY;
const defaultBranch = process.env.CI_DEFAULT_BRANCH;
const batchPath =
process.env.CI_TIMING_MANIFEST ??
join(BATCH_DIRECTORY, "batch-manifest.json");
const batchManifest = JSON.parse(await readBoundedFile(batchPath));
const api = createGitHubApi();
await reportCiFailures({
repository,
defaultBranch,
batchManifest,
api,
outputDirectory: process.env.CI_FAILURES_DIRECTORY ?? OUTPUT_DIRECTORY,
summaryPath: process.env.GITHUB_STEP_SUMMARY,
});
}
async function readBoundedFile(path) {
const bytes = await readFile(path);
if (bytes.byteLength > MAX_JSON_BYTES)
throw new Error("timing manifest exceeds size limit");
return bytes.toString("utf8");
}
if (
process.argv[1] &&
resolve(process.argv[1]) === fileURLToPath(import.meta.url)
) {
try {
await main();
} catch (error) {
console.error(error instanceof Error ? error.message : String(error));
process.exitCode = 1;
}
}
+16
View File
@@ -0,0 +1,16 @@
export interface GitHubApiBudget {
requests: number;
startedAt: number;
limitMs: number;
}
export type GitHubApiRequest = (
method: string,
endpoint: string,
budget: GitHubApiBudget,
) => Promise<unknown>;
export function createGhApiRequest(options?: {
env?: NodeJS.ProcessEnv;
now?: () => number;
}): GitHubApiRequest;
+33
View File
@@ -0,0 +1,33 @@
import { execFile } from "node:child_process";
import { promisify } from "node:util";
const execFileAsync = promisify(execFile);
const MAX_BUFFER = 8 * 1024 * 1024;
const REQUEST_TIMEOUT_MS = 10_000;
/** Create a bounded GitHub CLI JSON transport with GET-only authority. */
export function createGhApiRequest({ env = process.env, now = Date.now } = {}) {
return async (method, endpoint, budget) => {
if (method !== "GET")
throw new Error(
"GitHub API transport supports read-only GET requests only",
);
const remaining = budget.limitMs - (now() - budget.startedAt);
if (remaining <= 0) throw new Error("lookup_time_budget_exhausted");
const { stdout } = await execFileAsync(
"gh",
["api", "--method", "GET", endpoint],
{
env,
encoding: "utf8",
maxBuffer: MAX_BUFFER,
timeout: Math.min(REQUEST_TIMEOUT_MS, remaining),
},
);
try {
return JSON.parse(stdout);
} catch (cause) {
throw new Error("github_api_malformed_json", { cause });
}
};
}
+3
View File
@@ -103,6 +103,9 @@ export async function collectJobTimingsBatch({
id: run.id,
runAttempt: run.run_attempt,
workflow: workflow.name,
event: typeof run.event === "string" ? run.event : null,
headBranch:
typeof run.head_branch === "string" ? run.head_branch : null,
conclusion: run.conclusion ?? null,
createdAt: run.created_at ?? null,
});
+5
View File
@@ -62,6 +62,10 @@ function classifyPackage(base, head) {
]),
].filter((key) => beforeScripts?.[key] !== afterScripts?.[key]);
for (const script of changed) {
if (/^test:(coverage|mutation):reverse-tools$/.test(script)) {
selected.reverse_tools = true;
continue;
}
if (script === "test:sqlite" || script === "test:sqlite:run") {
selected.sqlite = true;
continue;
@@ -162,6 +166,7 @@ if (tier === "reused") {
.split("\0")
.filter(Boolean);
for (const file of files) {
if (matchesAny(file, SCOPES.reverse_tools)) selected.reverse_tools = true;
if (
/^(README(?:_[^/]+)?\.md|AGENTS\.md|CONTRIBUTING\.md|CHANGELOG\.md|SECURITY\.md|native\/windows\/README\.md|\.github\/pull_request_template\.md)$/.test(
file,
+95
View File
@@ -0,0 +1,95 @@
export interface PrCiHead {
repositoryId: number | null;
repository?: string | null;
ref: string | null;
sha: string | null;
}
export interface PrCiPullRequest {
number: number | null;
draft?: boolean;
identityValid: boolean;
mergeable?: boolean;
head: PrCiHead;
[key: string]: unknown;
}
export interface PrCiWorkflowRun {
id?: number;
run_attempt?: number;
event?: string;
head_branch?: string;
head_repository?: { id?: number | null } | null;
head_sha?: string;
status?: string;
conclusion?: string | null;
created_at?: string;
html_url?: string;
pull_requests?: Array<{
number?: number;
head?: { sha?: string; repo?: { id?: number | null } } | null;
}>;
[key: string]: unknown;
}
export interface PrCiClassification {
category: string;
reason: string;
runs: Array<Record<string, unknown>>;
}
export interface PrCiHealthReport {
schemaVersion: 1;
observedAt: string;
repository: string;
repositoryId: number | null;
defaultBranch: string;
lookbackDays: number;
scan: {
status: "complete" | "partial";
cutoff: string;
pullRequestPages: number;
workflowRunPages: number;
pullRequestInventoryComplete: boolean;
workflowRunInventoryComplete: boolean;
pullRequestDetailsFetched: number;
pullRequestDetailsLimit: number;
apiRequests: number;
apiRequestLimit: number;
errors: string[];
};
counts: Record<string, number>;
pullRequests: Array<PrCiPullRequest & { ci: PrCiClassification }>;
}
export function collectPrCiHealth(options: {
repository: string;
repositoryId?: number | string | null;
defaultBranch: string;
lookbackDays?: number;
now?: number;
apiRequest?: GitHubApiRequest;
}): Promise<PrCiHealthReport>;
export function classifyPrCi(input: {
pull: PrCiPullRequest;
runs: Array<{ run: PrCiWorkflowRun; basis: string }>;
runsComplete: boolean;
pullRequestInventoryComplete: boolean;
ambiguousRuns: Array<{ run: PrCiWorkflowRun; basis: string }>;
}): PrCiClassification;
export function matchRunToPullRequest(input: {
run: PrCiWorkflowRun;
pull: PrCiPullRequest;
identityCounts: Map<string, number>;
inventoryComplete?: boolean;
}): { kind: "none" } | { kind: "ambiguous" } | { kind: "match"; basis: string };
export function writePrCiHealthReport(
report: PrCiHealthReport,
outputDirectory?: string,
): Promise<{ jsonPath: string; markdownPath: string }>;
export function renderMarkdownSummary(report: PrCiHealthReport): string;
import type { GitHubApiRequest } from "./github-api.mjs";
+718
View File
@@ -0,0 +1,718 @@
import { appendFile, mkdir, writeFile } from "node:fs/promises";
import { join, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { createGhApiRequest } from "./github-api.mjs";
const OUTPUT_DIRECTORY = join(".cache", "ci-pr-health");
const PAGE_SIZE = 100;
const MAX_PULL_REQUEST_PAGES = 3;
const MAX_WORKFLOW_RUN_PAGES = 5;
const MAX_PULL_REQUEST_DETAILS = 40;
const MAX_API_REQUESTS =
MAX_PULL_REQUEST_PAGES + MAX_WORKFLOW_RUN_PAGES + MAX_PULL_REQUEST_DETAILS;
const LOOKBACK_DAYS = 14;
const MAX_LOOKBACK_DAYS = 30;
const MAX_TOTAL_TIME_MS = 60_000;
const SHA_PATTERN = /^[0-9a-f]{40}$/iu;
const COMPLETED_CATEGORIES = new Map([
["failure", "completed_failure"],
["timed_out", "completed_failure"],
["cancelled", "completed_canceled"],
["success", "completed_success"],
]);
/** Read workflow/PR state and conservatively distinguish absent CI from unknown. */
export async function collectPrCiHealth({
repository,
repositoryId,
defaultBranch,
lookbackDays = LOOKBACK_DAYS,
now = Date.now(),
apiRequest = createGhApiRequest(),
}) {
const identity = validateInputs({
repository,
repositoryId,
defaultBranch,
lookbackDays,
now,
});
const observedAt = new Date(now).toISOString();
const cutoff = now - identity.lookbackDays * 24 * 60 * 60 * 1_000;
const snapshot = await collectApiSnapshot({ apiRequest, identity, cutoff });
const classified = classifyPullRequests(snapshot);
const { pulls, runs, budget } = snapshot;
const errors = [pulls.error, runs.error, ...snapshot.detailsErrors].filter(
Boolean,
);
return {
schemaVersion: 1,
observedAt,
repository: identity.repository,
repositoryId: identity.repositoryId,
defaultBranch: identity.defaultBranch,
lookbackDays: identity.lookbackDays,
scan: {
status:
errors.length === 0 && pulls.complete && runs.complete
? "complete"
: "partial",
cutoff: new Date(cutoff).toISOString(),
pullRequestPages: pulls.pages,
workflowRunPages: runs.pages,
pullRequestInventoryComplete: pulls.complete,
workflowRunInventoryComplete: runs.complete,
pullRequestDetailsFetched: snapshot.detailsFetched,
pullRequestDetailsLimit: MAX_PULL_REQUEST_DETAILS,
apiRequests: budget.requests,
apiRequestLimit: MAX_API_REQUESTS,
errors,
},
counts: countCategories(classified),
pullRequests: classified,
};
}
async function collectApiSnapshot({ apiRequest, identity, cutoff }) {
const budget = {
requests: 0,
startedAt: Date.now(),
limitMs: MAX_TOTAL_TIME_MS,
};
const requestGet = async (endpoint) => {
if (budget.requests >= MAX_API_REQUESTS)
throw new Error("lookup_request_budget_exhausted");
if (Date.now() - budget.startedAt >= budget.limitMs)
throw new Error("lookup_time_budget_exhausted");
budget.requests += 1;
return await apiRequest("GET", endpoint, budget);
};
const pulls = await listOpenPullRequests({
requestGet,
identity,
});
const candidates = pulls.items.filter(
(pull) =>
!pull.draft &&
Number.isFinite(Date.parse(pull.createdAt ?? "")) &&
Date.parse(pull.createdAt ?? "") >= cutoff &&
pull.base.ref === identity.defaultBranch &&
(identity.repositoryId === null ||
pull.base.repositoryId === identity.repositoryId),
);
const runs = await listRecentWorkflowRuns({
requestGet,
identity,
cutoff,
});
const detailResult = await resolveMergeability({
candidates,
requestGet,
identity,
});
return {
budget,
pulls,
runs,
candidates,
detailsFetched: detailResult.fetched,
detailsErrors: detailResult.errors,
};
}
function classifyPullRequests(snapshot) {
const { candidates, pulls, runs } = snapshot;
const identityCounts = countHeadIdentities(pulls.items);
return candidates.map((pull) => {
const relevant = [];
const ambiguousRuns = [];
for (const run of runs.items) {
const match = matchRunToPullRequest({
run,
pull,
identityCounts,
inventoryComplete: pulls.complete,
});
if (match.kind === "match") relevant.push({ run, basis: match.basis });
if (match.kind === "ambiguous")
ambiguousRuns.push({ run, basis: "ambiguous_head_identity" });
}
return {
...pull,
ci: classifyPrCi({
pull,
runs: relevant,
runsComplete: runs.complete,
pullRequestInventoryComplete: pulls.complete,
ambiguousRuns,
}),
};
});
}
async function resolveMergeability({ candidates, requestGet, identity }) {
let detailsFetched = 0;
const errors = new Set();
for (const pull of candidates) {
if (pull.mergeable !== undefined) continue;
if (detailsFetched >= MAX_PULL_REQUEST_DETAILS) {
errors.add("pull_request_mergeability_lookup_budget_exhausted");
continue;
}
const result = await getPullRequestDetails({ requestGet, identity, pull });
detailsFetched += 1;
if (result.error !== null) {
errors.add(result.error);
continue;
}
const { detail } = result;
const identityChanged =
detail.headSha !== pull.head.sha ||
detail.headRef !== pull.head.ref ||
detail.headRepositoryId !== pull.head.repositoryId ||
detail.baseRef !== pull.base.ref ||
detail.baseRepositoryId !== pull.base.repositoryId;
if (identityChanged) {
pull.identityValid = false;
pull.identityChangedDuringScan = true;
errors.add("pull_request_identity_changed_during_scan");
} else {
pull.mergeable = detail.mergeable;
pull.detailFetched = true;
if (detail.mergeable === undefined)
errors.add("pull_request_mergeability_unknown");
}
}
return { fetched: detailsFetched, errors: [...errors] };
}
function countCategories(pulls) {
const categories = [
"missing",
"startup_failure",
"queued_pending_executing",
"approval_required",
"completed_success",
"completed_failure",
"completed_canceled",
"completed_other",
"merge_conflict",
"unknown",
"deferred",
];
return Object.fromEntries(
categories.map((category) => [
category,
pulls.filter(({ ci }) => ci.category === category).length,
]),
);
}
/** Pure status classifier; missing requires complete, identity-safe inventories. */
export function classifyPrCi({
pull,
runs,
runsComplete,
pullRequestInventoryComplete,
ambiguousRuns,
}) {
if (!pull.identityValid)
return result("unknown", "pull_request_head_identity_invalid", []);
const evidence = [...runs, ...ambiguousRuns];
if (pull.mergeable === false)
return result("merge_conflict", "github_reports_merge_conflict", evidence);
// The newest collected run is not proven current until pagination completes:
// an older-created run outside this snapshot may have been retried recently.
if (!runsComplete)
return result(
evidence.length > 0 ? "unknown" : "deferred",
evidence.length > 0
? "workflow_run_inventory_incomplete"
: "lookup_inventory_incomplete",
evidence,
);
const selection = newestRun(runs);
if (!selection.known)
return result("unknown", "workflow_run_order_unknown", evidence);
const latest = selection.latest;
if (
ambiguousRuns.some((candidate) => {
const order = latest ? compareRunEvidence(candidate, latest) : null;
return order === null || order >= 0;
})
)
return result("unknown", "workflow_run_identity_ambiguous", evidence);
if (latest !== undefined) {
const run = latest.run;
if (run.conclusion === "startup_failure")
return result("startup_failure", "workflow_startup_failure", evidence);
if (run.status === "waiting" || run.conclusion === "action_required")
return result(
"approval_required",
"workflow_waiting_for_approval_or_gate",
evidence,
);
if (["queued", "requested", "pending", "in_progress"].includes(run.status))
return result(
"queued_pending_executing",
`workflow_${run.status}`,
evidence,
);
if (run.status === "completed")
return result(
COMPLETED_CATEGORIES.get(run.conclusion) ?? "completed_other",
run.conclusion === "success"
? "workflow_succeeded"
: `workflow_${run.conclusion ?? "unknown_conclusion"}`,
evidence,
);
return result("unknown", "workflow_status_unrecognized", evidence);
}
if (!pullRequestInventoryComplete)
return result("deferred", "lookup_inventory_incomplete", []);
if (pull.mergeable !== true)
return result("unknown", "pull_request_mergeability_unknown", []);
return result("missing", "no_pull_request_event_run_for_current_head", []);
}
/** Match only a pull_request event proven to belong to this immutable PR head. */
export function matchRunToPullRequest({
run,
pull,
identityCounts,
inventoryComplete = true,
}) {
if (run?.event !== "pull_request") return { kind: "none" };
if (!pull.identityValid || !isRecord(run)) return { kind: "none" };
const association = matchExplicitPullAssociation(run, pull);
if (association === "match")
return { kind: "match", basis: "event_pr_number_and_head_sha" };
if (association === "ambiguous") return { kind: "ambiguous" };
if (association === "other" || !sameHeadRepositoryAndRef(run, pull))
return { kind: "none" };
if (!uniqueHeadRepositoryAndRef(pull, identityCounts, inventoryComplete))
return { kind: "ambiguous" };
if (isSha(run.head_sha) && run.head_sha.toLowerCase() === pull.head.sha)
return { kind: "match", basis: "event_unique_head_ref_and_repository_id" };
return { kind: "none" };
}
function matchExplicitPullAssociation(run, pull) {
const associations = Array.isArray(run.pull_requests)
? run.pull_requests
: [];
if (associations.length === 0) return "absent";
const matchingNumber = associations.filter(
(item) => item?.number === pull.number,
);
if (matchingNumber.length === 0) return "other";
const exactHead = matchingNumber.find(
(item) => item?.head?.sha === pull.head.sha,
);
if (exactHead === undefined) {
return matchingNumber.some(
(item) =>
typeof item?.head?.sha === "string" && item.head.sha !== pull.head.sha,
)
? "other"
: "absent";
}
const associatedHeadRepositoryId = positiveInteger(exactHead.head?.repo?.id);
const runHeadRepositoryId = positiveInteger(run.head_repository?.id);
if (associatedHeadRepositoryId === null || runHeadRepositoryId === null)
return "ambiguous";
if (
associatedHeadRepositoryId !== pull.head.repositoryId ||
runHeadRepositoryId !== pull.head.repositoryId
)
return "other";
const baseRefMatches =
typeof exactHead.base?.ref !== "string" ||
exactHead.base.ref === pull.base.ref;
const baseRepositoryId = positiveInteger(exactHead.base?.repo?.id);
const baseRepositoryMatches =
baseRepositoryId === null || baseRepositoryId === pull.base.repositoryId;
return baseRefMatches && baseRepositoryMatches ? "match" : "other";
}
function sameHeadRepositoryAndRef(run, pull) {
return (
run.head_branch === pull.head.ref &&
run.head_repository?.id === pull.head.repositoryId
);
}
function uniqueHeadRepositoryAndRef(pull, identityCounts, inventoryComplete) {
if (!inventoryComplete) return false;
const key = headIdentityKey(pull.head.repositoryId, pull.head.ref);
const unknownRepositoryKey = headIdentityKey(null, pull.head.ref);
return (
identityCounts.get(key) === 1 &&
(identityCounts.get(unknownRepositoryKey) ?? 0) === 0
);
}
function normalizePullRequest(raw, identity) {
const number = positiveInteger(raw?.number);
const base = normalizeBase(raw?.base);
const head = normalizeHead(raw?.head);
const draft = raw?.draft === true;
return {
number,
draft,
createdAt: typeof raw?.created_at === "string" ? raw.created_at : null,
url: typeof raw?.html_url === "string" ? raw.html_url : null,
base,
head,
mergeable: typeof raw?.mergeable === "boolean" ? raw.mergeable : undefined,
identityValid: hasValidPullIdentity({ raw, identity, number, base, head }),
};
}
function normalizeBase(raw) {
return {
ref: typeof raw?.ref === "string" ? raw.ref : null,
repositoryId: positiveInteger(raw?.repo?.id),
};
}
function normalizeHead(raw) {
return {
repositoryId: positiveInteger(raw?.repo?.id),
repository:
typeof raw?.repo?.full_name === "string" ? raw.repo.full_name : null,
ref: typeof raw?.ref === "string" ? raw.ref : null,
sha:
typeof raw?.sha === "string" && isSha(raw.sha)
? raw.sha.toLowerCase()
: null,
};
}
function hasValidPullIdentity({ raw, identity, number, base, head }) {
return (
number !== null &&
typeof raw?.draft === "boolean" &&
base.ref === identity.defaultBranch &&
(identity.repositoryId === null ||
base.repositoryId === identity.repositoryId) &&
head.repositoryId !== null &&
head.sha !== null &&
head.ref !== null
);
}
function countHeadIdentities(pulls) {
const counts = new Map();
for (const pull of pulls) {
if (typeof pull.head.ref !== "string") continue;
const key = headIdentityKey(pull.head.repositoryId, pull.head.ref);
counts.set(key, (counts.get(key) ?? 0) + 1);
}
return counts;
}
function headIdentityKey(repositoryId, ref) {
return `${String(repositoryId)}\u0000${ref}`;
}
function newestRun(runs) {
let latest = runs[0];
for (const candidate of runs) {
if (latest && (compareRunEvidence(candidate, latest) ?? 0) > 0)
latest = candidate;
}
const known = runs.every((candidate) => {
if (candidate === latest) return true;
const order = compareRunEvidence(candidate, latest);
return order !== null && order <= 0;
});
return { known, latest };
}
// Attempt ordering is meaningful within one run; different run IDs are not clocks.
function compareRunEvidence(left, right) {
const leftRun = left.run;
const rightRun = right.run;
const id = positiveInteger(leftRun.id);
if (id !== null && id === positiveInteger(rightRun.id)) {
const leftAttempt = positiveInteger(leftRun.run_attempt);
const rightAttempt = positiveInteger(rightRun.run_attempt);
if (leftAttempt === null || rightAttempt === null) return null;
if (leftAttempt !== rightAttempt) return leftAttempt - rightAttempt;
return leftRun.status === rightRun.status &&
leftRun.conclusion === rightRun.conclusion
? 0
: null;
}
// A retry may start long after its original creation; without an attempt
// clock, creation dates only order first attempts from different runs.
if (
positiveInteger(leftRun.run_attempt) !== 1 ||
positiveInteger(rightRun.run_attempt) !== 1
)
return null;
const time =
Date.parse(leftRun.created_at ?? "") -
Date.parse(rightRun.created_at ?? "");
return Number.isFinite(time) && time !== 0 ? time : null;
}
function result(category, reason, runs) {
return {
category,
reason,
runs: runs.map(({ run, basis }) => ({
id: positiveInteger(run.id),
attempt: positiveInteger(run.run_attempt),
status: typeof run.status === "string" ? run.status : null,
conclusion: typeof run.conclusion === "string" ? run.conclusion : null,
headSha: isSha(run.head_sha) ? run.head_sha.toLowerCase() : null,
createdAt: typeof run.created_at === "string" ? run.created_at : null,
url: typeof run.html_url === "string" ? run.html_url : null,
identityBasis: basis,
})),
};
}
async function listOpenPullRequests({ requestGet, identity }) {
const items = [];
let complete = false;
let pages = 0;
let error = null;
for (let page = 1; page <= MAX_PULL_REQUEST_PAGES; page += 1) {
try {
const endpoint = `repos/${identity.repository}/pulls?state=open&sort=created&direction=desc&per_page=${PAGE_SIZE}&page=${page}`;
const response = await requestGet(endpoint);
if (!Array.isArray(response))
throw new Error("pull_request_page_malformed");
pages += 1;
const normalized = response.map((raw) =>
normalizePullRequest(raw, identity),
);
if (
normalized.some(
(pull) => !Number.isFinite(Date.parse(pull.createdAt ?? "")),
)
)
throw new Error("pull_request_page_malformed");
items.push(...normalized);
if (response.length < PAGE_SIZE) {
complete = true;
break;
}
} catch (cause) {
error = safeErrorCode(cause);
break;
}
}
return { items, pages, complete, error };
}
async function listRecentWorkflowRuns({ requestGet, identity, cutoff }) {
const items = [];
let complete = false;
let pages = 0;
let error = null;
for (let page = 1; page <= MAX_WORKFLOW_RUN_PAGES; page += 1) {
try {
const cutoffDate = new Date(cutoff).toISOString().slice(0, 10);
const endpoint = `repos/${identity.repository}/actions/workflows/ci.yml/runs?event=pull_request&created=%3E%3D${cutoffDate}&per_page=${PAGE_SIZE}&page=${page}`;
const response = await requestGet(endpoint);
if (!isRecord(response) || !Array.isArray(response.workflow_runs))
throw new Error("workflow_run_page_malformed");
pages += 1;
if (!response.workflow_runs.every(isRecord))
throw new Error("workflow_run_page_malformed");
items.push(...response.workflow_runs);
if (response.workflow_runs.length < PAGE_SIZE) {
complete = true;
break;
}
} catch (cause) {
error = safeErrorCode(cause);
break;
}
}
return { items, pages, complete, error };
}
async function getPullRequestDetails({ requestGet, identity, pull }) {
if (pull.number === null)
return { detail: null, error: "pull_request_detail_identity_missing" };
try {
const response = await requestGet(
`repos/${identity.repository}/pulls/${pull.number}`,
);
if (!isRecord(response))
return { detail: null, error: "pull_request_detail_malformed" };
return {
detail: {
mergeable:
typeof response.mergeable === "boolean"
? response.mergeable
: undefined,
headSha: isSha(response.head?.sha)
? response.head.sha.toLowerCase()
: null,
headRef:
typeof response.head?.ref === "string" ? response.head.ref : null,
headRepositoryId: positiveInteger(response.head?.repo?.id),
baseRef:
typeof response.base?.ref === "string" ? response.base.ref : null,
baseRepositoryId: positiveInteger(response.base?.repo?.id),
},
error: null,
};
} catch (cause) {
return { detail: null, error: safeErrorCode(cause) };
}
}
function validateInputs({
repository,
repositoryId,
defaultBranch,
lookbackDays,
now,
}) {
if (
typeof repository !== "string" ||
!/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/u.test(repository)
)
throw new Error(
"CI_REPOSITORY must be an owner/name repository identifier",
);
if (
typeof defaultBranch !== "string" ||
defaultBranch.length === 0 ||
/[\r\n]/u.test(defaultBranch)
)
throw new Error("CI_DEFAULT_BRANCH must be a nonempty branch name");
const parsedRepositoryId =
repositoryId === undefined || repositoryId === null || repositoryId === ""
? null
: positiveInteger(repositoryId);
if (
repositoryId !== undefined &&
repositoryId !== null &&
repositoryId !== "" &&
parsedRepositoryId === null
)
throw new Error("CI_REPOSITORY_ID must be a positive safe integer");
if (
!Number.isInteger(lookbackDays) ||
lookbackDays < 1 ||
lookbackDays > MAX_LOOKBACK_DAYS
)
throw new Error(
`lookbackDays must be an integer from 1 to ${String(MAX_LOOKBACK_DAYS)}`,
);
if (!Number.isFinite(now)) throw new Error("now must be a finite timestamp");
return {
repository,
repositoryId: parsedRepositoryId,
defaultBranch,
lookbackDays,
};
}
function positiveInteger(value) {
const number = typeof value === "number" ? value : Number(value);
return Number.isSafeInteger(number) && number > 0 ? number : null;
}
function isSha(value) {
return typeof value === "string" && SHA_PATTERN.test(value);
}
function isRecord(value) {
return typeof value === "object" && value !== null && !Array.isArray(value);
}
function safeErrorCode(cause) {
if (cause?.message === "lookup_time_budget_exhausted")
return "lookup_time_budget_exhausted";
if (cause?.message === "lookup_request_budget_exhausted")
return "lookup_request_budget_exhausted";
if (cause?.message === "github_api_malformed_json")
return "github_api_malformed_json";
if (cause?.message?.endsWith("_malformed")) return cause.message;
if (cause?.code === "ETIMEDOUT" || cause?.killed) return "github_api_timeout";
return "github_api_request_failed";
}
export async function writePrCiHealthReport(
report,
outputDirectory = OUTPUT_DIRECTORY,
) {
const jsonPath = join(outputDirectory, "report.json");
const markdownPath = join(outputDirectory, "summary.md");
await mkdir(outputDirectory, { recursive: true });
await writeFile(jsonPath, `${JSON.stringify(report, null, 2)}\n`, "utf8");
await writeFile(markdownPath, renderMarkdownSummary(report), "utf8");
return { jsonPath, markdownPath };
}
export function renderMarkdownSummary(report) {
const rows = report.pullRequests.map(
(pull) =>
`| #${String(pull.number ?? "?")} | ${escapeCell(pull.head.repository ?? "unknown")} | ${escapeCell(pull.head.ref ?? "unknown")} | \`${pull.head.sha ?? "unknown"}\` | ${pull.ci.category} | ${escapeCell(pull.ci.reason)} |`,
);
return [
"# Pull request CI health snapshot",
"",
`Observed ${report.observedAt} for \`${report.repository}\`, target branch \`${escapeCell(report.defaultBranch)}\`; recent window ${String(report.lookbackDays)} days. Scan: **${report.scan.status}**.`,
"",
"This is read-only point-in-time telemetry. Missing is reported only when PR and workflow-run inventories are complete and the current immutable PR head identity is unambiguous. Incomplete lookups remain deferred or unknown.",
"",
`API pages: ${String(report.scan.pullRequestPages)} PR, ${String(report.scan.workflowRunPages)} workflow runs; ${String(report.scan.apiRequests)} bounded requests. Errors: ${report.scan.errors.length === 0 ? "none" : report.scan.errors.join(", ")}.`,
"",
"| PR | Head repository | Head ref | Head SHA | CI classification | Evidence |",
"| ---: | --- | --- | --- | --- | --- |",
...rows,
"",
"Categories: missing, startup failure, queued/pending/executing, approval required, completed outcomes, merge conflict, unknown, and deferred.",
"",
].join("\n");
}
function escapeCell(value) {
return String(value)
.replaceAll("|", "\\|")
.replaceAll("\n", " ")
.replaceAll("\r", " ");
}
if (
process.argv[1] !== undefined &&
resolve(process.argv[1]) === fileURLToPath(import.meta.url)
) {
try {
const report = await collectPrCiHealth({
repository: process.env.CI_REPOSITORY,
repositoryId: process.env.CI_REPOSITORY_ID,
defaultBranch: process.env.CI_DEFAULT_BRANCH,
});
const paths = await writePrCiHealthReport(
report,
process.env.CI_PR_HEALTH_DIRECTORY ?? OUTPUT_DIRECTORY,
);
if (process.env.GITHUB_STEP_SUMMARY)
await appendFile(
process.env.GITHUB_STEP_SUMMARY,
renderMarkdownSummary(report),
"utf8",
);
process.stdout.write(
`Wrote ${report.pullRequests.length} recent PR CI records to ${paths.jsonPath}\n`,
);
} catch (cause) {
process.stderr.write(
`PR CI health telemetry failed: ${cause instanceof Error ? cause.message : "unknown_error"}\n`,
);
process.exitCode = 1;
}
}
+4 -3
View File
@@ -2,6 +2,7 @@ import { execFileSync } from "node:child_process";
import { appendFileSync, mkdirSync, writeFileSync } from "node:fs";
import { resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { normalizeWorkflowRun } from "./workflow-run.mjs";
const ARTIFACT_NAME = "ci-full-qualification-v1";
const MAX_AGE_MS = 24 * 60 * 60 * 1000;
@@ -119,8 +120,8 @@ function admit() {
// Artifact metadata narrows the search before run lookups. Never scan an
// unbounded history or treat a missing receipt as a successful qualification.
for (const artifact of candidates.slice(0, 3)) {
const run = api(
`repos/${repository}/actions/runs/${artifact.workflow_run.id}`,
const run = normalizeWorkflowRun(
api(`repos/${repository}/actions/runs/${artifact.workflow_run.id}`),
);
// An old run can upload a new artifact when only its gate is rerun.
// Bound the original run age as well so retries cannot renew stale proof.
@@ -133,7 +134,7 @@ function admit() {
run.id === artifact.workflow_run.id &&
run.status === "completed" &&
run.conclusion === "success" &&
run.path === ".github/workflows/ci.yml" &&
run.workflowPath?.file === ".github/workflows/ci.yml" &&
["schedule", "workflow_dispatch"].includes(run.event) &&
run.head_sha === head &&
run.head_branch === branch &&
+6 -1
View File
@@ -30,7 +30,12 @@ if (outputs.tier === "full" && selectedScopes.length !== CI_FLAGS.length)
throw new Error("Full qualification requires every canonical CI scope");
const required = reused ? ["changes"] : ["changes", "static", "test"];
const lanes = {
code: ["build", "test-shard"],
code: [
"build",
"test-shard",
...(outputs.tier === "fast" ? ["test-source"] : []),
],
reverse_tools: ["reverse-tools-quality"],
runtime: ["windows-native-build", "package-e2e"],
package: ["windows-curated"],
sqlite: ["sqlite-runtime"],
+56
View File
@@ -2,6 +2,62 @@
// Shared build inputs are classified once in plan.mjs rather than repeated in
// every workflow.
export const SCOPES = {
reverse_tools: [
"src/application/reverse/**",
"src/application/binary/BinarySession.ts",
"src/cutter/**",
"src/gdb/**",
"src/frida/frida-bindings.d.ts",
"src/objdump/**",
"src/cli/reverseEngineeringCommands.ts",
"src/process/ownedDebuggerSession.ts",
"src/rizin/**",
"src/contracts/*ToolContracts.ts",
"src/server/registerCutterTools.ts",
"src/server/externalMutationAdmission.ts",
"src/server/registerGdbTools.ts",
"src/server/registerReverseEngineeringTools.ts",
"src/server/providerEnvironment.ts",
"src/process/ExecFileOutput.ts",
"src/process/ExecFileOutput.test.ts",
"tests/composition/analysis-sessions/binarySession.test.ts",
"tests/boundary/filesystem/directAnalysisSnapshotReplay.test.ts",
"tests/boundary/filesystem/reverseToolsMutationConfig.test.ts",
"src/server/registerRizinDebugTools.ts",
"tests/boundary/providers/CutterBridge*.test.ts",
"tests/boundary/providers/cutterBridgeProducer.test.ts",
"tests/boundary/providers/GdbSession*.test.ts",
"tests/boundary/providers/GdbCommandQueue.test.ts",
"tests/boundary/providers/gdbTestHelpers.ts",
"tests/boundary/providers/RizinDebugSessionCoverage.part*.test.ts",
"tests/boundary/providers/RizinCommandTimeout.test.ts",
"tests/boundary/providers/RizinTimeoutEvidence.test.ts",
"tests/boundary/providers/RizinDebugSession*.test.ts",
"tests/boundary/providers/RizinInferiorTty.test.ts",
"tests/boundary/providers/RizinTestInferiorTty.ts",
"tests/boundary/process/ownedDebuggerSession.test.ts",
"tests/boundary/cli/gdbStartupCleanupCli.test.ts",
"tests/boundary/cli/reverseEngineeringCommands.test.ts",
"tests/boundary/mcp/cutter*.test.ts",
"tests/boundary/mcp/gdbCancellationMcp.test.ts",
"tests/boundary/mcp/debuggerCancellationMcp.test.ts",
"tests/boundary/mcp/rizinDebuggerCancellationMcp.test.ts",
"tests/boundary/mcp/reverseEngineeringPartialMcp.test.ts",
"tests/boundary/mcp/workflowSnapshotReplayMcp.test.ts",
"tests/boundary/mcp/reverseEngineeringEnvironmentMcp.test.ts",
"tests/support/reverseEngineering*.ts",
"tests/support/ownedRizinCommandEvidenceTests.ts",
"tests/support/reverseDebuggerMcpTestHelpers.ts",
"tests/processOwnershipRunner.ts",
"tests/composition/reverseEngineering*.test.ts",
"vitest.reverse-tools.config.ts",
"vitest.reverse-tools-semantics.config.ts",
"stryker.config.mjs",
"stryker.semantics.config.mjs",
"tsconfig.reverse-tools-mutation.json",
"scripts/prepare-reverse-tools-mutation.mjs",
"scripts/lib/reverse-tools-mutation-targets.mjs",
],
// Apple artifact CLI/MCP lane on macOS, including its focused regressions.
apple: [
"src/native/Apple*",
+2
View File
@@ -133,6 +133,8 @@ try {
for (const clone of report.duplicates)
for (const file of [clone.firstFile, clone.secondFile])
file.name = relative(process.cwd(), file.name).split(sep).join("/");
// Record the actual checker result, including caller-selected thresholds.
report.reaCheck = { exitCode: result.status };
await writeFile(reportPath, JSON.stringify(report, null, 2));
const { sources, clones, percentage } = report.statistics.total;
console.log(
+18
View File
@@ -0,0 +1,18 @@
export interface StaticTaskContext {
readonly version: 1;
readonly sourceSha: string;
readonly sourceClean: boolean;
readonly prHeadSha?: string;
readonly nodeVersion: string;
readonly npmVersion: string;
readonly turboVersion: string;
readonly platform: string;
readonly architecture: string;
readonly taskHashes: Readonly<Record<string, string>>;
}
export function parseStaticTaskContext(value: unknown): StaticTaskContext;
export function recordStaticTaskContext(options?: {
root?: string;
npmCli?: string;
outputDirectory?: string;
}): Promise<StaticTaskContext>;
+104
View File
@@ -0,0 +1,104 @@
import { execFile } from "node:child_process";
import { mkdir, readFile, writeFile } from "node:fs/promises";
import { join, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { promisify } from "node:util";
import { z } from "zod";
const execute = promisify(execFile);
const contextSchema = z.object({
version: z.literal(1),
sourceSha: z.string().regex(/^[a-f0-9]{40}$/u),
sourceClean: z.boolean(),
prHeadSha: z
.string()
.regex(/^[a-f0-9]{40}$/u)
.optional(),
nodeVersion: z.string().min(1),
npmVersion: z.string().min(1),
turboVersion: z.string().min(1),
platform: z.string().min(1),
architecture: z.string().min(1),
taskHashes: z.record(z.string(), z.string().regex(/^[a-f0-9]{16}$/u)),
});
/** Parse the producing check graph's receipt; incomplete provenance is unknown. */
export const parseStaticTaskContext = (value) => contextSchema.parse(value);
/** Retain only named task hashes and tool/source identity, never the environment. */
export async function recordStaticTaskContext({
root = process.cwd(),
npmCli = process.env.npm_execpath,
outputDirectory = join(root, ".cache/static-checks"),
} = {}) {
if (typeof npmCli !== "string" || !npmCli)
throw new Error(
"Run static context recording through npm run ci:static-context",
);
const options = {
cwd: root,
encoding: "utf8",
timeout: 30_000,
maxBuffer: 32 * 1024 * 1024,
};
const [graph, source, status, npmVersion, turbo] = await Promise.all([
execute(
process.execPath,
[npmCli, "run", "--silent", "check:ci:tasks", "--", "--dry=json"],
options,
),
execute("git", ["rev-parse", "HEAD"], options),
execute(
"git",
["status", "--porcelain", "--untracked-files=normal"],
options,
),
execute(process.execPath, [npmCli, "--version"], options),
readFile(join(root, "node_modules/turbo/package.json"), "utf8"),
]);
const tasks = z
.object({
tasks: z
.array(
z.object({
task: z.string().min(1),
hash: z.string().regex(/^[a-f0-9]{16}$/u),
}),
)
.min(1),
})
.parse(JSON.parse(graph.stdout)).tasks;
if (new Set(tasks.map(({ task }) => task)).size !== tasks.length)
throw new Error("Static graph contains duplicate task identities");
const context = parseStaticTaskContext({
version: 1,
sourceSha: source.stdout.trim(),
sourceClean: status.stdout.length === 0,
...(process.env.CI_PR_HEAD_SHA
? { prHeadSha: process.env.CI_PR_HEAD_SHA }
: {}),
nodeVersion: process.version,
npmVersion: npmVersion.stdout.trim(),
turboVersion: z.object({ version: z.string() }).parse(JSON.parse(turbo))
.version,
platform: process.platform,
architecture: process.arch,
taskHashes: Object.fromEntries(tasks.map(({ task, hash }) => [task, hash])),
});
if (process.env.GITHUB_SHA && process.env.GITHUB_SHA !== context.sourceSha)
throw new Error(
"Static context source does not match the workflow revision",
);
await mkdir(outputDirectory, { recursive: true });
await writeFile(
join(outputDirectory, "static-task-context.json"),
JSON.stringify(context, null, 2) + "\n",
);
return context;
}
if (
process.argv[1] &&
resolve(process.argv[1]) === fileURLToPath(import.meta.url)
)
await recordStaticTaskContext();
+46
View File
@@ -0,0 +1,46 @@
import { spawn } from "node:child_process";
import { resolve } from "node:path";
import {
BUILT_TEST_PROJECTS,
SOURCE_TEST_PROJECTS,
} from "../lib/test-projects.mjs";
const [group, ...arguments_] = process.argv.slice(2);
const projects = { source: SOURCE_TEST_PROJECTS, built: BUILT_TEST_PROJECTS }[
group
];
if (!projects) throw new Error("Expected source or built test group");
// The group owns project selection; callers can request reporters or shards.
if (
arguments_.some((argument) => /^--(?:project|exclude)(?:=|$)/u.test(argument))
)
throw new Error("Test groups cannot override their project inventory");
const child = spawn(
process.execPath,
[
resolve("node_modules/vitest/vitest.mjs"),
"run",
...projects.flatMap(({ name }) => ["--project", name]),
...arguments_,
],
{ stdio: "inherit" },
);
let shutdownSignal;
for (const signal of ["SIGINT", "SIGTERM"])
process.on(signal, () => {
shutdownSignal ??= signal;
child.kill(signal);
});
child.once("error", (error) => {
console.error(error.message);
process.exitCode = 1;
});
child.once("close", (code) => {
process.exitCode =
shutdownSignal === "SIGINT"
? 130
: shutdownSignal === "SIGTERM"
? 143
: (code ?? 1);
});
+4 -3
View File
@@ -2,6 +2,7 @@ import { execFileSync } from "node:child_process";
import { appendFileSync } from "node:fs";
import { resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { normalizeWorkflowRun } from "./workflow-run.mjs";
const ARTIFACT_NAME = "test-timings";
const MAX_AGE_MS = 30 * 24 * 60 * 60 * 1000;
@@ -68,8 +69,8 @@ function findTimingRun({ repository, branch, repositoryId, now = Date.now() }) {
.slice(0, MAX_CANDIDATES);
for (const artifact of candidates) {
const run = api(
`repos/${repository}/actions/runs/${artifact.workflow_run.id}`,
const run = normalizeWorkflowRun(
api(`repos/${repository}/actions/runs/${artifact.workflow_run.id}`),
);
const runAge = now - Date.parse(run?.created_at);
if (
@@ -80,7 +81,7 @@ function findTimingRun({ repository, branch, repositoryId, now = Date.now() }) {
run.id === artifact.workflow_run.id &&
run.status === "completed" &&
run.conclusion === "success" &&
run.path === ".github/workflows/ci.yml" &&
run.workflowPath?.file === ".github/workflows/ci.yml" &&
["schedule", "workflow_dispatch"].includes(run.event) &&
run.head_branch === branch &&
run.head_repository?.full_name === repository
+21 -5
View File
@@ -41,9 +41,20 @@ const files = report.files.map(({ name, durationMs, state }) => {
throw new Error(`Test report path is outside the checkout: ${name}`);
return { name: path.split(sep).join("/"), durationMs, state };
});
const complete = process.env.SHARD_RESULT === "success";
// Keep group outcomes intact: an unavailable group is not a completed failure.
const groupResults = [
process.env.SHARD_RESULT,
...(process.env.SOURCE_REQUIRED === "true"
? [process.env.SOURCE_RESULT]
: []),
];
const groupsCompleted = groupResults.every((state) =>
["success", "failure"].includes(state),
);
const passed =
complete && process.env.MERGE_RESULT === "success" && report.success;
groupResults.every((state) => state === "success") &&
process.env.MERGE_RESULT === "success" &&
report.success;
// Successful shards and merged reports must account for the complete portable
// inventory. Coverage thresholds alone cannot prove that every file ran.
const verifyInventory = process.env.CI_VERIFY_TEST_INVENTORY === "true";
@@ -69,7 +80,7 @@ if (process.env.CI_TEST_SELECTION) {
comparison.complete &&
report.unhandledErrors === 0 &&
["passed", "failed"].includes(report.reason) &&
["success", "failure"].includes(process.env.SHARD_RESULT) &&
groupsCompleted &&
["success", "failure"].includes(process.env.MERGE_RESULT),
executionSha: process.env.GITHUB_SHA ?? null,
prHeadSha: process.env.CI_PR_HEAD_SHA ?? null,
@@ -91,7 +102,9 @@ if (passed && verifyInventory) {
);
}
const summary = [
complete ? "## Merged test diagnostics" : "## Partial test diagnostics",
groupsCompleted
? "## Merged test diagnostics"
: "## Partial test diagnostics",
"",
...(selection
? [
@@ -99,11 +112,14 @@ const summary = [
"",
`Plan: ${selection.plan.mode}. Proposed files: ${selection.selected.length}; omitted: ${selection.omitted.length}.`,
`Full-run comparison: ${selection.complete ? "complete" : "incomplete"}; failures outside proposed selection: ${selection.missedFailures.length}.`,
"The complete suite still ran. This report cannot enable omissions or qualify a revision. Skipped, missing, and interrupted observations do not establish parity.",
"This observational report cannot enable omissions or qualify a revision. Skipped, missing, and interrupted observations do not establish parity.",
"",
]
: []),
`Shard result: ${process.env.SHARD_RESULT ?? "unknown"}; merge result: ${process.env.MERGE_RESULT ?? "unknown"}.`,
...(process.env.SOURCE_REQUIRED === "true"
? [`Source result: ${process.env.SOURCE_RESULT ?? "unknown"}.`]
: []),
passed
? "Successful timing history is available."
: "This report is diagnostic only and is not a successful timing baseline.",
+10
View File
@@ -0,0 +1,10 @@
export interface WorkflowPath {
readonly file: string;
readonly ref: string | null;
}
export interface NormalizedWorkflowRun {
readonly workflowPath: WorkflowPath | null;
}
export function normalizeWorkflowRun<T extends Record<string, unknown>>(
value: T,
): Omit<T, "workflowPath"> & NormalizedWorkflowRun;
+15
View File
@@ -0,0 +1,15 @@
/** Keep the API path as evidence and parse its optional ref at the boundary. */
export function normalizeWorkflowRun(value) {
if (typeof value !== "object" || value === null || Array.isArray(value))
throw new Error("workflow_run_malformed");
const match =
typeof value.path === "string" && !/[\u0000-\u001f\u007f]/u.test(value.path)
? /^(\.github\/workflows\/[^/\\@\s]+\.ya?ml)(?:@([^\s]+))?$/u.exec(
value.path,
)
: null;
return {
...value,
workflowPath: match ? { file: match[1], ref: match[2] ?? null } : null,
};
}
@@ -5,6 +5,7 @@ import { fileURLToPath } from "node:url";
import { promisify } from "node:util";
import { TraceMap, eachMapping } from "@jridgewell/trace-mapping";
import { CdpBrowserProvider } from "../../dist/browser/CdpBrowserProvider.js";
import { listBrowserTargetsInputSchema } from "../../dist/domain/browserObservation.js";
import { CdpConnection } from "../../dist/browser/CdpConnection.js";
import { parseEvidence } from "../../dist/domain/evidence.js";
import { traceSourceMap } from "../../dist/javascript/sourceMaps/TraceSourceMap.js";
@@ -89,10 +90,12 @@ async function verifyCase(executable, entrypoint, scenario) {
fixture = await startRuntimeFixtureBrowser(executable, site.origin);
const endpoint = `http://127.0.0.1:${fixture.port}`;
const provider = new CdpBrowserProvider();
const targets = await provider.listTargets({
cdp_endpoint: endpoint,
allowed_origins: [site.origin],
});
const targets = await provider.listTargets(
listBrowserTargetsInputSchema.parse({
cdp_endpoint: endpoint,
allowed_origins: [site.origin],
}),
);
if (!targets.ok) throw targets.error;
const target = targets.value.targets[0];
assert.ok(target, "Owned fixture target missing");
+7 -4
View File
@@ -8,6 +8,7 @@ import { promisify } from "node:util";
import { Client } from "@modelcontextprotocol/client";
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
import { CdpBrowserProvider } from "../../dist/browser/CdpBrowserProvider.js";
import { listBrowserTargetsInputSchema } from "../../dist/domain/browserObservation.js";
import { CdpConnection } from "../../dist/browser/CdpConnection.js";
import { parseEvidence } from "../../dist/domain/evidence.js";
import { webExecutionSchema } from "../../dist/domain/webExecution.js";
@@ -45,10 +46,12 @@ export async function verifyBrowserRuntime(
try {
fixture = await startRuntimeFixtureBrowser(executable, site.origin);
const endpoint = `http://127.0.0.1:${fixture.port}`;
const targets = await new CdpBrowserProvider().listTargets({
cdp_endpoint: endpoint,
allowed_origins: [site.origin],
});
const targets = await new CdpBrowserProvider().listTargets(
listBrowserTargetsInputSchema.parse({
cdp_endpoint: endpoint,
allowed_origins: [site.origin],
}),
);
if (!targets.ok) throw targets.error;
const target = targets.value.targets[0];
assert.ok(target, "owned fixture page target missing");
+36
View File
@@ -19,6 +19,11 @@ export const toolFamilyCatalog = (sources) => {
contracts: [
...sources.nativeContracts.NATIVE_TOOL_CONTRACTS,
...sources.binaryDiagnosticsContracts.BINARY_DIAGNOSTICS_TOOL_CONTRACTS,
...sources.cutterContracts.CUTTER_TOOL_CONTRACTS,
...sources.reverseEngineeringContracts
.REVERSE_ENGINEERING_TOOL_CONTRACTS,
...sources.gdbContracts.GDB_TOOL_CONTRACTS,
...sources.rizinDebugContracts.RIZIN_DEBUG_TOOL_CONTRACTS,
],
},
{
@@ -28,6 +33,7 @@ export const toolFamilyCatalog = (sources) => {
...sources.artifactContracts.ARTIFACT_TOOL_CONTRACTS,
...sources.evmContracts.EVM_TOOL_CONTRACTS,
...sources.goContracts.GO_TOOL_CONTRACTS,
...sources.rustContracts.RUST_TOOL_CONTRACTS,
...sources.wasmContracts.WASM_TOOL_CONTRACTS,
...sources.sqliteContracts.SQLITE_TOOL_CONTRACTS,
...sources.captureContracts.CAPTURE_TOOL_CONTRACTS,
@@ -163,6 +169,32 @@ export const providerCatalog = (sources) => {
activeContracts,
} = electronContractSlices(sources);
return [
{
identity: sources.cutterProvider.CUTTER_PROVIDER_IDENTITY,
contracts: sources.cutterContracts.CUTTER_TOOL_CONTRACTS,
},
{
identity: sources.objdumpProvider.OBJDUMP_PROVIDER_IDENTITY,
contracts:
sources.reverseEngineeringContracts.REVERSE_ENGINEERING_TOOL_CONTRACTS.filter(
({ name }) => name === "inspect_with_objdump",
),
},
{
identity: sources.rizinProvider.RIZIN_PROVIDER_IDENTITY,
contracts:
sources.reverseEngineeringContracts.REVERSE_ENGINEERING_TOOL_CONTRACTS.filter(
({ name }) => name === "execute_rizin_command",
),
},
{
identity: sources.gdbProvider.GDB_PROVIDER_IDENTITY,
contracts: sources.gdbContracts.GDB_TOOL_CONTRACTS,
},
{
identity: sources.rizinDebugProvider.RIZIN_DEBUGGER_PROVIDER_IDENTITY,
contracts: sources.rizinDebugContracts.RIZIN_DEBUG_TOOL_CONTRACTS,
},
{
identity: sources.fridaProvider.FRIDA_PROVIDER_IDENTITY,
contracts: sources.fridaContracts.FRIDA_TOOL_CONTRACTS,
@@ -225,6 +257,10 @@ export const providerCatalog = (sources) => {
identity: sources.goProvider.GO_BINARY_PROVIDER_IDENTITY,
contracts: sources.goContracts.GO_TOOL_CONTRACTS,
},
{
identity: sources.rustProvider.RUST_BINARY_PROVIDER_IDENTITY,
contracts: sources.rustContracts.RUST_TOOL_CONTRACTS,
},
{
identity: sources.sqliteDomain.SQLITE_PROVIDER_IDENTITY,
contracts: sources.sqliteContracts.SQLITE_TOOL_CONTRACTS,
+12
View File
@@ -43,6 +43,16 @@ const SOURCE_PATHS = {
sessionContracts: "dist/contracts/sessionToolContracts.js",
binaryDiagnosticsContracts:
"dist/contracts/native/binaryDiagnosticsToolContracts.js",
cutterContracts: "dist/contracts/cutterToolContracts.js",
cutterProvider: "dist/cutter/CutterBridgeClient.js",
reverseEngineeringContracts:
"dist/contracts/reverseEngineeringToolContracts.js",
gdbContracts: "dist/contracts/gdbToolContracts.js",
gdbProvider: "dist/gdb/GdbSessionManager.js",
rizinDebugContracts: "dist/contracts/rizinDebugToolContracts.js",
objdumpProvider: "dist/objdump/ObjdumpCommand.js",
rizinProvider: "dist/rizin/RizinCommand.js",
rizinDebugProvider: "dist/rizin/RizinDebugSessionManager.js",
fridaContracts: "dist/contracts/fridaToolContracts.js",
fridaProvider: "dist/frida/FridaInstrumentationManager.js",
pwntoolsProvider: "dist/native/pwntools/PwntoolsRelease.js",
@@ -59,6 +69,8 @@ const SOURCE_PATHS = {
evmProvider: "dist/evm/EvmoleRelease.js",
goContracts: "dist/contracts/go/goToolContracts.js",
goProvider: "dist/go/GoBinaryProvider.js",
rustContracts: "dist/contracts/rust/rustToolContracts.js",
rustProvider: "dist/rust/RustBinaryProvider.js",
artifactContracts: "dist/contracts/artifactToolContracts.js",
managedContracts: "dist/contracts/managed/managedToolContracts.js",
firmwareContracts: "dist/contracts/firmware/firmwareToolContracts.js",
+11 -20
View File
@@ -1,17 +1,4 @@
const sourceProjects = [
"domain",
"services",
"adapters",
"composition",
"conformance",
"evaluation",
];
const sourceTest = (path) =>
path.startsWith("src/") ||
["composition", "conformance", "evaluation"].some((project) =>
path.startsWith(`tests/${project}/`),
);
import { SOURCE_TEST_PROJECTS, projectForTest } from "./test-projects.mjs";
/** Parse explicit test paths and an optional branch-comparison base. */
export const parseDevelopmentTestRequest = (mode, arguments_) => {
@@ -35,10 +22,9 @@ export const parseDevelopmentTestRequest = (mode, arguments_) => {
path.split("/").some((part) => part === ".." || part === ".")
)
throw new Error(`Expected an exact repository test path: ${argument}`);
if (mode !== "focused" && !sourceTest(path))
throw new Error(
`Use test:focused for compiled boundary tests: ${path}`,
);
const project = projectForTest(path);
if (mode !== "focused" && project.group !== "source")
throw new Error(`Use test:focused for built test projects: ${path}`);
paths.push(path);
}
}
@@ -72,9 +58,14 @@ export const developmentTestPlan = (request, baseCommit) => {
!/^[a-f0-9]{40,64}$/u.test(baseCommit ?? "")
)
throw new Error("Changed tests require a resolved Git merge base");
const projects = request.mode === "focused" ? [] : sourceProjects;
const projects =
request.mode === "focused"
? []
: SOURCE_TEST_PROJECTS.map(({ name }) => name);
return {
needsBuild: request.paths.some((path) => !sourceTest(path)),
needsBuild: request.paths.some(
(path) => projectForTest(path).group === "built",
),
artifactTasks: Object.entries(artifactConsumers).flatMap(
([task, consumers]) =>
request.paths.some((path) => consumers.includes(path)) ? [task] : [],
+1
View File
@@ -8,6 +8,7 @@ const MIGRATED_PROVIDER_ROOTS = new Set([
"sqlite",
"evm",
"go",
"rust",
"wasm",
"captures",
"signals",
+87 -1
View File
@@ -215,6 +215,27 @@ async function verifyNativeValueAdapters(
const functionEvidence = parseEvidence(analyzed.structuredContent);
assert.equal(functionEvidence.operation, "analyze_function");
assert.equal(functionEvidence.provider.id, "ghidra");
assert.deepEqual(
functionEvidence.normalized_result.facet_availability,
Object.fromEntries(
[
"pseudocode",
"assembly",
"comments",
"callers",
"callees",
"references",
"strings_names",
"cfg",
].map((facet) => [facet, { available: true }]),
),
);
assert.equal(functionEvidence.relationship_coverage?.status, "complete");
assert.ok(
functionEvidence.relationship_coverage.diagnostics.some((diagnostic) =>
diagnostic.includes("indirect calls remain unknown"),
),
);
const functionProfile = analysisProfileSchema.parse(
functionEvidence.analysis_profile,
);
@@ -235,7 +256,11 @@ async function verifyNativeValueAdapters(
);
assert.notEqual(comparison.isError, true, JSON.stringify(comparison));
const comparisonEvidence = parseEvidence(comparison.structuredContent);
assert.equal(comparisonEvidence.normalized_result.status, "unchanged");
assert.equal(
comparisonEvidence.normalized_result.status,
"unchanged",
JSON.stringify(comparisonEvidence.normalized_result.dimensions),
);
assert.deepEqual(
comparisonEvidence.normalized_result,
comparison.structuredContent?.normalized_result,
@@ -243,6 +268,7 @@ async function verifyNativeValueAdapters(
assert.ok(
comparisonEvidence.evidence_links.includes(functionEvidence.evidence_id),
);
await verifyUnresolvedCallEvidence(client);
const bundle = await client.callTool({
name: "get_evidence_bundle",
arguments: {},
@@ -303,3 +329,63 @@ async function verifyNativeValueAdapters(
unknowns: cliGraph.unknowns.length,
};
}
async function verifyUnresolvedCallEvidence(client) {
const inventory = await client.callTool({
name: "list_procedures",
arguments: {},
});
assert.notEqual(inventory.isError, true, JSON.stringify(inventory));
const procedures = parseEvidence(
inventory.structuredContent,
).normalized_result;
const indirect = procedures.find((item) =>
item.value.endsWith("rea_ghidra_inventory_indirect"),
);
const leaf = procedures.find((item) =>
item.value.endsWith("rea_ghidra_inventory_leaf"),
);
assert.ok(
indirect && leaf,
"Source fixture lacks the unresolved callback and its possible target",
);
const analyzed = await client.callTool(
{ name: "analyze_function", arguments: { procedure: indirect.address } },
{ timeout: 180000 },
);
assert.notEqual(analyzed.isError, true, JSON.stringify(analyzed));
const evidence = parseEvidence(analyzed.structuredContent);
assert.equal(evidence.relationship_coverage?.status, "partial");
assert.ok(evidence.normalized_result.unresolved_calls.length > 0);
const traced = await client.callTool(
{
name: "trace_call_path",
arguments: {
start: indirect.address,
goal: leaf.address,
direction: "forward",
},
},
{ timeout: 180000 },
);
assert.notEqual(traced.isError, true, JSON.stringify(traced));
const trace = parseEvidence(traced.structuredContent).normalized_result;
assert.equal(trace.goal_status, "unknown");
assert.equal(trace.truncated, true);
assert.ok(trace.residual_unknowns.length > 0);
const compared = await client.callTool(
{
name: "compare_functions",
arguments: {
left: analyzed.structuredContent,
right: analyzed.structuredContent,
},
},
{ timeout: 180000 },
);
assert.notEqual(compared.isError, true, JSON.stringify(compared));
assert.equal(
parseEvidence(compared.structuredContent).normalized_result.status,
"unknown",
);
}
+19
View File
@@ -131,6 +131,25 @@ export async function verifyGhidraBoundaries(
const externalDossier = await call("analyze_function", {
procedure: external.address,
});
assert.equal(externalDossier.pseudocode, "");
assert.deepEqual(externalDossier.assembly, []);
assert.deepEqual(externalDossier.callees, []);
assert.deepEqual(externalDossier.facet_availability.pseudocode, {
available: false,
reason: "Ghidra does not decompile external functions.",
});
for (const facet of [
"assembly",
"comments",
"callers",
"callees",
"references",
"strings_names",
"cfg",
])
assert.deepEqual(externalDossier.facet_availability[facet], {
available: true,
});
const externalEntry = await call("resolve_containing_procedure", {
address: external.address,
});
+19
View File
@@ -10,6 +10,25 @@ interface StringExpectation {
readonly recognitionOptional?: boolean;
}
/** Verify native fragments against a complete, independently read source extent. */
export function verifyHopperStringFragments(
call: VerifierCall,
inventory: readonly z.output<typeof analysisStringSchema>[],
expectation: {
readonly value: string;
readonly symbol: string;
readonly recognitionOptional?: boolean;
},
): Promise<{
readonly sourceBytes: number;
readonly recognition: {
readonly address: string;
readonly state: "observed" | "not_observed";
readonly decodedObject: "verified" | "unverified";
};
readonly fragments: readonly z.output<typeof analysisStringSchema>[];
}>;
/** Verify source bytes, observed decoding, address filters and literal searches. */
export function verifyHopperStringObjects(
call: VerifierCall,
+84 -56
View File
@@ -106,27 +106,18 @@ async function verifySearchModes(call, address) {
[{ address, value: "REA_Search_Upper" }],
);
const strings = await call("list_strings");
const linux = process.platform === "linux";
const fullLiteral = "REA_LONG_LITERAL_" + "x".repeat(4096) + "needle";
// Recognition is a provider/loader capability, not an adapter guarantee.
// Always retain the original size in raw-byte coverage; Linux additionally
// requires an extent observed to produce native fragmented string objects.
const fullBytes = Buffer.from(fullLiteral + "\0");
const raw = await call("read_bytes", {
address: `${fixtureSymbolPrefix}rea_long_literal`,
length: fullBytes.length,
const fullLiteral = await verifyHopperStringFragments(call, strings, {
symbol: `${fixtureSymbolPrefix}rea_long_literal`,
value: "REA_LONG_LITERAL_" + "x".repeat(4096) + "needle",
recognitionOptional: true,
});
assert.equal(raw.complete, true);
assert.equal(raw.bytes_hex, fullBytes.toString("hex"));
const long = linux
? "REA_FRAGMENTED_LITERAL_" + "x".repeat(512) + "fragment_tail"
: fullLiteral;
const longItem = strings.find(
(item) => long.startsWith(item.value) && item.value.startsWith("REA_"),
);
assert.ok(longItem, "fixture omitted its real long literal");
if (!linux) assert.equal(longItem.address, raw.address);
assert.ok(long.startsWith(longItem.value));
const fragmentedLiteral = await verifyHopperStringFragments(call, strings, {
symbol: `${fixtureSymbolPrefix}rea_fragmented_literal`,
value: "REA_FRAGMENTED_LITERAL_" + "x".repeat(512) + "fragment_tail",
});
const [longItem] = fragmentedLiteral.fragments;
assert.ok(longItem, "fixture omitted its typed fragmented literal");
assert.ok(fragmentedLiteral.fragments.length > 1);
assert.ok(longItem.provider_value.endsWith("…"));
assert.equal(longItem.string.termination, "missing");
const literalProcedure = (await call("list_procedures")).find((item) =>
@@ -154,33 +145,13 @@ async function verifySearchModes(call, address) {
"function dossier discarded typed string provenance",
);
const fragments = strings.filter((item) => {
const offset = BigInt(item.address) - BigInt(longItem.address);
return offset >= 0n && offset < BigInt(Buffer.byteLength(long));
});
assert.equal(fragments.map((item) => item.value).join(""), long);
for (const fragment of fragments) {
assert.equal(
Buffer.byteLength(fragment.value),
fragment.string.byte_length -
(fragment.string.termination === "missing" ? 0 : 1),
);
const bytes = await call("read_bytes", {
address: fragment.address,
length: fragment.string.byte_length,
});
const expected = Buffer.from(
fragment.value + (fragment.string.termination === "missing" ? "" : "\0"),
);
assert.equal(bytes.bytes_hex, expected.toString("hex"));
}
assert.deepEqual(
await call("search_strings", {
pattern: linux ? "fragment_tail" : "needle",
pattern: "fragment_tail",
mode: "literal",
case_sensitive: true,
}),
[fragments.at(-1)],
[fragmentedLiteral.fragments.at(-1)],
);
const expected = strings.filter((item) =>
/^REA_C_(?:ENTRY|LEAF)$/u.test(item.value),
@@ -201,7 +172,7 @@ async function verifySearchModes(call, address) {
value: "REA_UTF8_é_😀",
encoding: "utf-8",
symbol: `${fixtureSymbolPrefix}rea_utf8_literal`,
recognitionOptional: linux,
recognitionOptional: true,
},
{ value: 'REA_ESCAPED_"\\line\nend\t\r', encoding: "utf-8" },
{ value: "REA_LITERAL_BACKSLASH_\\n", encoding: "utf-8" },
@@ -209,33 +180,90 @@ async function verifySearchModes(call, address) {
value: "REA_LITERAL_…",
encoding: "utf-8",
symbol: `${fixtureSymbolPrefix}rea_ellipsis_literal`,
recognitionOptional: linux,
recognitionOptional: true,
},
{
value: "REA_LATIN1_ÿ",
encoding: "latin-1",
symbol: `${fixtureSymbolPrefix}rea_latin1_literal`,
recognitionOptional: linux,
recognitionOptional: true,
},
],
strings,
);
return {
fullLiteralSourceBytes: fullBytes.length,
fragmentedLiteralSourceBytes: Buffer.byteLength(long),
fullLiteralRecognition: {
address: raw.address,
state: strings.some((item) => item.address === raw.address)
? "observed"
: "not_observed",
// Linux validates the original through raw bytes; its required decoded
// fragment/dossier checks exercise the separate supported-size literal.
decodedObject: linux ? "unverified" : "verified",
},
fullLiteralSourceBytes: fullLiteral.sourceBytes,
fragmentedLiteralSourceBytes: fragmentedLiteral.sourceBytes,
fullLiteralRecognition: fullLiteral.recognition,
...objects,
};
}
/** Bind native fragments to exact source bytes without assuming loader recognition. */
export async function verifyHopperStringFragments(
call,
strings,
{ symbol, value, recognitionOptional = false },
) {
const expectedBytes = Buffer.from(value + "\0");
const raw = await call("read_bytes", {
address: symbol,
length: expectedBytes.length,
});
assert.equal(raw.complete, true);
assert.equal(raw.bytes_hex, expectedBytes.toString("hex"));
const start = BigInt(raw.address);
const end = start + BigInt(expectedBytes.length);
const fragments = strings.filter((item) => {
const address = BigInt(item.address);
return address >= start && address < end;
});
if (fragments.length === 0 && recognitionOptional)
return {
sourceBytes: expectedBytes.length,
recognition: {
address: raw.address,
state: "not_observed",
decodedObject: "unverified",
},
fragments,
};
assert.ok(fragments.length > 0, "fixture omitted its typed string fragments");
let next = start;
for (const [index, fragment] of fragments.entries()) {
assert.equal(
BigInt(fragment.address),
next,
"string fragments have a gap, overlap or wrong source identity",
);
const terminal = index === fragments.length - 1;
assert.equal(
fragment.string.termination,
terminal ? "present_or_not_required" : "missing",
);
const expected = Buffer.from(fragment.value + (terminal ? "\0" : ""));
assert.equal(fragment.string.byte_length, expected.length);
const bytes = await call("read_bytes", {
address: fragment.address,
length: expected.length,
});
assert.equal(bytes.complete, true);
assert.equal(bytes.bytes_hex, expected.toString("hex"));
next += BigInt(expected.length);
}
assert.equal(next, end, "string fragments do not cover the source extent");
assert.equal(fragments.map((item) => item.value).join(""), value);
return {
sourceBytes: expectedBytes.length,
recognition: {
address: raw.address,
state: "observed",
decodedObject: "verified",
},
fragments,
};
}
/** Compare native string identities and values with the source fixture's bytes. */
export async function verifyHopperStringObjects(
call,
+48 -5
View File
@@ -327,14 +327,57 @@ export const analyzeFixtureProcedure = async (
options,
procedure,
normalizedResult,
) =>
normalizedResult(
) => {
const reply = await client.callTool(
{
name: "analyze_function",
arguments: { procedure: procedure.address },
},
options,
);
const dossier = normalizedResult(reply, "analyze_function");
assert.deepEqual(reply.structuredContent.relationship_coverage, {
status: "complete",
});
for (const facet of [
"pseudocode",
"assembly",
"comments",
"callers",
"callees",
"references",
"strings_names",
"cfg",
])
assert.deepEqual(dossier.facet_availability[facet], { available: true });
const comparison = normalizedResult(
await client.callTool(
{
name: "analyze_function",
arguments: { procedure: procedure.address },
name: "compare_functions",
arguments: {
left: reply.structuredContent,
right: reply.structuredContent,
},
},
options,
),
"analyze_function",
"compare_functions",
);
assert.deepEqual(
Object.fromEntries(
comparison.dimensions.map(({ dimension, status }) => [dimension, status]),
),
{
identity: "unchanged",
pseudocode: "unchanged",
assembly: "unchanged",
comments: "unchanged",
calls: "unchanged",
references: "unknown",
strings_names: "unchanged",
cfg: "unchanged",
},
JSON.stringify(comparison.dimensions),
);
return dossier;
};
@@ -0,0 +1,182 @@
import { readFileSync } from "node:fs";
import ts from "typescript6";
const compact = (text) => text.replace(/\s+/gu, "");
const nameOf = (node, source) => node.name?.getText(source);
const methodOwner = (node, source) => {
for (let parent = node; parent !== undefined; parent = parent.parent) {
if (ts.isMethodDeclaration(parent) || ts.isConstructorDeclaration(parent))
return {
owner: nameOf(parent.parent, source),
body: parent.body,
method: ts.isConstructorDeclaration(parent)
? "constructor"
: nameOf(parent, source),
};
}
return undefined;
};
const withinOwner = (node, selector, source) => {
if (selector.owner === undefined) return true;
const owner = methodOwner(node, source);
return (
owner?.owner === selector.owner &&
(selector.method === undefined || owner.method === selector.method)
);
};
const contains = (node, predicate) =>
predicate(node) ||
ts.forEachChild(node, (child) => contains(child, predicate)) === true;
const inBlockWithBinding = (node, binding) => {
if (binding === undefined) return true;
let block = node.parent;
while (block !== undefined && !ts.isBlock(block)) block = block.parent;
return block?.statements.some(
(statement) =>
ts.isVariableStatement(statement) &&
statement.declarationList.declarations.some(
(declaration) =>
ts.isIdentifier(declaration.name) &&
declaration.name.text === binding,
),
);
};
const isCommandHandler = (node, command) => {
if (!ts.isArrowFunction(node)) return false;
const property = node.parent;
if (
!ts.isPropertyAssignment(property) ||
!ts.isIdentifier(property.name) ||
property.name.text !== "run"
)
return false;
const call = property.parent.parent;
if (
!ts.isCallExpression(call) ||
!ts.isPropertyAccessExpression(call.expression) ||
!ts.isIdentifier(call.expression.expression) ||
call.expression.expression.text !== "cli" ||
call.expression.name.text !== "command"
)
return false;
const selected = call.arguments[0];
return (
selected !== undefined &&
ts.isPropertyAccessExpression(selected) &&
ts.isIdentifier(selected.expression) &&
selected.expression.text === "CLI_COMMANDS" &&
selected.name.text === command
);
};
const matches = (node, selector, source) => {
if (!withinOwner(node, selector, source)) return false;
if (
selector.direct === true &&
node.parent !== methodOwner(node, source)?.body
)
return false;
switch (selector.kind) {
case "expression":
return (
ts.isBinaryExpression(node) &&
compact(node.getText(source)) === compact(selector.text)
);
case "declaration":
return (
ts.isVariableDeclaration(node) &&
nameOf(node, source) === selector.name &&
inBlockWithBinding(node, selector.withinBlockWithBinding)
);
case "method":
return (
ts.isMethodDeclaration(node) && nameOf(node, source) === selector.name
);
case "constructor":
return ts.isConstructorDeclaration(node);
case "guard":
return (
ts.isIfStatement(node) &&
compact(node.expression.getText(source)) === compact(selector.condition)
);
case "call":
return (
ts.isCallExpression(node) &&
compact(node.expression.getText(source)) === compact(selector.callee) &&
(selector.event === undefined ||
(node.arguments[0] !== undefined &&
ts.isStringLiteral(node.arguments[0]) &&
node.arguments[0].text === selector.event))
);
case "try":
return (
ts.isTryStatement(node) &&
contains(node.tryBlock, (child) =>
selector.assignment !== undefined
? ts.isBinaryExpression(child) &&
child.operatorToken.kind === ts.SyntaxKind.EqualsToken &&
ts.isIdentifier(child.left) &&
child.left.text === selector.assignment
: ts.isCallExpression(child) &&
compact(child.expression.getText(source)) ===
compact(selector.callee),
)
);
case "command-handler":
return isCommandHandler(node, selector.command);
default:
throw new Error(
`Unknown mutation selector kind: ${String(selector.kind)}`,
);
}
};
/** Parse a source once and resolve one owned region for every requested selector. */
export const mutationRanges = (path, selectors) => {
if (!Array.isArray(selectors) || selectors.length === 0)
throw new Error(`Mutation selectors must be nonempty: ${path}`);
for (const selector of selectors)
if (
["method", "constructor", "guard", "call", "try"].includes(
selector.kind,
) &&
typeof selector.owner !== "string"
)
throw new Error(
`Mutation selector requires a named class owner: ${path}`,
);
const source = ts.createSourceFile(
path,
readFileSync(path, "utf8"),
ts.ScriptTarget.Latest,
true,
);
if (source.parseDiagnostics.length !== 0)
throw new Error(
`Cannot select mutations from malformed TypeScript: ${path}`,
);
const found = selectors.map(() => []);
const visit = (node) => {
for (const [index, selector] of selectors.entries())
if (matches(node, selector, source)) found[index].push(node);
ts.forEachChild(node, visit);
};
visit(source);
return selectors.map((selector, index) => {
const candidates = found[index];
if (candidates.length !== 1)
throw new Error(
`Expected one mutation target in ${path}: ${JSON.stringify(selector)}; found ${candidates.length}`,
);
const node = candidates[0];
const first =
source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1;
const last = source.getLineAndCharacterOfPosition(node.getEnd()).line + 1;
return `${path}:${first}-${last}`;
});
};
+10
View File
@@ -0,0 +1,10 @@
export interface TestProjectDefinition {
readonly name: string;
readonly group: "source" | "built";
readonly include: readonly string[];
readonly exclude?: readonly string[];
}
export const SOURCE_TEST_PROJECTS: readonly TestProjectDefinition[];
export const BUILT_TEST_PROJECTS: readonly TestProjectDefinition[];
export function projectForTest(testPath: string): TestProjectDefinition;
+107
View File
@@ -0,0 +1,107 @@
import { matchesGlob } from "node:path";
/** Canonical file ownership shared by Vitest and development-test planning. */
export const SOURCE_TEST_PROJECTS = [
{
name: "domain",
group: "source",
include: ["src/{contracts,domain}/**/*.test.ts"],
},
{
name: "services",
group: "source",
include: ["src/application/**/*.test.ts"],
},
{
name: "adapters",
group: "source",
include: [
"src/*.test.ts",
"src/{apktool,jeb,adb,artifacts,browser,dotnet,evm,firmware,flutter,pcap,ghidra,go,hopper,ida,inspector,javascript,native,process,reference,rust,server,wasm,windows}/**/*.test.ts",
],
},
{
name: "composition",
group: "source",
include: ["tests/composition/**/*.test.ts"],
},
{
name: "conformance",
group: "source",
include: ["tests/conformance/**/*.test.ts"],
exclude: ["tests/conformance/providers/hopper/realHopperSearch.test.ts"],
},
{
name: "evaluation",
group: "source",
include: ["tests/evaluation/**/*.test.ts"],
},
];
export const BUILT_TEST_PROJECTS = [
{
name: "boundary",
group: "built",
include: [
"tests/boundary/**/*.test.ts",
"tests/conformance/providers/hopper/realHopperSearch.test.ts",
],
exclude: [
"tests/boundary/cli/**/*.test.ts",
"tests/boundary/mcp/**/*.test.ts",
"tests/boundary/process/**/*.test.ts",
],
},
{
name: "cli-boundary",
group: "built",
include: ["tests/boundary/cli/**/*.test.ts"],
},
{
name: "process-boundary",
group: "built",
include: ["tests/boundary/process/**/*.test.ts"],
},
{
name: "mcp-boundary",
group: "built",
include: ["tests/boundary/mcp/**/*.test.ts"],
},
{
name: "acceptance",
group: "built",
include: ["tests/acceptance/**/*.test.ts"],
},
{
name: "process-global",
group: "built",
include: ["tests/process-global/**/*.test.ts"],
},
];
const ALL_TEST_PROJECTS = [...SOURCE_TEST_PROJECTS, ...BUILT_TEST_PROJECTS];
/** Return the unique Vitest owner for an exact repository-relative test path. */
export const projectForTest = (testPath) => {
if (
typeof testPath !== "string" ||
testPath.startsWith("/") ||
testPath.includes("\\") ||
testPath.split("/").some((part) => part === ".." || part === ".") ||
!testPath.endsWith(".test.ts")
)
throw new Error(`Expected a normalized repository test path: ${testPath}`);
const owners = ALL_TEST_PROJECTS.filter(
({ include, exclude = [] }) =>
include.some((pattern) => matchesGlob(testPath, pattern)) &&
!exclude.some((pattern) => matchesGlob(testPath, pattern)),
);
if (owners.length !== 1)
throw new Error(
owners.length === 0
? `No test project owns ${testPath}`
: `Multiple test projects own ${testPath}: ${owners.map(({ name }) => name).join(", ")}`,
);
return owners[0];
};
@@ -0,0 +1,19 @@
import { mkdir, rm, symlink } from "node:fs/promises";
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
const root = resolve(dirname(fileURLToPath(import.meta.url)), "..");
const compiler = resolve(root, "node_modules/typescript6");
for (const packageName of ["core", "typescript-checker"]) {
const packagePath = resolve(
root,
"node_modules/@stryker-mutator",
packageName,
);
const nodeModulesPath = resolve(packagePath, "node_modules");
const typescriptPath = resolve(nodeModulesPath, "typescript");
await mkdir(nodeModulesPath, { recursive: true });
await rm(typescriptPath, { recursive: true, force: true });
await symlink(compiler, typescriptPath, "dir");
}
+23 -4
View File
@@ -1,12 +1,31 @@
/** Derive agent and Hopper setup support from the corresponding doctor checks. */
/**
* Host facts the packaged setup support is derived from.
*
* `linuxDistribution` is the distribution record the Hopper installer owner
* parses; it is absent when no distribution could be read, which leaves
* installer applicability unknown rather than unsupported.
*/
export interface SetupHostFacts {
readonly platform: NodeJS.Platform;
readonly linuxDistribution?: {
readonly hopperSetupSupported: boolean;
};
}
/**
* Derive agent setup support from the doctor node check and automated Hopper
* installer applicability from the facts their owners parse. Applicability is
* undefined when its owning fact is unavailable.
*/
export function packageSetupSupport(
checks:
| readonly { readonly name: string; readonly ok: boolean }[]
| undefined,
platform: NodeJS.Platform,
host: SetupHostFacts,
): {
supportedSetupHost: boolean;
hopperSetupSupported: boolean;
hopperReadinessRequired: boolean;
hopperSetupSupported: boolean | undefined;
};
/** Validate --help, --llms, and doctor output and determine host setup support. */
@@ -15,5 +34,5 @@ export function verifyPackageDiscovery(input: {
readonly environment: Readonly<Record<string, string | undefined>>;
}): Promise<{
supportedSetupHost: boolean;
hopperSetupSupported: boolean;
hopperSetupSupported: boolean | undefined;
}>;
+54 -12
View File
@@ -27,15 +27,56 @@ const REQUIRED_LLM_TOPICS = [
"analyze-javascript-application",
];
/** Derive agent and Hopper setup support from the corresponding doctor checks. */
export function packageSetupSupport(checks, platform) {
/**
* Derive agent setup support from the doctor node check and automated Hopper
* installer applicability from the facts their owners parse.
*
* Host readiness and installer applicability are different facts: a
* distribution REA supports can still be absent from the Hopper package's
* tested list, so the doctor host check cannot answer the second question.
* Applicability stays undefined when its owning fact is unavailable, which is
* distinct from a host known to lack an automated installer.
*/
export function packageSetupSupport(checks, host) {
const supportedSetupHost =
checks?.find(({ name }) => name === "node")?.ok === true;
const hopperSetupSupported =
supportedSetupHost &&
checks?.find(({ name }) => name === "host")?.ok === true &&
platform !== "win32";
return { supportedSetupHost, hopperSetupSupported };
const hopperReadinessRequired =
host.platform !== "win32" &&
checks?.find(({ name }) => name === "host")?.ok === true;
return {
supportedSetupHost,
hopperReadinessRequired,
hopperSetupSupported: hopperInstallerSupported(
host,
checks?.find(({ name }) => name === "host")?.ok,
),
};
}
/**
* Whether `rea setup --install-hopper` can install Hopper automatically here.
* On macOS the doctor host check already is the owner's installer predicate
* (macOS 12 or later); on Linux it reports REA host support instead, so the
* distribution's own parsed applicability governs.
*/
function hopperInstallerSupported(host, hostCheckOk) {
if (host.platform === "win32") return false;
if (host.platform === "linux")
return host.linuxDistribution?.hopperSetupSupported;
return hostCheckOk;
}
/**
* The distribution facts the Hopper installer owner parses, taken from the
* built application so the verifier follows the predicate the package ships.
* Loaded only where a distribution can exist, which also keeps the derivation
* above testable without a build.
*/
async function readHostLinuxDistribution() {
if (process.platform !== "linux") return undefined;
const { readLinuxDistribution } =
await import("../dist/application/LinuxHopper.js");
return readLinuxDistribution();
}
/** Validate --help, --llms, and doctor output and determine host setup support. */
@@ -48,10 +89,11 @@ export async function verifyPackageDiscovery({ cli, environment }) {
environment,
);
const doctor = json(doctorExecution.stdout);
const { supportedSetupHost, hopperSetupSupported } = packageSetupSupport(
doctor.checks,
process.platform,
);
const { supportedSetupHost, hopperReadinessRequired, hopperSetupSupported } =
packageSetupSupport(doctor.checks, {
platform: process.platform,
linuxDistribution: await readHostLinuxDistribution(),
});
const hopperReady = doctor.checks?.find(({ name }) => name === "hopper")?.ok;
const expectedDoctorHealth = doctor.checks?.every(({ ok }) => ok) === true;
const missingHelp = REQUIRED_HELP_COMMANDS.filter(
@@ -65,7 +107,7 @@ export async function verifyPackageDiscovery({ cli, environment }) {
missingLlms.length !== 0 ||
doctor.healthy !== expectedDoctorHealth ||
doctorExecution.status !== (expectedDoctorHealth ? 0 : 1) ||
(hopperSetupSupported && hopperReady !== true)
(hopperReadinessRequired && hopperReady !== true)
)
throw new Error(
`packaged CLI discovery or doctor failed: ${JSON.stringify({ helpSetup: help.includes("setup"), llmsDecompile: llms.includes("decompile"), doctor })}`,
+6
View File
@@ -8,4 +8,10 @@ export function assertLinuxPackageProviderFailure(execution: {
export function verifyPackagePlatform(input: {
readonly cli: string;
readonly environment: Readonly<Record<string, string | undefined>>;
readonly platform?: string;
readonly runCommand?: (
command: string,
arguments_: readonly string[],
environment: Readonly<Record<string, string | undefined>>,
) => Promise<string>;
}): Promise<void>;
+29 -15
View File
@@ -1,8 +1,13 @@
import { json, run, runWithStatus } from "./lib/verify-package-core.mjs";
/** Run platform-specific deep-analysis smoke tests. */
export async function verifyPackagePlatform({ cli, environment }) {
if (process.platform === "linux") {
export async function verifyPackagePlatform({
cli,
environment,
platform = process.platform,
runCommand = run,
}) {
if (platform === "linux") {
const unsupportedExecution = await runWithStatus(
cli,
["analyze", process.execPath, "--json"],
@@ -11,25 +16,27 @@ export async function verifyPackagePlatform({ cli, environment }) {
assertLinuxPackageProviderFailure(unsupportedExecution);
} else {
const overview = json(
await run(cli, ["analyze", process.execPath, "--json"], environment),
await runCommand(
cli,
["analyze", process.execPath, "--json"],
environment,
),
);
if (
overview.operation !== "binary_overview" ||
overview.normalized_result?.procedure_count < 1
)
if (!hasPositiveProcedureCount(overview))
throw new Error(
`packaged Hopper-backed analyze CLI failed: ${JSON.stringify(overview)}`,
);
const inspected = json(
await run(cli, ["inspect", process.execPath, "--json"], environment),
await runCommand(
cli,
["inspect", process.execPath, "--json"],
environment,
),
);
if (
inspected.operation !== "binary_overview" ||
inspected.normalized_result?.procedure_count < 1
)
if (!hasPositiveProcedureCount(inspected))
throw new Error("packaged inspect CLI failed");
const functionResult = json(
await run(
await runCommand(
cli,
["function", process.execPath, "0x1000", "--json"],
environment,
@@ -44,7 +51,7 @@ export async function verifyPackagePlatform({ cli, environment }) {
`packaged function CLI failed: ${JSON.stringify(functionResult)}`,
);
const xrefs = json(
await run(
await runCommand(
cli,
["xrefs", process.execPath, "0x1000", "--json"],
environment,
@@ -56,7 +63,7 @@ export async function verifyPackagePlatform({ cli, environment }) {
)
throw new Error(`packaged xrefs CLI failed: ${JSON.stringify(xrefs)}`);
const trace = json(
await run(
await runCommand(
cli,
["trace", process.execPath, "fixture", "--json"],
environment,
@@ -93,3 +100,10 @@ export const assertLinuxPackageProviderFailure = (execution) => {
`packaged Linux Hopper verification did not fail closed: ${JSON.stringify(failure)}`,
);
};
const hasPositiveProcedureCount = (result) =>
typeof result === "object" &&
result !== null &&
result.operation === "binary_overview" &&
Number.isInteger(result.normalized_result?.procedure_count) &&
result.normalized_result.procedure_count > 0;
+2 -3
View File
@@ -356,9 +356,8 @@ const verifySetupApply = async ({
hopperSetupSupported,
}) => {
const status = "ready";
const hopperStatus = hopperSetupSupported
? "needs_confirmation"
: "needs_human";
const hopperStatus =
hopperSetupSupported === true ? "needs_confirmation" : "needs_human";
const firstExecution = await runWithStatus(
cli,
["setup", "--yes", "--all-detected", "--json"],
+2
View File
@@ -4,6 +4,7 @@ import { promisify } from "node:util";
const exec = promisify(execFile);
const packedHopperBridge = "package/bridge/hopper_bridge.py";
const packedCutterBridge = "package/bridge/cutter/rea_bridge.py";
const packedGhidraBridge = "package/bridge/ghidra/ReaGhidraBridge.java";
const packedGhidraActivator =
"package/bridge/ghidra/ReaGhidraBundleActivator.java";
@@ -12,6 +13,7 @@ const packedGhidraActivator =
export async function verifyPackedBridge({ workspace, tarball, packedFiles }) {
for (const path of [
packedHopperBridge,
packedCutterBridge,
packedGhidraBridge,
packedGhidraActivator,
]) {
+214
View File
@@ -0,0 +1,214 @@
#!/usr/bin/env node
import assert from "node:assert/strict";
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
import { execFile } from "node:child_process";
import { createHash, randomUUID } from "node:crypto";
import {
access,
constants,
mkdtemp,
readFile,
rm,
writeFile,
} from "node:fs/promises";
import { tmpdir } from "node:os";
import { join, resolve } from "node:path";
import { promisify } from "node:util";
import { createServer } from "../dist/server/createServer.js";
const execFileAsync = promisify(execFile);
const cli = resolve("scripts/rea.mjs");
const runCli = async (...arguments_) => {
const { stdout } = await execFileAsync(
process.execPath,
[cli, ...arguments_, "--format", "json"],
{
encoding: "utf8",
maxBuffer: 4 * 1024 * 1024,
env: process.env,
},
);
return JSON.parse(stdout);
};
const projectRoot = await mkdtemp(join(tmpdir(), "rea-cutter-smoke-"));
const projectPath = join(projectRoot, "smoke.rzdb");
const rizinQuote = (value) =>
`"${value.replaceAll("\\", "\\\\").replaceAll('"', '\\"')}"`;
const unavailableAnalysis = {
execute: async () => {
throw new Error(
"The Cutter verification does not call unrelated analysis tools.",
);
},
};
const expectedPlatform = {
Linux: "linux",
macOS: "darwin",
Windows: "win32",
}[process.env.EXPECTED_PLATFORM];
if (expectedPlatform !== undefined)
assert.equal(
process.platform,
expectedPlatform,
"Cutter runner did not match its declared platform.",
);
try {
const discovery = await runCli("list-cutter-sessions");
assert.equal(
discovery.discovery_status,
"sessions_found",
"Open upstream Cutter with the REA plugin before running this smoke test.",
);
assert.ok(discovery.sessions.length > 0);
const session = discovery.sessions[0];
assert.ok(session);
assert.ok(
session.cutter_version,
"The upstream Cutter API did not report its version.",
);
if (process.env.REA_CUTTER_EXPECTED_VERSION !== undefined)
assert.ok(
session.cutter_version.includes(process.env.REA_CUTTER_EXPECTED_VERSION),
"The live Cutter version did not match the configured version.",
);
assert.ok(
session.current_file,
"Open a disposable local binary in Cutter before running this smoke test.",
);
const artifactPath = session.current_file;
const artifactDigest = createHash("sha256")
.update(await readFile(artifactPath))
.digest("hex");
const inspection = await runCli(
"cutter-command",
session.session_id,
String(session.document_generation),
"ij",
"--json",
);
assert.equal(inspection.predicate_type, "rea.cutter.command-observation");
assert.ok(
Object.hasOwn(inspection, "raw_result"),
"Cutter ij result was not retained as Evidence.",
);
assert.equal(typeof inspection.raw_result.bin?.arch, "string");
const mcpServer = createServer(
{ kind: "fixed", analysis: unavailableAnalysis },
{
providerEnvironment: process.env,
},
);
const mcpClient = new Client({
name: "rea-cutter-upstream-smoke",
version: "1",
});
const [clientTransport, serverTransport] =
InMemoryTransport.createLinkedPair();
try {
await mcpServer.connect(serverTransport);
await mcpClient.connect(clientTransport);
const mcpDiscovery = await mcpClient.callTool({
name: "list_cutter_sessions",
arguments: {},
});
assert.notEqual(mcpDiscovery.isError, true);
assert.equal(
mcpDiscovery.structuredContent.discovery_status,
"sessions_found",
);
const mcpInspection = await mcpClient.callTool({
name: "cutter_command",
arguments: {
session_id: session.session_id,
expected_generation: session.document_generation,
command: "ij",
json: true,
},
});
assert.notEqual(mcpInspection.isError, true);
assert.deepEqual(
mcpInspection.structuredContent.normalized_result,
inspection.normalized_result,
"Cutter CLI and MCP returned different analysis results.",
);
} finally {
await mcpClient.close();
await mcpServer.close();
}
const annotation = `rea-smoke-${randomUUID()}`;
await runCli(
"cutter-command",
session.session_id,
String(session.document_generation),
`CC ${annotation} @ entry0`,
);
await runCli(
"cutter-command",
session.session_id,
String(session.document_generation),
`Ps ${rizinQuote(projectPath)}`,
);
await access(projectPath, constants.R_OK | constants.W_OK);
await runCli(
"cutter-command",
session.session_id,
String(session.document_generation),
"CC- @ entry0",
);
const removed = await runCli(
"cutter-command",
session.session_id,
String(session.document_generation),
"CC. @ entry0",
);
assert.ok(
!String(removed.raw_result).includes(annotation),
"The in-memory annotation was not removed before project reopening.",
);
await runCli(
"cutter-command",
session.session_id,
String(session.document_generation),
`Po ${rizinQuote(projectPath)}`,
);
const recovered = await runCli(
"cutter-command",
session.session_id,
String(session.document_generation),
"CC. @ entry0",
);
assert.equal(recovered.predicate_type, "rea.cutter.command-observation");
assert.ok(
String(recovered.raw_result).includes(annotation),
"The saved project did not preserve the analysis comment after reopening.",
);
const finalArtifactDigest = createHash("sha256")
.update(await readFile(artifactPath))
.digest("hex");
assert.equal(
finalArtifactDigest,
artifactDigest,
"Cutter project edits changed the executable bytes.",
);
const report = {
ok: true,
platform: process.platform,
cutter_version: session.cutter_version,
document_generation: session.document_generation,
cli_mcp_evidence_parity: true,
annotation_saved_and_reopened: true,
executable_digest_unchanged: true,
};
await writeFile("cutter-smoke.json", `${JSON.stringify(report, null, 2)}\n`, {
mode: 0o600,
});
console.log(JSON.stringify(report));
} finally {
await rm(projectRoot, { recursive: true, force: true });
}
+282
View File
@@ -0,0 +1,282 @@
#!/usr/bin/env node
import assert from "node:assert/strict";
import { execFile } from "node:child_process";
import { createHash } from "node:crypto";
import { mkdtemp, mkdir, readFile, rm } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { fileURLToPath } from "node:url";
import { promisify } from "node:util";
import { Client } from "@modelcontextprotocol/client";
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
import { parseBinaryTarget } from "../dist/application/BinaryTargetResolver.js";
import {
inspectPowerPcReadelf,
assertPowerPcLoadedImage,
assertPowerPcProbe,
assertPowerPcGlobal,
} from "../tests/conformance/ghidra/ppc-checks.mjs";
import { parseEvidence } from "../dist/domain/evidence.js";
import { parseAnalysisSnapshot } from "../dist/domain/analysisSnapshot.js";
import { functionDossierSchema } from "../dist/domain/hopperValues.js";
import { inspectGhidraInstallation } from "../dist/ghidra/GhidraInstallation.js";
import { buildPowerPcFixture } from "../tests/conformance/ghidra/ppc-fixture.mjs";
import { requireMcpOperationResult } from "./lib/mcp-verifier-results.mjs";
import { createVerifierRun, completeVerifierRun } from "./lib/verifier-run.mjs";
// Optional cross-target lane. No tool acquisition and no target execution.
if (process.argv.length !== 2)
throw new Error("Usage: node scripts/verify-real-ghidra-ppc.mjs");
if (!["linux", "darwin"].includes(process.platform))
throw new Error(
"PowerPC verification requires a supported Linux/macOS Ghidra host",
);
if (process.env.GHIDRA_INSTALL_DIR === undefined)
throw new Error("Missing prerequisite: caller-supplied GHIDRA_INSTALL_DIR");
const installation = inspectGhidraInstallation({
environment: process.env,
installDir: process.env.GHIDRA_INSTALL_DIR,
...(process.env.JAVA_HOME === undefined
? {}
: { javaHome: process.env.JAVA_HOME }),
});
if (installation.status !== "available")
throw new Error(
`Ghidra prerequisite unavailable: ${JSON.stringify(installation)}`,
);
const execute = promisify(execFile);
const entrypoint = fileURLToPath(new URL("./rea.mjs", import.meta.url));
const run = createVerifierRun();
const workspace = await mkdtemp(join(tmpdir(), "rea-ppc-proof-"));
const runtime = join(workspace, "runtime");
await mkdir(runtime);
const env = {
PATH: process.env.PATH ?? "/usr/bin:/bin",
TMPDIR: runtime,
REA_LOG_LEVEL: "silent",
REA_ANALYSIS_PROVIDER: "ghidra",
REA_PROCESS_RUN_ID: run.run_id,
GHIDRA_INSTALL_DIR: installation.installDir,
JAVA_HOME: installation.javaHome,
HOPPER_LAUNCHER_PATH: "/rea-unconfigured-deep-provider/hopper",
};
for (const setting of ["GHIDRA_HEADLESS_MAXMEM", "GHIDRA_MAXMEM"]) {
if (process.env[setting] !== undefined) env[setting] = process.env[setting];
}
const reports = [];
let primaryFailure;
try {
{
const fixture = await buildPowerPcFixture(workspace);
const independent = await inspectPowerPcReadelf(fixture.path);
const resolved = await parseBinaryTarget(fixture.path);
if (!resolved.ok) throw resolved.error;
assert.deepEqual(
resolved.value.powerpc,
independent.powerpc,
"REA ELF interpretation disagrees with GNU readelf",
);
assert.equal(resolved.value.sha256, fixture.sha256);
const snapshotPath = join(workspace, "ppc.snapshot.json");
const transport = new StdioClientTransport({
command: process.execPath,
args: [entrypoint, "mcp"],
env,
stderr: "pipe",
});
const client = new Client({ name: "rea-real-ppc-proof", version: "1" });
let stderr = "";
transport.stderr?.on("data", (chunk) => {
stderr = (stderr + chunk.toString()).slice(-65536);
});
const call = async (name, args = {}) => {
const reply = await client.callTool(
{ name, arguments: args },
undefined,
{ timeout: 180000 },
);
return requireMcpOperationResult(reply, name);
};
try {
await client.connect(transport);
const target = await call("open_binary", {
path: fixture.path,
provider_id: "ghidra",
});
assert.equal(target.architecture, "powerpc");
assert.equal(target.sha256, fixture.sha256);
// ELF load-image verification is not the DOS comparison lane. Its retained
// observations still expose the actual Ghidra language and loaded bytes;
// the plain loader would have chosen e500 for this header.
const image = await call("inspect_native_load_image");
assertPowerPcLoadedImage(image.observations, fixture.sha256);
const procedures = await call("list_procedures");
const entry = procedures.find((p) => p.value === "rea_ppc_entry");
const leaf = procedures.find((p) => p.value === "rea_ppc_leaf");
assert.ok(entry, "Entry function missing from real Ghidra inventory");
assert.ok(leaf, "Leaf function missing from real Ghidra inventory");
assert.equal(
BigInt(entry.address),
BigInt(independent.symbols.rea_ppc_entry),
);
assert.equal(
BigInt(leaf.address),
BigInt(independent.symbols.rea_ppc_leaf),
);
const probe = independent.symbols.rea_ppc_probe;
assert.ok(
procedures.some(
(p) =>
p.value === "rea_ppc_probe" && BigInt(p.address) === BigInt(probe),
),
);
const move = await call("inspect_native_instruction", { address: probe });
const branch = await call("inspect_native_instruction", {
address: `0x${(BigInt(probe) + 8n).toString(16)}`,
});
assertPowerPcProbe(move, branch, probe);
const global = await call("read_bytes", {
address: independent.symbols.rea_ppc_global,
length: 4,
});
assert.equal(global.returned_bytes, 4);
assertPowerPcGlobal(global.bytes_hex);
const marker = await call("read_bytes", {
address: independent.symbols.rea_ppc_marker,
length: 29,
});
assert.equal(
marker.bytes_hex,
Buffer.from("rea-ppc-source-owned-fixture\0").toString("hex"),
);
const callees = await call("procedure_callees", {
procedure: entry.address,
});
assert.ok(
callees.includes(leaf.address),
"Expected direct call not recovered",
);
const assembly = await call("procedure_assembly", {
procedure: entry.address,
});
assert.ok(assembly.trim().length > 0);
const dossier = functionDossierSchema.parse(
await call("analyze_function", { procedure: entry.address }),
);
assert.ok(dossier.pseudocode.trim().length > 0);
const mapping = await call("address_to_file_offset", {
address: entry.address,
});
const memory = await call("read_bytes", {
address: entry.address,
length: 16,
});
const sourceBytes = await readFile(fixture.path);
assert.equal(memory.returned_bytes, 16);
assert.equal(
memory.bytes_hex,
sourceBytes
.subarray(mapping.file_offset, mapping.file_offset + 16)
.toString("hex"),
);
const saved = await call("close_binary", {
snapshot_path: snapshotPath,
});
assert.ok(saved.evidence_records > 0);
const snapshot = parseAnalysisSnapshot(
JSON.parse(await readFile(snapshotPath, "utf8")),
);
assert.equal(snapshot.target.architecture, "powerpc");
assert.equal(
snapshot.binding.analysis_profile.parameters.language_id,
"PowerPC:BE:32:default",
);
assert.ok(snapshot.evidence_bundle.records.length > 0);
for (const evidence of snapshot.evidence_bundle.records)
assert.equal(parseEvidence(evidence).subject?.architecture, "powerpc");
await call("open_binary", {
path: fixture.path,
provider_id: "ghidra",
snapshot_path: snapshotPath,
});
assert.deepEqual(await call("list_procedures"), procedures);
await call("close_binary");
// Same public operation through CLI, not a private injected provider.
const cli = await execute(
process.execPath,
[
entrypoint,
"function",
fixture.path,
"rea_ppc_entry",
"--provider",
"ghidra",
"--json",
],
{ env, timeout: 240000, maxBuffer: 16 * 1024 * 1024 },
);
const evidence = parseEvidence(JSON.parse(cli.stdout));
assert.equal(evidence.subject?.architecture, "powerpc");
assert.equal(evidence.subject?.digest.sha256, fixture.sha256);
const cliDossier = functionDossierSchema.parse(
evidence.normalized_result,
);
assert.equal(cliDossier.procedure.address, dossier.procedure.address);
assert.ok(cliDossier.pseudocode.trim().length > 0);
assert.equal(
createHash("sha256")
.update(await readFile(fixture.path))
.digest("hex"),
fixture.sha256,
"Analysis modified the source executable",
);
reports.push({
...fixture,
independent_reader: independent,
effective_language: image.observations.language_id,
effective_compiler_spec: image.observations.compiler_spec_id,
checks: [
"independent ELF header and symbols",
"loaded Ghidra identity and bound language",
"fixed instruction bytes and immediate",
"conditional branch destination",
"global word and marker bytes",
"CLI/MCP and snapshot identity",
],
procedures: procedures.length,
status: "passed",
});
} catch (cause) {
throw new Error(`PowerPC verification failed; MCP stderr: ${stderr}`, {
cause,
});
} finally {
try {
await client.close();
} finally {
await transport.close();
}
}
}
} catch (cause) {
primaryFailure = cause;
}
const completed = await completeVerifierRun(run);
if (
completed.process_lineage.status !== "verified" ||
completed.process_lineage.descendants.length !== 0
)
throw new Error(
`Cleanup unverified; retained diagnostic workspace: ${workspace}`,
{ cause: primaryFailure },
);
if (primaryFailure !== undefined)
throw new Error(
`PowerPC verification failed; retained workspace: ${workspace}`,
{
cause: primaryFailure,
},
);
await rm(workspace, { recursive: true, force: true });
console.log(JSON.stringify({ ...completed, fixtures: reports }, null, 2));
+1 -1
View File
@@ -213,7 +213,7 @@ const verifyCurrentTarget = async (client, options) => {
);
return {
procedure: dossier.procedure,
procedureCount: procedures.total,
procedureCount: procedures.length,
boundedPseudocodeChars: boundedPseudocode.length,
analyzedPseudocodeChars: [...dossier.pseudocode].length,
callerCount: relationships.procedure_callers.length,
+52 -18
View File
@@ -276,12 +276,41 @@ try {
)
).stdout.split(/\r?\n/);
if (nativeHelp.at(-1) === "") nativeHelp.pop();
const nativeCatalogText = (
await execute(
process.env.REA_SIGROK_COMMAND,
["--dont-scan", "--list-supported"],
{ env: environment, timeout: 30000, maxBuffer: 4 * 1024 * 1024 },
)
).stdout;
const catalogHeading = "Supported protocol decoders:\n";
assert.ok(nativeCatalogText.includes(catalogHeading));
// Independent native-output oracle, without importing the production parser.
const nativeCatalog = nativeCatalogText
.split(catalogHeading)[1]
.trim()
.split("\n")
.map((line) => {
const record = line.trimStart();
const separator = record.indexOf(" ");
assert.ok(separator > 0);
return {
id: record.slice(0, separator),
name: record.slice(separator).trimStart(),
};
});
assert.ok(nativeCatalog.length > 0);
for (const input of [
{ query: "uart" },
{},
{ query: "UaRt" },
{ limit: 1 },
{ offset: 1, limit: 2 },
{ limit: null },
{ offset: nativeCatalog.length, limit: 2 },
{ decoder: "uart" },
{ decoder: "uart", query: "BaUd" },
{ decoder: "uart", offset: 50, limit: null },
{ decoder: "uart", query: "[" },
{ query: "rea_no_such_decoder" },
]) {
const started = performance.now();
@@ -306,23 +335,28 @@ try {
JSON.stringify(response),
),
});
if (input.decoder) {
const matched = nativeHelp
.map((text, i) => ({ line_number: i + 1, text }))
.filter(({ text }) =>
text.toLowerCase().includes((input.query ?? "").toLowerCase()),
);
assert.deepEqual(
report.help_lines,
matched.slice(
input.offset ?? 0,
input.limit === null
? undefined
: (input.offset ?? 0) + (input.limit ?? 50),
),
);
} else if (input.query === "uart")
assert.ok(report.decoders.some(({ id }) => id === "uart"));
const nativeRecords = input.decoder
? nativeHelp.map((text, i) => ({ line_number: i + 1, text }))
: nativeCatalog;
const matched = nativeRecords.filter((record) =>
("text" in record ? record.text : `${record.id} ${record.name}`)
.toLowerCase()
.includes((input.query ?? "").toLowerCase()),
);
const offset = input.offset ?? 0;
const page = matched.slice(
offset,
input.limit === null ? undefined : offset + (input.limit ?? 50),
);
assert.deepEqual(input.decoder ? report.help_lines : report.decoders, page);
assert.deepEqual(input.decoder ? report.decoders : report.help_lines, []);
assert.deepEqual(report.output_window, {
unit: input.decoder ? "help-lines" : "decoders",
examined: nativeRecords.length,
matching: matched.length,
returned: page.length,
has_more: offset + page.length < matched.length,
});
const flags = Object.entries(input).flatMap(([key, value]) =>
value === null ? ["--all"] : [`--${key}`, String(value)],
);
+39 -10
View File
@@ -190,12 +190,21 @@ try {
const candidate = join(candidateRoot, "module.wasm");
await writeFile(join(candidateRoot, "source.wat"), "(module (memory 2))");
await tool("wat2wasm", ["source.wat", "-o", "module.wasm"], candidateRoot);
const glue = join(fixtureRoot, "glue.js");
await writeFile(
glue,
'fetch("./module.wasm"); new URL("https://example.invalid/module.wasm?version=1", import.meta.url);',
const glueSource =
'fetch("./module.wasm"); new URL("https://example.invalid/module.wasm?version=1", import.meta.url);';
const glueSources = [
glueSource,
`\uFEFF${glueSource}`,
`\uFEFF\n${glueSource}`,
`#!/usr/bin/env node\n${glueSource}`,
`\uFEFF#!/usr/bin/env node\n${glueSource}`,
];
const gluePaths = glueSources.map((_, index) =>
join(fixtureRoot, `glue-${index}.js`),
);
const input = { path, glue_paths: [glue], candidate_paths: [candidate] };
for (const [index, gluePath] of gluePaths.entries())
await writeFile(gluePath, glueSources[index]);
const input = { path, glue_paths: gluePaths, candidate_paths: [candidate] };
assert.ok(ajv.validate(advertised.inputSchema, input));
const cliValue = await inspectCli(input);
assert.equal(cliValue.category, undefined, JSON.stringify(cliValue));
@@ -219,11 +228,31 @@ try {
assert.equal(report.wat.sha256, sha256(wat));
assert.equal(report.headers, `${headers}\n`);
assert.equal(report.details, details.slice(1));
assert.equal(report.glue[0].artifact.sha256, sha256(await readFile(glue)));
assert.deepEqual(
report.glue[0].references.map(({ candidate_paths }) => candidate_paths),
[[path], [path, candidate]],
);
assert.equal(report.glue.length, glueSources.length);
for (const [index, source] of glueSources.entries()) {
const observed = report.glue[index];
assert.equal(observed.artifact.path, gluePaths[index]);
assert.equal(observed.artifact.sha256, sha256(source));
assert.equal(observed.artifact.bytes, Buffer.byteLength(source));
assert.equal(await readFile(gluePaths[index], "utf8"), source);
assert.equal(observed.parse_status, "complete");
assert.deepEqual(
observed.references.map(({ candidate_paths }) => candidate_paths),
[[path], [path, candidate]],
);
assert.deepEqual(
observed.references.map(({ line, column }) => ({ line, column })),
["./module.wasm", "https://example.invalid/module.wasm?version=1"].map(
(value) => {
const offset = source.indexOf(`"${value}"`);
return {
line: source.slice(0, offset).split("\n").length,
column: offset - source.lastIndexOf("\n", offset) - 1,
};
},
),
);
}
assert.notEqual(report.candidates[0].sha256, report.candidates[1].sha256);
for (const command of report.tool_profile.commands)
assert.equal(command.sha256, sha256(await readFile(command.path)));
+21 -6
View File
@@ -5,7 +5,9 @@ import {
mkdir,
mkdtemp,
readdir,
rmdir,
rm,
stat,
symlink,
writeFile,
} from "node:fs/promises";
@@ -52,7 +54,7 @@ try {
join(workspace, "dist", "windows", "WindowsNativeLoader.js"),
).href;
const source = `import assert from 'node:assert/strict';
import {readdirSync,renameSync,statSync} from 'node:fs';
import {existsSync,mkdirSync,readdirSync,renameSync,statSync} from 'node:fs';
import {join} from 'node:path';
import {systemWindowsNativeAuthority} from ${JSON.stringify(loader)};
const temp=process.env.TEMP;
@@ -62,14 +64,20 @@ assert.equal(first.retryable,true);
assert.match(first.reason,/Delete owned object by handle failed.*Win32 5/s);
const [name,...extra]=readdirSync(temp);assert.ok(name);assert.equal(extra.length,0);
const path=join(temp,name);const identity=statSync(path,{bigint:true});
assert.throws(()=>renameSync(path,path+'-replacement'));
assert.equal(statSync(path,{bigint:true}).ino,identity.ino);
// Ownership follows the retained NTFS handle even when the directory moves.
// A replacement at its old pathname must remain caller-owned.
const moved=path+'-renamed';renameSync(path,moved);
assert.equal(statSync(moved,{bigint:true}).ino,identity.ino);
mkdirSync(path);const replacement=statSync(path,{bigint:true});
assert.notEqual(replacement.ino,identity.ino);
if(process.argv[2]!=='teardown'){
const second=systemWindowsNativeAuthority();assert.equal(second.available,true);
assert.equal(readdirSync(temp).length,0);
assert.equal(existsSync(moved),false);
assert.deepEqual(readdirSync(temp),[name]);
assert.equal(statSync(path,{bigint:true}).ino,replacement.ino);
assert.equal(systemWindowsNativeAuthority(),second);
}
console.log(JSON.stringify({mode:process.argv[2],firstFailed:true,retainedOwner:true,inode:identity.ino.toString()}));
console.log(JSON.stringify({mode:process.argv[2],firstFailed:true,retainedOwner:true,inode:identity.ino.toString(),replacementName:name,replacementInode:replacement.ino.toString()}));
`;
const fixture = join(workspace, "probe.mjs");
await writeFile(fixture, source);
@@ -85,10 +93,17 @@ console.log(JSON.stringify({mode:process.argv[2],firstFailed:true,retainedOwner:
}),
);
assert.equal(observed.retainedOwner, true);
assert.deepEqual(await readdir(temp), [observed.replacementName]);
const replacement = join(temp, observed.replacementName);
assert.equal(
(await stat(replacement, { bigint: true })).ino.toString(),
observed.replacementInode,
);
await rmdir(replacement);
assert.deepEqual(await readdir(temp), []);
}
process.stdout.write(
`${JSON.stringify({ ok: true, controlledDispositionFailure: true, retainedOwner: true, retryRecovers: true, successfulAdmissionCached: true, environmentTeardownCleansProbe: true, issue1701HostCauseReproduced: false })}\n`,
`${JSON.stringify({ ok: true, controlledDispositionFailure: true, retainedOwner: true, renamedOwnerCleanup: true, replacementPreserved: true, retryRecovers: true, successfulAdmissionCached: true, environmentTeardownCleansProbe: true, issue1701HostCauseReproduced: false })}\n`,
);
} finally {
await rm(workspace, { recursive: true, force: true });
+49
View File
@@ -148,6 +148,10 @@ process.stdout.write(JSON.stringify({executable:basename(process.execPath),abiVe
"//localhost/share/target.bin",
])
assert.throws(() => native.call("open", [rejected]));
assert.throws(
() => native.call("cutter_bridge_verify_directory", [sourceDirectory]),
/owner|DACL/u,
);
report.controls.ordinaryDriveSeparatorsAndRequestedIdentity = true;
// An owned runtime's DELETE lease conflicts with a fresh parent admission.
// This produces a genuine sharing failure after successful authority caching,
@@ -282,6 +286,10 @@ process.stdout.write(JSON.stringify({executable:basename(process.execPath),abiVe
() => native.call("open", [join(junction, "target.bin")]),
/Reparse/u,
);
assert.throws(
() => native.call("cutter_bridge_verify_directory", [junction]),
/Reparse/u,
);
assert.throws(() => native.call("open", [source + ":stream"]));
const runtime = native.call("runtime_create", [
workspace.replaceAll("\\", "/"),
@@ -326,6 +334,47 @@ process.stdout.write(JSON.stringify({executable:basename(process.execPath),abiVe
"descriptor.json",
Buffer.from("fixture"),
]);
assert.equal(
native.call("cutter_bridge_verify_directory", [runtime.path]).privateDacl,
true,
);
assert.equal(
native
.call("cutter_bridge_read_descriptor", [
runtime.path,
"descriptor.json",
64 * 1024,
])
.toString("utf8"),
"fixture",
);
const descriptorJunction = join(runtime.path, "descriptor-link.json");
await symlink(sourceDirectory, descriptorJunction, "junction");
assert.throws(() =>
native.call("cutter_bridge_read_descriptor", [
runtime.path,
"descriptor-link.json",
64 * 1024,
]),
);
assert.throws(
() =>
native.call("cutter_bridge_read_descriptor", [
runtime.path,
"descriptor.json",
3,
]),
/byte limit/u,
);
assert.throws(
() =>
native.call("cutter_bridge_read_descriptor", [
runtime.path,
"..\\escape.json",
64 * 1024,
]),
/filename component/u,
);
assert.throws(() =>
native.call("runtime_write", [
runtime.handle,