@matter/testing 0.17.9 → 0.18.0-alpha.0-20260812-4d7f2790e

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 (277) hide show
  1. package/dist/cjs/chai.js +4 -4
  2. package/dist/cjs/chai.js.map +2 -2
  3. package/dist/cjs/chip/cert/cert-context.d.ts +115 -0
  4. package/dist/cjs/chip/cert/cert-context.d.ts.map +1 -0
  5. package/dist/cjs/chip/cert/cert-context.js +22 -0
  6. package/dist/cjs/chip/cert/cert-context.js.map +6 -0
  7. package/dist/cjs/chip/cert/cert-dsl.d.ts +48 -0
  8. package/dist/cjs/chip/cert/cert-dsl.d.ts.map +1 -0
  9. package/dist/cjs/chip/cert/cert-dsl.js +308 -0
  10. package/dist/cjs/chip/cert/cert-dsl.js.map +6 -0
  11. package/dist/cjs/chip/cert/cert-test.d.ts +46 -0
  12. package/dist/cjs/chip/cert/cert-test.d.ts.map +1 -0
  13. package/dist/cjs/chip/cert/cert-test.js +250 -0
  14. package/dist/cjs/chip/cert/cert-test.js.map +6 -0
  15. package/dist/cjs/chip/cert/chip-app-subject.d.ts +80 -0
  16. package/dist/cjs/chip/cert/chip-app-subject.d.ts.map +1 -0
  17. package/dist/cjs/chip/cert/chip-app-subject.js +337 -0
  18. package/dist/cjs/chip/cert/chip-app-subject.js.map +6 -0
  19. package/dist/cjs/chip/cert/controller-adapter.d.ts +119 -0
  20. package/dist/cjs/chip/cert/controller-adapter.d.ts.map +1 -0
  21. package/dist/cjs/chip/cert/controller-adapter.js +45 -0
  22. package/dist/cjs/chip/cert/controller-adapter.js.map +6 -0
  23. package/dist/cjs/chip/cert/device-config.d.ts +15 -0
  24. package/dist/cjs/chip/cert/device-config.d.ts.map +1 -0
  25. package/dist/cjs/chip/cert/device-config.js +43 -0
  26. package/dist/cjs/chip/cert/device-config.js.map +6 -0
  27. package/dist/cjs/chip/cert/evidence.d.ts +70 -0
  28. package/dist/cjs/chip/cert/evidence.d.ts.map +1 -0
  29. package/dist/cjs/chip/cert/evidence.js +128 -0
  30. package/dist/cjs/chip/cert/evidence.js.map +6 -0
  31. package/dist/cjs/chip/cert/log-follower.d.ts +96 -0
  32. package/dist/cjs/chip/cert/log-follower.d.ts.map +1 -0
  33. package/dist/cjs/chip/cert/log-follower.js +209 -0
  34. package/dist/cjs/chip/cert/log-follower.js.map +6 -0
  35. package/dist/cjs/chip/cert/matterjs-subject-registry.d.ts +22 -0
  36. package/dist/cjs/chip/cert/matterjs-subject-registry.d.ts.map +1 -0
  37. package/dist/cjs/chip/cert/matterjs-subject-registry.js +40 -0
  38. package/dist/cjs/chip/cert/matterjs-subject-registry.js.map +6 -0
  39. package/dist/cjs/chip/cert/prompt-driven-python-test.d.ts +40 -0
  40. package/dist/cjs/chip/cert/prompt-driven-python-test.d.ts.map +1 -0
  41. package/dist/cjs/chip/cert/prompt-driven-python-test.js +77 -0
  42. package/dist/cjs/chip/cert/prompt-driven-python-test.js.map +6 -0
  43. package/dist/cjs/chip/chip-bins.d.ts +132 -0
  44. package/dist/cjs/chip/chip-bins.d.ts.map +1 -0
  45. package/dist/cjs/chip/chip-bins.js +232 -0
  46. package/dist/cjs/chip/chip-bins.js.map +6 -0
  47. package/dist/cjs/chip/chip-test-common.d.ts.map +1 -1
  48. package/dist/cjs/chip/chip-test-common.js +1 -1
  49. package/dist/cjs/chip/chip-test-common.js.map +1 -1
  50. package/dist/cjs/chip/chip.d.ts.map +1 -1
  51. package/dist/cjs/chip/chip.js +1 -1
  52. package/dist/cjs/chip/chip.js.map +1 -1
  53. package/dist/cjs/chip/config.d.ts +26 -0
  54. package/dist/cjs/chip/config.d.ts.map +1 -1
  55. package/dist/cjs/chip/config.js +11 -3
  56. package/dist/cjs/chip/config.js.map +1 -1
  57. package/dist/cjs/chip/index.d.ts +26 -0
  58. package/dist/cjs/chip/index.d.ts.map +1 -1
  59. package/dist/cjs/chip/index.js +49 -0
  60. package/dist/cjs/chip/index.js.map +2 -2
  61. package/dist/cjs/chip/pics/file.d.ts +8 -0
  62. package/dist/cjs/chip/pics/file.d.ts.map +1 -1
  63. package/dist/cjs/chip/pics/file.js +4 -1
  64. package/dist/cjs/chip/pics/file.js.map +1 -1
  65. package/dist/cjs/chip/pics/source.d.ts +8 -5
  66. package/dist/cjs/chip/pics/source.d.ts.map +1 -1
  67. package/dist/cjs/chip/pics/source.js +25 -17
  68. package/dist/cjs/chip/pics/source.js.map +1 -1
  69. package/dist/cjs/chip/python-test.d.ts +12 -0
  70. package/dist/cjs/chip/python-test.d.ts.map +1 -1
  71. package/dist/cjs/chip/python-test.js +6 -4
  72. package/dist/cjs/chip/python-test.js.map +1 -1
  73. package/dist/cjs/chip/state.d.ts.map +1 -1
  74. package/dist/cjs/chip/state.js +24 -7
  75. package/dist/cjs/chip/state.js.map +1 -1
  76. package/dist/cjs/chip/yaml-test.js +1 -1
  77. package/dist/cjs/chip/yaml-test.js.map +1 -1
  78. package/dist/cjs/cli.d.ts.map +1 -1
  79. package/dist/cjs/cli.js +33 -2
  80. package/dist/cjs/cli.js.map +1 -1
  81. package/dist/cjs/device/backchannel.d.ts.map +1 -1
  82. package/dist/cjs/device/subject.d.ts.map +1 -1
  83. package/dist/cjs/device/test.d.ts.map +1 -1
  84. package/dist/cjs/docker/container.d.ts.map +1 -1
  85. package/dist/cjs/docker/docker.d.ts.map +1 -1
  86. package/dist/cjs/docker/edit.d.ts.map +1 -1
  87. package/dist/cjs/docker/errors.d.ts.map +1 -1
  88. package/dist/cjs/docker/network.d.ts.map +1 -1
  89. package/dist/cjs/docker/terminal.d.ts.map +1 -1
  90. package/dist/cjs/failure-reporter.d.ts.map +1 -1
  91. package/dist/cjs/global-declarations.d.js +0 -1
  92. package/dist/cjs/global-declarations.d.js.map +1 -1
  93. package/dist/cjs/global-declarations.d.ts +2 -2
  94. package/dist/cjs/global-definitions.js +17 -4
  95. package/dist/cjs/global-definitions.js.map +2 -2
  96. package/dist/cjs/index.d.js +2 -0
  97. package/dist/cjs/index.d.js.map +1 -1
  98. package/dist/cjs/index.d.ts +3 -0
  99. package/dist/cjs/index.js +2 -0
  100. package/dist/cjs/index.js.map +1 -1
  101. package/dist/cjs/mocha.d.ts.map +1 -1
  102. package/dist/cjs/mocha.js +5 -0
  103. package/dist/cjs/mocha.js.map +1 -1
  104. package/dist/cjs/mocharc.cjs +4 -3
  105. package/dist/cjs/options.d.ts.map +1 -1
  106. package/dist/cjs/print-report.js +1 -1
  107. package/dist/cjs/print-report.js.map +1 -1
  108. package/dist/cjs/test-descriptor.d.ts +1 -1
  109. package/dist/cjs/test-descriptor.d.ts.map +1 -1
  110. package/dist/cjs/text-diff.d.ts.map +1 -1
  111. package/dist/cjs/util/async.d.ts +30 -0
  112. package/dist/cjs/util/async.d.ts.map +1 -0
  113. package/dist/cjs/util/async.js +85 -0
  114. package/dist/cjs/util/async.js.map +6 -0
  115. package/dist/cjs/util/trace-unhandled.d.ts.map +1 -1
  116. package/dist/cjs/util/wtf.d.ts.map +1 -1
  117. package/dist/cjs/util/wtf.js +1 -1
  118. package/dist/cjs/util/wtf.js.map +1 -1
  119. package/dist/cjs/web.d.ts.map +1 -1
  120. package/dist/cjs/web.js +5 -1
  121. package/dist/cjs/web.js.map +1 -1
  122. package/dist/esm/chai.js +1 -1
  123. package/dist/esm/chai.js.map +1 -1
  124. package/dist/esm/chip/cert/cert-context.d.ts +115 -0
  125. package/dist/esm/chip/cert/cert-context.d.ts.map +1 -0
  126. package/dist/esm/chip/cert/cert-context.js +6 -0
  127. package/dist/esm/chip/cert/cert-context.js.map +6 -0
  128. package/dist/esm/chip/cert/cert-dsl.d.ts +48 -0
  129. package/dist/esm/chip/cert/cert-dsl.d.ts.map +1 -0
  130. package/dist/esm/chip/cert/cert-dsl.js +288 -0
  131. package/dist/esm/chip/cert/cert-dsl.js.map +6 -0
  132. package/dist/esm/chip/cert/cert-test.d.ts +46 -0
  133. package/dist/esm/chip/cert/cert-test.d.ts.map +1 -0
  134. package/dist/esm/chip/cert/cert-test.js +230 -0
  135. package/dist/esm/chip/cert/cert-test.js.map +6 -0
  136. package/dist/esm/chip/cert/chip-app-subject.d.ts +80 -0
  137. package/dist/esm/chip/cert/chip-app-subject.d.ts.map +1 -0
  138. package/dist/esm/chip/cert/chip-app-subject.js +317 -0
  139. package/dist/esm/chip/cert/chip-app-subject.js.map +6 -0
  140. package/dist/esm/chip/cert/controller-adapter.d.ts +119 -0
  141. package/dist/esm/chip/cert/controller-adapter.d.ts.map +1 -0
  142. package/dist/esm/chip/cert/controller-adapter.js +25 -0
  143. package/dist/esm/chip/cert/controller-adapter.js.map +6 -0
  144. package/dist/esm/chip/cert/device-config.d.ts +15 -0
  145. package/dist/esm/chip/cert/device-config.d.ts.map +1 -0
  146. package/dist/esm/chip/cert/device-config.js +23 -0
  147. package/dist/esm/chip/cert/device-config.js.map +6 -0
  148. package/dist/esm/chip/cert/evidence.d.ts +70 -0
  149. package/dist/esm/chip/cert/evidence.d.ts.map +1 -0
  150. package/dist/esm/chip/cert/evidence.js +108 -0
  151. package/dist/esm/chip/cert/evidence.js.map +6 -0
  152. package/dist/esm/chip/cert/log-follower.d.ts +96 -0
  153. package/dist/esm/chip/cert/log-follower.d.ts.map +1 -0
  154. package/dist/esm/chip/cert/log-follower.js +189 -0
  155. package/dist/esm/chip/cert/log-follower.js.map +6 -0
  156. package/dist/esm/chip/cert/matterjs-subject-registry.d.ts +22 -0
  157. package/dist/esm/chip/cert/matterjs-subject-registry.d.ts.map +1 -0
  158. package/dist/esm/chip/cert/matterjs-subject-registry.js +20 -0
  159. package/dist/esm/chip/cert/matterjs-subject-registry.js.map +6 -0
  160. package/dist/esm/chip/cert/prompt-driven-python-test.d.ts +40 -0
  161. package/dist/esm/chip/cert/prompt-driven-python-test.d.ts.map +1 -0
  162. package/dist/esm/chip/cert/prompt-driven-python-test.js +57 -0
  163. package/dist/esm/chip/cert/prompt-driven-python-test.js.map +6 -0
  164. package/dist/esm/chip/chip-bins.d.ts +132 -0
  165. package/dist/esm/chip/chip-bins.d.ts.map +1 -0
  166. package/dist/esm/chip/chip-bins.js +212 -0
  167. package/dist/esm/chip/chip-bins.js.map +6 -0
  168. package/dist/esm/chip/chip-test-common.d.ts.map +1 -1
  169. package/dist/esm/chip/chip-test-common.js +1 -1
  170. package/dist/esm/chip/chip-test-common.js.map +1 -1
  171. package/dist/esm/chip/chip.d.ts.map +1 -1
  172. package/dist/esm/chip/chip.js +1 -1
  173. package/dist/esm/chip/chip.js.map +1 -1
  174. package/dist/esm/chip/config.d.ts +26 -0
  175. package/dist/esm/chip/config.d.ts.map +1 -1
  176. package/dist/esm/chip/config.js +11 -3
  177. package/dist/esm/chip/config.js.map +1 -1
  178. package/dist/esm/chip/index.d.ts +26 -0
  179. package/dist/esm/chip/index.d.ts.map +1 -1
  180. package/dist/esm/chip/index.js +60 -0
  181. package/dist/esm/chip/index.js.map +1 -1
  182. package/dist/esm/chip/pics/file.d.ts +8 -0
  183. package/dist/esm/chip/pics/file.d.ts.map +1 -1
  184. package/dist/esm/chip/pics/file.js +4 -1
  185. package/dist/esm/chip/pics/file.js.map +1 -1
  186. package/dist/esm/chip/pics/source.d.ts +8 -5
  187. package/dist/esm/chip/pics/source.d.ts.map +1 -1
  188. package/dist/esm/chip/pics/source.js +24 -16
  189. package/dist/esm/chip/pics/source.js.map +1 -1
  190. package/dist/esm/chip/python-test.d.ts +12 -0
  191. package/dist/esm/chip/python-test.d.ts.map +1 -1
  192. package/dist/esm/chip/python-test.js +6 -4
  193. package/dist/esm/chip/python-test.js.map +1 -1
  194. package/dist/esm/chip/state.d.ts.map +1 -1
  195. package/dist/esm/chip/state.js +25 -8
  196. package/dist/esm/chip/state.js.map +1 -1
  197. package/dist/esm/chip/yaml-test.js +1 -1
  198. package/dist/esm/chip/yaml-test.js.map +1 -1
  199. package/dist/esm/cli.d.ts.map +1 -1
  200. package/dist/esm/cli.js +33 -2
  201. package/dist/esm/cli.js.map +1 -1
  202. package/dist/esm/device/backchannel.d.ts.map +1 -1
  203. package/dist/esm/device/subject.d.ts.map +1 -1
  204. package/dist/esm/device/test.d.ts.map +1 -1
  205. package/dist/esm/docker/container.d.ts.map +1 -1
  206. package/dist/esm/docker/docker.d.ts.map +1 -1
  207. package/dist/esm/docker/edit.d.ts.map +1 -1
  208. package/dist/esm/docker/errors.d.ts.map +1 -1
  209. package/dist/esm/docker/network.d.ts.map +1 -1
  210. package/dist/esm/docker/terminal.d.ts.map +1 -1
  211. package/dist/esm/failure-reporter.d.ts.map +1 -1
  212. package/dist/esm/global-declarations.d.js +0 -1
  213. package/dist/esm/global-declarations.d.js.map +1 -1
  214. package/dist/esm/global-declarations.d.ts +2 -2
  215. package/dist/esm/global-definitions.js +16 -3
  216. package/dist/esm/global-definitions.js.map +1 -1
  217. package/dist/esm/index.d.js +2 -0
  218. package/dist/esm/index.d.js.map +1 -1
  219. package/dist/esm/index.d.ts +3 -0
  220. package/dist/esm/index.js +2 -0
  221. package/dist/esm/index.js.map +1 -1
  222. package/dist/esm/mocha.d.ts.map +1 -1
  223. package/dist/esm/mocha.js +5 -0
  224. package/dist/esm/mocha.js.map +1 -1
  225. package/dist/esm/mocharc.cjs +4 -3
  226. package/dist/esm/options.d.ts.map +1 -1
  227. package/dist/esm/print-report.js +1 -1
  228. package/dist/esm/print-report.js.map +1 -1
  229. package/dist/esm/test-descriptor.d.ts +1 -1
  230. package/dist/esm/test-descriptor.d.ts.map +1 -1
  231. package/dist/esm/text-diff.d.ts.map +1 -1
  232. package/dist/esm/util/async.d.ts +30 -0
  233. package/dist/esm/util/async.d.ts.map +1 -0
  234. package/dist/esm/util/async.js +65 -0
  235. package/dist/esm/util/async.js.map +6 -0
  236. package/dist/esm/util/trace-unhandled.d.ts.map +1 -1
  237. package/dist/esm/util/wtf.d.ts.map +1 -1
  238. package/dist/esm/util/wtf.js +1 -1
  239. package/dist/esm/util/wtf.js.map +1 -1
  240. package/dist/esm/web.d.ts.map +1 -1
  241. package/dist/esm/web.js +5 -1
  242. package/dist/esm/web.js.map +1 -1
  243. package/package.json +9 -9
  244. package/src/chai.ts +3 -3
  245. package/src/chip/cert/cert-context.ts +126 -0
  246. package/src/chip/cert/cert-dsl.ts +451 -0
  247. package/src/chip/cert/cert-test.ts +360 -0
  248. package/src/chip/cert/chip-app-subject.ts +457 -0
  249. package/src/chip/cert/controller-adapter.ts +142 -0
  250. package/src/chip/cert/device-config.ts +33 -0
  251. package/src/chip/cert/evidence.ts +170 -0
  252. package/src/chip/cert/log-follower.ts +266 -0
  253. package/src/chip/cert/matterjs-subject-registry.ts +33 -0
  254. package/src/chip/cert/prompt-driven-python-test.ts +104 -0
  255. package/src/chip/chip-bins.ts +401 -0
  256. package/src/chip/chip-test-common.ts +3 -1
  257. package/src/chip/chip.ts +1 -1
  258. package/src/chip/config.ts +28 -1
  259. package/src/chip/index.ts +67 -0
  260. package/src/chip/pics/file.ts +8 -0
  261. package/src/chip/pics/source.ts +39 -19
  262. package/src/chip/python-test.ts +5 -4
  263. package/src/chip/state.ts +39 -8
  264. package/src/chip/yaml-test.ts +1 -1
  265. package/src/cli.ts +40 -2
  266. package/src/global-declarations.d.ts +2 -2
  267. package/src/global-definitions.ts +27 -3
  268. package/src/index.d.ts +3 -0
  269. package/src/index.js +1 -0
  270. package/src/mocha.ts +13 -0
  271. package/src/mocharc.cjs +4 -3
  272. package/src/print-report.ts +1 -1
  273. package/src/test-descriptor.ts +1 -1
  274. package/src/util/async.ts +83 -0
  275. package/src/util/wtf.ts +3 -1
  276. package/src/web.ts +5 -1
  277. package/test/util/AsyncTest.ts +68 -0
