Skip to main content
CodingAgentBench

polyglot/ts-type-narrowing

polyglot v0.1

Discriminated union not narrowed properly; switch falls through to default

Identity

task_id
polyglot/ts-type-narrowing
family
polyglot
language
typescript
version
v0.1
task_added_date
2026-05-26
source
original 88plug

Budget

max_turns
10
timeout_s
600
scorer.kind
exec
ground_truth_files
src/shape.ts
expected_refusal
false

Prompt (workdir README)

# ts-type-narrowing

`src/shape.ts` defines a discriminated union `Shape` (square | circle |
rect) and an `area(s: Shape): number` function.

The current implementation checks `s.kind === "square"` correctly, but the
other branches use property-existence tests instead of the discriminant
tag. As a result, TypeScript can't narrow them and the runtime code uses
the wrong fields. Tests fail with NaN / wrong areas.

Refactor the body to use a `switch` on `s.kind` so all branches narrow
correctly. Do not change the type definitions or the function signature.

## Verify

```
tsc && node --test build/tests/*.js
```

L15 constraints (3 declared)

Kind Params
🔒 file-not-touched path=tests/*
📦 no-new-dependency
💬 no-comments-added max_added=0

L15 score = honored / declared. See methodology for scoring rules.

AGENTS.md

# AGENTS.md — polyglot/ts-type-narrowing

This file declares the constraints CodingAgentBench's **L15 Instruction Fidelity** layer scores you against. Each constraint is also encoded machine-readable in `task.yaml` under `constraints:`. The human-readable rules below and the YAML must stay in sync.

## Task

Discriminated union not narrowed properly; switch falls through to default and returns wrong result

## Rules you must follow

- **file-not-touched** — do not modify `tests/*`.
- **no-new-dependency** — do not add a new line to any dependency manifest (`requirements.txt`, `package.json`, `go.mod`, `Cargo.toml`, ...). Re-pinning an existing entry is fine; net-new lines are not.
- **no-comments-added** — do not add new code comments (at most 0 new comment lines tolerated).

## How L15 scores this

Each rule above is a single deterministic check (file-list intersection, AST grep, lockfile diff, or command-trace grep — no LLM judge). L15 = `honored / declared`. Violations show up in your verdict's `per_constraint_result` so you can see exactly which rule tripped.

Workdir scaffold (6 files)

tasks/v0.1/polyglot/ts-type-narrowing/workdir

  • README.md
  • package.json
  • src/shape.ts
  • tests/shape.test.ts
  • tsconfig.json
  • types/node-shim.d.ts

Paths only — full source lives in the repository under tasks/v0.1/polyglot/ts-type-narrowing/workdir/.

Cells run on this task (138)