@xenon-device-management/xenon 2.16.0 → 2.17.1

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.
Files changed (135) hide show
  1. package/README.md +2 -2
  2. package/lib/package.json +2 -3
  3. package/lib/public/assets/{AnnotationOverlay-2W4JvEyZ.js → AnnotationOverlay-CB8njQvS.js} +1 -1
  4. package/lib/public/assets/{ApiKeyGate-GmckX_7r.js → ApiKeyGate-B-804QBS.js} +1 -1
  5. package/lib/public/assets/DeviceMosaicView-BsDvfjR1.js +2 -0
  6. package/lib/public/assets/{EmptyState-7hETKEWb.js → EmptyState-WzLw1cEV.js} +1 -1
  7. package/lib/public/assets/{FieldGroup-GOgssFEP.js → FieldGroup-CaQNXgcE.js} +1 -1
  8. package/lib/public/assets/{FilterMenu-Yvf6RGMd.js → FilterMenu-C9gAiypL.js} +1 -1
  9. package/lib/public/assets/{Menu-KrPnfdsf.js → Menu-CfTti3rw.js} +1 -1
  10. package/lib/public/assets/{Modal-C6WjZFeI.js → Modal-BcZUFhDm.js} +1 -1
  11. package/lib/public/assets/{RecordingPage-CSRIhZEh.js → RecordingPage-B_pbl3UE.js} +1 -1
  12. package/lib/public/assets/{RecordingsPage-CB8ST3nE.js → RecordingsPage-BkVhplE3.js} +1 -1
  13. package/lib/public/assets/{SegmentedControl-C9o90KId.js → SegmentedControl-CDLMLNl5.js} +1 -1
  14. package/lib/public/assets/{SettingCard-CPm3w9l2.js → SettingCard-Lyw5CB1F.js} +1 -1
  15. package/lib/public/assets/{Table-DwIgERRt.js → Table-CK414bOU.js} +1 -1
  16. package/lib/public/assets/{activity-DrLbHifn.js → activity-pEyAdE-M.js} +1 -1
  17. package/lib/public/assets/{ai-settings-DU_Ls06P.js → ai-settings-CIhS7MMq.js} +1 -1
  18. package/lib/public/assets/{api-keys-CWYdEzJ_.js → api-keys-D2J44Ebv.js} +1 -1
  19. package/lib/public/assets/{apps-BqNVdln7.js → apps-CCV3RZY8.js} +1 -1
  20. package/lib/public/assets/{arrow-left-BtB0_Jg_.js → arrow-left-DaEUmERk.js} +1 -1
  21. package/lib/public/assets/{arrow-right-C8NhdtyN.js → arrow-right-CnRXHXit.js} +1 -1
  22. package/lib/public/assets/{arrow-up-right-gMg0ffvv.js → arrow-up-right-BGCS7zhi.js} +1 -1
  23. package/lib/public/assets/{auth-shell-CiYZ3N4M.js → auth-shell-CpW1zsxD.js} +2 -2
  24. package/lib/public/assets/{builds-page-EaaqDmLN.js → builds-page-B-xdzjMx.js} +1 -1
  25. package/lib/public/assets/{button-DDau4Axv.js → button-B5QkOVa4.js} +1 -1
  26. package/lib/public/assets/{calendar-DQ83B1ed.js → calendar-gX_1EKue.js} +1 -1
  27. package/lib/public/assets/{check-K1ovTQam.js → check-MIM4THvH.js} +1 -1
  28. package/lib/public/assets/{chevron-right-Biq00pMt.js → chevron-right-BZIp3-9t.js} +1 -1
  29. package/lib/public/assets/{circle-check-CBv88cH7.js → circle-check-Crt-G_uy.js} +1 -1
  30. package/lib/public/assets/{circle-x-Bmltailn.js → circle-x-C8GvvXVt.js} +1 -1
  31. package/lib/public/assets/{clock-BPrld-3h.js → clock-MFKV4qGa.js} +1 -1
  32. package/lib/public/assets/{copy-t0QB14JI.js → copy-BU-Z7mBK.js} +1 -1
  33. package/lib/public/assets/device-explorer-D-78Twa0.js +282 -0
  34. package/lib/public/assets/{download-BroHxNOh.js → download-DIoLCCYv.js} +1 -1
  35. package/lib/public/assets/{forgot-password-Bjmf49i6.js → forgot-password-vNYlPnia.js} +1 -1
  36. package/lib/public/assets/{h264Stream-DeD__6wa.js → h264Stream-BLcSplMU.js} +1 -1
  37. package/lib/public/assets/{index-B0gQkEg0.js → index-BpqyclNY.js} +2 -2
  38. package/lib/public/assets/{index-B0JeuZbg.js → index-Hl1OL-k_.js} +1 -1
  39. package/lib/public/assets/{index-72oF89LJ.js → index-QbukVVrl.js} +1 -1
  40. package/lib/public/assets/{input-DIc4MSC7.js → input-DHH3fHer.js} +1 -1
  41. package/lib/public/assets/{line-chart-BcWm2vW8.js → line-chart-PdViEphw.js} +1 -1
  42. package/lib/public/assets/{list-checks-B06IJJad.js → list-checks-DI_heIg9.js} +1 -1
  43. package/lib/public/assets/{lock-pVLvnN30.js → lock-DVP_dL6J.js} +1 -1
  44. package/lib/public/assets/{login-CN77vy--.js → login-B8vtTDcr.js} +1 -1
  45. package/lib/public/assets/{maintenance-settings-CSdzQSkY.js → maintenance-settings-BMa5EfgI.js} +1 -1
  46. package/lib/public/assets/{monitor-BtrN5IkI.js → monitor-CtzX_RkD.js} +1 -1
  47. package/lib/public/assets/{mouse-pointer-2-CNsQfo6w.js → mouse-pointer-2-BA09sdS9.js} +1 -1
  48. package/lib/public/assets/{network-BSfA8ZxG.js → network-B_F9Nox-.js} +1 -1
  49. package/lib/public/assets/{overview-BfTebCK5.js → overview-kWCYMHMV.js} +1 -1
  50. package/lib/public/assets/{page-header-D8KUX6Qg.js → page-header-CAbH1O1a.js} +1 -1
  51. package/lib/public/assets/{play-Cvc8xzic.js → play-sg95hLqA.js} +1 -1
  52. package/lib/public/assets/{plus-C9Zj84UF.js → plus-BT9mk2gj.js} +1 -1
  53. package/lib/public/assets/{profile-page-Bi27STgs.js → profile-page-DZOz5Ypc.js} +1 -1
  54. package/lib/public/assets/{reset-password-CPsOuwSu.js → reset-password-CqeImlEO.js} +1 -1
  55. package/lib/public/assets/{runbook-page-DEQ-DBOX.js → runbook-page-U_8TSysj.js} +1 -1
  56. package/lib/public/assets/{select-BWpnhWXj.js → select-Cx4JDzsR.js} +1 -1
  57. package/lib/public/assets/{selector-detail-redirect-BefSCSpe.js → selector-detail-redirect-DiMRe7DW.js} +1 -1
  58. package/lib/public/assets/{selector-health-page-MSk96Zz7.js → selector-health-page-CKR5URll.js} +1 -1
  59. package/lib/public/assets/{session-detail-page-DPyBNef_.js → session-detail-page-DuIVzTW_.js} +1 -1
  60. package/lib/public/assets/{settings-V6x-cXwy.js → settings-B5fuvgTP.js} +1 -1
  61. package/lib/public/assets/{stat-tile-Duex-GZD.js → stat-tile-CtHX1dkh.js} +1 -1
  62. package/lib/public/assets/{tablet-BBcoqBmL.js → tablet-DCGD0GQt.js} +1 -1
  63. package/lib/public/assets/{teams-ts8p5rEh.js → teams-MzlELlw9.js} +1 -1
  64. package/lib/public/assets/{trash-2-CZ2ew6AZ.js → trash-2-BIRm2KVs.js} +1 -1
  65. package/lib/public/assets/{upload-Dv99y_le.js → upload-C-lgyswH.js} +1 -1
  66. package/lib/public/assets/{use-builds-data-DrYC8JCF.js → use-builds-data-IOydXA8d.js} +1 -1
  67. package/lib/public/assets/{use-password-reset-mode-C7QkBNkP.js → use-password-reset-mode-CIVXG7Me.js} +1 -1
  68. package/lib/public/assets/{users-gJ5Y01yo.js → users-hwK5XGIy.js} +1 -1
  69. package/lib/public/assets/{users-D7tKMESH.js → users-ivNCjeus.js} +1 -1
  70. package/lib/public/assets/{video-off-CqZVuZGs.js → video-off-DvcIEsdZ.js} +1 -1
  71. package/lib/public/assets/{webhook-settings-DI5DSW99.js → webhook-settings-DukgCe1u.js} +1 -1
  72. package/lib/public/assets/{zap-ClcHFxfo.js → zap-BE9gacFj.js} +1 -1
  73. package/lib/public/index.html +1 -1
  74. package/lib/schema.json +1 -1
  75. package/lib/src/app/index.js +2 -0
  76. package/lib/src/app/openapi/control.yaml +69 -4
  77. package/lib/src/app/openapi/grid.yaml +102 -0
  78. package/lib/src/app/routers/control.js +24 -5
  79. package/lib/src/dashboard/event-manager.js +5 -8
  80. package/lib/src/device-managers/ios/IOSStreamService.js +147 -18
  81. package/lib/src/device-utils.js +61 -24
  82. package/lib/src/gateway/internalCall.js +33 -5
  83. package/lib/src/gateway/nodeAsk.js +57 -0
  84. package/lib/src/gateway/nodeSessionDeviceLogs.js +35 -0
  85. package/lib/src/gateway/sessionGateway.js +9 -4
  86. package/lib/src/helpers/index.js +9 -6
  87. package/lib/src/interceptors/CommandInterceptor.js +10 -0
  88. package/lib/src/plugin.js +4 -1
  89. package/lib/src/scripts/initialize-database.js +0 -6
  90. package/lib/src/scripts/run-migrations.js +123 -880
  91. package/lib/src/services/ServerManager.js +25 -4
  92. package/lib/src/services/SessionLifecycleService.js +20 -5
  93. package/lib/src/services/UserService.js +8 -3
  94. package/lib/src/services/interceptor/CertManager.js +50 -16
  95. package/lib/src/services/logcat/NodeDeviceLogStore.js +99 -0
  96. package/lib/src/services/logcat/NodeDeviceLogsCollector.js +164 -0
  97. package/lib/src/services/logcat/SessionDeviceLogs.js +199 -44
  98. package/lib/src/services/logcat/nodeDeviceLogs.js +91 -0
  99. package/lib/src/services/metrics/nodeMetrics.js +20 -49
  100. package/lib/src/sessions/RemoteSession.js +11 -2
  101. package/lib/src/sessions/SessionManager.js +28 -1
  102. package/lib/src/sessions/appiumUmbrella.js +11 -0
  103. package/lib/src/sessions/sessionMemory.js +11 -2
  104. package/lib/test/helpers/fake-logcat.js +80 -0
  105. package/lib/test/helpers/hub-node-pair.js +227 -0
  106. package/lib/test/unit/UserService.test.js +8 -0
  107. package/lib/test/unit/boot-device-sync.spec.js +195 -0
  108. package/lib/test/unit/dashboard-events-device-logs.spec.js +15 -0
  109. package/lib/test/unit/hub-node-gateway-appium-server.spec.js +21 -0
  110. package/lib/test/unit/hub-node-iphone-readiness.spec.js +134 -0
  111. package/lib/test/unit/hub-node-session-device-logs.spec.js +194 -0
  112. package/lib/test/unit/hub-node-session-metrics.spec.js +24 -192
  113. package/lib/test/unit/hub-remote-session-heartbeat.spec.js +8 -1
  114. package/lib/test/unit/install-scripts.spec.js +98 -0
  115. package/lib/test/unit/interceptor/CertManager.spec.js +89 -0
  116. package/lib/test/unit/internal-call.spec.js +99 -0
  117. package/lib/test/unit/internal-calls-session-record.spec.js +312 -0
  118. package/lib/test/unit/ios-simulator-preview.spec.js +315 -0
  119. package/lib/test/unit/is-xenon-running.spec.js +10 -0
  120. package/lib/test/unit/node-device-log-store.spec.js +102 -0
  121. package/lib/test/unit/node-device-logs-collector.spec.js +343 -0
  122. package/lib/test/unit/node-gateway-create-appium-server.spec.js +8 -1
  123. package/lib/test/unit/node-hub-session-owner.spec.js +8 -1
  124. package/lib/test/unit/node-session-device-logs-route.spec.js +103 -0
  125. package/lib/test/unit/run-migrations-database.spec.js +57 -424
  126. package/lib/test/unit/run-migrations.test.js +74 -674
  127. package/lib/test/unit/session-device-logs-hub-node.spec.js +340 -0
  128. package/lib/test/unit/session-device-logs-lifecycle.spec.js +137 -0
  129. package/lib/test/unit/session-device-logs.spec.js +32 -94
  130. package/lib/test/unit/session-log-indexes.spec.js +15 -0
  131. package/lib/tsconfig.tsbuildinfo +1 -1
  132. package/package.json +2 -3
  133. package/schema.json +1 -1
  134. package/lib/public/assets/DeviceMosaicView-DqODzkyo.js +0 -2
  135. package/lib/public/assets/device-explorer-BgGZ8AvV.js +0 -282
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ require("reflect-metadata");
16
+ const chai_1 = require("chai");
17
+ const sinon_1 = __importDefault(require("sinon"));
18
+ const device_utils_1 = require("../../src/device-utils");
19
+ const device_service_1 = require("../../src/data-service/device-service");
20
+ const device_store_1 = require("../../src/data-service/device-store");
21
+ const localDeviceHosts_1 = require("../../src/device-managers/localDeviceHosts");
22
+ const IOSStreamService_1 = __importDefault(require("../../src/device-managers/ios/IOSStreamService"));
23
+ const WDAClient_1 = require("../../src/device-managers/ios/WDAClient");
24
+ const IPluginArgs_1 = require("../../src/interfaces/IPluginArgs");
25
+ const test_container_1 = require("../helpers/test-container");
26
+ const loki_stores_1 = require("../helpers/loki-stores");
27
+ const scratch_database_1 = require("../helpers/scratch-database");
28
+ /**
29
+ * Before a session, allocation asks the phone's manager whether it is ready.
30
+ * For an iPhone that asks WebDriverAgent on 127.0.0.1, at the port the phone's
31
+ * row names, and on no answer starts a go-ios stream for the phone. Both are
32
+ * this machine's: they say nothing about a phone another server drives.
33
+ *
34
+ * A hub ran it for its nodes' iPhones too. With the node on another machine
35
+ * nothing answered on the hub, its stream found no phone of its own to start,
36
+ * and every session on the node's iPhone was refused as "unhealthy". With both
37
+ * on one Mac, the hub started its own WebDriverAgent on the phone the node
38
+ * drives. The node checks the phone itself when it allocates it.
39
+ */
40
+ describe("Readiness before a session, on a hub allocating a node's iPhone", function () {
41
+ this.timeout(60000);
42
+ const scratch = (0, scratch_database_1.useScratchDatabase)();
43
+ (0, loki_stores_1.usePrismaStores)();
44
+ const NODE_ID = 'node-process';
45
+ const UDID = '00008110-000A1B2C3D4E5F60';
46
+ const pluginArgs = Object.assign(Object.assign({}, IPluginArgs_1.DefaultPluginArgs), { platform: 'ios', iosDeviceType: 'both' });
47
+ let hubNodeId;
48
+ let hubOrigin;
49
+ let verifyWda;
50
+ let startStream;
51
+ const iPhone = (over) => (Object.assign({ udid: UDID, name: 'iPhone 14 Plus', platform: 'ios', sdk: '18.0', deviceType: 'real', realDevice: true, state: 'device', busy: false, offline: false, userBlocked: false, wdaLocalPort: 8100, mjpegServerPort: 9100, totalUtilizationTimeMilliSec: 0, sessionStartTime: 0 }, over));
52
+ const caps = (extra = {}) => ({
53
+ alwaysMatch: Object.assign({ platformName: 'iOS', 'appium:udid': UDID }, extra),
54
+ firstMatch: [{}],
55
+ });
56
+ const allocate = (extra = {}) => (0, device_utils_1.allocateDeviceForSession)(caps(extra), 1000, 50, pluginArgs);
57
+ const row = (host) => device_store_1.DeviceStoreFactory.getStore().findDevice({ udid: UDID, host });
58
+ beforeEach(() => __awaiter(this, void 0, void 0, function* () {
59
+ const { context, xenonManager } = (0, test_container_1.setupTestContainer)(pluginArgs);
60
+ xenonManager.init();
61
+ hubNodeId = context.nodeId;
62
+ hubOrigin = (0, localDeviceHosts_1.serverOrigin)(context.pluginArgs, context.port);
63
+ yield scratch.db.device.deleteMany({});
64
+ yield scratch.db.deviceSetting.deleteMany({});
65
+ verifyWda = sinon_1.default.stub(WDAClient_1.WDAClient.prototype, 'verifyWDAStatus');
66
+ startStream = sinon_1.default.stub(IOSStreamService_1.default.prototype, 'startStream');
67
+ }));
68
+ afterEach(() => __awaiter(this, void 0, void 0, function* () {
69
+ sinon_1.default.restore();
70
+ yield (0, test_container_1.resetTestContainer)();
71
+ }));
72
+ describe('a node on another machine', () => {
73
+ const NODE = 'http://203.0.113.7:4723';
74
+ beforeEach(() => {
75
+ // What the hub's own machine answers: no WebDriverAgent on its
76
+ // 127.0.0.1, and no row of its own to start a stream from.
77
+ verifyWda.resolves(false);
78
+ startStream.rejects(new Error(`Device ${UDID} not found`));
79
+ });
80
+ it("allocates the node's iPhone, which the node checks itself", () => __awaiter(this, void 0, void 0, function* () {
81
+ var _a;
82
+ yield (0, device_service_1.addNewDevice)([iPhone({ host: NODE, nodeId: NODE_ID })]);
83
+ const device = yield allocate();
84
+ (0, chai_1.expect)(device).to.include({ udid: UDID, host: NODE });
85
+ (0, chai_1.expect)((_a = (yield row(NODE))) === null || _a === void 0 ? void 0 : _a.busy).to.equal(true);
86
+ }));
87
+ it("never asks the hub's own WebDriverAgent or starts a stream for it", () => __awaiter(this, void 0, void 0, function* () {
88
+ yield (0, device_service_1.addNewDevice)([iPhone({ host: NODE, nodeId: NODE_ID })]);
89
+ yield allocate().catch(() => undefined);
90
+ (0, chai_1.expect)(verifyWda.called, 'verifyWDAStatus called').to.equal(false);
91
+ (0, chai_1.expect)(startStream.called, 'startStream called').to.equal(false);
92
+ }));
93
+ });
94
+ describe('a node on the same Mac', () => {
95
+ it("never starts the hub's own stream for the iPhone the node drives", () => __awaiter(this, void 0, void 0, function* () {
96
+ var _a;
97
+ const node = `http://${pluginArgs.bindHostOrIp}:4724`;
98
+ // The hub sees the same iPhone and files it under its own host; the
99
+ // client asks for the node's.
100
+ yield (0, device_service_1.addNewDevice)([
101
+ iPhone({ host: node, nodeId: NODE_ID }),
102
+ iPhone({ host: hubOrigin, nodeId: hubNodeId, wdaLocalPort: 8101 }),
103
+ ]);
104
+ // The hub's stream starts for the udid, and its WebDriverAgent then
105
+ // answers: a second one beside the node's.
106
+ verifyWda.callsFake(() => __awaiter(this, void 0, void 0, function* () { return startStream.called; }));
107
+ startStream.resolves({ wdaPort: 8102, mjpegPort: 9102 });
108
+ const device = yield allocate({ 'appium:filterByHost': node });
109
+ (0, chai_1.expect)(device).to.include({ udid: UDID, host: node });
110
+ (0, chai_1.expect)(startStream.called, 'startStream called').to.equal(false);
111
+ (0, chai_1.expect)(verifyWda.called, 'verifyWDAStatus called').to.equal(false);
112
+ (0, chai_1.expect)((_a = (yield row(hubOrigin))) === null || _a === void 0 ? void 0 : _a.busy).to.equal(false);
113
+ }));
114
+ });
115
+ describe("the hub's own iPhone", () => {
116
+ it('is still checked, and allocated when its WebDriverAgent answers', () => __awaiter(this, void 0, void 0, function* () {
117
+ yield (0, device_service_1.addNewDevice)([iPhone({ host: hubOrigin, nodeId: hubNodeId })]);
118
+ verifyWda.resolves(true);
119
+ const device = yield allocate();
120
+ (0, chai_1.expect)(device).to.include({ udid: UDID, host: hubOrigin });
121
+ (0, chai_1.expect)(verifyWda.calledWith(UDID)).to.equal(true);
122
+ }));
123
+ it('is still refused, and released, when it is not ready and cannot be recovered', () => __awaiter(this, void 0, void 0, function* () {
124
+ var _a;
125
+ yield (0, device_service_1.addNewDevice)([iPhone({ host: hubOrigin, nodeId: hubNodeId })]);
126
+ verifyWda.resolves(false);
127
+ startStream.rejects(new Error('go-ios could not start'));
128
+ const error = yield allocate().then(() => null, (e) => e);
129
+ (0, chai_1.expect)(error === null || error === void 0 ? void 0 : error.message).to.match(/is unhealthy and could not be autonomously recovered/);
130
+ (0, chai_1.expect)(startStream.calledWith(UDID)).to.equal(true);
131
+ (0, chai_1.expect)((_a = (yield row(hubOrigin))) === null || _a === void 0 ? void 0 : _a.busy).to.equal(false);
132
+ }));
133
+ });
134
+ });
@@ -0,0 +1,194 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ require("reflect-metadata");
16
+ const chai_1 = require("chai");
17
+ const typedi_1 = require("typedi");
18
+ const loopbackRequest_1 = __importDefault(require("../helpers/loopbackRequest"));
19
+ const SessionDeviceLogs_1 = require("../../src/services/logcat/SessionDeviceLogs");
20
+ const NodeDeviceLogStore_1 = require("../../src/services/logcat/NodeDeviceLogStore");
21
+ const NodeDeviceLogsCollector_1 = require("../../src/services/logcat/NodeDeviceLogsCollector");
22
+ const nodeDeviceLogs_1 = require("../../src/services/logcat/nodeDeviceLogs");
23
+ const deviceLogBook_1 = require("../../src/services/logcat/deviceLogBook");
24
+ const hubSessionToken_1 = require("../../src/gateway/hubSessionToken");
25
+ const commandAuth_1 = require("../../src/middleware/commandAuth");
26
+ const IPluginArgs_1 = require("../../src/interfaces/IPluginArgs");
27
+ const scratch_database_1 = require("../helpers/scratch-database");
28
+ const selector_health_fixture_1 = require("../helpers/selector-health-fixture");
29
+ const hub_node_pair_1 = require("../helpers/hub-node-pair");
30
+ const fake_logcat_1 = require("../helpers/fake-logcat");
31
+ /**
32
+ * A hub writes the Device logs of a session on a node's phone, collected from
33
+ * the node: the node records its phone's log for the session the hub created
34
+ * (its dashboard off) and holds the lines; the hub asks for them with its
35
+ * session token (per-command auth is on) and writes them as the session page
36
+ * reads them. The node's `adb logcat` is fake; everything from it to the
37
+ * hub's rows is the real thing.
38
+ */
39
+ const quiet = { info: () => undefined, warn: () => undefined, debug: () => undefined };
40
+ /** The node's service, its phone's log stream fake. */
41
+ class NodeSideDeviceLogs extends SessionDeviceLogs_1.SessionDeviceLogs {
42
+ constructor(logcat, unclaimed = 60000) {
43
+ super();
44
+ this.logcat = logcat;
45
+ this.unclaimed = unclaimed;
46
+ }
47
+ streams() {
48
+ return this.logcat;
49
+ }
50
+ readClock() {
51
+ return __awaiter(this, void 0, void 0, function* () {
52
+ return deviceLogBook_1.UNKNOWN_CLOCK;
53
+ });
54
+ }
55
+ unclaimedMs() {
56
+ return this.unclaimed;
57
+ }
58
+ }
59
+ /** The hub's service: none of the phones are its own; it asks the node every 50 ms. */
60
+ class HubSideDeviceLogs extends SessionDeviceLogs_1.SessionDeviceLogs {
61
+ context() {
62
+ return {
63
+ pluginArgs: Object.assign(Object.assign({}, IPluginArgs_1.DefaultPluginArgs), { bindHostOrIp: '127.0.0.1' }),
64
+ port: 4799,
65
+ nodeId: 'hub-1',
66
+ };
67
+ }
68
+ collectorFor(source, onLines, storedTail) {
69
+ return new NodeDeviceLogsCollector_1.NodeDeviceLogsCollector({
70
+ source,
71
+ onLines,
72
+ storedTail,
73
+ support: typedi_1.Container.get(nodeDeviceLogs_1.NodeDeviceLogsSupport),
74
+ logger: quiet,
75
+ intervalMs: 50,
76
+ });
77
+ }
78
+ }
79
+ describe('a hub writes a node session’s device log', function () {
80
+ this.timeout(60000);
81
+ const scratch = (0, scratch_database_1.useScratchDatabase)();
82
+ const pair = (0, hub_node_pair_1.useHubAndNode)(scratch, [
83
+ SessionDeviceLogs_1.SessionDeviceLogs,
84
+ NodeDeviceLogStore_1.NodeDeviceLogStore,
85
+ nodeDeviceLogs_1.NodeDeviceLogsSupport,
86
+ ]);
87
+ let logcat;
88
+ beforeEach(() => {
89
+ logcat = new fake_logcat_1.FakeLogcatStreams();
90
+ typedi_1.Container.set(NodeDeviceLogStore_1.NodeDeviceLogStore, new NodeDeviceLogStore_1.NodeDeviceLogStore());
91
+ typedi_1.Container.set(nodeDeviceLogs_1.NodeDeviceLogsSupport, new nodeDeviceLogs_1.NodeDeviceLogsSupport());
92
+ });
93
+ afterEach(() => logcat.cleanup());
94
+ /** Boots the pair, the node's device log service `nodeLogs`; no CPU and memory sampling. */
95
+ function boot(nodeLogs) {
96
+ return __awaiter(this, void 0, void 0, function* () {
97
+ typedi_1.Container.set(SessionDeviceLogs_1.SessionDeviceLogs, nodeLogs);
98
+ yield pair.boot({ sessionMetrics: false });
99
+ });
100
+ }
101
+ /** The hub's row for the session, as onSessionStarted writes it. */
102
+ const hubRow = (sessionId) => scratch.db.session.create({
103
+ data: {
104
+ id: sessionId,
105
+ device_udid: 'phone-1',
106
+ device_platform: 'android',
107
+ device_version: '14',
108
+ desired_capabilities: '{}',
109
+ session_capabilities: '{}',
110
+ node_id: hub_node_pair_1.NODE_ID,
111
+ has_live_video: false,
112
+ status: 'running',
113
+ },
114
+ });
115
+ /** The session's Device logs as the hub's session page gets them. */
116
+ const page = (sessionId) => __awaiter(this, void 0, void 0, function* () {
117
+ const res = yield (0, loopbackRequest_1.default)((0, selector_health_fixture_1.selectorHealthApp)(selector_health_fixture_1.ADMIN)).get(`/session/${sessionId}/logs/device`);
118
+ (0, chai_1.expect)(res.status, res.text).to.equal(200);
119
+ return res.body.map((r) => r.message.replace(/^.*?Tag {5}: /, ''));
120
+ });
121
+ /** The page, once `ok` holds for it. */
122
+ const pageOnce = (sessionId, ok) => __awaiter(this, void 0, void 0, function* () {
123
+ const end = Date.now() + 5000;
124
+ for (;;) {
125
+ const rows = yield page(sessionId);
126
+ if (ok(rows))
127
+ return rows;
128
+ if (Date.now() > end)
129
+ throw new Error(`timed out at ${JSON.stringify(rows)}`);
130
+ yield new Promise((r) => setTimeout(r, 50));
131
+ }
132
+ });
133
+ const device = () => ({ udid: 'phone-1', host: pair.nodeOrigin, nodeId: hub_node_pair_1.NODE_ID, platform: 'android' });
134
+ it('writes the lines as the session runs, and the last ones when it ends', () => __awaiter(this, void 0, void 0, function* () {
135
+ const nodeLogs = new NodeSideDeviceLogs(logcat);
136
+ yield boot(nodeLogs);
137
+ const sessionId = yield pair.nodeSession();
138
+ // The node records the session the hub created, its dashboard off.
139
+ (0, chai_1.expect)(nodeLogs.isRecording(sessionId)).to.equal(true);
140
+ yield (0, fake_logcat_1.until)(() => logcat.procs.length === 1);
141
+ logcat.proc.stdout.write((0, fake_logcat_1.lineAt)(Date.now() - 600000, 'before the session'));
142
+ logcat.proc.stdout.write((0, fake_logcat_1.lineAt)(Date.now(), 'app started'));
143
+ yield hubRow(sessionId);
144
+ const hub = new HubSideDeviceLogs();
145
+ yield hub.start({ sessionId, device: device(), source: pair.hubSide(sessionId) });
146
+ // Live: written while the session runs.
147
+ (0, chai_1.expect)(yield pageOnce(sessionId, (rows) => rows.length > 0)).to.deep.equal(['app started']);
148
+ // The test's last moments, then the hub's DELETE reaches the node.
149
+ logcat.proc.stdout.write((0, fake_logcat_1.lineAt)(Date.now(), 'FATAL EXCEPTION: main'));
150
+ yield (0, fake_logcat_1.until)(() => typedi_1.Container.get(NodeDeviceLogStore_1.NodeDeviceLogStore).read(sessionId, null).lines.length > 0);
151
+ yield pair.deleteOnNode(sessionId);
152
+ (0, chai_1.expect)(nodeLogs.isRecording(sessionId)).to.equal(false);
153
+ yield hub.stop(sessionId);
154
+ (0, chai_1.expect)(yield page(sessionId)).to.deep.equal(['app started', 'FATAL EXCEPTION: main']);
155
+ }));
156
+ it('asks only with the hub’s token for the session', () => __awaiter(this, void 0, void 0, function* () {
157
+ yield boot(new NodeSideDeviceLogs(logcat));
158
+ const sessionId = yield pair.nodeSession();
159
+ const route = `/xenon/api/node/sessions/${sessionId}/device-logs`;
160
+ const without = yield (0, loopbackRequest_1.default)(pair.nodeOrigin).get(route);
161
+ const forged = yield (0, loopbackRequest_1.default)(pair.nodeOrigin).get(route).set(hubSessionToken_1.HUB_TOKEN_HEADER, 'forged');
162
+ (0, chai_1.expect)([without.status, without.body]).to.deep.equal([404, commandAuth_1.UNKNOWN_SESSION_BODY]);
163
+ (0, chai_1.expect)([forged.status, forged.body]).to.deep.equal([404, commandAuth_1.UNKNOWN_SESSION_BODY]);
164
+ const asked = yield pair.hubSide(sessionId).nodeDeviceLogs(null);
165
+ (0, chai_1.expect)(asked).to.deep.equal({
166
+ kind: 'answer',
167
+ answer: { state: 'recording', lines: [], more: false },
168
+ });
169
+ yield pair.deleteOnNode(sessionId);
170
+ }));
171
+ it('records nothing for a session that turned its device log off', () => __awaiter(this, void 0, void 0, function* () {
172
+ const nodeLogs = new NodeSideDeviceLogs(logcat);
173
+ yield boot(nodeLogs);
174
+ const sessionId = yield pair.nodeSession({ 'xe:save_device_logs': false });
175
+ (0, chai_1.expect)(nodeLogs.isRecording(sessionId)).to.equal(false);
176
+ (0, chai_1.expect)(logcat.procs).to.have.length(0);
177
+ (0, chai_1.expect)(yield pair.hubSide(sessionId).nodeDeviceLogs(null)).to.deep.equal({
178
+ kind: 'answer',
179
+ answer: { state: 'off', lines: [], more: false },
180
+ });
181
+ yield pair.deleteOnNode(sessionId);
182
+ }));
183
+ it('stops recording a session its hub doesn’t ask about', () => __awaiter(this, void 0, void 0, function* () {
184
+ const nodeLogs = new NodeSideDeviceLogs(logcat, 50);
185
+ yield boot(nodeLogs);
186
+ const sessionId = yield pair.nodeSession();
187
+ yield (0, fake_logcat_1.until)(() => !nodeLogs.isRecording(sessionId));
188
+ (0, chai_1.expect)(yield pair.hubSide(sessionId).nodeDeviceLogs(null)).to.deep.equal({
189
+ kind: 'answer',
190
+ answer: { state: 'off', lines: [], more: false },
191
+ });
192
+ yield pair.deleteOnNode(sessionId);
193
+ }));
194
+ });
@@ -14,38 +14,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  require("reflect-metadata");
16
16
  const chai_1 = require("chai");
