Files
bytecii 73f5bd7c21 chore: cleanup items 31+32 — nested-function rule, layout, CI audit, ls facets
Closes the two remaining small items of Block E. Both were largely
recon: much of what they filed had already been fixed, and the part
that had not turned up a real GNU divergence.

Item 31 (T3-7), rule/doc reconciliation
---------------------------------------

The `object`-parameter half is already done: #825's mypy inversion took
the package from the filed 28 down to 7, of which 3 are docstring prose
and the remaining 4 are protocol methods (`__contains__`, `pop`) whose
signatures typeshed dictates, all already listed in the no-object gate.
`utils/errors.py` reads `str | PathSpec` today, and `builders/sed.py` no
longer holds flag values at all -- item 22 moved that to the generic.

That left the nested-function rule, which the plan asked to decide
before gating. Measured: 39 nested defs, and **every one of them closes
over its enclosing scope** -- 38 by free variable, and `sed_helper._repl`
by binding through parameter defaults, the loop-variable idiom, with a
comment saying so. A flat "do not nest" is a rule the architecture
cannot keep (op factories, provision builders, the read-through cache,
every decorator's wrapper), so gating it as written would have meant 39
standing violations.

So the rule now says what it was reaching for: a nested def must capture
the scope around it, or it belongs at module level. That is mechanical
and enforceable -- `tests/test_nested_functions_are_closures.py` reads
free variables from `symtable` and parameter defaults from the AST. It
passes on the tree as-is and fires on a helper that reads only its own
arguments.

Layout: the eight test-only TS directories are flattened
(`ram/{cat,cut,grep,head,ls,tail,wc}/`, `ssh/ls/`), `awk_helper.ts` moves
up beside its nine siblings, and the `provision.ts` / `_provision.ts`
split is settled on Python's convention -- `_provision` for a backend's
own, bare `provision` for the shared ones (cli, generic_bind). That last
one was not cosmetic: Python already had `_provision.py` for github,
gmail, redis and email, so renaming **closed 4 real parity divergences**
(layout baseline 296 -> 292). The `findEval`/`findParse` line was
already done in #827.

Item 32 (T3-8), test/CI tidiness
--------------------------------

The two asymmetric `ls` conformance matrices are raised to symmetry, and
they pass: python `[ram,disk,redis]` vs typescript `[ram]` was stale
caution, not a divergence. Both runners now reject an asymmetric matrix
at load time unless the case carries a `divergence` key explaining why --
a case is a parity claim, and narrowing one side reads as coverage while
the side that still lists the backend goes green. Loading the corpus
under the new assertion proves no other case was asymmetric. The README
documented the override as "not yet needed"; it exists now.

Adds the `ts-audit` job, mirroring `test_python.yml`'s exactly (same
`continue-on-error`, same out-of-gate placement). Nothing ran `pnpm
audit` for the TS tree while `typescript/package.json` carried 27
hand-written CVE overrides that only a person remembering to check kept
current.

Integ facets for `ls`: `-A`, `-d`, `-r`, `-S`, `-h`, all pinned against
GNU coreutils 9.7 in docker. `-S` uses regular files only, because GNU
sorts a directory by its inode size while mirage counts it as 0 -- a
divergence CLAUDE.md documents deliberately.

The `-h` facet found a real bug
-------------------------------

`ls -h` disagreed with GNU three ways, and because the flag had zero
cross-backend coverage nothing caught it. GNU prints a count below one
unit with no suffix (`24`); mirage printed `24B`. GNU rounds *up* to the
precision shown (1025 bytes is `1.1K`); mirage gave `1.0K`. GNU drops
the decimal once the value reaches ten (`10K`); mirage gave `10.0K`.

One shared engine replaces both formatters in both languages -- GNU runs
`-h` and `-H` through one `human_readable`, and so do we now. Rounding
up can carry past the base (1048575 ceils to 1024K, which GNU shows as
`1.0M`), so the unit is re-chosen after rounding rather than once up
front. 21 GNU-read points are pinned as a table in each language.

Blast radius, all re-pinned: five integ cases that had recorded the `B`
suffix (du, discord, langfuse, email, gmail), and the du fan-out tests.
Those last ones needed care rather than a new number: they exist to
prove the total is humanized once instead of twice, and their 1500+1500
stops discriminating under correct rounding, since 3000 bytes and two
`1.5K` readings both render `3.0K`. They now use 1025+1025, where
single-rounding gives `2.1K` and double-rounding would give `2.2K`.

