tokenusage-cli 0.1.0 → 0.2.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.
- package/CHANGELOG.md +39 -19
- package/LICENSE +22 -22
- package/README.md +94 -94
- package/THIRD_PARTY_NOTICES.md +140 -140
- package/bin/tokenusage.js +69 -69
- package/package.json +59 -59
- package/src/cli.js +146 -134
- package/src/commands/device-login.js +205 -205
- package/src/commands/diagnostics.js +38 -38
- package/src/commands/doctor.js +110 -110
- package/src/commands/init.js +2484 -2436
- package/src/commands/pause.js +77 -0
- package/src/commands/sessions.js +29 -29
- package/src/commands/status.js +1758 -1747
- package/src/commands/sync.js +8048 -7934
- package/src/commands/uninstall.js +322 -312
- package/src/lib/account-usage-dedup.js +267 -267
- package/src/lib/antigravity-paths.js +48 -48
- package/src/lib/ark-agent-plan-limits.js +438 -438
- package/src/lib/ark-coding-plan-limits.js +537 -537
- package/src/lib/async-queue-reader.js +138 -138
- package/src/lib/atomic-json.js +27 -27
- package/src/lib/bearer-token.js +11 -11
- package/src/lib/categorizer-utils.js +232 -232
- package/src/lib/claude-categorizer.js +1343 -1343
- package/src/lib/claude-config.js +279 -279
- package/src/lib/claude-user-identity.js +56 -56
- package/src/lib/cli-ui.js +179 -179
- package/src/lib/cloud-account.js +541 -541
- package/src/lib/cloud-device-token.js +141 -141
- package/src/lib/cloud-sync-prefs.js +14 -14
- package/src/lib/cloud-usage-reset.js +115 -115
- package/src/lib/codex-config.js +595 -595
- package/src/lib/codex-context-breakdown.js +806 -806
- package/src/lib/codex-model-attribution.js +128 -128
- package/src/lib/codex-rollout-parser.js +1471 -1471
- package/src/lib/codex-service-tier.js +49 -49
- package/src/lib/codex-token-refresh.js +140 -140
- package/src/lib/codex-token-usage.js +195 -195
- package/src/lib/codex-usage-record.js +195 -195
- package/src/lib/collection-pause.js +77 -0
- package/src/lib/command-runner.js +313 -313
- package/src/lib/commandcode-limits.js +317 -317
- package/src/lib/context-health.js +124 -124
- package/src/lib/cursor-config.js +605 -605
- package/src/lib/cursor-store.js +1918 -1918
- package/src/lib/debug-flags.js +7 -7
- package/src/lib/devin-limits.js +249 -249
- package/src/lib/devin-usage.js +212 -212
- package/src/lib/diagnostics.js +383 -383
- package/src/lib/doctor.js +385 -385
- package/src/lib/dumate.js +95 -95
- package/src/lib/fs.js +455 -455
- package/src/lib/function-url.js +14 -14
- package/src/lib/gemini-config.js +291 -291
- package/src/lib/git-outcomes.js +243 -243
- package/src/lib/grok-context-breakdown.js +890 -890
- package/src/lib/grok-hook.js +360 -360
- package/src/lib/grok-limits.js +865 -865
- package/src/lib/grok-usage.js +98 -98
- package/src/lib/heatmap-compact.js +114 -114
- package/src/lib/ingest-sanitize.js +41 -41
- package/src/lib/init-flow.js +42 -42
- package/src/lib/install-resolver.js +170 -170
- package/src/lib/jsonl-lines.js +134 -134
- package/src/lib/kimi-model-repair.js +173 -173
- package/src/lib/kimi-profile.js +61 -61
- package/src/lib/kimi-session.js +216 -216
- package/src/lib/local-api.js +3588 -3588
- package/src/lib/machine-id.js +238 -238
- package/src/lib/multi-install-parser.js +113 -113
- package/src/lib/notify-command.js +38 -38
- package/src/lib/omp-hook.js +589 -589
- package/src/lib/openclaw-cli.js +104 -104
- package/src/lib/openclaw-hook.js +375 -375
- package/src/lib/openclaw-session-plugin.js +560 -560
- package/src/lib/opencode-config.js +121 -121
- package/src/lib/opencode-go-limits.js +807 -807
- package/src/lib/outcomes-engine.js +253 -253
- package/src/lib/passive-mode.js +219 -219
- package/src/lib/pet-packages.js +722 -722
- package/src/lib/pricing/curated-overrides.json +822 -822
- package/src/lib/pricing/index.js +379 -379
- package/src/lib/pricing/litellm-fetcher.js +172 -172
- package/src/lib/pricing/matcher.js +456 -456
- package/src/lib/pricing/seed-snapshot.json +1 -1
- package/src/lib/progress.js +76 -76
- package/src/lib/project-usage-purge.js +117 -117
- package/src/lib/prompt.js +24 -24
- package/src/lib/provider-status.js +104 -104
- package/src/lib/proxy-env.js +489 -489
- package/src/lib/proxy-settings.js +163 -163
- package/src/lib/qoder-cn-cli-limits.js +119 -119
- package/src/lib/qoder-limits.js +880 -880
- package/src/lib/quiet-warnings.js +26 -26
- package/src/lib/rollout.js +26005 -25966
- package/src/lib/runtime-config.js +9 -4
- package/src/lib/scan-roots.js +277 -277
- package/src/lib/scheduled-task.js +145 -0
- package/src/lib/sentry.js +231 -231
- package/src/lib/session-analytics.js +2972 -2972
- package/src/lib/session-performance.js +237 -237
- package/src/lib/session-upload.js +379 -379
- package/src/lib/skill-usage.js +267 -267
- package/src/lib/skills-manager.js +1591 -1591
- package/src/lib/source-metadata.js +48 -48
- package/src/lib/sqlite-reader.js +215 -215
- package/src/lib/star-cta.js +73 -73
- package/src/lib/subscription-manager.js +293 -293
- package/src/lib/subscriptions.js +508 -508
- package/src/lib/sync-report.js +138 -0
- package/src/lib/telemetry.js +193 -193
- package/src/lib/tracker-paths.js +16 -16
- package/src/lib/trae-cn-config.js +548 -548
- package/src/lib/trae-db.js +127 -127
- package/src/lib/trae-snapshot.js +230 -230
- package/src/lib/trae-sqlite.js +143 -143
- package/src/lib/trae-usage.js +121 -121
- package/src/lib/upload-queue.js +134 -134
- package/src/lib/upload-throttle.js +171 -171
- package/src/lib/usage-limits.js +4552 -4552
- package/src/lib/wrapped-aggregator.js +236 -236
- package/src/lib/wsl-probe.js +281 -281
- package/src/lib/zcode-limits.js +1172 -1172
- package/src/lib/zcode-reset-credits.js +66 -66
- package/test/audit-fixes.test.js +200 -0
- package/test/cli-smoke.test.js +53 -53
- package/test/collection-controls.test.js +181 -0
- package/test/ingest-sanitize.test.js +162 -162
- package/test/quiet-warnings.test.js +53 -53
- package/test/session-upload.test.js +427 -427
|
@@ -1,162 +1,162 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
// Regression tests for the upload-path poison-row defense. The ingest edge
|
|
4
|
-
// validates every row before writing and rejects the WHOLE batch on the
|
|
5
|
-
// first contract-invalid row; the queue offset only advances on success, so
|
|
6
|
-
// one bad row would otherwise stall every source behind it forever. These
|
|
7
|
-
// tests pin: sanitizeBucketForUpload coerces buckets into the contract shape
|
|
8
|
-
// (docs/cli-contract.md §2.4), readQueueBatch drops rows it cannot repair,
|
|
9
|
-
// and a dropped row never occupies its dedup key.
|
|
10
|
-
|
|
11
|
-
const assert = require("node:assert/strict");
|
|
12
|
-
const fs = require("node:fs");
|
|
13
|
-
const os = require("node:os");
|
|
14
|
-
const path = require("node:path");
|
|
15
|
-
const { test, beforeEach, afterEach } = require("node:test");
|
|
16
|
-
|
|
17
|
-
const { sanitizeBucketForUpload } = require("../src/lib/ingest-sanitize");
|
|
18
|
-
const { readQueueBatch } = require("../src/commands/sync");
|
|
19
|
-
const { validSessionId } = require("../src/lib/session-upload");
|
|
20
|
-
|
|
21
|
-
let tmpDir;
|
|
22
|
-
|
|
23
|
-
beforeEach(() => {
|
|
24
|
-
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "tokenusage-ingest-sanitize-"));
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
afterEach(() => {
|
|
28
|
-
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
function writeQueue(lines) {
|
|
32
|
-
const queuePath = path.join(tmpDir, "queue.jsonl");
|
|
33
|
-
fs.writeFileSync(queuePath, lines.map((line) => JSON.stringify(line)).join("\n") + "\n");
|
|
34
|
-
return queuePath;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function validBucket(overrides = {}) {
|
|
38
|
-
return {
|
|
39
|
-
hour_start: "2026-10-26T01:00:00.000Z",
|
|
40
|
-
source: "claude",
|
|
41
|
-
model: "claude-x",
|
|
42
|
-
input_tokens: 10,
|
|
43
|
-
cached_input_tokens: 2,
|
|
44
|
-
cache_creation_input_tokens: 3,
|
|
45
|
-
output_tokens: 4,
|
|
46
|
-
reasoning_output_tokens: 1,
|
|
47
|
-
total_tokens: 19,
|
|
48
|
-
billable_total_tokens: 19,
|
|
49
|
-
conversation_count: 1,
|
|
50
|
-
total_cost_usd: 0.5,
|
|
51
|
-
...overrides,
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function validState(overrides = {}) {
|
|
56
|
-
return {
|
|
57
|
-
kind: "account_session_state",
|
|
58
|
-
source: "trae-cn",
|
|
59
|
-
session_id: "session-1",
|
|
60
|
-
model: "kimi-k2",
|
|
61
|
-
bucket_start: "2026-10-26T01:00:00.000Z",
|
|
62
|
-
input_tokens: 100,
|
|
63
|
-
output_tokens: 20,
|
|
64
|
-
cached_input_tokens: 30,
|
|
65
|
-
cache_creation_input_tokens: 10,
|
|
66
|
-
reasoning_output_tokens: 5,
|
|
67
|
-
total_tokens: 160,
|
|
68
|
-
snapshot_verified_at: "2026-10-26T02:00:00.000Z",
|
|
69
|
-
...overrides,
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
test("sanitizeBucketForUpload floors fractional counters and clamps negatives to 0", () => {
|
|
74
|
-
const out = sanitizeBucketForUpload(validBucket({
|
|
75
|
-
input_tokens: 10.75,
|
|
76
|
-
output_tokens: -4,
|
|
77
|
-
reasoning_output_tokens: Number.NaN,
|
|
78
|
-
total_cost_usd: -0.5,
|
|
79
|
-
}));
|
|
80
|
-
assert.equal(out.input_tokens, 10);
|
|
81
|
-
assert.equal(out.output_tokens, 0);
|
|
82
|
-
assert.equal(out.reasoning_output_tokens, 0);
|
|
83
|
-
assert.equal(out.total_cost_usd, 0);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
test("sanitizeBucketForUpload keeps a valid row verbatim, incl. explicit billable null", () => {
|
|
87
|
-
const row = validBucket({ billable_total_tokens: null });
|
|
88
|
-
assert.deepEqual(sanitizeBucketForUpload(row), row);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
test("sanitizeBucketForUpload drops rows without a parseable hour_start and non-objects", () => {
|
|
92
|
-
assert.equal(sanitizeBucketForUpload(validBucket({ hour_start: "garbage" })), null);
|
|
93
|
-
assert.equal(sanitizeBucketForUpload(validBucket({ hour_start: 17 })), null);
|
|
94
|
-
assert.equal(sanitizeBucketForUpload(null), null);
|
|
95
|
-
assert.equal(sanitizeBucketForUpload([validBucket()]), null);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
test("sanitizeBucketForUpload fills missing counters with 0 and cost with 0", () => {
|
|
99
|
-
const out = sanitizeBucketForUpload({
|
|
100
|
-
hour_start: "2026-10-26T01:00:00.000Z",
|
|
101
|
-
source: "x",
|
|
102
|
-
model: "m",
|
|
103
|
-
total_tokens: 5,
|
|
104
|
-
});
|
|
105
|
-
assert.equal(out.input_tokens, 0);
|
|
106
|
-
assert.equal(out.total_tokens, 5);
|
|
107
|
-
assert.equal(out.billable_total_tokens, null);
|
|
108
|
-
assert.equal(out.total_cost_usd, 0);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
test("readQueueBatch drops poison account_session_states and keeps the valid one", async () => {
|
|
112
|
-
const tooLong = validState({ session_id: "s".repeat(300) });
|
|
113
|
-
const brokenSum = validState({ session_id: "broken", total_tokens: 99 });
|
|
114
|
-
const good = validState({ session_id: "good" });
|
|
115
|
-
const queuePath = writeQueue([validBucket(), tooLong, brokenSum, good]);
|
|
116
|
-
const result = await readQueueBatch(queuePath, 0, 500);
|
|
117
|
-
assert.equal(result.buckets.length, 1);
|
|
118
|
-
assert.equal(result.sessionStates.length, 1);
|
|
119
|
-
assert.equal(result.sessionStates[0].session_id, "good");
|
|
120
|
-
assert.equal(result.nextOffset, fs.statSync(queuePath).size);
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
test("a poison row does not occupy its dedup key — a later valid snapshot is admitted", async () => {
|
|
124
|
-
const poison = validState({ total_tokens: 99 });
|
|
125
|
-
const good = validState({ total_tokens: 160 });
|
|
126
|
-
const queuePath = writeQueue([poison, good]);
|
|
127
|
-
const result = await readQueueBatch(queuePath, 0, 500);
|
|
128
|
-
assert.equal(result.sessionStates.length, 1);
|
|
129
|
-
assert.equal(result.sessionStates[0].total_tokens, 160);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
test("readQueueBatch drops hourly rows the edge would 400 and floors fractional counters", async () => {
|
|
133
|
-
const badHour = validBucket({ hour_start: "garbage" });
|
|
134
|
-
const fractional = validBucket({ hour_start: "2026-10-26T02:00:00.000Z", total_tokens: 19.5 });
|
|
135
|
-
const good = validBucket({ hour_start: "2026-10-26T03:00:00.000Z" });
|
|
136
|
-
const queuePath = writeQueue([badHour, fractional, good]);
|
|
137
|
-
const result = await readQueueBatch(queuePath, 0, 500);
|
|
138
|
-
assert.equal(result.buckets.length, 2);
|
|
139
|
-
assert.equal(result.buckets.find((b) => b.hour_start === "2026-10-26T02:00:00.000Z").total_tokens, 19);
|
|
140
|
-
assert.equal(result.buckets.find((b) => b.hour_start === "2026-10-26T03:00:00.000Z").total_tokens, 19);
|
|
141
|
-
assert.equal(result.nextOffset, fs.statSync(queuePath).size);
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
test("a segment of only-poison rows reads empty with the offset advanced", async () => {
|
|
145
|
-
const queuePath = writeQueue([
|
|
146
|
-
validBucket({ hour_start: "garbage" }),
|
|
147
|
-
validState({ total_tokens: 99 }),
|
|
148
|
-
]);
|
|
149
|
-
const result = await readQueueBatch(queuePath, 0, 500);
|
|
150
|
-
assert.deepEqual(result.buckets, []);
|
|
151
|
-
assert.deepEqual(result.sessionStates, []);
|
|
152
|
-
assert.equal(result.nextOffset, fs.statSync(queuePath).size);
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
test("validSessionId rejects the full Unicode Cc range (incl. C1), matching the server", () => {
|
|
156
|
-
assert.equal(validSessionId("ok-id"), true);
|
|
157
|
-
assert.equal(validSessionId("bad\u0085-id"), false); // NEL, C1
|
|
158
|
-
assert.equal(validSessionId("bad\u001f-id"), false); // C0
|
|
159
|
-
assert.equal(validSessionId("bad\u007f-id"), false); // DEL
|
|
160
|
-
assert.equal(validSessionId("with/slash"), false);
|
|
161
|
-
assert.equal(validSessionId("with\\slash"), false);
|
|
162
|
-
});
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// Regression tests for the upload-path poison-row defense. The ingest edge
|
|
4
|
+
// validates every row before writing and rejects the WHOLE batch on the
|
|
5
|
+
// first contract-invalid row; the queue offset only advances on success, so
|
|
6
|
+
// one bad row would otherwise stall every source behind it forever. These
|
|
7
|
+
// tests pin: sanitizeBucketForUpload coerces buckets into the contract shape
|
|
8
|
+
// (docs/cli-contract.md §2.4), readQueueBatch drops rows it cannot repair,
|
|
9
|
+
// and a dropped row never occupies its dedup key.
|
|
10
|
+
|
|
11
|
+
const assert = require("node:assert/strict");
|
|
12
|
+
const fs = require("node:fs");
|
|
13
|
+
const os = require("node:os");
|
|
14
|
+
const path = require("node:path");
|
|
15
|
+
const { test, beforeEach, afterEach } = require("node:test");
|
|
16
|
+
|
|
17
|
+
const { sanitizeBucketForUpload } = require("../src/lib/ingest-sanitize");
|
|
18
|
+
const { readQueueBatch } = require("../src/commands/sync");
|
|
19
|
+
const { validSessionId } = require("../src/lib/session-upload");
|
|
20
|
+
|
|
21
|
+
let tmpDir;
|
|
22
|
+
|
|
23
|
+
beforeEach(() => {
|
|
24
|
+
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "tokenusage-ingest-sanitize-"));
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
afterEach(() => {
|
|
28
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
function writeQueue(lines) {
|
|
32
|
+
const queuePath = path.join(tmpDir, "queue.jsonl");
|
|
33
|
+
fs.writeFileSync(queuePath, lines.map((line) => JSON.stringify(line)).join("\n") + "\n");
|
|
34
|
+
return queuePath;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function validBucket(overrides = {}) {
|
|
38
|
+
return {
|
|
39
|
+
hour_start: "2026-10-26T01:00:00.000Z",
|
|
40
|
+
source: "claude",
|
|
41
|
+
model: "claude-x",
|
|
42
|
+
input_tokens: 10,
|
|
43
|
+
cached_input_tokens: 2,
|
|
44
|
+
cache_creation_input_tokens: 3,
|
|
45
|
+
output_tokens: 4,
|
|
46
|
+
reasoning_output_tokens: 1,
|
|
47
|
+
total_tokens: 19,
|
|
48
|
+
billable_total_tokens: 19,
|
|
49
|
+
conversation_count: 1,
|
|
50
|
+
total_cost_usd: 0.5,
|
|
51
|
+
...overrides,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function validState(overrides = {}) {
|
|
56
|
+
return {
|
|
57
|
+
kind: "account_session_state",
|
|
58
|
+
source: "trae-cn",
|
|
59
|
+
session_id: "session-1",
|
|
60
|
+
model: "kimi-k2",
|
|
61
|
+
bucket_start: "2026-10-26T01:00:00.000Z",
|
|
62
|
+
input_tokens: 100,
|
|
63
|
+
output_tokens: 20,
|
|
64
|
+
cached_input_tokens: 30,
|
|
65
|
+
cache_creation_input_tokens: 10,
|
|
66
|
+
reasoning_output_tokens: 5,
|
|
67
|
+
total_tokens: 160,
|
|
68
|
+
snapshot_verified_at: "2026-10-26T02:00:00.000Z",
|
|
69
|
+
...overrides,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
test("sanitizeBucketForUpload floors fractional counters and clamps negatives to 0", () => {
|
|
74
|
+
const out = sanitizeBucketForUpload(validBucket({
|
|
75
|
+
input_tokens: 10.75,
|
|
76
|
+
output_tokens: -4,
|
|
77
|
+
reasoning_output_tokens: Number.NaN,
|
|
78
|
+
total_cost_usd: -0.5,
|
|
79
|
+
}));
|
|
80
|
+
assert.equal(out.input_tokens, 10);
|
|
81
|
+
assert.equal(out.output_tokens, 0);
|
|
82
|
+
assert.equal(out.reasoning_output_tokens, 0);
|
|
83
|
+
assert.equal(out.total_cost_usd, 0);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test("sanitizeBucketForUpload keeps a valid row verbatim, incl. explicit billable null", () => {
|
|
87
|
+
const row = validBucket({ billable_total_tokens: null });
|
|
88
|
+
assert.deepEqual(sanitizeBucketForUpload(row), row);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test("sanitizeBucketForUpload drops rows without a parseable hour_start and non-objects", () => {
|
|
92
|
+
assert.equal(sanitizeBucketForUpload(validBucket({ hour_start: "garbage" })), null);
|
|
93
|
+
assert.equal(sanitizeBucketForUpload(validBucket({ hour_start: 17 })), null);
|
|
94
|
+
assert.equal(sanitizeBucketForUpload(null), null);
|
|
95
|
+
assert.equal(sanitizeBucketForUpload([validBucket()]), null);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test("sanitizeBucketForUpload fills missing counters with 0 and cost with 0", () => {
|
|
99
|
+
const out = sanitizeBucketForUpload({
|
|
100
|
+
hour_start: "2026-10-26T01:00:00.000Z",
|
|
101
|
+
source: "x",
|
|
102
|
+
model: "m",
|
|
103
|
+
total_tokens: 5,
|
|
104
|
+
});
|
|
105
|
+
assert.equal(out.input_tokens, 0);
|
|
106
|
+
assert.equal(out.total_tokens, 5);
|
|
107
|
+
assert.equal(out.billable_total_tokens, null);
|
|
108
|
+
assert.equal(out.total_cost_usd, 0);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test("readQueueBatch drops poison account_session_states and keeps the valid one", async () => {
|
|
112
|
+
const tooLong = validState({ session_id: "s".repeat(300) });
|
|
113
|
+
const brokenSum = validState({ session_id: "broken", total_tokens: 99 });
|
|
114
|
+
const good = validState({ session_id: "good" });
|
|
115
|
+
const queuePath = writeQueue([validBucket(), tooLong, brokenSum, good]);
|
|
116
|
+
const result = await readQueueBatch(queuePath, 0, 500);
|
|
117
|
+
assert.equal(result.buckets.length, 1);
|
|
118
|
+
assert.equal(result.sessionStates.length, 1);
|
|
119
|
+
assert.equal(result.sessionStates[0].session_id, "good");
|
|
120
|
+
assert.equal(result.nextOffset, fs.statSync(queuePath).size);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test("a poison row does not occupy its dedup key — a later valid snapshot is admitted", async () => {
|
|
124
|
+
const poison = validState({ total_tokens: 99 });
|
|
125
|
+
const good = validState({ total_tokens: 160 });
|
|
126
|
+
const queuePath = writeQueue([poison, good]);
|
|
127
|
+
const result = await readQueueBatch(queuePath, 0, 500);
|
|
128
|
+
assert.equal(result.sessionStates.length, 1);
|
|
129
|
+
assert.equal(result.sessionStates[0].total_tokens, 160);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test("readQueueBatch drops hourly rows the edge would 400 and floors fractional counters", async () => {
|
|
133
|
+
const badHour = validBucket({ hour_start: "garbage" });
|
|
134
|
+
const fractional = validBucket({ hour_start: "2026-10-26T02:00:00.000Z", total_tokens: 19.5 });
|
|
135
|
+
const good = validBucket({ hour_start: "2026-10-26T03:00:00.000Z" });
|
|
136
|
+
const queuePath = writeQueue([badHour, fractional, good]);
|
|
137
|
+
const result = await readQueueBatch(queuePath, 0, 500);
|
|
138
|
+
assert.equal(result.buckets.length, 2);
|
|
139
|
+
assert.equal(result.buckets.find((b) => b.hour_start === "2026-10-26T02:00:00.000Z").total_tokens, 19);
|
|
140
|
+
assert.equal(result.buckets.find((b) => b.hour_start === "2026-10-26T03:00:00.000Z").total_tokens, 19);
|
|
141
|
+
assert.equal(result.nextOffset, fs.statSync(queuePath).size);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test("a segment of only-poison rows reads empty with the offset advanced", async () => {
|
|
145
|
+
const queuePath = writeQueue([
|
|
146
|
+
validBucket({ hour_start: "garbage" }),
|
|
147
|
+
validState({ total_tokens: 99 }),
|
|
148
|
+
]);
|
|
149
|
+
const result = await readQueueBatch(queuePath, 0, 500);
|
|
150
|
+
assert.deepEqual(result.buckets, []);
|
|
151
|
+
assert.deepEqual(result.sessionStates, []);
|
|
152
|
+
assert.equal(result.nextOffset, fs.statSync(queuePath).size);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
test("validSessionId rejects the full Unicode Cc range (incl. C1), matching the server", () => {
|
|
156
|
+
assert.equal(validSessionId("ok-id"), true);
|
|
157
|
+
assert.equal(validSessionId("bad\u0085-id"), false); // NEL, C1
|
|
158
|
+
assert.equal(validSessionId("bad\u001f-id"), false); // C0
|
|
159
|
+
assert.equal(validSessionId("bad\u007f-id"), false); // DEL
|
|
160
|
+
assert.equal(validSessionId("with/slash"), false);
|
|
161
|
+
assert.equal(validSessionId("with\\slash"), false);
|
|
162
|
+
});
|
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
// The bin entry installs the node:sqlite ExperimentalWarning filter before
|
|
4
|
-
// any require can pull node:sqlite in; redirected scheduled-task logs grow
|
|
5
|
-
// by one identical warning per cycle otherwise. Pin the filter's contract:
|
|
6
|
-
// drop only that warning, pass everything else through, stay idempotent.
|
|
7
|
-
|
|
8
|
-
const assert = require("node:assert/strict");
|
|
9
|
-
const { test } = require("node:test");
|
|
10
|
-
|
|
11
|
-
const { suppressSqliteExperimentalWarning } = require("../src/lib/quiet-warnings");
|
|
12
|
-
|
|
13
|
-
test("filters the node:sqlite experimental warning and passes everything else through", () => {
|
|
14
|
-
const seen = [];
|
|
15
|
-
const saved = process.emitWarning;
|
|
16
|
-
process.emitWarning = (warning, ...args) => {
|
|
17
|
-
seen.push(warning);
|
|
18
|
-
};
|
|
19
|
-
try {
|
|
20
|
-
suppressSqliteExperimentalWarning();
|
|
21
|
-
|
|
22
|
-
process.emitWarning(
|
|
23
|
-
"SQLite is an experimental feature and might change at any time",
|
|
24
|
-
{ type: "ExperimentalWarning", code: "ExperimentalWarnings" },
|
|
25
|
-
);
|
|
26
|
-
assert.equal(seen.length, 0);
|
|
27
|
-
|
|
28
|
-
const other = new Error("some other experimental feature");
|
|
29
|
-
other.name = "ExperimentalWarning";
|
|
30
|
-
process.emitWarning(other);
|
|
31
|
-
assert.equal(seen.length, 1);
|
|
32
|
-
assert.equal(seen[0], other);
|
|
33
|
-
|
|
34
|
-
process.emitWarning("plain string warning");
|
|
35
|
-
assert.equal(seen.length, 2);
|
|
36
|
-
assert.equal(seen[1], "plain string warning");
|
|
37
|
-
} finally {
|
|
38
|
-
process.emitWarning = saved;
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
test("suppressSqliteExperimentalWarning is idempotent (does not stack filters)", () => {
|
|
43
|
-
const saved = process.emitWarning;
|
|
44
|
-
process.emitWarning = () => {};
|
|
45
|
-
try {
|
|
46
|
-
suppressSqliteExperimentalWarning();
|
|
47
|
-
const onceFiltered = process.emitWarning;
|
|
48
|
-
suppressSqliteExperimentalWarning();
|
|
49
|
-
assert.equal(process.emitWarning, onceFiltered);
|
|
50
|
-
} finally {
|
|
51
|
-
process.emitWarning = saved;
|
|
52
|
-
}
|
|
53
|
-
});
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// The bin entry installs the node:sqlite ExperimentalWarning filter before
|
|
4
|
+
// any require can pull node:sqlite in; redirected scheduled-task logs grow
|
|
5
|
+
// by one identical warning per cycle otherwise. Pin the filter's contract:
|
|
6
|
+
// drop only that warning, pass everything else through, stay idempotent.
|
|
7
|
+
|
|
8
|
+
const assert = require("node:assert/strict");
|
|
9
|
+
const { test } = require("node:test");
|
|
10
|
+
|
|
11
|
+
const { suppressSqliteExperimentalWarning } = require("../src/lib/quiet-warnings");
|
|
12
|
+
|
|
13
|
+
test("filters the node:sqlite experimental warning and passes everything else through", () => {
|
|
14
|
+
const seen = [];
|
|
15
|
+
const saved = process.emitWarning;
|
|
16
|
+
process.emitWarning = (warning, ...args) => {
|
|
17
|
+
seen.push(warning);
|
|
18
|
+
};
|
|
19
|
+
try {
|
|
20
|
+
suppressSqliteExperimentalWarning();
|
|
21
|
+
|
|
22
|
+
process.emitWarning(
|
|
23
|
+
"SQLite is an experimental feature and might change at any time",
|
|
24
|
+
{ type: "ExperimentalWarning", code: "ExperimentalWarnings" },
|
|
25
|
+
);
|
|
26
|
+
assert.equal(seen.length, 0);
|
|
27
|
+
|
|
28
|
+
const other = new Error("some other experimental feature");
|
|
29
|
+
other.name = "ExperimentalWarning";
|
|
30
|
+
process.emitWarning(other);
|
|
31
|
+
assert.equal(seen.length, 1);
|
|
32
|
+
assert.equal(seen[0], other);
|
|
33
|
+
|
|
34
|
+
process.emitWarning("plain string warning");
|
|
35
|
+
assert.equal(seen.length, 2);
|
|
36
|
+
assert.equal(seen[1], "plain string warning");
|
|
37
|
+
} finally {
|
|
38
|
+
process.emitWarning = saved;
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("suppressSqliteExperimentalWarning is idempotent (does not stack filters)", () => {
|
|
43
|
+
const saved = process.emitWarning;
|
|
44
|
+
process.emitWarning = () => {};
|
|
45
|
+
try {
|
|
46
|
+
suppressSqliteExperimentalWarning();
|
|
47
|
+
const onceFiltered = process.emitWarning;
|
|
48
|
+
suppressSqliteExperimentalWarning();
|
|
49
|
+
assert.equal(process.emitWarning, onceFiltered);
|
|
50
|
+
} finally {
|
|
51
|
+
process.emitWarning = saved;
|
|
52
|
+
}
|
|
53
|
+
});
|