Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 11 additions & 18 deletions src/domain/analysisView/EnvironmentManifestAccumulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import {
} from "./recordedResponseBody.js";
import { readRecordedRequestBody } from "./recordedExchangeBody.js";
import { isJson, isJsonLike, mediaTypeEssence } from "./recordedMediaType.js";
import type { UnsignedAnalysisView } from "./analysisView.js";
import { z } from "zod";
import { environmentManifestFields } from "./environmentManifestSchema.js";
import type { ScenarioResponseBodyRetention } from "./scenarioCaptureRecords.js";
import { WebNetworkProjectionAccumulator } from "./WebNetworkProjectionAccumulator.js";
import {
Expand Down Expand Up @@ -55,21 +56,13 @@ import {
type RouteTemplate,
} from "./webNetworkRouteTemplates.js";

type Manifest = Extract<UnsignedAnalysisView, { kind: "environment-manifest" }>;
type ManifestFields = Pick<
Manifest,
| "origin"
| "name"
| "tools"
| "records"
| "excluded"
| "unknowns"
| "templated_groups"
| "coverage"
| "limitations"
>;
type Tool = Manifest["tools"][number];
type Exclusion = Manifest["excluded"][number];
type ManifestCore = {
[Key in keyof typeof environmentManifestFields]: z.output<
(typeof environmentManifestFields)[Key]
>;
};
type Tool = ManifestCore["tools"][number];
type Exclusion = ManifestCore["excluded"][number];
type RequestLine = Extract<RecordedRequestLine, { kind: "line" }>;

interface RecordLine {
Expand Down Expand Up @@ -134,7 +127,7 @@ const WRITE_METHODS = new Set(["POST", "PUT", "PATCH"]);
const BODILESS_WRITE_METHODS = new Set([...WRITE_METHODS, "DELETE"]);
/** Quotes, separators and brackets a four-part composite key adds around its texts. */
const KEY_OVERHEAD_CHARS = 32;
const UNKNOWNS: Manifest["unknowns"] = [
const UNKNOWNS: ManifestCore["unknowns"] = [
{
kind: "authorization-model",
statement:
Expand Down Expand Up @@ -477,7 +470,7 @@ export class EnvironmentManifestAccumulator extends WebNetworkProjectionAccumula
}

/** Project the complete manifest; tools, records and exclusions are sorted deterministically. */
finish(): Result<ManifestFields, AnalysisError> {
finish() {
const primary = primaryOrigin(this.#origins);
const toolGroups: GroupState[] = [];
const exclusions = new Map<string, Exclusion & { templated: boolean }>();
Expand Down
28 changes: 5 additions & 23 deletions src/domain/analysisView/EnvironmentStateAccumulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
WEB_NETWORK_CAPTURE_LIMITS,
type WebNetworkCaptureRecord,
} from "../webNetworkCapture.js";
import type { UnsignedAnalysisView } from "./analysisView.js";
import { EnvironmentManifestAccumulator } from "./EnvironmentManifestAccumulator.js";
import { isJsonLike, mediaTypeEssence } from "./recordedMediaType.js";
import { readRecordedRequestBody } from "./recordedExchangeBody.js";
Expand Down Expand Up @@ -40,23 +39,6 @@ import {
textBytes,
} from "./webNetworkRouteTemplates.js";

type StateView = Extract<UnsignedAnalysisView, { kind: "environment-state" }>;
type StateFields = Pick<
StateView,
| "origin"
| "name"
| "timeline"
| "types"
| "entities"
| "documents"
| "views"
| "writes"
| "write_clock"
| "unknowns"
| "coverage"
| "limitations"
>;

/**
* Levels the state's own nesting adds above a recorded value: Evidence, a `data/get` reply and a
* JSON-RPC response hold a body's members about ten levels down, so a body must leave this much
Expand Down Expand Up @@ -102,19 +84,19 @@ interface RecordEntry {
readonly record: WebNetworkCaptureRecord;
}

const UNKNOWNS: StateView["unknowns"] = [
const UNKNOWNS = [
{
kind: "authorization-model",
kind: "authorization-model" as const,
statement:
"Authorization headers and cookies are structurally excluded from captures; the state states no authorization model.",
},
{
kind: "response-semantics",
kind: "response-semantics" as const,
statement:
"Views reproduce their recorded responses from the state; they do not establish how the application computes responses, derived values or values copied outside entity objects.",
},
{
kind: "state-transition",
kind: "state-transition" as const,
statement:
"The state is one snapshot from before the first related recorded write; write effects are modelled only from the calls the capture recorded, and served only where its later reads confirmed them.",
},
Expand Down Expand Up @@ -340,7 +322,7 @@ export class EnvironmentStateAccumulator extends EnvironmentManifestAccumulator
}

/** Project the init state of the manifest's primary origin; records keep timeline order. */
finishState(): Result<StateFields, AnalysisError> {
finishState() {
const manifest = this.finish();
if (!manifest.ok) return manifest;
const entries = [...this.#entries.values()].filter(
Expand Down
26 changes: 10 additions & 16 deletions src/domain/analysisView/WebNetworkApiSurfaceAccumulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
type WebNetworkCaptureRecord,
} from "../webNetworkCapture.js";
import { pageViewCoverage } from "./analysisViewCoverage.js";
import type { UnsignedAnalysisView } from "./analysisView.js";
import { z } from "zod";
import { apiSurfaceFields } from "./apiSurfaceSchema.js";
import { WebNetworkProjectionAccumulator } from "./WebNetworkProjectionAccumulator.js";
import {
CAPTURE_CONTAINER_BYTES,
Expand All @@ -23,9 +24,13 @@ import {
type RouteTemplate,
} from "./webNetworkRouteTemplates.js";

type Surface = Extract<UnsignedAnalysisView, { kind: "api-surface" }>;
type Group = Surface["groups"][number];
type Exclusion = Surface["excluded_records"][number];
type ApiSurfaceFields = {
[Key in keyof typeof apiSurfaceFields]: z.output<
(typeof apiSurfaceFields)[Key]
>;
};
type Group = ApiSurfaceFields["groups"][number];
type Exclusion = ApiSurfaceFields["excluded_records"][number];
interface GroupState {
readonly method: string;
readonly origin: string;
Expand Down Expand Up @@ -181,18 +186,7 @@ export class WebNetworkApiSurfaceAccumulator extends WebNetworkProjectionAccumul
return ok(undefined);
}

page(
offset: number,
limit: number,
): Pick<
Surface,
| "coverage"
| "groups"
| "templated_groups"
| "excluded_records"
| "limitations"
| "unknowns"
> {
page(offset: number, limit: number) {
this.#groups.sort(
(a, b) =>
compare(a.origin, b.origin) ||
Expand Down
2 changes: 1 addition & 1 deletion src/domain/analysisView/WebNetworkProjectionAccumulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import { admitAnalysisViewData } from "./analysisViewDataAdmission.js";
import { analysisViewInputError } from "./analysisViewErrors.js";
import { analysisViewResultInputError } from "./analysisViewParent.js";
import type { AnalysisViewParent } from "./analysisView.js";
import type { AnalysisViewParent } from "./analysisViewParent.js";
import {
ENTRY_BYTES,
textBytes,
Expand Down
Loading
Loading