@watchtowerobservability/node 0.0.0-stage → 0.3.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 (181) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +304 -2
  3. package/dist/cjs/appsec.d.ts +95 -0
  4. package/dist/cjs/appsec.js +206 -0
  5. package/dist/cjs/buffer.d.ts +49 -0
  6. package/dist/cjs/buffer.js +134 -0
  7. package/dist/cjs/errors.d.ts +17 -0
  8. package/dist/cjs/errors.js +55 -0
  9. package/dist/cjs/index.d.ts +123 -0
  10. package/dist/cjs/index.js +315 -0
  11. package/dist/cjs/integrations/amqp.d.ts +13 -0
  12. package/dist/cjs/integrations/amqp.js +96 -0
  13. package/dist/cjs/integrations/azure-functions.d.ts +18 -0
  14. package/dist/cjs/integrations/azure-functions.js +97 -0
  15. package/dist/cjs/integrations/bullmq.d.ts +19 -0
  16. package/dist/cjs/integrations/bullmq.js +83 -0
  17. package/dist/cjs/integrations/cache.d.ts +13 -0
  18. package/dist/cjs/integrations/cache.js +51 -0
  19. package/dist/cjs/integrations/db.d.ts +62 -0
  20. package/dist/cjs/integrations/db.js +288 -0
  21. package/dist/cjs/integrations/duckdb.d.ts +22 -0
  22. package/dist/cjs/integrations/duckdb.js +66 -0
  23. package/dist/cjs/integrations/express.d.ts +25 -0
  24. package/dist/cjs/integrations/express.js +58 -0
  25. package/dist/cjs/integrations/fastify.d.ts +6 -0
  26. package/dist/cjs/integrations/fastify.js +44 -0
  27. package/dist/cjs/integrations/genai-agents.d.ts +36 -0
  28. package/dist/cjs/integrations/genai-agents.js +124 -0
  29. package/dist/cjs/integrations/genai-stream.d.ts +19 -0
  30. package/dist/cjs/integrations/genai-stream.js +135 -0
  31. package/dist/cjs/integrations/genai.d.ts +18 -0
  32. package/dist/cjs/integrations/genai.js +150 -0
  33. package/dist/cjs/integrations/graphile-worker.d.ts +22 -0
  34. package/dist/cjs/integrations/graphile-worker.js +50 -0
  35. package/dist/cjs/integrations/koa.d.ts +19 -0
  36. package/dist/cjs/integrations/koa.js +34 -0
  37. package/dist/cjs/integrations/lambda.d.ts +11 -0
  38. package/dist/cjs/integrations/lambda.js +68 -0
  39. package/dist/cjs/integrations/level.d.ts +18 -0
  40. package/dist/cjs/integrations/level.js +71 -0
  41. package/dist/cjs/integrations/lmdb.d.ts +26 -0
  42. package/dist/cjs/integrations/lmdb.js +78 -0
  43. package/dist/cjs/integrations/logs.d.ts +10 -0
  44. package/dist/cjs/integrations/logs.js +77 -0
  45. package/dist/cjs/integrations/messaging.d.ts +17 -0
  46. package/dist/cjs/integrations/messaging.js +73 -0
  47. package/dist/cjs/integrations/mqtt.d.ts +7 -0
  48. package/dist/cjs/integrations/mqtt.js +41 -0
  49. package/dist/cjs/integrations/nats.d.ts +17 -0
  50. package/dist/cjs/integrations/nats.js +73 -0
  51. package/dist/cjs/integrations/nestjs.d.ts +16 -0
  52. package/dist/cjs/integrations/nestjs.js +30 -0
  53. package/dist/cjs/integrations/next.d.ts +11 -0
  54. package/dist/cjs/integrations/next.js +59 -0
  55. package/dist/cjs/integrations/orm.d.ts +47 -0
  56. package/dist/cjs/integrations/orm.js +93 -0
  57. package/dist/cjs/integrations/pg-boss.d.ts +8 -0
  58. package/dist/cjs/integrations/pg-boss.js +63 -0
  59. package/dist/cjs/integrations/pools.d.ts +41 -0
  60. package/dist/cjs/integrations/pools.js +94 -0
  61. package/dist/cjs/integrations/postgres.d.ts +12 -0
  62. package/dist/cjs/integrations/postgres.js +92 -0
  63. package/dist/cjs/integrations/prisma.d.ts +3 -0
  64. package/dist/cjs/integrations/prisma.js +33 -0
  65. package/dist/cjs/integrations/sqlite.d.ts +36 -0
  66. package/dist/cjs/integrations/sqlite.js +125 -0
  67. package/dist/cjs/integrations/util.d.ts +9 -0
  68. package/dist/cjs/integrations/util.js +37 -0
  69. package/dist/cjs/jest.d.ts +21 -0
  70. package/dist/cjs/jest.js +45 -0
  71. package/dist/cjs/load.d.ts +1 -0
  72. package/dist/cjs/load.js +11 -0
  73. package/dist/cjs/metrics.d.ts +10 -0
  74. package/dist/cjs/metrics.js +81 -0
  75. package/dist/cjs/package.json +1 -0
  76. package/dist/cjs/payload.d.ts +42 -0
  77. package/dist/cjs/payload.js +145 -0
  78. package/dist/cjs/pprof.d.ts +6 -0
  79. package/dist/cjs/pprof.js +88 -0
  80. package/dist/cjs/probes.d.ts +97 -0
  81. package/dist/cjs/probes.js +422 -0
  82. package/dist/cjs/profiling.d.ts +84 -0
  83. package/dist/cjs/profiling.js +263 -0
  84. package/dist/cjs/reporter-core.d.ts +32 -0
  85. package/dist/cjs/reporter-core.js +102 -0
  86. package/dist/cjs/sql.d.ts +19 -0
  87. package/dist/cjs/sql.js +332 -0
  88. package/dist/cjs/test-plan.d.ts +102 -0
  89. package/dist/cjs/test-plan.js +352 -0
  90. package/dist/cjs/vitest.d.ts +27 -0
  91. package/dist/cjs/vitest.js +52 -0
  92. package/dist/esm/appsec.d.ts +95 -0
  93. package/dist/esm/appsec.js +193 -0
  94. package/dist/esm/buffer.d.ts +49 -0
  95. package/dist/esm/buffer.js +92 -0
  96. package/dist/esm/errors.d.ts +17 -0
  97. package/dist/esm/errors.js +50 -0
  98. package/dist/esm/index.d.ts +123 -0
  99. package/dist/esm/index.js +264 -0
  100. package/dist/esm/integrations/amqp.d.ts +13 -0
  101. package/dist/esm/integrations/amqp.js +92 -0
  102. package/dist/esm/integrations/azure-functions.d.ts +18 -0
  103. package/dist/esm/integrations/azure-functions.js +60 -0
  104. package/dist/esm/integrations/bullmq.d.ts +19 -0
  105. package/dist/esm/integrations/bullmq.js +79 -0
  106. package/dist/esm/integrations/cache.d.ts +13 -0
  107. package/dist/esm/integrations/cache.js +46 -0
  108. package/dist/esm/integrations/db.d.ts +62 -0
  109. package/dist/esm/integrations/db.js +239 -0
  110. package/dist/esm/integrations/duckdb.d.ts +22 -0
  111. package/dist/esm/integrations/duckdb.js +29 -0
  112. package/dist/esm/integrations/express.d.ts +25 -0
  113. package/dist/esm/integrations/express.js +54 -0
  114. package/dist/esm/integrations/fastify.d.ts +6 -0
  115. package/dist/esm/integrations/fastify.js +41 -0
  116. package/dist/esm/integrations/genai-agents.d.ts +36 -0
  117. package/dist/esm/integrations/genai-agents.js +118 -0
  118. package/dist/esm/integrations/genai-stream.d.ts +19 -0
  119. package/dist/esm/integrations/genai-stream.js +130 -0
  120. package/dist/esm/integrations/genai.d.ts +18 -0
  121. package/dist/esm/integrations/genai.js +138 -0
  122. package/dist/esm/integrations/graphile-worker.d.ts +22 -0
  123. package/dist/esm/integrations/graphile-worker.js +46 -0
  124. package/dist/esm/integrations/koa.d.ts +19 -0
  125. package/dist/esm/integrations/koa.js +31 -0
  126. package/dist/esm/integrations/lambda.d.ts +11 -0
  127. package/dist/esm/integrations/lambda.js +32 -0
  128. package/dist/esm/integrations/level.d.ts +18 -0
  129. package/dist/esm/integrations/level.js +35 -0
  130. package/dist/esm/integrations/lmdb.d.ts +26 -0
  131. package/dist/esm/integrations/lmdb.js +42 -0
  132. package/dist/esm/integrations/logs.d.ts +10 -0
  133. package/dist/esm/integrations/logs.js +40 -0
  134. package/dist/esm/integrations/messaging.d.ts +17 -0
  135. package/dist/esm/integrations/messaging.js +64 -0
  136. package/dist/esm/integrations/mqtt.d.ts +7 -0
  137. package/dist/esm/integrations/mqtt.js +38 -0
  138. package/dist/esm/integrations/nats.d.ts +17 -0
  139. package/dist/esm/integrations/nats.js +70 -0
  140. package/dist/esm/integrations/nestjs.d.ts +16 -0
  141. package/dist/esm/integrations/nestjs.js +26 -0
  142. package/dist/esm/integrations/next.d.ts +11 -0
  143. package/dist/esm/integrations/next.js +22 -0
  144. package/dist/esm/integrations/orm.d.ts +47 -0
  145. package/dist/esm/integrations/orm.js +86 -0
  146. package/dist/esm/integrations/pg-boss.d.ts +8 -0
  147. package/dist/esm/integrations/pg-boss.js +60 -0
  148. package/dist/esm/integrations/pools.d.ts +41 -0
  149. package/dist/esm/integrations/pools.js +89 -0
  150. package/dist/esm/integrations/postgres.d.ts +12 -0
  151. package/dist/esm/integrations/postgres.js +55 -0
  152. package/dist/esm/integrations/prisma.d.ts +3 -0
  153. package/dist/esm/integrations/prisma.js +30 -0
  154. package/dist/esm/integrations/sqlite.d.ts +36 -0
  155. package/dist/esm/integrations/sqlite.js +84 -0
  156. package/dist/esm/integrations/util.d.ts +9 -0
  157. package/dist/esm/integrations/util.js +32 -0
  158. package/dist/esm/jest.d.ts +21 -0
  159. package/dist/esm/jest.js +41 -0
  160. package/dist/esm/load.d.ts +1 -0
  161. package/dist/esm/load.js +5 -0
  162. package/dist/esm/metrics.d.ts +10 -0
  163. package/dist/esm/metrics.js +44 -0
  164. package/dist/esm/package.json +1 -0
  165. package/dist/esm/payload.d.ts +42 -0
  166. package/dist/esm/payload.js +131 -0
  167. package/dist/esm/pprof.d.ts +6 -0
  168. package/dist/esm/pprof.js +85 -0
  169. package/dist/esm/probes.d.ts +97 -0
  170. package/dist/esm/probes.js +412 -0
  171. package/dist/esm/profiling.d.ts +84 -0
  172. package/dist/esm/profiling.js +251 -0
  173. package/dist/esm/reporter-core.d.ts +32 -0
  174. package/dist/esm/reporter-core.js +63 -0
  175. package/dist/esm/sql.d.ts +19 -0
  176. package/dist/esm/sql.js +324 -0
  177. package/dist/esm/test-plan.d.ts +102 -0
  178. package/dist/esm/test-plan.js +336 -0
  179. package/dist/esm/vitest.d.ts +27 -0
  180. package/dist/esm/vitest.js +48 -0
  181. package/package.json +379 -4
