mirror of
https://github.com/morluto/rea
synced 2026-10-25 22:08:11 -04:00
test(environment): derive capacity fixtures from current contracts
This commit is contained in:
@@ -21,7 +21,7 @@ import {
|
||||
type EnvironmentBundleOptions,
|
||||
} from "./environmentBundle.js";
|
||||
import type { EnvironmentSource } from "./environmentSource.js";
|
||||
import { prepareServedState } from "./environmentState.js";
|
||||
import { prepareServedState, servedCatalog } from "./environmentState.js";
|
||||
import { environmentToolAnswer } from "./environmentToolAnswer.js";
|
||||
import { EnvironmentStateStore } from "./environmentStateStore.js";
|
||||
|
||||
@@ -388,21 +388,51 @@ describe("planEnvironmentBundle without a state", () => {
|
||||
});
|
||||
|
||||
it("serves and predicts replay when the state's catalog exceeds the discovery budget that replay's fits", () => {
|
||||
// Read tools only, so leaving out write tools saves nothing while each state description is longer.
|
||||
// 300 sits between the two catalogs on this fixture: replay still fits and the state catalog does not.
|
||||
// Locate the state admission boundary instead of pinning a count to description sizes.
|
||||
const reads = servedSource.manifest.tools.filter(
|
||||
({ method }) => method === "GET",
|
||||
);
|
||||
const tools = Array.from({ length: 300 }, (_, index) => {
|
||||
const tool = reads[index % reads.length]!;
|
||||
return index < reads.length
|
||||
? tool
|
||||
: { ...tool, name: `${tool.name}_${String(index)}` };
|
||||
});
|
||||
const source = {
|
||||
expect(reads.length).toBeGreaterThan(0);
|
||||
const sourceAt = (count: number): EnvironmentSource => ({
|
||||
...servedSource,
|
||||
manifest: { ...servedSource.manifest, tools },
|
||||
};
|
||||
manifest: {
|
||||
...servedSource.manifest,
|
||||
tools: Array.from({ length: count }, (_, index) => {
|
||||
const tool = reads[index % reads.length]!;
|
||||
return index < reads.length
|
||||
? tool
|
||||
: { ...tool, name: `${tool.name}_${String(index)}` };
|
||||
}),
|
||||
},
|
||||
});
|
||||
const stateFits = (count: number): boolean =>
|
||||
servedCatalog(
|
||||
sourceAt(count),
|
||||
{ writes: new Map() },
|
||||
servedSource.manifest.name,
|
||||
).ok;
|
||||
let fitting = 0;
|
||||
let exceeding = reads.length;
|
||||
// This fixture ceiling bounds setup if catalog admission stops refusing.
|
||||
const fixtureToolLimit = 4096;
|
||||
while (exceeding < fixtureToolLimit && stateFits(exceeding)) {
|
||||
fitting = exceeding;
|
||||
exceeding = Math.min(exceeding * 2, fixtureToolLimit);
|
||||
}
|
||||
expect(
|
||||
stateFits(exceeding),
|
||||
"State discovery must exceed its budget within the fixture safety ceiling",
|
||||
).toBe(false);
|
||||
while (exceeding - fitting > 1) {
|
||||
const middle = Math.floor((fitting + exceeding) / 2);
|
||||
if (stateFits(middle)) fitting = middle;
|
||||
else exceeding = middle;
|
||||
}
|
||||
const source = sourceAt(exceeding);
|
||||
expect(
|
||||
servedCatalog(source, undefined, source.manifest.name).ok,
|
||||
"The fixture must fit replay discovery while exceeding state discovery",
|
||||
).toBe(true);
|
||||
const prepared = prepareServedState(source, fixture.capture);
|
||||
expect(prepared.state).toBeUndefined();
|
||||
expect(prepared.report).toMatchObject({
|
||||
@@ -419,7 +449,7 @@ describe("planEnvironmentBundle without a state", () => {
|
||||
served: false,
|
||||
code: "resource_constraint",
|
||||
});
|
||||
expect(planned.value.toolCount).toBe(300);
|
||||
expect(planned.value.toolCount).toBe(source.manifest.tools.length);
|
||||
expect(planned.value.check).toEqual({
|
||||
tool: "get_annotations",
|
||||
recordOrdinal: 25,
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
selectReplayExchange,
|
||||
} from "./environmentReplay.js";
|
||||
|
||||
it("matches a late repeated query and a distant path coordinate without full tuple/segment arrays", () => {
|
||||
it("matches every repeated query occurrence and a distant path coordinate", () => {
|
||||
const source = environmentServeSourceWithBody("{}", "application/json");
|
||||
const original = source.manifest.tools.find(
|
||||
(tool) => tool.name === "get_users_by_id",
|
||||
@@ -22,12 +22,16 @@ it("matches a late repeated query and a distant path coordinate without full tup
|
||||
path: `/${"literal/".repeat(20000)}wanted`,
|
||||
query: `?${"q=miss&".repeat(20000)}q=hit`,
|
||||
};
|
||||
const exchanges = new Map([[ordinal, retained]]);
|
||||
const selected = selectReplayExchange(tool, exchanges, {
|
||||
id: "wanted",
|
||||
q: [...Array.from({ length: 20000 }, () => "miss"), "hit"],
|
||||
});
|
||||
expect(selected?.exchange).toBe(retained);
|
||||
expect(selected?.exact).toBe(true);
|
||||
expect(
|
||||
selectReplayExchange(tool, new Map([[ordinal, retained]]), {
|
||||
id: "wanted",
|
||||
q: "hit",
|
||||
}),
|
||||
).toEqual({ exchange: retained, exact: true });
|
||||
selectReplayExchange(tool, exchanges, { id: "wanted", q: "hit" })?.exact,
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("bounds content-type display without changing body interpretation or retained source", () => {
|
||||
|
||||
Reference in New Issue
Block a user