mirror of
https://github.com/morluto/rea.git
synced 2026-11-09 16:26:36 +00:00
fix(views): select every retained module path without losing identity
Use one retained-path owner for module references and items. Preserve selected paths and genuine ambiguity across module kinds; remove the superseded singular helper. Fixes #6790
This commit is contained in:
1 parent
9a3780229b
commit
f719dc46c5
4 files changed
+180
-20
No files matched your search
@@ -0,0 +1,85 @@
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { expect } from "vitest";
|
||||
|
||||
import { parseEvidence } from "../../../src/domain/evidence.js";
|
||||
import { analysisViewResultSchema } from "../../../src/domain/analysisView/analysisView.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { cliTest } from "../../support/cli/cliFixture.js";
|
||||
|
||||
cliTest(
|
||||
"selects each retained path of a content-deduplicated module",
|
||||
async ({ cli }) => {
|
||||
const root = await createTestTempDirectory("rea-js-module-alias-view-");
|
||||
const source = "export const answer = 42;\n";
|
||||
await Promise.all(
|
||||
["a.js", "b.js"].map((path) => writeFile(join(root, path), source)),
|
||||
);
|
||||
const analyzed = await cli.run({
|
||||
arguments: ["analyze-javascript-application", root, "--format", "json"],
|
||||
});
|
||||
expect(analyzed.exitCode, analyzed.stdout + analyzed.stderr).toBe(0);
|
||||
const evidence = parseEvidence(analyzed.json);
|
||||
const evidencePath = join(root, "evidence.json");
|
||||
await writeFile(evidencePath, JSON.stringify(evidence));
|
||||
const queryPath = join(root, "query.json");
|
||||
|
||||
const inspect = async (view: Record<string, unknown>) => {
|
||||
await writeFile(
|
||||
queryPath,
|
||||
JSON.stringify({
|
||||
source: { kind: "evidence-file", path: evidencePath },
|
||||
view,
|
||||
}),
|
||||
);
|
||||
const result = await cli.run({
|
||||
arguments: ["inspect-analysis-view", queryPath, "--json"],
|
||||
});
|
||||
expect(result.exitCode, result.stdout + result.stderr).toBe(0);
|
||||
return analysisViewResultSchema.parse(
|
||||
parseEvidence(result.json).normalized_result,
|
||||
);
|
||||
};
|
||||
|
||||
let sharedNodeId: string | undefined;
|
||||
for (const path of ["a.js", "b.js"]) {
|
||||
const references = await inspect({
|
||||
kind: "javascript",
|
||||
collection: "modules",
|
||||
projection: "references",
|
||||
where: { kind: "javascript-asset", path },
|
||||
});
|
||||
expect(references).toMatchObject({
|
||||
kind: "javascript",
|
||||
rows: [{ path }],
|
||||
coverage: { total: 1, examined: 1, exhausted: true },
|
||||
});
|
||||
if (references.kind !== "javascript")
|
||||
throw new Error("expected JavaScript module references");
|
||||
const nodeId = references.rows[0]?.node_id;
|
||||
expect(nodeId).toBeDefined();
|
||||
if (sharedNodeId === undefined) sharedNodeId = nodeId;
|
||||
else expect(nodeId).toBe(sharedNodeId);
|
||||
}
|
||||
const item = await inspect({
|
||||
kind: "item",
|
||||
collection: "modules",
|
||||
selector: { node_id: sharedNodeId },
|
||||
});
|
||||
expect(item).toMatchObject({
|
||||
kind: "item",
|
||||
item: {
|
||||
node_id: sharedNodeId,
|
||||
path: "a.js",
|
||||
observations: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
properties: expect.objectContaining({ path: "a.js" }),
|
||||
}),
|
||||
expect.objectContaining({
|
||||
properties: expect.objectContaining({ path: "b.js" }),
|
||||
}),
|
||||
]),
|
||||
},
|
||||
});
|
||||
},
|
||||
);
|
||||
Reference in new issue
Block a user