@@ -0,0 +1,332 @@
1
+ "use strict";
2
+ // Shared SQL normaliser and statement hash. A byte-for-byte port of the worker's
3
+ // services/worker/src/sqlnorm.rs (`normalize_with`, xxh3_64), so `db.query.hash` from the SDK equals
4
+ // the `wt.db.query_hash` the server stamps. Algorithm: docs/product/instrumentation/sql-normalization.md;
5
+ // vectors: testdata/sql_normalize_vectors.json. Change both sides together.
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.isPgDialect = exports.MAX_STATEMENT_BYTES = void 0;
8
+ exports.normalizeSql = normalizeSql;
9
+ exports.normalizeAndHash = normalizeAndHash;
10
+ exports.querySummary = querySummary;
11
+ exports.xxh3 = xxh3;
12
+ /** Longest statement looked at, in UTF-8 bytes; the rest is dropped. */
13
+ exports.MAX_STATEMENT_BYTES = 8 * 1024;
14
+ const MAX_DOLLAR_TAG = 32;
15
+ const ALNUM = /^[\p{Alphabetic}\p{N}]$/u; // Rust char::is_alphanumeric
16
+ const SPACE = /^\p{White_Space}$/u; // Rust char::is_whitespace
17
+ const isAlnum = (c) => ALNUM.test(c);
18
+ const isWord = (c) => c === '_' || c === '$' || ALNUM.test(c);
19
+ const isDigit = (c) => c !== undefined && c >= '0' && c <= '9';
20
+ /** Code points of the first 8 KiB of UTF-8, cut back to a whole character. */
21
+ function cap(s) {
22
+ const out = [];
23
+ let bytes = 0;
24
+ for (const c of s) {
25
+ const cp = c.codePointAt(0);
26
+ bytes += cp < 0x80 ? 1 : cp < 0x800 ? 2 : cp < 0x10000 ? 3 : 4;
27
+ if (bytes > exports.MAX_STATEMENT_BYTES)
28
+ break;
29
+ out.push(c);
30
+ }
31
+ return out;
32
+ }
33
+ const startsWith = (cs, at, tag) => tag.every((t, k) => cs[at + k] === t);
34
+ function dollarQuoted(cs, i) {
35
+ let tagLen = -1;
36
+ for (let k = 0; k < MAX_DOLLAR_TAG + 1 && i + 1 + k < cs.length; k++) {
37
+ if (cs[i + 1 + k] === '$') {
38
+ tagLen = k;
39
+ break;
40
+ }
41
+ }
42
+ if (tagLen < 0)
43
+ return undefined;
44
+ const tag = cs.slice(i, i + tagLen + 2);
45
+ if (!tag.slice(1, tagLen + 1).every((c) => isAlnum(c) || c === '_') || isDigit(tag[1]))
46
+ return undefined;
47
+ for (let j = i + tag.length; j < cs.length; j++)
48
+ if (startsWith(cs, j, tag))
49
+ return j + tag.length;
50
+ return cs.length;
51
+ }
52
+ function token(cs, i, pg, out) {
53
+ const c = cs[i];
54
+ if (c === "'") {
55
+ i++;
56
+ while (i < cs.length) {
57
+ if (cs[i] === "'") {
58
+ if (cs[i + 1] !== "'")
59
+ break;
60
+ i++;
61
+ }
62
+ i++;
63
+ }
64
+ out.push('?');
65
+ // a quote right after a backslash is ambiguous (MySQL escapes): mask to the end
66
+ return i < cs.length && cs[i - 1] === '\\' ? cs.length : i + 1;
67
+ }
68
+ if (c === '"' || c === '`') {
69
+ let close = cs.indexOf(c, i + 1);
70
+ if (close < 0)
71
+ close = cs.length;
72
+ const body = cs.slice(i + 1, close);
73
+ const ident = c === '"' && pg && close < cs.length && body.length >= 1 && body.length <= 64
74
+ && body.every((b) => isAlnum(b) || b === '_' || b === '$');
75
+ if (ident)
76
+ out.push(...cs.slice(i, close + 1));
77
+ else
78
+ out.push('?');
79
+ return close + 1;
80
+ }
81
+ if (c === '$') {
82
+ if (isDigit(cs[i + 1])) {
83
+ i++;
84
+ while (isDigit(cs[i]))
85
+ i++;
86
+ out.push('?');
87
+ return i;
88
+ }
89
+ const end = dollarQuoted(cs, i);
90
+ if (end !== undefined) {
91
+ out.push('?');
92
+ return end;
93
+ }
94
+ }
95
+ if (isDigit(c)) {
96
+ while (i < cs.length && (isWord(cs[i]) || cs[i] === '.'))
97
+ i++;
98
+ out.push('?');
99
+ }
100
+ else if (isWord(c)) {
101
+ while (i < cs.length && isWord(cs[i]))
102
+ out.push(cs[i++]);
103
+ }
104
+ else {
105
+ out.push(c);
106
+ i++;
107
+ }
108
+ return i;
109
+ }
110
+ const enc = new TextEncoder();
111
+ const dec = new TextDecoder();
112
+ const SP = 0x20;
113
+ /** After `in`: optional spaces, `(`, `?` items split by commas, `)`. Returns [open, end]. */
114
+ function inList(b, i) {
115
+ const skip = () => { while (b[i] === SP)
116
+ i++; };
117
+ skip();
118
+ const open = i;
119
+ if (b[i] !== 0x28)
120
+ return undefined;
121
+ i++;
122
+ for (;;) {
123
+ skip();
124
+ if (b[i] !== 0x3f)
125
+ return undefined;
126
+ i++;
127
+ skip();
128
+ if (b[i] === 0x2c)
129
+ i++;
130
+ else if (b[i] === 0x29)
131
+ return [open, i + 1];
132
+ else
133
+ return undefined;
134
+ }
135
+ }
136
+ /** `in (?, ?, ?)` -> `in (?+)`. On UTF-8 bytes like the Rust: the word check reads the previous byte as Latin-1. */
137
+ function collapseIn(s) {
138
+ const out = [];
139
+ let i = 0;
140
+ while (i < s.length) {
141
+ const atWord = i === 0 || !isWord(String.fromCharCode(s[i - 1]));
142
+ const span = atWord && i + 2 <= s.length && (s[i] | 0x20) === 0x69 && (s[i + 1] | 0x20) === 0x6e
143
+ ? inList(s, i + 2) : undefined;
144
+ if (span) {
145
+ for (let k = i; k < span[0]; k++)
146
+ out.push(s[k]);
147
+ out.push(0x28, 0x3f, 0x2b, 0x29);
148
+ i = span[1];
149
+ }
150
+ else {
151
+ out.push(s[i++]);
152
+ }
153
+ }
154
+ return Uint8Array.from(out);
155
+ }
156
+ function normalizeBytes(stmt, pg) {
157
+ const cs = cap(stmt);
158
+ const out = [];
159
+ let space = false;
160
+ let i = 0;
161
+ while (i < cs.length) {
162
+ const c = cs[i];
163
+ const next = cs[i + 1];
164
+ if (SPACE.test(c)) {
165
+ space = true;
166
+ i++;
167
+ }
168
+ else if (c === '/' && next === '*') {
169
+ let depth = 1;
170
+ i += 2;
171
+ while (i < cs.length && depth > 0) {
172
+ if (cs[i] === '/' && cs[i + 1] === '*') {
173
+ depth++;
174
+ i += 2;
175
+ }
176
+ else if (cs[i] === '*' && cs[i + 1] === '/') {
177
+ depth--;
178
+ i += 2;
179
+ }
180
+ else
181
+ i++;
182
+ }
183
+ space = true;
184
+ }
185
+ else if ((c === '-' && next === '-') || (c === '#' && !pg)) {
186
+ while (i < cs.length && cs[i] !== '\n')
187
+ i++;
188
+ space = true;
189
+ }
190
+ else {
191
+ if (space && out.length)
192
+ out.push(' ');
193
+ space = false;
194
+ i = token(cs, i, pg, out);
195
+ }
196
+ }
197
+ return collapseIn(enc.encode(out.join('')));
198
+ }
199
+ /**
200
+ * Literal-free statement text: strings, numbers and `$1` become `?`, comments go, whitespace
201
+ * collapses, `IN (?, ?)` becomes `IN (?+)`. `pg` keeps short `"identifiers"` and the `#` operator.
202
+ */
203
+ function normalizeSql(stmt, pg = false) {
204
+ return dec.decode(normalizeBytes(stmt, pg));
205
+ }
206
+ /** `[normalized text, decimal xxh3_64 of its UTF-8 bytes]`: the `db.query.hash` spans carry. */
207
+ function normalizeAndHash(stmt, pg = false) {
208
+ const b = normalizeBytes(stmt, pg);
209
+ return [dec.decode(b), xxh3(b).toString()];
210
+ }
211
+ /** Systems whose dialect keeps `"identifier"` quotes and the `#` operator (as the worker decides). */
212
+ const isPgDialect = (system) => system === 'postgresql' || system === 'cockroachdb' || system === 'redshift';
213
+ exports.isPgDialect = isPgDialect;
214
+ const OP = /^\s*(?:with\b[\s\S]*?\)\s*)?([a-z]+)/i;
215
+ const TARGET = /\b(?:from|into|update|join|table)\s+((?:"[^"]+"|[\w$]+)(?:\.(?:"[^"]+"|[\w$]+))?)/i;
216
+ /** `SELECT users`-style summary: the operation and first table, never values or the statement text. */
217
+ function querySummary(text, fallback = 'postgres') {
218
+ const operation = text?.match(OP)?.[1]?.toUpperCase();
219
+ const target = text?.match(TARGET)?.[1]?.replace(/"/g, '');
220
+ return { operation, target, summary: [operation ?? fallback, target].filter(Boolean).join(' ') };
221
+ }
222
+ // ---- XXH3-64, seed 0, default secret (port of the xxHash reference; BigInt is fine at <= 8 KiB) ----
223
+ const M64 = (1n << 64n) - 1n;
224
+ const P32_1 = 0x9e3779b1n, P32_2 = 0x85ebca77n, P32_3 = 0xc2b2ae3dn;
225
+ const P64_1 = 0x9e3779b185ebca87n, P64_2 = 0xc2b2ae3d27d4eb4fn, P64_3 = 0x165667b19e3779f9n;
226
+ const P64_4 = 0x85ebca77c2b2ae63n, P64_5 = 0x27d4eb2f165667c5n;
227
+ const SECRET = Uint8Array.from(Buffer.from('b8fe6c3923a44bbe7c01812cf721ad1cded46de9839097db7240a4a4b7b3671fcb79e64eccc0e578825ad07dccff7221'
228
+ + 'b8084674f743248ee03590e6813a264c3c2852bb91c300cb88d0658b1b532ea371644897a20df94e3819ef46a9deacd8'
229
+ + 'a8fa763fe39c343ff9dcbbc7c70b4f1d8a51e04bcdb45931c89f7ec9d9787364eac5ac8334d3ebc3c581a0fffa1363eb'
230
+ + '170ddd51b7f0da49d316552629d4689e2b16be587d47a1fc8ff8b8d17ad031ce45cb3a8f95160428afd7fbcabb4b407e', 'hex'));
231
+ const r64 = (b, o) => new DataView(b.buffer, b.byteOffset + o, 8).getBigUint64(0, true);
232
+ const r32 = (b, o) => BigInt(new DataView(b.buffer, b.byteOffset + o, 4).getUint32(0, true));
233
+ const mul = (a, b) => (a * b) & M64;
234
+ const add = (a, b) => (a + b) & M64;
235
+ const rotl = (x, r) => ((x << r) | (x >> (64n - r))) & M64;
236
+ const swap64 = (x) => {
237
+ let r = 0n;
238
+ for (let k = 0; k < 8; k++) {
239
+ r = (r << 8n) | (x & 0xffn);
240
+ x >>= 8n;
241
+ }
242
+ return r;
243
+ };
244
+ const fold = (a, b) => { const p = a * b; return (p ^ (p >> 64n)) & M64; };
245
+ const avalanche = (h) => { h ^= h >> 37n; h = mul(h, 0x165667919e3779f9n); return h ^ (h >> 32n); };
246
+ const avalanche64 = (h) => {
247
+ h ^= h >> 33n;
248
+ h = mul(h, P64_2);
249
+ h ^= h >> 29n;
250
+ h = mul(h, P64_3);
251
+ return h ^ (h >> 32n);
252
+ };
253
+ const mix16 = (p, o, s) => fold(r64(p, o) ^ r64(SECRET, s), r64(p, o + 8) ^ r64(SECRET, s + 8));
254
+ function accumulate512(acc, p, o, s) {
255
+ for (let i = 0; i < 8; i++) {
256
+ const v = r64(p, o + 8 * i);
257
+ const k = v ^ r64(SECRET, s + 8 * i);
258
+ acc[i ^ 1] = add(acc[i ^ 1], v);
259
+ acc[i] = add(acc[i], (k & 0xffffffffn) * (k >> 32n));
260
+ }
261
+ }
262
+ function long(p) {
263
+ const len = p.length;
264
+ const acc = [P32_3, P64_1, P64_2, P64_3, P64_4, P32_2, P64_5, P32_1];
265
+ const stripesPerBlock = (SECRET.length - 64) / 8;
266
+ const block = 64 * stripesPerBlock;
267
+ const blocks = Math.floor((len - 1) / block);
268
+ for (let n = 0; n < blocks; n++) {
269
+ for (let s = 0; s < stripesPerBlock; s++)
270
+ accumulate512(acc, p, n * block + s * 64, s * 8);
271
+ for (let i = 0; i < 8; i++) {
272
+ let a = acc[i];
273
+ a ^= a >> 47n;
274
+ a ^= r64(SECRET, SECRET.length - 64 + 8 * i);
275
+ acc[i] = mul(a, P32_1);
276
+ }
277
+ }
278
+ const stripes = Math.floor((len - 1 - block * blocks) / 64);
279
+ for (let s = 0; s < stripes; s++)
280
+ accumulate512(acc, p, blocks * block + s * 64, s * 8);
281
+ accumulate512(acc, p, len - 64, SECRET.length - 64 - 7);
282
+ let r = mul(BigInt(len), P64_1);
283
+ for (let i = 0; i < 4; i++)
284
+ r = add(r, fold(acc[2 * i] ^ r64(SECRET, 11 + 16 * i), acc[2 * i + 1] ^ r64(SECRET, 19 + 16 * i)));
285
+ return avalanche(r);
286
+ }
287
+ /** XXH3_64bits(input), seed 0. */
288
+ function xxh3(p) {
289
+ const len = p.length;
290
+ const L = BigInt(len);
291
+ if (len === 0)
292
+ return avalanche64(r64(SECRET, 56) ^ r64(SECRET, 64));
293
+ if (len <= 3) {
294
+ const combined = (BigInt(p[0]) << 16n) | (BigInt(p[len >> 1]) << 24n) | BigInt(p[len - 1]) | (L << 8n);
295
+ return avalanche64(combined ^ (r32(SECRET, 0) ^ r32(SECRET, 4)));
296
+ }
297
+ if (len <= 8) {
298
+ const keyed = (r32(p, len - 4) + (r32(p, 0) << 32n)) ^ (r64(SECRET, 8) ^ r64(SECRET, 16));
299
+ let h = keyed ^ rotl(keyed, 49n) ^ rotl(keyed, 24n);
300
+ h = mul(h, 0x9fb21c651e98df25n);
301
+ h ^= add(h >> 35n, L);
302
+ h = mul(h, 0x9fb21c651e98df25n);
303
+ return h ^ (h >> 28n);
304
+ }
305
+ if (len <= 16) {
306
+ const lo = r64(p, 0) ^ (r64(SECRET, 24) ^ r64(SECRET, 32));
307
+ const hi = r64(p, len - 8) ^ (r64(SECRET, 40) ^ r64(SECRET, 48));
308
+ return avalanche(add(add(add(L, swap64(lo)), hi), fold(lo, hi)));
309
+ }
310
+ if (len <= 128) {
311
+ let acc = mul(L, P64_1);
312
+ if (len > 32) {
313
+ if (len > 64) {
314
+ if (len > 96)
315
+ acc = add(add(acc, mix16(p, 48, 96)), mix16(p, len - 64, 112));
316
+ acc = add(add(acc, mix16(p, 32, 64)), mix16(p, len - 48, 80));
317
+ }
318
+ acc = add(add(acc, mix16(p, 16, 32)), mix16(p, len - 32, 48));
319
+ }
320
+ return avalanche(add(add(acc, mix16(p, 0, 0)), mix16(p, len - 16, 16)));
321
+ }
322
+ if (len <= 240) {
323
+ let acc = mul(L, P64_1);
324
+ for (let i = 0; i < 8; i++)
325
+ acc = add(acc, mix16(p, 16 * i, 16 * i));
326
+ acc = avalanche(acc);
327
+ for (let i = 8; i < Math.floor(len / 16); i++)
328
+ acc = add(acc, mix16(p, 16 * i, 16 * (i - 8) + 3));
329
+ return avalanche(add(acc, mix16(p, len - 16, 136 - 17)));
330
+ }
331
+ return long(p);
332
+ }
@@ -0,0 +1,102 @@
1
+ import type { TestRecord } from './reporter-core.js';
2
+ import type { Client } from './index.js';
3
+ export interface TestPlan {
4
+ quarantined: {
5
+ id: string;
6
+ ticket_url?: string | null;
7
+ owner?: string | null;
8
+ }[];
9
+ disabled: string[];
10
+ skippable: string[];
11
+ new_tests: string[];
12
+ efd_retries: number;
13
+ }
14
+ /** What the plan says about one test. */
15
+ export interface TestDecision {
16
+ skip?: 'disabled' | 'unaffected';
17
+ /** ticket URL (or "no ticket") of a quarantined test */
18
+ quarantined?: string;
19
+ isNew?: boolean;
20
+ retries: number;
21
+ }
22
+ export declare const suiteName: (framework: string) => string;
23
+ export declare function testId(suite: string, file: string | undefined, names: string[]): string;
24
+ export declare function changedFiles(): string[];
25
+ /** The session plan; `null` without a project or when the API is unreachable (then everything runs). */
26
+ export declare function fetchTestPlan(client: Client | null, tests?: string[]): Promise<TestPlan | null>;
27
+ /** The plan the global setup wrote (workers and reporters), cached per process. */
28
+ export declare function loadPlan(): TestPlan | null;
29
+ /** Vitest/Jest global setup: fetch the plan once and publish it to the workers (which inherit the env). */
30
+ export default function globalSetup(): Promise<void>;
31
+ /** Decides per test id; with no plan nothing is skipped or retried. */
32
+ export declare function decider(plan: TestPlan | null): (id: string) => TestDecision;
33
+ /** The slice of a Vitest task the setup reads and changes. */
34
+ export interface PlanTask {
35
+ type?: string;
36
+ name: string;
37
+ mode?: string;
38
+ retry?: number;
39
+ filepath?: string;
40
+ tasks?: PlanTask[];
41
+ meta?: Record<string, unknown>;
42
+ result?: {
43
+ state?: string;
44
+ errors?: {
45
+ message?: string;
46
+ }[];
47
+ };
48
+ }
49
+ /** Vitest's `beforeAll`/`afterEach`/`afterAll`, passed in so this package does not import Vitest. */
50
+ export interface VitestHooks {
51
+ beforeAll(fn: (suite: PlanTask) => unknown): void;
52
+ afterEach(fn: (ctx: {
53
+ task: PlanTask;
54
+ skip(note?: string): void;
55
+ }) => unknown): void;
56
+ /** needed for WT_TIA_RECORD=1 */
57
+ afterAll?(fn: (suite: PlanTask) => unknown): void;
58
+ }
59
+ /** Applies the plan in a Vitest setup file. Decisions go to `task.meta.wt` for the reporter. */
60
+ export declare function vitestSetup(hooks: VitestHooks): void;
61
+ interface CircusBlock {
62
+ name: string;
63
+ parent?: CircusBlock;
64
+ children?: ({
65
+ type?: string;
66
+ name: string;
67
+ } & Partial<CircusTest>)[];
68
+ }
69
+ interface CircusTest {
70
+ name: string;
71
+ mode?: string;
72
+ status?: string;
73
+ errors: unknown[];
74
+ parent?: CircusBlock;
75
+ }
76
+ export interface CircusEvent {
77
+ name: string;
78
+ test?: CircusTest;
79
+ describeBlock?: CircusBlock;
80
+ }
81
+ type JestEnvBase = new (...args: any[]) => {
82
+ global: Record<string | symbol, unknown>;
83
+ handleTestEvent?(event: CircusEvent, state: unknown): unknown;
84
+ };
85
+ /**
86
+ * Wraps a Jest test environment class so it applies the plan: skips disabled/unaffected tests on
87
+ * `test_start`, raises `jest.retryTimes` for describe blocks holding a new test, and turns a
88
+ * quarantined test's failure into a skip that keeps its failure message (the reporter reads it).
89
+ */
90
+ export declare function jestEnvironment<B extends JestEnvBase>(Base: B): B;
91
+ /** One <testsuite>; a test retried k times gets k failed attempts ahead of its final result. */
92
+ export declare function toJunit(suite: string, tests: TestRecord[]): string;
93
+ /** Posts the results as JUnit when WT_CI_RUN_ID is set; never throws. */
94
+ export declare function uploadResults(client: Client | null, suite: string, tests: TestRecord[]): Promise<boolean>;
95
+ /** Repository-relative files with an executed statement in an istanbul coverage object. */
96
+ export declare function coveredFiles(cov: unknown, root?: string): string[];
97
+ /**
98
+ * Uploads the coverage of one test file for its tests (`suite::rest` ids); never throws.
99
+ * Needs WT_API_URL, WT_PROJECT_ID and WT_API_KEY (the coverage map needs a project API key).
100
+ */
101
+ export declare function uploadCoverage(file: string | undefined, ids: string[], cov: unknown, fetchImpl?: typeof globalThis.fetch): Promise<boolean>;
102
+ export {};