@matter/testing 0.18.0 → 0.18.1-alpha.0-20261111-b89790712

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 (124) hide show
  1. package/dist/cjs/chip/app-reference.d.ts +41 -0
  2. package/dist/cjs/chip/app-reference.d.ts.map +1 -0
  3. package/dist/cjs/chip/app-reference.js +83 -0
  4. package/dist/cjs/chip/app-reference.js.map +6 -0
  5. package/dist/cjs/chip/cert/cert-context.d.ts +4 -2
  6. package/dist/cjs/chip/cert/cert-context.d.ts.map +1 -1
  7. package/dist/cjs/chip/cert/cert-context.js.map +1 -1
  8. package/dist/cjs/chip/cert/cert-dsl.d.ts +7 -1
  9. package/dist/cjs/chip/cert/cert-dsl.d.ts.map +1 -1
  10. package/dist/cjs/chip/cert/cert-dsl.js +4 -1
  11. package/dist/cjs/chip/cert/cert-dsl.js.map +1 -1
  12. package/dist/cjs/chip/cert/cert-test.d.ts.map +1 -1
  13. package/dist/cjs/chip/cert/cert-test.js +5 -18
  14. package/dist/cjs/chip/cert/cert-test.js.map +1 -1
  15. package/dist/cjs/chip/cert/chip-app-subject.d.ts.map +1 -1
  16. package/dist/cjs/chip/cert/chip-app-subject.js +23 -7
  17. package/dist/cjs/chip/cert/chip-app-subject.js.map +1 -1
  18. package/dist/cjs/chip/cert/controller-adapter.d.ts +71 -18
  19. package/dist/cjs/chip/cert/controller-adapter.d.ts.map +1 -1
  20. package/dist/cjs/chip/cert/controller-adapter.js +1 -3
  21. package/dist/cjs/chip/cert/controller-adapter.js.map +1 -1
  22. package/dist/cjs/chip/cert/evidence.d.ts +3 -3
  23. package/dist/cjs/chip/cert/evidence.js +1 -1
  24. package/dist/cjs/chip/cert/log-follower.d.ts +10 -0
  25. package/dist/cjs/chip/cert/log-follower.d.ts.map +1 -1
  26. package/dist/cjs/chip/cert/log-follower.js +48 -21
  27. package/dist/cjs/chip/cert/log-follower.js.map +1 -1
  28. package/dist/cjs/chip/cert/prompt-driven-python-test.js +1 -1
  29. package/dist/cjs/chip/cert/prompt-driven-python-test.js.map +1 -1
  30. package/dist/cjs/chip/cert/step-actions.d.ts +2 -3
  31. package/dist/cjs/chip/cert/step-actions.d.ts.map +1 -1
  32. package/dist/cjs/chip/cert/step-actions.js +2 -27
  33. package/dist/cjs/chip/cert/step-actions.js.map +1 -1
  34. package/dist/cjs/chip/index.d.ts +2 -1
  35. package/dist/cjs/chip/index.d.ts.map +1 -1
  36. package/dist/cjs/chip/index.js +2 -0
  37. package/dist/cjs/chip/index.js.map +1 -1
  38. package/dist/cjs/chip/python-test.d.ts +5 -0
  39. package/dist/cjs/chip/python-test.d.ts.map +1 -1
  40. package/dist/cjs/chip/python-test.js +12 -1
  41. package/dist/cjs/chip/python-test.js.map +1 -1
  42. package/dist/cjs/chip/state.d.ts.map +1 -1
  43. package/dist/cjs/chip/state.js +4 -1
  44. package/dist/cjs/chip/state.js.map +1 -1
  45. package/dist/cjs/device/backchannel.d.ts +10 -1
  46. package/dist/cjs/device/backchannel.d.ts.map +1 -1
  47. package/dist/cjs/test-descriptor.d.ts +4 -1
  48. package/dist/cjs/test-descriptor.d.ts.map +1 -1
  49. package/dist/cjs/test-descriptor.js.map +1 -1
  50. package/dist/cjs/util/async.d.ts +1 -0
  51. package/dist/cjs/util/async.d.ts.map +1 -1
  52. package/dist/cjs/util/async.js +1 -0
  53. package/dist/cjs/util/async.js.map +1 -1
  54. package/dist/esm/chip/app-reference.d.ts +41 -0
  55. package/dist/esm/chip/app-reference.d.ts.map +1 -0
  56. package/dist/esm/chip/app-reference.js +63 -0
  57. package/dist/esm/chip/app-reference.js.map +6 -0
  58. package/dist/esm/chip/cert/cert-context.d.ts +4 -2
  59. package/dist/esm/chip/cert/cert-context.d.ts.map +1 -1
  60. package/dist/esm/chip/cert/cert-context.js.map +1 -1
  61. package/dist/esm/chip/cert/cert-dsl.d.ts +7 -1
  62. package/dist/esm/chip/cert/cert-dsl.d.ts.map +1 -1
  63. package/dist/esm/chip/cert/cert-dsl.js +4 -1
  64. package/dist/esm/chip/cert/cert-dsl.js.map +1 -1
  65. package/dist/esm/chip/cert/cert-test.d.ts.map +1 -1
  66. package/dist/esm/chip/cert/cert-test.js +5 -18
  67. package/dist/esm/chip/cert/cert-test.js.map +1 -1
  68. package/dist/esm/chip/cert/chip-app-subject.d.ts.map +1 -1
  69. package/dist/esm/chip/cert/chip-app-subject.js +23 -7
  70. package/dist/esm/chip/cert/chip-app-subject.js.map +1 -1
  71. package/dist/esm/chip/cert/controller-adapter.d.ts +71 -18
  72. package/dist/esm/chip/cert/controller-adapter.d.ts.map +1 -1
  73. package/dist/esm/chip/cert/controller-adapter.js +1 -3
  74. package/dist/esm/chip/cert/controller-adapter.js.map +1 -1
  75. package/dist/esm/chip/cert/evidence.d.ts +3 -3
  76. package/dist/esm/chip/cert/evidence.js +1 -1
  77. package/dist/esm/chip/cert/log-follower.d.ts +10 -0
  78. package/dist/esm/chip/cert/log-follower.d.ts.map +1 -1
  79. package/dist/esm/chip/cert/log-follower.js +49 -22
  80. package/dist/esm/chip/cert/log-follower.js.map +1 -1
  81. package/dist/esm/chip/cert/prompt-driven-python-test.js +1 -1
  82. package/dist/esm/chip/cert/prompt-driven-python-test.js.map +1 -1
  83. package/dist/esm/chip/cert/step-actions.d.ts +2 -3
  84. package/dist/esm/chip/cert/step-actions.d.ts.map +1 -1
  85. package/dist/esm/chip/cert/step-actions.js +2 -29
  86. package/dist/esm/chip/cert/step-actions.js.map +1 -1
  87. package/dist/esm/chip/index.d.ts +2 -1
  88. package/dist/esm/chip/index.d.ts.map +1 -1
  89. package/dist/esm/chip/index.js +2 -0
  90. package/dist/esm/chip/index.js.map +1 -1
  91. package/dist/esm/chip/python-test.d.ts +5 -0
  92. package/dist/esm/chip/python-test.d.ts.map +1 -1
  93. package/dist/esm/chip/python-test.js +12 -1
  94. package/dist/esm/chip/python-test.js.map +1 -1
  95. package/dist/esm/chip/state.d.ts.map +1 -1
  96. package/dist/esm/chip/state.js +4 -1
  97. package/dist/esm/chip/state.js.map +1 -1
  98. package/dist/esm/device/backchannel.d.ts +10 -1
  99. package/dist/esm/device/backchannel.d.ts.map +1 -1
  100. package/dist/esm/test-descriptor.d.ts +4 -1
  101. package/dist/esm/test-descriptor.d.ts.map +1 -1
  102. package/dist/esm/test-descriptor.js.map +1 -1
  103. package/dist/esm/util/async.d.ts +1 -0
  104. package/dist/esm/util/async.d.ts.map +1 -1
  105. package/dist/esm/util/async.js +1 -0
  106. package/dist/esm/util/async.js.map +1 -1
  107. package/package.json +5 -5
  108. package/src/chip/app-reference.ts +91 -0
  109. package/src/chip/cert/cert-context.ts +4 -2
  110. package/src/chip/cert/cert-dsl.ts +16 -4
  111. package/src/chip/cert/cert-test.ts +7 -33
  112. package/src/chip/cert/chip-app-subject.ts +35 -10
  113. package/src/chip/cert/controller-adapter.ts +82 -21
  114. package/src/chip/cert/evidence.ts +3 -3
  115. package/src/chip/cert/log-follower.ts +58 -23
  116. package/src/chip/cert/prompt-driven-python-test.ts +1 -1
  117. package/src/chip/cert/step-actions.ts +4 -32
  118. package/src/chip/index.ts +3 -0
  119. package/src/chip/python-test.ts +18 -1
  120. package/src/chip/state.ts +6 -2
  121. package/src/device/backchannel.ts +11 -0
  122. package/src/test-descriptor.ts +4 -1
  123. package/src/util/async.ts +1 -1
  124. package/test/chip/AppReferenceTest.ts +113 -0