Verified: pre-commit clean, integ 8054/0 on ram+disk+redis in both
languages, conformance green in both, and the layout, spec, barrel,
docs, case-target and PathSpec gates all pass.

Not covered, still open on item 32: integ facets for `ls -t` (mtime
order is not stable across backends without a seeded fixture), mktemp,
gzip, the checksum `--check` companions, `df -H/-k/-a`, and `cmp
-n/-b/-i`; and the T2-7 helper unit-suite mirroring. Item 31 leaves the
provision *presence* sets unreconciled (Python has lancedb/qdrant, TS has
trello) -- that is a question about which backends should provision at
all, not about naming.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-16 06:57:08 -07:00
..

Command Conformance Spec

One declarative spec for command behavior, run by both the Python and TypeScript implementations (issue #151). Each case pins the exact bytes of stdout, the exact bytes of stderr, and the exit code — so trailing newlines, empty output, and binary output are all part of the contract.

Runners

  • Python: python/tests/conformance/test_conformance.py runs every case against ram and disk, plus redis when REDIS_URL is set. Runs as part of uv run pytest.
  • TypeScript: typescript/packages/node/src/conformance.test.ts runs the same matrix — ram and disk, plus redis when REDIS_URL is set. Runs as part of pnpm test.

Both CI test jobs provide a redis:7 service and set REDIS_URL, so the redis rows run there rather than skipping.

A third runner, integ/runners/parity.py, is a different net: instead of checking each language against a fixed expectation, it runs both integ batteries over the shared targets (ram, disk, redis) and diffs them case by case, so a change that breaks identically in both languages still fails. CI runs it as the integ-shared-parity job.

Files

  • seeds.json — files written into the workspace before every case, via the ops/fs write API (not shell commands). Values are {"text": ...} for UTF-8 content or {"base64": ...} for binary content.
  • cases/<command>.json — cases for one command:
{
  "command": "wc",
  "cases": [
    {
      "id": "wc_default",
      "cmd": "wc /data/a.txt",
      "matrix": {
        "python": ["ram", "disk", "redis"],
        "typescript": ["ram", "disk", "redis"]
      },
      "expect": {
        "exit": 0,
        "stdout_text": " 5  5 24 /data/a.txt\n",
        "stderr_text": ""
      }
    }
  ]
}
  • stdout / stderr use exactly one of *_text (UTF-8) or *_base64 (arbitrary bytes). Trailing newlines are significant.
  • stdin_text / stdin_base64 optionally feed stdin to the command.
  • matrix is explicit: a case runs only on the listed backends. Listing a backend is a claim of support — a missing command there is a failure, not a skip. A case whose matrix is empty is a load-time error in both runners.
  • The two languages must list the same backends. A case is a parity claim, so narrowing one side reads as coverage while it is really an unexamined divergence — and it goes unnoticed, because the side that still lists the backend passes. Both runners reject an asymmetric matrix at load time.
  • divergence is the override: a string saying why one language cannot run the case everywhere the other does. Setting it permits an asymmetric matrix, and it is the only thing that does.

Policy

  • One expected value per case. If a backend or language legitimately diverges, that divergence is triaged first: either it is a bug (fix the implementation) or it is intended semantics, recorded in the case's divergence key so the narrowing is stated rather than inferred from a short matrix.
  • This spec is an acceptance/parity net, not a replacement for backend tests. API call counts, pushdown/fallback, cache invalidation, error injection, and concurrency stay in hand-written per-backend tests.
  • spec/ (command definitions exported from the registries) is a different artifact: it describes the command surface; this folder describes command behavior.

Adding a backend

Add a backend when its command behavior should be compared against the same expectations as the existing implementations:

  1. Add its name to SUPPORTED_MATRIX in the Python and/or TypeScript runner.

  2. Add runner setup that constructs a fresh workspace and resets backend state between cases.

  3. For API-backed resources, use mocked clients with payloads shaped like real provider responses. Do not call live APIs from this suite.

  4. Add the backend to the applicable case matrices:

    "matrix": {
      "python": ["ram", "disk", "redis", "github"],
      "typescript": ["ram", "disk", "redis", "github"]
    }
    
  5. Run the focused Python and TypeScript conformance tests.

Both runners are discovered by the existing Python and TypeScript CI test jobs; no workflow change is required.

Only add a backend to a case when both should produce the same exact stdout, stderr, and exit code. Keep provider-specific API calls, cache behavior, error injection, and concurrency in backend tests.