test(javascript): share primitive expansion producer fixtures
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { primitiveByteExpansionSource } from "../../../tests/fixtures/javascriptPrimitiveExpansion.js";
|
||||
import * as t from "@babel/types";
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
@@ -111,15 +112,7 @@ it("preserves primitive candidate budget unknowns in semantic graph coverage", (
|
||||
});
|
||||
|
||||
it("preserves derived string-byte limit reasons in semantic graph unknowns", () => {
|
||||
const declarations = ['const value0 = "x";'];
|
||||
for (let index = 1; index <= 30; index += 1) {
|
||||
const previous = `value${String(index - 1)}`;
|
||||
declarations.push(
|
||||
`const value${String(index)} = ${previous} + ${previous};`,
|
||||
);
|
||||
}
|
||||
declarations.push("const answer = value30;");
|
||||
const source = declarations.join("\n");
|
||||
const source = primitiveByteExpansionSource();
|
||||
const ir = analyzeJavaScriptSemantics(source);
|
||||
const graph = graphFor(source, ir);
|
||||
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
import {
|
||||
primitiveCandidateExpansionSource,
|
||||
primitiveByteExpansionSource,
|
||||
} from "../../fixtures/javascriptPrimitiveExpansion.js";
|
||||
import { createHash } from "node:crypto";
|
||||
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
@@ -102,21 +106,9 @@ it("keeps a contradicted nested ASAR opaque during JavaScript reconstruction", a
|
||||
});
|
||||
|
||||
it("retains semantic resource limits alongside recorded integrity contradictions", async () => {
|
||||
const expression = Array.from(
|
||||
{ length: 20 },
|
||||
() => '(true ? "a" : "b")',
|
||||
).join(" + ");
|
||||
const declarations = ['const value0 = "x";'];
|
||||
for (let index = 1; index <= 30; index += 1) {
|
||||
const previous = `value${String(index - 1)}`;
|
||||
declarations.push(
|
||||
`const value${String(index)} = ${previous} + ${previous};`,
|
||||
);
|
||||
}
|
||||
declarations.push("const answer = value30;");
|
||||
const { archive } = await createStrippedAsarAddon([
|
||||
{ path: "app.js", contents: `const answer = { nested: ${expression} };` },
|
||||
{ path: "growth.js", contents: declarations.join("\n") },
|
||||
{ path: "app.js", contents: primitiveCandidateExpansionSource() },
|
||||
{ path: "growth.js", contents: primitiveByteExpansionSource() },
|
||||
]);
|
||||
const analyzed = await analyzeJavaScriptApplication({
|
||||
input_path: archive,
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
import {
|
||||
primitiveCandidateExpansionSource,
|
||||
primitiveByteExpansionSource,
|
||||
} from "../../fixtures/javascriptPrimitiveExpansion.js";
|
||||
import { createHash } from "node:crypto";
|
||||
import { mkdir, rm, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
@@ -102,23 +106,8 @@ it("preserves graph commitments and export shapes when consuming file-local IR",
|
||||
|
||||
it("reports semantic value resource limits in application graph coverage", async () => {
|
||||
const root = await createTestTempDirectory("rea-javascript-semantic-limit-");
|
||||
const expression = Array.from(
|
||||
{ length: 20 },
|
||||
() => '(true ? "a" : "b")',
|
||||
).join(" + ");
|
||||
await writeFile(
|
||||
join(root, "app.js"),
|
||||
`const answer = { nested: ${expression} };`,
|
||||
);
|
||||
const declarations = ['const value0 = "x";'];
|
||||
for (let index = 1; index <= 30; index += 1) {
|
||||
const previous = `value${String(index - 1)}`;
|
||||
declarations.push(
|
||||
`const value${String(index)} = ${previous} + ${previous};`,
|
||||
);
|
||||
}
|
||||
declarations.push("const answer = value30;");
|
||||
await writeFile(join(root, "growth.js"), declarations.join("\n"));
|
||||
await writeFile(join(root, "app.js"), primitiveCandidateExpansionSource());
|
||||
await writeFile(join(root, "growth.js"), primitiveByteExpansionSource());
|
||||
const snapshot = await scanCanonicalArtifactInventory(root, {});
|
||||
const reader = createJavaScriptArtifactReader(root, "directory");
|
||||
try {
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
/** Source whose concatenated alternatives exceed primitive candidate storage. */
|
||||
export const primitiveCandidateExpansionSource = (): string => {
|
||||
const expression = Array.from(
|
||||
{ length: 20 },
|
||||
() => '(true ? "a" : "b")',
|
||||
).join(" + ");
|
||||
return `const answer = { nested: ${expression} };`;
|
||||
};
|
||||
|
||||
/** Source whose repeated doubling exceeds derived primitive string storage. */
|
||||
export const primitiveByteExpansionSource = (): string => {
|
||||
const declarations = ['const value0 = "x";'];
|
||||
for (let index = 1; index <= 30; index += 1) {
|
||||
const previous = `value${String(index - 1)}`;
|
||||
declarations.push(
|
||||
`const value${String(index)} = ${previous} + ${previous};`,
|
||||
);
|
||||
}
|
||||
declarations.push("const answer = value30;");
|
||||
return declarations.join("\n");
|
||||
};
|
||||
Reference in New Issue
Block a user