kage-baileys 25.3.40 → 25.3.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/WAProto/WAProto.proto +0 -15
- package/package.json +8 -3
- package/scripts/verify-package.mjs +13 -1
- package/scripts/verify-proto.mjs +344 -0
- package/test/proto-runtime.test.js +35 -0
- package/test/proto-schema.test.js +28 -0
package/WAProto/WAProto.proto
CHANGED
|
@@ -7150,7 +7150,6 @@ message WebMessageInfo {
|
|
|
7150
7150
|
optional GroupHistoryBundleInfo groupHistoryBundleInfo = 75;
|
|
7151
7151
|
optional InteractiveMessageAdditionalMetadata interactiveMessageAdditionalMetadata = 76;
|
|
7152
7152
|
optional QuarantinedMessage quarantinedMessage = 77;
|
|
7153
|
-
// Additional WebMessageInfo metadata merged from the Elaina/Dnuzi schema lineage.
|
|
7154
7153
|
optional uint32 nonJidMentions = 78;
|
|
7155
7154
|
optional string hsmTag = 79;
|
|
7156
7155
|
optional uint64 ephemeralExpirationTimestamp = 80;
|
|
@@ -7490,20 +7489,6 @@ POLL_ADDED_OPTION_REMOVED = 291;
|
|
|
7490
7489
|
}
|
|
7491
7490
|
|
|
7492
7491
|
|
|
7493
|
-
optional uint32 nonJidMentions = 78;
|
|
7494
|
-
|
|
7495
|
-
optional string hsmTag = 79;
|
|
7496
|
-
|
|
7497
|
-
optional uint64 ephemeralExpirationTimestamp = 80;
|
|
7498
|
-
|
|
7499
|
-
optional ScheduledMessageMetadata scheduledMessageMetadata = 81;
|
|
7500
|
-
|
|
7501
|
-
string decisionId = 82;
|
|
7502
|
-
|
|
7503
|
-
repeated string decisionSources = 83;
|
|
7504
|
-
|
|
7505
|
-
.proto.EventInviteAdditionalMetadata eventInviteAdditionalMetadata = 84;
|
|
7506
|
-
|
|
7507
7492
|
}
|
|
7508
7493
|
|
|
7509
7494
|
message WebNotificationsInfo {
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kage-baileys",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "25.3.
|
|
5
|
-
"description": "Kage Baileys with RedX RC15
|
|
4
|
+
"version": "25.3.41",
|
|
5
|
+
"description": "Kage Baileys with RedX RC15 fixes, extended WAProto schema validation, Native Flow, media recovery and protocol extensions",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"whatsapp",
|
|
8
8
|
"automation"
|
|
@@ -23,7 +23,12 @@
|
|
|
23
23
|
"helpers/**/*",
|
|
24
24
|
"licenses/**/*",
|
|
25
25
|
"scripts/**/*",
|
|
26
|
-
"test/**/*"
|
|
26
|
+
"test/**/*",
|
|
27
|
+
"README.md",
|
|
28
|
+
"REDX-RC15-INTEGRATION.md",
|
|
29
|
+
"TEST-REPORT.md",
|
|
30
|
+
"VIEWONCE-FIX-REPORT.md",
|
|
31
|
+
"PROTO-SCHEMA-FIX-REPORT.md"
|
|
27
32
|
],
|
|
28
33
|
"scripts": {
|
|
29
34
|
"build:all": "npm run check",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { spawnSync } from 'node:child_process';
|
|
2
2
|
import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
+
import { validateProtoSchema } from './verify-proto.mjs';
|
|
4
5
|
import { fileURLToPath } from 'node:url';
|
|
5
6
|
|
|
6
7
|
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
@@ -134,6 +135,17 @@ for (const file of checked) {
|
|
|
134
135
|
}
|
|
135
136
|
}
|
|
136
137
|
|
|
138
|
+
const protoPath = path.join(root, 'WAProto', 'WAProto.proto');
|
|
139
|
+
if (existsSync(protoPath)) {
|
|
140
|
+
const protoResult = validateProtoSchema(readFileSync(protoPath, 'utf8'));
|
|
141
|
+
for (const error of protoResult.errors) failures.push(`WAProto/WAProto.proto: ${error}`);
|
|
142
|
+
if (!protoResult.errors.length) {
|
|
143
|
+
console.log(`WAProto validation passed: ${protoResult.messageCount} messages, ${protoResult.enumCount} enums, ${protoResult.fieldCount} fields.`);
|
|
144
|
+
}
|
|
145
|
+
} else {
|
|
146
|
+
failures.push('WAProto/WAProto.proto is missing');
|
|
147
|
+
}
|
|
148
|
+
|
|
137
149
|
const packageJson = JSON.parse(readFileSync(path.join(root, 'package.json'), 'utf8'));
|
|
138
150
|
for (const field of ['main', 'types']) {
|
|
139
151
|
if (packageJson[field] && !existsSync(path.join(root, packageJson[field]))) {
|
|
@@ -146,5 +158,5 @@ if (failures.length) {
|
|
|
146
158
|
for (const failure of failures) console.error(`- ${failure}`);
|
|
147
159
|
process.exitCode = 1;
|
|
148
160
|
} else {
|
|
149
|
-
console.log(`Package check passed: ${checked.length} JavaScript files; syntax, local paths,
|
|
161
|
+
console.log(`Package check passed: ${checked.length} JavaScript files; syntax, local paths, static import/export names, and WAProto schema are valid.`);
|
|
150
162
|
}
|
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
|
|
5
|
+
const builtinTypes = new Set([
|
|
6
|
+
'double', 'float', 'int32', 'int64', 'uint32', 'uint64', 'sint32', 'sint64',
|
|
7
|
+
'fixed32', 'fixed64', 'sfixed32', 'sfixed64', 'bool', 'string', 'bytes'
|
|
8
|
+
]);
|
|
9
|
+
|
|
10
|
+
function stripComments(source) {
|
|
11
|
+
let output = '';
|
|
12
|
+
let index = 0;
|
|
13
|
+
let quote = null;
|
|
14
|
+
while (index < source.length) {
|
|
15
|
+
const current = source[index];
|
|
16
|
+
const next = source[index + 1];
|
|
17
|
+
if (quote) {
|
|
18
|
+
output += current;
|
|
19
|
+
if (current === '\\') {
|
|
20
|
+
output += next ?? '';
|
|
21
|
+
index += 2;
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
if (current === quote) quote = null;
|
|
25
|
+
index++;
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (current === '"' || current === "'") {
|
|
29
|
+
quote = current;
|
|
30
|
+
output += current;
|
|
31
|
+
index++;
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (current === '/' && next === '/') {
|
|
35
|
+
while (index < source.length && source[index] !== '\n') {
|
|
36
|
+
output += ' ';
|
|
37
|
+
index++;
|
|
38
|
+
}
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (current === '/' && next === '*') {
|
|
42
|
+
output += ' ';
|
|
43
|
+
index += 2;
|
|
44
|
+
while (index < source.length && !(source[index] === '*' && source[index + 1] === '/')) {
|
|
45
|
+
output += source[index] === '\n' ? '\n' : ' ';
|
|
46
|
+
index++;
|
|
47
|
+
}
|
|
48
|
+
if (index < source.length) {
|
|
49
|
+
output += ' ';
|
|
50
|
+
index += 2;
|
|
51
|
+
}
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
output += current;
|
|
55
|
+
index++;
|
|
56
|
+
}
|
|
57
|
+
return output;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function tokenize(source) {
|
|
61
|
+
const tokens = [];
|
|
62
|
+
const pattern = /\s+|[A-Za-z_][A-Za-z0-9_]*|\d+|"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[{}=;\[\]<>.,()\-]/gy;
|
|
63
|
+
let index = 0;
|
|
64
|
+
while (index < source.length) {
|
|
65
|
+
pattern.lastIndex = index;
|
|
66
|
+
const match = pattern.exec(source);
|
|
67
|
+
if (!match) {
|
|
68
|
+
throw new SyntaxError(`Unsupported protobuf token near: ${source.slice(index, index + 40).replace(/\s+/g, ' ')}`);
|
|
69
|
+
}
|
|
70
|
+
const value = match[0];
|
|
71
|
+
const start = index;
|
|
72
|
+
index = pattern.lastIndex;
|
|
73
|
+
if (/^\s+$/.test(value)) continue;
|
|
74
|
+
const line = source.slice(0, start).split('\n').length;
|
|
75
|
+
tokens.push({ value, line });
|
|
76
|
+
}
|
|
77
|
+
return tokens;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function validateProtoSchema(source) {
|
|
81
|
+
const tokens = tokenize(stripComments(source));
|
|
82
|
+
let index = 0;
|
|
83
|
+
const errors = [];
|
|
84
|
+
const symbols = new Set(['proto']);
|
|
85
|
+
const pendingTypes = [];
|
|
86
|
+
let messageCount = 0;
|
|
87
|
+
let enumCount = 0;
|
|
88
|
+
let fieldCount = 0;
|
|
89
|
+
|
|
90
|
+
const peek = () => tokens[index]?.value;
|
|
91
|
+
const take = () => tokens[index++];
|
|
92
|
+
const fail = (message, token = tokens[index] ?? tokens.at(-1)) => {
|
|
93
|
+
errors.push(`line ${token?.line ?? 1}: ${message}`);
|
|
94
|
+
};
|
|
95
|
+
const expect = value => {
|
|
96
|
+
if (peek() !== value) {
|
|
97
|
+
fail(`expected '${value}', found '${peek() ?? 'end of file'}'`);
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
take();
|
|
101
|
+
return true;
|
|
102
|
+
};
|
|
103
|
+
const isIdentifier = value => /^[A-Za-z_][A-Za-z0-9_]*$/.test(value ?? '');
|
|
104
|
+
|
|
105
|
+
function skipStatement() {
|
|
106
|
+
let depth = 0;
|
|
107
|
+
while (index < tokens.length) {
|
|
108
|
+
const value = take().value;
|
|
109
|
+
if (value === '[' || value === '(' || value === '<') depth++;
|
|
110
|
+
else if (value === ']' || value === ')' || value === '>') depth--;
|
|
111
|
+
else if (value === ';' && depth <= 0) return;
|
|
112
|
+
else if (value === '}' && depth <= 0) {
|
|
113
|
+
index--;
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function parseTypeName() {
|
|
120
|
+
let name = '';
|
|
121
|
+
if (peek() === '.') name += take().value;
|
|
122
|
+
if (!isIdentifier(peek())) {
|
|
123
|
+
fail(`expected protobuf type name, found '${peek() ?? 'end of file'}'`);
|
|
124
|
+
return name;
|
|
125
|
+
}
|
|
126
|
+
name += take().value;
|
|
127
|
+
while (peek() === '.') {
|
|
128
|
+
name += take().value;
|
|
129
|
+
if (!isIdentifier(peek())) {
|
|
130
|
+
fail('expected type name segment after dot');
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
name += take().value;
|
|
134
|
+
}
|
|
135
|
+
return name;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function parseField(message, oneof = false) {
|
|
139
|
+
const start = tokens[index];
|
|
140
|
+
let label;
|
|
141
|
+
if (['optional', 'required', 'repeated'].includes(peek())) label = take().value;
|
|
142
|
+
if (oneof && label) fail(`oneof field cannot have '${label}' label`, start);
|
|
143
|
+
|
|
144
|
+
let typeName;
|
|
145
|
+
if (peek() === 'map') {
|
|
146
|
+
take();
|
|
147
|
+
expect('<');
|
|
148
|
+
parseTypeName();
|
|
149
|
+
expect(',');
|
|
150
|
+
parseTypeName();
|
|
151
|
+
expect('>');
|
|
152
|
+
typeName = 'map';
|
|
153
|
+
} else {
|
|
154
|
+
typeName = parseTypeName();
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const fieldNameToken = take();
|
|
158
|
+
const fieldName = fieldNameToken?.value;
|
|
159
|
+
if (!isIdentifier(fieldName)) {
|
|
160
|
+
fail(`expected field name, found '${fieldName ?? 'end of file'}'`, fieldNameToken ?? start);
|
|
161
|
+
skipStatement();
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
expect('=');
|
|
165
|
+
const numberToken = take();
|
|
166
|
+
const number = Number(numberToken?.value);
|
|
167
|
+
if (!Number.isInteger(number) || !/^\d+$/.test(numberToken?.value ?? '')) {
|
|
168
|
+
fail(`field '${fieldName}' has an invalid field number`, numberToken ?? start);
|
|
169
|
+
} else {
|
|
170
|
+
if (number < 1 || number > 536870911 || (number >= 19000 && number <= 19999)) {
|
|
171
|
+
fail(`field '${fieldName}' uses reserved/invalid field number ${number}`, numberToken);
|
|
172
|
+
}
|
|
173
|
+
if (message.fieldNames.has(fieldName)) {
|
|
174
|
+
fail(`duplicate field name '${fieldName}' in ${message.path}; first declared on line ${message.fieldNames.get(fieldName)}`, fieldNameToken);
|
|
175
|
+
} else {
|
|
176
|
+
message.fieldNames.set(fieldName, fieldNameToken.line);
|
|
177
|
+
}
|
|
178
|
+
if (message.fieldNumbers.has(number)) {
|
|
179
|
+
fail(`duplicate field number ${number} in ${message.path}; already used by '${message.fieldNumbers.get(number)}'`, numberToken);
|
|
180
|
+
} else {
|
|
181
|
+
message.fieldNumbers.set(number, fieldName);
|
|
182
|
+
}
|
|
183
|
+
if (typeName && typeName !== 'map') {
|
|
184
|
+
pendingTypes.push({ typeName, scope: message.path, line: start.line, fieldName });
|
|
185
|
+
}
|
|
186
|
+
fieldCount++;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (peek() === '[') {
|
|
190
|
+
take();
|
|
191
|
+
let depth = 1;
|
|
192
|
+
while (index < tokens.length && depth > 0) {
|
|
193
|
+
const value = take().value;
|
|
194
|
+
if (value === '[') depth++;
|
|
195
|
+
if (value === ']') depth--;
|
|
196
|
+
}
|
|
197
|
+
if (depth !== 0) fail(`unterminated field options for '${fieldName}'`, start);
|
|
198
|
+
}
|
|
199
|
+
expect(';');
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function parseEnum(parentPath) {
|
|
203
|
+
const start = take();
|
|
204
|
+
const nameToken = take();
|
|
205
|
+
const name = nameToken?.value;
|
|
206
|
+
if (!isIdentifier(name)) fail('expected enum name', nameToken ?? start);
|
|
207
|
+
const enumPath = `${parentPath}.${name}`;
|
|
208
|
+
symbols.add(enumPath);
|
|
209
|
+
enumCount++;
|
|
210
|
+
expect('{');
|
|
211
|
+
const names = new Map();
|
|
212
|
+
const values = new Map();
|
|
213
|
+
let allowAlias = false;
|
|
214
|
+
while (index < tokens.length && peek() !== '}') {
|
|
215
|
+
if (peek() === 'option') {
|
|
216
|
+
const optionStart = index;
|
|
217
|
+
while (index < tokens.length && peek() !== ';' && peek() !== '}') index++;
|
|
218
|
+
const text = tokens.slice(optionStart, index).map(token => token.value).join(' ');
|
|
219
|
+
if (/allow_alias\s*=\s*true/.test(text)) allowAlias = true;
|
|
220
|
+
if (peek() === ';') take();
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
if (peek() === 'reserved') {
|
|
224
|
+
skipStatement();
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
const valueName = take();
|
|
228
|
+
if (!isIdentifier(valueName?.value)) {
|
|
229
|
+
fail(`invalid enum member '${valueName?.value ?? 'EOF'}'`, valueName);
|
|
230
|
+
skipStatement();
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
expect('=');
|
|
234
|
+
let sign = 1;
|
|
235
|
+
if (peek() === '-') { take(); sign = -1; }
|
|
236
|
+
const numberToken = take();
|
|
237
|
+
const number = sign * Number(numberToken?.value);
|
|
238
|
+
if (!Number.isInteger(number) || !/^\d+$/.test(numberToken?.value ?? '')) {
|
|
239
|
+
fail(`enum member '${valueName.value}' has invalid numeric value`, numberToken ?? valueName);
|
|
240
|
+
}
|
|
241
|
+
if (names.has(valueName.value)) {
|
|
242
|
+
fail(`duplicate enum member '${valueName.value}' in ${enumPath}`, valueName);
|
|
243
|
+
}
|
|
244
|
+
if (!allowAlias && values.has(number)) {
|
|
245
|
+
fail(`enum ${enumPath} repeats value ${number} without option allow_alias = true`, numberToken);
|
|
246
|
+
}
|
|
247
|
+
names.set(valueName.value, valueName.line);
|
|
248
|
+
values.set(number, valueName.value);
|
|
249
|
+
if (peek() === '[') {
|
|
250
|
+
take();
|
|
251
|
+
while (index < tokens.length && peek() !== ']') take();
|
|
252
|
+
expect(']');
|
|
253
|
+
}
|
|
254
|
+
expect(';');
|
|
255
|
+
}
|
|
256
|
+
expect('}');
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function parseMessage(parentPath) {
|
|
260
|
+
const start = take();
|
|
261
|
+
const nameToken = take();
|
|
262
|
+
const name = nameToken?.value;
|
|
263
|
+
if (!isIdentifier(name)) fail('expected message name', nameToken ?? start);
|
|
264
|
+
const messagePath = `${parentPath}.${name}`;
|
|
265
|
+
symbols.add(messagePath);
|
|
266
|
+
messageCount++;
|
|
267
|
+
expect('{');
|
|
268
|
+
const message = { path: messagePath, fieldNames: new Map(), fieldNumbers: new Map() };
|
|
269
|
+
const nestedNames = new Set();
|
|
270
|
+
while (index < tokens.length && peek() !== '}') {
|
|
271
|
+
const value = peek();
|
|
272
|
+
if (value === 'message' || value === 'enum') {
|
|
273
|
+
const nestedName = tokens[index + 1]?.value;
|
|
274
|
+
if (nestedNames.has(nestedName)) fail(`duplicate nested type '${nestedName}' in ${messagePath}`);
|
|
275
|
+
nestedNames.add(nestedName);
|
|
276
|
+
if (value === 'message') parseMessage(messagePath);
|
|
277
|
+
else parseEnum(messagePath);
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
if (value === 'oneof') {
|
|
281
|
+
take();
|
|
282
|
+
take();
|
|
283
|
+
expect('{');
|
|
284
|
+
while (index < tokens.length && peek() !== '}') {
|
|
285
|
+
if (peek() === 'option') { skipStatement(); continue; }
|
|
286
|
+
if (peek() === 'reserved') { skipStatement(); continue; }
|
|
287
|
+
parseField(message, true);
|
|
288
|
+
}
|
|
289
|
+
expect('}');
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
if (['option', 'reserved', 'extensions'].includes(value)) {
|
|
293
|
+
skipStatement();
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
296
|
+
parseField(message);
|
|
297
|
+
}
|
|
298
|
+
expect('}');
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
while (index < tokens.length) {
|
|
302
|
+
if (peek() === 'message') parseMessage('proto');
|
|
303
|
+
else if (peek() === 'enum') parseEnum('proto');
|
|
304
|
+
else if (['syntax', 'package', 'import', 'option'].includes(peek())) skipStatement();
|
|
305
|
+
else {
|
|
306
|
+
const unknown = take();
|
|
307
|
+
fail(`unexpected top-level token '${unknown.value}'`, unknown);
|
|
308
|
+
skipStatement();
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
for (const item of pendingTypes) {
|
|
313
|
+
if (builtinTypes.has(item.typeName)) continue;
|
|
314
|
+
let candidates;
|
|
315
|
+
if (item.typeName.startsWith('.')) {
|
|
316
|
+
candidates = [item.typeName.slice(1)];
|
|
317
|
+
} else {
|
|
318
|
+
const parentParts = item.scope.split('.');
|
|
319
|
+
candidates = [];
|
|
320
|
+
while (parentParts.length) {
|
|
321
|
+
candidates.push(`${parentParts.join('.')}.${item.typeName}`);
|
|
322
|
+
parentParts.pop();
|
|
323
|
+
}
|
|
324
|
+
candidates.push(`proto.${item.typeName}`);
|
|
325
|
+
}
|
|
326
|
+
if (!candidates.some(candidate => symbols.has(candidate))) {
|
|
327
|
+
errors.push(`line ${item.line}: unresolved type '${item.typeName}' for field '${item.fieldName}' in ${item.scope}`);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
return { errors, messageCount, enumCount, fieldCount };
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
335
|
+
const schemaPath = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../WAProto/WAProto.proto');
|
|
336
|
+
const result = validateProtoSchema(readFileSync(schemaPath, 'utf8'));
|
|
337
|
+
if (result.errors.length) {
|
|
338
|
+
console.error(`WAProto validation failed (${result.errors.length} issue${result.errors.length === 1 ? '' : 's'}):`);
|
|
339
|
+
for (const error of result.errors) console.error(`- ${error}`);
|
|
340
|
+
process.exitCode = 1;
|
|
341
|
+
} else {
|
|
342
|
+
console.log(`WAProto validation passed: ${result.messageCount} messages, ${result.enumCount} enums, ${result.fieldCount} fields; no duplicate fields/numbers, invalid references, or structural errors.`);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
|
|
4
|
+
const missingDependency = error => error?.code === 'ERR_MODULE_NOT_FOUND'
|
|
5
|
+
&& /protobufjs/.test(error.message);
|
|
6
|
+
|
|
7
|
+
test('protobufjs parses the merged schema and Kage runtime encodes WebMessageInfo extensions', async t => {
|
|
8
|
+
let runtime;
|
|
9
|
+
try {
|
|
10
|
+
runtime = await import('../WAProto/index.js');
|
|
11
|
+
} catch (error) {
|
|
12
|
+
if (missingDependency(error)) {
|
|
13
|
+
t.skip('protobufjs is declared in package.json but not installed in this validation environment');
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
throw error;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const { proto } = runtime;
|
|
20
|
+
assert.ok(proto?.WebMessageInfo, 'WebMessageInfo runtime type is exposed');
|
|
21
|
+
|
|
22
|
+
const source = {
|
|
23
|
+
nonJidMentions: 4,
|
|
24
|
+
hsmTag: 'kage-test',
|
|
25
|
+
decisionId: 'decision-1',
|
|
26
|
+
decisionSources: ['source-a', 'source-b']
|
|
27
|
+
};
|
|
28
|
+
const encoded = proto.WebMessageInfo.encode(proto.WebMessageInfo.fromObject(source)).finish();
|
|
29
|
+
const decoded = proto.WebMessageInfo.decode(encoded);
|
|
30
|
+
|
|
31
|
+
assert.equal(decoded.nonJidMentions, source.nonJidMentions);
|
|
32
|
+
assert.equal(decoded.hsmTag, source.hsmTag);
|
|
33
|
+
assert.equal(decoded.decisionId, source.decisionId);
|
|
34
|
+
assert.deepEqual(decoded.decisionSources, source.decisionSources);
|
|
35
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { readFileSync } from 'node:fs';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { validateProtoSchema } from '../scripts/verify-proto.mjs';
|
|
7
|
+
|
|
8
|
+
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
9
|
+
|
|
10
|
+
test('WAProto schema has unique field names/numbers and resolvable types', () => {
|
|
11
|
+
const schema = readFileSync(path.join(root, 'WAProto', 'WAProto.proto'), 'utf8');
|
|
12
|
+
const result = validateProtoSchema(schema);
|
|
13
|
+
assert.deepEqual(result.errors, []);
|
|
14
|
+
assert.ok(result.messageCount > 700);
|
|
15
|
+
assert.ok(result.fieldCount > 3000);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test('WAProto validator detects duplicate field names', () => {
|
|
19
|
+
const schema = `syntax = \"proto3\"; package proto; message WebMessageInfo { string id = 1; string id = 2; }`;
|
|
20
|
+
const result = validateProtoSchema(schema);
|
|
21
|
+
assert.ok(result.errors.some(error => error.includes("duplicate field name 'id' in proto.WebMessageInfo")));
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('WAProto validator detects duplicate field numbers', () => {
|
|
25
|
+
const schema = `syntax = \"proto3\"; package proto; message WebMessageInfo { string id = 1; bool read = 1; }`;
|
|
26
|
+
const result = validateProtoSchema(schema);
|
|
27
|
+
assert.ok(result.errors.some(error => error.includes('duplicate field number 1 in proto.WebMessageInfo')));
|
|
28
|
+
});
|