@agiledigital/pingone-aic-script-tester 0.1.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.
Files changed (169) hide show
  1. package/LICENSE-APACHE +201 -0
  2. package/LICENSE-MIT +21 -0
  3. package/README.md +274 -0
  4. package/dist/bin/fetch-jar.d.ts +2 -0
  5. package/dist/bin/fetch-jar.js +13 -0
  6. package/dist/bin/pull-profile.d.ts +2 -0
  7. package/dist/bin/pull-profile.js +40 -0
  8. package/dist/bin/show-log.d.ts +2 -0
  9. package/dist/bin/show-log.js +31 -0
  10. package/dist/classes/.complete +12 -0
  11. package/dist/classes/AmClassShutter.class +0 -0
  12. package/dist/classes/AmContextFactory$ObservedContext.class +0 -0
  13. package/dist/classes/AmContextFactory.class +0 -0
  14. package/dist/classes/AmScopes.class +0 -0
  15. package/dist/classes/HostOps.class +0 -0
  16. package/dist/classes/JsValues.class +0 -0
  17. package/dist/classes/Json$Parser.class +0 -0
  18. package/dist/classes/Json.class +0 -0
  19. package/dist/classes/LanguageVersions.class +0 -0
  20. package/dist/classes/Runner.class +0 -0
  21. package/dist/classes/ScriptContextScope.class +0 -0
  22. package/dist/src/aic/callbacks.d.ts +35 -0
  23. package/dist/src/aic/callbacks.js +130 -0
  24. package/dist/src/aic/conform.d.ts +90 -0
  25. package/dist/src/aic/conform.js +193 -0
  26. package/dist/src/aic/constants.d.ts +13 -0
  27. package/dist/src/aic/constants.js +13 -0
  28. package/dist/src/aic/diff.d.ts +25 -0
  29. package/dist/src/aic/diff.js +201 -0
  30. package/dist/src/aic/emit-journey.d.ts +64 -0
  31. package/dist/src/aic/emit-journey.js +254 -0
  32. package/dist/src/aic/emit-result.d.ts +10 -0
  33. package/dist/src/aic/emit-result.js +39 -0
  34. package/dist/src/aic/emit-session.d.ts +26 -0
  35. package/dist/src/aic/emit-session.js +132 -0
  36. package/dist/src/aic/emit-subject.d.ts +40 -0
  37. package/dist/src/aic/emit-subject.js +210 -0
  38. package/dist/src/aic/file-lease.d.ts +35 -0
  39. package/dist/src/aic/file-lease.js +543 -0
  40. package/dist/src/aic/http.d.ts +21 -0
  41. package/dist/src/aic/http.js +127 -0
  42. package/dist/src/aic/idm.d.ts +10 -0
  43. package/dist/src/aic/idm.js +112 -0
  44. package/dist/src/aic/index.d.ts +35 -0
  45. package/dist/src/aic/index.js +21 -0
  46. package/dist/src/aic/js.d.ts +8 -0
  47. package/dist/src/aic/js.js +11 -0
  48. package/dist/src/aic/lease-identity.d.ts +38 -0
  49. package/dist/src/aic/lease-identity.js +72 -0
  50. package/dist/src/aic/lease-lock.d.ts +45 -0
  51. package/dist/src/aic/lease-lock.js +173 -0
  52. package/dist/src/aic/managed.d.ts +28 -0
  53. package/dist/src/aic/managed.js +199 -0
  54. package/dist/src/aic/provider.d.ts +156 -0
  55. package/dist/src/aic/provider.js +416 -0
  56. package/dist/src/aic/record.d.ts +28 -0
  57. package/dist/src/aic/record.js +183 -0
  58. package/dist/src/aic/resource-snapshot.d.ts +12 -0
  59. package/dist/src/aic/resource-snapshot.js +116 -0
  60. package/dist/src/aic/run.d.ts +102 -0
  61. package/dist/src/aic/run.js +450 -0
  62. package/dist/src/aic/tenant.d.ts +107 -0
  63. package/dist/src/aic/tenant.js +307 -0
  64. package/dist/src/aic/trace.d.ts +25 -0
  65. package/dist/src/aic/trace.js +56 -0
  66. package/dist/src/aic/txid.d.ts +11 -0
  67. package/dist/src/aic/txid.js +25 -0
  68. package/dist/src/aic/unsupported.d.ts +15 -0
  69. package/dist/src/aic/unsupported.js +60 -0
  70. package/dist/src/bindings/allowlist.d.ts +42 -0
  71. package/dist/src/bindings/allowlist.js +62 -0
  72. package/dist/src/bindings/harvest.d.ts +7 -0
  73. package/dist/src/bindings/harvest.js +137 -0
  74. package/dist/src/bindings/index.d.ts +4 -0
  75. package/dist/src/bindings/index.js +3 -0
  76. package/dist/src/bindings/preamble.d.ts +23 -0
  77. package/dist/src/bindings/preamble.js +36 -0
  78. package/dist/src/bindings/run.d.ts +33 -0
  79. package/dist/src/bindings/run.js +55 -0
  80. package/dist/src/case/equal.d.ts +2 -0
  81. package/dist/src/case/equal.js +40 -0
  82. package/dist/src/case/index.d.ts +5 -0
  83. package/dist/src/case/index.js +4 -0
  84. package/dist/src/case/portable.d.ts +10 -0
  85. package/dist/src/case/portable.js +28 -0
  86. package/dist/src/case/session.d.ts +34 -0
  87. package/dist/src/case/session.js +66 -0
  88. package/dist/src/case/state.d.ts +4 -0
  89. package/dist/src/case/state.js +47 -0
  90. package/dist/src/case/types.d.ts +266 -0
  91. package/dist/src/case/types.js +106 -0
  92. package/dist/src/case/util.d.ts +7 -0
  93. package/dist/src/case/util.js +115 -0
  94. package/dist/src/case/validate.d.ts +8 -0
  95. package/dist/src/case/validate.js +463 -0
  96. package/dist/src/case/verdict.d.ts +6 -0
  97. package/dist/src/case/verdict.js +810 -0
  98. package/dist/src/diagnostics.d.ts +7 -0
  99. package/dist/src/diagnostics.js +5 -0
  100. package/dist/src/emit-dts.d.ts +2 -0
  101. package/dist/src/emit-dts.js +82 -0
  102. package/dist/src/emit-js.d.ts +3 -0
  103. package/dist/src/emit-js.js +149 -0
  104. package/dist/src/harness/failures.d.ts +26 -0
  105. package/dist/src/harness/failures.js +113 -0
  106. package/dist/src/harness/idm.d.ts +12 -0
  107. package/dist/src/harness/idm.js +44 -0
  108. package/dist/src/harness/index.d.ts +11 -0
  109. package/dist/src/harness/index.js +6 -0
  110. package/dist/src/harness/lease.d.ts +136 -0
  111. package/dist/src/harness/lease.js +286 -0
  112. package/dist/src/harness/residue.d.ts +23 -0
  113. package/dist/src/harness/residue.js +73 -0
  114. package/dist/src/harness/show-log.d.ts +43 -0
  115. package/dist/src/harness/show-log.js +253 -0
  116. package/dist/src/harness/spec.d.ts +67 -0
  117. package/dist/src/harness/spec.js +189 -0
  118. package/dist/src/harness/step.d.ts +80 -0
  119. package/dist/src/harness/step.js +97 -0
  120. package/dist/src/harness/types.d.ts +100 -0
  121. package/dist/src/harness/types.js +1 -0
  122. package/dist/src/harness/vitest.d.ts +52 -0
  123. package/dist/src/harness/vitest.js +155 -0
  124. package/dist/src/idents.d.ts +4 -0
  125. package/dist/src/idents.js +42 -0
  126. package/dist/src/jvm.d.ts +124 -0
  127. package/dist/src/jvm.js +432 -0
  128. package/dist/src/load.d.ts +2 -0
  129. package/dist/src/load.js +104 -0
  130. package/dist/src/paths.d.ts +36 -0
  131. package/dist/src/paths.js +50 -0
  132. package/dist/src/profile/index.d.ts +5 -0
  133. package/dist/src/profile/index.js +3 -0
  134. package/dist/src/profile/normalise.d.ts +16 -0
  135. package/dist/src/profile/normalise.js +106 -0
  136. package/dist/src/profile/pull.d.ts +22 -0
  137. package/dist/src/profile/pull.js +36 -0
  138. package/dist/src/profile/seed.d.ts +11 -0
  139. package/dist/src/profile/seed.js +28 -0
  140. package/dist/src/profile/store.d.ts +13 -0
  141. package/dist/src/profile/store.js +60 -0
  142. package/dist/src/profile/types.d.ts +45 -0
  143. package/dist/src/profile/types.js +1 -0
  144. package/dist/src/profile/validate.d.ts +38 -0
  145. package/dist/src/profile/validate.js +129 -0
  146. package/dist/src/project.d.ts +37 -0
  147. package/dist/src/project.js +93 -0
  148. package/dist/src/protocol.d.ts +62 -0
  149. package/dist/src/protocol.js +68 -0
  150. package/dist/src/provider-module.d.ts +11 -0
  151. package/dist/src/provider-module.js +46 -0
  152. package/dist/src/runner.d.ts +39 -0
  153. package/dist/src/runner.js +337 -0
  154. package/dist/src/schema.d.ts +48 -0
  155. package/dist/src/schema.js +93 -0
  156. package/generated/scripted-decision-mocks.cjs +722 -0
  157. package/generated/scripted-decision-mocks.d.ts +626 -0
  158. package/generated/scripted-decision-next.json +3640 -0
  159. package/java/AmClassShutter.java +98 -0
  160. package/java/AmContextFactory.java +69 -0
  161. package/java/AmScopes.java +49 -0
  162. package/java/HostOps.java +180 -0
  163. package/java/JsValues.java +39 -0
  164. package/java/Json.java +441 -0
  165. package/java/LanguageVersions.java +55 -0
  166. package/java/Runner.java +289 -0
  167. package/java/ScriptContextScope.java +147 -0
  168. package/package.json +88 -0
  169. package/src/bindings/rhino/runtime.cjs +3021 -0
