Repository navigation
feat(native-network-logs): one compact row per request by default #1413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
blazejkustra
wants to merge
11
commits into
main
Choose a base branch
from
feat/native-network-summary
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+554
−13
Draft
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
19c1849
feat(native-network-logs): one compact row per request by default
blazejkustra bb2139d
test(native-network-logs): pass the new format param in typed calls
blazejkustra 1d3fbb8
fix(native-network-logs): keep redirect, failure and buffer facts in …
blazejkustra 5369d35
fix(native-network-logs): keep the tool description a plain literal
blazejkustra 58cc865
Merge remote-tracking branch 'origin/main' into pr-1413-work
blazejkustra dff731d
fix(native-network-logs): tighten finalUrl, limit and truncated in re…
blazejkustra 42a718b
fix(native-network-logs): use the dylib's duration when a row lost it…
blazejkustra ff409ac
fix(native-network-logs): measure durationMs from the dylib's duratio…
blazejkustra 44fd683
fix(native-network-logs): flag a truncated log in format events too
blazejkustra 300527c
test(native-devtools): cover the network log ring buffer through a re…
blazejkustra 3c1312b
test(native-network-logs): cover the limit clamp and overlapping requ…
blazejkustra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
packages/tool-server/test/native-network-log-buffer.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| import { describe, it, expect, vi } from "vitest"; | ||
| import * as net from "node:net"; | ||
| import type { DeviceInfo } from "@argent/registry"; | ||
|
|
||
| vi.mock("@argent/native-devtools-ios", () => ({ | ||
| bootstrapDylibPath: () => "/fake/dylibs/libArgentInjectionBootstrap.dylib", | ||
| bootstrapDylibPathTcp: () => "/fake/dylibs/tcp/libArgentInjectionBootstrap.dylib", | ||
| bootstrapDylibPathTvos: () => "/fake/dylibs/tvos/libArgentInjectionBootstrap.dylib", | ||
| tcpInjectionDylibs: () => [], | ||
| axServiceBinaryPath: () => "/fake/ax-service", | ||
| axServiceBinaryPathTcp: () => "/fake/ax-service-tcp", | ||
| })); | ||
|
|
||
| type ExecCb = (err: Error | null, out: { stdout: string; stderr: string }) => void; | ||
|
|
||
| vi.mock("node:child_process", async () => { | ||
| const actual = await vi.importActual<typeof import("node:child_process")>("node:child_process"); | ||
| return { | ||
| ...actual, | ||
| execFile: (_cmd: string, _args: readonly string[], opts: unknown, cb?: ExecCb) => { | ||
| const callback = (typeof opts === "function" ? opts : cb!) as ExecCb; | ||
| callback(null, { stdout: "", stderr: "" }); | ||
| }, | ||
| }; | ||
| }); | ||
|
|
||
| import { nativeDevtoolsBlueprint, type NativeDevtoolsApi } from "../src/blueprints/native-devtools"; | ||
| import { processScopedUdid } from "./helpers/process-scoped-udid"; | ||
|
|
||
| const UDID = processScopedUdid("-5555-6666-7777-888888888888"); | ||
| const BUNDLE = "com.example.app"; | ||
| const LOG_LIMIT = 1000; | ||
|
|
||
| const device: DeviceInfo = { id: UDID, platform: "ios", kind: "simulator" }; | ||
|
|
||
| function frame(type: string, payload: unknown): string { | ||
| return JSON.stringify({ type, payload }) + "\n"; | ||
| } | ||
|
|
||
| function cdpEvent(index: number): string { | ||
| return frame("CDP", { | ||
| method: "Network.dataReceived", | ||
| params: { requestId: `r${index}`, dataLength: 1 }, | ||
| }); | ||
| } | ||
|
|
||
| function sendEvents(sock: net.Socket, from: number, to: number) { | ||
| const lines: string[] = []; | ||
| for (let i = from; i < to; i++) lines.push(cdpEvent(i)); | ||
| sock.write(lines.join("")); | ||
| } | ||
|
|
||
| function requestIds(api: NativeDevtoolsApi): string[] { | ||
| return api.getNetworkLog(BUNDLE).map((e) => (e.params as { requestId: string }).requestId); | ||
| } | ||
|
|
||
| async function waitForLastEvent(api: NativeDevtoolsApi, index: number) { | ||
| await vi.waitFor(() => expect(requestIds(api).at(-1)).toBe(`r${index}`)); | ||
| } | ||
|
|
||
| function connectAgent(socketPath: string): Promise<net.Socket> { | ||
| return new Promise((resolve) => { | ||
| const sock = net.createConnection(socketPath, () => { | ||
| sock.write(frame("Control", { bundleId: BUNDLE })); | ||
| resolve(sock); | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| describe.skipIf(process.platform === "win32")("native-devtools network log ring buffer", () => { | ||
| it("drops the oldest event past the limit, flags it, and resets on clear", async () => { | ||
| const instance = await nativeDevtoolsBlueprint.factory({}, device, { device }); | ||
| const api = instance.api as NativeDevtoolsApi; | ||
| const sock = await connectAgent(api.socketPath); | ||
| try { | ||
| await vi.waitFor(() => expect(api.isConnected(BUNDLE)).toBe(true)); | ||
|
|
||
| sendEvents(sock, 0, LOG_LIMIT); | ||
| await waitForLastEvent(api, LOG_LIMIT - 1); | ||
| expect(api.getNetworkLog(BUNDLE)).toHaveLength(LOG_LIMIT); | ||
| expect(api.networkLogEvicted(BUNDLE)).toBe(false); | ||
|
|
||
| sendEvents(sock, LOG_LIMIT, LOG_LIMIT + 1); | ||
| await waitForLastEvent(api, LOG_LIMIT); | ||
| const ids = requestIds(api); | ||
| expect(ids).toHaveLength(LOG_LIMIT); | ||
| expect(ids[0]).toBe("r1"); | ||
| expect(api.networkLogEvicted(BUNDLE)).toBe(true); | ||
|
|
||
| const snapshot = api.getNetworkLog(BUNDLE); | ||
| api.clearNetworkLog(BUNDLE); | ||
| expect(snapshot).toHaveLength(LOG_LIMIT); | ||
| expect(api.getNetworkLog(BUNDLE)).toEqual([]); | ||
| expect(api.networkLogEvicted(BUNDLE)).toBe(false); | ||
| } finally { | ||
| sock.destroy(); | ||
| await instance.dispose(); | ||
| } | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.