mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-25 09:31:43 +01:00
* Attribute every paid trial's cost: bind label-named records by testName, price aborted SDK sessions from streamed usage, model-free cases cost $0
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* fix: case cost adds streamed sessions to record sums and keeps record cost_known
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* fix: the paid report headline counts ledger-only session cost once
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* fix: a cost-only record never sets the trial model
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* test: recordE2E writes cost_case_id only for a registered label-named case
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* docs: CHANGELOG for paid-report cost attribution (Unreleased)
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* fix: the headline adds only streamed session cost; cache writes without a 5m key
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* docs: how the paid report prices a trial and what stays cost-unknown
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* Price PTY sessions from their transcripts: pin a session id, sum the session's and its subagents' usage into the ledger's streamed_cost_usd
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* fix: transcript pricing never throws from a PTY ledger writer
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* chore: pin transcript-cost.ts as non-behavioral at HARNESS_VERSION 6
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* fix: recognise --session-id= and --resume= forms
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* docs: CHANGELOG for PTY transcript pricing (Unreleased)
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* docs: PTY sessions priced from their transcripts
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* fix: price PTY transcripts without adding a launch argument; native AUQ capture opts out
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* docs: harness notes and CHANGELOG match the transcript claim
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* feat(flaky): gstack-flaky run reruns a failed JUnit test once and ledgers the flake (GSTA-158)
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* fix(flaky): stream output, keep unreported runner failures red, fail-closed duplicates and nonzero reruns
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* fix: pre-landing review fixes
gstack-flaky never greens an incomplete run: a targeted rerun needs the
runner's summary proving the first run complete, otherwise (and always for
generic runners) the rerun repeats the whole command. A rerun clears a test
only when it exits 0 and the test passes once on its first attempt. Killed
runners exit 3 (FLAKY_COMMAND_KILLED) and signals are forwarded. The first
report is restored at --junit with reruns kept beside it; ids are redacted at
every output; the ledger gets its own GSTACK_FLAKE_LEDGER_JUNIT; fixtures are
registered in FREE_FIXTURES.
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* fix: latch cancellation and check whole-command rerun reports
A cancel forwarded to a runner that traps the signal now counts as killed for
every later attempt, so a cancelled job is never rerun or greened. A
whole-command rerun clears nothing when its report has a failed test, misses a
first-run test, or its runner counted failures outside the report.
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* fix: whole-command rerun when coverage or runner-flaky tests can fail the run
A coverage threshold or a fail-on-flaky policy fails a run for a reason a
narrowed rerun cannot reproduce, so either forces a whole-command rerun.
--junit refuses an existing file that is not a JUnit report instead of
deleting it.
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* feat(flaky): rerun the whole command by default; targeted rerun is opt-in
A rerun counts only on the runner's own full green verdict: exit 0, no failed
or missing test, nothing counted outside the report. That covers every way a
run can fail, which a narrowed rerun cannot (a coverage threshold with an lcov
reporter, a fail-on-flaky policy, a test never reached). --rerun-scope test
reruns the failed test alone, with its preconditions documented and the
complete-run checks kept as a safety net. An unreadable existing --junit file
is a usage error, not a crash.
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* docs: gstack-flaky CHANGELOG entry and standalone-binaries row (GSTA-158)
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* feat(flaky): quarantine registry for repeat flakes (GSTA-158 P2)
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* fix(flaky): bound renewal dates; match non-ASCII paths in check --base
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* fix(flaky): reword the FLAKY_QUARANTINE_BASE hint so the egress scanner does not read it as a network op
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* test(agent-sdk): every SDK caller passes the claude_code preset or names why not
The SDK's default system prompt is a bare stub that drops the line telling the
model to run /skill through the Skill tool. runAgentSdkTest now refuses a
missing, empty or bare-string prompt; non-preset callers name a reason; a free
tripwire scans test/ and scripts/ for the same mistake.
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* test: record the SDK prompt guard as a non-behavioral harness change and baseline its tripwire
harness-version: runAgentSdkTest validates systemPrompt before starting; every
live caller already passed the claude_code preset, so no verdict can change.
test-of-test ratchet: the tripwire's subject is the eval harness by design.
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* docs: name the preset literal callers pass and the unnamed-prompt refusal
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* feat(eval-plan): frontier models under test (R54)
Haiku and Sonnet are not models under test. dry-run refuses a plan whose every
arm is Haiku or Sonnet unless --tier-question names what it asks about that
tier, warns on a mix, and re-costs the plan on Opus 5.5 and GPT-6.1 Sol.
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* fix(eval-plan): trim R54 skill prose and raise the eval-plan context ceiling
The R54 paragraph and CHECK: frontier bullet were cut to the minimum; the
exemptions and verdict rule stay in docs/TESTING_INTERNALS.md. The remaining
growth is the feature, so only the eval-plan eager ceiling moves (4887 -> 5458,
the capture helper's value); other skills' ceilings are left as they were.
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* fix(eval-plan): pilot start keeps the R54 refusal; --tier-question rejects a flag
Review pass 1 (full depth) found the frontier refusal could be skipped by
starting a pilot on Haiku or Sonnet arms behind a dry run made on other arms,
or behind a dry-run.json written before the check existed. startPilot now
refuses a pilot whose every arm is Haiku or Sonnet unless its dry run recorded
a tier question. dry-run --tier-question no longer takes the next flag as its
answer. The testing doc now says the frontier re-cost is printed for
comparison with the brief cap, not enforced.
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* docs(support-tiers): Windows CI in the present tense now that windows-smoke is required (#3806)
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* chore: empty commit for a clean check set at the same tree (cancelled orphan free-suite check at 97487df)
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* docs(skills): /eval-plan entry names the R54 frontier check
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
---------
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
204 lines
14 KiB
TypeScript
204 lines
14 KiB
TypeScript
/**
|
|
* PR 2 of GSTA-150: every trial's cost is attributed. A display-label record binds its cost by
|
|
* runSkillTest's testName (cost_case_id) without changing the failed record or failure class; a case
|
|
* with no record takes its sessions' streamed cost; a listed model-free case costs a known $0.
|
|
*/
|
|
import { describe, expect, test } from 'bun:test';
|
|
import * as fs from 'node:fs';
|
|
import * as os from 'node:os';
|
|
import * as path from 'node:path';
|
|
import { MODEL_FREE_CASES, caseCost, junitCensus } from '../scripts/lib/paid-report';
|
|
import { anthropicUsageCostUsd, streamedUsageCostUsd } from '../lib/pricing';
|
|
import { E2E_TOUCHFILES } from './helpers/touchfiles-data';
|
|
import type { SessionLedgerRow } from './helpers/session-ledger';
|
|
import { recordE2E } from './helpers/e2e-helpers';
|
|
import { newTranscriptSessionId, pricedTranscript, ptyTranscriptCostUsd, transcriptFiles } from './helpers/pty/transcript-cost';
|
|
|
|
const ROOT = path.resolve(import.meta.dir, '..');
|
|
const session = (over: Partial<SessionLedgerRow>): SessionLedgerRow => ({ key: 'k', runner: 'agent-sdk', started_at: 't', elapsed_ms: 1, end: 'aborted', ...over });
|
|
|
|
describe('pricing usage', () => {
|
|
test('cache writes bill 1.25x input (5-minute) and 2x (1-hour); reads at the cached rate', () => {
|
|
// claude-opus-5-5: input $4, output $20, cache read $0.20 per Mtok.
|
|
expect(anthropicUsageCostUsd({ input_tokens: 1_000_000, output_tokens: 1_000_000, cache_read_input_tokens: 1_000_000, cache_creation_input_tokens: 1_000_000 }, 'claude-opus-5-5'))
|
|
.toBeCloseTo(4 + 20 + 0.2 + 5, 6);
|
|
expect(anthropicUsageCostUsd({ cache_creation_input_tokens: 3_000_000, cache_creation: { ephemeral_5m_input_tokens: 1_000_000, ephemeral_1h_input_tokens: 2_000_000 } }, 'claude-opus-5-5'))
|
|
.toBeCloseTo(5 + 16, 6);
|
|
expect(anthropicUsageCostUsd({ cache_creation_input_tokens: 3_000_000, cache_creation: { ephemeral_1h_input_tokens: 2_000_000 } }, 'claude-opus-5-5'))
|
|
.toBeCloseTo(5 + 16, 6);
|
|
expect(anthropicUsageCostUsd({ input_tokens: 10 }, 'no-such-model')).toBeUndefined();
|
|
});
|
|
|
|
test('streamed messages count once per id at their largest output, sidechains included; an unpriced model is unknown', () => {
|
|
const msg = (id: string, output: number, extra: Record<string, unknown> = {}) => ({ message: { id, model: 'claude-opus-5-5', usage: { input_tokens: 0, output_tokens: output } }, ...extra });
|
|
expect(streamedUsageCostUsd([msg('a', 10), msg('a', 1_000_000), msg('b', 500_000, { parent_tool_use_id: 'tool-1' })])).toBeCloseTo(30, 6);
|
|
expect(streamedUsageCostUsd([{ message: { id: 'a', model: '<synthetic>', usage: { output_tokens: 5 } } }])).toBeUndefined();
|
|
expect(streamedUsageCostUsd([{ message: { id: 'a', model: 'no-such-model', usage: { output_tokens: 5 } } }, msg('b', 5)])).toBeUndefined();
|
|
expect(streamedUsageCostUsd([{ message: { id: 'a', usage: { output_tokens: 1_000_000 } } }], 'claude-opus-5-5')).toBeCloseTo(20, 6);
|
|
});
|
|
});
|
|
|
|
describe('caseCost', () => {
|
|
test('a billed session\'s cost is already in the records; a streamed session adds what no record carries', () => {
|
|
expect(caseCost('x', [{ cost_usd: 0.25 }, { cost_usd: 0.1 }], [session({ billed: true, cost_usd: 9 })])).toEqual({ cost_usd: 0.35 });
|
|
expect(caseCost('x', [{ cost_usd: 0 }], [session({ billed: false, streamed_cost_usd: 0.4 })])).toEqual({ cost_usd: 0.4 });
|
|
expect(caseCost('x', [{ cost_usd: 0.2 }], [session({ runner: 'pty', billed: false })])).toEqual({ cost_usd: 0.2, cost_known: false });
|
|
expect(caseCost('x', [{ cost_usd: 0.2, cost_known: false }], [])).toEqual({ cost_usd: 0.2, cost_known: false });
|
|
});
|
|
|
|
test('a case with no record takes its sessions\' billed or streamed cost, else stays unknown', () => {
|
|
expect(caseCost('auq', [], [session({ billed: false, streamed_cost_usd: 0.123 })])).toEqual({ cost_usd: 0.12 });
|
|
expect(caseCost('auq', [], [session({ billed: false })])).toEqual({ cost_usd: 0, cost_known: false });
|
|
expect(caseCost('auq', [], [session({ runner: 'claude-p', billed: true })])).toEqual({ cost_usd: 0, cost_known: false });
|
|
});
|
|
|
|
test('only a listed model-free case with neither record nor session costs a known $0', () => {
|
|
expect(caseCost('timeline-event-flow', [], [])).toEqual({ cost_usd: 0 });
|
|
expect(caseCost('some-other-case', [], [])).toEqual({ cost_usd: 0, cost_known: false });
|
|
});
|
|
|
|
test('every listed model-free case body starts no model session', () => {
|
|
for (const id of MODEL_FREE_CASES) {
|
|
const file = E2E_TOUCHFILES[id]?.find(entry => /^test\/[^/]+\.test\.ts$/.test(entry));
|
|
expect(file, id).toBeTruthy();
|
|
const source = fs.readFileSync(path.join(ROOT, file!), 'utf8');
|
|
const start = source.search(new RegExp(`IfSelected\\(\\s*['"\`]${id}['"\`]`));
|
|
expect(start, id).toBeGreaterThan(-1);
|
|
const rest = source.slice(start + 1);
|
|
const end = rest.search(/IfSelected\(/);
|
|
const body = end === -1 ? rest : rest.slice(0, end);
|
|
expect(body, id).not.toMatch(/runSkillTest|runAgentSdkTest|runCodex|launchClaudePty|runPtySession|claude-pty|callJudge|judge\w*\(/);
|
|
}
|
|
});
|
|
});
|
|
|
|
describe('recordE2E cost_case_id', () => {
|
|
const entry = (name: string, testName?: string) => {
|
|
const tests: any[] = [];
|
|
const result: any = { toolCalls: [], browseErrors: [], exitReason: 'success', duration: 1, output: '', transcript: [], model: 'claude-opus-5-5',
|
|
costEstimate: { estimatedCost: 0.05, turnsUsed: 1, estimatedTokens: 1 }, ...(testName ? { testName } : {}) };
|
|
recordE2E({ addTest: (t: any) => tests.push(t) } as any, name, 'suite', result);
|
|
return tests[0];
|
|
};
|
|
|
|
test('a display-label record carries its registered runSkillTest testName as cost_case_id, and nothing else does', () => {
|
|
expect(entry('browse basic commands', 'browse-basic')).toMatchObject({ name: 'browse basic commands', cost_case_id: 'browse-basic' });
|
|
expect(entry('browse-basic', 'browse-basic').cost_case_id).toBeUndefined();
|
|
expect(entry('browse basic commands', 'not-a-registered-case').cost_case_id).toBeUndefined();
|
|
expect(entry('browse basic commands').cost_case_id).toBeUndefined();
|
|
});
|
|
});
|
|
|
|
describe('junitCensus cost binding', () => {
|
|
const key = 'test/skill-e2e-bws.test.ts';
|
|
const census = (records: any[], ledger: SessionLedgerRow[] = []) => {
|
|
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'paid-report-cost-'));
|
|
const shard = path.join(root, 'shards', 'skill-e2e-bws');
|
|
fs.mkdirSync(shard, { recursive: true });
|
|
fs.writeFileSync(path.join(shard, 'junit.xml'), `<testsuites><testsuite name="${key}">
|
|
<testcase name="browse-basic" classname="${key}" time="1"></testcase>
|
|
<testcase name="browse-snapshot" classname="${key}" time="1"><failure type="AssertionError" message="expected snapshot"/></testcase>
|
|
</testsuite></testsuites>`);
|
|
fs.writeFileSync(path.join(shard, 'session-ledger.jsonl'), ledger.map(row => JSON.stringify(row)).join('\n'));
|
|
const manifest: any = { version: 1, tier: 'gate', evalsAll: true, sliceCount: 1, profile: 'full', selection: { e2e: null, judges: null }, entries: [{ file: key, slice: 1, status: 'planned', estimatedMs: 1 }] };
|
|
const result: any = { version: 1, tier: 'gate', profile: 'full', selection: { e2e: null, judges: null }, sliceIndex: 1, sliceCount: 1, attempt: 1,
|
|
outcomes: [{ files: [key], status: 'failed', exitCode: 1, elapsedMs: 10, executedTests: 2, skippedTests: 0 }] };
|
|
try { return junitCensus(manifest, [{ root, result }], new Map([[key, records]]), {}); } finally { fs.rmSync(root, { recursive: true, force: true }); }
|
|
};
|
|
const labelled = [
|
|
{ name: 'browse basic commands', passed: true, cost_usd: 0.05, cost_case_id: 'browse-basic' },
|
|
{ name: 'browse snapshot flags', passed: false, cost_usd: 0.06, cost_case_id: 'browse-snapshot', exit_reason: 'timeout', failure_class: 'infra', error: 'record error' },
|
|
];
|
|
|
|
test('display-label records bind their cost by cost_case_id in a multi-case shard', () => {
|
|
const cases = census(labelled).ruleCases;
|
|
expect(cases.map(c => [c.id, c.costUsd, c.costKnown])).toEqual([['browse-basic', 0.05, true], ['browse-snapshot', 0.06, true]]);
|
|
});
|
|
|
|
test('the failed record and failure class stay what the named records give, as without cost_case_id', () => {
|
|
const bound = census(labelled).ruleCases.find(c => c.id === 'browse-snapshot')!;
|
|
const unbound = census(labelled.map(({ cost_case_id, ...rest }) => rest)).ruleCases.find(c => c.id === 'browse-snapshot')!;
|
|
expect(unbound).toMatchObject({ costUsd: 0, costKnown: false });
|
|
expect({ failureClass: bound.failureClass, error: bound.error, line: bound.line?.replace(/ {2}\[slice.*$/, '') })
|
|
.toEqual({ failureClass: unbound.failureClass, error: unbound.error, line: unbound.line?.replace(/ {2}\[slice.*$/, '') });
|
|
expect(bound.failureClass).toBe('assertion');
|
|
});
|
|
|
|
test('a cost-only record never sets the trial\'s model, which keys its pass-rate series', () => {
|
|
const history = census(labelled.map(r => ({ ...r, model: 'claude-opus-5-5' }))).history;
|
|
expect(history.map(h => [h.case, h.model])).toEqual([['browse-basic', undefined], ['browse-snapshot', undefined]]);
|
|
});
|
|
});
|
|
|
|
describe('PTY transcript pricing (GSTA-150 PR 3)', () => {
|
|
const SID = '11111111-2222-4333-8444-555555555555';
|
|
const OTHER = '99999999-2222-4333-8444-555555555555';
|
|
const assistant = (sid: string, id: string, model: string, usage: object, extra: object = {}) =>
|
|
JSON.stringify({ type: 'assistant', sessionId: sid, cwd: '/fixture/cwd', message: { id, model, role: 'assistant', usage }, ...extra });
|
|
const fixture = (write: (project: string) => void) => {
|
|
const config = fs.mkdtempSync(path.join(os.tmpdir(), 'pty-cost-'));
|
|
const project = path.join(config, 'projects', '-fixture-cwd');
|
|
fs.mkdirSync(project, { recursive: true });
|
|
write(project);
|
|
return config;
|
|
};
|
|
|
|
test('prices the session, its inline sidechains and subagent files, each message id once at its largest output', () => {
|
|
const config = fixture(project => {
|
|
fs.writeFileSync(path.join(project, `${SID}.jsonl`), [
|
|
JSON.stringify({ type: 'user', sessionId: SID, message: { role: 'user', content: 'hi' } }),
|
|
assistant(SID, 'msg_a', 'claude-opus-5-5', { input_tokens: 1000, output_tokens: 10 }),
|
|
assistant(SID, 'msg_a', 'claude-opus-5-5', { input_tokens: 1000, output_tokens: 500 }),
|
|
assistant(SID, 'msg_side', 'claude-opus-5-5', { input_tokens: 0, output_tokens: 1000 }, { isSidechain: true }),
|
|
assistant(SID, 'msg_syn', '<synthetic>', { input_tokens: 0, output_tokens: 0 }),
|
|
'{"partial":',
|
|
].join('\n'));
|
|
fs.mkdirSync(path.join(project, SID, 'subagents'), { recursive: true });
|
|
fs.writeFileSync(path.join(project, SID, 'subagents', 'agent-x.jsonl'),
|
|
assistant(SID, 'msg_sub', 'claude-opus-5-5', { input_tokens: 0, cache_read_input_tokens: 10000, output_tokens: 0 }) + '\n');
|
|
fs.writeFileSync(path.join(project, `${OTHER}.jsonl`), assistant(OTHER, 'msg_foreign', 'claude-opus-5-5', { input_tokens: 1_000_000 }) + '\n');
|
|
});
|
|
try {
|
|
// opus-5-5: $4 in, $20 out, $0.20 cached per MTok.
|
|
const expected = (1000 * 4 + 500 * 20 + 1000 * 20 + 10000 * 0.2) / 1_000_000;
|
|
expect(ptyTranscriptCostUsd(config, SID)).toBeCloseTo(expected, 6);
|
|
expect(pricedTranscript({ transcriptCostUsd: () => ptyTranscriptCostUsd(config, SID) }).streamed_cost_usd).toBeCloseTo(expected, 6);
|
|
} finally { fs.rmSync(config, { recursive: true, force: true }); }
|
|
});
|
|
|
|
test('stays cost-unknown without a transcript, a session id, usage, a priced model or a readable file, and never throws', () => {
|
|
const unpriced = fixture(project => fs.writeFileSync(path.join(project, `${SID}.jsonl`),
|
|
assistant(SID, 'msg_a', 'claude-opus-5-5', { output_tokens: 1 }) + '\n' + assistant(SID, 'msg_b', 'some-unpriced-model', { output_tokens: 1 }) + '\n'));
|
|
const empty = fixture(project => fs.writeFileSync(path.join(project, `${SID}.jsonl`), JSON.stringify({ type: 'user', sessionId: SID }) + '\n'));
|
|
const unreadable = fixture(project => fs.mkdirSync(path.join(project, `${SID}.jsonl`)));
|
|
try {
|
|
expect(ptyTranscriptCostUsd(unpriced, SID)).toBeUndefined();
|
|
expect(ptyTranscriptCostUsd(empty, SID)).toBeUndefined();
|
|
expect(ptyTranscriptCostUsd(empty, OTHER)).toBeUndefined();
|
|
expect(ptyTranscriptCostUsd(unpriced, undefined)).toBeUndefined();
|
|
expect(ptyTranscriptCostUsd(null, SID)).toBeUndefined();
|
|
expect(ptyTranscriptCostUsd(path.join(empty, 'missing'), SID)).toBeUndefined();
|
|
expect(ptyTranscriptCostUsd(unreadable, SID)).toBeUndefined();
|
|
expect(newTranscriptSessionId(unreadable, new Set(), '/fixture/cwd')).toBeUndefined();
|
|
expect(pricedTranscript(undefined)).toEqual({});
|
|
expect(pricedTranscript({})).toEqual({});
|
|
} finally { for (const dir of [unpriced, empty, unreadable]) fs.rmSync(dir, { recursive: true, force: true }); }
|
|
});
|
|
|
|
test('a launch claims only the one transcript it created for its own cwd', () => {
|
|
const cwd = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'pty-cost-cwd-')));
|
|
const line = (sid: string, at: string) => JSON.stringify({ type: 'user', sessionId: sid, cwd: at }) + '\n';
|
|
const config = fixture(project => fs.writeFileSync(path.join(project, `${OTHER}.jsonl`), line(OTHER, cwd)));
|
|
try {
|
|
const before = transcriptFiles(config);
|
|
const project = path.join(config, 'projects', '-fixture-cwd');
|
|
fs.writeFileSync(path.join(project, '22222222-2222-4333-8444-555555555555.jsonl'), line('22222222-2222-4333-8444-555555555555', '/a/concurrent/test'));
|
|
expect(newTranscriptSessionId(config, before, cwd)).toBeUndefined();
|
|
fs.writeFileSync(path.join(project, `${SID}.jsonl`), line(SID, cwd));
|
|
expect(newTranscriptSessionId(config, before, cwd)).toBe(SID);
|
|
fs.writeFileSync(path.join(project, '33333333-2222-4333-8444-555555555555.jsonl'), line('33333333-2222-4333-8444-555555555555', cwd));
|
|
expect(newTranscriptSessionId(config, before, cwd)).toBeUndefined();
|
|
} finally { fs.rmSync(config, { recursive: true, force: true }); fs.rmSync(cwd, { recursive: true, force: true }); }
|
|
});
|
|
});
|