Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions scripts/expected-failure-log.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Marks the output of a deliberate negative control in a job log.
*
* Some proofs run a control that must fail for one exact reason, then verify
* that failure. Its output is evidence and stays in the log, which outlives
* the job's artifacts. Every line it prints carries `EXPECTED_FAILURE_PREFIX`,
* so neither a reader nor `failingLines` (`scripts/pr-status.ts`) takes its
* designed failure for the job's. The verdict on the control is printed by
* the parent without the prefix: a control that fails for any other reason
* still fails the job in plain text (#2921).
*/
export const EXPECTED_FAILURE_PREFIX = "expected-failure control | ";

/** Copies `stream` to `write`, prefixing every line, including a final line without a newline. */
export async function relayExpectedFailure(stream: ReadableStream<Uint8Array>, write: (text: string) => void): Promise<void> {
const decoder = new TextDecoder();
let pending = "";
for await (const chunk of stream) {
pending += decoder.decode(chunk, { stream: true });
const lines = pending.split("\n");
pending = lines.pop()!;
for (const line of lines) write(`${EXPECTED_FAILURE_PREFIX}${line}\n`);
}
pending += decoder.decode();
if (pending) write(`${EXPECTED_FAILURE_PREFIX}${pending}\n`);
}

/** Runs a negative control with every line it prints marked, and returns its exit code. */
export async function runExpectedFailureControl(argv: string[]): Promise<number> {
const child = Bun.spawn(argv, { stdin: "ignore", stdout: "pipe", stderr: "pipe" });
await Promise.all([
relayExpectedFailure(child.stdout, text => process.stdout.write(text)),
relayExpectedFailure(child.stderr, text => process.stderr.write(text)),
]);
return await child.exited;
}
15 changes: 15 additions & 0 deletions scripts/native-proof/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,21 @@ expected failure with `qualification: false`; it does not turn the failing
invocation into a healthy fifth matrix cell. The selected hosted runtime job
therefore exercises the reproduction under its enforced AppArmor profile too.

So every `runtime_host` log, green or red, holds a Pi UID 0 invocation that
fails `NATIVE_AUTOMATIC_INDEX_COMPLETED: NativeBrainManagerError: Native manager
outcome is unknown … AbortError` and then `Native hosted proof failed (1)`.
That is the control failing as designed. The parent prints each of its lines
behind `expected-failure control | ` (`scripts/expected-failure-log.ts`), and
`bun scripts/pr-status.ts <pr> --failures --logs <dir>` counts them instead of
listing them. The plain lines after them are the verdict.
`Verified expected automatic-index failure …` means the control passed. A
thrown `NATIVE_INDEX_RELEASE_REPRO_<fact>` means it did not fail as designed:
it failed somewhere else, or its evidence is incomplete. Every other failure in
the job belongs to the phase that `BRAIN_RESOURCE_RECEIPT` records with
`"success":false`. #2921 traced six recorded "automatic-index aborts" to this
control. Each of those jobs had failed for a different, separately owned
reason.

## Reference pool allocation

`bun scripts/prove-reference-pool.ts` is the reference pool's required runtime
Expand Down
13 changes: 10 additions & 3 deletions scripts/pr-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { mkdirSync, writeFileSync } from "node:fs";
import { join } from "node:path";
import { DEFAULT_REPO, type Gh } from "./issue-queue";
import { RECEIPT_START } from "./check-receipt";
import { EXPECTED_FAILURE_PREFIX } from "./expected-failure-log";

const realGh: Gh = args => {
const result = Bun.spawnSync(["gh", ...args], { stdout: "pipe", stderr: "pipe" });
Expand Down Expand Up @@ -55,11 +56,17 @@ export function summarizeChecks(rollup: readonly Rollup[]): Checks & { total: nu
const ANSI = /\u001b\[[0-9;]*[A-Za-z]/g;
const FAILING = /\(fail\)|\berror\b[:\s]|\bError:|✗|\bFAIL\b|##\[error\]|Process completed with exit code [1-9]/;

/** The lines of a job log worth reading: failures, without timestamps or colour. */
/**
* The lines of a job log worth reading: failures, without timestamps or colour.
* A deliberate negative control's lines are counted, not shown: it fails by
* design, and its parent reports in plain text whether it failed as designed.
*/
export function failingLines(log: string, limit = 30): string[] {
const lines = log.split("\n").map(line => line.replace(ANSI, "").replace(/^\d{4}-\d{2}-\d{2}T[\d:.]+Z /, "").trimEnd());
const found = lines.filter(line => FAILING.test(line));
return found.length > limit ? [...found.slice(0, limit), `(+${found.length - limit} more failing lines)`] : found;
const failing = lines.filter(line => FAILING.test(line));
const found = failing.filter(line => !line.startsWith(EXPECTED_FAILURE_PREFIX)), control = failing.length - found.length;
const cut = found.length > limit ? [...found.slice(0, limit), `(+${found.length - limit} more failing lines)`] : found;
return control ? [...cut, `(${control} line${control === 1 ? "" : "s"} of a deliberate expected-failure control left out)`] : cut;
}

export interface StatusIo { gh?: Gh; out: (text: string) => void }
Expand Down
8 changes: 4 additions & 4 deletions scripts/prove-native-host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { chmodSync, mkdtempSync, mkdirSync, readFileSync, readdirSync, realpathSync, writeFileSync } from "node:fs";
import { basename, dirname, join, resolve } from "node:path";
import { verifyIndexReleaseReproduction } from "./native-proof/verify-index-release-repro.js";
import { EXPECTED_FAILURE_PREFIX, runExpectedFailureControl } from "./expected-failure-log.js";

import { ownedCleanupComplete } from "./native-proof/verify-owned-remove.js";

Expand Down Expand Up @@ -90,10 +91,9 @@ if (import.meta.main) {
// Four healthy cells qualify first. This separate negative control must
// fail the original index-completion assertion for the measured reason.
const before = new Set(readdirSync(output));
console.log("Verifying the deliberately retained index namespace reproduces the expected failure.");
const reproduction = Bun.spawn([process.execPath, import.meta.filename, "--backend=pi", "--app-uid=0", "--retain-index-namespace"],
{ stdin: "ignore", stdout: "inherit", stderr: "inherit" });
const code = await reproduction.exited;
// #2921: its designed failure reads like the job's, so every line it prints is marked.
console.log(`Verifying the deliberately retained index namespace reproduces the expected failure. Its lines carry "${EXPECTED_FAILURE_PREFIX.trim()}"; the verdict follows.`);
const code = await runExpectedFailureControl([process.execPath, import.meta.filename, "--backend=pi", "--app-uid=0", "--retain-index-namespace"]);
const created = readdirSync(output, { withFileTypes: true }).filter(entry => entry.isDirectory() && !before.has(entry.name));
if (created.length !== 1) throw Error("Native index-release reproduction did not retain exactly one owned invocation");
const receipt = verifyIndexReleaseReproduction(join(output, created[0]!.name), code);
Expand Down
16 changes: 16 additions & 0 deletions scripts/skill-tests/pr-status.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { join } from "node:path";
import type { Gh } from "../issue-queue";
import { failingLines, main, summarizeChecks } from "../pr-status";
import { RECEIPT_START } from "../check-receipt";
import { EXPECTED_FAILURE_PREFIX } from "../expected-failure-log";

const REPO = "schlessera/brain-kit";
const HEAD = "a".repeat(40), BASE = "b".repeat(40), OLD_BASE = "c".repeat(40), MERGE = "d".repeat(40);
Expand Down Expand Up @@ -47,6 +48,21 @@ describe("reading a job log", () => {
expect(failingLines(log)).toEqual(["(fail) the ship > reefs the sail [4.01ms]", "error: expect(received).toBe(expected)", "##[error]Process completed with exit code 1."]);
});

test("a deliberate expected-failure control's lines are left out, and counted", () => {
// #2921: runtime_host's retained-namespace control fails by design in every
// run, green or red; its lines were read as the job's failure six times.
const control = [
"2026-07-12T09:00:00.0000000Z Verifying the deliberately retained index namespace reproduces the expected failure.",
`2026-07-12T09:00:01.0000000Z ${EXPECTED_FAILURE_PREFIX}{"kind": "command", "code": 1, "stderr": "error: NATIVE_AUTOMATIC_INDEX_COMPLETED: AbortError"}`,
`2026-07-12T09:00:01.1000000Z ${EXPECTED_FAILURE_PREFIX}\u001b[31merror\u001b[0m: Native hosted proof failed (1); inspect run-pi-uid0-Ithaca.`,
"2026-07-12T09:00:02.0000000Z Verified expected automatic-index failure, namespace correlation and owned cleanup; all four healthy cells remain qualified.",
"2026-07-12T09:00:03.0000000Z error: Identity fixture mutation anchor changed",
"2026-07-12T09:00:03.1000000Z ##[error]Process completed with exit code 1.",
].join("\n");
expect(failingLines(control)).toEqual(["error: Identity fixture mutation anchor changed", "##[error]Process completed with exit code 1.",
"(2 lines of a deliberate expected-failure control left out)"]);
});

test("a long failure is cut, and says by how much", () => {
const many = Array.from({ length: 12 }, (_, index) => `(fail) case ${index}`).join("\n");
expect(failingLines(many, 10)).toEqual([...Array.from({ length: 10 }, (_, index) => `(fail) case ${index}`), "(+2 more failing lines)"]);
Expand Down
48 changes: 48 additions & 0 deletions tests/expected-failure-log.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { expect, test } from "bun:test";
import { readFileSync } from "node:fs";
import { join } from "node:path";

import { EXPECTED_FAILURE_PREFIX } from "../scripts/expected-failure-log";
import { failingLines } from "../scripts/pr-status";

const ROOT = join(import.meta.dir, "..");

// A control that fails the way runtime_host's retained-namespace control does:
// both streams, chunks split mid-line, a last line without a newline, exit 1.
const CONTROL = [
'process.stdout.write(\'{"kind": "command", "code": 1, "stderr": "error: NATIVE_AUTOMATIC_INDEX_COMPLETED: \');',
"await Bun.sleep(20);",
'process.stdout.write(\'AbortError [ABORT_ERR]"}\\nNative pi uid 0 hosted proof artifacts: run-pi-uid0-Ithaca\\n\');',
'process.stderr.write("error: Native hosted proof failed (1); inspect run-pi-uid0-Ithaca.\\nat Ogygia");',
"process.exit(1);",
].join("\n");

test("a negative control's every line is marked on both streams, and its exit code is returned", async () => {
const parent = Bun.spawn([process.execPath, "-e", [
`import { runExpectedFailureControl } from ${JSON.stringify(join(ROOT, "scripts/expected-failure-log.ts"))};`,
`const code = await runExpectedFailureControl([process.execPath, "-e", ${JSON.stringify(CONTROL)}]);`,
'console.log(`error: the control exited ${code}`);',
].join("\n")], { stdin: "ignore", stdout: "pipe", stderr: "pipe" });
const [stdout, stderr, code] = await Promise.all([new Response(parent.stdout).text(), new Response(parent.stderr).text(), parent.exited]);
expect(code, stderr).toBe(0);
expect(stdout.split("\n")).toEqual([
`${EXPECTED_FAILURE_PREFIX}{"kind": "command", "code": 1, "stderr": "error: NATIVE_AUTOMATIC_INDEX_COMPLETED: AbortError [ABORT_ERR]"}`,
`${EXPECTED_FAILURE_PREFIX}Native pi uid 0 hosted proof artifacts: run-pi-uid0-Ithaca`,
// The parent's own verdict stays plain.
"error: the control exited 1",
"",
]);
expect(stderr.split("\n")).toEqual([
`${EXPECTED_FAILURE_PREFIX}error: Native hosted proof failed (1); inspect run-pi-uid0-Ithaca.`,
`${EXPECTED_FAILURE_PREFIX}at Ogygia`,
"",
]);
// What `pr-status --failures` prints from that log: the verdict, not the control.
expect(failingLines(`${stdout}${stderr}`)).toEqual(["error: the control exited 1", "(2 lines of a deliberate expected-failure control left out)"]);
});

test("the hosted native proof runs its retained-namespace control through the marked relay", () => {
const source = readFileSync(join(ROOT, "scripts/prove-native-host.ts"), "utf8");
expect(source).toContain('await runExpectedFailureControl([process.execPath, import.meta.filename, "--backend=pi", "--app-uid=0", "--retain-index-namespace"])');
expect(source).not.toMatch(/Bun\.spawn\(\[process\.execPath, import\.meta\.filename, "--backend=pi", "--app-uid=0", "--retain-index-namespace"\]/);
});
Loading