chore: merge main into feat/pkg-inventory

This commit is contained in:
morluto
2026-10-08 21:21:07 +08:00
11 changed files with 333 additions and 20 deletions
@@ -0,0 +1,32 @@
import { expect } from "vitest";
import { cliTest } from "../../support/cli/cliFixture.js";
cliTest.for(["", " \t "])(
"rejects blank Electron application_root (%j) before filesystem or provider work",
async (applicationRoot, { cli }) => {
const response = await cli.run({
arguments: [
"capture-electron-scenario",
JSON.stringify({
executable_path: "/synthetic/missing-electron",
application_path: "/synthetic/missing-app",
application_root: applicationRoot,
}),
"--json",
],
environment: { REA_LOG_LEVEL: "silent" },
timeoutMs: 15000,
});
expect(response.exitCode).toBe(1);
expect(response.json).toMatchObject({
code: "invalid_request",
details: {
operation: "capture_electron_scenario",
issues: expect.arrayContaining([
{ path: ["application_root"], reason: "out_of_range", minimum: 1 },
]),
},
});
},
);
@@ -172,6 +172,22 @@ describe("curl installer scenarios", { timeout: 20_000 }, () => {
});
});
describe("native macOS installer", { timeout: 20_000 }, () => {
it("installs on Darwin with an empty prefix argument array", async () => {
const fixture = await createFixture();
const result = await runInstaller(fixture, ["--version", "0.3.0"], {
FAKE_PLATFORM: "Darwin",
FAKE_NPM_PREFIX: join(fixture.home, "npm global prefix"),
});
expect(result.stdout).toContain("REA 0.3.0 is installed");
expect(await readFile(fixture.npmLog, "utf8")).toBe(
"prefix --global\ninstall --global rea-agents@0.3.0\n",
);
expect(await readFile(fixture.reaLog, "utf8")).toBe("--version\n");
expect(await readdir(fixture.temporary)).toEqual([]);
});
});
describe("installer semantic version parsing", { timeout: 20_000 }, () => {
it.each(["1.2.3-01"])(
"rejects malformed semantic versions before invoking npm: %s",
@@ -309,6 +325,7 @@ printf '%s\n' "$*" >> "$FAKE_NPM_LOG"
[ "$1" = "prefix" ] && { [ "\${FAKE_NPM_PREFIX_FAIL:-}" = "1" ] && exit 1; printf '%s\n' "$FAKE_NPM_PREFIX"; exit 0; }
[ "\${FAKE_NPM_FAIL:-}" = "1" ] && exit 1
prefix="$HOME/.local"
[ "\${FAKE_PLATFORM:-Linux}" = "Darwin" ] && prefix="$FAKE_NPM_PREFIX"
while [ "$#" -gt 0 ]; do
if [ "$1" = "--prefix" ]; then shift; prefix="$1"; fi
shift
@@ -1,7 +1,11 @@
import { mkdir, writeFile } from "node:fs/promises";
import { execFile } from "node:child_process";
import { mkdir, realpath, writeFile } from "node:fs/promises";
import { createRequire } from "node:module";
import { dirname, join, relative, sep } from "node:path";
import { fileURLToPath } from "node:url";
import { promisify } from "node:util";
import { expect, it } from "vitest";
import { reconstructJavaScriptArtifact } from "../../../src/application/javascript/JavaScriptArtifactReconstruction.js";
@@ -160,3 +164,108 @@ it.each(cases)(
expect(result.graph.coverage.status).toBe("complete");
},
);
const runNode = promisify(execFile);
it.each([
{
name: "import uses main before bundler module",
kind: "import",
metadata: { main: "actual.cjs", module: "bundler.mjs" },
},
{
name: "import ignores a module-only entry",
kind: "import",
metadata: { module: "bundler.mjs" },
},
{
name: "require ignores a module-only entry",
kind: "require",
metadata: { module: "bundler.mjs" },
},
{
name: "import preserves a main-only entry",
kind: "import",
metadata: { main: "actual.cjs" },
},
{
name: "require preserves main before bundler module",
kind: "require",
metadata: { main: "actual.cjs", module: "bundler.mjs" },
},
{
name: "import preserves declared exports before legacy entries",
kind: "import",
metadata: {
main: "actual.cjs",
module: "bundler.mjs",
exports: { import: "./exported.mjs", require: "./actual.cjs" },
},
},
] as const)(
"matches the native Node loader when $name",
async ({ kind, metadata }) => {
const root = await createTestTempDirectory("rea-node-package-fields-");
const entry = kind === "import" ? "main.mjs" : "main.cjs";
const source =
kind === "import"
? `import value from "fixture"; console.log(JSON.stringify({value, resolved: import.meta.resolve("fixture")}));`
: `const value = require("fixture"); console.log(JSON.stringify({value, resolved: require.resolve("fixture")}));`;
const files = {
"package.json": JSON.stringify({
name: "app",
main: entry,
type: kind === "import" ? "module" : "commonjs",
}),
[entry]: source,
"node_modules/fixture/package.json": JSON.stringify({
name: "fixture",
...metadata,
}),
"node_modules/fixture/actual.cjs": "module.exports = 'actual.cjs';",
"node_modules/fixture/index.js": "module.exports = 'index.js';",
"node_modules/fixture/bundler.mjs": "export default 'bundler.mjs';",
"node_modules/fixture/exported.mjs": "export default 'exported.mjs';",
};
await Promise.all(
Object.entries(files).map(async ([path, text]) => {
await mkdir(dirname(join(root, path)), { recursive: true });
await writeFile(join(root, path), text);
}),
);
const { stdout } = await runNode(process.execPath, [join(root, entry)], {
cwd: root,
});
const oracle: unknown = JSON.parse(stdout);
expect(oracle).toMatchObject({
value: expect.any(String),
resolved: expect.any(String),
});
if (typeof oracle !== "object" || oracle === null)
throw new Error("Node returned no package identity");
const resolved: unknown = Reflect.get(oracle, "resolved");
if (typeof resolved !== "string")
throw new Error("Node returned no resolved path");
const expected = relative(
await realpath(root),
kind === "import" ? fileURLToPath(resolved) : resolved,
)
.split(sep)
.join("/");
expect(Reflect.get(oracle, "value")).toBe(expected.split("/").at(-1));
const result = await reconstructJavaScriptArtifact({
input_path: root,
format: "directory",
});
const edge = result.graph.edges.find(
({ properties }) =>
properties.module_link_kind === kind &&
properties.specifier === "fixture",
);
expect(edge?.properties).toMatchObject({
resolution_status: "resolved",
resolved_path: expected,
});
expect(result.graph.coverage.status).toBe("complete");
},
);
+12 -4
View File
@@ -328,8 +328,10 @@ describe("MCP JSON Schema validity", () => {
await Promise.allSettled([client.close(), server.close()]);
}
});
});
it("advertises the structural request requirements enforced at runtime", async () => {
describe("MCP root input schemas", () => {
it("advertises object roots while enforcing union requirements at runtime", async () => {
const server = new McpServer({ name: "schema-constraints", version: "0" });
const client = new Client({ name: "schema-constraints", version: "0" });
const [clientTransport, serverTransport] =
@@ -353,12 +355,18 @@ describe("MCP JSON Schema validity", () => {
if (graphContract === undefined || graphTool === undefined)
throw new Error("Managed application graph tool was not advertised");
expect(graphContract.inputSchema.safeParse({}).success).toBe(false);
expect(graphTool.inputSchema).toMatchObject({ type: "object" });
expect(ajv.compile(graphTool.inputSchema)({})).toBe(false);
expect(ajv.compile(graphTool.inputSchema)({ unrelated: true })).toBe(
false,
);
for (const contract of TOOL_CONTRACTS) {
const validate = ajv.compile(
advertised.get(contract.name)!.inputSchema,
);
const inputSchema = advertised.get(contract.name)!.inputSchema;
expect(inputSchema.type, contract.name).toBe("object");
expect(inputSchema.properties, contract.name).toBeDefined();
expect(inputSchema.anyOf, contract.name).toBeUndefined();
const validate = ajv.compile(inputSchema);
for (const example of contract.examples)
expect(
validate(example.input),