refactor(files): use caller paths for local evidence files
This commit is contained in:
@@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
type AnalysisSnapshot,
|
||||
analysisSnapshotSchema,
|
||||
snapshotBinding,
|
||||
snapshotEvidenceForQuery,
|
||||
snapshotTarget,
|
||||
@@ -15,6 +16,32 @@ import { createEvidence } from "./evidence.js";
|
||||
import { createEvidenceBundle } from "./evidenceBundle.js";
|
||||
|
||||
describe("analysis snapshot contract", () => {
|
||||
it("accepts snapshots with more than ten thousand analysis entries", () => {
|
||||
const binding = snapshotBinding(ANALYSIS_SNAPSHOT_PROFILE);
|
||||
const entry = {
|
||||
query_id: `query_${"0".repeat(64)}`,
|
||||
operation: "analyze_function",
|
||||
parameters: {},
|
||||
execution: {
|
||||
result: null,
|
||||
raw_result: null,
|
||||
provider: binding.provider,
|
||||
limitations: [],
|
||||
locations: [],
|
||||
subject: null,
|
||||
},
|
||||
};
|
||||
|
||||
const parsed = analysisSnapshotSchema.parse({
|
||||
target: snapshotTarget(ANALYSIS_SNAPSHOT_TARGET),
|
||||
binding,
|
||||
entries: Array.from({ length: 10_001 }, () => entry),
|
||||
evidence_bundle: createEvidenceBundle([]),
|
||||
});
|
||||
|
||||
expect(parsed.entries).toHaveLength(10_001);
|
||||
});
|
||||
|
||||
it("finds only Evidence committed to the exact binding and profile", () => {
|
||||
const evidence = createEvidence(
|
||||
ANALYSIS_SNAPSHOT_TARGET,
|
||||
|
||||
@@ -103,7 +103,7 @@ const entrySchema = z.object({
|
||||
export const analysisSnapshotSchema = z.object({
|
||||
target: targetSchema,
|
||||
binding: bindingSchema,
|
||||
entries: z.array(entrySchema).max(10_000),
|
||||
entries: z.array(entrySchema),
|
||||
evidence_bundle: evidenceBundleSchema,
|
||||
});
|
||||
|
||||
|
||||
@@ -45,14 +45,6 @@ export const evidenceBundleSchema = z.object({
|
||||
|
||||
export type EvidenceBundle = z.infer<typeof evidenceBundleSchema>;
|
||||
|
||||
export interface EvidenceFilePolicy {
|
||||
readonly roots: readonly string[];
|
||||
readonly maxBytes: number;
|
||||
readonly maxDepth: number;
|
||||
readonly maxStringLength: number;
|
||||
readonly maxNodes: number;
|
||||
}
|
||||
|
||||
/** Project records into a deterministic bundle whose order has no semantics. */
|
||||
export const createEvidenceBundle = (
|
||||
records: readonly Evidence[],
|
||||
|
||||
@@ -131,7 +131,7 @@ describe("permission policy", () => {
|
||||
describe("permission policy lifecycle", () => {
|
||||
it("consumes once grants and applies revocation and ceiling reload immediately", () => {
|
||||
const ceiling = {
|
||||
capability: "evidence_write" as const,
|
||||
capability: "process_capture" as const,
|
||||
roots: ["/workspace/evidence"],
|
||||
executables: [],
|
||||
environment_names: [],
|
||||
@@ -180,7 +180,7 @@ describe("permission policy lifecycle", () => {
|
||||
|
||||
it("reports a missing scope when revoked grants cover a different root", () => {
|
||||
const ceiling = {
|
||||
capability: "evidence_write" as const,
|
||||
capability: "process_capture" as const,
|
||||
roots: ["/workspace"],
|
||||
executables: [],
|
||||
environment_names: [],
|
||||
|
||||
@@ -10,13 +10,8 @@ export const PERMISSION_CAPABILITIES = [
|
||||
"electron_observe",
|
||||
"electron_automate",
|
||||
"v8_inspector_observe",
|
||||
"evidence_read",
|
||||
"evidence_write",
|
||||
"snapshot_read",
|
||||
"snapshot_write",
|
||||
"artifact_extract",
|
||||
"native_mount",
|
||||
"reference_read",
|
||||
"javascript_replay",
|
||||
"managed_runtime",
|
||||
] as const;
|
||||
|
||||
@@ -5,13 +5,11 @@ import canonicalize from "canonicalize";
|
||||
import { z } from "zod";
|
||||
|
||||
import { compareUnicodeCodePoints } from "./unicodeCodePointOrder.js";
|
||||
const MAX_PATH = 4_096;
|
||||
const digestSchema = z.string().regex(/^[a-f0-9]{64}$/u);
|
||||
const boundedTextSchema = z.string().min(1).max(1_024);
|
||||
const boundedTextSchema = z.string().min(1);
|
||||
const relativePathSchema = z
|
||||
.string()
|
||||
.min(1)
|
||||
.max(MAX_PATH)
|
||||
.refine(
|
||||
(path) =>
|
||||
!path.startsWith("/") &&
|
||||
@@ -35,14 +33,14 @@ const classificationSchema = z.enum([
|
||||
|
||||
const entryBaseShape = {
|
||||
path: relativePathSchema,
|
||||
classifications: z.array(classificationSchema).min(1).max(8),
|
||||
limitations: z.array(boundedTextSchema).max(100),
|
||||
classifications: z.array(classificationSchema).min(1),
|
||||
limitations: z.array(boundedTextSchema),
|
||||
};
|
||||
|
||||
const sourceFileBaseShape = {
|
||||
...entryBaseShape,
|
||||
kind: z.literal("file"),
|
||||
language: z.string().min(1).max(100).nullable(),
|
||||
language: z.string().min(1).nullable(),
|
||||
};
|
||||
|
||||
const sourceFileSchema = z.union([
|
||||
@@ -60,7 +58,6 @@ const sourceFileSchema = z.union([
|
||||
"redacted-secret",
|
||||
"excluded",
|
||||
"unreadable",
|
||||
"too-large",
|
||||
"unknown",
|
||||
]),
|
||||
}),
|
||||
@@ -81,7 +78,6 @@ const sourceDirectorySchema = z.strictObject({
|
||||
const symlinkTargetSchema = z
|
||||
.string()
|
||||
.min(1)
|
||||
.max(MAX_PATH)
|
||||
.refine(
|
||||
(target) =>
|
||||
target === "<outside-root>" ||
|
||||
@@ -112,7 +108,7 @@ const sourceEntrySchema = z.union([
|
||||
|
||||
const sourceRelationshipSchema = z.strictObject({
|
||||
from_path: relativePathSchema,
|
||||
to: z.string().min(1).max(MAX_PATH),
|
||||
to: z.string().min(1),
|
||||
kind: z.enum(["imports", "requires", "references", "declares-module"]),
|
||||
resolution: z.enum(["internal", "external", "unresolved", "unknown"]),
|
||||
parse_state: z.enum(["parsed", "partial", "unknown"]),
|
||||
@@ -120,7 +116,7 @@ const sourceRelationshipSchema = z.strictObject({
|
||||
|
||||
const parseFailureSchema = z.strictObject({
|
||||
path: relativePathSchema,
|
||||
parser: z.string().min(1).max(100),
|
||||
parser: z.string().min(1),
|
||||
reason: boundedTextSchema,
|
||||
});
|
||||
|
||||
@@ -162,23 +158,22 @@ const graphShape = {
|
||||
root_alias: z.literal("$REFERENCE_ROOT"),
|
||||
root_sha256: digestSchema,
|
||||
inventory_state: z.enum(["complete", "partial", "unknown"]),
|
||||
entries: z.array(sourceEntrySchema).max(100_000),
|
||||
relationships: z.array(sourceRelationshipSchema).max(200_000),
|
||||
parse_failures: z.array(parseFailureSchema).max(10_000),
|
||||
exclusions: z.array(exclusionSchema).max(100_000),
|
||||
languages: z.array(z.string().min(1).max(100)).max(1_000),
|
||||
manifests: z.array(relativePathSchema).max(10_000),
|
||||
entries: z.array(sourceEntrySchema),
|
||||
relationships: z.array(sourceRelationshipSchema),
|
||||
parse_failures: z.array(parseFailureSchema),
|
||||
exclusions: z.array(exclusionSchema),
|
||||
languages: z.array(z.string().min(1)),
|
||||
manifests: z.array(relativePathSchema),
|
||||
vcs: vcsSchema,
|
||||
provenance: z.strictObject({
|
||||
importer: z.string().min(1).max(100),
|
||||
importer_version: z.string().min(1).max(100).nullable(),
|
||||
importer: z.string().min(1),
|
||||
importer_version: z.string().min(1).nullable(),
|
||||
caller: z
|
||||
.string()
|
||||
.min(1)
|
||||
.max(200)
|
||||
.regex(/^[\w .:@/+-]+$/u),
|
||||
}),
|
||||
limitations: z.array(boundedTextSchema).max(1_000),
|
||||
limitations: z.array(boundedTextSchema),
|
||||
};
|
||||
|
||||
const historicalSourceGraphStructureSchema = z
|
||||
@@ -209,8 +204,8 @@ const historicalSourceManifestBaseSchema = z.strictObject({
|
||||
graph_sha256: digestSchema,
|
||||
root_sha256: digestSchema,
|
||||
inventory_state: z.enum(["complete", "partial", "unknown"]),
|
||||
entry_count: z.number().int().min(0).max(100_000),
|
||||
relationship_count: z.number().int().min(0).max(200_000),
|
||||
entry_count: z.number().int().min(0).max(Number.MAX_SAFE_INTEGER),
|
||||
relationship_count: z.number().int().min(0).max(Number.MAX_SAFE_INTEGER),
|
||||
});
|
||||
|
||||
export type HistoricalSourceGraph = z.infer<typeof historicalSourceGraphSchema>;
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
/** Operator-approved roots, exclusions, and hard caps for source imports. */
|
||||
/** Exclusions and maximum traversal sizes for historical source imports. */
|
||||
export interface ReferenceSourcePolicy {
|
||||
readonly roots: readonly string[];
|
||||
readonly secretPatterns: readonly string[];
|
||||
readonly maxBytes: number;
|
||||
readonly maxEntries: number;
|
||||
readonly maxDepth: number;
|
||||
readonly maxPathBytes: number;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user