@g9tm/app-diagnostic 0.2.0 → 0.2.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.
- package/package.json +20 -12
- package/src/bytes.ts +48 -48
- package/src/host.ts +124 -124
- package/src/index.ts +30 -30
- package/src/live/bundle.ts +77 -77
- package/src/live/channel.ts +496 -496
- package/src/live/handlers.ts +426 -426
- package/src/live/models.ts +366 -360
- package/src/live/upload.ts +175 -175
- package/src/recording.ts +176 -176
- package/src/store.ts +39 -39
- package/src/strings.generated.ts +242 -242
- package/src/strings.ts +37 -37
- package/src/tester/archive.ts +83 -83
- package/src/tester/compose.ts +99 -99
- package/src/tester/feed.ts +182 -182
- package/src/tester/gesture.ts +61 -61
- package/src/tester/model.ts +125 -125
- package/src/tester/outbox.ts +131 -131
- package/src/tester/screen.ts +117 -117
- package/src/tester/store.ts +145 -145
- package/src/tester/timeline.ts +98 -98
- package/src/upload.ts +236 -236
- package/src/wire.ts +133 -133
package/src/wire.ts
CHANGED
|
@@ -1,133 +1,133 @@
|
|
|
1
|
-
// The live channel's wire (shared/schema/live-channel.schema.json): the profile both sides must agree on byte for byte,
|
|
2
|
-
// the device hub's method and listener names, the capabilities, the transfer sizes. The TypeScript twin of
|
|
3
|
-
// G9AppDiagnostic.Shared (DiagnosticWire, ProtocolVersion, Hubs/HubMethodNames, IDeviceHubListeners, DeviceCapabilities).
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* The strings a device and its gateway must agree on: the protocol tag Hello is judged by (and every signature is bound
|
|
7
|
-
* to), the device hub's route, the magic of a password-encrypted backup, the bootstrap envelope's kind. A product that ran
|
|
8
|
-
* an earlier gateway keeps its own values (its devices carry them); a new product takes {@link NEUTRAL_WIRE}.
|
|
9
|
-
*/
|
|
10
|
-
export interface DiagnosticWireProfile {
|
|
11
|
-
/** Printable ASCII, 8-40 characters. */
|
|
12
|
-
readonly protocolTag: string;
|
|
13
|
-
/** Relative to the gateway's base address, no slash. */
|
|
14
|
-
readonly deviceHubRoute: string;
|
|
15
|
-
/** Exactly 16 printable ASCII characters. */
|
|
16
|
-
readonly backupMagic: string;
|
|
17
|
-
readonly bootstrapKind: string;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const NEUTRAL_WIRE: DiagnosticWireProfile = {
|
|
21
|
-
protocolTag: 'G9_LIVE_DIAG_v1',
|
|
22
|
-
deviceHubRoute: 'device-hub',
|
|
23
|
-
backupMagic: 'G9_APPD_BPASS_v2',
|
|
24
|
-
bootstrapKind: 'G9_LIVE_DIAG_BOOTSTRAP_v1',
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
/** The neutral header the hub connection carries the protocol tag in (an earlier product keeps its own). */
|
|
28
|
-
export const NEUTRAL_PROTOCOL_HEADER = 'X-G9-Protocol';
|
|
29
|
-
|
|
30
|
-
/** The protocol major a client of this package speaks (ProtocolVersion.CurrentMajor). */
|
|
31
|
-
export const PROTOCOL_MAJOR = 1;
|
|
32
|
-
|
|
33
|
-
const ascii = (s: string): boolean => s.length > 0 && /^[\x21-\x7e]+$/.test(s);
|
|
34
|
-
|
|
35
|
-
/** Throws when a value cannot work on the wire (the .NET DiagnosticWireProfile.Validate, rule for rule). */
|
|
36
|
-
export function validateWire(p: DiagnosticWireProfile): void {
|
|
37
|
-
if (!ascii(p.protocolTag) || p.protocolTag.length < 8 || p.protocolTag.length > 40) throw new Error('protocolTag: 8-40 printable ASCII characters.');
|
|
38
|
-
if (!ascii(p.deviceHubRoute) || p.deviceHubRoute.indexOf('/') >= 0) throw new Error('deviceHubRoute: printable ASCII, no slash.');
|
|
39
|
-
if (!ascii(p.backupMagic) || p.backupMagic.length !== 16) throw new Error('backupMagic: exactly 16 printable ASCII characters.');
|
|
40
|
-
if (!ascii(p.bootstrapKind)) throw new Error('bootstrapKind: printable ASCII.');
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const same = (a: DiagnosticWireProfile, b: DiagnosticWireProfile): boolean =>
|
|
44
|
-
a.protocolTag === b.protocolTag && a.deviceHubRoute === b.deviceHubRoute && a.backupMagic === b.backupMagic && a.bootstrapKind === b.bootstrapKind;
|
|
45
|
-
|
|
46
|
-
let current: DiagnosticWireProfile = NEUTRAL_WIRE;
|
|
47
|
-
let set = false;
|
|
48
|
-
|
|
49
|
-
/** The profile in force: {@link NEUTRAL_WIRE} until {@link useWire} is called. */
|
|
50
|
-
export const currentWire = (): DiagnosticWireProfile => current;
|
|
51
|
-
|
|
52
|
-
/** Sets the profile, once, at startup. A second call with other values throws: a process speaks one profile. */
|
|
53
|
-
export function useWire(profile: DiagnosticWireProfile): void {
|
|
54
|
-
validateWire(profile);
|
|
55
|
-
if (set && !same(current, profile)) throw new Error('The diagnostic wire profile is already set to other values.');
|
|
56
|
-
current = { ...profile };
|
|
57
|
-
set = true;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/** Tests only: back to the neutral profile. */
|
|
61
|
-
export function resetWireForTests(): void {
|
|
62
|
-
current = NEUTRAL_WIRE;
|
|
63
|
-
set = false;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/** The device hub's URL for a gateway base address ("https://gw.example/" → "https://gw.example/device-hub"). */
|
|
67
|
-
export function hubUrlOf(gateway: string, profile: DiagnosticWireProfile = current): string {
|
|
68
|
-
return `${gateway.replace(/\/+$/, '')}/${profile.deviceHubRoute}`;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/** Device → gateway (DeviceHubMethods; the schema's x-methods). */
|
|
72
|
-
export const DeviceHubMethods = {
|
|
73
|
-
hello: 'Hello',
|
|
74
|
-
announcePresence: 'AnnouncePresence',
|
|
75
|
-
announceForeground: 'AnnounceForeground',
|
|
76
|
-
pong: 'Pong',
|
|
77
|
-
pushLogBatch: 'PushLogBatch',
|
|
78
|
-
pushScreenshot: 'PushScreenshot',
|
|
79
|
-
reportScreenshotError: 'ReportScreenshotError',
|
|
80
|
-
pushCpuSample: 'PushCpuSample',
|
|
81
|
-
pushSqlResult: 'PushSqlResult',
|
|
82
|
-
pushQaResult: 'PushQaResult',
|
|
83
|
-
pushLogFileList: 'PushLogFileList',
|
|
84
|
-
pushLogFileContent: 'PushLogFileContent',
|
|
85
|
-
pushSyncHealth: 'PushSyncHealth',
|
|
86
|
-
pushSyncCacheCleared: 'PushSyncCacheCleared',
|
|
87
|
-
pushSyncRunResult: 'PushSyncRunResult',
|
|
88
|
-
pushNfcWriteResult: 'PushNfcWriteResult',
|
|
89
|
-
pushRestoreResult: 'PushRestoreResult',
|
|
90
|
-
pushRestoreReady: 'PushRestoreReady',
|
|
91
|
-
backupUploadInit: 'BackupUploadInit',
|
|
92
|
-
backupUploadStream: 'BackupUploadStream',
|
|
93
|
-
backupUploadComplete: 'BackupUploadComplete',
|
|
94
|
-
} as const;
|
|
95
|
-
|
|
96
|
-
/** Gateway → device (IDeviceHubListeners; the schema's x-listeners). */
|
|
97
|
-
export const DeviceHubListeners = {
|
|
98
|
-
roleChallengeIssued: 'OnRoleChallengeIssuedAsync',
|
|
99
|
-
peerConnected: 'OnPeerConnectedAsync',
|
|
100
|
-
peerDisconnected: 'OnPeerDisconnectedAsync',
|
|
101
|
-
sealedFromPeer: 'OnSealedFromPeerAsync',
|
|
102
|
-
expandOverlay: 'OnExpandOverlayRequestAsync',
|
|
103
|
-
uploadProgress: 'OnUploadProgressAsync',
|
|
104
|
-
downloadProgress: 'OnDownloadProgressAsync',
|
|
105
|
-
screenshotRequest: 'OnScreenshotRequestAsync',
|
|
106
|
-
backupRequest: 'OnBackupRequestAsync',
|
|
107
|
-
backupCancelled: 'OnBackupCancelledAsync',
|
|
108
|
-
sqlRequest: 'OnSqlRequestAsync',
|
|
109
|
-
logFileListRequest: 'OnLogFileListRequestAsync',
|
|
110
|
-
logFileReadRequest: 'OnLogFileReadRequestAsync',
|
|
111
|
-
ping: 'OnPingAsync',
|
|
112
|
-
restoreBegin: 'OnRestoreBeginAsync',
|
|
113
|
-
restoreResume: 'OnRestoreResumeAsync',
|
|
114
|
-
restoreChunk: 'OnRestoreChunkAsync',
|
|
115
|
-
restoreComplete: 'OnRestoreCompleteAsync',
|
|
116
|
-
remoteInput: 'OnRemoteInputAsync',
|
|
117
|
-
syncHealthRequest: 'OnSyncHealthRequestAsync',
|
|
118
|
-
clearSyncCacheRequest: 'OnClearSyncCacheRequestAsync',
|
|
119
|
-
runSyncRequest: 'OnRunSyncRequestAsync',
|
|
120
|
-
nfcWriteRequest: 'OnNfcWriteRequestAsync',
|
|
121
|
-
qaCommand: 'OnQaCommandAsync',
|
|
122
|
-
deviceSettingsChanged: 'OnDeviceSettingsChangedAsync',
|
|
123
|
-
} as const;
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* What this client build serves (DeviceCapabilities.Current). The contract: absent = the client predates the tag = not
|
|
127
|
-
* capable, so a request it cannot answer fails fast at the gateway instead of timing out.
|
|
128
|
-
*/
|
|
129
|
-
export const DeviceCapabilities = { logFiles: 'logfiles' } as const;
|
|
130
|
-
export const CURRENT_CAPABILITIES: readonly string[] = [DeviceCapabilities.logFiles];
|
|
131
|
-
|
|
132
|
-
/** The archive upload over the hub (x-transfer): 256 KiB per stream item, 4 MiB per stream call. */
|
|
133
|
-
export const TRANSFER = { chunkBytes: 256 * 1024, segmentBytes: 4 * 1024 * 1024, busyRetries: 6, busyDelayMs: 1500 } as const;
|
|
1
|
+
// The live channel's wire (shared/schema/live-channel.schema.json): the profile both sides must agree on byte for byte,
|
|
2
|
+
// the device hub's method and listener names, the capabilities, the transfer sizes. The TypeScript twin of
|
|
3
|
+
// G9AppDiagnostic.Shared (DiagnosticWire, ProtocolVersion, Hubs/HubMethodNames, IDeviceHubListeners, DeviceCapabilities).
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The strings a device and its gateway must agree on: the protocol tag Hello is judged by (and every signature is bound
|
|
7
|
+
* to), the device hub's route, the magic of a password-encrypted backup, the bootstrap envelope's kind. A product that ran
|
|
8
|
+
* an earlier gateway keeps its own values (its devices carry them); a new product takes {@link NEUTRAL_WIRE}.
|
|
9
|
+
*/
|
|
10
|
+
export interface DiagnosticWireProfile {
|
|
11
|
+
/** Printable ASCII, 8-40 characters. */
|
|
12
|
+
readonly protocolTag: string;
|
|
13
|
+
/** Relative to the gateway's base address, no slash. */
|
|
14
|
+
readonly deviceHubRoute: string;
|
|
15
|
+
/** Exactly 16 printable ASCII characters. */
|
|
16
|
+
readonly backupMagic: string;
|
|
17
|
+
readonly bootstrapKind: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const NEUTRAL_WIRE: DiagnosticWireProfile = {
|
|
21
|
+
protocolTag: 'G9_LIVE_DIAG_v1',
|
|
22
|
+
deviceHubRoute: 'device-hub',
|
|
23
|
+
backupMagic: 'G9_APPD_BPASS_v2',
|
|
24
|
+
bootstrapKind: 'G9_LIVE_DIAG_BOOTSTRAP_v1',
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/** The neutral header the hub connection carries the protocol tag in (an earlier product keeps its own). */
|
|
28
|
+
export const NEUTRAL_PROTOCOL_HEADER = 'X-G9-Protocol';
|
|
29
|
+
|
|
30
|
+
/** The protocol major a client of this package speaks (ProtocolVersion.CurrentMajor). */
|
|
31
|
+
export const PROTOCOL_MAJOR = 1;
|
|
32
|
+
|
|
33
|
+
const ascii = (s: string): boolean => s.length > 0 && /^[\x21-\x7e]+$/.test(s);
|
|
34
|
+
|
|
35
|
+
/** Throws when a value cannot work on the wire (the .NET DiagnosticWireProfile.Validate, rule for rule). */
|
|
36
|
+
export function validateWire(p: DiagnosticWireProfile): void {
|
|
37
|
+
if (!ascii(p.protocolTag) || p.protocolTag.length < 8 || p.protocolTag.length > 40) throw new Error('protocolTag: 8-40 printable ASCII characters.');
|
|
38
|
+
if (!ascii(p.deviceHubRoute) || p.deviceHubRoute.indexOf('/') >= 0) throw new Error('deviceHubRoute: printable ASCII, no slash.');
|
|
39
|
+
if (!ascii(p.backupMagic) || p.backupMagic.length !== 16) throw new Error('backupMagic: exactly 16 printable ASCII characters.');
|
|
40
|
+
if (!ascii(p.bootstrapKind)) throw new Error('bootstrapKind: printable ASCII.');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const same = (a: DiagnosticWireProfile, b: DiagnosticWireProfile): boolean =>
|
|
44
|
+
a.protocolTag === b.protocolTag && a.deviceHubRoute === b.deviceHubRoute && a.backupMagic === b.backupMagic && a.bootstrapKind === b.bootstrapKind;
|
|
45
|
+
|
|
46
|
+
let current: DiagnosticWireProfile = NEUTRAL_WIRE;
|
|
47
|
+
let set = false;
|
|
48
|
+
|
|
49
|
+
/** The profile in force: {@link NEUTRAL_WIRE} until {@link useWire} is called. */
|
|
50
|
+
export const currentWire = (): DiagnosticWireProfile => current;
|
|
51
|
+
|
|
52
|
+
/** Sets the profile, once, at startup. A second call with other values throws: a process speaks one profile. */
|
|
53
|
+
export function useWire(profile: DiagnosticWireProfile): void {
|
|
54
|
+
validateWire(profile);
|
|
55
|
+
if (set && !same(current, profile)) throw new Error('The diagnostic wire profile is already set to other values.');
|
|
56
|
+
current = { ...profile };
|
|
57
|
+
set = true;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Tests only: back to the neutral profile. */
|
|
61
|
+
export function resetWireForTests(): void {
|
|
62
|
+
current = NEUTRAL_WIRE;
|
|
63
|
+
set = false;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** The device hub's URL for a gateway base address ("https://gw.example/" → "https://gw.example/device-hub"). */
|
|
67
|
+
export function hubUrlOf(gateway: string, profile: DiagnosticWireProfile = current): string {
|
|
68
|
+
return `${gateway.replace(/\/+$/, '')}/${profile.deviceHubRoute}`;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Device → gateway (DeviceHubMethods; the schema's x-methods). */
|
|
72
|
+
export const DeviceHubMethods = {
|
|
73
|
+
hello: 'Hello',
|
|
74
|
+
announcePresence: 'AnnouncePresence',
|
|
75
|
+
announceForeground: 'AnnounceForeground',
|
|
76
|
+
pong: 'Pong',
|
|
77
|
+
pushLogBatch: 'PushLogBatch',
|
|
78
|
+
pushScreenshot: 'PushScreenshot',
|
|
79
|
+
reportScreenshotError: 'ReportScreenshotError',
|
|
80
|
+
pushCpuSample: 'PushCpuSample',
|
|
81
|
+
pushSqlResult: 'PushSqlResult',
|
|
82
|
+
pushQaResult: 'PushQaResult',
|
|
83
|
+
pushLogFileList: 'PushLogFileList',
|
|
84
|
+
pushLogFileContent: 'PushLogFileContent',
|
|
85
|
+
pushSyncHealth: 'PushSyncHealth',
|
|
86
|
+
pushSyncCacheCleared: 'PushSyncCacheCleared',
|
|
87
|
+
pushSyncRunResult: 'PushSyncRunResult',
|
|
88
|
+
pushNfcWriteResult: 'PushNfcWriteResult',
|
|
89
|
+
pushRestoreResult: 'PushRestoreResult',
|
|
90
|
+
pushRestoreReady: 'PushRestoreReady',
|
|
91
|
+
backupUploadInit: 'BackupUploadInit',
|
|
92
|
+
backupUploadStream: 'BackupUploadStream',
|
|
93
|
+
backupUploadComplete: 'BackupUploadComplete',
|
|
94
|
+
} as const;
|
|
95
|
+
|
|
96
|
+
/** Gateway → device (IDeviceHubListeners; the schema's x-listeners). */
|
|
97
|
+
export const DeviceHubListeners = {
|
|
98
|
+
roleChallengeIssued: 'OnRoleChallengeIssuedAsync',
|
|
99
|
+
peerConnected: 'OnPeerConnectedAsync',
|
|
100
|
+
peerDisconnected: 'OnPeerDisconnectedAsync',
|
|
101
|
+
sealedFromPeer: 'OnSealedFromPeerAsync',
|
|
102
|
+
expandOverlay: 'OnExpandOverlayRequestAsync',
|
|
103
|
+
uploadProgress: 'OnUploadProgressAsync',
|
|
104
|
+
downloadProgress: 'OnDownloadProgressAsync',
|
|
105
|
+
screenshotRequest: 'OnScreenshotRequestAsync',
|
|
106
|
+
backupRequest: 'OnBackupRequestAsync',
|
|
107
|
+
backupCancelled: 'OnBackupCancelledAsync',
|
|
108
|
+
sqlRequest: 'OnSqlRequestAsync',
|
|
109
|
+
logFileListRequest: 'OnLogFileListRequestAsync',
|
|
110
|
+
logFileReadRequest: 'OnLogFileReadRequestAsync',
|
|
111
|
+
ping: 'OnPingAsync',
|
|
112
|
+
restoreBegin: 'OnRestoreBeginAsync',
|
|
113
|
+
restoreResume: 'OnRestoreResumeAsync',
|
|
114
|
+
restoreChunk: 'OnRestoreChunkAsync',
|
|
115
|
+
restoreComplete: 'OnRestoreCompleteAsync',
|
|
116
|
+
remoteInput: 'OnRemoteInputAsync',
|
|
117
|
+
syncHealthRequest: 'OnSyncHealthRequestAsync',
|
|
118
|
+
clearSyncCacheRequest: 'OnClearSyncCacheRequestAsync',
|
|
119
|
+
runSyncRequest: 'OnRunSyncRequestAsync',
|
|
120
|
+
nfcWriteRequest: 'OnNfcWriteRequestAsync',
|
|
121
|
+
qaCommand: 'OnQaCommandAsync',
|
|
122
|
+
deviceSettingsChanged: 'OnDeviceSettingsChangedAsync',
|
|
123
|
+
} as const;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* What this client build serves (DeviceCapabilities.Current). The contract: absent = the client predates the tag = not
|
|
127
|
+
* capable, so a request it cannot answer fails fast at the gateway instead of timing out.
|
|
128
|
+
*/
|
|
129
|
+
export const DeviceCapabilities = { logFiles: 'logfiles' } as const;
|
|
130
|
+
export const CURRENT_CAPABILITIES: readonly string[] = [DeviceCapabilities.logFiles];
|
|
131
|
+
|
|
132
|
+
/** The archive upload over the hub (x-transfer): 256 KiB per stream item, 4 MiB per stream call. */
|
|
133
|
+
export const TRANSFER = { chunkBytes: 256 * 1024, segmentBytes: 4 * 1024 * 1024, busyRetries: 6, busyDelayMs: 1500 } as const;
|