mirror of
https://github.com/morluto/rea.git
synced 2026-11-22 06:25:44 +00:00
fix(javascript): read the target of method-first request(method, url) calls
endpointArgument takes the first literal of a get/post/put/patch/delete/request
call as its endpoint candidate. Method-first clients (superagent's
request(method, url), needle.request, Angular HttpClient.request) put the HTTP
method there, so Api.request("get", "/api/v1/profile") reported the candidate
"get" in both analyze_javascript_application and analyze_web_bundle, and the
path was lost.
For a request callee whose first literal is a standard HTTP method (the
XHR_METHODS set that xhrOpenUrl uses, compared after toUpperCase), an exact
second string is now the candidate. A computed target keeps the method token,
so request("POST", target) is unchanged, as are RPC names, Octokit route
strings and URL-first calls.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
fe8e571f78
commit
73bc6f48c7
4 files changed
+100
-1
No files matched your search
@@ -113,6 +113,39 @@ cliTest(
|
||||
},
|
||||
);
|
||||
|
||||
cliTest.for(["CLI", "stdio MCP"] as const)(
|
||||
"reports the exact target of method-first request calls through %s",
|
||||
async (surface, { cli }) => {
|
||||
const root = await createTestTempDirectory("rea-method-first-request-");
|
||||
await writeFixtureFiles(root, {
|
||||
"api.js": `
|
||||
const BASE = "https://api.example.test";
|
||||
class Api {
|
||||
static request(method, path, body) {
|
||||
return fetch(BASE + path, { method, body: JSON.stringify(body) });
|
||||
}
|
||||
}
|
||||
Api.request("get", "/api/v1/profile");
|
||||
Api.request("POST", "/api/v1/items", { name: "item" });
|
||||
Api.request("delete", \`/api/v1/items/\${id}\`);
|
||||
`,
|
||||
});
|
||||
const result = await analyzeJavaScriptDirectory(surface, cli, root);
|
||||
const requests = result.graph.nodes
|
||||
.filter(({ kind }) => kind === "endpoint")
|
||||
.flatMap(({ observations }) => observations)
|
||||
.filter(({ properties }) => properties.mechanism === "call:Api.request");
|
||||
expect(
|
||||
requests.map(({ properties }) => String(properties.value)).sort(),
|
||||
).toEqual(["/api/v1/items", "/api/v1/profile", "delete"]);
|
||||
for (const observation of requests)
|
||||
expect(observation).toMatchObject({
|
||||
properties: { interpretation: "candidate" },
|
||||
evidence: { state: "inferred", confidence: "low" },
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
cliTest(
|
||||
"preserves binding-backed XHR identity and qualifies replaced open methods",
|
||||
async ({ cli }) => {
|
||||
|
||||
Reference in new issue
Block a user