17
- const express_1 = __importDefault(require("express"));
18
- const fs_1 = __importDefault(require("fs"));
19
- const http_1 = __importDefault(require("http"));
20
- const os_1 = __importDefault(require("os"));
21
- const path_1 = __importDefault(require("path"));
22
- const sinon_1 = __importDefault(require("sinon"));
23
17
  const loopbackRequest_1 = __importDefault(require("../helpers/loopbackRequest"));
24
18
  const typedi_1 = require("typedi");
25
- const plugin_1 = require("../../src/plugin");
26
- const registerCommandAuth_1 = require("../../src/app/registerCommandAuth");
27
- const defaultGateway_1 = require("../../src/gateway/defaultGateway");
28
- const hubSessionToken_1 = require("../../src/gateway/hubSessionToken");
29
- const nodeSessionStatus_1 = require("../../src/gateway/nodeSessionStatus");
30
- const nodeSessionMetrics_1 = require("../../src/gateway/nodeSessionMetrics");
31
19
  const SessionMetricsService_1 = require("../../src/services/metrics/SessionMetricsService");
32
20
  const NodeMetricsStore_1 = require("../../src/services/metrics/NodeMetricsStore");
33
21
  const NodeMetricsCollector_1 = require("../../src/services/metrics/NodeMetricsCollector");
