Skip to content

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

g1t.sh
56 linesCodeBlameRaw
1import assert from "node:assert/strict";
2import { test } from "node:test";
3
4import {
5 DEFAULT_FREE_TELEMETRY_BYTES_PER_MONTH,
6 GB,
7 TELEMETRY_MICROS_PER_GB,
8 capOf,
9 dailyCap,
10 freeMonthlyBytes,
11 overCap,
12 overCapMessage,
13 sizeOf,
14 telemetryCost,
15 telemetryDetail,
16} from "./quota.ts";
17
18test("a free workspace sends a thirtieth of 1 GB a day", () => {
19 assert.equal(freeMonthlyBytes(undefined), DEFAULT_FREE_TELEMETRY_BYTES_PER_MONTH);
20 assert.equal(freeMonthlyBytes(" "), DEFAULT_FREE_TELEMETRY_BYTES_PER_MONTH);
21 assert.equal(freeMonthlyBytes("3000"), 3000);
22 assert.equal(freeMonthlyBytes("0"), 0);
23 assert.equal(dailyCap(3000), 100);
24 assert.equal(dailyCap(0), null);
25 assert.equal(dailyCap(DEFAULT_FREE_TELEMETRY_BYTES_PER_MONTH), 35_791_395);
26});
27
28test("past the day's share is over, and no cap never is", () => {
29 assert.equal(overCap(90, 10, 100), false);
30 assert.equal(overCap(90, 11, 100), true);
31 assert.equal(overCap(1e12, 1e12, null), false);
32 assert.match(overCapMessage(35_791_395), /its 34 MB for today across its projects/);
33 // A held workspace's projects take nothing.
34 assert.equal(overCap(0, 1, 0), true);
35 assert.match(overCapMessage(0), /put a hold on/);
36});
37
38test("a held workspace takes nothing, a free one its day's share, the plan no cap; unknown is free", () => {
39 assert.equal(capOf("held", 100), 0);
40 assert.equal(capOf("free", 100), 100);
41 assert.equal(capOf("paid", 100), null);
42 assert.equal(capOf(null, 100), 100);
43});
44
45test("what is sent past the free amount costs by the GB; up to it, nothing", () => {
46 assert.equal(telemetryCost(DEFAULT_FREE_TELEMETRY_BYTES_PER_MONTH, DEFAULT_FREE_TELEMETRY_BYTES_PER_MONTH, TELEMETRY_MICROS_PER_GB), 0);
47 assert.equal(telemetryCost(10, 100, TELEMETRY_MICROS_PER_GB), 0);
48 assert.equal(telemetryCost(GB + 100, 100, 8_500_000), 8_500_000);
49 assert.equal(telemetryCost(GB / 2, 0, 8_500_000), 4_250_000);
50 assert.equal(telemetryDetail(2_400_000_000, DEFAULT_FREE_TELEMETRY_BYTES_PER_MONTH), "2.40 GB sent, 1.07 GB free");
51});
52
53test("a row counts as what is kept of it", () => {
54 assert.equal(sizeOf({ body: "hello" }), '{"body":"hello"}'.length);
55 assert.equal(sizeOf(undefined), 0);
56});