mirror of
https://github.com/morluto/rea.git
synced 2026-10-30 11:25:39 +00:00
The environment-state view now builds a write plan for every tool whose method may change state (create, update, delete or document, by the state type or document its path names) from its first successful recorded call: the request body members the application stored as sent, values it generated (identities, sequences, UUIDs, clock values in their recorded format), values derived from the call (copies, path values, slugs, strings around a generated id) and the recorded response's shape. It replays the capture's timeline on a copy of the initial state, applying each modelled write and checking every later read the served state would answer; a plan is served only when a later read confirms it and none contradicts it. Writes it does not model leave the entities and collections below their paths unknown until a read shows them again, and failures they may explain are checked only on the members a write sent. Unserved plans carry their reason. Served from the state, the catalog adds the confirmed write tools, described by their effect and body members. A call applies its effect atomically to the live store and answers with a recorded status and a rendered body; refused calls leave the state unchanged. Generated values are deterministic per state Evidence and write count, sequences never reuse a value, and the clock starts at the capture's end: data/reset and data/add restart them. Reads of an entity the state does not hold answer the recorded 400, 404 or 410, and a list line that only pages its collection and listed all of it answers calls without query arguments from the state. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
35 lines
1.3 KiB
TypeScript
35 lines
1.3 KiB
TypeScript
import type { AnalysisError } from "../../domain/analysisErrorBase.js";
|
|
import type { Result } from "../../domain/result.js";
|
|
import {
|
|
replayEnvironmentTool,
|
|
type ReplayArguments,
|
|
type ReplayResult,
|
|
} from "./environmentReplay.js";
|
|
import type {
|
|
EnvironmentManifestTool,
|
|
EnvironmentSource,
|
|
} from "./environmentSource.js";
|
|
import { answerFromState } from "./environmentStateAnswer.js";
|
|
import type { EnvironmentStateStore } from "./environmentStateStore.js";
|
|
import { answerWrite } from "./environmentStateWriteAnswer.js";
|
|
|
|
/** How a served environment answers one tool call. */
|
|
export type EnvironmentToolAnswer = (
|
|
tool: EnvironmentManifestTool,
|
|
args: ReplayArguments,
|
|
) => Result<ReplayResult, AnalysisError>;
|
|
|
|
/** The answer a served environment gives: replay without a state store; with one, a served write applies to the live state and a read answers from it. */
|
|
export const environmentToolAnswer = (
|
|
source: EnvironmentSource,
|
|
store: EnvironmentStateStore | undefined,
|
|
): EnvironmentToolAnswer =>
|
|
store === undefined
|
|
? (tool, args) => replayEnvironmentTool(source, tool, args)
|
|
: (tool, args) => {
|
|
const plan = store.state.writes.get(tool.name);
|
|
return plan?.served === true
|
|
? answerWrite({ source, store }, { tool, plan, args })
|
|
: answerFromState({ source, store }, tool, args);
|
|
};
|