# First coding task — guided trial worksheet

Use this tiny standalone JavaScript task to compare your own workflow. It is
intentionally not a benchmark, does not report a model result, and does not
measure cost. Record only the observations you choose to keep locally.

## What you need

- Node.js 18 or later (uses the built-in `node:test` runner)
- A new empty directory
- No dependencies, credentials, or repository access

## 1. Create the fixture files

Create this structure:

```text
first-coding-task/
  src/total-cost.mjs
  test/total-cost.test.mjs
```

### `src/total-cost.mjs`

```js
export function totalCost({ inputTokens, cachedInputTokens, outputTokens }) {
  // Starter implementation: intentionally incorrect.
  // It does not apply the documented rates or validate invalid values.
  return inputTokens + cachedInputTokens + outputTokens;
}
```

### `test/total-cost.test.mjs`

```js
import assert from 'node:assert/strict';
import test from 'node:test';

import { totalCost } from '../src/total-cost.mjs';

test('prices uncached input and output at the documented rates', () => {
  assert.equal(
    totalCost({ inputTokens: 10000, cachedInputTokens: 0, outputTokens: 2000 }),
    0.08
  );
});

test('prices cached input without charging the uncached rate too', () => {
  assert.equal(
    totalCost({ inputTokens: 10000, cachedInputTokens: 10000, outputTokens: 2000 }),
    0.042
  );
});

test('rejects non-integer and negative token counts', () => {
  assert.throws(
    () => totalCost({ inputTokens: 100.5, cachedInputTokens: 0, outputTokens: 0 }),
    /non-negative whole number/i
  );
  assert.throws(
    () => totalCost({ inputTokens: -1, cachedInputTokens: 0, outputTokens: 0 }),
    /non-negative whole number/i
  );
});

test('rejects a cache count above total input', () => {
  assert.throws(
    () => totalCost({ inputTokens: 4, cachedInputTokens: 5, outputTokens: 0 }),
    /cannot exceed/i
  );
});
```

Run the intentionally failing starter:

```bash
node --test test/total-cost.test.mjs
```

The starter is expected to fail. Those tests are acceptance requirements for a
solution; they are not a performance benchmark and do not show that any model
has been tested by this guide.

## 2. Prompt for your coding tool

```text
You are working in a tiny JavaScript fixture with Node's built-in node:test.
Implement src/total-cost.mjs so totalCost({ inputTokens, cachedInputTokens,
outputTokens }) returns the per-request USD token cost using these rates per
one million tokens: $4 for uncached input, $0.20 for cached input, and $20 for
output. Cached input is part of total input, so only inputTokens -
cachedInputTokens receives the uncached input rate.

Rules:
- inputTokens, cachedInputTokens, and outputTokens must each be finite,
  non-negative whole numbers.
- cachedInputTokens must not exceed inputTokens.
- Throw a helpful Error when a rule is violated.
- Keep the public function name and input object shape unchanged.
- Add focused tests only if they add a distinct edge case.
- Run `node --test test/total-cost.test.mjs` and report the result.
Do not use external packages or change the task into a different project.
```

## 3. Check the result

Review the changed file and run the test command yourself. A passing test run
means the submitted code met this fixture's acceptance requirements. It does
not establish model quality, token cost, quota usage, or a general result.

If you use an API, consult its actual usage and billing records separately. If
you use a subscription, note any quota message you personally observed rather
than converting it to a dollar figure.
