P3.1: wire dist CLI into build + test (0100 unblocked)

The sx 0100 fix (cli.parse / json.parse name collision) is merged on sx
master, so `dist.sx` — co-importing std.cli (via dist) and std.json (via
json_out) — now lowers and builds. Finish the step:

- dist.sx: fix two real frontend errors the old IR-lowering crash had
  masked — `main` returns `!` (noreturn exit tails), and the post-parse
  dispatch is guarded by `if !perr` so the failable `p` is used only with
  its error proven absent. Drop the stale BLOCKED narration.
- Makefile: `make build` now also compiles src/dist.sx -> build/dist;
  `make test` depends on `build` so the acceptance test finds the binary.
- tests/cli_dispatch.sx: drives the BUILT build/dist via process.run and
  asserts the std.cli exit-code + --json purity contract: no-args and
  unknown-command -> human text on stderr + EX_USAGE (64); `ci publish
  --json` -> stdout is a single valid JSON object (std.json.parse, no
  trailing junk) with the human ack on stderr; `--help` lists ci/release.

Handlers stay honest stubs (real ci publish is P3.4). Gate green:
make build (build/dist), make test (7/7).
This commit is contained in:
agra
2026-06-06 03:33:20 +03:00
parent 6dc6433c2d
commit c2acd0e449
4 changed files with 119 additions and 21 deletions

View File

@@ -20,14 +20,6 @@
// carries ONLY the machine-readable JSON object (emitted via `std.json`,
// isolated in `json_out.sx`); ALL human-readable text (help, progress,
// errors) goes to stderr. In non-json mode human text on stdout is fine.
//
// NOTE (BLOCKED — see P3.1 worker report): `std.cli` and `std.json` both
// export a top-level `parse`; with both in the compilation closure the sx
// compiler crashes while lowering the `cli.parse` call. `json_out.sx` keeps
// the `std.json` import out of this file, but `sx build` lowers the whole
// transitive closure, so the collision (and crash) persists. This program
// therefore does NOT yet build; it is the intended wiring pending the sx
// fix.
// =====================================================================
#import "modules/std.sx";
@@ -116,7 +108,7 @@ dispatch :: (p: *Parsed, json_mode: bool) {
exit_usage();
}
main :: () -> s32 {
main :: () -> ! {
// Real process argv -> logical args: drop argv[0] (the program path).
storage : [64]string = ---;
argbuf : []string = ---;
@@ -158,6 +150,8 @@ main :: () -> s32 {
exit_usage();
}
dispatch(@p, json_mode);
if !perr {
dispatch(@p, json_mode);
}
exit_ok();
}

View File

@@ -1,12 +1,9 @@
// =====================================================================
// json_out.sx — `--json` mode output for `dist`, built with `std.json`.
//
// Isolated in its own module so the `std.json` writer (which the
// `--json` contract requires) is not imported into the same file as the
// `std.cli` dispatcher. `std.cli` and `std.json` BOTH export a top-level
// `parse`; co-importing them and calling `cli.parse` currently crashes the
// sx compiler's IR lowering (see this step's blocked report). Splitting the
// emission out keeps each file individually well-formed sx.
// The machine-readable JSON object a `--json` run writes to stdout is
// built here, keeping the `std.json` writer in one place, separate from
// the `std.cli` dispatch in dist.sx.
// =====================================================================
#import "modules/std.sx";