@@ -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
 
@@ -92,6 +91,7 @@ const CONTROLLER: Classified<ControllerAdapter> = {
92
91
  commission: "action",
93
92
  parseQrPayload: "none",
94
93
  parseManualPairingCode: "none",
94
+ discoverCommissionableNodes: "none",
95
95
  node: { handle: NODE },
96
96
  group: { handle: GROUP },
97
97
  webRtcRequestor: { handle: WEB_RTC_REQUESTOR },
@@ -102,12 +102,10 @@ const CONTROLLER: Classified<ControllerAdapter> = {
102
102
  /**
103
103
  * Counts the controller calls of the current step that may change a device.
104
104
  *
105
- * A call counts when it starts, so one still running when the step ends is counted, and a call that is refused
106
- * with {@link UnsupportedByControllerError} is taken back: a controller refuses before it sends anything. A call
107
- * that fails otherwise stays counted, since its request may have reached the device.
105
+ * A call counts when it starts, so one still running when the step ends is counted, and one that fails stays
106
+ * counted, since its request may have reached the device.
108
107
  */
109
108
  export class StepActions {
110
- #step = 0;
111
109
  #count = 0;
112
110
 
113
111
  get count() {
@@ -115,7 +113,6 @@ export class StepActions {
115
113
  }
116
114
 
117
115
  nextStep() {
118
- this.#step++;
119
116
  this.#count = 0;
120
117
  }
121
118
 
@@ -135,7 +132,7 @@ export class StepActions {
135
132
  if (typeof member === "function") {
136
133
  return (...args: unknown[]) => {
137
134
  if (classification === "action") {
138
- return this.#act(() => Reflect.apply(member, target, args));
135
+ this.#count++;
139
136
  }
140
137
  const result: unknown = Reflect.apply(member, target, args);
141
138
  return typeof classification === "object" && isApi(result)
@@ -149,31 +146,6 @@ export class StepActions {
149
146
  },
150
147
  });
151
148
  }
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
149
  }
178
150
 
179
151
  /** 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";
@@ -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
- // Initialize single-use subject
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
  };
@@ -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
+ });