fix(contracts): preserve local inputs and comparison uncertainty
This commit is contained in:
@@ -4,13 +4,14 @@ import type { ToolContract } from "../toolContracts.js";
|
||||
import { managedOutputSchemas } from "../toolOutputSchemas.js";
|
||||
import { toolContractMetadata } from "../toolEffects.js";
|
||||
import { requireOutputSchema } from "../toolOutputSchemaPrimitives.js";
|
||||
import { isAbsoluteLocalPath } from "../../domain/localPath.js";
|
||||
import {
|
||||
isAbsoluteLocalPath,
|
||||
localPathStringSchema,
|
||||
} from "../../domain/localPath.js";
|
||||
|
||||
/** Exact caller boundary for execution-free PE/CLI triage and identity. */
|
||||
const managedTargetInputSchema = z.strictObject({
|
||||
path: z
|
||||
.string()
|
||||
.min(1)
|
||||
path: localPathStringSchema
|
||||
.refine(isAbsoluteLocalPath, {
|
||||
message:
|
||||
"path must be an absolute local filesystem path (for example /tmp/Example.dll or C:\\Example.dll)",
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
import type { ToolContract } from "../toolContracts.js";
|
||||
import { nativeOutputSchemas } from "../toolOutputSchemas.js";
|
||||
import { jsonValueSchema } from "../../domain/jsonValue.js";
|
||||
import { localPathStringSchema } from "../../domain/localPath.js";
|
||||
import { toolContractMetadata } from "../toolEffects.js";
|
||||
import { requireOutputSchema } from "../toolOutputSchemaPrimitives.js";
|
||||
|
||||
@@ -69,7 +70,8 @@ export const swiftSymbolsSchema = z
|
||||
z
|
||||
.string()
|
||||
.min(1)
|
||||
.regex(/^[^\n]*$/u, "Each Swift symbol must be one line."),
|
||||
.regex(/^[^\n]*$/u, "Each Swift symbol must be one line.")
|
||||
.regex(/^[^\0]*$/u, "Swift symbols cannot contain NUL."),
|
||||
)
|
||||
.min(1);
|
||||
|
||||
@@ -104,7 +106,7 @@ export const NATIVE_TOOL_CONTRACTS = [
|
||||
"inspect_plist",
|
||||
"Parse Info.plist from the active artifact by default, or pass any local plist path. Returns normalized JSON rather than plutil text.",
|
||||
z.object({
|
||||
path: z.string().min(1).optional(),
|
||||
path: localPathStringSchema.optional(),
|
||||
}),
|
||||
),
|
||||
native(
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import { executableFormatHintSchema } from "../domain/dosCom.js";
|
||||
import { isAbsoluteLocalPath } from "../domain/localPath.js";
|
||||
import {
|
||||
isAbsoluteLocalPath,
|
||||
localPathStringSchema,
|
||||
} from "../domain/localPath.js";
|
||||
import { z } from "zod";
|
||||
import { analysisProviderSelectorSchema } from "./providerSelection.js";
|
||||
|
||||
/** Caller-supplied analysis snapshot path; must name its destination absolutely. */
|
||||
const snapshotPathSchema = z
|
||||
.string()
|
||||
.min(1)
|
||||
const snapshotPathSchema = localPathStringSchema
|
||||
.refine(isAbsoluteLocalPath, {
|
||||
message:
|
||||
"snapshot_path must be an absolute local filesystem path (for example /tmp/rea/analysis.json or C:\\rea\\analysis.json)",
|
||||
@@ -16,9 +17,7 @@ const snapshotPathSchema = z
|
||||
);
|
||||
|
||||
/** Caller-supplied analysis target path; must name the target absolutely. */
|
||||
const binaryTargetPathSchema = z
|
||||
.string()
|
||||
.min(1)
|
||||
const binaryTargetPathSchema = localPathStringSchema
|
||||
.refine(isAbsoluteLocalPath, {
|
||||
message:
|
||||
"path must be an absolute local filesystem path (for example /tmp/fixture.bin or C:\\analysis\\fixture.bin)",
|
||||
|
||||
@@ -147,6 +147,29 @@ it.each(cases)("$name requires an absolute local path", (pathCase) => {
|
||||
expect(pathCase.omitted(), pathCase.name).toBe(true);
|
||||
});
|
||||
|
||||
it("preserves whitespace in selected browser and Electron filesystem names", () => {
|
||||
const executable = "/opt/browser with trailing space ";
|
||||
expect(
|
||||
browserScenarioBrowserSchema.parse({
|
||||
mode: "launch",
|
||||
executable_path: executable,
|
||||
}),
|
||||
).toMatchObject({ executable_path: executable });
|
||||
const application = "/tmp/application ";
|
||||
const root = "/tmp/application root ";
|
||||
expect(
|
||||
electronActiveObservationInputSchema.parse({
|
||||
executable_path: executable,
|
||||
application_path: application,
|
||||
application_root: root,
|
||||
}),
|
||||
).toMatchObject({
|
||||
executable_path: executable,
|
||||
application_path: application,
|
||||
application_root: root,
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps evidence bundle export overwrite disabled by default", () => {
|
||||
expect(
|
||||
exportEvidenceBundleInputSchema.safeParse({ path: "/tmp/bundle.json" }),
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { isAbsoluteLocalPath } from "../domain/localPath.js";
|
||||
import {
|
||||
isAbsoluteLocalPath,
|
||||
localPathStringSchema,
|
||||
} from "../domain/localPath.js";
|
||||
|
||||
/** Optional expectations used to compare the live session with its caller. */
|
||||
export const binarySessionInputSchema = z.strictObject({
|
||||
@@ -9,9 +12,7 @@ export const binarySessionInputSchema = z.strictObject({
|
||||
.string()
|
||||
.regex(/^[a-f0-9]{64}$/u)
|
||||
.optional(),
|
||||
expected_server_path: z
|
||||
.string()
|
||||
.min(1)
|
||||
expected_server_path: localPathStringSchema
|
||||
.refine(isAbsoluteLocalPath, {
|
||||
message:
|
||||
"expected_server_path must be an absolute local filesystem path (for example /opt/rea/dist/main.js)",
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { isAbsoluteLocalPath } from "../domain/localPath.js";
|
||||
import {
|
||||
isAbsoluteLocalPath,
|
||||
localPathStringSchema,
|
||||
} from "../domain/localPath.js";
|
||||
import {
|
||||
sessionOutputSchemas,
|
||||
requireOutputSchema,
|
||||
@@ -31,7 +34,10 @@ import { examplesFor } from "./toolContractHelpers.js";
|
||||
import type { ToolContract } from "./toolContractTypes.js";
|
||||
import { toolContractMetadata } from "./toolEffects.js";
|
||||
|
||||
const session = <Name extends string, Schema extends z.ZodObject>(
|
||||
const session = <
|
||||
Name extends keyof typeof sessionOutputSchemas,
|
||||
Schema extends z.ZodObject,
|
||||
>(
|
||||
name: Name,
|
||||
description: string,
|
||||
inputSchema: Schema,
|
||||
@@ -48,9 +54,7 @@ const session = <Name extends string, Schema extends z.ZodObject>(
|
||||
|
||||
/** Session-owned Evidence bundle export options. */
|
||||
export const exportEvidenceBundleInputSchema = z.strictObject({
|
||||
path: z
|
||||
.string()
|
||||
.min(1)
|
||||
path: localPathStringSchema
|
||||
.refine(isAbsoluteLocalPath, {
|
||||
message:
|
||||
"path must be an absolute local filesystem path (for example /tmp/rea/evidence.json or C:\\rea\\evidence.json)",
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { isAbsoluteLocalPath } from "../domain/localPath.js";
|
||||
import {
|
||||
isAbsoluteLocalPath,
|
||||
localPathStringSchema,
|
||||
} from "../domain/localPath.js";
|
||||
|
||||
import { artifactComparisonInputSchema } from "../domain/artifactComparison.js";
|
||||
import { bundleComparisonInputSchema } from "../domain/bundleComparison.js";
|
||||
import { callPathInputSchema } from "../domain/callPath.js";
|
||||
import { changedBehaviorInputSchema } from "../domain/changedBehavior.js";
|
||||
import { functionComparisonInputSchema } from "../domain/functionComparison.js";
|
||||
import { jsonValueSchema } from "../domain/jsonValue.js";
|
||||
import { processScenarioSchema } from "../domain/process/processCapture.js";
|
||||
import { processTraceSpecificationSchema } from "../domain/process/processTraceComparison.js";
|
||||
import { recordUnknownInputSchema } from "../domain/residualUnknown.js";
|
||||
@@ -38,9 +40,7 @@ export const addressContextInputSchema = z.strictObject({
|
||||
|
||||
/** Session-owned Evidence bundle import options. */
|
||||
export const importEvidenceBundleInputSchema = z.strictObject({
|
||||
path: z
|
||||
.string()
|
||||
.min(1)
|
||||
path: localPathStringSchema
|
||||
.refine(isAbsoluteLocalPath, {
|
||||
message:
|
||||
"path must be an absolute local filesystem path (for example /tmp/evidence.json or C:\\rea\\evidence.json)",
|
||||
|
||||
@@ -373,7 +373,7 @@ export const managedWorkflowOutputSchemas: Readonly<
|
||||
};
|
||||
|
||||
/** Exact structured-content schemas for target lifecycle operations. */
|
||||
export const sessionOutputSchemas: Readonly<Record<string, z.ZodObject>> = {
|
||||
export const sessionOutputSchemas = {
|
||||
open_binary: lifecycleResultOf(
|
||||
z.object({
|
||||
path: z.string(),
|
||||
@@ -469,4 +469,4 @@ export const sessionOutputSchemas: Readonly<Record<string, z.ZodObject>> = {
|
||||
unknown: residualUnknownSchema,
|
||||
}),
|
||||
),
|
||||
};
|
||||
} satisfies Readonly<Record<string, z.ZodObject>>;
|
||||
|
||||
@@ -25,7 +25,8 @@ import { prefixedDigestSchema } from "./../domain/digests.js";
|
||||
/** Inline result with its complete Evidence record. */
|
||||
export const inlineEvidenceRecordSchema = evidenceEnvelopeSchema;
|
||||
|
||||
export const evidenceResultOf = (schema: z.ZodType) =>
|
||||
/** Wrap a result and its Evidence while preserving the result schema type. */
|
||||
export const evidenceResultOf = <Schema extends z.ZodType>(schema: Schema) =>
|
||||
z.strictObject({
|
||||
result: schema,
|
||||
evidence_id: prefixedDigestSchema("ev"),
|
||||
@@ -33,14 +34,18 @@ export const evidenceResultOf = (schema: z.ZodType) =>
|
||||
});
|
||||
|
||||
const resultOf = evidenceResultOf;
|
||||
export const lifecycleResultOf = (schema: z.ZodType) =>
|
||||
/** Wrap a lifecycle result while preserving its exact schema type. */
|
||||
export const lifecycleResultOf = <Schema extends z.ZodType>(schema: Schema) =>
|
||||
z.object({ result: schema });
|
||||
|
||||
/** Resolve a required named output schema or reject contract drift. */
|
||||
export const requireOutputSchema = (
|
||||
schemas: Readonly<Record<string, z.ZodObject>>,
|
||||
name: string,
|
||||
): z.ZodObject => {
|
||||
export const requireOutputSchema = <
|
||||
Schemas extends Readonly<Record<string, z.ZodObject>>,
|
||||
Name extends keyof Schemas & string,
|
||||
>(
|
||||
schemas: Schemas,
|
||||
name: Name,
|
||||
): Schemas[Name] => {
|
||||
const schema = schemas[name];
|
||||
if (schema === undefined)
|
||||
throw new Error(`Missing output schema for ${name}`);
|
||||
|
||||
Reference in New Issue
Block a user