34
22
  const nodeMetrics_1 = require("../../src/services/metrics/nodeMetrics");
35
- const JwtKeyService_1 = require("../../src/services/token/JwtKeyService");
36
- const PluginContext_1 = require("../../src/PluginContext");
23
+ const SessionDeviceLogs_1 = require("../../src/services/logcat/SessionDeviceLogs");
37
24
  const IPluginArgs_1 = require("../../src/interfaces/IPluginArgs");
38
- const device_managers_1 = require("../../src/device-managers");
39
- const device_store_1 = require("../../src/data-service/device-store");
40
- const prisma_store_1 = require("../../src/data-service/prisma-store");
41
- const SessionManager_1 = require("../../src/sessions/SessionManager");
42
- const RemoteSession_1 = require("../../src/sessions/RemoteSession");
43
- const appiumUmbrella_1 = require("../../src/sessions/appiumUmbrella");
44
- const config_1 = require("../../src/config");
45
- const container_registration_1 = require("../helpers/container-registration");
46
25
  const scratch_database_1 = require("../helpers/scratch-database");
47
26
  const selector_health_fixture_1 = require("../helpers/selector-health-fixture");
48
- const appium_umbrella_1 = require("../helpers/appium-umbrella");
27
+ const hub_node_pair_1 = require("../helpers/hub-node-pair");
49
28
  /**
50
29
  * A hub collects CPU and memory for a session on a node's phone from the
51
30
  * node: against a node in Appium 3's own server() (Appium's umbrella with
@@ -55,7 +34,6 @@ const appium_umbrella_1 = require("../helpers/appium-umbrella");
55
34
  * test drives; everything between it and the hub's writes is the real thing.
56
35
  */
