* refactor(test): colocate pure-domain tests and reduce test debt Move focused immutable domain/contracts/adapter tests from tests/composition/** beside their production owners under src/** as colocated *.test.ts/*.fixture.ts, and relocate persistence-shaped composition tests under tests/boundary/filesystem/**. Update import paths, the Vitest project topology (shared worker context for pure domain/contracts and recording-port service projects), the test migration ledger, testing docs, and AGENTS.md to match. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * docs: remove test migration ledger The cutover is complete and the ledger is no longer referenced anywhere in source, scripts, or the docs gate. Drop the standalone artifact. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * docs: clean up stale migration artifacts Remove empty directories left by the test migration and replace the "final cutover" language in docs/testing.md with standing PR guidance that no longer references the completed migration. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix: repair CI failures from schema, knip, and stale generated artifacts Three root causes fixed: 1. catalog-schemas.mjs: valuesAt only traversed anyOf from Zod's toJSONSchema, not oneOf. The webScreenshotDiffSchema change to a discriminated union produces oneOf, so the product catalog generator could not derive the web_screenshot_diff schema version. Add oneOf traversal. 2. conformancePackage.ts: the test rewrite removed the only imports of ScenarioManifest, ReplayPlan, ShimPlan, and ExpectedEvidence, making them unused exports that knip flags. Remove the dead type aliases. 3. Regenerate stale artifacts (product catalog, MCP tool catalog, skill metadata, conformance manifest) that drifted from the source changes. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> --------- Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
156 lines
5.1 KiB
TypeScript
156 lines
5.1 KiB
TypeScript
import { chmod, stat, symlink, writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
|
|
import {
|
|
readProjectPermissionStore,
|
|
revokeProjectPermissionGrant,
|
|
writeProjectPermissionStore,
|
|
} from "../../../src/application/ProjectPermissionStore.js";
|
|
|
|
describe("project permission store", () => {
|
|
it("persists explicit project grants atomically with owner-only permissions", async () => {
|
|
const project = await createTestTempDirectory("rea-policy-project-");
|
|
const path = join(project, ".rea", "permissions.json");
|
|
const grant = {
|
|
grant_id: "project:evidence-read",
|
|
capability: "evidence_read" as const,
|
|
roots: [project],
|
|
executables: [],
|
|
environment_names: [],
|
|
network: "none" as const,
|
|
mount: false,
|
|
lifetime: "project" as const,
|
|
operation_identity: null,
|
|
expires_at: null,
|
|
};
|
|
|
|
const written = await writeProjectPermissionStore(path, project, [grant]);
|
|
expect(written.ok).toBe(true);
|
|
expect((await stat(path)).mode & 0o077).toBe(0);
|
|
const loaded = await readProjectPermissionStore(path, project);
|
|
expect(loaded).toMatchObject({
|
|
ok: true,
|
|
value: { grants: [grant] },
|
|
});
|
|
});
|
|
|
|
it("rejects stores readable by another user class", async () => {
|
|
const project = await createTestTempDirectory("rea-policy-mode-");
|
|
const path = join(project, "permissions.json");
|
|
const written = await writeProjectPermissionStore(path, project, []);
|
|
expect(written.ok).toBe(true);
|
|
await chmod(path, 0o644);
|
|
|
|
expect(await readProjectPermissionStore(path, project)).toMatchObject({
|
|
ok: false,
|
|
error: { reason: "not_owner_only" },
|
|
});
|
|
});
|
|
|
|
it("binds grants to canonical project identity", async () => {
|
|
const first = await createTestTempDirectory("rea-policy-first-");
|
|
const second = await createTestTempDirectory("rea-policy-second-");
|
|
const path = join(first, "permissions.json");
|
|
expect((await writeProjectPermissionStore(path, first, [])).ok).toBe(true);
|
|
|
|
expect(await readProjectPermissionStore(path, second)).toMatchObject({
|
|
ok: false,
|
|
error: { reason: "invalid" },
|
|
});
|
|
});
|
|
|
|
it("rejects a symlink even when its target is owner-only", async () => {
|
|
const project = await createTestTempDirectory("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 createTestTempDirectory("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 createTestTempDirectory("rea-policy-invalid-");
|
|
const path = join(project, "permissions.json");
|
|
await writeFile(path, "{", { mode: 0o600 });
|
|
|
|
expect(await readProjectPermissionStore(path, project)).toMatchObject({
|
|
ok: false,
|
|
error: { reason: "invalid" },
|
|
});
|
|
});
|
|
|
|
it("serializes concurrent grant revocations without losing an update", async () => {
|
|
const project = await createTestTempDirectory("rea-policy-revoke-");
|
|
const path = join(project, ".rea", "permissions.json");
|
|
const grant = (grantId: string) => ({
|
|
grant_id: grantId,
|
|
capability: "evidence_read" as const,
|
|
roots: [project],
|
|
executables: [],
|
|
environment_names: [],
|
|
network: "none" as const,
|
|
mount: false,
|
|
lifetime: "project" as const,
|
|
operation_identity: null,
|
|
expires_at: null,
|
|
});
|
|
expect(
|
|
(
|
|
await writeProjectPermissionStore(path, project, [
|
|
grant("grant-one"),
|
|
grant("grant-two"),
|
|
])
|
|
).ok,
|
|
).toBe(true);
|
|
|
|
const revoked = await Promise.all([
|
|
revokeProjectPermissionGrant(path, project, "grant-one"),
|
|
revokeProjectPermissionGrant(path, project, "grant-two"),
|
|
]);
|
|
|
|
expect(revoked).toEqual([
|
|
{ ok: true, value: true },
|
|
{ ok: true, value: true },
|
|
]);
|
|
expect(await readProjectPermissionStore(path, project)).toMatchObject({
|
|
ok: true,
|
|
value: { grants: [] },
|
|
});
|
|
});
|
|
});
|