mirror of
https://github.com/morluto/rea.git
synced 2026-10-22 13:52:32 -05:00
* refactor(test): colocate pure-domain tests and reduce test debt Move focused immutable domain/contracts/adapter tests from tests/composition/** beside their production owners under src/** as colocated *.test.ts/*.fixture.ts, and relocate persistence-shaped composition tests under tests/boundary/filesystem/**. Update import paths, the Vitest project topology (shared worker context for pure domain/contracts and recording-port service projects), the test migration ledger, testing docs, and AGENTS.md to match. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * docs: remove test migration ledger The cutover is complete and the ledger is no longer referenced anywhere in source, scripts, or the docs gate. Drop the standalone artifact. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * docs: clean up stale migration artifacts Remove empty directories left by the test migration and replace the "final cutover" language in docs/testing.md with standing PR guidance that no longer references the completed migration. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix: repair CI failures from schema, knip, and stale generated artifacts Three root causes fixed: 1. catalog-schemas.mjs: valuesAt only traversed anyOf from Zod's toJSONSchema, not oneOf. The webScreenshotDiffSchema change to a discriminated union produces oneOf, so the product catalog generator could not derive the web_screenshot_diff schema version. Add oneOf traversal. 2. conformancePackage.ts: the test rewrite removed the only imports of ScenarioManifest, ReplayPlan, ShimPlan, and ExpectedEvidence, making them unused exports that knip flags. Remove the dead type aliases. 3. Regenerate stale artifacts (product catalog, MCP tool catalog, skill metadata, conformance manifest) that drifted from the source changes. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> --------- Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
255 lines
8.4 KiB
TypeScript
255 lines
8.4 KiB
TypeScript
import { mkdir, writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
|
|
import { reconstructJavaScriptArtifact } from "../../../src/application/JavaScriptArtifactReconstruction.js";
|
|
import type {
|
|
ApplicationEdge,
|
|
ApplicationNode,
|
|
JavaScriptApplicationGraph,
|
|
} from "../../../src/domain/javascriptApplicationGraph.js";
|
|
|
|
describe("Webpack and Rspack runtime adapters", () => {
|
|
it("recovers runtime entry modules, async chunks, and factory require aliases", async () => {
|
|
const root = await bundlerFixture();
|
|
const result = await reconstructJavaScriptArtifact({ input_path: root });
|
|
const graph = result.graph;
|
|
|
|
const webpackEntry = chunk(graph, "webpackChunkcustomPortal", "main");
|
|
const webpackLazy = chunk(graph, "webpackChunkcustomPortal", "lazy");
|
|
const webpackModule = moduleNode(graph, "10");
|
|
const rspackEntry = chunk(graph, "rspackChunkcustomPortal", "editor");
|
|
const rspackModel = chunk(graph, "rspackChunkcustomPortal", "model");
|
|
const rspackModule = moduleNode(graph, "src/entry.ts");
|
|
|
|
expect(webpackEntry?.observations[0]?.properties).toMatchObject({
|
|
bundler: "webpack",
|
|
runtime_require_name: "__webpack_require__",
|
|
runtime_module_cache_status: "observed",
|
|
entry_module_keys: ["10"],
|
|
async_chunk_keys: ["lazy", "missing"],
|
|
unknown_async_chunk_keys: 1,
|
|
});
|
|
expect(webpackModule?.observations[0]?.properties).toMatchObject({
|
|
factory_require_name: "__webpack_require__",
|
|
runtime_entry: true,
|
|
chunk_keys: ["main"],
|
|
});
|
|
expect(rspackEntry?.observations[0]?.properties).toMatchObject({
|
|
bundler: "rspack",
|
|
runtime_require_name: "r",
|
|
entry_module_keys: ["src/entry.ts"],
|
|
async_chunk_keys: ["model"],
|
|
});
|
|
expect(rspackModule?.observations[0]?.properties).toMatchObject({
|
|
factory_require_name: "r",
|
|
runtime_entry: true,
|
|
});
|
|
|
|
expect(edge(graph, webpackEntry, webpackModule, "loads")).toMatchObject({
|
|
properties: expect.objectContaining({
|
|
kind: "bundler-entry-module",
|
|
resolution_status: "resolved",
|
|
}),
|
|
});
|
|
expect(edge(graph, webpackEntry, webpackLazy, "imports")).toMatchObject({
|
|
properties: expect.objectContaining({
|
|
kind: "bundler-async-chunk",
|
|
resolution_status: "resolved",
|
|
}),
|
|
});
|
|
expect(edge(graph, webpackModule, webpackLazy, "imports")).toMatchObject({
|
|
properties: expect.objectContaining({
|
|
kind: "dynamic-import",
|
|
specifier: "chunk:lazy",
|
|
resolved_path: "renderer/chunks/runtime.js#chunk:lazy",
|
|
}),
|
|
});
|
|
expect(edge(graph, rspackEntry, rspackModel, "imports")).toMatchObject({
|
|
properties: expect.objectContaining({
|
|
kind: "bundler-async-chunk",
|
|
resolution_status: "resolved",
|
|
}),
|
|
});
|
|
expect(edge(graph, rspackModule, rspackModel, "imports")).toMatchObject({
|
|
properties: expect.objectContaining({
|
|
kind: "dynamic-import",
|
|
specifier: "chunk:model",
|
|
}),
|
|
});
|
|
|
|
expect(
|
|
graph.nodes.find((node) =>
|
|
node.observations.some(
|
|
({ properties }) =>
|
|
properties.semantic_role === "bundler-chunk-reference" &&
|
|
properties.chunk_key === "missing" &&
|
|
properties.resolution_status === "not-found",
|
|
),
|
|
),
|
|
).toBeDefined();
|
|
expect(
|
|
graph.edges.some(
|
|
({ relation, properties }) =>
|
|
relation === "imports" &&
|
|
properties.kind === "require" &&
|
|
properties.specifier === "lazy",
|
|
),
|
|
).toBe(false);
|
|
});
|
|
|
|
it("recovers esbuild wrapper modules and Vite preload dependencies", async () => {
|
|
const root = await esmRuntimeFixture();
|
|
const { graph } = await reconstructJavaScriptArtifact({
|
|
input_path: root,
|
|
});
|
|
const commonJsModule = moduleNode(graph, "src/dep.js");
|
|
const esmModule = moduleNode(graph, "src/core.js");
|
|
|
|
expect(commonJsModule?.observations[0]?.properties).toMatchObject({
|
|
bundler: "esbuild",
|
|
runtime: "esbuild-commonjs",
|
|
module_key: "src/dep.js",
|
|
});
|
|
expect(esmModule?.observations[0]?.properties).toMatchObject({
|
|
bundler: "esbuild",
|
|
runtime: "esbuild-esm",
|
|
module_key: "src/core.js",
|
|
});
|
|
expect(
|
|
graph.edges.filter(
|
|
({ relation, properties }) =>
|
|
relation === "imports" &&
|
|
properties.kind === "dynamic-import" &&
|
|
["./feature.js", "./main.css"].includes(String(properties.specifier)),
|
|
),
|
|
).toHaveLength(2);
|
|
});
|
|
});
|
|
|
|
const bundlerFixture = async (): Promise<string> => {
|
|
const root = await createTestTempDirectory("rea-bundler-adapters-");
|
|
await mkdir(join(root, "renderer", "chunks"), { recursive: true });
|
|
await writeFile(
|
|
join(root, "renderer", "chunks", "runtime.js"),
|
|
`
|
|
var __webpack_module_cache__ = {};
|
|
(globalThis["webpackChunkcustomPortal"] = globalThis["webpackChunkcustomPortal"] || []).push([
|
|
["main"],
|
|
{
|
|
10: (module, exports, __webpack_require__) => {
|
|
const direct = __webpack_require__(11);
|
|
const lazy = __webpack_require__.e("lazy").then(
|
|
__webpack_require__.bind(__webpack_require__, 20)
|
|
);
|
|
const missing = __webpack_require__.e("missing");
|
|
const dynamicChunk = window.name;
|
|
__webpack_require__.e(dynamicChunk);
|
|
exports.start = () => [direct, lazy, missing];
|
|
},
|
|
11: (module) => { module.exports = "direct"; }
|
|
},
|
|
(__webpack_require__) => {
|
|
__webpack_require__.O(0, ["main"], () => __webpack_require__(10));
|
|
}
|
|
]);
|
|
(globalThis["webpackChunkcustomPortal"] = globalThis["webpackChunkcustomPortal"] || []).push([
|
|
["lazy"],
|
|
{
|
|
20: (module) => { module.exports = "lazy"; }
|
|
}
|
|
]);
|
|
(self.rspackChunkcustomPortal = self.rspackChunkcustomPortal || []).push([
|
|
["editor"],
|
|
{
|
|
"src/entry.ts": (module, exports, r) => {
|
|
r.e("model").then(r.bind(r, "src/model.ts"));
|
|
exports.render = () => r("src/model.ts");
|
|
}
|
|
},
|
|
(r) => { r("src/entry.ts"); }
|
|
]);
|
|
(self.rspackChunkcustomPortal = self.rspackChunkcustomPortal || []).push([
|
|
["model"],
|
|
{
|
|
"src/model.ts": (module) => { module.exports = "model"; }
|
|
}
|
|
]);
|
|
`,
|
|
);
|
|
return root;
|
|
};
|
|
|
|
const esmRuntimeFixture = async (): Promise<string> => {
|
|
const root = await createTestTempDirectory("rea-esm-runtime-adapters-");
|
|
await writeFile(
|
|
join(root, "main.js"),
|
|
`
|
|
const __vite__mapDeps = (indexes, map = __vite__mapDeps, dependencies =
|
|
(map.f || (map.f = ["./feature.js", "./main.css"]))) =>
|
|
indexes.map((index) => dependencies[index]);
|
|
const require_dep = __commonJS({
|
|
"src/dep.js"(exports, module) {
|
|
module.exports = { value: 1 };
|
|
}
|
|
});
|
|
const init_core = __esm({
|
|
"src/core.js"() {
|
|
require_dep();
|
|
}
|
|
});
|
|
__vite__mapDeps([0, 1]);
|
|
init_core();
|
|
`,
|
|
);
|
|
await writeFile(join(root, "feature.js"), "export const feature = true;");
|
|
await writeFile(join(root, "main.css"), ".app { color: green; }");
|
|
return root;
|
|
};
|
|
|
|
const chunk = (
|
|
graph: JavaScriptApplicationGraph,
|
|
runtime: string,
|
|
chunkKey: string,
|
|
): ApplicationNode | undefined =>
|
|
graph.nodes.find(
|
|
({ kind, observations }) =>
|
|
kind === "javascript-chunk" &&
|
|
observations.some(
|
|
({ properties }) =>
|
|
properties.runtime === runtime &&
|
|
Array.isArray(properties.chunk_keys) &&
|
|
properties.chunk_keys.includes(chunkKey),
|
|
),
|
|
);
|
|
|
|
const moduleNode = (
|
|
graph: JavaScriptApplicationGraph,
|
|
moduleKey: string,
|
|
): ApplicationNode | undefined =>
|
|
graph.nodes.find(
|
|
({ kind, observations }) =>
|
|
kind === "javascript-module" &&
|
|
observations.some(
|
|
({ properties }) => properties.module_key === moduleKey,
|
|
),
|
|
);
|
|
|
|
const edge = (
|
|
graph: JavaScriptApplicationGraph,
|
|
source: ApplicationNode | undefined,
|
|
target: ApplicationNode | undefined,
|
|
relation: string,
|
|
): ApplicationEdge | undefined =>
|
|
graph.edges.find(
|
|
({ source_node_id, target_node_id, relation: edgeRelation }) =>
|
|
source !== undefined &&
|
|
target !== undefined &&
|
|
source_node_id === source.node_id &&
|
|
target_node_id === target.node_id &&
|
|
edgeRelation === relation,
|
|
);
|