mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 19:53:50 +00:00
refactor(javascript): bind JavaScript source analysis in composition (#11467)
This commit is contained in:
1 parent
24406aa018
commit
64e6caeca2
22 files changed
+102
-34
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import { setImmediate } from "node:timers";
|
||||
import { mkdir, open, realpath, symlink, writeFile } from "node:fs/promises";
|
||||
import { javascriptSourceAnalysis } from "../../../src/composition/javascriptSourceAnalysis.js";
|
||||
import { basename, join } from "node:path";
|
||||
import { expect, it, onTestFinished, vi } from "vitest";
|
||||
import { z } from "zod";
|
||||
@@ -57,6 +58,7 @@ it.each(["worker-phase", "final-cleanup", "no-cancellation"] as const)(
|
||||
{ input_path: root, format: "directory" },
|
||||
scope,
|
||||
{
|
||||
sourceAnalysis: javascriptSourceAnalysis,
|
||||
signal: controller.signal,
|
||||
progress: {
|
||||
async report(event) {
|
||||
@@ -130,6 +132,7 @@ it("retains worker cleanup when progress reporting fails during analysis", async
|
||||
{ input_path: root, format: "directory" },
|
||||
scope,
|
||||
{
|
||||
sourceAnalysis: javascriptSourceAnalysis,
|
||||
progress: {
|
||||
async report(event) {
|
||||
if (
|
||||
@@ -185,7 +188,10 @@ it.each(["during cleanup", "on the next control turn"] as const)(
|
||||
const result = await analyzeOwnedApplication(
|
||||
{ input_path: selected, format: "directory" },
|
||||
scope,
|
||||
{ signal: controller.signal },
|
||||
{
|
||||
sourceAnalysis: javascriptSourceAnalysis,
|
||||
signal: controller.signal,
|
||||
},
|
||||
);
|
||||
if (result.ok) throw new Error("Cancelled handoff must not succeed");
|
||||
expect(result.error.cause).toBe(reason);
|
||||
@@ -598,6 +604,7 @@ it("keeps the exact retained descriptor owner through application failure transl
|
||||
const result = await analyzeOwnedApplication(
|
||||
{ input_path: root, format: "directory" },
|
||||
scope,
|
||||
{ sourceAnalysis: javascriptSourceAnalysis },
|
||||
);
|
||||
if (result.ok) throw new Error("Expected retained cleanup to block analysis");
|
||||
expect(result.error.cleanupIncomplete).toBe(true);
|
||||
|
||||
@@ -12,13 +12,7 @@ import { analyzeParsedJavaScriptStaticSource } from "../../fixtures/javascriptSt
|
||||
import { parseJavaScriptSource } from "../../../src/domain/javascript/javascriptSourceParser.js";
|
||||
import { ok, err } from "../../../src/domain/result.js";
|
||||
import { discoverJavaScriptPreloadPaths } from "../../../src/application/javascript/JavaScriptPreloadDiscovery.js";
|
||||
const acquire = vi.hoisted(() => vi.fn());
|
||||
vi.mock(
|
||||
"../../../src/artifacts/javascript/JavaScriptSourceAnalysis.js",
|
||||
() => ({
|
||||
createJavaScriptSourceAnalysis: acquire,
|
||||
}),
|
||||
);
|
||||
const acquire = vi.fn();
|
||||
const file = (
|
||||
path: string,
|
||||
text: string,
|
||||
@@ -82,6 +76,7 @@ it("resolves an exact preload before its declaring source regardless of inventor
|
||||
fixture(),
|
||||
limits,
|
||||
new ArtifactResourceScope(),
|
||||
acquire,
|
||||
);
|
||||
expect(result).toEqual({
|
||||
paths: new Set(["a".repeat(64) + ":preload.js"]),
|
||||
@@ -113,6 +108,7 @@ it("keeps discovering after one source exceeds its worker limit", async () => {
|
||||
{ ...files, files: [file("big.js", ""), ...files.files] },
|
||||
limits,
|
||||
new ArtifactResourceScope(),
|
||||
acquire,
|
||||
);
|
||||
// The gap stays reported even if source analysis later reads big.js.
|
||||
expect(result).toEqual({
|
||||
@@ -141,6 +137,7 @@ it("does not turn an invalid ESM require declaration into a preload identity", a
|
||||
{ ...files, files: [...files.files.slice(0, 2), source] },
|
||||
limits,
|
||||
new ArtifactResourceScope(),
|
||||
acquire,
|
||||
)
|
||||
).paths,
|
||||
).toEqual(new Set());
|
||||
@@ -160,6 +157,7 @@ it("does not transfer preload identity across containers", async () => {
|
||||
},
|
||||
limits,
|
||||
new ArtifactResourceScope(),
|
||||
acquire,
|
||||
)
|
||||
).paths,
|
||||
).toEqual(new Set());
|
||||
@@ -176,6 +174,7 @@ it("skips discovery when package scope cannot change a .js loader", async () =>
|
||||
},
|
||||
limits,
|
||||
new ArtifactResourceScope(),
|
||||
acquire,
|
||||
);
|
||||
expect(acquire).not.toHaveBeenCalled();
|
||||
});
|
||||
@@ -193,7 +192,13 @@ it("retains a failed close and the original cancellation until scope cleanup ret
|
||||
acquire.mockResolvedValue({ analyze: failingAnalyze, close });
|
||||
const scope = new ArtifactResourceScope();
|
||||
await expect(
|
||||
discoverJavaScriptPreloadPaths(fixture(), limits, scope, controller.signal),
|
||||
discoverJavaScriptPreloadPaths(
|
||||
fixture(),
|
||||
limits,
|
||||
scope,
|
||||
acquire,
|
||||
controller.signal,
|
||||
),
|
||||
).rejects.toMatchObject({
|
||||
cleanupIncomplete: true,
|
||||
cause: expect.objectContaining({
|
||||
|
||||
@@ -7,7 +7,7 @@ import { expect, it } from "vitest";
|
||||
import { withVerifierCleanup } from "../../../scripts/lib/verifier-cleanup.mjs";
|
||||
import { phaseGate } from "../../support/lifecycleHarness.js";
|
||||
import { JavaScriptAnalysisWorker } from "../../../src/javascript/analysis/JavaScriptAnalysisWorker.js";
|
||||
import { createJavaScriptSourceAnalysis } from "../../../src/artifacts/javascript/JavaScriptSourceAnalysis.js";
|
||||
import { createJavaScriptSourceAnalysis } from "../../../src/javascript/analysis/JavaScriptSourceAnalysis.js";
|
||||
import { ArtifactResourceScope } from "../../../src/resources/ArtifactResourceScope.js";
|
||||
import { cleanupOwnedProcessGroup } from "../../../src/process/ProcessOwnership.js";
|
||||
import { ProcessOwnershipEvidenceOwner } from "../../../src/process/ProcessOwnershipEvidence.js";
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { javascriptSourceAnalysis } from "../../../src/composition/javascriptSourceAnalysis.js";
|
||||
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
@@ -18,6 +19,7 @@ const analyzeFixture = async (source: string, addonPath = "addon.node") => {
|
||||
const result = await analyzeJavaScriptApplication(
|
||||
{ input_path: fixture, format: "directory" },
|
||||
scope,
|
||||
{ sourceAnalysis: javascriptSourceAnalysis },
|
||||
);
|
||||
if (!result.ok) throw result.error;
|
||||
return javascriptApplicationAnalysisResultSchema.parse(
|
||||
|
||||
Reference in new issue
Block a user