mirror of
https://github.com/morluto/rea.git
synced 2026-11-18 20:53:00 +00:00
test(inspector): spell Node discovery targets as Node reports them (#10663)
* test(inspector): spell Node discovery targets as Node reports them The fake V8 Inspector gave Node-type targets a percent-encoded WHATWG file URL, while Node's /json/list reports `file://` plus the raw pathname with quotes and backslashes replaced by underscores. The product reads that channel literally, so a TMPDIR containing a space or percent sign named a pathname that did not exist and the target stayed unresolved: the Inspector cancellation test and "includes targets outside the old caller root filter" failed on unrelated assertions. Add nodeDiscoveryTargetUrl to the fake and use it where a resolved Node target location is asserted. The underscore case stays with createNodeDiscoveryTempDirectory. Validation: 69 inspector/browser/MCP/acceptance test files, 1168/1168 passing under TMPDIR spellings with an underscore, a space, a percent sign and none; check:fast passes. Refs morluto/rea#9996 * test(inspector): pin special-character Node discovery spellings Review follow-up for Node discovery target URLs. Neither caller gave nodeDiscoveryTargetUrl an explicit special-character path, so spaces and percent signs were exercised only when TMPDIR happened to contain them. A boundary case now lists two targets in one discovery root. "with space %41.js" is reported literally and resolves to its file. 'with "quote".js' is reported with underscores and stays an unresolved, unverifiable file location. Tests: tests/boundary/inspector/javascriptRuntimeObservation.test.ts passes (31). * test(inspector): spell the consolidated target listing as Node reports it main folded the test this branch had respelled into "lists all connectable targets on the selected endpoint across directories", which still built its two discovery targets with pathToFileURL. Under a temporary directory with a space or a percent sign those targets came back unresolved and the file-location assertions failed. Build them with nodeDiscoveryTargetUrl, as the rest of this branch does.
This commit is contained in:
1 parent
932afbeec5
commit
93bf4df3e4
3 files changed
+59
-6
No files matched your search
@@ -81,7 +81,10 @@ import { AnalysisCancelledError } from "../domain/analysisErrorCore.js";
|
||||
import { listElectronTargetsInputSchema } from "../domain/javascript/electronObservation.js";
|
||||
import { V8InspectorProvider } from "./V8InspectorProvider.js";
|
||||
import { startFakeCdpBrowser } from "../../tests/fixtures/fakeCdpBrowser.js";
|
||||
import { startFakeV8Inspector } from "../../tests/fixtures/inspector/fakeV8Inspector.js";
|
||||
import {
|
||||
nodeDiscoveryTargetUrl,
|
||||
startFakeV8Inspector,
|
||||
} from "../../tests/fixtures/inspector/fakeV8Inspector.js";
|
||||
import { createNodeDiscoveryTempDirectory } from "../../tests/fixtures/temporaryDirectory.js";
|
||||
import { isRecord } from "../kernel/isRecord.js";
|
||||
|
||||
@@ -118,8 +121,8 @@ it("stops Inspector target authorization after the current stat settles", async
|
||||
await writeFile(extraPath, "// second inert target file\n");
|
||||
fileAccess.extraPath = extraPath;
|
||||
const fake = await startFakeV8Inspector({
|
||||
targetUrl: pathToFileURL(path).href,
|
||||
additionalTargets: [{ url: pathToFileURL(extraPath).href }],
|
||||
targetUrl: nodeDiscoveryTargetUrl(path),
|
||||
additionalTargets: [{ url: nodeDiscoveryTargetUrl(extraPath) }],
|
||||
additionalTargetCount: 1,
|
||||
});
|
||||
fixtures.push(fake);
|
||||
|
||||
@@ -29,7 +29,10 @@ import {
|
||||
} from "../../../src/domain/evidence.js";
|
||||
import { javascriptRuntimeReconciliationResultSchema } from "../../../src/domain/javascript/javascriptRuntimeReconciliationSchemas.js";
|
||||
import { parseRuntimeCapture } from "../../../src/domain/javascript/javascriptRuntimeReconciliationCaptureParsing.js";
|
||||
import { startFakeV8Inspector } from "../../fixtures/inspector/fakeV8Inspector.js";
|
||||
import {
|
||||
nodeDiscoveryTargetUrl,
|
||||
startFakeV8Inspector,
|
||||
} from "../../fixtures/inspector/fakeV8Inspector.js";
|
||||
import { startFakeCdpBrowser } from "../../fixtures/fakeCdpBrowser.js";
|
||||
import { createNodeDiscoveryTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
@@ -274,8 +277,8 @@ test("lists all connectable targets on the selected endpoint across directories"
|
||||
const fixture = await runtimeFixture();
|
||||
const outside = await temporaryFile("outside.js");
|
||||
const fake = await startFakeV8Inspector({
|
||||
targetUrl: pathToFileURL(fixture.entry).href,
|
||||
additionalTargets: [{ url: pathToFileURL(outside).href }],
|
||||
targetUrl: nodeDiscoveryTargetUrl(fixture.entry),
|
||||
additionalTargets: [{ url: nodeDiscoveryTargetUrl(outside) }],
|
||||
additionalTargetCount: 205,
|
||||
});
|
||||
try {
|
||||
@@ -396,6 +399,45 @@ test("preserves attachment facts and refuses attached or unconnectable Inspector
|
||||
}
|
||||
});
|
||||
|
||||
// Node reports the raw pathname: spaces and % stay literal, and quotes or
|
||||
// backslashes become underscores that cannot identify the original path.
|
||||
test.skipIf(process.platform === "win32")(
|
||||
"resolves discovery paths with spaces and percent signs but not quote spellings",
|
||||
async () => {
|
||||
const root = await createNodeDiscoveryTempDirectory("rea-v8-spelling-");
|
||||
const spaced = join(root, "with space %41.js");
|
||||
const quoted = join(root, 'with "quote".js');
|
||||
await writeFile(spaced, "export {};\n");
|
||||
await writeFile(quoted, "export {};\n");
|
||||
expect(nodeDiscoveryTargetUrl(spaced)).toBe(`file://${spaced}`);
|
||||
expect(nodeDiscoveryTargetUrl(quoted)).toBe(
|
||||
`file://${join(root, "with _quote_.js")}`,
|
||||
);
|
||||
const fake = await startFakeV8Inspector({
|
||||
targetUrl: nodeDiscoveryTargetUrl(spaced),
|
||||
additionalTargets: [{ url: nodeDiscoveryTargetUrl(quoted) }],
|
||||
});
|
||||
try {
|
||||
const result = await new V8InspectorProvider().listTargets({
|
||||
inspector_endpoint: fake.endpoint,
|
||||
});
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value.targets.map(({ location }) => location)).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({ kind: "file", file_path: spaced }),
|
||||
{
|
||||
kind: "unresolved",
|
||||
reported_url: nodeDiscoveryTargetUrl(quoted),
|
||||
reason: "unverifiable-file-location",
|
||||
},
|
||||
]),
|
||||
);
|
||||
} finally {
|
||||
await fake.close();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
test("captures complete metadata with two enable commands", async () => {
|
||||
const fixture = await runtimeFixture();
|
||||
const outside = await temporaryFile("secret.js");
|
||||
|
||||
+8
@@ -2,6 +2,14 @@ import { createServer } from "node:http";
|
||||
|
||||
import { WebSocket, WebSocketServer } from "ws";
|
||||
|
||||
/**
|
||||
* Spell a script pathname the way Node's `/json/list` reports a target URL:
|
||||
* `file://` plus the raw pathname, with quotes and backslashes replaced by
|
||||
* underscores. It is not a WHATWG file URL, so spaces and `%` stay literal.
|
||||
*/
|
||||
export const nodeDiscoveryTargetUrl = (path: string): string =>
|
||||
`file://${path.replace(/["\\]/gu, "_")}`;
|
||||
|
||||
interface InspectorCommand {
|
||||
readonly id: number;
|
||||
readonly method: string;
|
||||
|
||||
Reference in new issue
Block a user