tina4-nodejs 3.13.162 → 3.13.163
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/CLAUDE.md +2 -2
- package/package.json +1 -1
- package/packages/cli/dist/bin.js +238 -129
- package/packages/cli/src/commands/test.ts +2 -2
- package/packages/core/dist/index.js +237 -127
- package/packages/core/src/index.ts +1 -1
- package/packages/core/src/mcp.ts +10 -4
- package/packages/core/src/queueBackends/kafkaBackend.ts +56 -10
- package/packages/core/src/testing.ts +181 -69
- package/packages/orm/dist/index.js +236 -127
- package/types/core/src/index.d.ts +1 -1
- package/types/core/src/mcp.d.ts +2 -2
- package/types/core/src/testing.d.ts +27 -4
package/CLAUDE.md
CHANGED
|
@@ -14,13 +14,13 @@ Even if the skill text is not currently loaded, these are non-negotiable:
|
|
|
14
14
|
|
|
15
15
|
The full discipline lives in `.claude/skills/tina4-maintainer/SKILL.md`; this block is the always-on floor.
|
|
16
16
|
|
|
17
|
-
# CLAUDE.md - AI Developer Guide for tina4-nodejs (v3.13.
|
|
17
|
+
# CLAUDE.md - AI Developer Guide for tina4-nodejs (v3.13.163)
|
|
18
18
|
|
|
19
19
|
> This file helps AI assistants (Claude, Copilot, Cursor, etc.) understand and work on this codebase effectively.
|
|
20
20
|
|
|
21
21
|
## What This Project Is
|
|
22
22
|
|
|
23
|
-
Tina4 for Node.js/TypeScript v3.13.
|
|
23
|
+
Tina4 for Node.js/TypeScript v3.13.163 - The Intelligent Native Application 4ramework. A convention-over-configuration structural paradigm. The developer writes TypeScript; Tina4 is invisible infrastructure.
|
|
24
24
|
|
|
25
25
|
The philosophy: zero ceremony, batteries included, file system as source of truth.
|
|
26
26
|
|
package/package.json
CHANGED
package/packages/cli/dist/bin.js
CHANGED
|
@@ -5964,11 +5964,11 @@ var init_firebird = __esm({
|
|
|
5964
5964
|
*/
|
|
5965
5965
|
async decodeBlobs(row) {
|
|
5966
5966
|
if (row === null || typeof row !== "object") return row;
|
|
5967
|
-
const
|
|
5968
|
-
for (const key of Object.keys(
|
|
5969
|
-
if (typeof
|
|
5970
|
-
|
|
5971
|
-
|
|
5967
|
+
const record2 = row;
|
|
5968
|
+
for (const key of Object.keys(record2)) {
|
|
5969
|
+
if (typeof record2[key] === "function") {
|
|
5970
|
+
record2[key] = await this.readBlob(
|
|
5971
|
+
record2[key]
|
|
5972
5972
|
);
|
|
5973
5973
|
}
|
|
5974
5974
|
}
|
|
@@ -13459,12 +13459,12 @@ function crudSortProp(model, requested, pkProp) {
|
|
|
13459
13459
|
}
|
|
13460
13460
|
return pkProp;
|
|
13461
13461
|
}
|
|
13462
|
-
function cellValue(
|
|
13463
|
-
return
|
|
13462
|
+
function cellValue(record2, col) {
|
|
13463
|
+
return record2[col];
|
|
13464
13464
|
}
|
|
13465
|
-
function buildCells(columns,
|
|
13465
|
+
function buildCells(columns, record2, editable, aligns) {
|
|
13466
13466
|
return columns.map((col, index) => {
|
|
13467
|
-
const raw = cellValue(
|
|
13467
|
+
const raw = cellValue(record2, col);
|
|
13468
13468
|
const value = h(raw === null || raw === void 0 ? "" : raw);
|
|
13469
13469
|
const css = aligns[index];
|
|
13470
13470
|
return editable ? `<td class="${css}" contenteditable="true" data-field="${h(col)}">${value}</td>` : `<td class="${css}">${value}</td>`;
|
|
@@ -13627,9 +13627,9 @@ function headerCell(opts, col, align) {
|
|
|
13627
13627
|
function tableData(opts) {
|
|
13628
13628
|
const aligns = opts.columns.map((col) => columnAlignment(opts.model, col));
|
|
13629
13629
|
const headers = opts.columns.map((col, index) => headerCell(opts, col, aligns[index]));
|
|
13630
|
-
const rows = opts.records.map((
|
|
13631
|
-
id: h(cellValue(
|
|
13632
|
-
cells: buildCells(opts.columns,
|
|
13630
|
+
const rows = opts.records.map((record2) => ({
|
|
13631
|
+
id: h(cellValue(record2, opts.pk) ?? ""),
|
|
13632
|
+
cells: buildCells(opts.columns, record2, opts.editable, aligns)
|
|
13633
13633
|
}));
|
|
13634
13634
|
return {
|
|
13635
13635
|
headers,
|
|
@@ -14828,9 +14828,9 @@ async function eagerLoadHasRelation(instances, model, relatedClass, relationName
|
|
|
14828
14828
|
if (nested.length > 0 && related.length > 0) await relatedClass._eagerLoad(related, nested);
|
|
14829
14829
|
const fkProp = reverseMappedColumn(relatedClass, relation.foreignKey);
|
|
14830
14830
|
const grouped = {};
|
|
14831
|
-
for (const
|
|
14832
|
-
const key = _joinKey(
|
|
14833
|
-
(grouped[key] ??= []).push(
|
|
14831
|
+
for (const record2 of related) {
|
|
14832
|
+
const key = _joinKey(record2[fkProp]);
|
|
14833
|
+
(grouped[key] ??= []).push(record2);
|
|
14834
14834
|
}
|
|
14835
14835
|
for (const instance of instances) {
|
|
14836
14836
|
const records = grouped[_joinKey(instance[pk])] ?? [];
|
|
@@ -14846,7 +14846,7 @@ async function eagerLoadBelongsToRelation(instances, model, relatedClass, relati
|
|
|
14846
14846
|
const related = await eagerQueryRelated(relatedClass, relatedPkColumn, values);
|
|
14847
14847
|
if (nested.length > 0 && related.length > 0) await relatedClass._eagerLoad(related, nested);
|
|
14848
14848
|
const lookup2 = {};
|
|
14849
|
-
for (const
|
|
14849
|
+
for (const record2 of related) lookup2[_joinKey(record2[relatedPk])] = record2;
|
|
14850
14850
|
for (const instance of instances) {
|
|
14851
14851
|
const value = instance[fkProp];
|
|
14852
14852
|
relationshipCache(instance)[relationName] = value !== void 0 && value !== null ? lookup2[_joinKey(value)] ?? null : null;
|
|
@@ -18092,7 +18092,7 @@ var init_bolt = __esm({
|
|
|
18092
18092
|
const session = this.database ? this.driver.session({ database: this.database }) : this.driver.session();
|
|
18093
18093
|
try {
|
|
18094
18094
|
const result = await session.run(cypher, params ?? {});
|
|
18095
|
-
return result.records.map((
|
|
18095
|
+
return result.records.map((record2) => record2.toObject());
|
|
18096
18096
|
} catch (exc) {
|
|
18097
18097
|
this.lastError = errorMessage(exc);
|
|
18098
18098
|
const code = exc?.code ?? "";
|
|
@@ -26111,7 +26111,7 @@ var init_session = __esm({
|
|
|
26111
26111
|
save() {
|
|
26112
26112
|
if (!this.sessionId || !this.data) return true;
|
|
26113
26113
|
if (this.isFresh()) return true;
|
|
26114
|
-
let
|
|
26114
|
+
let record2 = this.data;
|
|
26115
26115
|
if (this.stored) {
|
|
26116
26116
|
const current = this.safeRead(this.sessionId);
|
|
26117
26117
|
if (this.lastReadFailed) return false;
|
|
@@ -26120,9 +26120,9 @@ var init_session = __esm({
|
|
|
26120
26120
|
this.ended = true;
|
|
26121
26121
|
return true;
|
|
26122
26122
|
}
|
|
26123
|
-
if (!this.cleared)
|
|
26123
|
+
if (!this.cleared) record2 = this.merged(current);
|
|
26124
26124
|
}
|
|
26125
|
-
if (this.safeWrite(this.sessionId,
|
|
26125
|
+
if (this.safeWrite(this.sessionId, record2, this.ttl)) {
|
|
26126
26126
|
this.dirty = false;
|
|
26127
26127
|
this.stored = true;
|
|
26128
26128
|
this.cleared = false;
|
|
@@ -26139,19 +26139,19 @@ var init_session = __esm({
|
|
|
26139
26139
|
*/
|
|
26140
26140
|
merged(current) {
|
|
26141
26141
|
const data = this.data;
|
|
26142
|
-
const
|
|
26142
|
+
const record2 = { ...current };
|
|
26143
26143
|
for (const [key, value] of Object.entries(data)) {
|
|
26144
26144
|
const print = fingerprint(value);
|
|
26145
26145
|
if (print === void 0 || !this.loaded.has(key) || this.loaded.get(key) !== print) {
|
|
26146
|
-
|
|
26146
|
+
record2[key] = value;
|
|
26147
26147
|
}
|
|
26148
26148
|
}
|
|
26149
26149
|
for (const key of this.loaded.keys()) {
|
|
26150
26150
|
if (!Object.prototype.hasOwnProperty.call(data, key)) {
|
|
26151
|
-
delete
|
|
26151
|
+
delete record2[key];
|
|
26152
26152
|
}
|
|
26153
26153
|
}
|
|
26154
|
-
return
|
|
26154
|
+
return record2;
|
|
26155
26155
|
}
|
|
26156
26156
|
/**
|
|
26157
26157
|
* End the session for this request without touching the store: no id and
|
|
@@ -31329,7 +31329,7 @@ data: ${channel.buffer.shift()}
|
|
|
31329
31329
|
}
|
|
31330
31330
|
return { resources };
|
|
31331
31331
|
}
|
|
31332
|
-
_handleResourcesRead(params) {
|
|
31332
|
+
async _handleResourcesRead(params) {
|
|
31333
31333
|
const uri = params.uri;
|
|
31334
31334
|
if (!uri) {
|
|
31335
31335
|
throw new Error("Missing resource URI");
|
|
@@ -31338,7 +31338,7 @@ data: ${channel.buffer.shift()}
|
|
|
31338
31338
|
if (!resource) {
|
|
31339
31339
|
throw new Error(`Unknown resource: ${uri}`);
|
|
31340
31340
|
}
|
|
31341
|
-
const result = resource.handler();
|
|
31341
|
+
const result = await resource.handler();
|
|
31342
31342
|
let text;
|
|
31343
31343
|
if (typeof result === "string") {
|
|
31344
31344
|
text = result;
|
|
@@ -34872,6 +34872,12 @@ const outBytes = new Uint8Array(workerData.sab, 8);
|
|
|
34872
34872
|
// (test/kafkaErrorCodes.test.ts) can assert the floors.
|
|
34873
34873
|
const PRODUCE_VERSION = 3;
|
|
34874
34874
|
const FETCH_VERSION = 4;
|
|
34875
|
+
// How long the broker long-polls an empty partition before answering (ms).
|
|
34876
|
+
// Deliberately 1000, not tina4-php / tina4-python's 5000: Node's pop() is
|
|
34877
|
+
// synchronous (Atomics.wait on this worker), so the long-poll blocks the whole
|
|
34878
|
+
// event loop, not one request. The tombstone-skip deadline caps it further while
|
|
34879
|
+
// stepping so a stream of tombstones cannot hold pop() past ~1s.
|
|
34880
|
+
const FETCH_MAX_WAIT_MS = 1000;
|
|
34875
34881
|
|
|
34876
34882
|
let correlationId = 0;
|
|
34877
34883
|
let brokerSock = null;
|
|
@@ -35058,12 +35064,13 @@ async function produce(topic, valueBytes) {
|
|
|
35058
35064
|
}
|
|
35059
35065
|
|
|
35060
35066
|
// \u2500\u2500 fetch \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
35061
|
-
function fetchRequest(topic, offset) {
|
|
35067
|
+
function fetchRequest(topic, offset, maxWaitMs) {
|
|
35068
|
+
if (maxWaitMs === undefined) maxWaitMs = FETCH_MAX_WAIT_MS;
|
|
35062
35069
|
const topicBuf = Buffer.from(topic, "utf-8");
|
|
35063
35070
|
const buf = Buffer.alloc(4 + 4 + 4 + 4 + 1 + 4 + 2 + topicBuf.length + 4 + 4 + 8 + 4);
|
|
35064
35071
|
let p = 0;
|
|
35065
35072
|
buf.writeInt32BE(-1, p); p += 4; // replicaId
|
|
35066
|
-
buf.writeInt32BE(
|
|
35073
|
+
buf.writeInt32BE(maxWaitMs, p); p += 4; // maxWaitMs (long-poll bound; capped by the tombstone-skip deadline)
|
|
35067
35074
|
buf.writeInt32BE(1, p); p += 4; // minBytes
|
|
35068
35075
|
buf.writeInt32BE(1048576, p); p += 4; // maxBytes
|
|
35069
35076
|
buf.writeInt8(0, p); p += 1; // isolation READ_UNCOMMITTED
|
|
@@ -35076,8 +35083,12 @@ function fetchRequest(topic, offset) {
|
|
|
35076
35083
|
buf.writeInt32BE(1048576, p); p += 4;
|
|
35077
35084
|
return frame(1, FETCH_VERSION, buf);
|
|
35078
35085
|
}
|
|
35079
|
-
// Decode the
|
|
35080
|
-
//
|
|
35086
|
+
// Decode the FIRST record of the partition's record-set (the cross-framework
|
|
35087
|
+
// contract: only a batch's first record is decoded -- the Tina4 producer writes
|
|
35088
|
+
// one record per batch). Returns its value and absolute offset (baseOffset +
|
|
35089
|
+
// offsetDelta); a tombstone (null value) comes back with value null and its
|
|
35090
|
+
// offset so the caller can step past it. null = no usable record at all (empty /
|
|
35091
|
+
// old-format / short response).
|
|
35081
35092
|
function firstRecord(buf, start, end) {
|
|
35082
35093
|
let pos = start;
|
|
35083
35094
|
while (pos + 12 <= end) {
|
|
@@ -35093,8 +35104,7 @@ function firstRecord(buf, start, end) {
|
|
|
35093
35104
|
for (let i = 0; i < recordsCount && r < batchEnd; i++) {
|
|
35094
35105
|
const recLen = readVarint(buf, r);
|
|
35095
35106
|
let rp = recLen.next;
|
|
35096
|
-
|
|
35097
|
-
rp += 1;
|
|
35107
|
+
rp += 1; // record attributes byte
|
|
35098
35108
|
rp = readVarint(buf, rp).next; // timestampDelta
|
|
35099
35109
|
const offDelta = readVarint(buf, rp); rp = offDelta.next;
|
|
35100
35110
|
const keyLen = readVarint(buf, rp); rp = keyLen.next;
|
|
@@ -35106,15 +35116,23 @@ function firstRecord(buf, start, end) {
|
|
|
35106
35116
|
offset: Number(baseOffset) + offDelta.value,
|
|
35107
35117
|
};
|
|
35108
35118
|
}
|
|
35109
|
-
|
|
35119
|
+
// Tombstone (null value) or empty value: hand back a marker carrying its
|
|
35120
|
+
// offset instead of null. Returning null here used to mean "no record", so
|
|
35121
|
+
// pop() never advanced and re-fetched the tombstone for ever -- nothing
|
|
35122
|
+
// after it was delivered. The caller (fetchPastTombstones) steps the
|
|
35123
|
+
// offset on and re-fetches.
|
|
35124
|
+
return {
|
|
35125
|
+
value: null,
|
|
35126
|
+
offset: Number(baseOffset) + offDelta.value,
|
|
35127
|
+
};
|
|
35110
35128
|
}
|
|
35111
35129
|
pos = batchEnd;
|
|
35112
35130
|
}
|
|
35113
35131
|
return null;
|
|
35114
35132
|
}
|
|
35115
|
-
async function fetchAt(topic, offset) {
|
|
35133
|
+
async function fetchAt(topic, offset, maxWaitMs) {
|
|
35116
35134
|
const sock = await broker();
|
|
35117
|
-
const resp = await rpc(sock, fetchRequest(topic, offset));
|
|
35135
|
+
const resp = await rpc(sock, fetchRequest(topic, offset, maxWaitMs));
|
|
35118
35136
|
let pos = 4; // correlationId
|
|
35119
35137
|
pos += 4; // throttleTimeMs
|
|
35120
35138
|
const topicCount = resp.readInt32BE(pos); pos += 4;
|
|
@@ -35250,9 +35268,37 @@ async function broker() {
|
|
|
35250
35268
|
// Resume from the committed offset on the FIRST read of a topic in this worker,
|
|
35251
35269
|
// then advance the in-memory cursor; the committed offset only moves on a
|
|
35252
35270
|
// commit, so it lags and a crash before commit replays (at-least-once).
|
|
35271
|
+
// Fetch from the cursor, stepping past tombstones, until a record with a value
|
|
35272
|
+
// arrives, the topic is exhausted, or the deadline passes. A tombstone (null
|
|
35273
|
+
// value: Debezium deletes, compacted-topic delete markers) carries no job;
|
|
35274
|
+
// returning "nothing" without moving the offset re-fetched it for ever, so
|
|
35275
|
+
// nothing after it was ever delivered. The 1 s deadline holds while skipping
|
|
35276
|
+
// (the same steady-state bound as tina4-php/tina4-python), and the whole loop
|
|
35277
|
+
// stays inside this one worker round-trip (ADR-0022) -- well under
|
|
35278
|
+
// CALL_TIMEOUT_MS. Nothing is committed here: acknowledging the next record
|
|
35279
|
+
// commits past the skipped tombstones, as before.
|
|
35280
|
+
async function fetchPastTombstones(topic) {
|
|
35281
|
+
const deadline = Date.now() + 1000;
|
|
35282
|
+
let maxWaitMs = FETCH_MAX_WAIT_MS;
|
|
35283
|
+
while (true) {
|
|
35284
|
+
const offset = offsets[topic];
|
|
35285
|
+
const rec = await fetchAt(topic, offset, maxWaitMs);
|
|
35286
|
+
if (rec === null || rec.value !== null) return rec; // nothing, or a real record
|
|
35287
|
+
// Anti-spin: the decoder reads only a batch's first record, so a tombstone
|
|
35288
|
+
// sharing a batch with later records comes back at an offset already passed.
|
|
35289
|
+
// That must never loop this fetch.
|
|
35290
|
+
const next = rec.offset + 1;
|
|
35291
|
+
if (next <= offset) return null;
|
|
35292
|
+
offsets[topic] = next;
|
|
35293
|
+
const remaining = deadline - Date.now();
|
|
35294
|
+
if (remaining <= 0) return null;
|
|
35295
|
+
maxWaitMs = remaining;
|
|
35296
|
+
}
|
|
35297
|
+
}
|
|
35298
|
+
|
|
35253
35299
|
async function fetchNext(topic) {
|
|
35254
35300
|
if (!(topic in offsets)) offsets[topic] = await offsetFetch(topic);
|
|
35255
|
-
const rec = await
|
|
35301
|
+
const rec = await fetchPastTombstones(topic);
|
|
35256
35302
|
if (rec === null) return null;
|
|
35257
35303
|
offsets[topic] = rec.offset + 1;
|
|
35258
35304
|
return rec;
|
|
@@ -35757,7 +35803,7 @@ var init_liteBackend = __esm({
|
|
|
35757
35803
|
writeReserved(queue, job) {
|
|
35758
35804
|
const now = this.nowIso();
|
|
35759
35805
|
const vt = this.visibilityTimeout || 0;
|
|
35760
|
-
const
|
|
35806
|
+
const record2 = {
|
|
35761
35807
|
id: job.id,
|
|
35762
35808
|
payload: job.payload,
|
|
35763
35809
|
status: "reserved",
|
|
@@ -35769,7 +35815,7 @@ var init_liteBackend = __esm({
|
|
|
35769
35815
|
createdAt: job.createdAt ?? now,
|
|
35770
35816
|
topic: job.topic ?? queue
|
|
35771
35817
|
};
|
|
35772
|
-
writeFileSync12(this.reservedPath(queue,
|
|
35818
|
+
writeFileSync12(this.reservedPath(queue, record2.id), JSON.stringify(record2, null, 2));
|
|
35773
35819
|
}
|
|
35774
35820
|
/**
|
|
35775
35821
|
* Return expired reservations to the queue (at-least-once delivery).
|
|
@@ -35791,29 +35837,29 @@ var init_liteBackend = __esm({
|
|
|
35791
35837
|
}
|
|
35792
35838
|
for (const filename of filenames) {
|
|
35793
35839
|
const filePath = join25(reservedDir, filename);
|
|
35794
|
-
let
|
|
35840
|
+
let record2;
|
|
35795
35841
|
try {
|
|
35796
|
-
|
|
35842
|
+
record2 = JSON.parse(readFileSync16(filePath, "utf-8"));
|
|
35797
35843
|
} catch {
|
|
35798
35844
|
continue;
|
|
35799
35845
|
}
|
|
35800
|
-
if (
|
|
35846
|
+
if (record2.availableAt && record2.availableAt > now) continue;
|
|
35801
35847
|
try {
|
|
35802
35848
|
unlinkSync8(filePath);
|
|
35803
35849
|
} catch {
|
|
35804
35850
|
continue;
|
|
35805
35851
|
}
|
|
35806
|
-
const attempts = (
|
|
35852
|
+
const attempts = (record2.attempts ?? 0) + 1;
|
|
35807
35853
|
const error2 = "reservation timed out \u2014 consumer did not acknowledge within the visibility timeout";
|
|
35808
35854
|
const job = {
|
|
35809
|
-
id:
|
|
35810
|
-
payload:
|
|
35855
|
+
id: record2.id,
|
|
35856
|
+
payload: record2.payload,
|
|
35811
35857
|
status: "reserved",
|
|
35812
|
-
createdAt:
|
|
35858
|
+
createdAt: record2.createdAt ?? now,
|
|
35813
35859
|
attempts,
|
|
35814
35860
|
delayUntil: null,
|
|
35815
|
-
priority:
|
|
35816
|
-
topic:
|
|
35861
|
+
priority: record2.priority ?? 0,
|
|
35862
|
+
topic: record2.topic ?? queue,
|
|
35817
35863
|
error: error2
|
|
35818
35864
|
};
|
|
35819
35865
|
if (attempts >= maxRetries) {
|
|
@@ -49902,26 +49948,26 @@ var init_aiClient = __esm({
|
|
|
49902
49948
|
if (!part || typeof part !== "object" || Array.isArray(part)) {
|
|
49903
49949
|
throw new AiConfigError("AI content part must be an object with type and text/source");
|
|
49904
49950
|
}
|
|
49905
|
-
const
|
|
49906
|
-
switch (
|
|
49951
|
+
const record2 = part;
|
|
49952
|
+
switch (record2.type) {
|
|
49907
49953
|
case "text":
|
|
49908
|
-
this.validateTextPart(
|
|
49954
|
+
this.validateTextPart(record2);
|
|
49909
49955
|
return;
|
|
49910
49956
|
case "image":
|
|
49911
|
-
this.validateImagePart(
|
|
49957
|
+
this.validateImagePart(record2);
|
|
49912
49958
|
return;
|
|
49913
49959
|
case "tool_result":
|
|
49914
|
-
this.validateToolResultPart(
|
|
49960
|
+
this.validateToolResultPart(record2);
|
|
49915
49961
|
return;
|
|
49916
49962
|
default:
|
|
49917
|
-
throw new AiConfigError(`AI content part has unknown type '${String(
|
|
49963
|
+
throw new AiConfigError(`AI content part has unknown type '${String(record2.type)}'`);
|
|
49918
49964
|
}
|
|
49919
49965
|
}
|
|
49920
|
-
static validateTextPart(
|
|
49921
|
-
if (typeof
|
|
49966
|
+
static validateTextPart(record2) {
|
|
49967
|
+
if (typeof record2.text !== "string") throw new AiConfigError("AI text content part requires a string 'text' field");
|
|
49922
49968
|
}
|
|
49923
|
-
static validateImagePart(
|
|
49924
|
-
const source =
|
|
49969
|
+
static validateImagePart(record2) {
|
|
49970
|
+
const source = record2.source;
|
|
49925
49971
|
if (typeof source !== "string" || source.length === 0) {
|
|
49926
49972
|
throw new AiConfigError("AI image content part requires a non-empty string 'source' field");
|
|
49927
49973
|
}
|
|
@@ -49932,11 +49978,11 @@ var init_aiClient = __esm({
|
|
|
49932
49978
|
throw new AiConfigError("AI image data URI must be data:<media_type>;base64,<payload>");
|
|
49933
49979
|
}
|
|
49934
49980
|
}
|
|
49935
|
-
static validateToolResultPart(
|
|
49936
|
-
if (typeof
|
|
49981
|
+
static validateToolResultPart(record2) {
|
|
49982
|
+
if (typeof record2.tool_use_id !== "string" || record2.tool_use_id.length === 0) {
|
|
49937
49983
|
throw new AiConfigError("AI tool_result part requires a non-empty string 'tool_use_id'");
|
|
49938
49984
|
}
|
|
49939
|
-
if (typeof
|
|
49985
|
+
if (typeof record2.content !== "string") throw new AiConfigError("AI tool_result part requires a string 'content'");
|
|
49940
49986
|
}
|
|
49941
49987
|
/**
|
|
49942
49988
|
* Validate the outbound tool declarations (ADR-0061). Each tool needs a
|
|
@@ -49952,14 +49998,14 @@ var init_aiClient = __esm({
|
|
|
49952
49998
|
if (!tool || typeof tool !== "object" || Array.isArray(tool)) {
|
|
49953
49999
|
throw new AiConfigError("AI tool must be an object with name, description, parameters");
|
|
49954
50000
|
}
|
|
49955
|
-
const
|
|
49956
|
-
if (typeof
|
|
50001
|
+
const record2 = tool;
|
|
50002
|
+
if (typeof record2.name !== "string" || record2.name.length === 0) {
|
|
49957
50003
|
throw new AiConfigError("AI tool requires a non-empty string 'name'");
|
|
49958
50004
|
}
|
|
49959
|
-
if (typeof
|
|
50005
|
+
if (typeof record2.description !== "string") {
|
|
49960
50006
|
throw new AiConfigError("AI tool requires a string 'description'");
|
|
49961
50007
|
}
|
|
49962
|
-
if (!
|
|
50008
|
+
if (!record2.parameters || typeof record2.parameters !== "object" || Array.isArray(record2.parameters)) {
|
|
49963
50009
|
throw new AiConfigError("AI tool requires a JSON-Schema object 'parameters'");
|
|
49964
50010
|
}
|
|
49965
50011
|
}
|
|
@@ -49976,8 +50022,8 @@ var init_aiClient = __esm({
|
|
|
49976
50022
|
return;
|
|
49977
50023
|
}
|
|
49978
50024
|
if (choice && typeof choice === "object" && !Array.isArray(choice)) {
|
|
49979
|
-
const
|
|
49980
|
-
if (typeof
|
|
50025
|
+
const record2 = choice;
|
|
50026
|
+
if (typeof record2.name !== "string" || record2.name.length === 0) {
|
|
49981
50027
|
throw new AiConfigError("AI toolChoice object requires a non-empty string 'name'");
|
|
49982
50028
|
}
|
|
49983
50029
|
return;
|
|
@@ -51042,38 +51088,37 @@ function runAll(options = {}) {
|
|
|
51042
51088
|
const { quiet = false, failfast = false } = options;
|
|
51043
51089
|
const results = { passed: 0, failed: 0, errors: 0, details: [] };
|
|
51044
51090
|
for (const entry of registry2) {
|
|
51045
|
-
if (!quiet)
|
|
51046
|
-
console.log(`
|
|
51091
|
+
if (!quiet) console.log(`
|
|
51047
51092
|
${entry.name}`);
|
|
51093
|
+
for (const assertion of entry.assertions) {
|
|
51094
|
+
const label = assertionLabel(assertion, entry.name);
|
|
51095
|
+
const ok = record(results, label, quiet, () => judge(assertion, callSync(entry.fn, assertion.args)));
|
|
51096
|
+
if (!ok && failfast) {
|
|
51097
|
+
printSummary(results, quiet);
|
|
51098
|
+
return results;
|
|
51099
|
+
}
|
|
51048
51100
|
}
|
|
51101
|
+
}
|
|
51102
|
+
printSummary(results, quiet);
|
|
51103
|
+
return results;
|
|
51104
|
+
}
|
|
51105
|
+
async function runAllAsync(options = {}) {
|
|
51106
|
+
const { quiet = false, failfast = false, timeoutMs = 3e4 } = options;
|
|
51107
|
+
checkTimeout(timeoutMs);
|
|
51108
|
+
const results = { passed: 0, failed: 0, errors: 0, details: [] };
|
|
51109
|
+
for (const entry of registry2) {
|
|
51110
|
+
if (!quiet) console.log(`
|
|
51111
|
+
${entry.name}`);
|
|
51049
51112
|
for (const assertion of entry.assertions) {
|
|
51050
51113
|
const label = assertionLabel(assertion, entry.name);
|
|
51051
|
-
|
|
51052
|
-
|
|
51053
|
-
|
|
51054
|
-
|
|
51055
|
-
|
|
51056
|
-
|
|
51057
|
-
|
|
51058
|
-
|
|
51059
|
-
if (err instanceof TestAssertionError) {
|
|
51060
|
-
results.failed++;
|
|
51061
|
-
results.details.push({ name: label, status: "failed", message: err.message });
|
|
51062
|
-
if (!quiet) {
|
|
51063
|
-
console.log(` \x1B[31mx\x1B[0m ${label}: ${err.message}`);
|
|
51064
|
-
}
|
|
51065
|
-
} else {
|
|
51066
|
-
results.errors++;
|
|
51067
|
-
const msg = err instanceof Error ? `${err.constructor.name}: ${err.message}` : String(err);
|
|
51068
|
-
results.details.push({ name: label, status: "error", message: msg });
|
|
51069
|
-
if (!quiet) {
|
|
51070
|
-
console.log(` \x1B[33m!\x1B[0m ${label}: ${msg}`);
|
|
51071
|
-
}
|
|
51072
|
-
}
|
|
51073
|
-
if (failfast) {
|
|
51074
|
-
printSummary(results, quiet);
|
|
51075
|
-
return results;
|
|
51076
|
-
}
|
|
51114
|
+
const outcome = await callAsync(entry.fn, assertion.args, timeoutMs);
|
|
51115
|
+
const ok = record(results, label, quiet, () => {
|
|
51116
|
+
if (outcome instanceof TestRunError) throw outcome;
|
|
51117
|
+
judge(assertion, outcome);
|
|
51118
|
+
});
|
|
51119
|
+
if (!ok && failfast) {
|
|
51120
|
+
printSummary(results, quiet);
|
|
51121
|
+
return results;
|
|
51077
51122
|
}
|
|
51078
51123
|
}
|
|
51079
51124
|
}
|
|
@@ -51083,47 +51128,103 @@ function runAll(options = {}) {
|
|
|
51083
51128
|
function reset() {
|
|
51084
51129
|
registry2.length = 0;
|
|
51085
51130
|
}
|
|
51086
|
-
function
|
|
51087
|
-
|
|
51131
|
+
function isThenable(value) {
|
|
51132
|
+
return value !== null && (typeof value === "object" || typeof value === "function") && typeof value.then === "function";
|
|
51133
|
+
}
|
|
51134
|
+
function callSync(fn, args) {
|
|
51135
|
+
let value;
|
|
51136
|
+
try {
|
|
51137
|
+
value = fn(...args);
|
|
51138
|
+
} catch (error2) {
|
|
51139
|
+
return { threw: true, error: error2 };
|
|
51140
|
+
}
|
|
51141
|
+
if (isThenable(value)) {
|
|
51142
|
+
Promise.resolve(value).then(void 0, () => void 0);
|
|
51143
|
+
throw new TestRunError(
|
|
51144
|
+
"returned a Promise (async test function): runAll() cannot judge it, use await runAllAsync()"
|
|
51145
|
+
);
|
|
51146
|
+
}
|
|
51147
|
+
return { threw: false, value };
|
|
51148
|
+
}
|
|
51149
|
+
function checkTimeout(timeoutMs) {
|
|
51150
|
+
if (timeoutMs === Infinity) return;
|
|
51151
|
+
if (!(timeoutMs > 0 && timeoutMs <= MAX_TIMER_MS)) {
|
|
51152
|
+
throw new RangeError(
|
|
51153
|
+
`timeoutMs must be Infinity or a number of milliseconds in (0, ${MAX_TIMER_MS}], got ${timeoutMs}`
|
|
51154
|
+
);
|
|
51155
|
+
}
|
|
51156
|
+
}
|
|
51157
|
+
async function callAsync(fn, args, timeoutMs) {
|
|
51158
|
+
let timer;
|
|
51159
|
+
try {
|
|
51160
|
+
const value = fn(...args);
|
|
51161
|
+
if (!isThenable(value)) return { threw: false, value };
|
|
51162
|
+
if (timeoutMs === Infinity) return { threw: false, value: await value };
|
|
51163
|
+
const timeout = new Promise((_, reject) => {
|
|
51164
|
+
timer = setTimeout(
|
|
51165
|
+
() => reject(new TestRunError(`did not settle within ${timeoutMs} ms`)),
|
|
51166
|
+
timeoutMs
|
|
51167
|
+
);
|
|
51168
|
+
});
|
|
51169
|
+
return { threw: false, value: await Promise.race([Promise.resolve(value), timeout]) };
|
|
51170
|
+
} catch (error2) {
|
|
51171
|
+
if (error2 instanceof TestRunError) return error2;
|
|
51172
|
+
return { threw: true, error: error2 };
|
|
51173
|
+
} finally {
|
|
51174
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
51175
|
+
}
|
|
51176
|
+
}
|
|
51177
|
+
function record(results, label, quiet, check) {
|
|
51178
|
+
try {
|
|
51179
|
+
check();
|
|
51180
|
+
results.passed++;
|
|
51181
|
+
results.details.push({ name: label, status: "passed" });
|
|
51182
|
+
if (!quiet) console.log(` \x1B[32m+\x1B[0m ${label}`);
|
|
51183
|
+
return true;
|
|
51184
|
+
} catch (err) {
|
|
51185
|
+
if (err instanceof TestAssertionError) {
|
|
51186
|
+
results.failed++;
|
|
51187
|
+
results.details.push({ name: label, status: "failed", message: err.message });
|
|
51188
|
+
if (!quiet) console.log(` \x1B[31mx\x1B[0m ${label}: ${err.message}`);
|
|
51189
|
+
} else {
|
|
51190
|
+
results.errors++;
|
|
51191
|
+
const msg = err instanceof Error ? `${err.constructor.name}: ${err.message}` : String(err);
|
|
51192
|
+
results.details.push({ name: label, status: "error", message: msg });
|
|
51193
|
+
if (!quiet) console.log(` \x1B[33m!\x1B[0m ${label}: ${msg}`);
|
|
51194
|
+
}
|
|
51195
|
+
return false;
|
|
51196
|
+
}
|
|
51197
|
+
}
|
|
51198
|
+
function judgeRaises(assertion, outcome) {
|
|
51199
|
+
const ExcClass = assertion.exception;
|
|
51200
|
+
if (!outcome.threw) throw new TestAssertionError(`expected ${ExcClass.name} to be raised`);
|
|
51201
|
+
const err = outcome.error;
|
|
51202
|
+
if (err instanceof ExcClass) return;
|
|
51203
|
+
throw new TestAssertionError(
|
|
51204
|
+
`expected ${ExcClass.name}, got ${err instanceof Error ? err.constructor.name : typeof err}: ${err}`
|
|
51205
|
+
);
|
|
51206
|
+
}
|
|
51207
|
+
function judge(assertion, outcome) {
|
|
51208
|
+
const { type: type2 } = assertion;
|
|
51209
|
+
if (type2 === "raises") return judgeRaises(assertion, outcome);
|
|
51210
|
+
if (outcome.threw) throw outcome.error;
|
|
51211
|
+
const result = outcome.value;
|
|
51088
51212
|
switch (type2) {
|
|
51089
51213
|
case "equal": {
|
|
51090
|
-
const result = fn(...args);
|
|
51091
51214
|
const expected = assertion.expected;
|
|
51092
51215
|
if (result !== expected) {
|
|
51093
51216
|
throw new TestAssertionError(
|
|
51094
51217
|
`expected ${JSON.stringify(expected)}, got ${JSON.stringify(result)}`
|
|
51095
51218
|
);
|
|
51096
51219
|
}
|
|
51097
|
-
|
|
51098
|
-
}
|
|
51099
|
-
case "raises": {
|
|
51100
|
-
const ExcClass = assertion.exception;
|
|
51101
|
-
try {
|
|
51102
|
-
fn(...args);
|
|
51103
|
-
} catch (err) {
|
|
51104
|
-
if (err instanceof ExcClass) {
|
|
51105
|
-
return;
|
|
51106
|
-
}
|
|
51107
|
-
throw new TestAssertionError(
|
|
51108
|
-
`expected ${ExcClass.name}, got ${err instanceof Error ? err.constructor.name : typeof err}: ${err}`
|
|
51109
|
-
);
|
|
51110
|
-
}
|
|
51111
|
-
throw new TestAssertionError(`expected ${ExcClass.name} to be raised`);
|
|
51112
|
-
}
|
|
51113
|
-
case "true": {
|
|
51114
|
-
const result = fn(...args);
|
|
51115
|
-
if (!result) {
|
|
51116
|
-
throw new TestAssertionError(`expected truthy, got ${JSON.stringify(result)}`);
|
|
51117
|
-
}
|
|
51118
|
-
break;
|
|
51119
|
-
}
|
|
51120
|
-
case "false": {
|
|
51121
|
-
const result = fn(...args);
|
|
51122
|
-
if (result) {
|
|
51123
|
-
throw new TestAssertionError(`expected falsy, got ${JSON.stringify(result)}`);
|
|
51124
|
-
}
|
|
51125
|
-
break;
|
|
51220
|
+
return;
|
|
51126
51221
|
}
|
|
51222
|
+
case "true":
|
|
51223
|
+
if (!result) throw new TestAssertionError(`expected truthy, got ${JSON.stringify(result)}`);
|
|
51224
|
+
return;
|
|
51225
|
+
case "false":
|
|
51226
|
+
if (result) throw new TestAssertionError(`expected falsy, got ${JSON.stringify(result)}`);
|
|
51227
|
+
return;
|
|
51127
51228
|
default:
|
|
51128
51229
|
throw new Error(`unknown assertion type: ${type2}`);
|
|
51129
51230
|
}
|
|
@@ -51152,7 +51253,7 @@ function printSummary(results, quiet) {
|
|
|
51152
51253
|
`
|
|
51153
51254
|
);
|
|
51154
51255
|
}
|
|
51155
|
-
var registry2, TestAssertionError;
|
|
51256
|
+
var registry2, TestAssertionError, TestRunError, MAX_TIMER_MS;
|
|
51156
51257
|
var init_testing = __esm({
|
|
51157
51258
|
"../core/src/testing.ts"() {
|
|
51158
51259
|
"use strict";
|
|
@@ -51163,6 +51264,13 @@ var init_testing = __esm({
|
|
|
51163
51264
|
this.name = "TestAssertionError";
|
|
51164
51265
|
}
|
|
51165
51266
|
};
|
|
51267
|
+
TestRunError = class extends Error {
|
|
51268
|
+
constructor(message) {
|
|
51269
|
+
super(message);
|
|
51270
|
+
this.name = "TestRunError";
|
|
51271
|
+
}
|
|
51272
|
+
};
|
|
51273
|
+
MAX_TIMER_MS = 2147483647;
|
|
51166
51274
|
}
|
|
51167
51275
|
});
|
|
51168
51276
|
|
|
@@ -51978,6 +52086,7 @@ __export(src_exports3, {
|
|
|
51978
52086
|
resolveTemplate: () => resolveTemplate,
|
|
51979
52087
|
responseCache: () => responseCache,
|
|
51980
52088
|
runAll: () => runAll,
|
|
52089
|
+
runAllAsync: () => runAllAsync,
|
|
51981
52090
|
runRouteMiddlewares: () => runRouteMiddlewares,
|
|
51982
52091
|
runWithCspNonce: () => runWithCspNonce,
|
|
51983
52092
|
runtimeDir: () => runtimeDir,
|
|
@@ -52589,7 +52698,7 @@ function walkSource(dir) {
|
|
|
52589
52698
|
async function runInlineTests(cwd) {
|
|
52590
52699
|
const srcDir = resolve27(cwd, "src");
|
|
52591
52700
|
if (!existsSync33(srcDir)) return false;
|
|
52592
|
-
const {
|
|
52701
|
+
const { runAllAsync: runAllAsync2, reset: reset2 } = await Promise.resolve().then(() => (init_src3(), src_exports3));
|
|
52593
52702
|
reset2();
|
|
52594
52703
|
let discovered = 0;
|
|
52595
52704
|
for (const file of walkSource(srcDir)) {
|
|
@@ -52610,7 +52719,7 @@ async function runInlineTests(cwd) {
|
|
|
52610
52719
|
}
|
|
52611
52720
|
}
|
|
52612
52721
|
if (discovered === 0) return false;
|
|
52613
|
-
const results =
|
|
52722
|
+
const results = await runAllAsync2();
|
|
52614
52723
|
return results.failed + results.errors > 0;
|
|
52615
52724
|
}
|
|
52616
52725
|
async function runTests(testPath) {
|