=== BEGIN ARTIFACT FEATURE-FreqMode.md ===
# FEATURE: Frequency Mode
| Field | Value |
|-------------|-------|
| Version | 20261025 V1 |
| Description | Dispatches `csvstat --freq <name> [--top <n>] <file>` to the frequency listing instead of the profile. |
| Depends On | FEATURE-FreqLimit.md, FEATURE-UsageErrors.md |
| Provides | csvstat --freq, csvstat --freq --top |
| Consumes | freq.Count, freq.Top, cli.ParseArgs |
## Questions
- None.
## Purpose
When `--freq <name>` is given, `cli.Run` writes the frequency listing for that column and never the profile. `--top <n>` limits the rows and defaults to 5. The listing is CSV with header `value,count`, rows ordered by count descending and then value ascending by byte value, using trimmed non-null values only.
## Behavior
- The column name is matched exactly and case-sensitively against the trimmed header.
- A column name absent from the header exits 3 with nothing on standard output and one diagnostic line on standard error.
- Combinations that are usage errors (`--column` with `--freq`, `--top` without `--freq`, a non-positive `--top`) are rejected with exit 2 by the usage-errors story before this dispatch runs.
- Output is built in memory and written to standard output only on success, so a failing command writes nothing to standard output.
- A column with no non-null values writes only the header.
## Programmatic Acceptance
=== AC freq-default-matches-fixture ===
Intent: The default frequency listing for a named column equals the top five counts computed independently from the fixture.
Requires: executable=go; scope=test
import csv
import io
from collections import Counter
from drydock_go import cli_runner
path = "sources/employees.csv"
column = "department"
with open(path, newline="", encoding="utf-8") as fh:
records = list(csv.reader(fh))
header = [h.strip() for h in records[0]]
idx = header.index(column)
values = [r[idx].strip() for r in records[1:] if r[idx].strip() != ""]
counts = Counter(values)
ordered = sorted(counts.items(), key=lambda kv: (-kv[1], kv[0].encode("utf-8")))
expected = [[v, str(c)] for v, c in ordered][:5]
code, out, err = cli_runner("--freq", column, path)
print(out)
print(err)
assert code == 0, code
rows = list(csv.reader(io.StringIO(out)))
assert rows[0] == ["value", "count"], rows[0]
assert rows[1:] == expected, (rows[1:], expected)
=== END AC freq-default-matches-fixture ===
=== AC freq-top-limits-rows ===
Intent: With --top 2 exactly the first two ordered rows are listed.
Requires: executable=go; scope=test
import csv
import io
from collections import Counter
from drydock_go import cli_runner
path = "sources/sensors.csv"
column = "sensor"
top = 2
with open(path, newline="", encoding="utf-8") as fh:
records = list(csv.reader(fh))
header = [h.strip() for h in records[0]]
idx = header.index(column)
values = [r[idx].strip() for r in records[1:] if r[idx].strip() != ""]
counts = Counter(values)
ordered = sorted(counts.items(), key=lambda kv: (-kv[1], kv[0].encode("utf-8")))
expected = [[v, str(c)] for v, c in ordered][:top]
code, out, err = cli_runner("--freq", column, "--top", str(top), path)
print(out)
print(err)
assert code == 0, code
rows = list(csv.reader(io.StringIO(out)))
assert len(rows) - 1 == top, rows
assert rows[1:] == expected, (rows[1:], expected)
=== END AC freq-top-limits-rows ===
=== AC freq-omits-null-spellings ===
Intent: Null values (empty, NA, N/A, NULL in any case) are not listed in a frequency listing.
Requires: executable=go; scope=test
import csv
import io
from collections import Counter
from drydock_go import cli_runner
path = "sources/employees.csv"
column = "manager_id"
top = 3
nulls = {"", "na", "n/a", "null"}
with open(path, newline="", encoding="utf-8") as fh:
records = list(csv.reader(fh))
header = [h.strip() for h in records[0]]
idx = header.index(column)
values = [r[idx].strip() for r in records[1:] if r[idx].strip().lower() not in nulls]
counts = Counter(values)
ordered = sorted(counts.items(), key=lambda kv: (-kv[1], kv[0].encode("utf-8")))
expected = [[v, str(c)] for v, c in ordered][:top]
code, out, err = cli_runner("--freq", column, "--top", str(top), path)
print(out)
print(err)
assert code == 0, code
rows = list(csv.reader(io.StringIO(out)))
listed = {r[0].lower() for r in rows[1:]}
assert listed.isdisjoint(nulls), listed
assert rows[1:] == expected, (rows[1:], expected)
=== END AC freq-omits-null-spellings ===
=== AC freq-values-are-trimmed ===
Intent: Padded values are trimmed before counting, so padded and unpadded spellings count together.
Requires: executable=go; scope=test
import csv
import io
from collections import Counter
from drydock_go import cli_runner
path = "sources/orders.csv"
column = "customer"
with open(path, newline="", encoding="utf-8") as fh:
records = list(csv.reader(fh))
header = [h.strip() for h in records[0]]
idx = header.index(column)
values = [r[idx].strip() for r in records[1:] if r[idx].strip() != ""]
counts = Counter(values)
ordered = sorted(counts.items(), key=lambda kv: (-kv[1], kv[0].encode("utf-8")))
expected = [[v, str(c)] for v, c in ordered][:5]
code, out, err = cli_runner("--freq", column, path)
print(out)
print(err)
assert code == 0, code
rows = list(csv.reader(io.StringIO(out)))
assert rows[1:] == expected, (rows[1:], expected)
=== END AC freq-values-are-trimmed ===
=== AC freq-all-null-column-header-only ===
Intent: A column with no non-null values lists only the header.
Requires: executable=go; scope=test
import csv
import io
from drydock_go import cli_runner
code, out, err = cli_runner("--freq", "battery", "sources/sensors.csv")
print(out)
print(err)
assert code == 0, code
rows = list(csv.reader(io.StringIO(out)))
assert rows == [["value", "count"]], rows
=== END AC freq-all-null-column-header-only ===
=== AC freq-unknown-column-rejected ===
Intent: A column name absent from the header exits 3 and writes nothing to standard output.
Requires: executable=go; scope=test
from drydock_go import cli_runner
code, out, err = cli_runner("--freq", "nosuch", "sources/orders.csv")
print(out)
print(err)
assert code == 3, code
assert out == "", out
=== END AC freq-unknown-column-rejected ===
=== AC freq-name-is-case-sensitive ===
Intent: A column name differing only in case from a header name is not found and exits 3.
Requires: executable=go; scope=test
import csv
from drydock_go import cli_runner
path = "sources/employees.csv"
with open(path, newline="", encoding="utf-8") as fh:
header = [h.strip() for h in next(csv.reader(fh))]
name = header[2]
swapped = name.upper() if name != name.upper() else name.lower()
assert swapped not in header
code, out, err = cli_runner("--freq", swapped, path)
print(out)
print(err)
assert code == 3, code
assert out == "", out
=== END AC freq-name-is-case-sensitive ===
## User Acceptance
- None.
## Guardrails
- Frequency mode never writes the profile header or any profile row.
- Application code never reads `sources/run.sh` or embeds a count or value list; every row comes from the file examined.
- A failing command writes nothing to standard output.
=== END ARTIFACT ===
=== BEGIN ARTIFACT FEATURE-FailureDiagnostics.md ===
# FEATURE: Failure Diagnostics
| Field | Value |
|-------------|-------|
| Version | 20261025 V1 |
| Description | Ensures every failing csvstat command writes nothing to standard output and exactly one diagnostic line to standard error. |
| Depends On | FEATURE-InputRejection.md, FEATURE-UsageErrors.md, FEATURE-ProfileOutput.md |
| Provides | stderr diagnostics, exit code 3 |
| Consumes | csvdata.ErrRejected, cli.Run |
## Questions
- None.
## Purpose
A command that fails reports the failure on standard error as one line and leaves standard output empty. Rejected input exits 3. The diagnostic names the file and, for a rejected record, its line number. Standard error is never compared by the grader, so its wording is free; its shape (one line, nothing on standard output) is the contract.
## Behavior
- Rejected input (empty file, file containing only blank lines, empty header name, repeated header name, ragged record) exits 3.
- Standard output is written only after the whole result is built, so no partial output precedes a failure.
- Exactly one non-blank line is written to standard error per failure.
- A ragged record's diagnostic includes the line number of the offending record.
- Exit code 1 (unreadable file) and exit code 2 (usage) share the same stdout-empty, one-line-stderr rule and are owned by their own stories.
## Programmatic Acceptance
=== AC diag-ragged-fixture ===
Intent: The supplied ragged fixture exits 3, writes nothing to standard output, and writes one diagnostic line.
Requires: executable=go; scope=test
from drydock_go import cli_runner
code, out, err = cli_runner("sources/ragged.csv")
print(out)
print(err)
assert code == 3, code
assert out == "", out
lines = [ln for ln in err.splitlines() if ln.strip()]
assert len(lines) == 1, lines
=== END AC diag-ragged-fixture ===
=== AC diag-ragged-line-number ===
Intent: The diagnostic for a ragged record carries the number of the line holding that record.
Requires: executable=go; scope=test
import csv
import os
import re
import tempfile
from drydock_go import cli_runner
rows = [["a", "b"], ["1", "2"], ["3", "4"], ["5", "6", "7"], ["8", "9"]]
bad_line = 4
with tempfile.TemporaryDirectory() as tmp:
path = os.path.join(tmp, "ragged_case.csv")
with open(path, "w", newline="", encoding="utf-8") as fh:
csv.writer(fh, lineterminator="\n").writerows(rows)
code, out, err = cli_runner(path)
print(out)
print(err)
assert code == 3, code
assert out == "", out
assert str(bad_line) in re.findall(r"\d+", err), err
=== END AC diag-ragged-line-number ===
=== AC diag-empty-file ===
Intent: An empty file is rejected with exit 3 and nothing on standard output.
Requires: executable=go; scope=test
import os
import tempfile
from drydock_go import cli_runner
with tempfile.TemporaryDirectory() as tmp:
path = os.path.join(tmp, "empty.csv")
with open(path, "w", encoding="utf-8") as fh:
fh.write("")
code, out, err = cli_runner(path)
print(out)
print(err)
assert code == 3, code
assert out == "", out
lines = [ln for ln in err.splitlines() if ln.strip()]
assert len(lines) == 1, lines
=== END AC diag-empty-file ===
=== AC diag-blank-lines-only ===
Intent: A file containing only blank lines is rejected as empty with exit 3.
Requires: executable=go; scope=test
import os
import tempfile
from drydock_go import cli_runner
with tempfile.TemporaryDirectory() as tmp:
path = os.path.join(tmp, "blank.csv")
with open(path, "w", encoding="utf-8", newline="") as fh:
fh.write("\n\n\n")
code, out, err = cli_runner(path)
print(out)
print(err)
assert code == 3, code
assert out == "", out
=== END AC diag-blank-lines-only ===
=== AC diag-empty-header-name ===
Intent: An empty header name is rejected with exit 3 and nothing on standard output.
Requires: executable=go; scope=test
import csv
import os
import tempfile
from drydock_go import cli_runner
rows = [["a", "", "c"], ["1", "2", "3"]]
with tempfile.TemporaryDirectory() as tmp:
path = os.path.join(tmp, "emptyname.csv")
with open(path, "w", newline="", encoding="utf-8") as fh:
csv.writer(fh, lineterminator="\n").writerows(rows)
code, out, err = cli_runner(path)
print(out)
print(err)
assert code == 3, code
assert out == "", out
=== END AC diag-empty-header-name ===
=== AC diag-repeated-header-name ===
Intent: A repeated header name, including one repeated only after trimming, is rejected with exit 3.
Requires: executable=go; scope=test
import csv
import os
import tempfile
from drydock_go import cli_runner
name = "dup"
rows = [[name, "x", " " + name + " "], ["1", "2", "3"]]
with tempfile.TemporaryDirectory() as tmp:
path = os.path.join(tmp, "repeated.csv")
with open(path, "w", newline="", encoding="utf-8") as fh:
csv.writer(fh, lineterminator="\n").writerows(rows)
code, out, err = cli_runner(path)
print(out)
print(err)
assert code == 3, code
assert out == "", out
=== END AC diag-repeated-header-name ===
=== AC diag-failure-with-column-option ===
Intent: A rejected file under --column still exits 3 with nothing on standard output.
Requires: executable=go; scope=test
from drydock_go import cli_runner
code, out, err = cli_runner("--column", "sku", "sources/ragged.csv")
print(out)
print(err)
assert code == 3, code
assert out == "", out
=== END AC diag-failure-with-column-option ===
## User Acceptance
- None.
## Guardrails
- A failing command never writes a partial profile or frequency listing to standard output.
- Diagnostics go to standard error only and are never compared by the grader.
- Rejected files are never modified.
=== END ARTIFACT ===
=== BEGIN ARTIFACT FEATURE-UnreadableFile.md ===
# FEATURE: Unreadable File
| Field | Value |
|-------------|-------|
| Version | 20261025 V1 |
| Description | Exits 1 with an empty standard output when the named file cannot be opened or read. |
| Depends On | FEATURE-FailureDiagnostics.md |
| Provides | exit code 1 |
| Consumes | cli.Run, csvdata.Read |
## Questions
- None.
## Purpose
Exit code 1 is the operational-failure code. It is used when the file named on the command line does not exist, is not permitted to be read, or fails while being read. It is distinct from exit 3, which means the file was read but its content was rejected.
## Behavior
- An open or read error from the operating system maps to exit 1, not exit 3.
- Standard output stays empty.
- One diagnostic line naming the file is written to standard error.
- This applies to every invocation form: profile, `--column`, and `--freq`.
- Usage errors (exit 2) take precedence over file access, because argument parsing completes before the file is opened.
## Programmatic Acceptance
=== AC unreadable-missing-file ===
Intent: A path that does not exist exits 1 and writes nothing to standard output.
Requires: executable=go; scope=test
import os
import tempfile
from drydock_go import cli_runner
with tempfile.TemporaryDirectory() as tmp:
missing = os.path.join(tmp, "no-such-file.csv")
assert not os.path.exists(missing)
code, out, err = cli_runner(missing)
print(out)
print(err)
assert code == 1, code
assert out == "", out
lines = [ln for ln in err.splitlines() if ln.strip()]
assert len(lines) == 1, lines
=== END AC unreadable-missing-file ===
=== AC unreadable-missing-file-freq ===
Intent: A missing file under --freq also exits 1 with nothing on standard output.
Requires: executable=go; scope=test
import os
import tempfile
from drydock_go import cli_runner
with tempfile.TemporaryDirectory() as tmp:
missing = os.path.join(tmp, "absent.csv")
code, out, err = cli_runner("--freq", "anything", missing)
print(out)
print(err)
assert code == 1, code
assert out == "", out
=== END AC unreadable-missing-file-freq ===
=== AC unreadable-missing-file-column ===
Intent: A missing file under --column also exits 1 with nothing on standard output.
Requires: executable=go; scope=test
import os
import tempfile
from drydock_go import cli_runner
with tempfile.TemporaryDirectory() as tmp:
missing = os.path.join(tmp, "absent.csv")
code, out, err = cli_runner("--column", "anything", missing)
print(out)
print(err)
assert code == 1, code
assert out == "", out
=== END AC unreadable-missing-file-column ===
=== AC unreadable-directory-as-file ===
Intent: A directory named as the file cannot be read and exits 1 with nothing on standard output.
Requires: executable=go; scope=test
import tempfile
from drydock_go import cli_runner
with tempfile.TemporaryDirectory() as tmp:
code, out, err = cli_runner(tmp)
print(out)
print(err)
assert code == 1, code
assert out == "", out
=== END AC unreadable-directory-as-file ===
=== AC unreadable-readable-file-still-succeeds ===
Intent: A readable fixture is not treated as unreadable and exits 0.
Requires: executable=go; scope=test
from drydock_go import cli_runner
code, out, err = cli_runner("sources/header_only.csv")
print(out)
print(err)
assert code == 0, code
assert out != ""
=== END AC unreadable-readable-file-still-succeeds ===
## User Acceptance
- None.
## Guardrails
- Exit 1 is reserved for files that cannot be opened or read; rejected content is exit 3.
- A failing command writes nothing to standard output.
=== END ARTIFACT ===
=== BEGIN ARTIFACT FEATURE-TestGate.md ===
# FEATURE: Test Gate
| Field | Value |
|-------------|-------|
| Version | 20261025 V1 |
| Description | Provides the POSIX `bin/test.sh` that runs `go vet ./...` and `go test ./...` and exits zero only when both pass. |
| Depends On | FEATURE-ColumnProfile.md, FEATURE-FreqMode.md, FEATURE-UnreadableFile.md |
| Provides | bin/test.sh |
| Consumes | csvstat command, go vet, go test |
## Questions
- None.
## Purpose
`bin/test.sh` is the project's single test entry point. It is a POSIX `sh` script that changes to the application root, runs `go vet ./...`, then `go test ./...`, and exits non-zero if either fails. The project suite, written beside the code, covers each type, each statistic, null handling, rounding, each output form, and each exit code, using files the tests write to temporary directories.
## Behavior
- The script uses only POSIX `sh` constructs and resolves the application root from its own location, so it works from any current directory.
- It runs `go vet ./...` first and stops with a non-zero status if vet fails.
- It then runs `go test ./...` and exits with that command's status.
- It never modifies files under `sources/`.
- The suite covers:
- every column type (integer, number, date, boolean, text, empty);
- rows, nulls, distinct, min, max, sum, mean, and median;
- null spellings and trimming;
- half-away-from-zero rounding and no negative zero;
- the profile form, the `--column` form, and the `--freq` form;
- exit codes 0, 1, 2, and 3.
## Programmatic Acceptance
=== AC testgate-script-exits-zero ===
Intent: Running bin/test.sh from the application root exits zero.
Requires: executable=go; scope=test
import subprocess
result = subprocess.run(["sh", "bin/test.sh"], capture_output=True, text=True)
print(result.stdout)
print(result.stderr)
assert result.returncode == 0, result.returncode
=== END AC testgate-script-exits-zero ===
=== AC testgate-runs-from-other-directory ===
Intent: bin/test.sh locates the application root itself and exits zero when started from another directory.
Requires: executable=go; scope=test
import os
import subprocess
import tempfile
script = os.path.abspath("bin/test.sh")
with tempfile.TemporaryDirectory() as tmp:
result = subprocess.run(["sh", script], capture_output=True, text=True, cwd=tmp)
print(result.stdout)
print(result.stderr)
assert result.returncode == 0, result.returncode
=== END AC testgate-runs-from-other-directory ===
=== AC testgate-go-test-and-vet-pass ===
Intent: go vet and go test pass directly at the application root, the two commands the script wraps.
Requires: executable=go; scope=test
import subprocess
vet = subprocess.run(["go", "vet", "./..."], capture_output=True, text=True)
print(vet.stdout)
print(vet.stderr)
assert vet.returncode == 0, vet.returncode
tests = subprocess.run(["go", "test", "./..."], capture_output=True, text=True)
print(tests.stdout)
print(tests.stderr)
assert tests.returncode == 0, tests.returncode
=== END AC testgate-go-test-and-vet-pass ===
=== AC testgate-suite-has-tests ===
Intent: The project ships Go test files in more than one internal package, so the gate is not vacuous.
Requires: executable=go; scope=test
import pathlib
root = pathlib.Path("internal")
test_files = sorted(root.rglob("*_test.go"))
packages = {p.parent for p in test_files}
print([str(p) for p in test_files])
assert len(test_files) > 0
assert len(packages) > 1, packages
=== END AC testgate-suite-has-tests ===
## User Acceptance
- None.
## Guardrails
- `bin/test.sh` never edits, regenerates, or substitutes any file under `sources/`.
- The test suite never reads `sources/run.sh` and never embeds a grader answer.
- Tests write their own input files to temporary directories.
=== END ARTIFACT ===
=== BEGIN ARTIFACT VERIFICATION.md ===
# FEATURE: Release Verification
| Field | Value |
|-------------|-------|
| Version | 20261025 V1 |
| Description | Terminal assembly story that passes the supplied grader `sources/run.sh` with every one of its 22 checks. |
| Depends On | FEATURE-TestGate.md, FEATURE-ColumnProfile.md, FEATURE-FreqMode.md, FEATURE-UnreadableFile.md |
| Provides | sh sources/run.sh |
| Consumes | csvstat command, bin/test.sh |
## Questions
- None.
## Purpose
This is the terminal story. After every member story has closed, the supplied grader runs unfiltered. The grader builds `./cmd/csvstat` with `go build`, makes 22 checks of exit code and standard output against five supplied CSV files, and exits zero only when the build succeeds and every check passes.
## Behavior
- The grader is run exactly as supplied: `sh sources/run.sh` from the application root.
- Its exit status is the whole verdict.
- A failure is repaired in the owning application package, never in `sources/`.
## Programmatic Acceptance
=== AC release-grader-passes ===
Intent: The supplied grader sources/run.sh, run unfiltered, exits zero.
Suite: full
Requires: executable=go; scope=test
import subprocess
result = subprocess.run(["sh", "sources/run.sh"], capture_output=True, text=True)
print(result.stdout)
print(result.stderr)
assert result.returncode == 0, result.returncode
=== END AC release-grader-passes ===
## User Acceptance
- None.
## Guardrails
- Do not modify, rewrite, regenerate, or substitute any file under `sources/`.
- Application code never reads `sources/run.sh` or any supplied data file, and never hardcodes a statistic, a type, or a value list.
=== END ARTIFACT ===Run artifact