@@ -4,14 +4,15 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
7
- import { Package } from "@nacho-iot/js-tools";
8
7
  import { readFile } from "node:fs/promises";
9
8
  import { isAbsolute } from "node:path";
10
- import { State } from "../state.js";
9
+ import type { Container } from "../../docker/container.js";
11
10
  import { PicsFile } from "./file.js";
12
11
 
13
12
  const dataCache = new WeakMap<PicsSource, PicsFile>();
14
- const filenameCache = new WeakMap<PicsFile, string>();
13
+ // Keyed per-container: the same PicsFile installed into two containers needs two filenames, one
14
+ // actually written into each.
15
+ const filenameCache = new WeakMap<Container, WeakMap<PicsFile, string>>();
15
16
 
16
17
  let nextFileNo = 1;
17
18
 
@@ -25,9 +26,11 @@ export namespace PicsSource {
25
26
  /**
26
27
  * Load a {@link PicsFile} defined by a {@link PicsSource}.
27
28
  *
28
- * Caches results so a source always returns the same {@link PicsFile} instance.
29
+ * Caches results so a source always returns the same {@link PicsFile} instance. `container` is
30
+ * only actually read for a `"chip"`-kind source; callers that know their sources never resolve to
31
+ * one may omit it.
29
32
  */
30
- export async function load(source: PicsSource): Promise<PicsFile> {
33
+ export async function load(source: PicsSource, container?: Container): Promise<PicsFile> {
31
34
  let file = dataCache.get(source);
32
35
  if (file) {
33
36
  return file;
@@ -36,7 +39,7 @@ export namespace PicsSource {
36
39
  switch (source.kind) {
37
40
  case "composite":
38
41
  for (const subsource of source.sources) {
39
- const sourceFile = await load(subsource);
42
+ const sourceFile = await load(subsource, container);
40
43
  if (file) {
41
44
  file.patch(sourceFile);
42
45
  } else {
@@ -49,11 +52,14 @@ export namespace PicsSource {
49
52
  break;
50
53
 
51
54
  case "chip":
52
- file = new PicsFile(await State.container.read(source.name));
55
+ if (!container) {
56
+ throw new Error(`Loading PICS source "${source.name}" requires a container`);
57
+ }
58
+ file = new PicsFile(await container.read(source.name));
53
59
  break;
54
60
 
55
61
  case "file":
56
- file = new PicsFile(await readFile(resolve(source.name), "utf-8"));
62
+ file = new PicsFile(await readFile(await resolve(source.name), "utf-8"));
57
63
  break;
58
64
 
59
65
  case "lines":
@@ -76,14 +82,14 @@ export namespace PicsSource {
76
82
  /**
77
83
  * Save a {@link PicsFile} to the a {@link ChipFile} or {@link LocalFile}.
78
84
  */
79
- export async function save(target: ChipFile | LocalFile, file: PicsFile): Promise<void> {
85
+ export async function save(container: Container, target: ChipFile | LocalFile, file: PicsFile): Promise<void> {
80
86
  switch (target.kind) {
81
87
  case "chip":
82
- await State.container.write(target.name, file.toString());
88
+ await container.write(target.name, file.toString());
83
89
  break;
84
90
 
85
91
  case "file":
86
- await State.container.write(resolve(target.name), file.toString());
92
+ await container.write(await resolve(target.name), file.toString());
87
93
  break;
88
94
 
89
95
  default:
@@ -92,14 +98,20 @@ export namespace PicsSource {
92
98
  }
93
99
 
94
100
  /**
95
- * Install a {@link PicsSource} into the test container.
101
+ * Install a {@link PicsSource} into `container`.
96
102
  *
97
103
  * Returns the name of the file in the container.
98
104
  *
99
105
  * Results are cached so the same source always returns the same filename.
100
106
  */
101
- export async function install(file: PicsFile): Promise<string> {
102
- let filename = filenameCache.get(file);
107
+ export async function install(container: Container, file: PicsFile): Promise<string> {
108
+ let byFile = filenameCache.get(container);
109
+ if (!byFile) {
110
+ byFile = new WeakMap<PicsFile, string>();
111
+ filenameCache.set(container, byFile);
112
+ }
113
+
114
+ let filename = byFile.get(file);
103
115
  if (filename) {
104
116
  return filename;
105
117
  }
@@ -107,10 +119,10 @@ export namespace PicsSource {
107
119
  filename = `/pics-${nextFileNo++}.properties`;
108
120
 
109
121
  try {
110
- filenameCache.set(file, filename);
111
- await save({ kind: "chip", name: filename }, file);
122
+ byFile.set(file, filename);
123
+ await save(container, { kind: "chip", name: filename }, file);
112
124
  } catch (e) {
113
- filenameCache.delete(file);
125
+ byFile.delete(file);
114
126
  throw e;
115
127
  }
116
128
 
@@ -145,15 +157,23 @@ export namespace PicsSource {
145
157
  export type Source = ChipFile | LocalFile | Lines | Values;
146
158
  }
147
159
 
148
- function resolve(path: string): string {
160
+ // A "file"-kind PICS source is a rare, local-dev-only path (unused by any test in this suite).
161
+ // @nacho-iot/js-tools pulls in Node build tooling that isn't browser-bundleable; importing it lazily,
162
+ // only when this branch actually runs, keeps every other PicsSource kind (and everything that only
163
+ // ever installs/loads those) free of that dependency. The specifier is built at runtime, not written
164
+ // as a literal, so esbuild's Web test bundle can't trace and inline it (a literal `import("@nacho-iot/js-tools")`
165
+ // would drag its build-tooling submodules into that bundle even though this branch never runs there).
166
+ async function resolve(path: string): Promise<string> {
149
167
  if (isAbsolute(path)) {
150
168
  return path;
151
169
  }
152
170
 
171
+ const jsToolsSpecifier = ["@nacho-iot", "js-tools"].join("/");
172
+ const { Package }: typeof import("@nacho-iot/js-tools") = await import(jsToolsSpecifier);
153
173
  const testing = Package.findPackage("@matter/testing");
154
174
  if (testing.hasFile(path)) {
155
175
  return testing.resolve(path);
156
176
  }
157
177
 
158
- return resolve(path);
178
+ throw new Error(`PICS file "${path}" not found relative to @matter/testing`);
159
179
  }
@@ -132,7 +132,7 @@ export class PythonTest extends BaseTest {
132
132
 
133
133
  async #runPythonTest(subject: Subject, step: (title: string) => void, args: string[], uncommissioned: boolean) {
134
134
  const terminal = await this.container.exec(
135
- await createCommand(this.descriptor, subject, args, uncommissioned),
135
+ await createCommand(this.descriptor, this.container, subject, args, uncommissioned),
136
136
  Terminal.Line,
137
137
  {
138
138
  cwd: "/tmp",
@@ -163,7 +163,7 @@ export class PythonTest extends BaseTest {
163
163
  /**
164
164
  * Upgrade logging output with consistency and colors.
165
165
  */
166
- function spiffy(line: string) {
166
+ export function spiffy(line: string) {
167
167
  let timestamp = "";
168
168
  let level = "";
169
169
  let facility = "";
@@ -220,8 +220,9 @@ function spiffy(line: string) {
220
220
  *
221
221
  * A program defining mandatory arguments to itself seems silly but we work with what we've got amiright?
222
222
  */
223
- async function createCommand(
223
+ export async function createCommand(
224
224
  descriptor: TestFileDescriptor,
225
+ container: Container,
225
226
  subject: Subject,
226
227
  extraArgs: string[],
227
228
  uncommissioned: boolean,
@@ -240,7 +241,7 @@ async function createCommand(
240
241
  }
241
242
 
242
243
  if (!command.includes("--PICS")) {
243
- command.push("--PICS", await PicsSource.install(subject.pics));
244
+ command.push("--PICS", await PicsSource.install(container, subject.pics));
244
245
  }
245
246
 
246
247
  const qrCodePos = command.indexOf("--qr-code");
package/src/chip/state.ts CHANGED
@@ -20,10 +20,12 @@ 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 { createRegisteredCertTest } from "./cert/cert-test.js";
23
24
  import type { chip } from "./chip.js";
24
- import { Constants, ContainerPaths } from "./config.js";
25
+ import { CERT_BINS_PLATFORM, chipBinsPlatformSupported, prepareChipBins, resolveChipBinsSource } from "./chip-bins.js";
26
+ import { Constants, ContainerPaths, HARNESS_COMPOSITION_NAME, HARNESS_DBUS_PART_NAME } from "./config.js";
25
27
  import { ContainerCommandPipe } from "./container-command-pipe.js";
26
- import { PicsFile } from "./pics/file.js";
28
+ import { PicsFile, PicsUnavailableError } from "./pics/file.js";
27
29
  import { PicsSource } from "./pics/source.js";
28
30
  import { PythonTest } from "./python-test.js";
29
31
  import { YamlTest } from "./yaml-test.js";
@@ -104,7 +106,7 @@ export const State = {
104
106
 
105
107
  get defaultPics() {
106
108
  if (Values.defaultPics === undefined) {
107
- throw new Error("PICS not initialized");
109
+ throw new PicsUnavailableError("PICS not initialized");
108
110
  }
109
111
 
110
112
  return Values.defaultPics;
@@ -112,7 +114,7 @@ export const State = {
112
114
 
113
115
  get defaultPicsFilename() {
114
116
  if (Values.defaultPicsFilename === undefined) {
115
- throw new Error("PICS not initialized");
117
+ throw new PicsUnavailableError("PICS not initialized");
116
118
  }
117
119
 
118
120
  return Values.defaultPicsFilename;
@@ -168,6 +170,11 @@ export const State = {
168
170
  progress.success(
169
171
  `Initialized CHIP ${ansi.bold(chipCommit)} image ${ansi.bold(imageVersion)} for ${ansi.bold(arch)}`,
170
172
  );
173
+
174
+ if (resolveChipBinsSource() === "cert-bins") {
175
+ const { tag } = await prepareChipBins();
176
+ progress.success(`Using official chip-cert-bins ${ansi.bold(tag)} for chip-tool`);
177
+ }
171
178
  } catch (e) {
172
179
  progress.failure("Initializing containers");
173
180
  throw e;
@@ -432,6 +439,20 @@ async function configureContainer() {
432
439
  platform = `linux/${arch}`;
433
440
  }
434
441
 
442
+ // chip-cert-bins publishes linux/arm64 only (no amd64 manifest exists at any tag). Bind-mounting
443
+ // its binaries into a container running a different platform fails at exec time with a
444
+ // confusing "cannot execute: required file not found" deep inside a test run, so fail fast here
445
+ // instead, before spending time on extraction.
446
+ const chipBinsSelected = resolveChipBinsSource() === "cert-bins";
447
+ if (chipBinsSelected && !chipBinsPlatformSupported(platform)) {
448
+ throw new Error(
449
+ `MATTER_CHIP_BINS_SOURCE=cert-bins requires the harness "chip" container to run ` +
450
+ `${CERT_BINS_PLATFORM} (chip-cert-bins publishes no other platform), but it is configured for ` +
451
+ `${platform}. Set MATTER_CHIP_PLATFORM=${CERT_BINS_PLATFORM} and point MATTER_CHIP_IMAGE at an ` +
452
+ `${CERT_BINS_PLATFORM} build of the harness image, or unset MATTER_CHIP_BINS_SOURCE.`,
453
+ );
454
+ }
455
+
435
456
  const mdnsVolume = Volume(docker, Constants.mdnsVolumeName);
436
457
  await mdnsVolume.open();
437
458
 
@@ -440,7 +461,13 @@ async function configureContainer() {
440
461
  const restartFlagHostDir = await mkdtemp(join(tmpdir(), "matter-restart-"));
441
462
  Values.restartFlagHostDir = restartFlagHostDir;
442
463
 
443
- const composition = docker.compose("matter.js", {
464
+ // MATTER_CHIP_BINS_SOURCE=cert-bins swaps the classic yaml/python tests' chip-tool for the
465
+ // official connectedhomeip/chip-cert-bins build; bind-mounted rather than baked into our own
466
+ // image so selecting it needs no image rebuild. Constants.chipToolPath (config.ts) already
467
+ // points --server_path at the mount below.
468
+ const chipBins = chipBinsSelected ? await prepareChipBins() : undefined;
469
+
470
+ const composition = docker.compose(HARNESS_COMPOSITION_NAME, {
444
471
  image: Constants.imageName,
445
472
  platform,
446
473
  binds: { [mdnsVolume.name]: "/run/dbus" },
@@ -451,7 +478,7 @@ async function configureContainer() {
451
478
  });
452
479
 
453
480
  await composition.add({
454
- name: "dbus",
481
+ name: HARNESS_DBUS_PART_NAME,
455
482
  command: ["/usr/bin/dbus-daemon", "--nopidfile", "--system", "--nofork"],
456
483
  });
457
484
 
@@ -466,6 +493,7 @@ async function configureContainer() {
466
493
  binds: {
467
494
  [mdnsVolume.name]: "/run/dbus",
468
495
  [restartFlagHostDir]: Constants.RestartFlagDir,
496
+ ...(chipBins ? { [chipBins.dir]: ContainerPaths.officialChipBinsDir } : {}),
469
497
  },
470
498
  });
471
499
 
@@ -509,8 +537,8 @@ async function configureScripts() {
509
537
  * Create a PICS file in the container appropriate for matter.js.
510
538
  */
511
539
  async function configurePics() {
512
- Values.defaultPics = await PicsSource.load(Constants.defaultPics);
513
- Values.defaultPicsFilename = await PicsSource.install(Values.defaultPics);
540
+ Values.defaultPics = await PicsSource.load(Constants.defaultPics, State.container);
541
+ Values.defaultPicsFilename = await PicsSource.install(State.container, Values.defaultPics);
514
542
  }
515
543
 
516
544
  /**
@@ -642,6 +670,9 @@ function createTest(descriptor: TestDescriptor) {
642
670
  case "py":
643
671
  return new PythonTest(descriptor as TestFileDescriptor, State.container, Values.restartFlagHostDir);
644
672
 
673
+ case "cert":
674
+ return createRegisteredCertTest(descriptor);
675
+
645
676
  default:
646
677
  throw new Error(`Cannot implement CHIP test ${descriptor.name} of kind ${descriptor.kind}`);
647
678
  }
@@ -104,7 +104,7 @@ export class YamlTest extends BaseTest {
104
104
 
105
105
  async invoke(subject: Subject, step: (title: string) => void, args: string[]) {
106
106
  if (!args.includes("--PICS")) {
107
- args.push("--PICS", await PicsSource.install(subject.pics));
107
+ args.push("--PICS", await PicsSource.install(this.container, subject.pics));
108
108
  }
109
109
 
110
110
  const runnerArgs =
package/src/cli.ts CHANGED
@@ -17,8 +17,26 @@ import { chip } from "./chip/chip.js";
17
17
  import { defaultDescriptor, printReport } from "./print-report.js";
18
18
  import { TestRunner } from "./runner.js";
19
19
  import { TestDescriptor } from "./test-descriptor.js";
20
+ import { wtf } from "./util/wtf.js";
20
21
 
21
- const SHUTDOWN_TIMEOUT_MS = 5_000;
22
+ function resolveShutdownTimeoutMs(): number {
23
+ const raw = process.env.MATTER_TEST_SHUTDOWN_TIMEOUT_MS;
24
+ if (raw === undefined) {
25
+ return 5_000;
26
+ }
27
+ const parsed = Number(raw);
28
+ if (!Number.isFinite(parsed) || parsed <= 0) {
29
+ console.error(
30
+ `Warning: MATTER_TEST_SHUTDOWN_TIMEOUT_MS="${raw}" is not a positive number; falling back to 5000ms.`,
31
+ );
32
+ return 5_000;
33
+ }
34
+ return parsed;
35
+ }
36
+
37
+ // A graceful session close can legitimately wait out a full MRP resubmission budget (several seconds) for an
38
+ // unacked flush send. Override via MATTER_TEST_SHUTDOWN_TIMEOUT_MS for suites that exercise that path routinely.
39
+ const SHUTDOWN_TIMEOUT_MS = resolveShutdownTimeoutMs();
22
40
 
23
41
  enum TestType {
24
42
  esm = "esm",
@@ -35,6 +53,9 @@ interface Config {
35
53
  }
36
54
 
37
55
  export async function main(argv = process.argv) {
56
+ // Must run before any timers/handles are created or wtfnode cannot attribute them
57
+ await wtf.initialize();
58
+
38
59
  process.on("SIGINT", interrupt);
39
60
  process.on("SIGTERM", interrupt);
40
61
 
@@ -232,7 +253,24 @@ export async function main(argv = process.argv) {
232
253
  if (diagnostics) {
233
254
  console.log("\nPROCESS STATE:\n", diagnostics, "\n");
234
255
  }
235
- process.exit(101);
256
+ console.error("Active resources:", process.getActiveResourcesInfo().join(", "));
257
+
258
+ // Fallback guarantees exit even if the wtfnode dump stalls
259
+ setTimeout(() => process.exit(101), 5_000).unref();
260
+ import("wtfnode").then(
261
+ ({ dump }) => {
262
+ try {
263
+ dump({ fullStacks: true });
264
+ } catch (error) {
265
+ console.error("Error: wtfnode dump failed:", error);
266
+ }
267
+ process.exit(101);
268
+ },
269
+ error => {
270
+ console.error("Error: wtfnode dump failed:", error);
271
+ process.exit(101);
272
+ },
273
+ );
236
274
  }, SHUTDOWN_TIMEOUT_MS);
237
275
  timeout.unref();
238
276
  }
@@ -4,8 +4,8 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
7
- import type Chai from "chai";
8
- import "chai-as-promised";
7
+ import type * as Chai from "chai" with { "resolution-mode": "import" };
8
+ import type {} from "chai-as-promised" with { "resolution-mode": "import" };
9
9
  import type { DiffMarker } from "./chai.js";
10
10
  import type { BootKind } from "./mocks/boot.js";
11
11
  import type { DiagnosticMessageLike, MockLogger } from "./mocks/logging.js";
@@ -7,8 +7,8 @@
7
7
  // Note - we don't import mocha here because in the browser we load their standard browser bundle which is different
8
8
  // from the Node version
9
9
 
10
- import Chai from "chai";
11
- import ChaiAsPromised from "chai-as-promised";
10
+ import * as Chai from "chai";
11
+ import * as ChaiAsPromised from "chai-as-promised";
12
12
 
13
13
  import { browserSetup, extendApi, generalSetup } from "./mocha.js";
14
14
  import { bootSetup } from "./mocks/boot.js";
@@ -16,7 +16,7 @@ import { MockLogger, loggerSetup } from "./mocks/logging.js";
16
16
  import { timeSetup } from "./mocks/time.js";
17
17
 
18
18
  // This must go here so it initializes early
19
- Chai.use(ChaiAsPromised);
19
+ Chai.use(pluginOf(ChaiAsPromised));
20
20
 
21
21
  Object.assign(globalThis, {
22
22
  expect: Chai.expect,
@@ -40,3 +40,27 @@ if (globalThis === (globalThis as any).window) {
40
40
  function interrupt() {
41
41
  // Interrupt handling is platform dependent
42
42
  }
43
+
44
+ function isPlugin(value: unknown): value is (chai: unknown, utils: unknown) => void {
45
+ return typeof value === "function";
46
+ }
47
+
48
+ /**
49
+ * Unwrap a chai plugin from its module.
50
+ *
51
+ * An ES module reaches our CommonJS build as a namespace object, which the interop layer then nests under
52
+ * "default" a second time, so the plugin sits at a depth that differs between our two build formats.
53
+ */
54
+ function pluginOf(module: unknown) {
55
+ let candidate = module;
56
+
57
+ while (!isPlugin(candidate) && typeof candidate === "object" && candidate !== null && "default" in candidate) {
58
+ candidate = candidate.default;
59
+ }
60
+
61
+ if (!isPlugin(candidate)) {
62
+ throw new Error("Chai plugin module does not export a plugin function");
63
+ }
64
+
65
+ return candidate;
66
+ }
package/src/index.d.ts CHANGED
@@ -11,5 +11,8 @@ export * from "./docker/index.js";
11
11
  export { afterRun } from "./mocha.js";
12
12
  export * from "./mocharc.cjs";
13
13
  export * from "./runner.js";
14
+ /** @internal Test seam — not API. Needed to construct a {@link CertTest} directly in a unit test. */
15
+ export type { TestFileDescriptor } from "./test-descriptor.js";
16
+ export { LineQueue } from "./util/async.js";
14
17
  export * from "./util/heap.js";
15
18
  export * from "./util/wtf.js";
package/src/index.js CHANGED
@@ -11,5 +11,6 @@ export * from "./docker/index.js";
11
11
  export { afterRun } from "./mocha.js";
12
12
  export * from "./mocharc.cjs";
13
13
  export * from "./runner.js";
14
+ export { LineQueue } from "./util/async.js";
14
15
  export * from "./util/heap.js";
15
16
  export * from "./util/wtf.js";
package/src/mocha.ts CHANGED
@@ -89,7 +89,20 @@ export function generalSetup(mocha: Mocha) {
89
89
  TextDiff.generator = Base.generateDiff.bind(Base);
90
90
  }
91
91
 
92
+ // `global-definitions.ts` and `nodejs.ts` each call extendApi() unconditionally at module load, and
93
+ // nothing previously made both land in the same process — a test file that transitively reaches
94
+ // `state.ts` (e.g. via `python-test.ts`) does, and the second call's Object.defineProperty on the
95
+ // same Mocha.Suite.prototype then throws "Cannot redefine property". Guard by Mocha class identity
96
+ // (not a bare flag) so a genuinely different Mocha instance in a separate module registry still gets
97
+ // instrumented once.
98
+ const extendedMochas = new WeakSet<typeof MochaType>();
99
+
92
100
  export function extendApi(Mocha: typeof MochaType) {
101
+ if (extendedMochas.has(Mocha)) {
102
+ return;
103
+ }
104
+ extendedMochas.add(Mocha);
105
+
93
106
  (Mocha.Runnable.prototype as any)._timeoutError = function (timeoutMs: number) {
94
107
  // We use our error class so we get diagnostics and message isn't so verbose
95
108
  const error = new TestTimeoutError(`Timeout of ${timeoutMs}ms exceeded`);
package/src/mocharc.cjs CHANGED
@@ -14,11 +14,12 @@ if (globalThis.crypto === undefined) {
14
14
  }
15
15
 
16
16
  function mocharc(format = "cjs") {
17
- const { resolve } = require("path");
17
+ const { dirname, resolve } = require("path");
18
18
  const cli = require("mocha/lib/cli/cli");
19
19
  const listSupportFiles = require("./util/files.js").listSupportFiles;
20
20
 
21
- const TOOLS = resolve(__dirname, "../../../tools");
21
+ // The package exports no subpath for its binaries, so derive their location from the main entry point
22
+ const buildJs = resolve(dirname(require.resolve("@nacho-iot/js-tools")), "..", "..", "bin", "build.js");
22
23
 
23
24
  const testJs = `build/${format}/test`;
24
25
  const defaultSpec = `${testJs}/**/*Test.js`;
@@ -26,7 +27,7 @@ function mocharc(format = "cjs") {
26
27
  // Build. Ideally we'd import build code but it's asynchronous and mocharc isn't. So instead build in a separate
27
28
  // process
28
29
  const spawnSync = require("child_process").spawnSync;
29
- const result = spawnSync(`${TOOLS}/bin/build.js`, [format], { stdio: "inherit" });
30
+ const result = spawnSync(process.execPath, [buildJs, format], { stdio: "inherit" });
30
31
  if (result.error) {
31
32
  console.error(result.error);
32
33
  process.exit(-1);
@@ -34,7 +34,7 @@ function printDescriptor(descriptor: TestDescriptor, includeDisabled?: boolean,
34
34
 
35
35
  let steps: undefined | number;
36
36
  if (submembers.length) {
37
- if (member.kind === "py" || member.kind === "yaml" || member.kind === "manual") {
37
+ if (member.kind === "py" || member.kind === "yaml" || member.kind === "manual" || member.kind === "cert") {
38
38
  steps = submembers.length;
39
39
  submembers = [];
40
40
  } else {
@@ -49,7 +49,7 @@ export namespace TestDescriptor {
49
49
  */
50
50
  export const CURRENT_FORMAT = 2;
51
51
 
52
- export type Kind = "suite" | "js" | "py" | "yaml" | "manual" | "step";
52
+ export type Kind = "suite" | "js" | "py" | "yaml" | "manual" | "step" | "cert";
53
53
 
54
54
  export const DEFAULT_FILENAME = "build/test-report.json";
55
55
 
@@ -0,0 +1,83 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022-2026 Matter.js Authors
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ /**
8
+ * A push/pull line buffer: producers {@link push} synchronously, consumers iterate asynchronously.
9
+ * Any number of independent iterations (via {@link follow} or `for await` directly) each replay
10
+ * every line seen so far before tailing live until {@link close}. Lines are buffered for the
11
+ * queue's lifetime — the replay contract precludes dropping them.
12
+ *
13
+ * Structurally satisfies `LogSource` (`chip/cert/cert-context.ts`) via {@link follow}.
14
+ */
15
+ export class LineQueue implements AsyncIterable<string> {
16
+ #lines = new Array<string>();
17
+ #closed = false;
18
+ #waiters = new Array<() => void>();
19
+
20
+ push(line: string): void {
21
+ this.#lines.push(line);
22
+ this.#wake();
23
+ }
24
+
25
+ close(): void {
26
+ if (this.#closed) {
27
+ return;
28
+ }
29
+ this.#closed = true;
30
+ this.#wake();
31
+ }
32
+
33
+ follow(): AsyncIterable<string> {
34
+ return this.#iterate();
35
+ }
36
+
37
+ /** Forwards every line of `source` into the queue; resolves when `source` ends. */
38
+ async pump(source: AsyncIterable<string>): Promise<void> {
39
+ for await (const line of source) {
40
+ this.push(line);
41
+ }
42
+ }
43
+
44
+ [Symbol.asyncIterator](): AsyncIterator<string> {
45
+ return this.#iterate()[Symbol.asyncIterator]();
46
+ }
47
+
48
+ #wake(): void {
49
+ const waiters = this.#waiters;
50
+ this.#waiters = new Array<() => void>();
51
+ for (const waiter of waiters) {
52
+ waiter();
53
+ }
54
+ }
55
+
56
+ async *#iterate(): AsyncGenerator<string> {
57
+ let index = 0;
58
+ for (;;) {
59
+ while (index < this.#lines.length) {
60
+ yield this.#lines[index++];
61
+ }
62
+ if (this.#closed) {
63
+ return;
64
+ }
65
+ await new Promise<void>(resolve => this.#waiters.push(resolve));
66
+ }
67
+ }
68
+ }
69
+
70
+ // Node clamps a setTimeout delay above this to 1ms, which would busy-spin a timer/wake race
71
+ // instead of actually waiting.
72
+ const MAX_TIMEOUT_MS = 0x7fffffff;
73
+
74
+ /**
75
+ * A cancellable timeout for racing against other async work.
76
+ */
77
+ export function delay(ms: number): { promise: Promise<"timeout">; cancel: () => void } {
78
+ let timer: ReturnType<typeof setTimeout>;
79
+ const promise = new Promise<"timeout">(resolve => {
80
+ timer = setTimeout(() => resolve("timeout"), Math.min(ms, MAX_TIMEOUT_MS));
81
+ });
82
+ return { promise, cancel: () => clearTimeout(timer) };
83
+ }
package/src/util/wtf.ts CHANGED
@@ -18,7 +18,9 @@ export const wtf = {
18
18
  }
19
19
 
20
20
  const { dump } = await import("wtfnode");
21
- this.dump = () => dump();
21
+ // Full stacks capture each timer's creation site — the callback alone only points at the
22
+ // shared Time-abstraction wrapper
23
+ this.dump = () => dump({ fullStacks: true });
22
24
  },
23
25
 
24
26
  dump() {},
package/src/web.ts CHANGED
@@ -168,7 +168,11 @@ async function bundle(files: string[], { pkg, entrypointPreprocessor }: TestRunn
168
168
  bundle: true,
169
169
  format: "cjs",
170
170
  outfile: bundlePath,
171
- external: ["wtfnode"],
171
+ // Node-only test-support code (e.g. chip-app-subject.ts's process/container spawning) is
172
+ // dynamically imported behind a `typeof window === "undefined"` guard so it never actually
173
+ // runs in the browser; these entries just let esbuild leave the (unreachable) requires as-is
174
+ // instead of failing to resolve them.
175
+ external: ["wtfnode", "node:*", "dockerode"],
172
176
  keepNames: true,
173
177
  conditions: ["static-load"],
174
178