Merge branch 'feat/dylib-resolution' into feat/dyld-shared-cache
Bring in #927's merge of main (#964 at skill version 29): - README_ja/ar/ko/zh: keep the merged tables and count inspect_dyld_shared_cache in application workflows (13 -> 14). - Skill: #927 now uses version 30, so this branch moves to 31. - Regenerate the product catalog, conformance manifest, skill digest and package metadata (137 tools). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { mkdir, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
import { reconstructJavaScriptArtifact } from "../../../src/application/javascript/JavaScriptArtifactReconstruction.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
const cases = [
|
||||
['<script data-src="decoy.js"></script>', []],
|
||||
['<script x:src="decoy.js"></script>', []],
|
||||
[`<script title='src="decoy.js"'></script>`, []],
|
||||
["<script src=actual.js></script>", ["actual.js"]],
|
||||
['<script title=">" src="actual.js"></script>', ["actual.js"]],
|
||||
['<script src="actual.js"></script>', ["actual.js"]],
|
||||
["<script src='actual.js'></script>", ["actual.js"]],
|
||||
['<script data-src="decoy.js" src="actual.js"></script>', ["actual.js"]],
|
||||
['<!-- <script src="decoy.js"></script> -->', []],
|
||||
['<textarea><script src="decoy.js"></script></textarea>', []],
|
||||
['<template><script src="decoy.js"></script></template>', []],
|
||||
['<script src="actual.js" src="decoy.js"></script>', ["actual.js"]],
|
||||
] as const;
|
||||
|
||||
it.each(cases)(
|
||||
"projects local loads from actual HTML attributes in %s",
|
||||
async (html, expected) => {
|
||||
const root = await createTestTempDirectory("rea-html-entrypoints-");
|
||||
await Promise.all([
|
||||
writeFile(join(root, "index.html"), html),
|
||||
writeFile(join(root, "actual.js"), "globalThis.ownedActual = true;"),
|
||||
writeFile(join(root, "decoy.js"), "globalThis.ownedDecoy = true;"),
|
||||
]);
|
||||
const result = await reconstructJavaScriptArtifact({ input_path: root });
|
||||
const loads = result.graph.edges.filter(
|
||||
({ relation, properties }) =>
|
||||
relation === "loads" && properties.script_path !== undefined,
|
||||
);
|
||||
expect(loads.map(({ properties }) => properties.resolved_path)).toEqual(
|
||||
expected,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
it("preserves source digest, opening-tag range and decoded local base resolution", async () => {
|
||||
const root = await createTestTempDirectory("rea-html-entrypoint-evidence-");
|
||||
const opening = '<script title=">" src="actual.js">';
|
||||
const prefix = '<base data-href="decoy/"><base href=assets/>\n';
|
||||
const html = `${prefix}${opening}</script>`;
|
||||
await mkdir(join(root, "assets"));
|
||||
await Promise.all([
|
||||
writeFile(join(root, "index.html"), html),
|
||||
writeFile(
|
||||
join(root, "assets", "actual.js"),
|
||||
"globalThis.ownedActual = true;",
|
||||
),
|
||||
]);
|
||||
const result = await reconstructJavaScriptArtifact({ input_path: root });
|
||||
const loads = result.graph.edges.filter(
|
||||
({ relation, properties }) =>
|
||||
relation === "loads" && properties.script_path !== undefined,
|
||||
);
|
||||
expect(loads).toHaveLength(1);
|
||||
expect(loads[0]).toMatchObject({
|
||||
properties: {
|
||||
script_path: "actual.js",
|
||||
base_href: "assets/",
|
||||
resolved_path: "assets/actual.js",
|
||||
},
|
||||
evidence: {
|
||||
authority: "static-relationship-inference",
|
||||
artifact: {
|
||||
available: true,
|
||||
sha256: createHash("sha256").update(html).digest("hex"),
|
||||
},
|
||||
location: {
|
||||
available: true,
|
||||
value: {
|
||||
kind: "source-range",
|
||||
source: "index.html",
|
||||
start: { line: 2, column: 0 },
|
||||
end: { line: 2, column: opening.length },
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,133 @@
|
||||
import { mkdir, writeFile } from "node:fs/promises";
|
||||
import { createRequire } from "node:module";
|
||||
import { dirname, join, relative, sep } from "node:path";
|
||||
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
import { reconstructJavaScriptArtifact } from "../../../src/application/javascript/JavaScriptArtifactReconstruction.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
const cases: readonly {
|
||||
name: string;
|
||||
html: string;
|
||||
files: Readonly<Record<string, string>>;
|
||||
expected: readonly string[];
|
||||
}[] = [
|
||||
{
|
||||
name: "extension fallback",
|
||||
html: '<script src="./app"></script>',
|
||||
files: { "app.js": "globalThis.owned = true;" },
|
||||
expected: [],
|
||||
},
|
||||
{
|
||||
name: "directory index",
|
||||
html: '<script src="./app"></script>',
|
||||
files: { "app/index.js": "globalThis.owned = true;" },
|
||||
expected: [],
|
||||
},
|
||||
{
|
||||
name: "directory package",
|
||||
html: '<script src="./app"></script>',
|
||||
files: {
|
||||
"app/package.json": '{"main":"entry.js"}',
|
||||
"app/entry.js": "globalThis.owned = true;",
|
||||
},
|
||||
expected: [],
|
||||
},
|
||||
{
|
||||
name: "base directory",
|
||||
html: '<base href="assets/"><script src="./app"></script>',
|
||||
files: { "assets/app.js": "globalThis.owned = true;" },
|
||||
expected: [],
|
||||
},
|
||||
{
|
||||
name: "exact base resource",
|
||||
html: '<base href="assets/"><script src="./app.js?cache=1#v2"></script>',
|
||||
files: {
|
||||
"assets/app.js": "globalThis.owned = true;",
|
||||
"app.js": "globalThis.decoy = true;",
|
||||
},
|
||||
expected: ["assets/app.js"],
|
||||
},
|
||||
{
|
||||
name: "exact script resource",
|
||||
html: '<script src="./app.js?cache=1#v2"></script>',
|
||||
files: { "app.js": "globalThis.owned = true;" },
|
||||
expected: ["app.js"],
|
||||
},
|
||||
];
|
||||
|
||||
it.each(cases)(
|
||||
"uses exact HTML resource identity for $name",
|
||||
async ({ html, files, expected }) => {
|
||||
const root = await createTestTempDirectory("rea-html-resources-");
|
||||
await Promise.all(
|
||||
Object.entries({ ...files, "index.html": html }).map(
|
||||
async ([path, text]) => {
|
||||
await mkdir(dirname(join(root, path)), { recursive: true });
|
||||
await writeFile(join(root, path), text);
|
||||
},
|
||||
),
|
||||
);
|
||||
const result = await reconstructJavaScriptArtifact({ input_path: root });
|
||||
const loads = result.graph.edges.filter(
|
||||
({ relation, properties }) =>
|
||||
relation === "loads" && properties.script_path !== undefined,
|
||||
);
|
||||
expect(loads.map(({ properties }) => properties.resolved_path)).toEqual(
|
||||
expected,
|
||||
);
|
||||
if (expected.length === 0) {
|
||||
const reference = result.graph.nodes
|
||||
.flatMap(({ observations }) => observations)
|
||||
.find(
|
||||
({ properties }) => properties.mechanism === "html-script-reference",
|
||||
);
|
||||
expect(reference).toMatchObject({
|
||||
properties: {
|
||||
script_path: "./app",
|
||||
resolution_context: "html-reference",
|
||||
resolution_status: "not-found",
|
||||
resolved_path: null,
|
||||
},
|
||||
evidence: {
|
||||
authority: "static-relationship-inference",
|
||||
location: {
|
||||
available: true,
|
||||
value: { kind: "source-range", source: "index.html" },
|
||||
},
|
||||
limitations: expect.arrayContaining([
|
||||
expect.stringContaining("exact HTML resource"),
|
||||
]),
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
it("retains CommonJS extension resolution against Node", async () => {
|
||||
const root = await createTestTempDirectory("rea-html-node-control-");
|
||||
await Promise.all([
|
||||
writeFile(
|
||||
join(root, "main.cjs"),
|
||||
'const value = require("./app"); module.exports = value;',
|
||||
),
|
||||
writeFile(join(root, "app.js"), 'module.exports = "actual";'),
|
||||
]);
|
||||
const expected = relative(
|
||||
root,
|
||||
createRequire(join(root, "main.cjs")).resolve("./app"),
|
||||
)
|
||||
.split(sep)
|
||||
.join("/");
|
||||
const result = await reconstructJavaScriptArtifact({ input_path: root });
|
||||
const edge = result.graph.edges.find(
|
||||
({ properties }) =>
|
||||
properties.module_link_kind === "require" &&
|
||||
properties.specifier === "./app",
|
||||
);
|
||||
expect(edge?.properties).toMatchObject({
|
||||
resolution_status: "resolved",
|
||||
resolved_path: expected,
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,231 @@
|
||||
import { execFile } from "node:child_process";
|
||||
import { mkdir, writeFile } from "node:fs/promises";
|
||||
import { dirname, join } from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
import { expect, it } from "vitest";
|
||||
import { z } from "zod";
|
||||
|
||||
import { reconstructJavaScriptArtifact } from "../../../src/application/javascript/JavaScriptArtifactReconstruction.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
const cases: readonly {
|
||||
name: string;
|
||||
exports: unknown;
|
||||
expected: string | null;
|
||||
nodeError?: string;
|
||||
rejectedTarget?: string;
|
||||
}[] = [
|
||||
...[
|
||||
"./../outside.cjs",
|
||||
"./lib/../actual.cjs",
|
||||
"././actual.cjs",
|
||||
"./node_modules/actual.cjs",
|
||||
"./NODE_MODULES/actual.cjs",
|
||||
"./%2e%2e/outside.cjs",
|
||||
"./n%6fde_modules/actual.cjs",
|
||||
"./lib\\..\\actual.cjs",
|
||||
"../outside.cjs",
|
||||
"actual.cjs",
|
||||
"/actual.cjs",
|
||||
"file:./actual.cjs",
|
||||
"",
|
||||
].map((target) => ({
|
||||
name: `invalid target ${JSON.stringify(target)}`,
|
||||
exports: target,
|
||||
expected: null,
|
||||
nodeError: "ERR_INVALID_PACKAGE_TARGET",
|
||||
rejectedTarget: target,
|
||||
})),
|
||||
{
|
||||
name: "root subpath rejects a parent segment",
|
||||
exports: { ".": "./../outside.cjs" },
|
||||
expected: null,
|
||||
nodeError: "ERR_INVALID_PACKAGE_TARGET",
|
||||
rejectedTarget: "./../outside.cjs",
|
||||
},
|
||||
{
|
||||
name: "active condition rejects instead of selecting default",
|
||||
exports: { node: "./../outside.cjs", default: "./actual.cjs" },
|
||||
expected: null,
|
||||
nodeError: "ERR_INVALID_PACKAGE_TARGET",
|
||||
rejectedTarget: "./../outside.cjs",
|
||||
},
|
||||
{
|
||||
name: "top-level array skips an invalid target",
|
||||
exports: ["./../outside.cjs", "./actual.cjs"],
|
||||
expected: "node_modules/fixture/actual.cjs",
|
||||
},
|
||||
{
|
||||
name: "root array skips encoded invalid segments",
|
||||
exports: { ".": ["./%2e%2e/outside.cjs", "./actual.cjs"] },
|
||||
expected: "node_modules/fixture/actual.cjs",
|
||||
},
|
||||
{
|
||||
name: "nested arrays skip invalid package-local segments",
|
||||
exports: { node: [["./n%6fde_modules/actual.cjs", "./actual.cjs"]] },
|
||||
expected: "node_modules/fixture/actual.cjs",
|
||||
},
|
||||
{
|
||||
name: "last invalid target retains its reason",
|
||||
exports: ["./../outside.cjs", "././actual.cjs"],
|
||||
expected: null,
|
||||
nodeError: "ERR_INVALID_PACKAGE_TARGET",
|
||||
rejectedTarget: "././actual.cjs",
|
||||
},
|
||||
{
|
||||
name: "null following an invalid target blocks exports",
|
||||
exports: ["./../outside.cjs", null],
|
||||
expected: null,
|
||||
nodeError: "ERR_PACKAGE_PATH_NOT_EXPORTED",
|
||||
},
|
||||
{
|
||||
name: "an invalid target following null remains invalid",
|
||||
exports: [null, "./../outside.cjs"],
|
||||
expected: null,
|
||||
nodeError: "ERR_INVALID_PACKAGE_TARGET",
|
||||
rejectedTarget: "./../outside.cjs",
|
||||
},
|
||||
{
|
||||
name: "inactive invalid condition does not block default",
|
||||
exports: { browser: "./../outside.cjs", default: "./actual.cjs" },
|
||||
expected: "node_modules/fixture/actual.cjs",
|
||||
},
|
||||
...["./bad%.cjs", "./bad%C3.cjs"].map((target) => ({
|
||||
name: `malformed URL ${target} is selected before URL decoding`,
|
||||
exports: [target, "./actual.cjs"],
|
||||
expected: null,
|
||||
nodeError: "URIError",
|
||||
})),
|
||||
{
|
||||
name: "encoded separator is selected before final path refusal",
|
||||
exports: ["./lib%2Factual.cjs", "./actual.cjs"],
|
||||
expected: null,
|
||||
nodeError: "ERR_INVALID_MODULE_SPECIFIER",
|
||||
},
|
||||
{
|
||||
name: "missing first target does not select a second file",
|
||||
exports: ["./missing.cjs", "./actual.cjs"],
|
||||
expected: null,
|
||||
nodeError: "MODULE_NOT_FOUND",
|
||||
},
|
||||
{
|
||||
name: "nested directory is valid",
|
||||
exports: "./lib/actual.cjs",
|
||||
expected: "node_modules/fixture/lib/actual.cjs",
|
||||
},
|
||||
{
|
||||
name: "node_modules substring is not a forbidden segment",
|
||||
exports: "./node_modules.cjs",
|
||||
expected: "node_modules/fixture/node_modules.cjs",
|
||||
},
|
||||
{
|
||||
name: "encoded underscore and letters do not borrow a forbidden directory",
|
||||
exports: ["./%6eode%5fmodules/actual.cjs", "./actual.cjs"],
|
||||
expected: "node_modules/fixture/actual.cjs",
|
||||
},
|
||||
{
|
||||
name: "percent encoding is applied once",
|
||||
exports: "./literal%252e.cjs",
|
||||
expected: "node_modules/fixture/literal%2e.cjs",
|
||||
},
|
||||
];
|
||||
|
||||
const nativeResultSchema = z.object({
|
||||
value: z.string().nullable(),
|
||||
code: z.string().nullable(),
|
||||
});
|
||||
|
||||
it.each(
|
||||
(["import", "require"] as const).flatMap((moduleKind) =>
|
||||
cases.map((testCase) => ({ ...testCase, moduleKind })),
|
||||
),
|
||||
)(
|
||||
"matches Node $moduleKind target selection for $name",
|
||||
async ({
|
||||
moduleKind,
|
||||
name,
|
||||
exports,
|
||||
expected,
|
||||
nodeError,
|
||||
rejectedTarget,
|
||||
}) => {
|
||||
const root = await createTestTempDirectory("rea-package-target-");
|
||||
const mainPath = moduleKind === "import" ? "main.mjs" : "main.cjs";
|
||||
const files = {
|
||||
[mainPath]:
|
||||
moduleKind === "import"
|
||||
? 'import value from "fixture"; export default value;'
|
||||
: 'module.exports = require("fixture");',
|
||||
"node_modules/fixture/package.json": JSON.stringify({ exports }),
|
||||
...Object.fromEntries(
|
||||
[
|
||||
"node_modules/fixture/actual.cjs",
|
||||
"node_modules/outside.cjs",
|
||||
"node_modules/fixture/lib/actual.cjs",
|
||||
"node_modules/fixture/node_modules/actual.cjs",
|
||||
"node_modules/fixture/node_modules.cjs",
|
||||
"node_modules/fixture/literal%2e.cjs",
|
||||
].map((path) => [path, `module.exports = ${JSON.stringify(path)};`]),
|
||||
),
|
||||
};
|
||||
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 runner =
|
||||
moduleKind === "import"
|
||||
? 'const load = async () => (await import("fixture")).default;'
|
||||
: 'const load = async () => require("fixture");';
|
||||
const native = await promisify(execFile)(
|
||||
process.execPath,
|
||||
[
|
||||
"--input-type",
|
||||
moduleKind === "import" ? "module" : "commonjs",
|
||||
"--eval",
|
||||
`${runner} load().then(value => console.log(JSON.stringify({value,code:null})), error => console.log(JSON.stringify({value:null,code:error.code ?? error.name})));`,
|
||||
],
|
||||
{ cwd: root, timeout: 5_000 },
|
||||
);
|
||||
const oracle = nativeResultSchema.parse(JSON.parse(native.stdout));
|
||||
expect(oracle.value, name).toBe(expected);
|
||||
if (nodeError !== undefined)
|
||||
expect(oracle.code).toBe(
|
||||
moduleKind === "import" && nodeError === "MODULE_NOT_FOUND"
|
||||
? "ERR_MODULE_NOT_FOUND"
|
||||
: nodeError,
|
||||
);
|
||||
const result = await reconstructJavaScriptArtifact({
|
||||
input_path: root,
|
||||
format: "directory",
|
||||
});
|
||||
const edge = result.graph.edges.find(
|
||||
({ properties }) =>
|
||||
properties.specifier === "fixture" &&
|
||||
properties.resolution_status !== undefined &&
|
||||
properties.resolution_status !== null,
|
||||
);
|
||||
expect(edge).toBeDefined();
|
||||
expect(edge?.properties.resolved_path).toBe(expected);
|
||||
if (expected !== null) {
|
||||
expect(edge?.properties.resolution_status).toBe("resolved");
|
||||
} else {
|
||||
expect(edge?.properties.resolution_status).not.toBe("resolved");
|
||||
}
|
||||
if (rejectedTarget !== undefined) {
|
||||
expect(edge?.properties.resolution_status).toBe("rejected");
|
||||
expect(edge?.evidence.limitations.join(" ")).toContain(
|
||||
JSON.stringify(rejectedTarget),
|
||||
);
|
||||
expect(edge?.evidence.limitations.join(" ")).toContain("exports target");
|
||||
expect(edge?.evidence.limitations.join(" ")).not.toContain(
|
||||
"not valid package JSON",
|
||||
);
|
||||
expect(edge?.evidence.location).toMatchObject({
|
||||
value: { kind: "source-range", source: mainPath },
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
@@ -25,6 +25,26 @@ const cases: readonly {
|
||||
metadata: { main: "actual.cjs" },
|
||||
index: false,
|
||||
},
|
||||
{
|
||||
name: "top-level exports array",
|
||||
metadata: { exports: ["./actual.cjs"] },
|
||||
index: true,
|
||||
},
|
||||
{
|
||||
name: "root subpath exports array",
|
||||
metadata: { exports: { ".": ["./actual.cjs"] } },
|
||||
index: true,
|
||||
},
|
||||
{
|
||||
name: "exports array skips invalid and unmatched entries",
|
||||
metadata: { exports: [42, { browser: "./browser.js" }, "./actual.cjs"] },
|
||||
index: true,
|
||||
},
|
||||
{
|
||||
name: "nested root exports array",
|
||||
metadata: { exports: { ".": [[null, { require: "./actual.cjs" }]] } },
|
||||
index: true,
|
||||
},
|
||||
{ name: "index fallback", metadata: {}, index: true },
|
||||
{
|
||||
name: "missing legacy main fallback",
|
||||
|
||||
Reference in New Issue
Block a user