57
36
  const quiet = { info: () => undefined, warn: () => undefined, error: () => undefined };
58
- const NODE_ID = 'node-1';
59
37
  /** The node's sampler service, its phone sampler replaced by one the test drives. */
60
38
  class NodeSideMetrics extends SessionMetricsService_1.SessionMetricsService {
61
39
  constructor() {
@@ -139,169 +117,27 @@ const at = (t) => ({
139
117
  describe('a hub collects a node session’s CPU and memory', function () {
140
118
  this.timeout(60000);
141
119
  const scratch = (0, scratch_database_1.useScratchDatabase)();
142
- const servers = [];
143
- let dirs;
144
- let hubKeys;
145
- let appiumLogs;
146
- let restore;
147
- let saved;
148
- let authDisabledBefore;
149
- let commandAuthBefore;
150
- let umbrella;
151
- let hubUrl;
152
- let nodeOrigin;
120
+ const pair = (0, hub_node_pair_1.useHubAndNode)(scratch, [
121
+ SessionMetricsService_1.SessionMetricsService,
122
+ NodeMetricsStore_1.NodeMetricsStore,
123
+ nodeMetrics_1.NodeMetricsSupport,
124
+ SessionDeviceLogs_1.SessionDeviceLogs,
125
+ ]);
153
126
  let nodeMetrics;
154
- before(() => __awaiter(this, void 0, void 0, function* () {
155
- appiumLogs = (0, appium_umbrella_1.quietAppiumLogs)();
156
- dirs = [fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), 'xenon-heartbeat-keys-'))];
157
- hubKeys = new JwtKeyService_1.JwtKeyService();
158
- yield hubKeys.init(dirs[0]);
159
- }));
160
- after(() => {
161
- appiumLogs.restore();
162
- for (const dir of dirs)
163
- fs_1.default.rmSync(dir, { recursive: true, force: true });
164
- });
165
- beforeEach(() => __awaiter(this, void 0, void 0, function* () {
166
- restore = (0, container_registration_1.saveRegistrations)(JwtKeyService_1.JwtKeyService, hubSessionToken_1.HubSessionTokenIssuer, device_managers_1.XenonManager, appiumUmbrella_1.AppiumUmbrella, nodeSessionStatus_1.NodeSessionProbeSupport, SessionMetricsService_1.SessionMetricsService, NodeMetricsStore_1.NodeMetricsStore, nodeMetrics_1.NodeMetricsSupport);
127
+ beforeEach(() => {
167
128
  nodeMetrics = new NodeSideMetrics();
168
129
  typedi_1.Container.set(SessionMetricsService_1.SessionMetricsService, nodeMetrics);
169
130
  typedi_1.Container.set(NodeMetricsStore_1.NodeMetricsStore, new NodeMetricsStore_1.NodeMetricsStore());
170
131
  typedi_1.Container.set(nodeMetrics_1.NodeMetricsSupport, new nodeMetrics_1.NodeMetricsSupport());
171
- // One process plays both sides: the hub's keys sign, the node checks them.
172
- typedi_1.Container.set(JwtKeyService_1.JwtKeyService, hubKeys);
173
- typedi_1.Container.set(hubSessionToken_1.HubSessionTokenIssuer, new hubSessionToken_1.HubSessionTokenIssuer());
174
- typedi_1.Container.set(appiumUmbrella_1.AppiumUmbrella, new appiumUmbrella_1.AppiumUmbrella());
175
- typedi_1.Container.set(nodeSessionStatus_1.NodeSessionProbeSupport, new nodeSessionStatus_1.NodeSessionProbeSupport());
176
- typedi_1.Container.set(device_managers_1.XenonManager, {
177
- getMaxSessionCount: () => undefined,
178
- deviceInstances: () => __awaiter(this, void 0, void 0, function* () { return []; }),
179
- });
180
- const context = typedi_1.Container.get(PluginContext_1.PluginContext);
181
- saved = {
182
- store: device_store_1.DeviceStoreFactory._deviceStore,
183
- pending: device_store_1.DeviceStoreFactory._pendingSessionStore,
184
- context: Object.assign({}, context),
185
- };
186
- device_store_1.DeviceStoreFactory._deviceStore = new prisma_store_1.PrismaDeviceStore();
187
- device_store_1.DeviceStoreFactory._pendingSessionStore = new prisma_store_1.PrismaPendingSessionStore();
188
- authDisabledBefore = config_1.config.authDisabled;
189
- config_1.config.authDisabled = false;
190
- // Per-command auth on: the node then takes the hub's token and nothing else.
191
- commandAuthBefore = process.env.XENON_REQUIRE_COMMAND_AUTH;
192
- process.env.XENON_REQUIRE_COMMAND_AUTH = '1';
193
- yield scratch.db.pendingSession.deleteMany({});
194
- yield scratch.db.device.deleteMany({});
195
- }));
196
- afterEach(() => __awaiter(this, void 0, void 0, function* () {
197
- for (const s of SessionManager_1.SESSION_MANAGER.getAllSessions())
198
- SessionManager_1.SESSION_MANAGER.removeSession(s.getId());
199
- device_store_1.DeviceStoreFactory._deviceStore = saved.store;
200
- device_store_1.DeviceStoreFactory._pendingSessionStore = saved.pending;
201
- Object.assign(typedi_1.Container.get(PluginContext_1.PluginContext), saved.context);
202
- config_1.config.authDisabled = authDisabledBefore;
203
- if (commandAuthBefore === undefined)
204
- delete process.env.XENON_REQUIRE_COMMAND_AUTH;
205
- else
206
- process.env.XENON_REQUIRE_COMMAND_AUTH = commandAuthBefore;
207
- sinon_1.default.restore();
208
- restore();
209
- for (const s of servers.splice(0)) {
210
- s.closeAllConnections();
211
- yield new Promise((resolve) => http_1.default.Server.prototype.close.call(s, () => resolve()));
212
- }
213
- }));
214
- const port = (s) => s.address().port;
215
- /** A hub (its public keys) and a node. */
216
- function boot() {
217
- return __awaiter(this, void 0, void 0, function* () {
218
- const baseDriver = (0, appium_umbrella_1.appiumBaseDriver)();
219
- const hubServer = yield baseDriver.server({
220
- routeConfiguringFunction: baseDriver.routeConfiguringFunction((0, appium_umbrella_1.umbrellaWith)([])),
221
- port: 0,
222
- hostname: '127.0.0.1',
223
- basePath: '/wd/hub',
224
- cliArgs: { basePath: '/wd/hub' },
225
- serverUpdaters: [
226
- (app) => {
227
- app.get('/xenon/api/auth/jwks.json', (_req, res) => res.json(hubKeys.jwks()));
228
- },
229
- ],
230
- });
231
- servers.push(hubServer);
232
- hubUrl = `http://127.0.0.1:${port(hubServer)}`;
233
- const pluginArgs = Object.assign(Object.assign({}, IPluginArgs_1.DefaultPluginArgs), { hub: hubUrl, bindHostOrIp: '127.0.0.1', enableDashboard: false, deviceAvailabilityTimeoutMs: 1000, deviceAvailabilityQueryIntervalMs: 100 });
234
- umbrella = (0, appium_umbrella_1.umbrellaWith)([[plugin_1.XenonPlugin, 'xenon']]);
235
- const nodeServer = yield baseDriver.server({
236
- routeConfiguringFunction: baseDriver.routeConfiguringFunction(umbrella),
237
- port: 0,
238
- hostname: '127.0.0.1',
239
- basePath: '/node',
240
- cliArgs: { basePath: '/node' },
241
- serverUpdaters: [
242
- (app) => {
243
- (0, registerCommandAuth_1.registerSessionGateway)(app, { basePath: '/node' }, (0, registerCommandAuth_1.commandAuthDeps)({ enabled: () => true, authDisabled: () => false, logger: quiet }), (0, defaultGateway_1.nodeGatewayOptions)(hubUrl));
244
- // What ServerManager mounts under /xenon/api on a node.
245
- const api = express_1.default.Router();
246
- (0, nodeSessionStatus_1.registerNodeSessionStatus)(api, pluginArgs);
247
- (0, nodeSessionMetrics_1.registerNodeSessionMetrics)(api, pluginArgs);
248
- app.use('/xenon/api', api);
249
- },
250
- ],
251
- });
252
- servers.push(nodeServer);
253
- nodeOrigin = `http://127.0.0.1:${port(nodeServer)}`;
254
- typedi_1.Container.get(PluginContext_1.PluginContext).setContext(pluginArgs, port(nodeServer), NODE_ID, '/node');
255
- yield scratch.db.device.create({
256
- data: {
257
- udid: 'phone-1',
258
- host: nodeOrigin,
259
- nodeId: NODE_ID,
260
- platform: 'android',
261
- name: 'phone-1',
262
- sdk: '14',
263
- busy: false,
264
- userBlocked: false,
265
- offline: false,
266
- },
267
- });
268
- });
269
- }
270
- /** A session on the node, created as the hub creates it. */
271
- function nodeSession() {
272
- return __awaiter(this, void 0, void 0, function* () {
273
- const token = yield typedi_1.Container.get(hubSessionToken_1.HubSessionTokenIssuer).createTokenFor({
274
- userId: 'alice',
275
- udid: 'phone-1',
276
- host: nodeOrigin,
277
- });
278
- const res = yield (0, loopbackRequest_1.default)(nodeOrigin)
279
- .post('/node/session')
280
- .set(hubSessionToken_1.HUB_TOKEN_HEADER, token)
281
- .send({
282
- capabilities: {
283
- alwaysMatch: {
284
- platformName: 'Android',
285
- 'appium:automationName': appium_umbrella_1.FAKE_AUTOMATION,
286
- 'appium:newCommandTimeout': 0,
287
- 'appium:udid': 'phone-1',
288
- 'xe:options': { recordVideo: false },
289
- },
290
- firstMatch: [{}],
291
- },
292
- });
293
- (0, chai_1.expect)(res.status, JSON.stringify(res.body)).to.equal(200);
294
- return res.body.value.sessionId;
132
+ // The node records the session's device log too; not here.
133
+ typedi_1.Container.set(SessionDeviceLogs_1.SessionDeviceLogs, {
134
+ start: () => __awaiter(this, void 0, void 0, function* () { return undefined; }),
135
+ stop: () => __awaiter(this, void 0, void 0, function* () { return undefined; }),
295
136
  });
296
- }
297
- /** The hub's object for that session. */
298
- const hubSide = (sessionId) => new RemoteSession_1.RemoteSession({
299
- sessionId,
300
- device: { udid: 'phone-1', host: nodeOrigin, nodeId: NODE_ID, platform: 'android' },
301
- sessionResponse: {},
302
- xenonOption: {},
303
- baseUrl: `${nodeOrigin}/node`,
304
137
  });
138
+ const boot = () => pair.boot();
139
+ const nodeSession = () => pair.nodeSession();
140
+ const hubSide = (sessionId) => pair.hubSide(sessionId);
305
141
  it("the hub collects a node session's figures as it runs, and the last ones when it ends", () => __awaiter(this, void 0, void 0, function* () {
306
142
  yield boot();
307
143
  const sessionId = yield nodeSession();
@@ -312,8 +148,8 @@ describe('a hub collects a node session’s CPU and memory', function () {
312
148
  const hub = new HubSideMetrics();
313
149
  const device = {
314
150
  udid: 'phone-1',
315
- host: nodeOrigin,
316
- nodeId: NODE_ID,
151
+ host: pair.nodeOrigin,
152
+ nodeId: hub_node_pair_1.NODE_ID,
317
153
  platform: 'android',
318
154
  realDevice: true,
319
155
  };
@@ -323,11 +159,7 @@ describe('a hub collects a node session’s CPU and memory', function () {
323
159
  yield until(() => hub.written.length === 0 &&
324
160
  typedi_1.Container.get(NodeMetricsStore_1.NodeMetricsStore).read(sessionId, null).samples.length === 0);
325
161
  nodeMetrics.hooks[0].onSample(at(3000));
326
- const token = yield typedi_1.Container.get(hubSessionToken_1.HubSessionTokenIssuer).tokenFor(sessionId);
327
- const del = yield (0, loopbackRequest_1.default)(nodeOrigin)
328
- .delete(`/node/session/${sessionId}`)
329
- .set(hubSessionToken_1.HUB_TOKEN_HEADER, token);
330
- (0, chai_1.expect)(del.status, JSON.stringify(del.body)).to.equal(200);
162
+ yield pair.deleteOnNode(sessionId);
331
163
  (0, chai_1.expect)(nodeMetrics.stopped).to.equal(1);
332
164
  (0, chai_1.expect)(typedi_1.Container.get(NodeMetricsStore_1.NodeMetricsStore).read(sessionId, 2000).state).to.equal('ended');
333
165
  yield hub.stop(sessionId);
@@ -347,7 +179,7 @@ describe('a hub collects a node session’s CPU and memory', function () {
347
179
  device_version: '14',
348
180
  desired_capabilities: '{}',
349
181
  session_capabilities: '{}',
350
- node_id: NODE_ID,
182
+ node_id: hub_node_pair_1.NODE_ID,
351
183
  has_live_video: false,
352
184
  status: 'running',
353
185
  },
@@ -355,8 +187,8 @@ describe('a hub collects a node session’s CPU and memory', function () {
355
187
  const hub = new HubStoringMetrics();
356
188
  const device = {
357
189
  udid: 'phone-1',
358
- host: nodeOrigin,
359
- nodeId: NODE_ID,
190
+ host: pair.nodeOrigin,
191
+ nodeId: hub_node_pair_1.NODE_ID,
360
192
  platform: 'android',
361
193
  realDevice: true,
362
194
  };
@@ -386,8 +218,8 @@ describe('a hub collects a node session’s CPU and memory', function () {
386
218
  const hub = new HubSideMetrics();
387
219
  const device = {
388
220
  udid: 'phone-1',
389
- host: nodeOrigin,
390
- nodeId: NODE_ID,
221
+ host: pair.nodeOrigin,
222
+ nodeId: hub_node_pair_1.NODE_ID,
391
223
  platform: 'android',
392
224
  realDevice: true,
393
225
  };
@@ -38,6 +38,7 @@ const RemoteSession_1 = require("../../src/sessions/RemoteSession");
38
38
  const appiumUmbrella_1 = require("../../src/sessions/appiumUmbrella");
39
39
  const XenonSession_1 = require("../../src/sessions/XenonSession");
40
40
  const config_1 = require("../../src/config");
41
+ const SessionDeviceLogs_1 = require("../../src/services/logcat/SessionDeviceLogs");
41
42
  const container_registration_1 = require("../helpers/container-registration");
42
43
  const scratch_database_1 = require("../helpers/scratch-database");
43
44
  const appium_umbrella_1 = require("../helpers/appium-umbrella");
@@ -80,12 +81,18 @@ describe('the hub’s heartbeat on a node’s session', function () {
80
81
  fs_1.default.rmSync(dir, { recursive: true, force: true });
81
82
  });
82
83
  beforeEach(() => __awaiter(this, void 0, void 0, function* () {
83
- restore = (0, container_registration_1.saveRegistrations)(JwtKeyService_1.JwtKeyService, hubSessionToken_1.HubSessionTokenIssuer, device_managers_1.XenonManager, appiumUmbrella_1.AppiumUmbrella, nodeSessionStatus_1.NodeSessionProbeSupport);
84
+ restore = (0, container_registration_1.saveRegistrations)(JwtKeyService_1.JwtKeyService, hubSessionToken_1.HubSessionTokenIssuer, device_managers_1.XenonManager, appiumUmbrella_1.AppiumUmbrella, nodeSessionStatus_1.NodeSessionProbeSupport, SessionDeviceLogs_1.SessionDeviceLogs);
84
85
  // One process plays both sides: the hub's keys sign, the node checks them.
85
86
  typedi_1.Container.set(JwtKeyService_1.JwtKeyService, hubKeys);
86
87
  typedi_1.Container.set(hubSessionToken_1.HubSessionTokenIssuer, new hubSessionToken_1.HubSessionTokenIssuer());
87
88
  typedi_1.Container.set(appiumUmbrella_1.AppiumUmbrella, new appiumUmbrella_1.AppiumUmbrella());
88
89
  typedi_1.Container.set(nodeSessionStatus_1.NodeSessionProbeSupport, new nodeSessionStatus_1.NodeSessionProbeSupport());
90
+ // A node records the device log of each session its hub creates; its
91
+ // phone here is a row, so nothing may reach this machine's adb.
92
+ typedi_1.Container.set(SessionDeviceLogs_1.SessionDeviceLogs, {
93
+ start: () => __awaiter(this, void 0, void 0, function* () { return undefined; }),
94
+ stop: () => __awaiter(this, void 0, void 0, function* () { return undefined; }),
95
+ });
89
96
  typedi_1.Container.set(device_managers_1.XenonManager, {
90
97
  getMaxSessionCount: () => undefined,
91
98
  deviceInstances: () => __awaiter(this, void 0, void 0, function* () { return []; }),