@g9tm/lynxcontrols-pilot 0.0.0-stage → 2.4.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/README.md +159 -2
- package/catalog/cards/G9PilotHost.md +16 -0
- package/catalog/cards/G9PilotMask.md +10 -0
- package/catalog/cards/G9PilotPanel.md +10 -0
- package/catalog/catalog.json +420 -0
- package/catalog/index.md +7 -0
- package/check/cli.mjs +5 -0
- package/check/index.mjs +137 -0
- package/check/index.test.mjs +180 -0
- package/config/cli.mjs +31 -0
- package/config/index.d.ts +62 -0
- package/config/index.mjs +380 -0
- package/config/index.test.mjs +406 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/anchors.d.ts +39 -0
- package/dist/anchors.d.ts.map +1 -0
- package/dist/anchors.jsx +103 -0
- package/dist/bridge.d.ts +4 -0
- package/dist/bridge.d.ts.map +1 -0
- package/dist/bridge.jsx +143 -0
- package/dist/busy.d.ts +4 -0
- package/dist/busy.d.ts.map +1 -0
- package/dist/busy.jsx +43 -0
- package/dist/commands.d.ts +24 -0
- package/dist/commands.d.ts.map +1 -0
- package/dist/commands.jsx +286 -0
- package/dist/consent.d.ts +51 -0
- package/dist/consent.d.ts.map +1 -0
- package/dist/consent.jsx +131 -0
- package/dist/explore.d.ts +36 -0
- package/dist/explore.d.ts.map +1 -0
- package/dist/explore.jsx +133 -0
- package/dist/flags.d.ts +69 -0
- package/dist/flags.d.ts.map +1 -0
- package/dist/flags.jsx +81 -0
- package/dist/host-core.d.ts +36 -0
- package/dist/host-core.d.ts.map +1 -0
- package/dist/host-core.jsx +90 -0
- package/dist/host-sink.d.ts +43 -0
- package/dist/host-sink.d.ts.map +1 -0
- package/dist/host-sink.jsx +87 -0
- package/dist/index-marks.d.ts +33 -0
- package/dist/index-marks.d.ts.map +1 -0
- package/dist/index-marks.jsx +40 -0
- package/dist/index-observe.d.ts +17 -0
- package/dist/index-observe.d.ts.map +1 -0
- package/dist/index-observe.jsx +14 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.jsx +11 -0
- package/dist/info.d.ts +10 -0
- package/dist/info.d.ts.map +1 -0
- package/dist/info.jsx +9 -0
- package/dist/kit.d.ts +67 -0
- package/dist/kit.d.ts.map +1 -0
- package/dist/kit.jsx +1 -0
- package/dist/layer.d.ts +4 -0
- package/dist/layer.d.ts.map +1 -0
- package/dist/layer.jsx +10 -0
- package/dist/layers.d.ts +4 -0
- package/dist/layers.d.ts.map +1 -0
- package/dist/layers.jsx +146 -0
- package/dist/mask.d.ts +20 -0
- package/dist/mask.d.ts.map +1 -0
- package/dist/mask.jsx +35 -0
- package/dist/net.d.ts +17 -0
- package/dist/net.d.ts.map +1 -0
- package/dist/net.jsx +60 -0
- package/dist/observe.d.ts +99 -0
- package/dist/observe.d.ts.map +1 -0
- package/dist/observe.jsx +194 -0
- package/dist/off.d.ts +45 -0
- package/dist/off.d.ts.map +1 -0
- package/dist/off.jsx +81 -0
- package/dist/otlp.d.ts +61 -0
- package/dist/otlp.d.ts.map +1 -0
- package/dist/otlp.jsx +141 -0
- package/dist/panel.d.ts +13 -0
- package/dist/panel.d.ts.map +1 -0
- package/dist/panel.jsx +182 -0
- package/dist/session.d.ts +42 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.jsx +115 -0
- package/dist/types.d.ts +47 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.jsx +1 -0
- package/dist/watch.d.ts +17 -0
- package/dist/watch.d.ts.map +1 -0
- package/dist/watch.jsx +165 -0
- package/doctor/cli.mjs +5 -0
- package/doctor/index.mjs +214 -0
- package/doctor/index.test.mjs +174 -0
- package/gradle/g9pilot.app.gradle +55 -0
- package/gradle/g9pilot.settings.gradle +27 -0
- package/ios/g9pilot.rb +47 -0
- package/package.json +66 -4
- package/rspeedy/index.d.ts +40 -0
- package/rspeedy/index.mjs +100 -0
- package/rspeedy/index.test.mjs +192 -0
package/check/index.mjs
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// `g9pilot-check <artifact> [--expect <profile>]`: proves on the built artifact what a build of @g9tm/lynxcontrols-pilot
|
|
3
|
+
// carries — the rule of the bridge's guide («prove it on the artifact»), for every profile. The artifact is a page
|
|
4
|
+
// bundle (`main.lynx.bundle`), a dist folder (its bundle and pilot-receipt.json), or an APK / AAB / IPA (a zip: its dex
|
|
5
|
+
// files, native binaries and the bundle inside). The profile to expect comes from --expect, else the receipt.
|
|
6
|
+
// off no trace of G9AppPilot at all
|
|
7
|
+
// marks the test ids' busy reasons may be there; no watch, no bridge
|
|
8
|
+
// observe the watch may be there; no transport
|
|
9
|
+
// support / full the transport MUST be there (a test build that silently lost its bridge is a failure too)
|
|
10
|
+
// Native side: an artifact without the bridge holds no `com/g9tm/apppilot` class (Android) and no G9Pilot module (iOS);
|
|
11
|
+
// one without DevTool holds no `com/lynx/devtool/` class (the core's `devtoolwrapper` interfaces are not DevTool).
|
|
12
|
+
// Plain Node, no dependencies: the zip is read with node:zlib.
|
|
13
|
+
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
|
|
14
|
+
import { join } from 'node:path';
|
|
15
|
+
import { inflateRawSync } from 'node:zlib';
|
|
16
|
+
|
|
17
|
+
/** What each level leaves in a bundle (strings a minifier keeps: command names and event kinds). */
|
|
18
|
+
export const MARKERS = Object.freeze({
|
|
19
|
+
marks: ['ui:sheet:open', 'ui:popup'],
|
|
20
|
+
observe: ['oracle.list', 'g9.report'],
|
|
21
|
+
// the transport's own report keys (transport.ts): ui.ts names the request event too, so it is not a marker
|
|
22
|
+
bridge: ['pilot.respond', 'pilot.dispatch'],
|
|
23
|
+
});
|
|
24
|
+
const NATIVE_BRIDGE = ['com/g9tm/apppilot/', 'G9PilotModule', 'G9PilotListener'];
|
|
25
|
+
// DevTool's own classes; the core's `LynxDevtool*` helpers and `devtoolwrapper` interfaces are in every Lynx build
|
|
26
|
+
const NATIVE_DEVTOOL = ['com/lynx/devtool/'];
|
|
27
|
+
const ORDER = ['off', 'marks', 'observe', 'support', 'full'];
|
|
28
|
+
|
|
29
|
+
/** The entries of a zip (name → bytes), stored or deflated; enough for APK, AAB and IPA. */
|
|
30
|
+
export function readZip(buffer) {
|
|
31
|
+
const out = new Map();
|
|
32
|
+
let end = buffer.length - 22;
|
|
33
|
+
while (end >= 0 && buffer.readUInt32LE(end) !== 0x06054b50) end--;
|
|
34
|
+
if (end < 0) throw new Error('not a zip (no end of central directory)');
|
|
35
|
+
const count = buffer.readUInt16LE(end + 10);
|
|
36
|
+
let at = buffer.readUInt32LE(end + 16);
|
|
37
|
+
for (let i = 0; i < count; i++) {
|
|
38
|
+
if (buffer.readUInt32LE(at) !== 0x02014b50) throw new Error('a broken zip directory');
|
|
39
|
+
const method = buffer.readUInt16LE(at + 10);
|
|
40
|
+
const size = buffer.readUInt32LE(at + 20);
|
|
41
|
+
const nameLength = buffer.readUInt16LE(at + 28);
|
|
42
|
+
const extra = buffer.readUInt16LE(at + 30);
|
|
43
|
+
const comment = buffer.readUInt16LE(at + 32);
|
|
44
|
+
const local = buffer.readUInt32LE(at + 42);
|
|
45
|
+
const name = buffer.toString('utf8', at + 46, at + 46 + nameLength);
|
|
46
|
+
const dataAt = local + 30 + buffer.readUInt16LE(local + 26) + buffer.readUInt16LE(local + 28);
|
|
47
|
+
const raw = buffer.subarray(dataAt, dataAt + size);
|
|
48
|
+
out.set(name, () => (method === 0 ? raw : method === 8 ? inflateRawSync(raw) : Buffer.alloc(0)));
|
|
49
|
+
at += 46 + nameLength + extra + comment;
|
|
50
|
+
}
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const has = (bytes, text) => bytes.includes(Buffer.from(text, 'latin1'));
|
|
55
|
+
|
|
56
|
+
/** What the artifact holds: which bundle levels and which native parts. */
|
|
57
|
+
export function inspect(path) {
|
|
58
|
+
const bundles = [];
|
|
59
|
+
const natives = [];
|
|
60
|
+
let receipt = null;
|
|
61
|
+
if (statSync(path).isDirectory()) {
|
|
62
|
+
for (const f of readdirSync(path)) {
|
|
63
|
+
if (f.endsWith('.bundle')) bundles.push(readFileSync(join(path, f)));
|
|
64
|
+
if (f === 'pilot-receipt.json') receipt = JSON.parse(readFileSync(join(path, f), 'utf8'));
|
|
65
|
+
}
|
|
66
|
+
} else if (/\.(apk|aab|ipa|zip)$/i.test(path)) {
|
|
67
|
+
for (const [name, open] of readZip(readFileSync(path))) {
|
|
68
|
+
if (name.endsWith('.bundle')) bundles.push(open());
|
|
69
|
+
else if (/(^|\/)classes\d*\.dex$|\.so$|(^|\/)Payload\/[^/]+\.app\/[^/.]+$|\/Frameworks\/.+\/[^/.]+$/.test(name))
|
|
70
|
+
natives.push(open());
|
|
71
|
+
}
|
|
72
|
+
} else {
|
|
73
|
+
bundles.push(readFileSync(path));
|
|
74
|
+
const beside = join(path, '..', 'pilot-receipt.json');
|
|
75
|
+
if (existsSync(beside)) receipt = JSON.parse(readFileSync(beside, 'utf8'));
|
|
76
|
+
}
|
|
77
|
+
const level = (markers) => bundles.some((b) => markers.some((m) => has(b, m)));
|
|
78
|
+
return {
|
|
79
|
+
bundles: bundles.length,
|
|
80
|
+
natives: natives.length,
|
|
81
|
+
receipt,
|
|
82
|
+
page: { marks: level(MARKERS.marks), observe: level(MARKERS.observe), bridge: level(MARKERS.bridge) },
|
|
83
|
+
native: {
|
|
84
|
+
bridge: natives.some((n) => NATIVE_BRIDGE.some((m) => has(n, m))),
|
|
85
|
+
devtool: natives.some((n) => NATIVE_DEVTOOL.some((m) => has(n, m))),
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** The problems of an inspected artifact against a profile (an empty list: it holds what the profile says). */
|
|
91
|
+
export function verdict(found, profile, { devtool } = {}) {
|
|
92
|
+
if (!ORDER.includes(profile)) return [`unknown profile "${profile}" (one of ${ORDER.join(', ')})`];
|
|
93
|
+
const problems = [];
|
|
94
|
+
const rank = ORDER.indexOf(profile);
|
|
95
|
+
if (found.bundles === 0) problems.push('no page bundle in the artifact');
|
|
96
|
+
if (rank < 1 && found.page.marks) problems.push('the bundle holds test ids (marks) — an off build must hold nothing');
|
|
97
|
+
if (rank < 2 && found.page.observe) problems.push('the bundle holds the watch (observe) — not in this profile');
|
|
98
|
+
if (rank < 3 && found.page.bridge)
|
|
99
|
+
problems.push('the bundle holds the TRANSPORT — the bridge is not in this profile');
|
|
100
|
+
if (rank >= 3 && !found.page.bridge && found.bundles > 0)
|
|
101
|
+
problems.push('the bundle lacks the transport its profile needs');
|
|
102
|
+
if (found.natives > 0) {
|
|
103
|
+
if (rank < 3 && found.native.bridge)
|
|
104
|
+
problems.push('the native code holds G9AppPilot’s bridge — not in this profile');
|
|
105
|
+
if (rank >= 3 && !found.native.bridge) problems.push('the native code lacks G9AppPilot’s bridge its profile needs');
|
|
106
|
+
if (devtool === false && found.native.devtool)
|
|
107
|
+
problems.push('the native code holds Lynx DevTool — not in this build');
|
|
108
|
+
}
|
|
109
|
+
return problems;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** The command line: `g9pilot-check <artifact> [--expect <profile>]` (check/cli.mjs is the bin). */
|
|
113
|
+
export function main(args) {
|
|
114
|
+
const path = args.find((a) => !a.startsWith('--') && args[args.indexOf(a) - 1] !== '--expect');
|
|
115
|
+
if (!path || !existsSync(path)) {
|
|
116
|
+
console.error(
|
|
117
|
+
'usage: g9pilot-check <bundle | dist folder | .apk | .aab | .ipa> [--expect off|marks|observe|support|full]',
|
|
118
|
+
);
|
|
119
|
+
process.exitCode = 2;
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const found = inspect(path);
|
|
123
|
+
const at = args.indexOf('--expect');
|
|
124
|
+
const profile = at >= 0 ? args[at + 1] : found.receipt?.profile;
|
|
125
|
+
if (!profile) {
|
|
126
|
+
console.error('g9pilot-check: no --expect and no pilot-receipt.json beside the bundle');
|
|
127
|
+
process.exitCode = 2;
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
const devtool = found.receipt ? found.receipt.native?.devtool === true : profile === 'full' ? undefined : false;
|
|
131
|
+
const problems = verdict(found, profile, { devtool });
|
|
132
|
+
for (const p of problems) console.error(`FAIL ${p}`);
|
|
133
|
+
console.log(
|
|
134
|
+
`${problems.length ? 'FAIL' : 'ok '} ${path}: profile ${profile}; page ${['marks', 'observe', 'bridge'].filter((k) => found.page[k]).join(' + ') || 'none'}; native ${found.natives ? ['bridge', 'devtool'].filter((k) => found.native[k]).join(' + ') || 'none' : 'n/a'}`,
|
|
135
|
+
);
|
|
136
|
+
process.exitCode = problems.length ? 1 : 0;
|
|
137
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import test from 'node:test';
|
|
6
|
+
import { deflateRawSync } from 'node:zlib';
|
|
7
|
+
import { inspect, MARKERS, main, readZip, verdict } from './index.mjs';
|
|
8
|
+
|
|
9
|
+
/** A minimal zip writer (stored or deflated entries): enough to stand in for an APK or an IPA. */
|
|
10
|
+
function zip(entries) {
|
|
11
|
+
const locals = [];
|
|
12
|
+
const centrals = [];
|
|
13
|
+
let offset = 0;
|
|
14
|
+
for (const [name, text, deflate] of entries) {
|
|
15
|
+
const raw = Buffer.from(text, 'latin1');
|
|
16
|
+
const data = deflate ? deflateRawSync(raw) : raw;
|
|
17
|
+
const n = Buffer.from(name);
|
|
18
|
+
const local = Buffer.alloc(30);
|
|
19
|
+
local.writeUInt32LE(0x04034b50, 0);
|
|
20
|
+
local.writeUInt16LE(deflate ? 8 : 0, 8);
|
|
21
|
+
local.writeUInt32LE(data.length, 18);
|
|
22
|
+
local.writeUInt32LE(raw.length, 22);
|
|
23
|
+
local.writeUInt16LE(n.length, 26);
|
|
24
|
+
const central = Buffer.alloc(46);
|
|
25
|
+
central.writeUInt32LE(0x02014b50, 0);
|
|
26
|
+
central.writeUInt16LE(deflate ? 8 : 0, 10);
|
|
27
|
+
central.writeUInt32LE(data.length, 20);
|
|
28
|
+
central.writeUInt32LE(raw.length, 24);
|
|
29
|
+
central.writeUInt16LE(n.length, 28);
|
|
30
|
+
central.writeUInt32LE(offset, 42);
|
|
31
|
+
locals.push(local, n, data);
|
|
32
|
+
centrals.push(central, n);
|
|
33
|
+
offset += 30 + n.length + data.length;
|
|
34
|
+
}
|
|
35
|
+
const dir = Buffer.concat(centrals);
|
|
36
|
+
const end = Buffer.alloc(22);
|
|
37
|
+
end.writeUInt32LE(0x06054b50, 0);
|
|
38
|
+
end.writeUInt16LE(entries.length, 10);
|
|
39
|
+
end.writeUInt32LE(dir.length, 12);
|
|
40
|
+
end.writeUInt32LE(offset, 16);
|
|
41
|
+
return Buffer.concat([...locals, dir, end]);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const page = (...levels) => `var a=1;${levels.flatMap((l) => MARKERS[l]).join(';')}`;
|
|
45
|
+
|
|
46
|
+
function withDir(run) {
|
|
47
|
+
const dir = mkdtempSync(join(tmpdir(), 'g9pilot-check-'));
|
|
48
|
+
try {
|
|
49
|
+
return run(dir);
|
|
50
|
+
} finally {
|
|
51
|
+
rmSync(dir, { recursive: true, force: true });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
test('readZip: stored and deflated entries; anything else is refused', () => {
|
|
56
|
+
const entries = readZip(
|
|
57
|
+
zip([
|
|
58
|
+
['a.txt', 'plain'],
|
|
59
|
+
['b.txt', 'squeezed text', true],
|
|
60
|
+
]),
|
|
61
|
+
);
|
|
62
|
+
assert.equal(entries.get('a.txt')().toString(), 'plain');
|
|
63
|
+
assert.equal(entries.get('b.txt')().toString(), 'squeezed text');
|
|
64
|
+
assert.throws(() => readZip(Buffer.from('not a zip at all, sorry')), /not a zip/);
|
|
65
|
+
const broken = zip([['a', 'x']]);
|
|
66
|
+
broken.writeUInt32LE(0, broken.length - 22 + 16 - 0); // the directory now points at the local header
|
|
67
|
+
assert.throws(() => readZip(broken), /broken zip directory/);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('verdict: what each profile may and must hold', () => {
|
|
71
|
+
const found = (page, native = null) => ({
|
|
72
|
+
bundles: 1,
|
|
73
|
+
natives: native ? 1 : 0,
|
|
74
|
+
receipt: null,
|
|
75
|
+
page,
|
|
76
|
+
native: native ?? { bridge: false, devtool: false },
|
|
77
|
+
});
|
|
78
|
+
const none = { marks: false, observe: false, bridge: false };
|
|
79
|
+
const all = { marks: true, observe: true, bridge: true };
|
|
80
|
+
assert.deepEqual(verdict(found(none), 'off'), []);
|
|
81
|
+
assert.match(verdict(found({ ...none, marks: true }), 'off')[0], /test ids/);
|
|
82
|
+
assert.deepEqual(verdict(found({ ...none, marks: true }), 'marks'), []);
|
|
83
|
+
assert.match(verdict(found({ marks: true, observe: true, bridge: false }), 'marks')[0], /the watch/);
|
|
84
|
+
assert.match(verdict(found(all), 'observe')[0], /TRANSPORT/);
|
|
85
|
+
assert.deepEqual(verdict(found(all, { bridge: true, devtool: true }), 'full'), []);
|
|
86
|
+
assert.match(verdict(found({ marks: true, observe: true, bridge: false }), 'support')[0], /lacks the transport/);
|
|
87
|
+
assert.match(verdict(found(none, { bridge: true, devtool: false }), 'off')[0], /bridge — not in this profile/);
|
|
88
|
+
assert.match(verdict(found(all, { bridge: false, devtool: false }), 'support')[0], /lacks G9AppPilot’s bridge/);
|
|
89
|
+
assert.match(verdict(found(all, { bridge: true, devtool: true }), 'support', { devtool: false })[0], /DevTool/);
|
|
90
|
+
assert.match(verdict({ ...found(none), bundles: 0 }, 'off')[0], /no page bundle/);
|
|
91
|
+
assert.match(verdict(found(none), 'max')[0], /unknown profile/);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test('inspect: a bundle (with or without its receipt), a dist folder, an APK and an IPA', () =>
|
|
95
|
+
withDir((dir) => {
|
|
96
|
+
const dist = join(dir, 'dist');
|
|
97
|
+
mkdirSync(dist);
|
|
98
|
+
writeFileSync(join(dist, 'main.lynx.bundle'), page('marks'));
|
|
99
|
+
assert.deepEqual(inspect(join(dist, 'main.lynx.bundle')).page, { marks: true, observe: false, bridge: false });
|
|
100
|
+
assert.equal(inspect(join(dist, 'main.lynx.bundle')).receipt, null);
|
|
101
|
+
writeFileSync(join(dist, 'pilot-receipt.json'), JSON.stringify({ profile: 'marks', native: { devtool: false } }));
|
|
102
|
+
assert.equal(inspect(dist).receipt.profile, 'marks');
|
|
103
|
+
assert.equal(inspect(join(dist, 'main.lynx.bundle')).receipt.profile, 'marks');
|
|
104
|
+
const apk = join(dir, 'app.apk');
|
|
105
|
+
writeFileSync(
|
|
106
|
+
apk,
|
|
107
|
+
zip([
|
|
108
|
+
['assets/main.lynx.bundle', page('marks', 'observe', 'bridge'), true],
|
|
109
|
+
['classes.dex', 'Lcom/g9tm/apppilot/G9Pilot;Lcom/lynx/devtool/LynxDevtoolEnv;'],
|
|
110
|
+
['classes2.dex', 'Lcom/lynx/devtoolwrapper/DevToolSettings;LynxDevtoolGlobalHelper'],
|
|
111
|
+
['res/raw/other.txt', 'nothing'],
|
|
112
|
+
]),
|
|
113
|
+
);
|
|
114
|
+
const a = inspect(apk);
|
|
115
|
+
assert.deepEqual([a.bundles, a.natives, a.native], [1, 2, { bridge: true, devtool: true }]);
|
|
116
|
+
const store = join(dir, 'store.apk');
|
|
117
|
+
writeFileSync(
|
|
118
|
+
store,
|
|
119
|
+
zip([
|
|
120
|
+
['assets/main.lynx.bundle', page()],
|
|
121
|
+
['classes.dex', 'Lcom/lynx/devtoolwrapper/X;LynxDevtoolCardListener'],
|
|
122
|
+
]),
|
|
123
|
+
);
|
|
124
|
+
assert.deepEqual(inspect(store).native, { bridge: false, devtool: false });
|
|
125
|
+
const ipa = join(dir, 'app.ipa');
|
|
126
|
+
writeFileSync(
|
|
127
|
+
ipa,
|
|
128
|
+
zip([
|
|
129
|
+
['Payload/Shop.app/main.lynx.bundle', page()],
|
|
130
|
+
['Payload/Shop.app/Shop', 'G9PilotModule'],
|
|
131
|
+
]),
|
|
132
|
+
);
|
|
133
|
+
assert.deepEqual(inspect(ipa).native, { bridge: true, devtool: false });
|
|
134
|
+
}));
|
|
135
|
+
|
|
136
|
+
test('the command line: an expectation, a receipt, and what it says when it has neither', () =>
|
|
137
|
+
withDir((dir) => {
|
|
138
|
+
const logs = [];
|
|
139
|
+
const errors = [];
|
|
140
|
+
const log = console.log;
|
|
141
|
+
const error = console.error;
|
|
142
|
+
console.log = (m) => logs.push(m);
|
|
143
|
+
console.error = (m) => errors.push(m);
|
|
144
|
+
try {
|
|
145
|
+
const bundle = join(dir, 'main.lynx.bundle');
|
|
146
|
+
writeFileSync(bundle, page('marks', 'observe', 'bridge'));
|
|
147
|
+
main([bundle, '--expect', 'full']);
|
|
148
|
+
assert.equal(process.exitCode, 0);
|
|
149
|
+
assert.match(logs.at(-1), /^ok {3}.*profile full; page marks \+ observe \+ bridge; native n\/a/);
|
|
150
|
+
main([bundle, '--expect', 'off']);
|
|
151
|
+
assert.equal(process.exitCode, 1);
|
|
152
|
+
assert.match(errors.at(-1), /TRANSPORT/);
|
|
153
|
+
main([bundle]);
|
|
154
|
+
assert.equal(process.exitCode, 2);
|
|
155
|
+
assert.match(errors.at(-1), /no --expect and no pilot-receipt\.json/);
|
|
156
|
+
main([]);
|
|
157
|
+
assert.equal(process.exitCode, 2);
|
|
158
|
+
assert.match(errors.at(-1), /^usage:/);
|
|
159
|
+
writeFileSync(join(dir, 'pilot-receipt.json'), JSON.stringify({ profile: 'full', native: { devtool: true } }));
|
|
160
|
+
main([dir]);
|
|
161
|
+
assert.equal(process.exitCode, 0);
|
|
162
|
+
const apk = join(dir, 'a.apk');
|
|
163
|
+
writeFileSync(
|
|
164
|
+
apk,
|
|
165
|
+
zip([
|
|
166
|
+
['assets/main.lynx.bundle', page()],
|
|
167
|
+
['classes.dex', 'Lcom/lynx/devtool/X;'],
|
|
168
|
+
]),
|
|
169
|
+
);
|
|
170
|
+
main([apk, '--expect', 'off']);
|
|
171
|
+
assert.equal(process.exitCode, 1);
|
|
172
|
+
assert.match(errors.at(-1), /Lynx DevTool/);
|
|
173
|
+
main([apk, '--expect', 'full']);
|
|
174
|
+
assert.match(errors.join('\n'), /lacks the transport/);
|
|
175
|
+
} finally {
|
|
176
|
+
console.log = log;
|
|
177
|
+
console.error = error;
|
|
178
|
+
process.exitCode = 0;
|
|
179
|
+
}
|
|
180
|
+
}));
|
package/config/cli.mjs
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// `node config/cli.mjs [--env <name>] [--from <dir>] [--format json|gradle|native]`: the resolved g9pilot.config.json for
|
|
3
|
+
// the native builds, which cannot import ESM. Gradle and CocoaPods call it at configuration time.
|
|
4
|
+
// json the whole resolved configuration
|
|
5
|
+
// gradle key=value lines: profile, bridge, devtool, port (what decides the project and the dependencies)
|
|
6
|
+
// native the host's PilotConfig as JSON (environment, port, keys with the build's scope ceiling, signatureRequired,
|
|
7
|
+
// lan, consent, selfDrive): what a host packs as an asset and reads at start
|
|
8
|
+
import { G9PilotConfigError, loadPilotConfig, nativePilotConfig } from './index.mjs';
|
|
9
|
+
|
|
10
|
+
const args = process.argv.slice(2);
|
|
11
|
+
const flag = (name) => {
|
|
12
|
+
const i = args.indexOf(`--${name}`);
|
|
13
|
+
return i >= 0 ? args[i + 1] : undefined;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
const { file, resolved } = loadPilotConfig({ from: flag('from'), environment: flag('env') });
|
|
18
|
+
const format = flag('format') ?? 'json';
|
|
19
|
+
if (format === 'json') console.log(JSON.stringify({ file, ...resolved }, null, 2));
|
|
20
|
+
else if (format === 'gradle') {
|
|
21
|
+
console.log(`profile=${resolved.profile}`);
|
|
22
|
+
console.log(`bridge=${resolved.native.bridge}`);
|
|
23
|
+
console.log(`devtool=${resolved.native.devtool}`);
|
|
24
|
+
console.log(`port=${resolved.port}`);
|
|
25
|
+
console.log(`file=${file ?? ''}`);
|
|
26
|
+
} else if (format === 'native') console.log(JSON.stringify(nativePilotConfig(resolved)));
|
|
27
|
+
else throw new G9PilotConfigError(`unknown --format ${format} (json, gradle, native)`);
|
|
28
|
+
} catch (e) {
|
|
29
|
+
console.error(e instanceof G9PilotConfigError ? e.message : (e?.stack ?? String(e)));
|
|
30
|
+
process.exit(1);
|
|
31
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/** The profiles, from nothing to everything. */
|
|
2
|
+
export type G9PilotProfileName = 'off' | 'marks' | 'observe' | 'support' | 'full';
|
|
3
|
+
/** The scopes a key may hold. */
|
|
4
|
+
export type G9PilotScopeName = 'observe' | 'drive' | 'stage' | 'design' | 'write' | 'admin';
|
|
5
|
+
|
|
6
|
+
export declare const PROFILES: readonly G9PilotProfileName[];
|
|
7
|
+
export declare const SCOPES: readonly G9PilotScopeName[];
|
|
8
|
+
/** Every page module a profile can carry. */
|
|
9
|
+
export declare const MODULES: readonly string[];
|
|
10
|
+
|
|
11
|
+
/** A configuration mistake a build must not guess around. */
|
|
12
|
+
export declare class G9PilotConfigError extends Error {}
|
|
13
|
+
|
|
14
|
+
/** One build environment of g9pilot.config.json, resolved. */
|
|
15
|
+
export interface G9PilotResolved {
|
|
16
|
+
readonly environment: string | null;
|
|
17
|
+
readonly profile: G9PilotProfileName;
|
|
18
|
+
readonly distribution: 'store' | 'test';
|
|
19
|
+
readonly modules: Readonly<Record<string, boolean>>;
|
|
20
|
+
/** The keys the bridge trusts, each limited to the build's ceiling (empty without a bridge). */
|
|
21
|
+
readonly keys: ReadonlyArray<{
|
|
22
|
+
readonly kid: string;
|
|
23
|
+
readonly publicKey: string;
|
|
24
|
+
readonly scopes: readonly G9PilotScopeName[];
|
|
25
|
+
}>;
|
|
26
|
+
readonly maxScopes: readonly G9PilotScopeName[];
|
|
27
|
+
readonly signatureRequired: boolean;
|
|
28
|
+
readonly port: number;
|
|
29
|
+
/** false: the bridge listens on loopback only (adb forward, a relay inside the app, self-drive). */
|
|
30
|
+
readonly lan: boolean;
|
|
31
|
+
readonly badge: 'off' | 'remote' | 'realDeviceOrRemote' | 'always';
|
|
32
|
+
readonly consent: 'none' | 'session' | 'escalation';
|
|
33
|
+
/** secret: screenshots black out password fields and <G9PilotMask> boxes. */
|
|
34
|
+
readonly mask: 'off' | 'secret';
|
|
35
|
+
readonly session: { readonly maxMinutes: number };
|
|
36
|
+
readonly selfDrive: { readonly maxSeconds: number };
|
|
37
|
+
readonly observe: Readonly<Record<string, unknown>>;
|
|
38
|
+
readonly native: { readonly bridge: boolean; readonly devtool: boolean };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Resolves one environment of a parsed configuration (none → off); throws G9PilotConfigError on a mistake. */
|
|
42
|
+
export declare function resolvePilotConfig(
|
|
43
|
+
config: unknown,
|
|
44
|
+
environment: string | null | undefined,
|
|
45
|
+
options?: { readonly baseDir?: string },
|
|
46
|
+
): G9PilotResolved;
|
|
47
|
+
/** g9pilot.config.json found from `from` upward, parsed, or null. */
|
|
48
|
+
export declare function findPilotConfig(from?: string): { readonly file: string; readonly config: unknown } | null;
|
|
49
|
+
/** The environment a build names: the argument, else G9_PILOT_ENV, else none. */
|
|
50
|
+
export declare function pilotEnvironment(
|
|
51
|
+
explicit?: string | null,
|
|
52
|
+
env?: Record<string, string | undefined>,
|
|
53
|
+
): string | null;
|
|
54
|
+
/** Find, then resolve. */
|
|
55
|
+
export declare function loadPilotConfig(options?: { readonly from?: string; readonly environment?: string | null }): {
|
|
56
|
+
readonly file: string | null;
|
|
57
|
+
readonly resolved: G9PilotResolved;
|
|
58
|
+
};
|
|
59
|
+
/** The page-side constants a bundle is built with. */
|
|
60
|
+
export declare function pilotDefines(resolved: G9PilotResolved): Record<string, string>;
|
|
61
|
+
/** What the native bridge needs (the host's PilotConfig). */
|
|
62
|
+
export declare function nativePilotConfig(resolved: G9PilotResolved): Record<string, unknown>;
|