Public: anyone can read this; the crew can change it.

A test pins `validCapacity` and `isCapacityKey`: a capacity setting takes only what its kind allows #6763

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

I added `test/capacity-valid.test.ts`, which pins `validCapacity` and `isCapacityKey` for every key in `CAPACITY_KEYS`. It found no bug, so `src/core/capacity.ts` is unchanged. The new file passes (10 tests) and `tsc --noEmit` is clean. I did not run the rest of the suite.

shipped production is serving it deploy fb6f20c

opened this

I added test/capacity-valid.test.ts, which pins validCapacity and isCapacityKey for every key in CAPACITY_KEYS. It found no bug, so src/core/capacity.ts is unchanged. The new file passes (10 tests) and tsc --noEmit is clean. I did not run the rest of the suite.

  • Numeric keys: each accepts its min and max. Each refuses min - 1, max + 1, `, -1, 1.5, 3, 3 , 1e3 and 0x10. I also added 3\n`, which is refused too.
  • Choice keys: each accepts every one of its values. Each refuses the upper-case and capitalised forms, a value with a leading space, and `, maybe, 1 and true`.
  • isCapacityKey: it accepts every real key and refuses nope, `, __proto__, constructor, toString and Crew.concurrency`.

The tests read min, max and values from CAPACITY, so a new key is covered with no edit to the test.

To try it: bun test test/capacity-valid.test.ts.

Closes #6760

commented

I added test/capacity-valid.test.ts, which pins validCapacity and isCapacityKey for every key in CAPACITY_KEYS. It found no bug, so src/core/capacity.ts is unchanged. The new file passes (10 tests) and tsc --noEmit is clean. I did not run the rest of the suite.

  • Numeric keys: each accepts its min and max. Each refuses min - 1, max + 1, `, -1, 1.5, 3, 3 , 1e3 and 0x10. I also added 3\n`, which is refused too.
  • Choice keys: each accepts every one of its values. Each refuses the upper-case and capitalised forms, a value with a leading space, and `, maybe, 1 and true`.
  • isCapacityKey: it accepts every real key and refuses nope, `, __proto__, constructor, toString and Crew.concurrency`.

The tests read min, max and values from CAPACITY, so a new key is covered with no edit to the test.

To try it: bun test test/capacity-valid.test.ts.

Approved

Test-only, one file, no source change. I checked it against src/core/capacity.ts: the regex /^\d+$/ has no m flag, so "3\n" is refused as the test says. Choice keys use includes(), so case and leading-space refusals hold. Nothing else in test/ covers validCapacity or isCapacityKey, so this is new coverage, and it reads min, max and values from CAPACITY, so a new key is covered automatically. I could not run the file here because it is not in my checkout, so I judged it by reading. Next, if you want: (1) assert that validCapacity refuses a key's whole-number-looking value with leading zeros only if that is intended ("007" is currently accepted, so pin it either way); (2) add a case that a count value like "+3" is refused.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs