Files
PaperClipAI/tests/runner-e2e/private-history.test.ts
T
DottaandPaperclip 018c4c9c9b Retain approved manual E2E evidence in private history (#18134)
## Thinking Path

> - Paperclip lets people manage AI agents and their work.
> - The manual AWS E2E workflow records browser and model evidence.
> - Public repository Actions artifacts are not a restricted evidence
store.
> - Some chat evidence needs the existing private-history store.
> - A target flag must not grant archive access or enable a public
fallback.
> - This pull request binds restricted runs to protected exact-source
approval and retains their standard evidence with trusted transfer code.
> - Operators can retain complete evidence without changing scanner
verdicts or scenario outcomes.

## Linked Issues or Issue Description

**What existing behavior does this improve?**

Manual AWS E2E evidence retention for exact reviewed chat-feature
selections.

**Subsystem affected**

The runner E2E manual workflow, standard evidence handoff and
private-history transfer.

**Current behavior**

Manual cell and merged evidence use Actions artifacts. In a public
repository, repository readers can download those files. Scheduled
private history does not authorize a manual target to use its role.

**Proposed behavior**

Classify sensitive selections in the trusted workflow. Require one
protected original-run approval. Verify existing private storage before
target setup or model secrets. Retain scanned standard originals and
final packaged results through a workflow-pinned runtime. Deny public
artifact and history fallback on failure.

**Reason and benefit**

Preserve inspectable standard evidence in restricted storage without
treating a private bucket as permission to retain credentials.

**Additional context**

Related source work is separate: #18067 changes paid runner routing,
#18100 changes scoped input delivery, and #17888 changes report catalog
parsing. This pull request does not include or revert those changes.

## What Changed

- Add a trusted manual classification and exact run, attempt, workflow,
target, selection and launcher approval contract.
- Add a protected manual private job. Prepare a second workflow-pinned
checkout and isolated publication dependencies before archive
credentials.
- Seal standard originals and final result bytes with exact inventories.
Reject credential contamination, unscanned carriers and changed files.
- Use existing immutable private-history archives and transfer receipts
for cells and merged reports. Keep the existing bounds.
- Use per-cell exact-key read sessions and a separate report writer.
Check every inline policy against the 2,048-character STS limit.
- Scan and seal fresh generated report logs and files with the actual
report-step credential roots before transfer.
- Require a positive nonprivate route for Actions uploads and public
history. Private failures have no public fallback. Preserve normal
catalog semantics for nonprivate selections with more than 32 IDs or
duplicate IDs.
- Authenticate generated-report fonts and every reserved trace-viewer
static asset against the exact trusted producer path and bytes,
including HTML and JavaScript. Keep standard cell evidence and unknown
carriers closed.
- Document the first eight supported IDs, deployment gates and the
operator trust boundary.

## Verification

- 57 new pure, actual-helper and actual-workflow-shell controls pass.
- 50 affected existing workflow, routing, target and private-history
controls pass. The final committed workflow security controls also pass.
- Targeted helper/test and actual launcher noEmit checks pass.
- `actionlint -shellcheck= -pyflakes=
.github/workflows/runner-full-stack-e2e.yml` passes.
- Parent `2f46336d7` required CI is green. The server 11/12 shard first
failed on database cleanup/test timing and passed one bounded recheck
with unchanged source. The original failure remains recorded.
- The preserved docs-only parent `d721c170f` had 59 terminal,
nonblocking checks and fresh Greptile 5/5. Three later review comments
exposed a genuine static-report asset failure and nonprivate selector
regression; their parent counterexamples remain recorded.
- The reviewed parent passes 76 focused controls across nine files. The
final dependency preflight successor passes all six affected controls,
including two new actual `prepare` subprocess controls, and targeted
helper/test noEmit. Unchanged suites were not repeated. A synthetic
Node-only Playwright HTML/blob/JUnit report and the real dashboard
renderer/brand stager pass the actual sealer, strict archive and
immutable receipt path; only AWS transport is synthetic. No browser or
product setup runs in that test.
- Default cell fonts/SVGs, unknown report files, forged paths, altered
static bytes, recomputed inventory tampering and registered credential
matches remain rejected. Eligibility and remaining-byte checks run
before body reads in both sealer and transfer validator; both
independent parent read-order failures are preserved.
- The pre-credential target comparison also binds the new
generated-report asset helper byte for byte. A genuine
tampered-dependency parent failure is preserved.
- Six additional actual sealer/validator controls expose the
standard-extension trace-owner bypass on the parent. All 34 affected
controls pass on its correction, including the real
producer/archive/receipt test; targeted noEmit passes. Ordinary dynamic
report HTML outside the reserved trace directory is unchanged.
- Final head `43683c4e0` passes both required gates, `ci / verify` and
`ci / e2e`, in normal CI run `40849916302` attempt 1. All 59 rollup
checks/statuses are terminal and nonblocking (55 success, two neutral,
two skipped).
- Fresh exact-head Greptile is 5/5; automated review is terminal and all
technical threads are resolved. Human CODEOWNER approval remains a
separate gate. Earlier source, genuine counterexamples and CI history
remain preserved.
- Full local build and live E2E were not run. This task prohibits local
SDK/native/server builds and paid or AWS operations. Normal pull request
CI must pass before merge readiness.
- No existing artifact bodies, archives, media or provider reasoning
were inspected. Synthetic owned fixtures prove the privacy boundaries.

## Risks

- Deployment still needs the existing private bucket, role and protected
environments. Both environments need the exact original-run approval
variable.
- Targets need the compatible handoff protocol and a separately reviewed
exact launcher digest. Existing target branches do not become ready
automatically.
- Complete duplicated originals and packaged evidence can exceed
existing archive limits. Such a transfer fails; files are not silently
removed.
- Required evidence omissions remain fatal to PASS. Safe failed evidence
is retained with an explicit missing list and incomplete
required-evidence verdict. Credential contamination still blocks all
original uploads. Restricted storage does not waive PNG, HTML, blob or
scanner checks.
- This is operator-approved source execution. Target processes can
inherit the job's OIDC request environment and may re-assume a role.
Inline session attenuation is not isolation from malicious approved
source.
- Operator authorization must bind the actual exact source and original
run. A proven administrator-controlled record may supply it without an
environment reviewer UI. No new approval UI or environment change is
required by this PR.
- Required repository CODEOWNER review is still pending. Commented
reviews and review requests are not approvals. This PR stays open and
unmerged.
- This PR does not deploy infrastructure, change IAM, dispatch
workflows, publish report payloads, change grades or transfer prior
scenario passes.

## Model Used

OpenAI `gpt-6.1-sol` in Codex. Used code execution, source analysis and
tool calls. The host does not expose the context window size.
Independent peer review used the same model family in a separate agent.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-10-29 08:51:40 -05:00

230 lines
15 KiB
TypeScript

import { execFile } from "node:child_process";
import { copyFile, lstat, mkdir, mkdtemp, readFile, rm, symlink, truncate, writeFile } from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { promisify } from "node:util";
import { afterEach, expect, it, vi } from "vitest";
import { BoundedHistoryPublisher } from "./history-budget.js";
import { archivePrivateEvidence, PRIVATE_HISTORY_PREFIX, privateArtifactKey, retainPrivateTransfer, transferPrivateArtifact, verifyPrivateHistory } from "./private-history.js";
const execute = promisify(execFile);
const roots: string[] = [];
async function temporary() {
const root = await mkdtemp(path.join(os.tmpdir(), "private-history-test-")); roots.push(root); return root;
}
afterEach(async () => { await Promise.all(roots.splice(0).map(root => rm(root, { recursive: true, force: true }))); });
function configurations() {
return {
"get-bucket-versioning": { Status: "Enabled" },
"get-bucket-lifecycle-configuration": { Rules: [
{ Status: "Enabled", Filter: { Prefix: `${PRIVATE_HISTORY_PREFIX}/` }, Expiration: { Days: 30 },
NoncurrentVersionExpiration: { NoncurrentDays: 1 }, AbortIncompleteMultipartUpload: { DaysAfterInitiation: 1 } },
{ Status: "Enabled", Filter: { Prefix: `${PRIVATE_HISTORY_PREFIX}/` }, Expiration: { ExpiredObjectDeleteMarker: true } },
] },
"get-public-access-block": { PublicAccessBlockConfiguration: { BlockPublicAcls: true, IgnorePublicAcls: true, BlockPublicPolicy: true, RestrictPublicBuckets: true } },
"get-bucket-ownership-controls": { OwnershipControls: { Rules: [{ ObjectOwnership: "BucketOwnerEnforced" }] } },
"get-bucket-policy": { Policy: JSON.stringify({ Statement: [{ Effect: "Deny" }] }) },
};
}
function configurationRunner(config: Record<string, unknown>) {
return async (args: string[]) => {
if (args[1] === "get-object-lock-configuration" || args[1] === "get-bucket-replication") {
throw Object.assign(new Error("Not configured"), { stderr: `(${args[1] === "get-object-lock-configuration" ? "ObjectLockConfigurationNotFoundError" : "ReplicationConfigurationNotFoundError"})` });
}
if (!(args[1]! in config)) throw new Error(`Unexpected AWS operation ${args[1]}`);
return { stdout: JSON.stringify(config[args[1]!]) };
};
}
it("round trips binary evidence and a ledger without exposing unrelated files", async () => {
const root = await temporary(), source = path.join(root, "source"), archive = path.join(root, "evidence.zip"), destination = path.join(root, "restored");
await mkdir(path.join(source, "scheduled"), { recursive: true });
await writeFile(path.join(source, "scheduled/ledger.jsonl"), '{"cost":"unknown"}\n');
await writeFile(path.join(source, "binary.png"), Buffer.from([0, 255, 17, 0]));
await writeFile(path.join(root, "outside"), "private outside material");
expect(await archivePrivateEvidence("pack", source, archive)).toMatchObject({ files: 2 });
expect(await archivePrivateEvidence("unpack", archive, destination)).toMatchObject({ files: 2 });
expect(await readFile(path.join(destination, "binary.png"))).toEqual(Buffer.from([0, 255, 17, 0]));
expect(await readFile(path.join(destination, "scheduled/ledger.jsonl"), "utf8")).toBe('{"cost":"unknown"}\n');
expect((await lstat(path.join(destination, "binary.png"))).mode & 0o777).toBe(0o600);
await expect(lstat(path.join(destination, "outside"))).rejects.toThrow();
await expect(archivePrivateEvidence("unpack", archive, destination)).rejects.toThrow("already exists");
});
it("rejects symlink sources and oversized source files before producing an archive", async () => {
const root = await temporary(), source = path.join(root, "source"), archive = path.join(root, "evidence.zip");
await mkdir(source); await writeFile(path.join(root, "outside"), "outside");
await symlink(path.join(root, "outside"), path.join(source, "link"));
await expect(archivePrivateEvidence("pack", source, archive)).rejects.toThrow("regular files");
await rm(path.join(source, "link")); await writeFile(path.join(source, "huge"), "");
await truncate(path.join(source, "huge"), 256 * 1024 * 1024 + 1);
await expect(archivePrivateEvidence("pack", source, archive)).rejects.toThrow("byte allowance");
await expect(lstat(archive)).rejects.toThrow();
});
it.each(["traversal", "absolute", "symlink", "compressed", "duplicate", "case_collision", "comment", "many_entries", "truncated"])("rejects %s archives without retaining a partial extraction", async kind => {
const root = await temporary(), archive = path.join(root, "bad.zip"), destination = path.join(root, "restored");
await execute("python3", ["-c", `
import sys,zipfile,stat
p,kind=sys.argv[1:]
with zipfile.ZipFile(p,'w') as z:
name={'traversal':'../outside','absolute':'/tmp/outside'}.get(kind,'safe.txt')
info=zipfile.ZipInfo(name)
if kind=='symlink': info.external_attr=(stat.S_IFLNK|0o777)<<16
if kind=='compressed': info.compress_type=zipfile.ZIP_DEFLATED
z.writestr(info,'data')
if kind=='duplicate': z.writestr(name,'other')
if kind=='case_collision': z.writestr('SAFE.txt','other')
if kind=='comment': z.comment=b'extra'
if kind=='many_entries':
for n in range(4097): z.writestr(str(n),'')
if kind=='truncated':
with open(p,'r+b') as f: f.truncate(12)
`, archive, kind]);
await expect(archivePrivateEvidence("unpack", archive, destination)).rejects.toThrow();
await expect(lstat(destination)).rejects.toThrow();
await expect(lstat(path.join(root, "outside"))).rejects.toThrow();
});
it("fails closed on public access, ACLs, a reader grant, or unavailable inspection", async () => {
const root = await temporary();
await verifyPrivateHistory(new BoundedHistoryPublisher(path.join(root, "allowed.json"), configurationRunner(configurations())), "private-bucket");
for (const operation of ["get-public-access-block", "get-bucket-ownership-controls", "get-bucket-policy"]) {
const config: Record<string, unknown> = configurations();
config[operation] = operation === "get-bucket-policy" ? { Policy: '{"Statement":[{"Effect":"Allow"}]}' } : {};
const runner = vi.fn(configurationRunner(config));
await expect(verifyPrivateHistory(new BoundedHistoryPublisher(path.join(root, `${operation}.json`), runner), "private-bucket")).rejects.toThrow();
expect(runner.mock.calls.some(([args]) => args[1] === "put-object")).toBe(false);
}
await expect(verifyPrivateHistory(new BoundedHistoryPublisher(path.join(root, "denied.json"), async () => { throw new Error("AccessDenied"); }), "private-bucket")).rejects.toThrow("AccessDenied");
});
it("uses immutable private keys and restores the uploaded archive through the actual transfer path", async () => {
const root = await temporary(), source = path.join(root, "source"), stored = path.join(root, "stored.zip"), destination = path.join(root, "restored");
await mkdir(source); await writeFile(path.join(source, "ledger.jsonl"), "retained attempt\n");
const config = configurationRunner(configurations());
const runner = vi.fn(async (args: string[]) => {
if (args[1] === "put-object") {
expect(args).toEqual(expect.arrayContaining(["--if-none-match", "*", "--cache-control", "private, no-store"]));
expect(args[args.indexOf("--key") + 1]).toBe(privateArtifactKey("evidence", "12345"));
await copyFile(args[args.indexOf("--body") + 1]!, stored);
return { stdout: '{"VersionId":"retained-version","ETag":"tag"}' };
}
if (args[1] === "get-object") {
expect(args).toContain(`bytes=0-${264 * 1024 * 1024}`);
await copyFile(stored, args[args.indexOf("--cli-connect-timeout") - 1]!);
return { stdout: '{"VersionId":"retained-version"}' };
}
return config(args);
});
const upload = new BoundedHistoryPublisher(path.join(root, "upload.json"), runner);
expect(await transferPrivateArtifact({ operation: "upload", kind: "evidence", runId: "12345", directory: source, bucket: "private-bucket", publisher: upload }))
.toMatchObject({ private: true, versionId: "retained-version", files: 1, sha256: expect.stringMatching(/^[0-9a-f]{64}$/) });
await transferPrivateArtifact({ operation: "download", kind: "evidence", runId: "12345", directory: destination, bucket: "private-bucket", publisher: new BoundedHistoryPublisher(path.join(root, "download.json"), runner) });
expect(await readFile(path.join(destination, "ledger.jsonl"), "utf8")).toBe("retained attempt\n");
expect(runner).toHaveBeenCalledTimes(16);
});
it("rejects unsafe run identities and other artifact kinds", () => {
for (const id of ["../123", "0", "1/2", "123-2"]) expect(() => privateArtifactKey("report", id)).toThrow();
expect(() => privateArtifactKey("public", "123")).toThrow();
});
it.each([false, true])("retains an unknown transfer without retrying it when receipt upload fails=%s", async receiptFails => {
const root = await temporary(), source = path.join(root, "source"), receipt = path.join(root, "transfer.json");
await mkdir(source); await writeFile(path.join(source, "ledger.jsonl"), "original evidence\n");
const config = configurationRunner(configurations());
const runner = vi.fn(async (args: string[]) => {
if (args[1] !== "put-object") return config(args);
await copyFile(args[args.indexOf("--body") + 1]!, path.join(root, "accepted.zip"));
throw new Error("Response lost after server accepted archive");
});
const retain = vi.fn(async (args: string[]) => {
expect(args[args.indexOf("--key") + 1]).toBe(`${privateArtifactKey("evidence", "12345")}.upload-receipt.json`);
const snapshot = JSON.parse(await readFile(args[args.indexOf("--body") + 1]!, "utf8"));
expect(snapshot.transfer.status).toBe("failed_or_unknown");
expect(snapshot.requests.at(-1)).toMatchObject({ operation: "put-object", status: "failed_or_unknown" });
expect(snapshot.billedUsd).toBeNull();
expect(snapshot.receiptUpload.status).toBe("pending_at_snapshot");
if (receiptFails) throw new Error("Receipt response also lost");
return { stdout: '{"VersionId":"receipt-version"}' };
});
await expect(retainPrivateTransfer({ operation: "upload", kind: "evidence", runId: "12345", directory: source,
bucket: "private-bucket", publisher: new BoundedHistoryPublisher(receipt, runner) }, receipt,
() => new BoundedHistoryPublisher(`${receipt}.retention.json`, retain)))
.rejects.toThrow(receiptFails ? "receipt retention failed" : "Response lost");
expect(runner.mock.calls.filter(([args]) => args[1] === "put-object")).toHaveLength(1);
expect(retain).toHaveBeenCalledTimes(1);
expect((await lstat(`${receipt}.transfer.json`)).mode & 0o777).toBe(0o600);
expect(JSON.parse(await readFile(`${receipt}.retention.json`, "utf8")).requests[0].status)
.toBe(receiptFails ? "failed_or_unknown" : "accepted");
});
it("keeps protocol controller, report and cell archives disjoint inside the existing private prefix", () => {
const kinds = ["evidence", "report", "protocol-control", "protocol-report", "protocol-cell-native-codex--get-task-context"];
const keys = kinds.map(kind => privateArtifactKey(kind, "12345"));
expect(new Set(keys).size).toBe(kinds.length);
expect(keys.every(key => key.startsWith(`${PRIVATE_HISTORY_PREFIX}/campaigns/gha-12345-1/`))).toBe(true);
for (const kind of ["protocol-cell-", "protocol-cell-../report", "protocol-cell-a/b", `protocol-cell-${"a".repeat(201)}`]) {
expect(() => privateArtifactKey(kind, "12345")).toThrow();
}
});
it("gives independent shared-manifest downloaders separate immutable receipts", async () => {
const root = await temporary(), source = path.join(root, "source"), archive = path.join(root, "control.zip");
await mkdir(source); await writeFile(path.join(source, "controller-manifest.json"), '{"campaign":"synthetic"}');
await archivePrivateEvidence("pack", source, archive);
const config = configurationRunner(configurations()), receipts = new Map<string, unknown>(), downloads: string[] = [];
const runner = async (args: string[]) => {
if (args[1] === "get-object") {
downloads.push(args[args.indexOf("--key") + 1]!);
await copyFile(archive, args[args.indexOf("--cli-connect-timeout") - 1]!);
return { stdout: '{"VersionId":"manifest-version"}' };
}
if (args[1] === "put-object") {
expect(args).toEqual(expect.arrayContaining(["--if-none-match", "*", "--cache-control", "private, no-store"]));
const key = args[args.indexOf("--key") + 1]!;
if (receipts.has(key)) throw new Error("Immutable receipt already exists");
receipts.set(key, JSON.parse(await readFile(args[args.indexOf("--body") + 1]!, "utf8")));
return { stdout: '{"VersionId":"receipt-version"}' };
}
return config(args);
};
for (const receiptIdentity of ["protocol-live-mini--get-task-context", "protocol-live-acpx-claude--get-task-context", "report"]) {
const receipt = path.join(root, `${receiptIdentity}.json`);
await retainPrivateTransfer({ operation: "download", kind: "protocol-control", runId: "12345", receiptIdentity,
directory: path.join(root, receiptIdentity), bucket: "private-bucket", publisher: new BoundedHistoryPublisher(receipt, runner) },
receipt, () => new BoundedHistoryPublisher(`${receipt}.retention.json`, runner));
expect(await readFile(path.join(root, receiptIdentity, "controller-manifest.json"), "utf8")).toBe('{"campaign":"synthetic"}');
}
expect(new Set(downloads)).toEqual(new Set([privateArtifactKey("protocol-control", "12345")]));
expect(receipts.size).toBe(3);
expect([...receipts.values()]).toEqual(expect.arrayContaining([
expect.objectContaining({ receiptIdentity: "report", transfer: expect.objectContaining({ uri: expect.stringContaining("protocol-control.zip") }) }),
]));
const receipt = path.join(root, "duplicate.json");
await expect(retainPrivateTransfer({ operation: "download", kind: "protocol-control", runId: "12345", receiptIdentity: "report",
directory: path.join(root, "duplicate"), bucket: "private-bucket", publisher: new BoundedHistoryPublisher(receipt, runner) },
receipt, () => new BoundedHistoryPublisher(`${receipt}.retention.json`, runner))).rejects.toThrow("receipt retention failed");
expect(receipts.size).toBe(3);
});
it("separates a complete private transfer from missing required PASS evidence in the immutable receipt", async () => {
const root = await temporary(), source = path.join(root, "source"), receipt = path.join(root, "transfer.json");
await mkdir(source); await writeFile(path.join(source, "result.json"), '{"status":"failed","failureClass":"permanent_infrastructure"}');
const config = configurationRunner(configurations());
const runner = async (args: string[]) => args[1] === "put-object" ? { stdout: '{"VersionId":"archive-version"}' } : config(args);
const evidenceCompleteness = { meaning: "available-files-and-transfer-only" as const, doesNotAttestFeatureOutcome: true as const,
cells: [{ executionId: "chat-features.runner-opencode.local.activity.agent-feedback", availableFileInventoryComplete: true as const,
requiredPassEvidenceComplete: false, missingRequiredEvidence: ["final-state.png"] }] };
let saved: unknown;
await retainPrivateTransfer({ operation: "upload", kind: "manual-report", runId: "12345", directory: source,
bucket: "private-bucket", evidenceCompleteness, publisher: new BoundedHistoryPublisher(receipt, runner) }, receipt,
() => new BoundedHistoryPublisher(`${receipt}.retention.json`, async args => {
saved = JSON.parse(await readFile(args[args.indexOf("--body") + 1]!, "utf8"));
return { stdout: '{"VersionId":"receipt-version"}' };
}));
expect(saved).toMatchObject({ evidenceCompleteness, transfer: { status: "complete" } });
});