@matter/testing 0.18.0 → 0.18.1-alpha.0-20261111-b84c5d1bc
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/dist/cjs/chip/app-reference.d.ts +41 -0
- package/dist/cjs/chip/app-reference.d.ts.map +1 -0
- package/dist/cjs/chip/app-reference.js +83 -0
- package/dist/cjs/chip/app-reference.js.map +6 -0
- package/dist/cjs/chip/cert/cert-context.d.ts +4 -2
- package/dist/cjs/chip/cert/cert-context.d.ts.map +1 -1
- package/dist/cjs/chip/cert/cert-context.js.map +1 -1
- package/dist/cjs/chip/cert/cert-dsl.d.ts +7 -1
- package/dist/cjs/chip/cert/cert-dsl.d.ts.map +1 -1
- package/dist/cjs/chip/cert/cert-dsl.js +4 -1
- package/dist/cjs/chip/cert/cert-dsl.js.map +1 -1
- package/dist/cjs/chip/cert/cert-test.d.ts.map +1 -1
- package/dist/cjs/chip/cert/cert-test.js +5 -18
- package/dist/cjs/chip/cert/cert-test.js.map +1 -1
- package/dist/cjs/chip/cert/chip-app-subject.d.ts.map +1 -1
- package/dist/cjs/chip/cert/chip-app-subject.js +23 -7
- package/dist/cjs/chip/cert/chip-app-subject.js.map +1 -1
- package/dist/cjs/chip/cert/controller-adapter.d.ts +89 -18
- package/dist/cjs/chip/cert/controller-adapter.d.ts.map +1 -1
- package/dist/cjs/chip/cert/controller-adapter.js +1 -3
- package/dist/cjs/chip/cert/controller-adapter.js.map +1 -1
- package/dist/cjs/chip/cert/evidence.d.ts +3 -3
- package/dist/cjs/chip/cert/evidence.js +1 -1
- package/dist/cjs/chip/cert/log-follower.d.ts +10 -0
- package/dist/cjs/chip/cert/log-follower.d.ts.map +1 -1
- package/dist/cjs/chip/cert/log-follower.js +48 -21
- package/dist/cjs/chip/cert/log-follower.js.map +1 -1
- package/dist/cjs/chip/cert/prompt-driven-python-test.js +1 -1
- package/dist/cjs/chip/cert/prompt-driven-python-test.js.map +1 -1
- package/dist/cjs/chip/cert/step-actions.d.ts +2 -3
- package/dist/cjs/chip/cert/step-actions.d.ts.map +1 -1
- package/dist/cjs/chip/cert/step-actions.js +3 -27
- package/dist/cjs/chip/cert/step-actions.js.map +1 -1
- package/dist/cjs/chip/index.d.ts +2 -1
- package/dist/cjs/chip/index.d.ts.map +1 -1
- package/dist/cjs/chip/index.js +2 -0
- package/dist/cjs/chip/index.js.map +1 -1
- package/dist/cjs/chip/python-test.d.ts +5 -0
- package/dist/cjs/chip/python-test.d.ts.map +1 -1
- package/dist/cjs/chip/python-test.js +12 -1
- package/dist/cjs/chip/python-test.js.map +1 -1
- package/dist/cjs/chip/state.d.ts.map +1 -1
- package/dist/cjs/chip/state.js +4 -1
- package/dist/cjs/chip/state.js.map +1 -1
- package/dist/cjs/device/backchannel.d.ts +10 -1
- package/dist/cjs/device/backchannel.d.ts.map +1 -1
- package/dist/cjs/test-descriptor.d.ts +4 -1
- package/dist/cjs/test-descriptor.d.ts.map +1 -1
- package/dist/cjs/test-descriptor.js.map +1 -1
- package/dist/cjs/util/async.d.ts +1 -0
- package/dist/cjs/util/async.d.ts.map +1 -1
- package/dist/cjs/util/async.js +1 -0
- package/dist/cjs/util/async.js.map +1 -1
- package/dist/esm/chip/app-reference.d.ts +41 -0
- package/dist/esm/chip/app-reference.d.ts.map +1 -0
- package/dist/esm/chip/app-reference.js +63 -0
- package/dist/esm/chip/app-reference.js.map +6 -0
- package/dist/esm/chip/cert/cert-context.d.ts +4 -2
- package/dist/esm/chip/cert/cert-context.d.ts.map +1 -1
- package/dist/esm/chip/cert/cert-context.js.map +1 -1
- package/dist/esm/chip/cert/cert-dsl.d.ts +7 -1
- package/dist/esm/chip/cert/cert-dsl.d.ts.map +1 -1
- package/dist/esm/chip/cert/cert-dsl.js +4 -1
- package/dist/esm/chip/cert/cert-dsl.js.map +1 -1
- package/dist/esm/chip/cert/cert-test.d.ts.map +1 -1
- package/dist/esm/chip/cert/cert-test.js +5 -18
- package/dist/esm/chip/cert/cert-test.js.map +1 -1
- package/dist/esm/chip/cert/chip-app-subject.d.ts.map +1 -1
- package/dist/esm/chip/cert/chip-app-subject.js +23 -7
- package/dist/esm/chip/cert/chip-app-subject.js.map +1 -1
- package/dist/esm/chip/cert/controller-adapter.d.ts +89 -18
- package/dist/esm/chip/cert/controller-adapter.d.ts.map +1 -1
- package/dist/esm/chip/cert/controller-adapter.js +1 -3
- package/dist/esm/chip/cert/controller-adapter.js.map +1 -1
- package/dist/esm/chip/cert/evidence.d.ts +3 -3
- package/dist/esm/chip/cert/evidence.js +1 -1
- package/dist/esm/chip/cert/log-follower.d.ts +10 -0
- package/dist/esm/chip/cert/log-follower.d.ts.map +1 -1
- package/dist/esm/chip/cert/log-follower.js +49 -22
- package/dist/esm/chip/cert/log-follower.js.map +1 -1
- package/dist/esm/chip/cert/prompt-driven-python-test.js +1 -1
- package/dist/esm/chip/cert/prompt-driven-python-test.js.map +1 -1
- package/dist/esm/chip/cert/step-actions.d.ts +2 -3
- package/dist/esm/chip/cert/step-actions.d.ts.map +1 -1
- package/dist/esm/chip/cert/step-actions.js +3 -29
- package/dist/esm/chip/cert/step-actions.js.map +1 -1
- package/dist/esm/chip/index.d.ts +2 -1
- package/dist/esm/chip/index.d.ts.map +1 -1
- package/dist/esm/chip/index.js +2 -0
- package/dist/esm/chip/index.js.map +1 -1
- package/dist/esm/chip/python-test.d.ts +5 -0
- package/dist/esm/chip/python-test.d.ts.map +1 -1
- package/dist/esm/chip/python-test.js +12 -1
- package/dist/esm/chip/python-test.js.map +1 -1
- package/dist/esm/chip/state.d.ts.map +1 -1
- package/dist/esm/chip/state.js +4 -1
- package/dist/esm/chip/state.js.map +1 -1
- package/dist/esm/device/backchannel.d.ts +10 -1
- package/dist/esm/device/backchannel.d.ts.map +1 -1
- package/dist/esm/test-descriptor.d.ts +4 -1
- package/dist/esm/test-descriptor.d.ts.map +1 -1
- package/dist/esm/test-descriptor.js.map +1 -1
- package/dist/esm/util/async.d.ts +1 -0
- package/dist/esm/util/async.d.ts.map +1 -1
- package/dist/esm/util/async.js +1 -0
- package/dist/esm/util/async.js.map +1 -1
- package/package.json +5 -5
- package/src/chip/app-reference.ts +91 -0
- package/src/chip/cert/cert-context.ts +4 -2
- package/src/chip/cert/cert-dsl.ts +16 -4
- package/src/chip/cert/cert-test.ts +7 -33
- package/src/chip/cert/chip-app-subject.ts +35 -10
- package/src/chip/cert/controller-adapter.ts +104 -22
- package/src/chip/cert/evidence.ts +3 -3
- package/src/chip/cert/log-follower.ts +58 -23
- package/src/chip/cert/prompt-driven-python-test.ts +1 -1
- package/src/chip/cert/step-actions.ts +5 -32
- package/src/chip/index.ts +3 -0
- package/src/chip/python-test.ts +18 -1
- package/src/chip/state.ts +6 -2
- package/src/device/backchannel.ts +11 -0
- package/src/test-descriptor.ts +4 -1
- package/src/util/async.ts +1 -1
- package/test/chip/AppReferenceTest.ts +113 -0
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import { delay } from "../../util/async.js";
|
|
7
|
+
import { delay, MAX_TIMEOUT_MS } from "../../util/async.js";
|
|
8
8
|
import { deansify } from "../../util/text.js";
|
|
9
9
|
import type { DeviceFlavor, LogSource } from "./cert-context.js";
|
|
10
10
|
|
|
@@ -16,6 +16,13 @@ const DEFAULT_TIMEOUT_MS = 30_000;
|
|
|
16
16
|
export interface LogLine {
|
|
17
17
|
index: number;
|
|
18
18
|
at: Date;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* When the follower took the line in, on the monotonic clock (`performance.now()`, milliseconds). Use it for the
|
|
22
|
+
* time between two lines; {@link at} follows wall-clock steps.
|
|
23
|
+
*/
|
|
24
|
+
receivedAt: number;
|
|
25
|
+
|
|
19
26
|
text: string;
|
|
20
27
|
/** Set on a line added via {@link LogFollower.annotate} — never matched by {@link LogFollower.expect}. */
|
|
21
28
|
synthetic?: true;
|
|
@@ -153,15 +160,12 @@ export class LogFollower implements LogSource {
|
|
|
153
160
|
#closed = false;
|
|
154
161
|
#closeError?: Error;
|
|
155
162
|
#waiters = new Array<() => void>();
|
|
156
|
-
#
|
|
157
|
-
#
|
|
163
|
+
#isClosing = false;
|
|
164
|
+
#stopConsuming?: () => void;
|
|
158
165
|
#pump: Promise<void>;
|
|
159
166
|
|
|
160
167
|
constructor(source: AsyncIterable<string>, name: string) {
|
|
161
168
|
this.name = name;
|
|
162
|
-
this.#closeSignal = new Promise<void>(resolve => {
|
|
163
|
-
this.#resolveCloseSignal = resolve;
|
|
164
|
-
});
|
|
165
169
|
this.#pump = this.#consume(source);
|
|
166
170
|
}
|
|
167
171
|
|
|
@@ -172,7 +176,13 @@ export class LogFollower implements LogSource {
|
|
|
172
176
|
* satisfying a step's own pattern.
|
|
173
177
|
*/
|
|
174
178
|
annotate(text: string): void {
|
|
175
|
-
this.#lines.push({
|
|
179
|
+
this.#lines.push({
|
|
180
|
+
index: this.#lines.length,
|
|
181
|
+
at: new Date(),
|
|
182
|
+
receivedAt: performance.now(),
|
|
183
|
+
text,
|
|
184
|
+
synthetic: true,
|
|
185
|
+
});
|
|
176
186
|
this.#wake();
|
|
177
187
|
}
|
|
178
188
|
|
|
@@ -226,6 +236,14 @@ export class LogFollower implements LogSource {
|
|
|
226
236
|
await delay(0).promise;
|
|
227
237
|
}
|
|
228
238
|
|
|
239
|
+
/**
|
|
240
|
+
* Whether the source has ended, by {@link close} or because the process behind it stopped writing. Lines
|
|
241
|
+
* already taken in stay readable; no further line arrives.
|
|
242
|
+
*/
|
|
243
|
+
get closed(): boolean {
|
|
244
|
+
return this.#closed;
|
|
245
|
+
}
|
|
246
|
+
|
|
229
247
|
/**
|
|
230
248
|
* Every line seen so far, in arrival order. A fresh copy on each access — callers cannot
|
|
231
249
|
* mutate the follower's own buffer through it. Prefer {@link count} and {@link lastMatchBefore}
|
|
@@ -330,14 +348,23 @@ export class LogFollower implements LogSource {
|
|
|
330
348
|
async expectPattern(original: RegExp, options: Omit<LogExpectOptions, "flavor">): Promise<LogLine> {
|
|
331
349
|
const pattern = matchableCopy(original);
|
|
332
350
|
const from = options.from ?? this.#lastMark;
|
|
333
|
-
|
|
351
|
+
let timedOut = false;
|
|
352
|
+
const timer = setTimeout(
|
|
353
|
+
() => {
|
|
354
|
+
timedOut = true;
|
|
355
|
+
this.#wake();
|
|
356
|
+
},
|
|
357
|
+
Math.min(options.timeoutMs ?? DEFAULT_TIMEOUT_MS, MAX_TIMEOUT_MS),
|
|
358
|
+
);
|
|
359
|
+
let next = from;
|
|
334
360
|
|
|
335
361
|
try {
|
|
336
362
|
for (;;) {
|
|
337
|
-
const matched = this.#firstMatchFrom(pattern,
|
|
363
|
+
const matched = this.#firstMatchFrom(pattern, next);
|
|
338
364
|
if (matched) {
|
|
339
365
|
return matched;
|
|
340
366
|
}
|
|
367
|
+
next = Math.max(next, this.#lines.length);
|
|
341
368
|
|
|
342
369
|
if (this.#closeError) {
|
|
343
370
|
throw this.#closeError;
|
|
@@ -346,13 +373,13 @@ export class LogFollower implements LogSource {
|
|
|
346
373
|
throw new CertLogClosedError(this.name);
|
|
347
374
|
}
|
|
348
375
|
|
|
349
|
-
|
|
350
|
-
if (outcome === "timeout") {
|
|
376
|
+
if (timedOut) {
|
|
351
377
|
throw new CertLogTimeoutError(String(original), from, this.#lines.slice(from));
|
|
352
378
|
}
|
|
379
|
+
await this.#waitForWake();
|
|
353
380
|
}
|
|
354
381
|
} finally {
|
|
355
|
-
|
|
382
|
+
clearTimeout(timer);
|
|
356
383
|
}
|
|
357
384
|
}
|
|
358
385
|
|
|
@@ -361,7 +388,8 @@ export class LogFollower implements LogSource {
|
|
|
361
388
|
}
|
|
362
389
|
|
|
363
390
|
async close(): Promise<void> {
|
|
364
|
-
this.#
|
|
391
|
+
this.#isClosing = true;
|
|
392
|
+
this.#stopConsuming?.();
|
|
365
393
|
await this.#pump;
|
|
366
394
|
}
|
|
367
395
|
|
|
@@ -413,26 +441,33 @@ export class LogFollower implements LogSource {
|
|
|
413
441
|
}
|
|
414
442
|
}
|
|
415
443
|
|
|
416
|
-
//
|
|
417
|
-
//
|
|
444
|
+
// close() ends the wait for the next line at once, without forcing the source's iterator closed (which
|
|
445
|
+
// could hang on a source parked mid-await). Nothing attached per line may outlive that line.
|
|
418
446
|
// Never rethrows: failures land on #closeError for expect() to surface, so #pump always
|
|
419
447
|
// resolves and close() has nothing to catch.
|
|
420
448
|
async #consume(source: AsyncIterable<string>): Promise<void> {
|
|
421
449
|
const iterator = source[Symbol.asyncIterator]();
|
|
422
450
|
try {
|
|
423
|
-
|
|
424
|
-
const
|
|
425
|
-
|
|
426
|
-
this.#
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
451
|
+
while (!this.#isClosing) {
|
|
452
|
+
const next = iterator.next();
|
|
453
|
+
const result = await new Promise<IteratorResult<string> | undefined>((resolve, reject) => {
|
|
454
|
+
this.#stopConsuming = () => resolve(undefined);
|
|
455
|
+
next.then(resolve, reject);
|
|
456
|
+
});
|
|
457
|
+
this.#stopConsuming = undefined;
|
|
458
|
+
|
|
459
|
+
if (result === undefined || result.done) {
|
|
430
460
|
return;
|
|
431
461
|
}
|
|
432
462
|
|
|
433
463
|
// chip binaries colorize log output even when stdout isn't a TTY; a trailing ANSI reset
|
|
434
464
|
// sequence after the visible text breaks any pattern anchored on end-of-line ($).
|
|
435
|
-
this.#lines.push({
|
|
465
|
+
this.#lines.push({
|
|
466
|
+
index: this.#lines.length,
|
|
467
|
+
at: new Date(),
|
|
468
|
+
receivedAt: performance.now(),
|
|
469
|
+
text: deansify(result.value),
|
|
470
|
+
});
|
|
436
471
|
this.#wake();
|
|
437
472
|
}
|
|
438
473
|
} catch (e) {
|
|
@@ -85,7 +85,7 @@ export class PromptDrivenPythonTest extends PythonTest {
|
|
|
85
85
|
let handled = 0;
|
|
86
86
|
try {
|
|
87
87
|
for await (let line of terminal) {
|
|
88
|
-
this.#log.push({ index: this.#log.length, at: new Date(), text: line });
|
|
88
|
+
this.#log.push({ index: this.#log.length, at: new Date(), receivedAt: performance.now(), text: line });
|
|
89
89
|
|
|
90
90
|
line = parseStep(line, step);
|
|
91
91
|
|
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
CertIcdClientApi,
|
|
11
11
|
CertNodeApi,
|
|
12
12
|
ControllerAdapter,
|
|
13
|
-
UnsupportedByControllerError,
|
|
14
13
|
WebRtcRequestorApi,
|
|
15
14
|
} from "./controller-adapter.js";
|
|
16
15
|
|
|
@@ -62,6 +61,7 @@ const NODE: Classified<CertNodeApi> = {
|
|
|
62
61
|
scriptOtaProvider: "none",
|
|
63
62
|
openCommissioningWindow: "action",
|
|
64
63
|
decommission: "action",
|
|
64
|
+
updateOperationalCertificate: "action",
|
|
65
65
|
operationalMdnsInstanceName: "none",
|
|
66
66
|
};
|
|
67
67
|
|
|
@@ -92,6 +92,7 @@ const CONTROLLER: Classified<ControllerAdapter> = {
|
|
|
92
92
|
commission: "action",
|
|
93
93
|
parseQrPayload: "none",
|
|
94
94
|
parseManualPairingCode: "none",
|
|
95
|
+
discoverCommissionableNodes: "none",
|
|
95
96
|
node: { handle: NODE },
|
|
96
97
|
group: { handle: GROUP },
|
|
97
98
|
webRtcRequestor: { handle: WEB_RTC_REQUESTOR },
|
|
@@ -102,12 +103,10 @@ const CONTROLLER: Classified<ControllerAdapter> = {
|
|
|
102
103
|
/**
|
|
103
104
|
* Counts the controller calls of the current step that may change a device.
|
|
104
105
|
*
|
|
105
|
-
* A call counts when it starts, so one still running when the step ends is counted, and
|
|
106
|
-
*
|
|
107
|
-
* that fails otherwise stays counted, since its request may have reached the device.
|
|
106
|
+
* A call counts when it starts, so one still running when the step ends is counted, and one that fails stays
|
|
107
|
+
* counted, since its request may have reached the device.
|
|
108
108
|
*/
|
|
109
109
|
export class StepActions {
|
|
110
|
-
#step = 0;
|
|
111
110
|
#count = 0;
|
|
112
111
|
|
|
113
112
|
get count() {
|
|
@@ -115,7 +114,6 @@ export class StepActions {
|
|
|
115
114
|
}
|
|
116
115
|
|
|
117
116
|
nextStep() {
|
|
118
|
-
this.#step++;
|
|
119
117
|
this.#count = 0;
|
|
120
118
|
}
|
|
121
119
|
|
|
@@ -135,7 +133,7 @@ export class StepActions {
|
|
|
135
133
|
if (typeof member === "function") {
|
|
136
134
|
return (...args: unknown[]) => {
|
|
137
135
|
if (classification === "action") {
|
|
138
|
-
|
|
136
|
+
this.#count++;
|
|
139
137
|
}
|
|
140
138
|
const result: unknown = Reflect.apply(member, target, args);
|
|
141
139
|
return typeof classification === "object" && isApi(result)
|
|
@@ -149,31 +147,6 @@ export class StepActions {
|
|
|
149
147
|
},
|
|
150
148
|
});
|
|
151
149
|
}
|
|
152
|
-
|
|
153
|
-
#act(call: () => unknown): unknown {
|
|
154
|
-
const step = this.#step;
|
|
155
|
-
this.#count++;
|
|
156
|
-
const refused = (error: unknown) => {
|
|
157
|
-
if (error instanceof UnsupportedByControllerError && step === this.#step) {
|
|
158
|
-
this.#count--;
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
let result: unknown;
|
|
163
|
-
try {
|
|
164
|
-
result = call();
|
|
165
|
-
} catch (error) {
|
|
166
|
-
refused(error);
|
|
167
|
-
throw error;
|
|
168
|
-
}
|
|
169
|
-
if (result instanceof Promise) {
|
|
170
|
-
return result.catch((error: unknown) => {
|
|
171
|
-
refused(error);
|
|
172
|
-
throw error;
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
return result;
|
|
176
|
-
}
|
|
177
150
|
}
|
|
178
151
|
|
|
179
152
|
/** An API object to wrap, as opposed to a value or a promise of one, which a Proxy would break. */
|
package/src/chip/index.ts
CHANGED
|
@@ -107,11 +107,13 @@ export type {
|
|
|
107
107
|
CertSessionInfo,
|
|
108
108
|
ClientAttributePath,
|
|
109
109
|
ClientEndpointEntry,
|
|
110
|
+
CommissionableNodeFilter,
|
|
110
111
|
CommissioningTarget,
|
|
111
112
|
ControllerAdapter,
|
|
112
113
|
ControllerAdapterFactory,
|
|
113
114
|
ControllerAdapterOptions,
|
|
114
115
|
ControllerTransport,
|
|
116
|
+
DiscoveredCommissionableNode,
|
|
115
117
|
EventPathSpec,
|
|
116
118
|
EventReadEntry,
|
|
117
119
|
ManualPairingCodeFields,
|
|
@@ -181,6 +183,7 @@ export type { ChipBinsSource, EnsureChipBinsResult } from "./chip-bins.js";
|
|
|
181
183
|
export { parseDockerHubTagsResponse, resetChipBinsPrepareCacheForTesting } from "./chip-bins.js";
|
|
182
184
|
/** @internal Test seam — not API. */
|
|
183
185
|
export type { ChipBinsDockerHandle } from "./chip-bins.js";
|
|
186
|
+
export { UnresolvedAppPlaceholderError } from "./app-reference.js";
|
|
184
187
|
export { HarnessBusyError } from "./harness-lock.js";
|
|
185
188
|
/** @internal Test seam — not API. Exported for the Docker-backed lock test in support/chip-testing. */
|
|
186
189
|
export { acquireHarnessLock } from "./harness-lock.js";
|
package/src/chip/python-test.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { BaseTest } from "../device/test.js";
|
|
|
11
11
|
import type { Container } from "../docker/container.js";
|
|
12
12
|
import { Terminal } from "../docker/terminal.js";
|
|
13
13
|
import { TestFileDescriptor } from "../test-descriptor.js";
|
|
14
|
+
import { expandAppPlaceholders } from "./app-reference.js";
|
|
14
15
|
import { parseStep } from "./chip-test-common.js";
|
|
15
16
|
import { Constants, ContainerPaths } from "./config.js";
|
|
16
17
|
import { PicsSource } from "./pics/source.js";
|
|
@@ -253,6 +254,11 @@ export function spiffy(line: string) {
|
|
|
253
254
|
* or the test will not run. So we must extract these arguments to pass into the script.
|
|
254
255
|
*
|
|
255
256
|
* A program defining mandatory arguments to itself seems silly but we work with what we've got amiright?
|
|
257
|
+
*
|
|
258
|
+
* App placeholders in those arguments, such as `${TV_APP}`, are expanded to container paths; `extraArgs` are passed
|
|
259
|
+
* as given.
|
|
260
|
+
*
|
|
261
|
+
* @throws UnresolvedAppPlaceholderError if a placeholder names no executable app in the container
|
|
256
262
|
*/
|
|
257
263
|
export async function createCommand(
|
|
258
264
|
descriptor: TestFileDescriptor,
|
|
@@ -263,7 +269,7 @@ export async function createCommand(
|
|
|
263
269
|
) {
|
|
264
270
|
const command = ["python3", descriptor.path, ...Constants.PythonRunnerArgs];
|
|
265
271
|
|
|
266
|
-
const args = scriptArgsOf(descriptor);
|
|
272
|
+
const args = await expandAppPlaceholders(scriptArgsOf(descriptor), path => isExecutable(container, path));
|
|
267
273
|
|
|
268
274
|
command.push(...args, ...extraArgs);
|
|
269
275
|
|
|
@@ -286,6 +292,17 @@ export async function createCommand(
|
|
|
286
292
|
return command;
|
|
287
293
|
}
|
|
288
294
|
|
|
295
|
+
async function isExecutable(container: Container, path: string) {
|
|
296
|
+
const answer = await container.execAndRead([
|
|
297
|
+
"sh",
|
|
298
|
+
"-c",
|
|
299
|
+
'test -f "$1" && test -x "$1" && echo yes || echo no',
|
|
300
|
+
"sh",
|
|
301
|
+
path,
|
|
302
|
+
]);
|
|
303
|
+
return answer.trim() === "yes";
|
|
304
|
+
}
|
|
305
|
+
|
|
289
306
|
function scriptArgsOf(descriptor: TestFileDescriptor) {
|
|
290
307
|
let args: string[] | undefined;
|
|
291
308
|
|
package/src/chip/state.ts
CHANGED
|
@@ -20,6 +20,7 @@ import { afterRun, beforeRun } from "../mocha.js";
|
|
|
20
20
|
import { TestRunner } from "../runner.js";
|
|
21
21
|
import { RootTestDescriptor, TestDescriptor, TestFileDescriptor } from "../test-descriptor.js";
|
|
22
22
|
import { AccessoryServer } from "./accessory-server.js";
|
|
23
|
+
import { normalizeAppReferences } from "./app-reference.js";
|
|
23
24
|
import { createRegisteredCertTest } from "./cert/cert-test.js";
|
|
24
25
|
import { CERT_BINS_PLATFORM, chipBinsPlatformSupported, prepareChipBins, resolveChipBinsSource } from "./chip-bins.js";
|
|
25
26
|
import type { chip } from "./chip.js";
|
|
@@ -328,9 +329,11 @@ export const State = {
|
|
|
328
329
|
await State.container.exec(["bash", "-c", 'export GLOBIGNORE="/tmp/*_fifo_*"; rm -rf /tmp/*']);
|
|
329
330
|
|
|
330
331
|
if (!startCommissioned) {
|
|
331
|
-
//
|
|
332
|
+
// A single-use subject is closed by deactivateSubject(), also when it fails to start, and nothing
|
|
333
|
+
// else may hold it: a closed subject still references its log and the steps of its test
|
|
334
|
+
Values.activeSubject = subject;
|
|
335
|
+
Values.singleUseSubject = true;
|
|
332
336
|
await subject.initialize();
|
|
333
|
-
State.onClose(subject.close.bind(subject));
|
|
334
337
|
|
|
335
338
|
await beforeStart?.(subject, test);
|
|
336
339
|
await subject.start();
|
|
@@ -581,6 +584,7 @@ async function configureTests() {
|
|
|
581
584
|
throw new Error(`CHIP test descriptor has no members`);
|
|
582
585
|
}
|
|
583
586
|
|
|
587
|
+
normalizeAppReferences(descriptor);
|
|
584
588
|
Values.tests = TestDescriptor.Filesystem(descriptor);
|
|
585
589
|
}
|
|
586
590
|
|
|
@@ -24,6 +24,7 @@ export type BackchannelCommand =
|
|
|
24
24
|
| BackchannelCommand.BridgeSimulation
|
|
25
25
|
| BackchannelCommand.SendOnOffToBindings
|
|
26
26
|
| BackchannelCommand.UserIntentCommissioningStart
|
|
27
|
+
| BackchannelCommand.FactoryResetWithAppArgs
|
|
27
28
|
| BackchannelCommand.NoParameters;
|
|
28
29
|
|
|
29
30
|
export namespace BackchannelCommand {
|
|
@@ -176,6 +177,16 @@ export namespace BackchannelCommand {
|
|
|
176
177
|
name: "userIntentCommissioningStart";
|
|
177
178
|
};
|
|
178
179
|
|
|
180
|
+
/**
|
|
181
|
+
* Factory-reset the device and start it with `appArgs` in place of the arguments its case declared. The arguments
|
|
182
|
+
* the harness adds itself, such as ports, stay. A case that starts the TH with a different certificate set for each
|
|
183
|
+
* of its vectors uses it. Only a chip-local device takes it; the others refuse it as unsupported.
|
|
184
|
+
*/
|
|
185
|
+
export type FactoryResetWithAppArgs = {
|
|
186
|
+
name: "factoryResetWithAppArgs";
|
|
187
|
+
appArgs: string[];
|
|
188
|
+
};
|
|
189
|
+
|
|
179
190
|
export type NoParameters = {
|
|
180
191
|
name: "factoryReset" | "reboot" | "start" | "stop";
|
|
181
192
|
};
|
package/src/test-descriptor.ts
CHANGED
|
@@ -20,12 +20,15 @@ export interface TestDescriptor {
|
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* The app the test requires. A test naming an app the harness does not implement is skipped.
|
|
23
|
+
*
|
|
24
|
+
* The container's descriptor file may carry CHIP's own reference (`${ALL_CLUSTERS_APP}`); the harness brings it
|
|
25
|
+
* into harness form (`all-clusters`) when it loads the file.
|
|
23
26
|
*/
|
|
24
27
|
app?: string;
|
|
25
28
|
|
|
26
29
|
/**
|
|
27
30
|
* The app chip uses for the test. The harness dispatches to it when it implements the app and falls back to the
|
|
28
|
-
* default subject otherwise.
|
|
31
|
+
* default subject otherwise. Same naming as {@link app}.
|
|
29
32
|
*/
|
|
30
33
|
preferredApp?: string;
|
|
31
34
|
|
package/src/util/async.ts
CHANGED
|
@@ -69,7 +69,7 @@ export class LineQueue implements AsyncIterable<string> {
|
|
|
69
69
|
|
|
70
70
|
// Node clamps a setTimeout delay above this to 1ms, which would busy-spin a timer/wake race
|
|
71
71
|
// instead of actually waiting.
|
|
72
|
-
const MAX_TIMEOUT_MS = 0x7fffffff;
|
|
72
|
+
export const MAX_TIMEOUT_MS = 0x7fffffff;
|
|
73
73
|
|
|
74
74
|
/**
|
|
75
75
|
* A cancellable timeout for racing against other async work.
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2022-2026 Matter.js Authors
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
chipAppName,
|
|
9
|
+
expandAppPlaceholders,
|
|
10
|
+
normalizeAppReferences,
|
|
11
|
+
UnresolvedAppPlaceholderError,
|
|
12
|
+
} from "../../src/chip/app-reference.js";
|
|
13
|
+
import type { TestDescriptor } from "../../src/test-descriptor.js";
|
|
14
|
+
|
|
15
|
+
function executables(...paths: string[]) {
|
|
16
|
+
const present = new Set(paths);
|
|
17
|
+
const asked = new Array<string>();
|
|
18
|
+
return {
|
|
19
|
+
asked,
|
|
20
|
+
isExecutable: async (path: string) => {
|
|
21
|
+
asked.push(path);
|
|
22
|
+
return present.has(path);
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
describe("app-reference", () => {
|
|
28
|
+
describe("chipAppName", () => {
|
|
29
|
+
it("reduces CHIP app references to harness names", () => {
|
|
30
|
+
expect(chipAppName("${ALL_CLUSTERS_APP}")).equals("all-clusters");
|
|
31
|
+
expect(chipAppName("${ALL_CLUSTERS_NO_GROUPCAST_APP}")).equals("all-clusters-no-groupcast");
|
|
32
|
+
expect(chipAppName("${CHIP_LOCK_APP}")).equals("lock");
|
|
33
|
+
expect(chipAppName("${TV_APP}")).equals("tv");
|
|
34
|
+
expect(chipAppName("${LIGHTING_APP_NO_UNIQUE_ID}")).equals("lighting-app-no-unique-id");
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("leaves harness names unchanged", () => {
|
|
38
|
+
for (const name of ["all-clusters", "all-clusters-no-groupcast", "all-devices", "lit-icd", "rvc", "tv"]) {
|
|
39
|
+
expect(chipAppName(name)).equals(name);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe("normalizeAppReferences", () => {
|
|
45
|
+
it("normalizes app, preferredApp and config app throughout the tree", () => {
|
|
46
|
+
const tree: TestDescriptor = {
|
|
47
|
+
name: "chip",
|
|
48
|
+
kind: "suite",
|
|
49
|
+
members: [
|
|
50
|
+
{ name: "single", kind: "yaml", preferredApp: "${CHIP_LOCK_APP}" },
|
|
51
|
+
{
|
|
52
|
+
name: "multi",
|
|
53
|
+
kind: "suite",
|
|
54
|
+
members: [
|
|
55
|
+
{
|
|
56
|
+
name: "run1",
|
|
57
|
+
kind: "py",
|
|
58
|
+
app: "${ALL_DEVICES_APP}",
|
|
59
|
+
config: { app: "${ALL_DEVICES_APP}", quiet: true },
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
normalizeAppReferences(tree);
|
|
67
|
+
|
|
68
|
+
const [single, multi] = tree.members ?? [];
|
|
69
|
+
expect(single.preferredApp).equals("lock");
|
|
70
|
+
const run1 = multi.members?.[0];
|
|
71
|
+
expect(run1?.app).equals("all-devices");
|
|
72
|
+
expect(run1?.config).deep.equals({ app: "all-devices", quiet: true });
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
describe("expandAppPlaceholders", () => {
|
|
77
|
+
it("replaces a placeholder with the app's binary", async () => {
|
|
78
|
+
const { isExecutable } = executables("/bin/chip-tv-app");
|
|
79
|
+
|
|
80
|
+
const args = await expandAppPlaceholders(
|
|
81
|
+
["--string-arg", "th_server_app_path:${TV_APP}", "--endpoint", "1"],
|
|
82
|
+
isExecutable,
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
expect(args).deep.equals(["--string-arg", "th_server_app_path:/bin/chip-tv-app", "--endpoint", "1"]);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("replaces every placeholder in one argument", async () => {
|
|
89
|
+
const { isExecutable } = executables("/bin/chip-tv-app", "/bin/chip-lock-app");
|
|
90
|
+
|
|
91
|
+
const args = await expandAppPlaceholders(["a:${TV_APP},b:${CHIP_LOCK_APP}"], isExecutable);
|
|
92
|
+
|
|
93
|
+
expect(args).deep.equals(["a:/bin/chip-tv-app,b:/bin/chip-lock-app"]);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("checks nothing when there is no placeholder", async () => {
|
|
97
|
+
const { asked, isExecutable } = executables();
|
|
98
|
+
|
|
99
|
+
const args = await expandAppPlaceholders(["--endpoint", "1"], isExecutable);
|
|
100
|
+
|
|
101
|
+
expect(args).deep.equals(["--endpoint", "1"]);
|
|
102
|
+
expect(asked).deep.equals([]);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("fails on a placeholder that names no executable", async () => {
|
|
106
|
+
const { isExecutable } = executables("/bin/chip-tv-app");
|
|
107
|
+
|
|
108
|
+
await expect(
|
|
109
|
+
expandAppPlaceholders(["--string-arg", "th_server_app_path:${PUSH_AV_SERVER}"], isExecutable),
|
|
110
|
+
).rejectedWith(UnresolvedAppPlaceholderError, /\$\{PUSH_AV_SERVER\}.*\/bin\/chip-push-av-server-app/);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
});
|