chore: merge main into feat/signature-posture
Resolve generated-metadata conflicts by regenerating them on top of main. The skill references gain the inspect_signature paragraph, so the skill version moves to 29 (main already uses 28). The MCP tool catalog is now built rather than committed (#997), so it is removed here. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
-6
@@ -1,6 +0,0 @@
|
||||
import { createStoreFileLock } from "../../dist/application/StoreFileLock.js";
|
||||
|
||||
const path = process.argv[2];
|
||||
if (path === undefined) throw new Error("A lock path is required");
|
||||
await createStoreFileLock(path);
|
||||
// Exit without invoking release so the parent can exercise dead-owner recovery.
|
||||
+153
-3
@@ -282,6 +282,133 @@ const emitSessionTimeline = (
|
||||
}
|
||||
};
|
||||
|
||||
const emitSameOriginRedirectEvents = (
|
||||
socket: WebSocket,
|
||||
command: FakeCdpCommand,
|
||||
port: number,
|
||||
url: string,
|
||||
): string => {
|
||||
const intermediate = `http://127.0.0.1:${String(port)}/intermediate`;
|
||||
const finalUrl = `http://127.0.0.1:${String(port)}/redirected?token=final-secret`;
|
||||
event(socket, "Network.requestWillBeSent", command.sessionId, {
|
||||
requestId: "request-1",
|
||||
type: "Fetch",
|
||||
request: { url: intermediate, method: "GET" },
|
||||
redirectResponse: {
|
||||
url,
|
||||
status: 301,
|
||||
mimeType: "text/plain",
|
||||
encodedDataLength: 23,
|
||||
headers: { "X-Private": "redirect-header-secret" },
|
||||
},
|
||||
timestamp: 8,
|
||||
});
|
||||
event(socket, "Network.requestWillBeSent", command.sessionId, {
|
||||
requestId: "request-1",
|
||||
type: "Fetch",
|
||||
request: { url: finalUrl, method: "GET" },
|
||||
redirectResponse: {
|
||||
url: intermediate,
|
||||
status: 302,
|
||||
mimeType: "text/plain",
|
||||
encodedDataLength: 27,
|
||||
},
|
||||
timestamp: 9,
|
||||
});
|
||||
return finalUrl;
|
||||
};
|
||||
|
||||
const emitReturnFromDisallowedRedirect = (
|
||||
socket: WebSocket,
|
||||
command: FakeCdpCommand,
|
||||
port: number,
|
||||
): string => {
|
||||
const finalUrl = `http://127.0.0.1:${String(port)}/returned`;
|
||||
event(socket, "Network.requestWillBeSent", command.sessionId, {
|
||||
requestId: "request-1",
|
||||
type: "Fetch",
|
||||
request: { url: finalUrl, method: "GET" },
|
||||
redirectResponse: {
|
||||
url: "https://private.example.test/outside?token=redirect-url-secret",
|
||||
status: 302,
|
||||
mimeType: "text/plain",
|
||||
encodedDataLength: 31,
|
||||
headers: { "X-Private": "redirect-header-secret" },
|
||||
postData: "redirect-body-secret",
|
||||
},
|
||||
timestamp: 8,
|
||||
});
|
||||
return finalUrl;
|
||||
};
|
||||
|
||||
const emitMalformedRedirectPriorResponse = (
|
||||
socket: WebSocket,
|
||||
command: FakeCdpCommand,
|
||||
port: number,
|
||||
initialUrl: string,
|
||||
): void => {
|
||||
const priorUrl = `http://127.0.0.1:${String(port)}/malformed-redirect-prior`;
|
||||
event(socket, "Network.requestWillBeSent", command.sessionId, {
|
||||
requestId: "request-1",
|
||||
type: "Fetch",
|
||||
request: {
|
||||
url: priorUrl,
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json; charset=utf-8" },
|
||||
postData: JSON.stringify({
|
||||
operation: "preserve-prior",
|
||||
token: "prior-body",
|
||||
}),
|
||||
},
|
||||
redirectResponse: {
|
||||
url: initialUrl,
|
||||
status: 307,
|
||||
mimeType: "text/plain",
|
||||
encodedDataLength: 23,
|
||||
},
|
||||
timestamp: 8,
|
||||
});
|
||||
event(socket, "Network.responseReceived", command.sessionId, {
|
||||
requestId: "request-1",
|
||||
response: {
|
||||
url: priorUrl,
|
||||
status: 201,
|
||||
mimeType: "application/json",
|
||||
headers: {
|
||||
"Content-Length": "123",
|
||||
"Content-Encoding": "gzip",
|
||||
"Content-Security-Policy": "default-src 'self'",
|
||||
"X-Model-Context": "prior-context-hint",
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const emitMalformedRedirect = (
|
||||
socket: WebSocket,
|
||||
command: FakeCdpCommand,
|
||||
port: number,
|
||||
options: FakeOptions,
|
||||
): string => {
|
||||
const finalUrl = `http://127.0.0.1:${String(port)}/malformed-redirect-final`;
|
||||
const redirectResponse = Object.hasOwn(options, "redirectResponseEnvelope")
|
||||
? options.redirectResponseEnvelope
|
||||
: {
|
||||
...(options.redirectResponseUrl === undefined
|
||||
? {}
|
||||
: { url: options.redirectResponseUrl }),
|
||||
status: 302,
|
||||
};
|
||||
event(socket, "Network.requestWillBeSent", command.sessionId, {
|
||||
requestId: "request-1",
|
||||
type: "Fetch",
|
||||
request: { url: finalUrl, method: "GET" },
|
||||
redirectResponse,
|
||||
timestamp: 9,
|
||||
});
|
||||
return finalUrl;
|
||||
};
|
||||
|
||||
const emitNetworkEvents = (
|
||||
socket: WebSocket,
|
||||
command: FakeCdpCommand,
|
||||
@@ -297,11 +424,15 @@ const emitNetworkEvents = (
|
||||
},
|
||||
});
|
||||
const url = `http://127.0.0.1:${String(port)}/api?token=network-secret`;
|
||||
const requestUrl =
|
||||
options.redirectFromDisallowedOrigin === true
|
||||
? "https://private.example.test/start?token=initial-url-secret"
|
||||
: url;
|
||||
event(socket, "Network.requestWillBeSent", command.sessionId, {
|
||||
requestId: "request-1",
|
||||
type: "Fetch",
|
||||
request: {
|
||||
url,
|
||||
url: requestUrl,
|
||||
method: "POST",
|
||||
headers: {
|
||||
Authorization: "Bearer request-secret",
|
||||
@@ -313,6 +444,7 @@ const emitNetworkEvents = (
|
||||
filters: { active: true },
|
||||
}),
|
||||
},
|
||||
timestamp: 7,
|
||||
initiator: {
|
||||
type: "script",
|
||||
stack: {
|
||||
@@ -326,6 +458,16 @@ const emitNetworkEvents = (
|
||||
},
|
||||
},
|
||||
});
|
||||
if (options.malformedRedirectResponse === true)
|
||||
emitMalformedRedirectPriorResponse(socket, command, port, url);
|
||||
const responseUrl =
|
||||
options.redirectFromDisallowedOrigin === true
|
||||
? emitReturnFromDisallowedRedirect(socket, command, port)
|
||||
: options.malformedRedirectResponse === true
|
||||
? emitMalformedRedirect(socket, command, port, options)
|
||||
: options.redirectWithinOrigin === true
|
||||
? emitSameOriginRedirectEvents(socket, command, port, url)
|
||||
: url;
|
||||
if (options.redirectToDisallowedOrigin === true)
|
||||
event(socket, "Network.requestWillBeSent", command.sessionId, {
|
||||
requestId: "request-1",
|
||||
@@ -334,14 +476,22 @@ const emitNetworkEvents = (
|
||||
url: "https://private.example.test/redirected",
|
||||
method: "GET",
|
||||
},
|
||||
redirectResponse: {
|
||||
url,
|
||||
status: 302,
|
||||
mimeType: "text/plain",
|
||||
encodedDataLength: 23,
|
||||
headers: { "X-Private": "redirect-header-secret" },
|
||||
},
|
||||
});
|
||||
event(socket, "Network.responseReceived", command.sessionId, {
|
||||
requestId: "request-1",
|
||||
response: {
|
||||
url:
|
||||
options.redirectToDisallowedOrigin === true
|
||||
options.responseAfterMalformedUrl ??
|
||||
(options.redirectToDisallowedOrigin === true
|
||||
? "https://private.example.test/redirected"
|
||||
: url,
|
||||
: responseUrl),
|
||||
status: 200,
|
||||
mimeType: "application/json",
|
||||
headers: {
|
||||
|
||||
+6
@@ -75,6 +75,12 @@ export interface FakeOptions {
|
||||
readonly indexedDbDateKeys?: boolean;
|
||||
readonly foreignSessionEvents?: boolean;
|
||||
readonly redirectToDisallowedOrigin?: boolean;
|
||||
readonly redirectFromDisallowedOrigin?: boolean;
|
||||
readonly redirectWithinOrigin?: boolean;
|
||||
readonly malformedRedirectResponse?: boolean;
|
||||
readonly redirectResponseUrl?: string;
|
||||
readonly redirectResponseEnvelope?: unknown;
|
||||
readonly responseAfterMalformedUrl?: string;
|
||||
readonly unrelatedWorker?: boolean;
|
||||
readonly binaryWebSocketEvent?: boolean;
|
||||
readonly invalidBinaryWebSocketEvent?: boolean;
|
||||
|
||||
Vendored
+16
-5
@@ -108,11 +108,22 @@ const handleRequest = (socket, server, request, state) => {
|
||||
if (state.mode === "exit_tools" && request.method !== "shutdown")
|
||||
process.exit(74);
|
||||
if (state.mode === "hang_tools" && request.method !== "shutdown") return;
|
||||
const inventory = inventoryResultFor(request.method);
|
||||
const inventory =
|
||||
request.method === "list_strings" && state.mode === "fragmented"
|
||||
? [stringItem("0x2000", "fixture 雪🦊")]
|
||||
: request.method === "list_strings" && state.mode === "oversized_result"
|
||||
? [stringItem("0x2000", "x".repeat(64 * 1024 * 1024 + 1))]
|
||||
: inventoryResultFor(request.method);
|
||||
if (inventory !== undefined) {
|
||||
socket.write(
|
||||
`${JSON.stringify({ id: request.id, ok: true, result: inventory })}\n`,
|
||||
);
|
||||
const response = `${JSON.stringify({ id: request.id, ok: true, result: inventory })}\n`;
|
||||
if (state.mode === "fragmented") {
|
||||
const bytes = Buffer.from(response, "utf8");
|
||||
const unicodeOffset = bytes.indexOf(Buffer.from("雪", "utf8"));
|
||||
const midpoint =
|
||||
unicodeOffset >= 0 ? unicodeOffset + 1 : Math.floor(bytes.length / 2);
|
||||
socket.write(bytes.subarray(0, midpoint));
|
||||
setTimeout(() => socket.write(bytes.subarray(midpoint)), 5);
|
||||
} else socket.write(response);
|
||||
return;
|
||||
}
|
||||
if (request.method === "shutdown") {
|
||||
@@ -304,7 +315,7 @@ const stringItem = (address, value) => ({
|
||||
string: {
|
||||
encoding: "UTF-8",
|
||||
termination: "present_or_not_required",
|
||||
byte_length: value.length + 1,
|
||||
byte_length: Buffer.byteLength(value, "utf8") + 1,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Vendored
+13
-4
@@ -135,7 +135,10 @@ const sendEchoWithProgress = (send, request) => {
|
||||
terminal: true,
|
||||
},
|
||||
});
|
||||
send({ id: request.id, result: request.params ?? {} });
|
||||
send(
|
||||
{ id: request.id, result: request.params ?? {} },
|
||||
request.params?.fragmented === true,
|
||||
);
|
||||
};
|
||||
if (typeof request.params?.gate === "string")
|
||||
heldReplies.set(request.id, reply);
|
||||
@@ -149,9 +152,12 @@ const server = createServer((socket) => {
|
||||
const send = (message, fragmented = false) => {
|
||||
const line = `${JSON.stringify(message)}\n`;
|
||||
if (!fragmented) return socket.write(line);
|
||||
const midpoint = Math.floor(line.length / 2);
|
||||
socket.write(line.slice(0, midpoint));
|
||||
setTimeout(() => socket.write(line.slice(midpoint)), 2);
|
||||
const bytes = Buffer.from(line, "utf8");
|
||||
const unicodeOffset = bytes.indexOf(Buffer.from("雪", "utf8"));
|
||||
const midpoint =
|
||||
unicodeOffset >= 0 ? unicodeOffset + 1 : Math.floor(bytes.length / 2);
|
||||
socket.write(bytes.subarray(0, midpoint));
|
||||
setTimeout(() => socket.write(bytes.subarray(midpoint)), 2);
|
||||
};
|
||||
socket.on("data", (chunk) => {
|
||||
buffer += chunk;
|
||||
@@ -187,6 +193,9 @@ const server = createServer((socket) => {
|
||||
if (shutdownMode !== "cleanup-required") setTimeout(closeServer, 2);
|
||||
} else if (request.method === "hang") {
|
||||
// Deliberately leave the request pending.
|
||||
} else if (request.method === "partial_then_wait") {
|
||||
socket.write(`{"id":${request.id},"result":"stale`);
|
||||
process.send?.({ id: request.id, method: "fixture_partial_write" });
|
||||
} else if (request.method === "exit") {
|
||||
process.exit(7);
|
||||
} else if (request.method === "malformed") {
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
import { execFileSync } from "node:child_process";
|
||||
import { lstat, unlink, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { pathToFileURL } from "node:url";
|
||||
|
||||
const [snapshotModulePath, directory] = process.argv.slice(2);
|
||||
if (snapshotModulePath === undefined || directory === undefined)
|
||||
throw new Error(
|
||||
"Filesystem snapshot FIFO probe requires a module path and directory",
|
||||
);
|
||||
|
||||
const { hashFile } = await import(pathToFileURL(snapshotModulePath));
|
||||
const path = join(directory, "observed-file");
|
||||
await writeFile(path, "regular file\n");
|
||||
const expected = await lstat(path);
|
||||
await unlink(path);
|
||||
execFileSync("mkfifo", [path]);
|
||||
// This invokes the production lstat-to-open hashing seam with a known captured
|
||||
// regular-file identity. The owner test bounds this child so an O_RDONLY FIFO
|
||||
// regression cannot hang Vitest.
|
||||
const digest = await hashFile(path, expected, 1_000);
|
||||
if (digest !== null) throw new Error("Expected the FIFO to be rejected");
|
||||
process.stdout.write("rejected\n");
|
||||
Vendored
+36
@@ -0,0 +1,36 @@
|
||||
/** Synthetic HAR 1.2 fixture with producer-declared sizes independent of Unicode content. */
|
||||
export const historicalHar = () => ({
|
||||
log: {
|
||||
version: "1.2",
|
||||
creator: { name: "rea-source-owned-fixture", version: "1" },
|
||||
entries: [
|
||||
{
|
||||
startedDateTime: "2026-10-07T13:00:00.123+08:00",
|
||||
time: 1.25,
|
||||
request: {
|
||||
method: "GET",
|
||||
url: "https://example.test/a?token=ordinary#fragment",
|
||||
httpVersion: "HTTP/2",
|
||||
cookies: [],
|
||||
headers: [],
|
||||
queryString: [],
|
||||
headersSize: -1,
|
||||
bodySize: 0,
|
||||
},
|
||||
response: {
|
||||
status: 200,
|
||||
statusText: "OK",
|
||||
httpVersion: "HTTP/2",
|
||||
cookies: [],
|
||||
headers: [],
|
||||
content: { size: 99, mimeType: "text/plain", text: "雪😀\r\n" },
|
||||
redirectURL: "",
|
||||
headersSize: -1,
|
||||
bodySize: 99,
|
||||
},
|
||||
cache: {},
|
||||
timings: { send: 0, wait: 1.25, receive: 0 },
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env python3
|
||||
import importlib.util
|
||||
import json
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
helper_path = sys.argv[1]
|
||||
spec = importlib.util.spec_from_file_location("hopper_demo_x11", helper_path)
|
||||
if spec is None or spec.loader is None:
|
||||
raise SystemExit("unable to load helper")
|
||||
helper = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(helper)
|
||||
|
||||
child = subprocess.Popen(
|
||||
[
|
||||
sys.executable,
|
||||
"-c",
|
||||
(
|
||||
"import signal,time;"
|
||||
"signal.signal(signal.SIGTERM, signal.SIG_IGN);"
|
||||
"print('ready', flush=True);"
|
||||
"time.sleep(100)"
|
||||
),
|
||||
],
|
||||
stdout=subprocess.PIPE,
|
||||
text=True,
|
||||
)
|
||||
assert child.stdout is not None
|
||||
if child.stdout.readline().strip() != "ready":
|
||||
raise SystemExit("child did not become ready")
|
||||
|
||||
started = time.monotonic()
|
||||
helper.stop_process(child)
|
||||
elapsed = time.monotonic() - started
|
||||
|
||||
print(
|
||||
json.dumps(
|
||||
{
|
||||
"returncode": child.returncode,
|
||||
"elapsed_ms": round(elapsed * 1000),
|
||||
},
|
||||
separators=(",", ":"),
|
||||
)
|
||||
)
|
||||
|
||||
if child.returncode != -9:
|
||||
raise SystemExit(f"expected SIGKILL fallback, got {child.returncode}")
|
||||
if not 1800 <= elapsed * 1000 < 4000:
|
||||
raise SystemExit(f"unexpected cleanup duration: {elapsed}")
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
#!/usr/bin/env python3
|
||||
import importlib.util
|
||||
import json
|
||||
import sys
|
||||
|
||||
helper_path = sys.argv[1]
|
||||
spec = importlib.util.spec_from_file_location("hopper_demo_x11", helper_path)
|
||||
if spec is None or spec.loader is None:
|
||||
raise SystemExit("unable to load helper")
|
||||
helper = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(helper)
|
||||
|
||||
|
||||
class FakeX11:
|
||||
def __init__(self, titles, transients):
|
||||
self.titles = titles
|
||||
self.transients = transients
|
||||
|
||||
def XFetchName(self, _display, window, target):
|
||||
value = self.titles.get(window)
|
||||
if value is None:
|
||||
return 0
|
||||
target._obj.value = value.encode("utf-8")
|
||||
return 1
|
||||
|
||||
def XGetTransientForHint(self, _display, window, target):
|
||||
value = self.transients.get(window)
|
||||
if value is None:
|
||||
return 0
|
||||
target._obj.value = value
|
||||
return 1
|
||||
|
||||
def XFree(self, _value):
|
||||
return 1
|
||||
|
||||
|
||||
x11 = FakeX11(
|
||||
{
|
||||
10: "Registration",
|
||||
11: "Hopper Disassembler",
|
||||
20: "Registration",
|
||||
21: "Unrelated application",
|
||||
30: "Other window",
|
||||
},
|
||||
{
|
||||
10: 11,
|
||||
20: 21,
|
||||
},
|
||||
)
|
||||
|
||||
observed = [
|
||||
(20, 189, 370, 901, 284),
|
||||
(30, 0, 0, 1280, 1024),
|
||||
(10, 20, 100, 1200, 284),
|
||||
]
|
||||
|
||||
dialog = helper.find_demo_dialog(x11, 0, observed)
|
||||
if dialog is None:
|
||||
raise SystemExit("expected Hopper registration dialog was not detected")
|
||||
if dialog[0] != 10:
|
||||
raise SystemExit(f"wrong dialog detected: {dialog!r}")
|
||||
|
||||
print(
|
||||
json.dumps(
|
||||
{
|
||||
"dialog": dialog,
|
||||
"click": helper.demo_click(dialog),
|
||||
"wrong_parent_rejected": helper.find_demo_dialog(
|
||||
x11,
|
||||
0,
|
||||
[observed[0], observed[1]],
|
||||
)
|
||||
is None,
|
||||
},
|
||||
separators=(",", ":"),
|
||||
)
|
||||
)
|
||||
Vendored
+27
@@ -1,4 +1,5 @@
|
||||
import { spawn } from "node:child_process";
|
||||
import { writeFile } from "node:fs/promises";
|
||||
|
||||
const mode = process.argv[2];
|
||||
|
||||
@@ -63,6 +64,32 @@ if (mode === "interactive") {
|
||||
process.exit(23);
|
||||
} else if (mode === "hang") {
|
||||
setInterval(() => undefined, 1_000);
|
||||
} else if (mode === "ready-hang") {
|
||||
await writeFile(process.argv[3], "ready");
|
||||
process.stdout.write("ready\n");
|
||||
setInterval(() => undefined, 1_000);
|
||||
} else if (mode === "detached-cleanup") {
|
||||
const owned = spawn(process.execPath, [process.argv[1], "detached-child"], {
|
||||
detached: true,
|
||||
stdio: "ignore",
|
||||
});
|
||||
const unowned = spawn(process.execPath, [process.argv[1], "detached-child"], {
|
||||
detached: true,
|
||||
env: { ...process.env, REA_PROCESS_RUN_ID: "unowned-neighbor" },
|
||||
stdio: "ignore",
|
||||
});
|
||||
if (owned.pid === undefined || unowned.pid === undefined)
|
||||
throw new Error("detached fixture children did not receive PIDs");
|
||||
owned.unref();
|
||||
unowned.unref();
|
||||
await writeFile(
|
||||
process.argv[3],
|
||||
JSON.stringify({ ownedPid: owned.pid, unownedPid: unowned.pid }),
|
||||
);
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
process.stdout.write("detached-ready\n");
|
||||
} else if (mode === "detached-child") {
|
||||
setInterval(() => undefined, 1_000);
|
||||
} else {
|
||||
process.stderr.write("unknown fixture mode\n");
|
||||
process.exit(2);
|
||||
|
||||
+176
@@ -0,0 +1,176 @@
|
||||
import Foundation
|
||||
|
||||
func fixture(
|
||||
arguments: [String],
|
||||
environment: [String],
|
||||
pointerSize: Int = 8,
|
||||
executablePath: String = "/fixture/executable",
|
||||
appleRecords: [String] = ["pfz=synthetic"],
|
||||
zeroedPfz: Bool = false
|
||||
) -> [UInt8] {
|
||||
var bytes = withUnsafeBytes(of: Int32(arguments.count).littleEndian, Array.init)
|
||||
let pathBytes = Array(executablePath.utf8)
|
||||
bytes.append(contentsOf: pathBytes + [0])
|
||||
let prefixLength = Array("executable_path=".utf8).count
|
||||
let padding = (pointerSize - ((prefixLength + pathBytes.count + 1) % pointerSize)) % pointerSize
|
||||
bytes.append(contentsOf: repeatElement(UInt8(0), count: padding))
|
||||
for argument in arguments { bytes.append(contentsOf: Array(argument.utf8) + [0]) }
|
||||
for entry in environment { bytes.append(contentsOf: Array(entry.utf8) + [0]) }
|
||||
if zeroedPfz {
|
||||
bytes.append(contentsOf: repeatElement(UInt8(0), count: Array("pfz=synthetic".utf8).count + 1))
|
||||
}
|
||||
for record in appleRecords { bytes.append(contentsOf: Array(record.utf8) + [0]) }
|
||||
return bytes
|
||||
}
|
||||
|
||||
@main
|
||||
struct ProcessRunTokenParserProbe {
|
||||
static func main() throws {
|
||||
let argvDecoy = try token(in: fixture(
|
||||
arguments: ["/fixture/executable", "REA_PROCESS_RUN_ID=argv-decoy", "trailing"],
|
||||
environment: ["DECOY=words REA_PROCESS_RUN_ID=synthetic-decoy"]
|
||||
))
|
||||
let realToken = try token(in: fixture(
|
||||
arguments: ["/fixture/executable"],
|
||||
environment: ["DECOY=words REA_PROCESS_RUN_ID=synthetic-decoy", "REA_PROCESS_RUN_ID=owned-token"]
|
||||
))
|
||||
let emptyLaterArgument = try token(in: fixture(
|
||||
arguments: ["/fixture/executable", "", "after-empty"],
|
||||
environment: ["REA_PROCESS_RUN_ID=empty-argument-token"],
|
||||
pointerSize: 8
|
||||
))
|
||||
let alternatePadding = try token(in: fixture(
|
||||
arguments: ["/fixture/executable", "argument"],
|
||||
environment: ["REA_PROCESS_RUN_ID=alternate-padding-token"],
|
||||
pointerSize: 4
|
||||
), pointerSize: 4)
|
||||
let emptyArgv0Read = try token(in: fixture(
|
||||
arguments: ["", "", "after-empty"],
|
||||
environment: ["REA_PROCESS_RUN_ID=empty-argv0-token"],
|
||||
pointerSize: 8
|
||||
))
|
||||
let finalAssignmentArgumentRead = try token(in: fixture(
|
||||
arguments: ["/fixture/executable", "FOO=bar"],
|
||||
environment: ["REA_PROCESS_RUN_ID=final-assignment-token"]
|
||||
))
|
||||
let reservedArgumentIgnored = try token(in: fixture(
|
||||
arguments: ["/fixture/executable", "REA_PROCESS_RUN_ID=argv-decoy"],
|
||||
environment: ["DECOY=words REA_PROCESS_RUN_ID=synthetic-decoy"]
|
||||
))
|
||||
let nonAsciiPathRead = try token(in: fixture(
|
||||
arguments: ["/fixture/é", "FOO=bar"],
|
||||
environment: ["REA_PROCESS_RUN_ID=utf8-path-token"],
|
||||
pointerSize: 8,
|
||||
executablePath: "/fixture/é"
|
||||
))
|
||||
let appleVectorTokenFailsClosed: Bool
|
||||
do {
|
||||
_ = try token(in: fixture(
|
||||
arguments: ["/fixture/executable"],
|
||||
environment: ["pfz=user-value", "PATH=/usr/bin"],
|
||||
appleRecords: ["pfz=synthetic", "REA_PROCESS_RUN_ID=apple-decoy"]
|
||||
))
|
||||
appleVectorTokenFailsClosed = false
|
||||
} catch RunTokenReadError.ambiguousEnvironmentBoundary {
|
||||
appleVectorTokenFailsClosed = true
|
||||
}
|
||||
let clearedAppleVectorTokenFailsClosed: Bool
|
||||
do {
|
||||
_ = try token(in: fixture(
|
||||
arguments: ["/fixture/executable"],
|
||||
environment: ["REA_PROCESS_RUN_ID=cleared-pfz-owned-token"],
|
||||
appleRecords: ["REA_PROCESS_RUN_ID=apple-decoy"],
|
||||
zeroedPfz: true
|
||||
))
|
||||
clearedAppleVectorTokenFailsClosed = false
|
||||
} catch RunTokenReadError.ambiguousEnvironmentBoundary {
|
||||
clearedAppleVectorTokenFailsClosed = true
|
||||
}
|
||||
let callerPfzBeforeTokenRead = try token(in: fixture(
|
||||
arguments: ["/fixture/executable"],
|
||||
environment: ["pfz=caller-value", "REA_PROCESS_RUN_ID=cleared-pfz-owned-token"],
|
||||
zeroedPfz: true
|
||||
))
|
||||
let emptyEnvironmentRecordsBeforeTokenFailClosed: Bool
|
||||
do {
|
||||
_ = try token(in: fixture(
|
||||
arguments: ["/fixture/executable"],
|
||||
environment: ["DECOY=value", "", "", "REA_PROCESS_RUN_ID=synthetic-decoy"],
|
||||
appleRecords: [],
|
||||
zeroedPfz: true
|
||||
))
|
||||
emptyEnvironmentRecordsBeforeTokenFailClosed = false
|
||||
} catch RunTokenReadError.ambiguousEnvironmentBoundary {
|
||||
emptyEnvironmentRecordsBeforeTokenFailClosed = true
|
||||
}
|
||||
let zeroArgumentsRead = try token(in: fixture(
|
||||
arguments: [],
|
||||
environment: ["REA_PROCESS_RUN_ID=zero-argc-token"],
|
||||
pointerSize: 4
|
||||
), pointerSize: 4)
|
||||
var truncatedArgv = withUnsafeBytes(of: Int32(2).littleEndian, Array.init)
|
||||
let truncatedPath = Array("/fixture/executable".utf8)
|
||||
truncatedArgv.append(contentsOf: truncatedPath + [0])
|
||||
let truncatedPadding = (8 - ((Array("executable_path=".utf8).count + truncatedPath.count + 1) % 8)) % 8
|
||||
truncatedArgv.append(contentsOf: repeatElement(UInt8(0), count: truncatedPadding))
|
||||
truncatedArgv.append(contentsOf: Array("/fixture/executable".utf8) + [0])
|
||||
truncatedArgv.append(contentsOf: Array("REA_PROCESS_RUN_ID=synthetic-decoy".utf8))
|
||||
let truncatedArgvFailsClosed: Bool
|
||||
do {
|
||||
_ = try token(in: truncatedArgv)
|
||||
truncatedArgvFailsClosed = false
|
||||
} catch {
|
||||
truncatedArgvFailsClosed = true
|
||||
}
|
||||
let duplicateTokenFailsClosed: Bool
|
||||
do {
|
||||
_ = try token(in: fixture(
|
||||
arguments: ["/fixture/executable"],
|
||||
environment: ["REA_PROCESS_RUN_ID=first", "REA_PROCESS_RUN_ID=second"]
|
||||
))
|
||||
duplicateTokenFailsClosed = false
|
||||
} catch RunTokenReadError.duplicateToken {
|
||||
duplicateTokenFailsClosed = true
|
||||
}
|
||||
let emptyEnvironmentFailsClosed: Bool
|
||||
do {
|
||||
_ = try token(in: fixture(arguments: ["/fixture/executable"], environment: []))
|
||||
emptyEnvironmentFailsClosed = false
|
||||
} catch RunTokenReadError.environmentUnavailable {
|
||||
emptyEnvironmentFailsClosed = true
|
||||
}
|
||||
let missingAppleBoundaryFailsClosed: Bool
|
||||
do {
|
||||
_ = try token(in: fixture(
|
||||
arguments: ["/fixture/executable"],
|
||||
environment: ["REA_PROCESS_RUN_ID=synthetic-decoy"],
|
||||
appleRecords: []
|
||||
))
|
||||
missingAppleBoundaryFailsClosed = false
|
||||
} catch RunTokenReadError.appleVectorUnavailable {
|
||||
missingAppleBoundaryFailsClosed = true
|
||||
}
|
||||
|
||||
let result: [String: Any] = [
|
||||
"argvDecoyIgnored": argvDecoy == nil,
|
||||
"realTokenRead": realToken == "owned-token",
|
||||
"emptyLaterArgumentRead": emptyLaterArgument == "empty-argument-token",
|
||||
"alternatePaddingRead": alternatePadding == "alternate-padding-token",
|
||||
"truncatedArgvFailsClosed": truncatedArgvFailsClosed,
|
||||
"duplicateTokenFailsClosed": duplicateTokenFailsClosed,
|
||||
"emptyEnvironmentFailsClosed": emptyEnvironmentFailsClosed,
|
||||
"missingAppleBoundaryFailsClosed": missingAppleBoundaryFailsClosed,
|
||||
"emptyArgv0Read": emptyArgv0Read == "empty-argv0-token",
|
||||
"finalAssignmentArgumentRead": finalAssignmentArgumentRead == "final-assignment-token",
|
||||
"reservedArgumentIgnored": reservedArgumentIgnored == nil,
|
||||
"nonAsciiPathRead": nonAsciiPathRead == "utf8-path-token",
|
||||
"appleVectorTokenFailsClosed": appleVectorTokenFailsClosed,
|
||||
"clearedAppleVectorTokenFailsClosed": clearedAppleVectorTokenFailsClosed,
|
||||
"callerPfzBeforeTokenRead": callerPfzBeforeTokenRead == "cleared-pfz-owned-token",
|
||||
"emptyEnvironmentRecordsBeforeTokenFailClosed": emptyEnvironmentRecordsBeforeTokenFailClosed,
|
||||
"zeroArgumentsRead": zeroArgumentsRead == "zero-argc-token",
|
||||
]
|
||||
let output = try JSONSerialization.data(withJSONObject: result, options: [.sortedKeys])
|
||||
FileHandle.standardOutput.write(output)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import Darwin
|
||||
import Foundation
|
||||
|
||||
@main
|
||||
struct ProcessRunTokenSnapshotProbe {
|
||||
static func main() throws {
|
||||
var sizeQueries = 0
|
||||
var readAttempts = 0
|
||||
let retried = readProcessSnapshot { _, output, size in
|
||||
guard output != nil else {
|
||||
sizeQueries += 1
|
||||
size = MemoryLayout<kinfo_proc>.stride
|
||||
return 0
|
||||
}
|
||||
readAttempts += 1
|
||||
if readAttempts == 1 {
|
||||
errno = ENOMEM
|
||||
return -1
|
||||
}
|
||||
size = 0
|
||||
return 0
|
||||
}
|
||||
|
||||
let otherError = readProcessSnapshot { _, output, size in
|
||||
if output == nil {
|
||||
size = MemoryLayout<kinfo_proc>.stride
|
||||
return 0
|
||||
}
|
||||
errno = EACCES
|
||||
return -1
|
||||
}
|
||||
|
||||
let output: [String: Any] = [
|
||||
"retriedAfterFreshSize": retried.failure == nil && sizeQueries == 2 && readAttempts == 2,
|
||||
"preservedOtherErrno": otherError.failure == "process_table_failed_\(EACCES)"
|
||||
]
|
||||
let data = try JSONSerialization.data(withJSONObject: output, options: [.sortedKeys])
|
||||
FileHandle.standardOutput.write(data)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
const [root] = process.argv.slice(2);
|
||||
if (root === undefined)
|
||||
throw new Error("Snapshot cancellation fixture requires an observation root");
|
||||
|
||||
await writeFile(join(root, "created-after-start"), "x");
|
||||
Reference in New Issue
Block a user