Reuse checked bootstrap catalogs and coordinate execution deadlines
This commit is contained in:
@@ -19,12 +19,16 @@ import {
|
||||
expectedArtifactReceipt,
|
||||
checkExecutionInstallation,
|
||||
clientContractCatalog,
|
||||
createClientContractCatalog,
|
||||
CandidateMetadataBudget,
|
||||
compileKernelProgram,
|
||||
type ComponentArtifact,
|
||||
type PackageArtifacts,
|
||||
} from "../src/execution-world/index.js";
|
||||
import { validateWorkspaceRevision } from "../src/capability-model/index.js";
|
||||
import { presentationDeclarations, preparationArtifact } from "../src/react-build/declarations.js";
|
||||
import { compileQueryComposition } from "../src/query/composition.js";
|
||||
import type { InspectionKernel } from "../src/execution-world/inspection.js";
|
||||
|
||||
const source = { repository: "https://example.test/components.git", commit: "a".repeat(40) };
|
||||
const contract = (name: string) => {
|
||||
@@ -255,6 +259,56 @@ test("checked component-only artifacts install without a service and reject miss
|
||||
() => clientContractCatalog(plan, { ...installation, plan: "bad" }, [pkg.revision]),
|
||||
/CATALOG_PLAN_MISMATCH/,
|
||||
);
|
||||
const budget = new CandidateMetadataBudget();
|
||||
const scope = budget.acquire("catalog-test");
|
||||
const prepared = createClientContractCatalog(
|
||||
plan,
|
||||
installation,
|
||||
scope,
|
||||
compileKernelProgram(plan) as InspectionKernel,
|
||||
);
|
||||
try {
|
||||
assert.throws(() => prepared.select(["absent"]), /UNINSTALLED_PACKAGE/);
|
||||
assert.equal(scope.bytes, 0, "Unknown requests do not allocate compiler metadata");
|
||||
assert.deepEqual(prepared.select([pkg.revision]), catalog);
|
||||
const retained = scope.bytes;
|
||||
assert.ok(retained > 0);
|
||||
assert.ok(retained < 32 * 1024 * 1024, "Small catalogs retain a proportional metadata charge");
|
||||
const full = prepared.select([pkg.revision]);
|
||||
const empty = prepared.select([]);
|
||||
assert.deepEqual(empty.components, []);
|
||||
assert.deepEqual(empty.presentations, []);
|
||||
assert.deepEqual(empty.moduleBindings, []);
|
||||
assert.equal(empty.operations, full.operations, "Shared compiled metadata is reused");
|
||||
assert.equal(Object.isFrozen(full.operations), true);
|
||||
// Any plan access now would reveal a repeated digest/compile on the warm path.
|
||||
const definition = plan.definition;
|
||||
Object.defineProperty(plan, "definition", {
|
||||
configurable: true,
|
||||
get() {
|
||||
throw Error("RECOMPILED_PLAN");
|
||||
},
|
||||
});
|
||||
try {
|
||||
assert.deepEqual(prepared.select([pkg.revision]), full);
|
||||
assert.equal(scope.bytes, retained, "Package projections do not accumulate cache entries");
|
||||
} finally {
|
||||
Object.defineProperty(plan, "definition", { configurable: true, value: definition });
|
||||
}
|
||||
prepared.close();
|
||||
assert.equal(scope.bytes, 0);
|
||||
assert.throws(() => prepared.select([pkg.revision]), /CANDIDATE_METADATA_CLOSED/);
|
||||
} finally {
|
||||
prepared.close();
|
||||
scope.release();
|
||||
}
|
||||
const tight = new CandidateMetadataBudget({ bytes: 1000, ownerBytes: 1000, candidates: 1 });
|
||||
const tightScope = tight.acquire("catalog-test");
|
||||
const refused = createClientContractCatalog(plan, installation, tightScope);
|
||||
assert.throws(() => refused.select([pkg.revision]), /CANDIDATE_METADATA_LIMIT/);
|
||||
assert.equal(tightScope.bytes, 0);
|
||||
refused.close();
|
||||
tightScope.release();
|
||||
} finally {
|
||||
await rm(root, { recursive: true, force: true });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user