feat(permissions): add scoped process capture elicitation
This commit is contained in:
@@ -112,6 +112,37 @@ describe("runtime configuration", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("can configure a process-capture ceiling without an implicit grant", () => {
|
||||
const result = parseConfig({
|
||||
REA_PROCESS_CAPTURE_ENABLED: "true",
|
||||
REA_PROCESS_CAPTURE_AUTO_GRANT: "false",
|
||||
REA_PROCESS_EXECUTABLE_ROOTS_JSON: '["/opt/tools"]',
|
||||
REA_PROCESS_WORKING_ROOTS_JSON: '["/tmp/work"]',
|
||||
});
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value.permissionCeilings).toContainEqual(
|
||||
expect.objectContaining({ capability: "process_capture" }),
|
||||
);
|
||||
expect(result.value.administratorPermissionGrants).not.toContainEqual(
|
||||
expect.objectContaining({ capability: "process_capture" }),
|
||||
);
|
||||
});
|
||||
|
||||
it("preserves the configured process-capture administrator grant by default", () => {
|
||||
const result = parseConfig({
|
||||
REA_PROCESS_CAPTURE_ENABLED: "true",
|
||||
REA_PROCESS_EXECUTABLE_ROOTS_JSON: '["/opt/tools"]',
|
||||
REA_PROCESS_WORKING_ROOTS_JSON: '["/tmp/work"]',
|
||||
});
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value.administratorPermissionGrants).toContainEqual(
|
||||
expect.objectContaining({
|
||||
capability: "process_capture",
|
||||
lifetime: "administrator",
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("builds a no-network JavaScript replay ceiling only when enabled", () => {
|
||||
const result = parseConfig({
|
||||
REA_JAVASCRIPT_REPLAY_ENABLED: "true",
|
||||
|
||||
@@ -112,6 +112,30 @@ describe("runtime permission reload", () => {
|
||||
expect(await canRead(runtime.authority, fixture.newRoot)).toBe(false);
|
||||
expect(await canRead(runtime.authority, fixture.latestRoot)).toBe(true);
|
||||
});
|
||||
|
||||
it("continues with later reloads after an unexpected reload rejection", async () => {
|
||||
const fixture = await reloadFixture();
|
||||
let reads = 0;
|
||||
const runtime = await startRuntime(fixture.env, async () => {
|
||||
reads += 1;
|
||||
if (reads === 1) throw new Error("synthetic unexpected read failure");
|
||||
return ok(projectStore(fixture.projectRoot, []));
|
||||
});
|
||||
|
||||
configure(fixture.env, fixture.newRoot, true);
|
||||
runtime.reload();
|
||||
runtime.reload();
|
||||
await runtime.notificationCount(1);
|
||||
|
||||
expect(reads).toBe(2);
|
||||
expect(runtime.options.processPolicy?.enabled).toBe(true);
|
||||
expect(runtime.options.evidenceFilePolicy?.roots).toEqual([
|
||||
fixture.newRoot,
|
||||
]);
|
||||
expect(runtime.options.artifactIntegrityContinueEnabled?.()).toBe(true);
|
||||
expect(await canRead(runtime.authority, fixture.oldRoot)).toBe(false);
|
||||
expect(await canRead(runtime.authority, fixture.newRoot)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
const reloadFixture = async () => {
|
||||
|
||||
@@ -147,6 +147,131 @@ describe("permission authority", () => {
|
||||
expect(await canRead(authority.value, oldRoot)).toBe(false);
|
||||
expect(await canRead(authority.value, newRoot)).toBe(true);
|
||||
});
|
||||
|
||||
it("isolates transient grants and consumption between live connections", async () => {
|
||||
const sandbox = await mkdtemp(join(tmpdir(), "rea-permission-session-"));
|
||||
const scope = evidenceScope(sandbox);
|
||||
const configured = await createPermissionAuthority([scope]);
|
||||
expect(configured.ok).toBe(true);
|
||||
if (!configured.ok) return;
|
||||
const connectionA = configured.value.createConnectionAuthority();
|
||||
const connectionB = configured.value.createConnectionAuthority();
|
||||
const request = {
|
||||
...scope,
|
||||
operation_identity: "read:connection-owned",
|
||||
};
|
||||
|
||||
expect(
|
||||
connectionA.grant({
|
||||
...request,
|
||||
grant_id: "session:a",
|
||||
lifetime: "session",
|
||||
operation_identity: null,
|
||||
expires_at: null,
|
||||
}),
|
||||
).toMatchObject({ ok: true });
|
||||
expect(await connectionA.authorize(request, "read")).toMatchObject({
|
||||
ok: true,
|
||||
});
|
||||
expect(await connectionB.authorize(request, "read")).toMatchObject({
|
||||
ok: false,
|
||||
});
|
||||
|
||||
connectionB.clearSessionGrants();
|
||||
expect(await connectionA.authorize(request, "read")).toMatchObject({
|
||||
ok: true,
|
||||
});
|
||||
|
||||
connectionA.clearSessionGrants();
|
||||
const onceRequest = {
|
||||
...request,
|
||||
operation_identity: "read:once-on-a",
|
||||
};
|
||||
expect(
|
||||
connectionA.grant({
|
||||
...onceRequest,
|
||||
grant_id: "once:a",
|
||||
lifetime: "once",
|
||||
expires_at: null,
|
||||
}),
|
||||
).toMatchObject({ ok: true });
|
||||
expect(
|
||||
connectionB.grant({
|
||||
...onceRequest,
|
||||
grant_id: "once:a",
|
||||
lifetime: "once",
|
||||
expires_at: null,
|
||||
}),
|
||||
).toMatchObject({ ok: true });
|
||||
const concurrent = await Promise.all([
|
||||
connectionA.authorize(onceRequest, "read"),
|
||||
connectionA.authorize(onceRequest, "read"),
|
||||
]);
|
||||
expect(concurrent.filter(({ ok }) => ok)).toHaveLength(1);
|
||||
expect(await connectionB.authorize(onceRequest, "read")).toMatchObject({
|
||||
ok: true,
|
||||
});
|
||||
});
|
||||
|
||||
it("applies configured policy reloads to existing connections", async () => {
|
||||
const sandbox = await mkdtemp(
|
||||
join(tmpdir(), "rea-permission-live-reload-"),
|
||||
);
|
||||
const allowedRoot = join(sandbox, "allowed");
|
||||
const replacementRoot = join(sandbox, "replacement");
|
||||
await Promise.all([mkdir(allowedRoot), mkdir(replacementRoot)]);
|
||||
const configured = await createPermissionAuthority([
|
||||
evidenceScope(allowedRoot),
|
||||
]);
|
||||
expect(configured.ok).toBe(true);
|
||||
if (!configured.ok) return;
|
||||
const connection = configured.value.createConnectionAuthority();
|
||||
expect(
|
||||
connection.grant({
|
||||
...evidenceScope(allowedRoot),
|
||||
grant_id: "session:before-reload",
|
||||
lifetime: "session",
|
||||
operation_identity: null,
|
||||
expires_at: null,
|
||||
}),
|
||||
).toMatchObject({ ok: true });
|
||||
expect(await canRead(connection, allowedRoot)).toBe(true);
|
||||
|
||||
const collisionRequest = {
|
||||
...evidenceScope(allowedRoot),
|
||||
operation_identity: "read:reload-collision",
|
||||
};
|
||||
expect(
|
||||
connection.grant({
|
||||
...collisionRequest,
|
||||
grant_id: "shared-id",
|
||||
lifetime: "once",
|
||||
expires_at: null,
|
||||
}),
|
||||
).toMatchObject({ ok: true });
|
||||
expect(await connection.authorize(collisionRequest, "read")).toMatchObject({
|
||||
ok: true,
|
||||
});
|
||||
expect(
|
||||
await configured.value.replaceAdministratorGrants([
|
||||
{
|
||||
...evidenceScope(allowedRoot),
|
||||
grant_id: "shared-id",
|
||||
lifetime: "administrator",
|
||||
operation_identity: null,
|
||||
expires_at: null,
|
||||
},
|
||||
]),
|
||||
).toEqual({ ok: true, value: null });
|
||||
expect(await connection.authorize(collisionRequest, "read")).toMatchObject({
|
||||
ok: true,
|
||||
});
|
||||
|
||||
expect(
|
||||
await configured.value.reload([evidenceScope(replacementRoot)]),
|
||||
).toEqual({ ok: true, value: null });
|
||||
expect(await canRead(connection, allowedRoot)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
const evidenceScope = (root: string): PermissionScope => ({
|
||||
|
||||
@@ -0,0 +1,414 @@
|
||||
import { isInputRequiredResult } from "@modelcontextprotocol/server";
|
||||
import { mkdir, mkdtemp, rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { PermissionAuthority } from "../src/application/PermissionAuthority.js";
|
||||
import { createPermissionPolicy } from "../src/domain/permissionPolicy.js";
|
||||
import {
|
||||
authorizeProcessCaptureWithElicitation,
|
||||
type ProcessCaptureElicitationState,
|
||||
} from "../src/server/ProcessCaptureElicitation.js";
|
||||
|
||||
const request = {
|
||||
capability: "process_capture" as const,
|
||||
roots: ["/tmp"],
|
||||
executables: [process.execPath],
|
||||
environment_names: ["PATH"],
|
||||
network: "external" as const,
|
||||
mount: false,
|
||||
operation_identity: "capture:test",
|
||||
};
|
||||
|
||||
describe("process-capture MCP elicitation", () => {
|
||||
it("grants and reuses a signed session scope on the modern protocol", async () => {
|
||||
const authority = ceilingOnlyAuthority();
|
||||
let state: ProcessCaptureElicitationState | undefined;
|
||||
const elicitation = {
|
||||
stateCodec: {
|
||||
mint: (value: ProcessCaptureElicitationState) => {
|
||||
state = value;
|
||||
return Promise.resolve("signed-state");
|
||||
},
|
||||
verify: () => verifiedState(state),
|
||||
},
|
||||
supported: () => true,
|
||||
modern: () => true,
|
||||
consumedNonces: new Map<string, number>(),
|
||||
};
|
||||
const first = await authorizeProcessCaptureWithElicitation(
|
||||
authority,
|
||||
request,
|
||||
requestContext(),
|
||||
elicitation,
|
||||
);
|
||||
expect(isInputRequiredResult(first)).toBe(true);
|
||||
expect(first).toMatchObject({ requestState: "signed-state" });
|
||||
expect(first).toMatchObject({
|
||||
inputRequests: {
|
||||
process_capture_grant: {
|
||||
params: {
|
||||
message: expect.stringContaining("Mount access: no"),
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(state?.request).toEqual(request);
|
||||
|
||||
const accepted = await authorizeProcessCaptureWithElicitation(
|
||||
authority,
|
||||
request,
|
||||
requestContext(state, {
|
||||
action: "accept",
|
||||
content: { lifetime: "session" },
|
||||
}),
|
||||
elicitation,
|
||||
);
|
||||
expect(isInputRequiredResult(accepted)).toBe(false);
|
||||
if (isInputRequiredResult(accepted)) return;
|
||||
expect(accepted.ok).toBe(true);
|
||||
|
||||
const reused = await authorizeProcessCaptureWithElicitation(
|
||||
authority,
|
||||
request,
|
||||
requestContext(),
|
||||
elicitation,
|
||||
);
|
||||
expect(isInputRequiredResult(reused)).toBe(false);
|
||||
if (!isInputRequiredResult(reused)) expect(reused.ok).toBe(true);
|
||||
});
|
||||
|
||||
it("fails closed for legacy clients and altered continuations", async () => {
|
||||
const authority = ceilingOnlyAuthority();
|
||||
let state: ProcessCaptureElicitationState | undefined;
|
||||
const elicitation = {
|
||||
stateCodec: {
|
||||
mint: (value: ProcessCaptureElicitationState) => {
|
||||
state = value;
|
||||
return Promise.resolve("signed-state");
|
||||
},
|
||||
verify: () => verifiedState(state),
|
||||
},
|
||||
supported: () => true,
|
||||
modern: () => false,
|
||||
consumedNonces: new Map<string, number>(),
|
||||
};
|
||||
const legacy = await authorizeProcessCaptureWithElicitation(
|
||||
authority,
|
||||
request,
|
||||
requestContext(),
|
||||
elicitation,
|
||||
);
|
||||
expect(isInputRequiredResult(legacy)).toBe(false);
|
||||
if (!isInputRequiredResult(legacy)) expect(legacy.ok).toBe(false);
|
||||
|
||||
const modern = { ...elicitation, modern: () => true };
|
||||
await authorizeProcessCaptureWithElicitation(
|
||||
authority,
|
||||
request,
|
||||
requestContext(),
|
||||
modern,
|
||||
);
|
||||
const altered = await authorizeProcessCaptureWithElicitation(
|
||||
authority,
|
||||
{ ...request, operation_identity: "capture:altered" },
|
||||
requestContext(state, {
|
||||
action: "accept",
|
||||
content: { lifetime: "session" },
|
||||
}),
|
||||
modern,
|
||||
);
|
||||
expect(isInputRequiredResult(altered)).toBe(false);
|
||||
if (!isInputRequiredResult(altered)) expect(altered.ok).toBe(false);
|
||||
});
|
||||
|
||||
it("binds signed continuation state to exact origins", async () => {
|
||||
const authority = ceilingOnlyAuthority([
|
||||
"https://example.test",
|
||||
"https://other.test",
|
||||
]);
|
||||
let state: ProcessCaptureElicitationState | undefined;
|
||||
const elicitation = {
|
||||
stateCodec: {
|
||||
mint: (value: ProcessCaptureElicitationState) => {
|
||||
state = value;
|
||||
return Promise.resolve("signed-state");
|
||||
},
|
||||
verify: () => verifiedState(state),
|
||||
},
|
||||
supported: () => true,
|
||||
modern: () => true,
|
||||
consumedNonces: new Map<string, number>(),
|
||||
};
|
||||
const scoped = { ...request, origins: ["https://example.test"] };
|
||||
const prompted = await authorizeProcessCaptureWithElicitation(
|
||||
authority,
|
||||
scoped,
|
||||
requestContext(),
|
||||
elicitation,
|
||||
);
|
||||
expect(prompted).toMatchObject({
|
||||
inputRequests: {
|
||||
process_capture_grant: {
|
||||
params: {
|
||||
message: expect.stringContaining("Origins: https://example.test"),
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const altered = await authorizeProcessCaptureWithElicitation(
|
||||
authority,
|
||||
{ ...scoped, origins: ["https://other.test"] },
|
||||
requestContext(state, {
|
||||
action: "accept",
|
||||
content: { lifetime: "session" },
|
||||
}),
|
||||
elicitation,
|
||||
);
|
||||
|
||||
expect(isInputRequiredResult(altered)).toBe(false);
|
||||
if (!isInputRequiredResult(altered)) expect(altered.ok).toBe(false);
|
||||
});
|
||||
|
||||
it("consumes once grants and rejects continuation replay", async () => {
|
||||
const authority = ceilingOnlyAuthority();
|
||||
let state: ProcessCaptureElicitationState | undefined;
|
||||
const elicitation = {
|
||||
stateCodec: {
|
||||
mint: (value: ProcessCaptureElicitationState) => {
|
||||
state = value;
|
||||
return Promise.resolve("signed-state");
|
||||
},
|
||||
verify: () => verifiedState(state),
|
||||
},
|
||||
supported: () => true,
|
||||
modern: () => true,
|
||||
consumedNonces: new Map<string, number>(),
|
||||
};
|
||||
await authorizeProcessCaptureWithElicitation(
|
||||
authority,
|
||||
request,
|
||||
requestContext(),
|
||||
elicitation,
|
||||
);
|
||||
const response = {
|
||||
action: "accept",
|
||||
content: { lifetime: "once" },
|
||||
};
|
||||
const accepted = await authorizeProcessCaptureWithElicitation(
|
||||
authority,
|
||||
request,
|
||||
requestContext(state, response),
|
||||
elicitation,
|
||||
);
|
||||
if (isInputRequiredResult(accepted)) throw new Error("grant was not used");
|
||||
expect(accepted.ok).toBe(true);
|
||||
|
||||
const replayed = await authorizeProcessCaptureWithElicitation(
|
||||
authority,
|
||||
request,
|
||||
requestContext(state, response),
|
||||
elicitation,
|
||||
);
|
||||
expect(isInputRequiredResult(replayed)).toBe(false);
|
||||
if (!isInputRequiredResult(replayed)) expect(replayed.ok).toBe(false);
|
||||
|
||||
const next = await authorizeProcessCaptureWithElicitation(
|
||||
authority,
|
||||
request,
|
||||
requestContext(),
|
||||
elicitation,
|
||||
);
|
||||
expect(isInputRequiredResult(next)).toBe(true);
|
||||
|
||||
const declined = await authorizeProcessCaptureWithElicitation(
|
||||
authority,
|
||||
request,
|
||||
requestContext(state, { action: "decline" }),
|
||||
elicitation,
|
||||
);
|
||||
expect(isInputRequiredResult(declined)).toBe(false);
|
||||
const acceptedAfterDecline = await authorizeProcessCaptureWithElicitation(
|
||||
authority,
|
||||
request,
|
||||
requestContext(state, {
|
||||
action: "accept",
|
||||
content: { lifetime: "session" },
|
||||
}),
|
||||
elicitation,
|
||||
);
|
||||
expect(isInputRequiredResult(acceptedAfterDecline)).toBe(false);
|
||||
if (!isInputRequiredResult(acceptedAfterDecline))
|
||||
expect(acceptedAfterDecline.ok).toBe(false);
|
||||
});
|
||||
|
||||
it("bounds replay state and prunes entries at the signed-state TTL", async () => {
|
||||
const authority = ceilingOnlyAuthority();
|
||||
let state: ProcessCaptureElicitationState | undefined;
|
||||
const consumedNonces = new Map<string, number>();
|
||||
const elicitation = {
|
||||
stateCodec: {
|
||||
mint: (value: ProcessCaptureElicitationState) => {
|
||||
state = value;
|
||||
return Promise.resolve("signed-state");
|
||||
},
|
||||
verify: () => verifiedState(state),
|
||||
},
|
||||
supported: () => true,
|
||||
modern: () => true,
|
||||
consumedNonces,
|
||||
};
|
||||
await authorizeProcessCaptureWithElicitation(
|
||||
authority,
|
||||
request,
|
||||
requestContext(),
|
||||
elicitation,
|
||||
);
|
||||
const future = Date.now() + 600_000;
|
||||
for (let index = 0; index < 4_096; index += 1)
|
||||
consumedNonces.set(`occupied-${String(index)}`, future);
|
||||
|
||||
const rejectedAtCapacity = await authorizeProcessCaptureWithElicitation(
|
||||
authority,
|
||||
request,
|
||||
requestContext(state, {
|
||||
action: "accept",
|
||||
content: { lifetime: "session" },
|
||||
}),
|
||||
elicitation,
|
||||
);
|
||||
expect(isInputRequiredResult(rejectedAtCapacity)).toBe(false);
|
||||
if (!isInputRequiredResult(rejectedAtCapacity))
|
||||
expect(rejectedAtCapacity.ok).toBe(false);
|
||||
|
||||
consumedNonces.set("occupied-0", Date.now() - 1);
|
||||
const acceptedAfterPrune = await authorizeProcessCaptureWithElicitation(
|
||||
authority,
|
||||
request,
|
||||
requestContext(state, {
|
||||
action: "accept",
|
||||
content: { lifetime: "session" },
|
||||
}),
|
||||
elicitation,
|
||||
);
|
||||
expect(isInputRequiredResult(acceptedAfterPrune)).toBe(false);
|
||||
if (!isInputRequiredResult(acceptedAfterPrune))
|
||||
expect(acceptedAfterPrune.ok).toBe(true);
|
||||
expect(consumedNonces.has("occupied-0")).toBe(false);
|
||||
expect(consumedNonces.size).toBe(4_096);
|
||||
});
|
||||
|
||||
it.each(["result", "throw"] as const)(
|
||||
"revokes an elicited grant when final authorization ends with %s",
|
||||
async (failure) => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-elicit-rollback-"));
|
||||
const scoped = { ...request, roots: [root] };
|
||||
const policy = createPermissionPolicy([
|
||||
{
|
||||
capability: "process_capture",
|
||||
roots: scoped.roots,
|
||||
executables: scoped.executables,
|
||||
environment_names: scoped.environment_names,
|
||||
network: scoped.network,
|
||||
mount: scoped.mount,
|
||||
},
|
||||
]);
|
||||
class FailingFinalAuthority extends PermissionAuthority {
|
||||
private authorizationCount = 0;
|
||||
|
||||
override async authorize(
|
||||
...arguments_: Parameters<PermissionAuthority["authorize"]>
|
||||
): ReturnType<PermissionAuthority["authorize"]> {
|
||||
this.authorizationCount += 1;
|
||||
const result = await super.authorize(...arguments_);
|
||||
if (failure === "result" && this.authorizationCount === 2)
|
||||
await rm(root, { recursive: true, force: true });
|
||||
if (failure === "throw" && this.authorizationCount === 3)
|
||||
throw new Error("synthetic final authorization rejection");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
const authority = new FailingFinalAuthority(policy);
|
||||
let state: ProcessCaptureElicitationState | undefined;
|
||||
const elicitation = {
|
||||
stateCodec: {
|
||||
mint: (value: ProcessCaptureElicitationState) => {
|
||||
state = value;
|
||||
return Promise.resolve("signed-state");
|
||||
},
|
||||
verify: () => verifiedState(state),
|
||||
},
|
||||
supported: () => true,
|
||||
modern: () => true,
|
||||
consumedNonces: new Map<string, number>(),
|
||||
};
|
||||
await authorizeProcessCaptureWithElicitation(
|
||||
authority,
|
||||
scoped,
|
||||
requestContext(),
|
||||
elicitation,
|
||||
);
|
||||
const finalAuthorization = authorizeProcessCaptureWithElicitation(
|
||||
authority,
|
||||
scoped,
|
||||
requestContext(state, {
|
||||
action: "accept",
|
||||
content: { lifetime: "session" },
|
||||
}),
|
||||
elicitation,
|
||||
);
|
||||
if (failure === "throw")
|
||||
await expect(finalAuthorization).rejects.toThrow(
|
||||
"synthetic final authorization rejection",
|
||||
);
|
||||
else {
|
||||
const failed = await finalAuthorization;
|
||||
expect(isInputRequiredResult(failed)).toBe(false);
|
||||
if (!isInputRequiredResult(failed)) expect(failed.ok).toBe(false);
|
||||
await mkdir(root);
|
||||
}
|
||||
const retry = await authority.authorize(scoped, "read", {
|
||||
elicitationSupported: true,
|
||||
});
|
||||
expect(retry.ok).toBe(false);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
const ceilingOnlyAuthority = (
|
||||
origins?: readonly string[],
|
||||
): PermissionAuthority =>
|
||||
new PermissionAuthority(
|
||||
createPermissionPolicy([
|
||||
{
|
||||
capability: "process_capture",
|
||||
roots: request.roots,
|
||||
executables: request.executables,
|
||||
environment_names: request.environment_names,
|
||||
...(origins === undefined ? {} : { origins }),
|
||||
network: request.network,
|
||||
mount: request.mount,
|
||||
},
|
||||
]),
|
||||
);
|
||||
|
||||
const requestContext = (
|
||||
state?: ProcessCaptureElicitationState,
|
||||
response?: Record<string, unknown>,
|
||||
) => ({
|
||||
mcpReq: {
|
||||
requestState: () => state,
|
||||
...(response === undefined
|
||||
? {}
|
||||
: { inputResponses: { process_capture_grant: response } }),
|
||||
},
|
||||
});
|
||||
|
||||
const verifiedState = (
|
||||
state: ProcessCaptureElicitationState | undefined,
|
||||
): Promise<ProcessCaptureElicitationState> => {
|
||||
if (state === undefined) throw new Error("state was not minted");
|
||||
return Promise.resolve(state);
|
||||
};
|
||||
@@ -0,0 +1,30 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { processCapturePermissionRequest } from "../src/application/ProcessCapturePermission.js";
|
||||
import { parseProcessScenario } from "../src/domain/processCapture.js";
|
||||
|
||||
describe("process capture permission request", () => {
|
||||
it("projects the complete adapter-neutral authority scope", () => {
|
||||
const scenario = parseProcessScenario({
|
||||
approved: true,
|
||||
executable: "/bin/tool",
|
||||
arguments: ["--probe"],
|
||||
working_directory: "/workspace",
|
||||
environment: { FIXTURE_TOKEN: "secret" },
|
||||
inherit_environment: ["PATH"],
|
||||
filesystem_roots: ["/workspace/output"],
|
||||
network_access: "host",
|
||||
events: [],
|
||||
});
|
||||
|
||||
expect(processCapturePermissionRequest(scenario)).toEqual({
|
||||
capability: "process_capture",
|
||||
roots: ["/workspace", "/workspace/output"],
|
||||
executables: ["/bin/tool"],
|
||||
environment_names: ["FIXTURE_TOKEN", "PATH"],
|
||||
network: "external",
|
||||
mount: false,
|
||||
operation_identity: "capture_process_scenario:/bin/tool",
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,4 @@
|
||||
import { chmod, mkdtemp, stat, writeFile } from "node:fs/promises";
|
||||
import { chmod, mkdtemp, stat, symlink, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
||||
@@ -62,6 +62,46 @@ describe("project permission store", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects a symlink even when its target is owner-only", async () => {
|
||||
const project = await mkdtemp(join(tmpdir(), "rea-policy-symlink-"));
|
||||
const target = join(project, "target.json");
|
||||
const path = join(project, "permissions.json");
|
||||
expect((await writeProjectPermissionStore(target, project, [])).ok).toBe(
|
||||
true,
|
||||
);
|
||||
await symlink(target, path);
|
||||
|
||||
expect(await readProjectPermissionStore(path, project)).toMatchObject({
|
||||
ok: false,
|
||||
error: { reason: "not_owner_only" },
|
||||
});
|
||||
});
|
||||
|
||||
it("round-trips managed runtime project grants", async () => {
|
||||
const project = await mkdtemp(join(tmpdir(), "rea-policy-managed-"));
|
||||
const path = join(project, "permissions.json");
|
||||
const grant = {
|
||||
grant_id: "project:managed-runtime",
|
||||
capability: "managed_runtime" as const,
|
||||
roots: [project],
|
||||
executables: [process.execPath],
|
||||
environment_names: [],
|
||||
network: "none" as const,
|
||||
mount: false,
|
||||
lifetime: "project" as const,
|
||||
operation_identity: null,
|
||||
expires_at: null,
|
||||
};
|
||||
|
||||
expect(
|
||||
await writeProjectPermissionStore(path, project, [grant]),
|
||||
).toMatchObject({ ok: true, value: { grants: [grant] } });
|
||||
expect(await readProjectPermissionStore(path, project)).toMatchObject({
|
||||
ok: true,
|
||||
value: { grants: [grant] },
|
||||
});
|
||||
});
|
||||
|
||||
it("classifies malformed JSON as an invalid store", async () => {
|
||||
const project = await mkdtemp(join(tmpdir(), "rea-policy-invalid-"));
|
||||
const path = join(project, "permissions.json");
|
||||
|
||||
@@ -34,8 +34,12 @@ describe("canonical skill transaction", () => {
|
||||
expect(await readFile(`${destination}.rea.backup`, "utf8")).toBe(
|
||||
"stale managed skill\n",
|
||||
);
|
||||
expect(await readFile(destination, "utf8")).toContain('version: "21"');
|
||||
expect(await readFile(destination, "utf8")).toContain(
|
||||
const installedSkill = await readFile(destination, "utf8");
|
||||
expect(installedSkill).toContain('version: "22"');
|
||||
expect(installedSkill).toContain(
|
||||
"use normal repository tools and skip REA readiness",
|
||||
);
|
||||
expect(installedSkill).toContain(
|
||||
`tool_count: ${String(TOOL_CONTRACTS.length)}`,
|
||||
);
|
||||
expect(await readFile(sibling, "utf8")).toBe("unrelated skill\n");
|
||||
|
||||
Reference in New Issue
Block a user