limits: a daily token quota for the account the stack uses, and bus schema 3h to 3i (row 126, #1620)
The business file can name the account claude-code launches use,
`launch.account` = {name, credential}. `name` is an identifier and
`credential` names one login set's environment variables, never a value.
`launch.limits.tokens.daily.<account>` = {limit, since, reset, timeZone}
sets a daily quota for that account. A daily key that isn't the account's
name refuses the business read.
The new plug-in limit-check/daily-quota (interface 2, pure) starts a day at
the first instant at or after `reset` on that local date in `timeZone`. Across
DST that makes a 23- or 25-hour day, and a reset in a skipped hour starts at
the gap's end. It counts the account's known records of all four kinds since
the later of the day start and `since`, and counts unknown turns apart.
The launcher refuses account-credential-missing, account-credential-ambiguous
and account-is-credential (an account name equal to a session credential's
value). Messages name variables, never values. The account rides mayLaunch,
bindLaunch, the usage records, mustStop and the launch record. A pi launch
has no account, records NULL, and no daily quota covers it. `mosaic limits`
and the Console's Settings show one fixed line when a daily row shows:
"Daily quotas count only this stack's own use of the account, not its use
anywhere else."
Bus schema 3h to 3i: 3h reserved usage_records.account as
CHECK (account IS NULL). The new step 3h-3i.sql rebuilds the table in one
transaction, keeping every row's seq and the sqlite_sequence value, and
recreates the three append-only triggers. All of sqlite_master equals 3h's
apart from the account line. A 3h engine refuses a 3i store.
packages/bus/tests/account-migration.test.mjs covers all three, with a
step that fails partway and leaves 3h intact. 3i goes live only through
`stack-release.sh activate ... --migrate` with Jason present (P19 371); the
activate path takes the pre-migrate backup, and the way back is restoring
it (agents/dewey/work/queue-126/MIGRATION.md).
Mos's go mos-0835, six conditions: (1) one transaction, account-migration
test 2 and mutant D29; (2) sqlite_master against 3h, test 1 and mutant D28;
(3) account is never a credential, the launcher's account-is-credential
refusal (launch-account.test.mjs) and the business name pattern
(token-limit-settings.test.mjs); (4) MIGRATION.md, accepted by Mos in
mos-0837; (5) the packet's DESIGN.md "no schema change" line corrected;
(6) the public/ digest below.
The public/ change in bus.js (the daily line under the token-limit table)
carries Mos's decision 123 go mos-0833 on the +/- digest 03e6d9da...ba78,
unchanged at landing.
Owner Dewey, brief docs/plans/2026-10-14_prd-1.2-build.md, "Daily quota for
the credential the stack uses today". Review round 2 rebases the round 4
build onto 1df04f52f (row 167). Reviewer: Filbert approve 29068 on round 1
(manifest d18314f7...8e65); Filbert approve 29080 on
round 2 (manifest f332db76...6fa6).
Seat run on round 2: touched 158/0, singles 1388/0 with 1 esbuild skip,
test-land-work.sh 86/0, 30/30 mutants killed.
Sage gate on 54319f552: GATE_PASSED, 2474+422/0, all 15 packages, the queue
suite and 10 script selftests.
Nothing live.
This commit is contained in:
1 parent
54319f5521
commit
ca15d73e9f
39 files changed
+1334
-54
No files matched your search
@@ -341,6 +341,9 @@ is `{"ok": true, "result": {run, instance, harness, model}}` or
|
||||
| the instance resolves to `pi` or `claude-code` and a model | `unsupported-harness` |
|
||||
| its role has a contract file | `no-role-contract` |
|
||||
| a Claude Code session has `CLAUDE_CODE_OAUTH_TOKEN`, `ANTHROPIC_API_KEY`, or `ANTHROPIC_AUTH_TOKEN` with `ANTHROPIC_BASE_URL` to log in with | `no-session-credential` |
|
||||
| with `launch.account` set, its name is not the value of any of those variables the bus host sets, since usage records keep the name | `account-is-credential` |
|
||||
| with `launch.account` set, a Claude Code session's account names one of those login sets and the bus host holds all of it | `account-credential-missing` |
|
||||
| with `launch.account` set, the bus host sets no other of those variables, `ANTHROPIC_BASE_URL` included | `account-credential-ambiguous` |
|
||||
| bwrap runs here | `sandbox-unavailable` |
|
||||
| its model selects an exact entry in `launch.models` | `unsupported-harness` |
|
||||
| total, provider and exact provider/model limits have room; the PM counts too | `capacity-full` |
|
||||
@@ -348,6 +351,13 @@ is `{"ok": true, "result": {run, instance, harness, model}}` or
|
||||
| the workspace has a clone of each project, or the host can make one | `checkout-failed`, with the project id |
|
||||
| the bundle builds and the runner starts | `launch-failed` |
|
||||
|
||||
Row 126 (#1620): only a Claude Code launch spends `launch.account.name`. It
|
||||
goes to the `mayLaunch` limit checks, to the bus with the run, onto the
|
||||
run's usage records, and onto the `launch` record as `account`. A pi launch
|
||||
has account null: its records say null, no daily quota covers it, and the
|
||||
two account checks above are skipped. Both account refusals name the
|
||||
variables, never a value.
|
||||
|
||||
Every refusal is an `action.refused` event (the broker's `refuse`, or its
|
||||
own refusal for the last broker check) and a line in the launch log. Then
|
||||
the launcher reads the instance's credential status from the broker
|
||||
|
||||
@@ -243,6 +243,20 @@ export function createLauncher({
|
||||
const names = SESSION_CREDENTIALS.map((set) => set.join(" with ")).join(", ");
|
||||
throw new Refusal("no-session-credential", `the bus host has none of ${names}; the bus unit's EnvironmentFile sets one when the bus starts`);
|
||||
}
|
||||
// Row 126 (#1620): only a claude-code launch spends the named account; a pi launch has none.
|
||||
// The bus environment must hold the named set and no other credential variable, so the session
|
||||
// can't log in some other way. Messages name variables, never values.
|
||||
const account = model.harness === "claude-code" ? b.launch.account?.name ?? null : null;
|
||||
if (account !== null) {
|
||||
// The usage records keep this name (bus schema 3i), so it must never be a credential's value.
|
||||
const holds = [...new Set(SESSION_CREDENTIALS.flat())].filter((k) => env[k] === account);
|
||||
if (holds.length) throw new Refusal("account-is-credential", `launch.account.name is the value of ${holds.join(", ")}; it names the account, never its credential`);
|
||||
const named = b.launch.account.credential.split("+");
|
||||
if (!SESSION_CREDENTIALS.some((set) => set.join("+") === named.join("+")) || !named.every((k) => Boolean(env[k])))
|
||||
throw new Refusal("account-credential-missing", `account ${account} names ${named.join(" with ")}, which the bus host doesn't hold as a session login`);
|
||||
const other = [...new Set(SESSION_CREDENTIALS.flat())].filter((k) => !named.includes(k) && Boolean(env[k]));
|
||||
if (other.length) throw new Refusal("account-credential-ambiguous", `account ${account} names ${named.join(" with ")}, but the bus host also sets ${other.join(", ")}`);
|
||||
}
|
||||
const unavailable = sandboxProblem({ bwrap });
|
||||
if (unavailable) throw new Refusal("sandbox-unavailable", unavailable);
|
||||
const hit=limitHit(registry.sessions,b.id,b.launch.limits,model);
|
||||
@@ -251,7 +265,7 @@ export function createLauncher({
|
||||
// and so does a bus that can't answer (fail closed, lead decision 150).
|
||||
let may;
|
||||
try {
|
||||
may = await host.op({ op: "mayLaunch", business: b.id, instance, provider: model.provider, model: model.model });
|
||||
may = await host.op({ op: "mayLaunch", business: b.id, instance, provider: model.provider, model: model.model, account });
|
||||
} catch (e) {
|
||||
throw new Refusal("limit-check-failed", `bus: ${e.code ?? "launch-op-refused"}`);
|
||||
}
|
||||
@@ -259,11 +273,11 @@ export function createLauncher({
|
||||
if (may?.hit) { const error = new Refusal("limit-reached", JSON.stringify(may.hit)); error.limit = { check: may.check, ...may.hit }; throw error; }
|
||||
throw new Refusal("limit-check-failed", `${may?.check ?? "bus"}: ${may?.code ?? "malformed-answer"}`);
|
||||
}
|
||||
return { resolved, model };
|
||||
return { resolved, model, account };
|
||||
}
|
||||
|
||||
// Bundle, spawn, bind, register, hand over the capability.
|
||||
async function start({ instance, launchedBy, resolved, model, thread = null }) {
|
||||
async function start({ instance, launchedBy, resolved, model, account = null, thread = null }) {
|
||||
// A thread's store is checked first, so a bad id or an unsafe directory
|
||||
// launches nothing.
|
||||
let store = null;
|
||||
@@ -293,7 +307,7 @@ export function createLauncher({
|
||||
if (c.outcome === "kept") record({ event: "checkout-kept", instance, project: c.project, reason: c.reason });
|
||||
else if (c.outcome === "fetched") record({ event: "checkout-fetched", instance, project: c.project, reason: c.reason });
|
||||
}
|
||||
({resolved,model}=await check(instance,{pm:instance===b.launch.by,thread}));
|
||||
({resolved,model,account}=await check(instance,{pm:instance===b.launch.by,thread}));
|
||||
const { run, runDir } = newRun(dataRoot, b.id);
|
||||
const sessionDir = store ? store.session : join(runDir, "session");
|
||||
if (!store) mkdirSync(sessionDir, { mode: 0o700 });
|
||||
@@ -369,7 +383,7 @@ export function createLauncher({
|
||||
const outerStart = startTimeOf(child.pid);
|
||||
const runner = await runnerOf(child);
|
||||
if (!outerStart) throw new Error("the session process exited at once");
|
||||
const launch = await host.bindLaunch({ business: b.id, role: instance, run, harness: model.harness, provider: model.provider, model: model.model, pid: child.pid, startTime: outerStart, ...(thread ? { thread } : {}) });
|
||||
const launch = await host.bindLaunch({ business: b.id, role: instance, run, harness: model.harness, provider: model.provider, model: model.model, account, pid: child.pid, startTime: outerStart, ...(thread ? { thread } : {}) });
|
||||
bound = true;
|
||||
entry = {
|
||||
business: b.id, instance, ...(thread ? { thread } : {}), run, launchedBy, harness: model.harness, model: model.model, provider: model.provider, modelKey: model.modelKey,
|
||||
@@ -404,7 +418,7 @@ export function createLauncher({
|
||||
refusedRelease.delete(run);
|
||||
}
|
||||
});
|
||||
record({ event: "launch", instance, ...(thread ? { thread } : {}), run, launchedBy, harness: model.harness, model: model.model, provider: model.provider, modelKey: model.modelKey, pid: child.pid, runnerPid: entry.runnerPid, manifest });
|
||||
record({ event: "launch", instance, ...(thread ? { thread } : {}), run, launchedBy, harness: model.harness, model: model.model, provider: model.provider, modelKey: model.modelKey, account, pid: child.pid, runnerPid: entry.runnerPid, manifest });
|
||||
return { run, instance, harness: model.harness, model: model.model };
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,8 @@ export const LIMITS_USAGE = "mosaic limits [--business ID] [--json] | set --file
|
||||
"reset PATH... [--business ID] | migrate --file ORGANIZATION --models MAPPING [--roles-dir DIR]; " +
|
||||
"PATCH keys: revision, limits, models, instances, reset, assistants";
|
||||
|
||||
export const DAILY_NOTE = "Daily quotas count only this stack's own use of the account, not its use anywhere else.";
|
||||
|
||||
// Row 125 (#1619, REQ-LIMIT-3, REQ-LIMIT-4): one line per token limit, its path in the words
|
||||
// `mosaic limits reset` takes. A limit no switched-on check counts reads "not enforced".
|
||||
export function formatTokens(tokens) {
|
||||
@@ -24,7 +26,9 @@ export function formatTokens(tokens) {
|
||||
if (t.status === "not-enforced") return `${head}, not enforced${t.reason ? `: ${t.reason}` : ""}`;
|
||||
return `${head}, check failed: ${t.code}${t.check ? ` (${t.check})` : ""}`;
|
||||
});
|
||||
return `token limits:\n${lines.map(l => ` ${l}`).join("\n")}\n`;
|
||||
// Row 126 (#1620): a daily quota counts only the records this stack wrote. Said once, after the list.
|
||||
const daily = tokens.some(t => t.path?.[1] === "daily") ? `${DAILY_NOTE}\n` : "";
|
||||
return `token limits:\n${lines.map(l => ` ${l}`).join("\n")}\n${daily}`;
|
||||
}
|
||||
|
||||
export function parseLimits(args) {
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
// Row 126 (#1620, REQ-LIMIT-2): the account a launch spends. Only a claude-code launch carries
|
||||
// launch.account.name; the bus environment must hold the named login set and no other credential
|
||||
// variable, and the refusals name variables, never values. A pi launch has account null and skips
|
||||
// both checks. A stub host answers the ops; no sandbox, Docker or session process.
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import {readFileSync} from 'node:fs';
|
||||
import {createLauncher} from '../src/launcher.mjs';
|
||||
import {fixture,tmp} from './helpers.mjs';
|
||||
import {launchLogFile,SESSION_CREDENTIALS} from '../../seat/src/session.mjs';
|
||||
|
||||
const VALUE='stand-in-value-7f3a';
|
||||
const ACCOUNT={name:'jason-max',credential:'CLAUDE_CODE_OAUTH_TOKEN'};
|
||||
|
||||
// set is the credential variables the bus environment holds; every other one is removed.
|
||||
function setup(t,{harness='claude-code',account=ACCOUNT,set=['CLAUDE_CODE_OAUTH_TOKEN']}={}){
|
||||
const root=tmp(t),f=fixture(root,'acme',doc=>{
|
||||
doc.roles.coder.vars.model='claude-sonnet-5-5';doc.roles.coder.vars.harness=harness;
|
||||
if(account)doc.launch.account=account;
|
||||
return doc;
|
||||
}),ops=[];
|
||||
for(const k of SESSION_CREDENTIALS.flat())delete f.env[k];
|
||||
for(const k of set)f.env[k]=VALUE;
|
||||
const host={business:'acme',beforeClose:()=>{},op:async x=>{
|
||||
ops.push(x);
|
||||
if(x.op==='identity')return {business:'acme',role:'pm'};
|
||||
if(x.op==='mayLaunch')return {allow:true};
|
||||
if(x.op==='authorizeLaunch')throw Object.assign(Error('fixture authorization stop'),{code:'fixture-policy'});
|
||||
return {};
|
||||
}};
|
||||
const launcher=createLauncher({host,system:JSON.parse(readFileSync(f.config,'utf8')),env:f.env,bwrap:'/usr/bin/true',log:()=>{}});
|
||||
const last=()=>JSON.parse(readFileSync(launchLogFile(f.dataRoot,'acme'),'utf8').trim().split('\n').at(-1));
|
||||
const may=()=>ops.find(x=>x.op==='mayLaunch');
|
||||
return {launcher,ops,last,may};
|
||||
}
|
||||
|
||||
test('REQ-LIMIT-2 a claude-code launch asks mayLaunch with launch.account.name',async t=>{
|
||||
const {launcher,may}=setup(t);
|
||||
assert.equal((await launcher.fromSession('fixture-cap','coder')).error,'fixture-policy');
|
||||
assert.equal(may().account,'jason-max');
|
||||
});
|
||||
|
||||
test('REQ-LIMIT-2 each login set the account can name is accepted when the bus host holds exactly it',async t=>{
|
||||
for(const set of SESSION_CREDENTIALS){
|
||||
const {launcher,may}=setup(t,{account:{name:'jason-max',credential:set.join('+')},set});
|
||||
assert.equal((await launcher.fromSession('fixture-cap','coder')).error,'fixture-policy',set.join('+'));
|
||||
assert.equal(may().account,'jason-max');
|
||||
}
|
||||
});
|
||||
|
||||
test('REQ-LIMIT-2 account-credential-missing: the named set is not a login set, or the bus host lacks part of it',async t=>{
|
||||
for(const [credential,set] of [
|
||||
['ANTHROPIC_API_KEY',['CLAUDE_CODE_OAUTH_TOKEN']],
|
||||
// The host holds a login (OAuth), so no-session-credential passes; the named set lacks its URL.
|
||||
['ANTHROPIC_AUTH_TOKEN+ANTHROPIC_BASE_URL',['CLAUDE_CODE_OAUTH_TOKEN','ANTHROPIC_AUTH_TOKEN']],
|
||||
['ANTHROPIC_AUTH_TOKEN',['ANTHROPIC_AUTH_TOKEN','ANTHROPIC_BASE_URL']],
|
||||
['ANTHROPIC_BASE_URL+ANTHROPIC_AUTH_TOKEN',['ANTHROPIC_AUTH_TOKEN','ANTHROPIC_BASE_URL']],
|
||||
]){
|
||||
const {launcher,ops,last}=setup(t,{account:{name:'jason-max',credential},set});
|
||||
assert.deepEqual(await launcher.fromSession('fixture-cap','coder'),{ok:false,error:'account-credential-missing'},credential);
|
||||
const event=last();
|
||||
assert.equal(event.code,'account-credential-missing');
|
||||
assert.match(event.why,new RegExp(`^account jason-max names ${credential.split('+').join(' with ')},`));
|
||||
assert.ok(!JSON.stringify(event).includes(VALUE),'no value in the log');
|
||||
assert.equal(ops.find(x=>x.op==='mayLaunch'),undefined,credential);
|
||||
}
|
||||
});
|
||||
|
||||
test('REQ-LIMIT-2 account-credential-ambiguous: the bus host sets a credential variable outside the named set, ANTHROPIC_BASE_URL included',async t=>{
|
||||
for(const [extra,named] of [[['ANTHROPIC_API_KEY'],'ANTHROPIC_API_KEY'],[['ANTHROPIC_BASE_URL'],'ANTHROPIC_BASE_URL'],
|
||||
[['ANTHROPIC_AUTH_TOKEN','ANTHROPIC_BASE_URL'],'ANTHROPIC_AUTH_TOKEN, ANTHROPIC_BASE_URL']]){
|
||||
const {launcher,ops,last}=setup(t,{set:['CLAUDE_CODE_OAUTH_TOKEN',...extra]});
|
||||
assert.deepEqual(await launcher.fromSession('fixture-cap','coder'),{ok:false,error:'account-credential-ambiguous'},named);
|
||||
const event=last();
|
||||
assert.equal(event.why,`account jason-max names CLAUDE_CODE_OAUTH_TOKEN, but the bus host also sets ${named}`);
|
||||
assert.ok(!JSON.stringify(event).includes(VALUE),'no value in the log');
|
||||
assert.equal(ops.find(x=>x.op==='mayLaunch'),undefined,named);
|
||||
}
|
||||
});
|
||||
|
||||
// Usage records keep the account's name, so a name that is a credential variable's value refuses,
|
||||
// whichever variable holds it, before any message that names the account.
|
||||
test('REQ-LIMIT-2 account-is-credential: launch.account.name is the value of a credential variable the bus host sets',async t=>{
|
||||
for(const set of [['CLAUDE_CODE_OAUTH_TOKEN'],['CLAUDE_CODE_OAUTH_TOKEN','ANTHROPIC_API_KEY']]){
|
||||
const {launcher,ops,last}=setup(t,{account:{name:VALUE,credential:'CLAUDE_CODE_OAUTH_TOKEN'},set});
|
||||
assert.deepEqual(await launcher.fromSession('fixture-cap','coder'),{ok:false,error:'account-is-credential'},set.join());
|
||||
const event=last();
|
||||
assert.equal(event.code,'account-is-credential');
|
||||
assert.match(event.why,/^launch\.account\.name is the value of [A-Z_, ]+; it names the account, never its credential$/);
|
||||
for(const k of set)assert.ok(event.why.includes(k),k);
|
||||
assert.ok(!JSON.stringify(event).includes(VALUE),'no value in the log');
|
||||
assert.equal(ops.find(x=>x.op==='mayLaunch'),undefined,set.join());
|
||||
}
|
||||
});
|
||||
|
||||
test('REQ-LIMIT-2 a pi launch carries account null and skips both account checks',async t=>{
|
||||
// No credential variable at all, and two at once: neither refuses a pi launch.
|
||||
for(const set of [[],['CLAUDE_CODE_OAUTH_TOKEN','ANTHROPIC_API_KEY']]){
|
||||
const {launcher,may}=setup(t,{harness:'pi',set});
|
||||
assert.equal((await launcher.fromSession('fixture-cap','coder')).error,'fixture-policy',set.join());
|
||||
assert.equal(may().account,null);
|
||||
}
|
||||
});
|
||||
|
||||
test('REQ-LIMIT-2 with no launch.account a claude-code launch carries null and the environment is not checked for ambiguity',async t=>{
|
||||
const {launcher,may}=setup(t,{account:null,set:['CLAUDE_CODE_OAUTH_TOKEN','ANTHROPIC_API_KEY']});
|
||||
assert.equal((await launcher.fromSession('fixture-cap','coder')).error,'fixture-policy');
|
||||
assert.equal(may().account,null);
|
||||
});
|
||||
@@ -26,10 +26,10 @@ function setup(t,answer){
|
||||
return {launcher,ops,last};
|
||||
}
|
||||
|
||||
test('REQ-LIMIT-4 the launcher asks mayLaunch with the instance, provider and model, and goes on to authorization on an allow',async t=>{
|
||||
test('REQ-LIMIT-4 the launcher asks mayLaunch with the instance, provider, model and account (row 126), and goes on to authorization on an allow',async t=>{
|
||||
const {launcher,ops}=setup(t,{allow:true});
|
||||
assert.equal((await launcher.fromSession('fixture-cap','coder')).error,'fixture-policy');
|
||||
assert.deepEqual(ops.find(x=>x.op==='mayLaunch'),{op:'mayLaunch',business:'acme',instance:'coder',provider:'zai',model:'claude-sonnet-5-5'});
|
||||
assert.deepEqual(ops.find(x=>x.op==='mayLaunch'),{op:'mayLaunch',business:'acme',instance:'coder',provider:'zai',model:'claude-sonnet-5-5',account:null});
|
||||
assert.ok(ops.findIndex(x=>x.op==='mayLaunch')<ops.findIndex(x=>x.op==='authorizeLaunch'));
|
||||
});
|
||||
|
||||
|
||||
@@ -171,6 +171,8 @@ test("bus start --pm: the launcher instance (the chief of staff) runs under its
|
||||
const [launched] = log(f).filter((e) => e.event === "launch");
|
||||
assert.equal(launched.run, chief.run);
|
||||
assert.equal(launched.manifest, join(runDir, "bundle", "manifest.json"));
|
||||
// Row 126: a pi launch spends no account, so the record says null.
|
||||
assert.equal(launched.account, null);
|
||||
assert.equal(manifest.model, "claude-opus-5-5");
|
||||
|
||||
// A second PM is refused before anything spawns.
|
||||
@@ -708,6 +710,8 @@ test("a real Claude Code coder's shell can't read a stand-in secret or anything
|
||||
const given = prepare(t, (doc) => {
|
||||
doc.roles.coder.vars.harness = "claude-code";
|
||||
doc.roles.coder.vars["limits.tools"] = ["bash"];
|
||||
// Row 126: the claude-code launch spends this account, which names the proxy login set.
|
||||
doc.launch.account = { name: "proxy-login", credential: "ANTHROPIC_AUTH_TOKEN+ANTHROPIC_BASE_URL" };
|
||||
return doc;
|
||||
});
|
||||
delete given.f.env.CLAUDE_CODE_OAUTH_TOKEN;
|
||||
@@ -743,6 +747,7 @@ test("a real Claude Code coder's shell can't read a stand-in secret or anything
|
||||
assert.equal(JSON.parse(launched.body).instance, "coder", launched.body);
|
||||
const coder = readSessions(f.dataRoot).find((s) => s.instance === "coder");
|
||||
assert.equal(coder.harness, "claude-code");
|
||||
assert.deepEqual(log(f).filter((e) => e.event === "launch").map((e) => [e.instance, e.account]), [["chief", null], ["coder", "proxy-login"]]);
|
||||
|
||||
const hello = await client.call("message.send", { to: "coder", class: "REQUEST", body: "probe" });
|
||||
const reply = await until(async () => (await client.call("message.receive")).find((m) => m.in_reply_to === hello.id), 150000);
|
||||
@@ -758,6 +763,13 @@ test("a real Claude Code coder's shell can't read a stand-in secret or anything
|
||||
// The session logged in with the stand-in proxy key, against the mock.
|
||||
assert.ok(api.requests.length > 0);
|
||||
assert.ok(api.requests.some((r) => r.tools.includes("Bash")), api.requests.map((r) => r.tools.join(",")).join(" | "));
|
||||
// Row 126: the bus got the account with the run, so the coder's turn records it (no usage
|
||||
// source here, so the turn is unknown); the pi chief's turns record null.
|
||||
const accounts = await until(async () => {
|
||||
const seen = (await client.call("usage")).byAccount.map((r) => r.account);
|
||||
return seen.includes("proxy-login") && seen;
|
||||
});
|
||||
assert.deepEqual([...accounts].sort(), [null, "proxy-login"]);
|
||||
});
|
||||
|
||||
for (const exited of [false, true]) {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import {main} from '../src/cli.mjs';
|
||||
import {formatTokens} from '../src/limits.mjs';
|
||||
import {formatTokens,DAILY_NOTE} from '../src/limits.mjs';
|
||||
import {io,tmp} from './helpers.mjs';
|
||||
|
||||
const SINCE='2026-10-18T07:00:00.000Z';
|
||||
@@ -26,6 +26,15 @@ test('REQ-LIMIT-3 REQ-LIMIT-4 formatTokens shows each limit counted, not enforce
|
||||
for(const none of [[],undefined])assert.equal(formatTokens(none),'token limits: none\n');
|
||||
});
|
||||
|
||||
test('REQ-LIMIT-2 row 126: any daily quota row adds one line after the list saying the count is this stack\'s own use',()=>{
|
||||
const daily={path:['tokens','daily','jason-max'],limit:40,since:SINCE,status:'counted',check:'daily-quota',count:3,kinds:{input:1,output:1,cacheWrite:0,cacheRead:1},unknownTurns:0};
|
||||
const out=formatTokens([TOKENS[0],daily,{...daily,path:['tokens','daily','other'],status:'not-enforced',reason:null}]);
|
||||
assert.ok(out.endsWith(` tokens daily other: limit 40 since ${SINCE}, not enforced\n${DAILY_NOTE}\n`),out);
|
||||
assert.equal(out.split(DAILY_NOTE).length,2,'said once');
|
||||
assert.equal(DAILY_NOTE,"Daily quotas count only this stack's own use of the account, not its use anywhere else.");
|
||||
assert.ok(!formatTokens(TOKENS).includes(DAILY_NOTE));
|
||||
});
|
||||
|
||||
test('REQ-LIMIT-3 the view prints the limits then the token lines; --json keeps tokens in the result',async t=>{
|
||||
const root=tmp(t),deps={system:{dataRoot:root},transport:()=>()=>({revision:'b'.repeat(64),limits:{total:3},tokens:TOKENS})};
|
||||
const x=io();await main(['limits','--business','acme'],x,deps);
|
||||
|
||||
Reference in new issue
Block a user