Repository navigation
fix(native-network-logs): capture the launch after restart_required #1402
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
Open
blazejkustra
wants to merge
11
commits into
main
Choose a base branch
from
fix/native-network-launch
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.
+325
−6
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
7cfaa6d
fix(native-network-logs): capture the launch after restart_required
blazejkustra db24a6c
test(native-network-logs): capture is registered before restart_required
blazejkustra 91c0509
refactor(native-network-logs): drop the ordering comment
blazejkustra cfab9cd
fix(native-network-logs): never arm capture for a refused system app
blazejkustra c0511c6
fix(native-network-logs): say when capture started with this call
blazejkustra c156e3b
test(native-network-logs): cover capture delivery through the blueprint
blazejkustra 7d2a4e8
refactor(native-network-logs): single return with optional note
blazejkustra 9057ddd
refactor(native-network-logs): drop comments the tests already cover
blazejkustra 58d3e91
test(native-network-logs): wait for the activation instead of a fixed…
blazejkustra 5e100f0
Merge remote-tracking branch 'origin/main' into pr-1402-work
blazejkustra 82c1aec
fix(native-network-logs): keep the missed-launch note for the first o…
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
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
78 changes: 78 additions & 0 deletions
78
packages/tool-server/test/native-network-logs-activation.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,78 @@ | ||
| import { describe, it, expect, vi, beforeEach } from "vitest"; | ||
|
|
||
| vi.mock("../src/blueprints/native-devtools", async () => { | ||
| const actual = await vi.importActual<typeof import("../src/blueprints/native-devtools")>( | ||
| "../src/blueprints/native-devtools" | ||
| ); | ||
| return { | ||
| ...actual, | ||
| precheckNativeDevtools: vi.fn(async () => ({ | ||
| status: "restart_required", | ||
| message: "restart the app", | ||
| })), | ||
| }; | ||
| }); | ||
|
|
||
| const UDID = "AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA"; | ||
|
|
||
| describe("native-network-logs before the app is instrumented", () => { | ||
| beforeEach(async () => { | ||
| const { __resetDepCacheForTests, __primeDepCacheForTests } = | ||
| await import("../src/utils/check-deps"); | ||
| __resetDepCacheForTests(); | ||
| __primeDepCacheForTests(["xcrun"]); | ||
| }); | ||
|
|
||
| it("registers network capture before answering restart_required", async () => { | ||
| const activateNetworkInspection = vi.fn(); | ||
| const api = { activateNetworkInspection } as any; | ||
| const { nativeNetworkLogsTool } = | ||
| await import("../src/tools/native-devtools/native-network-logs"); | ||
|
|
||
| const result = await nativeNetworkLogsTool.execute( | ||
| { nativeDevtools: api }, | ||
| { udid: UDID, bundleId: "com.example.app", limit: 50, clear: false } | ||
| ); | ||
|
|
||
| expect(result).toMatchObject({ status: "restart_required" }); | ||
| // So the relaunched app starts capturing at its handshake. | ||
| expect(activateNetworkInspection).toHaveBeenCalledWith("com.example.app"); | ||
|
blazejkustra marked this conversation as resolved.
|
||
| }); | ||
|
|
||
| it("keeps the missed-requests note for the first ok answer", async () => { | ||
| const { precheckNativeDevtools } = await import("../src/blueprints/native-devtools"); | ||
| // Blocked once (init_failed after activation reached a live connection), then through. | ||
| vi.mocked(precheckNativeDevtools) | ||
| .mockResolvedValueOnce({ status: "init_failed", message: "re-boot" } as any) | ||
| .mockResolvedValueOnce(null); | ||
| let gap = false; | ||
| const api = { | ||
| activateNetworkInspection: vi.fn(() => { | ||
| gap = true; | ||
| }), | ||
| takeCaptureGap: vi.fn(() => { | ||
| const had = gap; | ||
| gap = false; | ||
| return had; | ||
| }), | ||
| isConnected: () => true, | ||
| getNetworkLog: () => [], | ||
| armsEnv: true, | ||
| } as any; | ||
| const { nativeNetworkLogsTool } = | ||
| await import("../src/tools/native-devtools/native-network-logs"); | ||
| const params = { udid: UDID, bundleId: "com.example.app", limit: 50, clear: false }; | ||
|
|
||
| expect(await nativeNetworkLogsTool.execute({ nativeDevtools: api }, params)).toMatchObject({ | ||
| status: "init_failed", | ||
| }); | ||
| expect(api.takeCaptureGap).not.toHaveBeenCalled(); | ||
|
|
||
| const ok = (await nativeNetworkLogsTool.execute({ nativeDevtools: api }, params)) as { | ||
| status: string; | ||
| note?: string; | ||
| }; | ||
| expect(ok.status).toBe("ok"); | ||
| expect(ok.note).toMatch(/were not recorded.*restart-app/); | ||
| }); | ||
| }); | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Diplomat, Opus 5.5]: Activation now runs before the
NATIVE_DEVTOOLS_NOT_CONNECTEDthrow below, so on a provider-attached device that error message is false: it says "No network log is being captured for it", but this call has just armed capture. In a harness with a realRegistry, the real blueprint and a fake provider socket, the first call after a cold attach threw that message. The provider's handshake then replayed the activation, and the next call returnedokwith the note. After a provider hang-up, the first call threw the same message, and a request the app sent after that throw was still in the next answer (count: 1). The tool description (line 44) also presents this error as final on these devices, so an agent that trusts it gives up on a capture that is actually running. Why the first call throws at all predates this PR, filed as #1561.