@gravitylabsllc/porthole 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/dist/adb.js +64 -0
- package/dist/adb.js.map +1 -0
- package/dist/capture.js +165 -0
- package/dist/capture.js.map +1 -0
- package/dist/cli.js +189 -0
- package/dist/cli.js.map +1 -0
- package/dist/device.js +174 -0
- package/dist/device.js.map +1 -0
- package/dist/index.js +417 -0
- package/dist/index.js.map +1 -0
- package/dist/report.js +161 -0
- package/dist/report.js.map +1 -0
- package/dist/timeline.js +232 -0
- package/dist/timeline.js.map +1 -0
- package/dist/trace.js +276 -0
- package/dist/trace.js.map +1 -0
- package/package.json +62 -0
- package/ui/dist/assets/index--1mlZuNZ.css +1 -0
- package/ui/dist/assets/index-BeVGHRFm.js +68 -0
- package/ui/dist/index.html +23 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/dist/adb.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// Copyright 2026 Gravity Labs
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { spawnSync } from "node:child_process";
|
|
4
|
+
import { existsSync } from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
/** adb, in the order a developer would look for it. Mirrors the Gradle plugin. */
|
|
7
|
+
export function findAdb() {
|
|
8
|
+
const binary = process.platform === "win32" ? "adb.exe" : "adb";
|
|
9
|
+
for (const variable of ["ANDROID_HOME", "ANDROID_SDK_ROOT"]) {
|
|
10
|
+
const root = process.env[variable];
|
|
11
|
+
if (!root)
|
|
12
|
+
continue;
|
|
13
|
+
const candidate = path.join(root, "platform-tools", binary);
|
|
14
|
+
if (existsSync(candidate))
|
|
15
|
+
return candidate;
|
|
16
|
+
}
|
|
17
|
+
return binary;
|
|
18
|
+
}
|
|
19
|
+
export function runAdb(args, serial) {
|
|
20
|
+
const prefix = serial ? ["-s", serial] : [];
|
|
21
|
+
const result = spawnSync(findAdb(), [...prefix, ...args], { encoding: "utf8" });
|
|
22
|
+
if (result.error) {
|
|
23
|
+
return {
|
|
24
|
+
ok: false,
|
|
25
|
+
output: `Could not run adb (${result.error.message}). ` +
|
|
26
|
+
"Set ANDROID_HOME, or put adb on your PATH.",
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
const output = ((result.stdout || "") + (result.stderr || "")).trim();
|
|
30
|
+
if (result.status !== 0) {
|
|
31
|
+
return {
|
|
32
|
+
ok: false,
|
|
33
|
+
output: output.includes("more than one") && !serial
|
|
34
|
+
? `${output}\nStart the UI with --serial <id>; 'adb devices' lists them.`
|
|
35
|
+
: output || `adb exited ${result.status}`,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
return { ok: true, output };
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Stop the app and start it again.
|
|
42
|
+
*
|
|
43
|
+
* Driven from this side rather than from inside the app: a process cannot
|
|
44
|
+
* reliably restart itself, and asking it to try is how you end up with a
|
|
45
|
+
* half-dead process that no longer answers the socket.
|
|
46
|
+
*/
|
|
47
|
+
export function restartApp(packageName, serial) {
|
|
48
|
+
const stopped = runAdb(["shell", "am", "force-stop", packageName], serial);
|
|
49
|
+
if (!stopped.ok)
|
|
50
|
+
return stopped;
|
|
51
|
+
const started = runAdb(["shell", "monkey", "-p", packageName, "-c", "android.intent.category.LAUNCHER", "1"], serial);
|
|
52
|
+
if (!started.ok)
|
|
53
|
+
return started;
|
|
54
|
+
// monkey reports success on stdout even when it launched nothing, so the
|
|
55
|
+
// absence of its "Events injected" line is the honest failure signal.
|
|
56
|
+
if (!started.output.includes("Events injected")) {
|
|
57
|
+
return {
|
|
58
|
+
ok: false,
|
|
59
|
+
output: started.output || `No launcher activity found for ${packageName}.`,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
return { ok: true, output: `restarted ${packageName}` };
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=adb.js.map
|
package/dist/adb.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adb.js","sourceRoot":"","sources":["../src/adb.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,sCAAsC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,kFAAkF;AAClF,MAAM,UAAU,OAAO;IACrB,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC;IAChE,KAAK,MAAM,QAAQ,IAAI,CAAC,cAAc,EAAE,kBAAkB,CAAC,EAAE,CAAC;QAC5D,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACnC,IAAI,CAAC,IAAI;YAAE,SAAS;QACpB,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,gBAAgB,EAAE,MAAM,CAAC,CAAC;QAC5D,IAAI,UAAU,CAAC,SAAS,CAAC;YAAE,OAAO,SAAS,CAAC;IAC9C,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAOD,MAAM,UAAU,MAAM,CAAC,IAAc,EAAE,MAAe;IACpD,MAAM,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC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AC,EACrF,MAAM,CACP,CAAC;IACF,IAAI,CAAC,OAAO,CAAC,EAAE;QAAE,OAAO,OAAO,CAAC;IAEhC,yEAAyE;IACzE,sEAAsE;IACtE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,CAAC;QAChD,OAAO;YACL,EAAE,EAAE,KAAK;YACT,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,kCAAkC,WAAW,GAAG;SAC3E,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,aAAa,WAAW,EAAE,EAAE,CAAC;AAC1D,CAAC"}
|
package/dist/capture.js
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
// Copyright 2026 Gravity Labs
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { spawn } from "node:child_process";
|
|
4
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
5
|
+
import { DeviceClient } from "./device.js";
|
|
6
|
+
import { renderComparison, renderReport } from "./report.js";
|
|
7
|
+
import { buildTrace } from "./trace.js";
|
|
8
|
+
export const CAPTURE_USAGE = `
|
|
9
|
+
porthole capture — record a run and write a trace
|
|
10
|
+
|
|
11
|
+
porthole capture --scenario <name> [options] -- <command to run>
|
|
12
|
+
|
|
13
|
+
--scenario <name> what this run is, and what a baseline is matched against
|
|
14
|
+
--out <file> where to write the trace (default porthole-trace.json)
|
|
15
|
+
--driver <name> what drove the app; compare warns when two runs differ
|
|
16
|
+
--with-events include the raw event stream. Large.
|
|
17
|
+
--fail-on <what> nothing (default), error, or regression
|
|
18
|
+
--baseline <file> compare against this trace when done
|
|
19
|
+
--port <n> device port (default 8677)
|
|
20
|
+
--serial <id> adb device serial
|
|
21
|
+
--no-forward skip 'adb forward'; use it if the bridge is already up
|
|
22
|
+
|
|
23
|
+
porthole report <trace.json>
|
|
24
|
+
porthole compare <baseline.json> <trace.json>
|
|
25
|
+
|
|
26
|
+
The command runs to completion with the porthole recording. Its exit code is
|
|
27
|
+
passed through unless --fail-on fires first.
|
|
28
|
+
`;
|
|
29
|
+
/** Waits for the device to answer, so a capture does not silently record nothing. */
|
|
30
|
+
async function awaitConnection(device, timeoutMs = 10_000) {
|
|
31
|
+
if (device.state === "connected")
|
|
32
|
+
return true;
|
|
33
|
+
return new Promise((resolve) => {
|
|
34
|
+
const timer = setTimeout(() => resolve(false), timeoutMs);
|
|
35
|
+
device.on("state", (state) => {
|
|
36
|
+
if (state === "connected") {
|
|
37
|
+
clearTimeout(timer);
|
|
38
|
+
resolve(true);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
export async function capture(options) {
|
|
44
|
+
const device = new DeviceClient("127.0.0.1", options.port);
|
|
45
|
+
const events = [];
|
|
46
|
+
device.on("event", (event) => events.push(event));
|
|
47
|
+
device.start();
|
|
48
|
+
const connected = await awaitConnection(device);
|
|
49
|
+
if (!connected) {
|
|
50
|
+
device.stop();
|
|
51
|
+
process.stderr.write(device.notConnectedMessage() + "\n");
|
|
52
|
+
return 1;
|
|
53
|
+
}
|
|
54
|
+
process.stderr.write(`recording "${options.scenario}"\n`);
|
|
55
|
+
const startedAt = Date.now();
|
|
56
|
+
const exitCode = await run(options.command);
|
|
57
|
+
const durationMs = Date.now() - startedAt;
|
|
58
|
+
// The last events are still in flight when the child exits.
|
|
59
|
+
await new Promise((resolve) => setTimeout(resolve, 750));
|
|
60
|
+
const hello = device.hello;
|
|
61
|
+
device.stop();
|
|
62
|
+
const trace = buildTrace({
|
|
63
|
+
scenario: options.scenario,
|
|
64
|
+
driver: options.driver,
|
|
65
|
+
events,
|
|
66
|
+
hello,
|
|
67
|
+
durationMs,
|
|
68
|
+
withEvents: options.withEvents,
|
|
69
|
+
});
|
|
70
|
+
await writeFile(options.out, JSON.stringify(trace, null, 2));
|
|
71
|
+
process.stderr.write(`\n${renderReport(trace)}`);
|
|
72
|
+
process.stderr.write(`\nwrote ${options.out} (${events.length} events)\n`);
|
|
73
|
+
let regressed = false;
|
|
74
|
+
if (options.baseline) {
|
|
75
|
+
const before = JSON.parse(await readFile(options.baseline, "utf8"));
|
|
76
|
+
const comparison = renderComparison(before, trace);
|
|
77
|
+
process.stderr.write(`\n${comparison.text}`);
|
|
78
|
+
regressed = comparison.regressed;
|
|
79
|
+
}
|
|
80
|
+
const hasError = trace.findings.some((finding) => finding.severity === "error");
|
|
81
|
+
if (options.failOn === "error" && hasError)
|
|
82
|
+
return 1;
|
|
83
|
+
if (options.failOn === "regression" && regressed)
|
|
84
|
+
return 1;
|
|
85
|
+
return exitCode;
|
|
86
|
+
}
|
|
87
|
+
/** Runs the child with its output passed straight through. */
|
|
88
|
+
function run(command) {
|
|
89
|
+
if (command.length === 0)
|
|
90
|
+
return Promise.resolve(0);
|
|
91
|
+
return new Promise((resolve) => {
|
|
92
|
+
// No shell. Passing an argv array through one concatenates it unescaped,
|
|
93
|
+
// which mangles any argument containing a space and turns the command into
|
|
94
|
+
// an injection point. A caller who wants a shell asks for one by name:
|
|
95
|
+
// `-- bash -c "..."`.
|
|
96
|
+
const child = spawn(command[0], command.slice(1), { stdio: "inherit" });
|
|
97
|
+
child.on("error", (error) => {
|
|
98
|
+
process.stderr.write(`could not run ${command[0]}: ${error.message}\n`);
|
|
99
|
+
resolve(127);
|
|
100
|
+
});
|
|
101
|
+
child.on("close", (code) => resolve(code ?? 0));
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
export async function report(file) {
|
|
105
|
+
const trace = JSON.parse(await readFile(file, "utf8"));
|
|
106
|
+
process.stdout.write(renderReport(trace));
|
|
107
|
+
return 0;
|
|
108
|
+
}
|
|
109
|
+
export async function compare(baseline, file) {
|
|
110
|
+
const before = JSON.parse(await readFile(baseline, "utf8"));
|
|
111
|
+
const after = JSON.parse(await readFile(file, "utf8"));
|
|
112
|
+
const comparison = renderComparison(before, after);
|
|
113
|
+
process.stdout.write(comparison.text);
|
|
114
|
+
// A refusal is not a pass. Exiting 0 would turn a gate that compared nothing
|
|
115
|
+
// into a green build, which is the one outcome worse than a red one.
|
|
116
|
+
if (comparison.refused)
|
|
117
|
+
return 2;
|
|
118
|
+
return comparison.regressed ? 1 : 0;
|
|
119
|
+
}
|
|
120
|
+
export function parseCapture(argv) {
|
|
121
|
+
const options = {
|
|
122
|
+
port: 8677,
|
|
123
|
+
scenario: "capture",
|
|
124
|
+
out: "porthole-trace.json",
|
|
125
|
+
withEvents: false,
|
|
126
|
+
failOn: "nothing",
|
|
127
|
+
forward: true,
|
|
128
|
+
command: [],
|
|
129
|
+
};
|
|
130
|
+
for (let i = 0; i < argv.length; i++) {
|
|
131
|
+
const arg = argv[i];
|
|
132
|
+
if (arg === "--") {
|
|
133
|
+
options.command = argv.slice(i + 1);
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
else if (arg === "--scenario")
|
|
137
|
+
options.scenario = argv[++i];
|
|
138
|
+
else if (arg === "--out")
|
|
139
|
+
options.out = argv[++i];
|
|
140
|
+
else if (arg === "--driver")
|
|
141
|
+
options.driver = argv[++i];
|
|
142
|
+
else if (arg === "--baseline")
|
|
143
|
+
options.baseline = argv[++i];
|
|
144
|
+
else if (arg === "--with-events")
|
|
145
|
+
options.withEvents = true;
|
|
146
|
+
else if (arg === "--fail-on")
|
|
147
|
+
options.failOn = argv[++i];
|
|
148
|
+
else if (arg === "--port")
|
|
149
|
+
options.port = Number(argv[++i]);
|
|
150
|
+
else if (arg === "--serial")
|
|
151
|
+
options.serial = argv[++i];
|
|
152
|
+
else if (arg === "--no-forward")
|
|
153
|
+
options.forward = false;
|
|
154
|
+
else if (arg === "--help" || arg === "-h") {
|
|
155
|
+
process.stdout.write(CAPTURE_USAGE);
|
|
156
|
+
process.exit(0);
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
process.stderr.write(`unknown option: ${arg}\n${CAPTURE_USAGE}`);
|
|
160
|
+
process.exit(2);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return options;
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=capture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capture.js","sourceRoot":"","sources":["../src/capture.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,sCAAsC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAoB,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAc,MAAM,YAAY,CAAC;AAyBpD,MAAM,CAAC,MAAM,aAAa,GAAG;;;;;;;;;;;;;;;;;;;;CAoB5B,CAAC;AAEF,qFAAqF;AACrF,KAAK,UAAU,eAAe,CAAC,MAAoB,EAAE,SAAS,GAAG,MAAM;IACrE,IAAI,MAAM,CAAC,KAAK,KAAK,WAAW;QAAE,OAAO,IAAI,CAAC;IAC9C,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,SAAS,CAAC,CAAC;QAC1D,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAa,EAAE,EAAE;YACnC,IAAI,KAAK,KAAK,WAAW,EAAE,CAAC;gBAC1B,YAAY,CAAC,KAAK,CAAC,CAAC;gBACpB,OAAO,CAAC,IAAI,CAAC,CAAC;YAChB,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,OAAuB;IACnD,MAAM,MAAM,GAAG,IAAI,YAAY,CAAC,WAAW,EAAE,OAAO,CAAC,IAAI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AAO,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC,CAA6B,CAAC;aAChF,IAAI,GAAG,KAAK,QAAQ;YAAE,OAAO,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;aACvD,IAAI,GAAG,KAAK,UAAU;YAAE,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;aACnD,IAAI,GAAG,KAAK,cAAc;YAAE,OAAO,CAAC,OAAO,GAAG,KAAK,CAAC;aACpD,IAAI,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;YAC1C,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;YACpC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,mBAAmB,GAAG,KAAK,aAAa,EAAE,CAAC,CAAC;YACjE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Copyright 2026 Gravity Labs
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
5
|
+
import { existsSync } from "node:fs";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { DeviceClient } from "./device.js";
|
|
8
|
+
import { TimelineServer } from "./timeline.js";
|
|
9
|
+
import { capture, compare, parseCapture, report } from "./capture.js";
|
|
10
|
+
import { runAdb } from "./adb.js";
|
|
11
|
+
const USAGE = `
|
|
12
|
+
porthole — a window into a running Android app
|
|
13
|
+
|
|
14
|
+
porthole ui open the live timeline
|
|
15
|
+
porthole capture --scenario <name> -- <command> record a run to a trace
|
|
16
|
+
porthole report <trace.json> what the run is worth looking at
|
|
17
|
+
porthole compare <base> <trace> regressions against a baseline
|
|
18
|
+
porthole mcp the MCP server (stdio)
|
|
19
|
+
|
|
20
|
+
porthole ui — open the live timeline for a running debug build
|
|
21
|
+
|
|
22
|
+
npx @gravitylabsllc/porthole ui [options]
|
|
23
|
+
|
|
24
|
+
--port <n> device port the porthole is listening on (default 8677)
|
|
25
|
+
--ui-port <n> port to serve the timeline on (default 8678)
|
|
26
|
+
--serial <id> adb device serial, when more than one is attached
|
|
27
|
+
--no-forward skip 'adb forward'; use it if you set the bridge up yourself
|
|
28
|
+
--no-open do not launch a browser, just print the URL
|
|
29
|
+
|
|
30
|
+
Needs a device or emulator with the debug build running: the porthole lives inside
|
|
31
|
+
the app process, and adb forward is what makes its socket reachable from here.
|
|
32
|
+
`;
|
|
33
|
+
function parse(argv) {
|
|
34
|
+
const options = {
|
|
35
|
+
port: 8677,
|
|
36
|
+
uiPort: 8678,
|
|
37
|
+
forward: true,
|
|
38
|
+
open: true,
|
|
39
|
+
};
|
|
40
|
+
for (let i = 0; i < argv.length; i++) {
|
|
41
|
+
const arg = argv[i];
|
|
42
|
+
if (arg === "--port")
|
|
43
|
+
options.port = Number(argv[++i]);
|
|
44
|
+
else if (arg === "--ui-port")
|
|
45
|
+
options.uiPort = Number(argv[++i]);
|
|
46
|
+
else if (arg === "--serial")
|
|
47
|
+
options.serial = argv[++i];
|
|
48
|
+
else if (arg === "--no-forward")
|
|
49
|
+
options.forward = false;
|
|
50
|
+
else if (arg === "--no-open")
|
|
51
|
+
options.open = false;
|
|
52
|
+
else if (arg === "--help" || arg === "-h") {
|
|
53
|
+
process.stdout.write(USAGE);
|
|
54
|
+
process.exit(0);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
process.stderr.write(`unknown option: ${arg}\n${USAGE}`);
|
|
58
|
+
process.exit(2);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return options;
|
|
62
|
+
}
|
|
63
|
+
/** adb, in the order a developer would look for it. Mirrors the Gradle plugin. */
|
|
64
|
+
function findAdb() {
|
|
65
|
+
const binary = process.platform === "win32" ? "adb.exe" : "adb";
|
|
66
|
+
for (const variable of ["ANDROID_HOME", "ANDROID_SDK_ROOT"]) {
|
|
67
|
+
const root = process.env[variable];
|
|
68
|
+
if (!root)
|
|
69
|
+
continue;
|
|
70
|
+
const candidate = path.join(root, "platform-tools", binary);
|
|
71
|
+
if (existsSync(candidate))
|
|
72
|
+
return candidate;
|
|
73
|
+
}
|
|
74
|
+
return binary;
|
|
75
|
+
}
|
|
76
|
+
function forwardPort(options) {
|
|
77
|
+
const adb = findAdb();
|
|
78
|
+
const args = options.serial ? ["-s", options.serial] : [];
|
|
79
|
+
args.push("forward", `tcp:${options.port}`, `tcp:${options.port}`);
|
|
80
|
+
const result = spawnSync(adb, args, { encoding: "utf8" });
|
|
81
|
+
if (result.error) {
|
|
82
|
+
console.error(`Could not run adb (${result.error.message}).\n` +
|
|
83
|
+
"Set ANDROID_HOME, or put adb on your PATH, or pass --no-forward if the\n" +
|
|
84
|
+
"bridge is already up.");
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (result.status !== 0) {
|
|
88
|
+
const message = (result.stderr || result.stdout || "").trim();
|
|
89
|
+
console.error(`adb forward failed: ${message}`);
|
|
90
|
+
if (message.includes("more than one")) {
|
|
91
|
+
console.error("Pass --serial <id>; 'adb devices' lists them.");
|
|
92
|
+
}
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
console.error(`forwarded 127.0.0.1:${options.port} to the device`);
|
|
96
|
+
}
|
|
97
|
+
function openBrowser(url) {
|
|
98
|
+
const [command, args] = process.platform === "win32"
|
|
99
|
+
? ["cmd", ["/c", "start", "", url]]
|
|
100
|
+
: process.platform === "darwin"
|
|
101
|
+
? ["open", [url]]
|
|
102
|
+
: ["xdg-open", [url]];
|
|
103
|
+
try {
|
|
104
|
+
spawn(command, args, { detached: true, stdio: "ignore" }).unref();
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
// Printing the URL is the fallback, and it is already printed.
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
async function ui(argv) {
|
|
111
|
+
const options = parse(argv);
|
|
112
|
+
if (options.forward)
|
|
113
|
+
forwardPort(options);
|
|
114
|
+
const device = new DeviceClient("127.0.0.1", options.port);
|
|
115
|
+
const timeline = new TimelineServer(device, options.uiPort, options.serial);
|
|
116
|
+
device.start();
|
|
117
|
+
let url;
|
|
118
|
+
try {
|
|
119
|
+
url = await timeline.start();
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
console.error(`Could not serve the timeline on port ${options.uiPort}: ${error.message}\n` +
|
|
123
|
+
"Something else is probably on it; pass --ui-port to move.");
|
|
124
|
+
process.exit(1);
|
|
125
|
+
}
|
|
126
|
+
console.error(`timeline at ${url}`);
|
|
127
|
+
if (options.open)
|
|
128
|
+
openBrowser(url);
|
|
129
|
+
device.on("state", (state) => {
|
|
130
|
+
if (state === "connected") {
|
|
131
|
+
const hello = device.hello;
|
|
132
|
+
console.error(hello ? `connected to ${hello.packageName} on ${hello.device}` : "connected");
|
|
133
|
+
}
|
|
134
|
+
else if (state === "disconnected") {
|
|
135
|
+
// Expected constantly during development: the app gets reinstalled and
|
|
136
|
+
// relaunched, and the client reconnects on its own.
|
|
137
|
+
console.error("waiting for the app...");
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
// The first connect usually lands in well under a second. Printing a
|
|
141
|
+
// troubleshooting wall immediately and then "connected" a moment later reads
|
|
142
|
+
// like something went wrong when nothing did.
|
|
143
|
+
setTimeout(() => {
|
|
144
|
+
if (device.state !== "connected")
|
|
145
|
+
console.error(device.notConnectedMessage());
|
|
146
|
+
}, 2000);
|
|
147
|
+
const shutdown = () => {
|
|
148
|
+
device.stop();
|
|
149
|
+
timeline.stop();
|
|
150
|
+
process.exit(0);
|
|
151
|
+
};
|
|
152
|
+
process.on("SIGINT", shutdown);
|
|
153
|
+
process.on("SIGTERM", shutdown);
|
|
154
|
+
}
|
|
155
|
+
const [command, ...rest] = process.argv.slice(2);
|
|
156
|
+
if (command === "ui") {
|
|
157
|
+
await ui(rest);
|
|
158
|
+
}
|
|
159
|
+
else if (command === "mcp") {
|
|
160
|
+
await import("./index.js");
|
|
161
|
+
}
|
|
162
|
+
else if (command === "capture") {
|
|
163
|
+
const options = parseCapture(rest);
|
|
164
|
+
if (options.forward) {
|
|
165
|
+
const forwarded = runAdb(["forward", `tcp:${options.port}`, `tcp:${options.port}`], options.serial);
|
|
166
|
+
if (!forwarded.ok)
|
|
167
|
+
console.error(forwarded.output);
|
|
168
|
+
}
|
|
169
|
+
process.exit(await capture(options));
|
|
170
|
+
}
|
|
171
|
+
else if (command === "report") {
|
|
172
|
+
if (!rest[0]) {
|
|
173
|
+
process.stderr.write("porthole report <trace.json>\n");
|
|
174
|
+
process.exit(2);
|
|
175
|
+
}
|
|
176
|
+
process.exit(await report(rest[0]));
|
|
177
|
+
}
|
|
178
|
+
else if (command === "compare") {
|
|
179
|
+
if (!rest[0] || !rest[1]) {
|
|
180
|
+
process.stderr.write("porthole compare <baseline.json> <trace.json>\n");
|
|
181
|
+
process.exit(2);
|
|
182
|
+
}
|
|
183
|
+
process.exit(await compare(rest[0], rest[1]));
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
process.stdout.write(USAGE);
|
|
187
|
+
process.exit(command === undefined || command === "--help" || command === "-h" ? 0 : 2);
|
|
188
|
+
}
|
|
189
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,8BAA8B;AAC9B,sCAAsC;AACtC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,S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