package/LICENSE-APACHE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/LICENSE-MIT ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Agile Digital
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,274 @@
1
+ # rhino-local TypeScript package
2
+
3
+ Two jobs, one package:
4
+
5
+ 1. Generate the **scripted-decision mock binding surface** from the captured AM
6
+ contexts metadata at `docs/api/bindings/scripted-decision-next.json`.
7
+ 2. Talk to the long-lived host-JVM runner so tests can eval scripts without
8
+ starting a JVM per case.
9
+
10
+ The generator emits presence, not behaviour: every method throws
11
+ `rhino-local: not mocked: <binding>.<method> arity=N overload=[…]` until the
12
+ handwritten overlay in `src/bindings/rhino/runtime.cjs` replaces it. A mock
13
+ that returned `undefined` would turn a missing feature into a passing test.
14
+
15
+ Implemented (still fail-loud for missing fixtures and for every method the
16
+ overlay does not replace): `nodeState` get/putShared/putTransient/isDefined,
17
+ legacy `sharedState`/`transientState` when `given.engine === "legacy"`,
18
+ request maps, `outcome` / `action.goTo`, `logger`, `openidm`, `httpClient`,
19
+ `callbacksBuilder` (the six authenticate-response types), `systemEnv`,
20
+ `idRepository.getIdentity`, next-gen `require()` (CommonJS eval of seeded
21
+ library bodies; a missing id throws naming `given.libraries`), legacy
22
+ `JavaImporter` + `Action.send(HiddenValueCallback)`. End-to-end cases live
23
+ in `cases/`.
24
+
25
+ ## Using the installed package
26
+
27
+ ```sh
28
+ npm install --save-dev @agiledigital/pingone-aic-script-tester vitest zod
29
+ ```
30
+
31
+ **Requirements**:
32
+
33
+ - Node 24.
34
+ - A Java 25 **runtime**. The runner classes are prebuilt, so no `javac` is
35
+ needed. Use `AIC_SCRIPT_TESTER_JAVA_HOME` or `JAVA_HOME`, else `java` on `PATH`.
36
+ - `vitest` and `zod`, as peer dependencies.
37
+
38
+ The first run downloads the Rhino jar from Maven Central and checks it by
39
+ SHA-256. On a machine without access, point `AIC_SCRIPT_TESTER_RHINO_JAR` at a copy
40
+ instead. `npx aic-script-tester-fetch-jar` fills the cache ahead of time.
41
+
42
+ A suite runs on the local lane by default:
43
+
44
+ ```ts
45
+ import { describe, expect, it } from "vitest";
46
+ import { z } from "zod";
47
+ import { defineSuite, useLease } from "@agiledigital/pingone-aic-script-tester";
48
+
49
+ const suite = defineSuite({
50
+ name: "greet",
51
+ script: 'if (nodeState.get("userId") === "alice") { action.goTo("known"); } else { action.goTo("unknown"); }',
52
+ outcomes: ["known", "unknown"],
53
+ inputs: z.object({ userId: z.string() }),
54
+ });
55
+
56
+ describe("greet", () => {
57
+ const lease = useLease(suite);
58
+ it("knows alice", async () => {
59
+ const run = await lease.run({ userId: "alice" }).expect({ outcome: "known" });
60
+ expect(run.verdict.summary).toBe("");
61
+ });
62
+ });
63
+ ```
64
+
65
+ To run the same suite against a tenant, spread `aicWhenEnabled("<unique-id>")`
66
+ into the `useLease` options, then run with `AIC_SCRIPT_TESTER_AIC=1`. The tenant
67
+ comes from the first of these that is configured:
68
+
69
+ 1. a `provider` passed in the options;
70
+ 2. a provider registered with `setTenantProvider()`, typically from a Vitest
71
+ `setupFiles` module;
72
+ 3. the environment: `AIC_SCRIPT_TESTER_TENANT_URL` (https, no path), plus either
73
+ `AIC_SCRIPT_TESTER_SA_ID` with `AIC_SCRIPT_TESTER_SA_JWK` or `AIC_SCRIPT_TESTER_SA_JWK_FILE`,
74
+ plus optional `AIC_SCRIPT_TESTER_LOG_KEY_ID` and `AIC_SCRIPT_TESTER_LOG_KEY_SECRET`;
75
+ 4. the `aic` CLI (`AIC_BIN`).
76
+
77
+ A partial environment configuration is an error rather than a fallthrough.
78
+
79
+ ```ts
80
+ // test/tenant.setup.ts — list it in vitest.config's test.setupFiles
81
+ import { setTenantProvider, tokenCallbackProvider } from "@agiledigital/pingone-aic-script-tester/aic";
82
+
83
+ setTenantProvider(
84
+ tokenCallbackProvider({
85
+ baseUrl: "https://tenant.example.com",
86
+ // Called again with reason "rejected" after a 401; don't return the same token.
87
+ getToken: async ({ reason }) => fetchBearerSomehow(reason),
88
+ // Optional, and needed only for aic-script-tester-show-log.
89
+ logKeys: { id: process.env.LOG_KEY_ID!, secret: process.env.LOG_KEY_SECRET! },
90
+ })
91
+ );
92
+ ```
93
+
94
+ **State.** Failure records, the log view and environment profiles can all
95
+ contain tenant data. They go to `<project>/.aic-script-tester/`, which writes its own
96
+ `*` `.gitignore`; the files are `0600`. `<project>` is the nearest ancestor with
97
+ a `.git`. `AIC_SCRIPT_TESTER_PROJECT` overrides the project and `AIC_SCRIPT_TESTER_STATE_DIR`
98
+ overrides the directory.
99
+
100
+ **Bins.** Both commands that talk to a tenant take
101
+ `--provider-module <file>`. That is the same setup module, or any module whose
102
+ default export is a `TenantProvider`. It exists because a bin runs in its own
103
+ process, where the Vitest registration does not reach.
104
+
105
+ - `aic-script-tester-pull-profile [--tenant <name>]` writes
106
+ `.aic-script-tester/profiles/<tenant>.json`. It prints only counts.
107
+ - `aic-script-tester-show-log [--stdout]` fetches the logs of recorded failures. It
108
+ writes them to `.aic-script-tester/failures/latest-logs.json`, and opens that in
109
+ `$LOGS_EDITOR` or `$EDITOR` if one is set. `--stdout` prints them instead;
110
+ don't use it in CI.
111
+
112
+ **Entry points:**
113
+
114
+ | Import | What it provides |
115
+ | --- | --- |
116
+ | `.` | the harness |
117
+ | `./case` | case definition and judging |
118
+ | `./aic` | providers and `setTenantProvider` |
119
+ | `./profile` | `pullProfile` and the profile store |
120
+ | `./diagnostics` | failure records, `runShowLog` and `loadProviderModule` |
121
+ | `./bindings` | the bindings runtime |
122
+ | `./runner` | `RhinoRunner` |
123
+
124
+ More detail lives in this repository's `docs/rhino-local-harness.md`, which is
125
+ not shipped with the package.
126
+
127
+ ## JVM runner client
128
+
129
+ `src/runner.ts` launches Java 25 from `AIC_SCRIPT_TESTER_JAVA_HOME` or `JAVA_HOME`
130
+ (`shell.nix` provides `temurin-bin-25`) and speaks line-delimited JSON.
131
+ `AIC_SCRIPT_TESTER_JVM` selects `host` (default), `container`, or `both`; the latter
132
+ lanes require Docker and the AM image. The cache defaults to
133
+ `~/.cache/aic-script-tester`; `AIC_SCRIPT_TESTER_CACHE` overrides it. Correlate by job `id`
134
+ — do not assume the JVM answers in order. A crashed JVM rejects every pending
135
+ job rather than hanging. `close()` ends stdin and waits for the process;
136
+ `afterAll` should call it.
137
+
138
+ Job shape (open enough to carry later mock bindings):
139
+
140
+ - `source` / `sourceName` — author's script; `sourceName` is Rhino's source
141
+ name, so a parse error names the author's file and line, not `<eval>`
142
+ - `globals` — JSON values placed in ENGINE_SCOPE Bindings
143
+ - `preamble` — evaluated first so concatenating mocks into `source` is not
144
+ needed (that would shift line numbers)
145
+ - `timeoutMs` — per-job; AM's `Error("Interrupt.")` past the instruction
146
+ observer. Omit for the runner's 10s harness default; `0` is AM's no-timeout
147
+
148
+ Outcomes are machine-readable and distinct: `ok`, `compile_error`,
149
+ `runtime_error`, `timeout`.
150
+
151
+ ## Artefacts
152
+
153
+ Committed under `generated/`:
154
+
155
+ - `scripted-decision-mocks.cjs` — evaluated inside AM's Rhino as part of the
156
+ script-under-test's scope
157
+ - `scripted-decision-mocks.d.ts` — TypeScript types for case authors
158
+
159
+ They are committed on purpose. Regenerating after Ping adds a method produces a
160
+ diff of the surface, which is the point of generating rather than hand-writing.
161
+
162
+ ## Re-run
163
+
164
+ From this directory (Node 24):
165
+
166
+ ```bash
167
+ npm install
168
+ npm run generate
169
+ npm test
170
+ npm run typecheck
171
+ npm run lint
172
+ npm run lint:am
173
+ npm run measure # JVM startup + per-job timings
174
+ npm run show-log # fetch AIC logs for a failed test (needs `aic login`)
175
+ ```
176
+
177
+ When a test that hit the AIC lane fails, `useLease` appends a JSONL record to
178
+ `.aic-script-tester/failures/failures.jsonl`. `npm run show-log` lists those records
179
+ newest first and fetches their logs from the tenant provider: the `aic` CLI's
180
+ `aic logs tx`, or the log API when log keys are configured. It fetches the
181
+ stem first, so one call covers a whole authenticate chain, and it never issues
182
+ a range query. It writes the logs to the 0600 view described above.
183
+
184
+ ## Per-file AIC lease
185
+
186
+ Opt a suite into automatic local-versus-AIC checking through `useLease`:
187
+
188
+ ```ts
189
+ const lease = useLease(suite, {
190
+ aic: {
191
+ id: "resolve-identity",
192
+ realm: "alpha",
193
+ unsupported: "fail",
194
+ },
195
+ });
196
+ ```
197
+
198
+ `id` is a stable, repository-chosen lease identity. The adapter opens one
199
+ deterministically named journey before the file, replaces and confirms its
200
+ subject script for each run, invokes it, and deletes the graph after the file.
201
+ `realm` defaults to `alpha` and seeds the same realm into the local lane;
202
+ `tenant` selects an AIC context, and `project` selects the CLI project and
203
+ binary location. Both are optional and otherwise use the current defaults.
204
+ The returned `RunResult.conformance` contains the per-pass AIC verdict,
205
+ disagreements, and observation gaps. A file may have only one AIC-enabled
206
+ `useLease`; split different scripts or outcome vocabularies into separate test
207
+ files.
208
+
209
+ Unsupported input fails by default. `unsupported: "skip"` is the explicit
210
+ opt-out for a suite that must retain skip behaviour. Step and final `check()`
211
+ hooks replay against a tenant-backed `IdmHandle` at their matching response
212
+ boundaries. Suite `cleanup()` runs afterwards in a `finally`, before fixture
213
+ deletion, even if a check throws. The remote handle returns full materialized
214
+ tenant records rather than projecting them to the local mock's shape, so assert
215
+ the fields a check needs instead of whole-record equality. An AIC-only throw is
216
+ reported as a lane disagreement naming the remote hook.
217
+
218
+ Object-form queries reject values that cannot be represented faithfully as the
219
+ measured CREST `eq` filter (quotes, nulls, arrays/objects, control characters,
220
+ and non-finite numbers) before making a request. Unknown fields are not
221
+ preflighted because AIC reports them as a successful zero-row query.
222
+
223
+ Every AM write is followed by a confirming read. A process lock excludes the
224
+ same lease on one host, and an identifier-only journal makes stale owned
225
+ resources discoverable after process death. Simultaneous use of the same
226
+ `aic.id` on different hosts is unsupported because no atomic AM create
227
+ precondition has been established. Generated subject and session-minter source
228
+ can contain test seeds while a lease is open; never put credentials or real
229
+ secrets in them.
230
+
231
+ For capacity planning only, the design estimate uses `O` distinct subject
232
+ outcomes after adding `true` and `false`, and `R = 2O + 3` graph resources. For
233
+ `N` one-pass cases without managed fixtures or sessions, the base call count is
234
+ `2 + 4R + 3N`: two CLI session calls, three calls per resource at
235
+ open, one delete per resource at close, and three calls per case. At the
236
+ smallest `R = 9`, that is an estimated `38 + 3N`, or 68 calls for ten cases.
237
+ Each `IdmHandle` read, encodable query, or delete in checks/cleanup adds one REST
238
+ call. Each additional outcome adds an estimated eight file-lifetime calls.
239
+ Step chains, managed fixtures, session minting, and credential refresh add
240
+ calls too.
241
+
242
+ `runAicChain()` remains the one-shot compatibility facade for external callers.
243
+ It provisions and deletes a throwaway graph per call. `useLease()` uses the
244
+ pre-opened file runner and does not route through that facade.
245
+
246
+ `npm run generate` reads the captured JSON (offline; it does not call the
247
+ tenant) and overwrites the two artefacts. Completeness tests fail if the
248
+ artefacts drift from the JSON, if a method is dropped, or if you forget to
249
+ regenerate after changing the emitter.
250
+
251
+ ## The `.cjs` is AM-safe JavaScript
252
+
253
+ The generated mock is **not** Node. AM's Rhino 1.7.14 rejects or silently
254
+ miscompiles a large slice of ES2015; the rules are runtime-verified in
255
+ `docs/api/12-script-bindings-matrix.md` and encoded in
256
+ `src/scripts/templates/am/eslint.config.js`. The emitter stays inside that
257
+ subset:
258
+
259
+ - `var` at top level; **no `let`**; **no top-level `const`** (parses, then
260
+ reads back `undefined` in a scripted-decision script)
261
+ - **no `for...of`**, object shorthand, destructuring, or default parameters
262
+ - **no `Map` / `Set` / `Symbol` / `Promise` / `WeakMap` / `WeakSet`**
263
+ - `function () { … arguments … }` for methods (no rest parameters)
264
+ - `const` _inside a function_ is allowed; this file just does not need it
265
+
266
+ `npm run lint:am` runs those Rhino rules over `generated/*.cjs`. The generator
267
+ itself is ordinary TypeScript and has no such limits.
268
+
269
+ ## What the JSON does not name
270
+
271
+ Empty-`elements` bindings (`requestHeaders`, `requestParameters`,
272
+ `requestCookies`, `locales`) are emitted as `{}` — a seam a test case seeds
273
+ directly. Scalar bindings (`realm`, `scriptName`, `cookieName`) start as
274
+ `"__rhino-local-unseeded__"`; `resumedFromSuspend` starts as `false`.
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Download and verify the pinned Rhino jar into the cache, and print its path.
4
+ *
5
+ * npx aic-script-tester-fetch-jar
6
+ *
7
+ * For machines that will run offline later, or CI images that pre-seed a
8
+ * cache. The jar is not bundled with the package (it is MPL-2.0 and 1.4 MB);
9
+ * a machine that cannot reach Maven Central can point AIC_SCRIPT_TESTER_RHINO_JAR at
10
+ * a copy instead, which is verified by the same SHA-256.
11
+ */
12
+ import { ensureRhinoJar } from "../src/jvm.js";
13
+ process.stdout.write(`${await ensureRhinoJar()}\n`);
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Pull an environment's managed-object schema into a harness profile.
4
+ *
5
+ * aic-script-tester-pull-profile [--tenant <name>] [--provider-module <file>]
6
+ *
7
+ * The tenant and bearer come from the configured tenant provider: the module
8
+ * named by `--provider-module`, else the AIC_SCRIPT_TESTER_TENANT_URL environment,
9
+ * else the current `aic` context. The bearer is never written to disk.
10
+ *
11
+ * Only counts are printed. The object names are the tenant's business
12
+ * vocabulary, and the tenant's name defaults to its hostname; both belong in
13
+ * the profile, not in a terminal or CI log.
14
+ */
15
+ import { dirname, join } from "node:path";
16
+ import { parseArgs } from "node:util";
17
+ import { pullProfile } from "../src/profile/pull.js";
18
+ import { loadProviderModule } from "../src/provider-module.js";
19
+ try {
20
+ const { values } = parseArgs({
21
+ options: {
22
+ tenant: { type: "string" },
23
+ "provider-module": { type: "string" },
24
+ },
25
+ });
26
+ if (values["provider-module"] !== undefined) {
27
+ await loadProviderModule(values["provider-module"]);
28
+ }
29
+ const { profile, path } = await pullProfile(values.tenant !== undefined ? { tenant: values.tenant } : {});
30
+ const names = Object.keys(profile.objects);
31
+ const fields = names.reduce((total, name) => total + Object.keys(profile.objects[name].properties).length, 0);
32
+ console.log(`pulled ${profile.pulledAt}`);
33
+ console.log(`objects ${names.length} (${fields} properties)`);
34
+ // The file is named after the tenant, whose name defaults to its hostname.
35
+ console.log(`written ${join(dirname(path), "<tenant>.json")}`);
36
+ }
37
+ catch (error) {
38
+ console.error(error instanceof Error ? error.message : String(error));
39
+ process.exit(1);
40
+ }
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * List failed AIC-lane tests and fetch their logs.
4
+ *
5
+ * aic-script-tester-show-log [--stdout] [--provider-module <file>]
6
+ *
7
+ * The logs are written to `.aic-script-tester/failures/latest-logs.json` (0600) and
8
+ * opened in LOGS_EDITOR or EDITOR; `--stdout` prints them instead. Logs come
9
+ * from the configured tenant provider (see `--provider-module`), which must
10
+ * have log access: log keys, or the `aic` CLI. Fetches one transaction at a
11
+ * time — never a range query.
12
+ */
13
+ import { parseArgs } from "node:util";
14
+ import { createDefaultIo, runShowLog } from "../src/harness/show-log.js";
15
+ import { loadProviderModule } from "../src/provider-module.js";
16
+ try {
17
+ const { values } = parseArgs({
18
+ options: {
19
+ stdout: { type: "boolean", default: false },
20
+ "provider-module": { type: "string" },
21
+ },
22
+ });
23
+ if (values["provider-module"] !== undefined) {
24
+ await loadProviderModule(values["provider-module"]);
25
+ }
26
+ process.exitCode = await runShowLog(createDefaultIo(), { stdout: values.stdout });
27
+ }
28
+ catch (error) {
29
+ console.error(error instanceof Error ? error.message : String(error));
30
+ process.exit(1);
31
+ }
@@ -0,0 +1,12 @@
1
+ 2f4387af5b2f111c
2
+ ed27b76cb8af30b744db60bc39392239b55e1925de636eefe9f8cd78b76c386c AmClassShutter.class
3
+ 0249ef274d91e63f807f6e444c64801e3a4bbd6377fa48b51d9d04df46e842c6 AmContextFactory$ObservedContext.class
4
+ d015aab82d1d78ea19b6c3c8737c60e54f6f446a2373c77999e950197a3bb242 AmContextFactory.class
5
+ 6fa95dff1410b7b26c1535b311c5d0c9282f21fb95bf6bde56467d909aad7040 AmScopes.class
6
+ 8e4ae16e1e3cec5e9a5b0cc8a38ee6b984a63515466df658c39149a147c9a7c6 HostOps.class
7
+ cd137064284ce0fc178ab49787fa98acaf3ebb56197d66bbe03db19760ae174a JsValues.class
8
+ bf3e72ca050d36e94eebb0cedaa0b76e9f7441b990f90de1df01e16a6c0a4da9 Json$Parser.class
9
+ 64e78f7b28bbdea862c2e69b63768a66c6b85bd4ac48810483aa1264399a0ee8 Json.class
10
+ bb691e612fb76272f33c30da85b37f232dc8cd25e2e74b31bf7f8d2412a020f9 LanguageVersions.class
11
+ e36527b3528630aac978fcd8d88ce457d4f384462a8e45c1560680e33c3ac5a3 Runner.class
12
+ 0dec344634df70ced0ab093567d22c597968701c5aa102d9ee1a3345684695d4 ScriptContextScope.class
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file