Repository navigation
feat(cli): add nano package check and build (#84) - #89
Merged
Merged
Conversation
Contract for check/build/test arguments, exit codes, output framing, diagnostic and report documents, and the strict fixture schema, frozen before any CLI dispatch edit. Adds the agent-package example cases file used as the frozen development set. Refs #84, #67 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Implements the check and build operations of the frozen contract in docs/package-cli.md as a thin adapter over the public compile_package(manifest, lock_path=lock) API. No compiler or runtime code changes. - nano/cli/package.py: new module with reusable helpers for the later `package test` lane (canonical_bytes, compiler_identity, diagnostic_dict, format_diagnostic, build_package -> CompiledPackage | PackageRejection, write_bytes_atomic) plus the check/build commands and argparse wiring. - --manifest and --lock are required; no discovery, no defaults. - PackageError chained to an OSError maps to IO_ERROR/io, span null, exit 3; other rejections exit 1 with their own code (PACKAGE_ERROR reported as category "package"). The OSError rendering in I/O messages is reduced to its strerror so documents never carry absolute paths. - JSON goes through the byte sink: canonical, ASCII, exactly one LF. - build refuses outputs that resolve to the manifest, lock, any manifest source, or each other (exit 2, nothing written); artifacts are staged as sibling temporaries and os.replace'd; failures leave no files and empty stdout. - tests/test_package_cli.py covers CLI==API bytes with pinned hashes, cwd / relocation / reordered-metadata / repeat stability, LF framing in a fresh interpreter, parametrized positioned negative controls, path escapes, no ambient discovery, I/O and usage exits, output safety, read-only inputs and a socket-denied fresh interpreter that loads no qiskit/nano_qsearch/numpy. - Docs: docs/README.md index entry, RFC 0066 deferred note, CLI section in examples/agent-package/README.md, help epilog examples. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review finding: with both -o and --module-output, a failing second os.replace left the first artifact committed. Destinations are now checked (directories refused) before staging, and any output already replaced is restored to its previous bytes or removed, matching the contract that a failed build leaves no partial artifact. Refs #84 Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
First slice of #84 (roadmap #67):
nano package checkandnano package build, a thin CLI over the shippedcompile_packageAPI. No compiler, runtime or IR file changes. The contract was frozen indocs/package-cli.mdbefore dispatch was touched.What changed
nano/cli/package.py(new):check(silent /-v/--jsonNanoPackageCheck 1.0.0) andbuild(canonical NanoPackage envelope to stdout or-o, plus--module-output).--manifestand--lockare required on every action; nothing is discovered or searched for.PackageErrorchained to anOSError).docs/package-cli.md(frozen contract), RFC 0066 deferred-work line,docs/README.mdindex, example README.Frozen inputs (commit
2a60d08):docs/package-cli.mdsha25643e460df…cab74;examples/agent-package/cases.jsonsha2563c97ba80…2abd(the dev set used by PR2).Evidence (base
cb6ea884d63dcaa8cc0e7c0b952bb88784e8219f, headc8c49e5bf903cf9c729b33ae6609bb6448dfb5a7)Missing behaviour at base:
nano package check …→ exit 2invalid choice: 'package'.RED before implementing:
tests/test_package_cli.py45 failed / 5 passed (the 5 are usage-error cases that are trivially exit 2 at base).Focused + compatibility suite (test_package_cli, test_cli, test_package, test_compiler_diagnostics, test_conformance, test_acceptance_parity, test_examples, test_docs):
The failure is pre-existing on base (see Limitations). The skip is test_docs (README advertises no count).
Example identity: CLI bytes ==
canonical(compile_package(...).to_dict()) + "\n"; packageHashsha256:b5f5a854…a099, moduleHashsha256:78031edf…200e; envelope sha2563a1bae4e…1070. Identical from another working directory, after relocation, after reordering metadata keys, and across repeated builds.Negative controls (exit code, code, path, line/column asserted): missing pin, stale pin, duplicate manifest key, duplicate symbol, wrong type, import cycle, recursion, ungranted effect, RESOURCE_LIMIT, unknown field. Rejected: absolute path,
../, symlink escape (actually run, not skipped), an unpinned sibling.nano. I/O (exit 3): missing manifest, lock or source, and a directory given as the manifest.Read-only: package bytes and mtimes unchanged after check, check --json, a failing check, and build -o. A fresh interpreter with sockets disabled leaves
qiskit,nano_qsearchandnumpyunloaded.scripts/check_contribution.py --all: 55 entries ready.Review: an independent reviewer found a partial-write case (
-oplus a--module-outputthat fails to commit). Fixed inc8c49e5with RED (2 failed) then GREEN tests. A suspected symlinked-manifest overlap gap is not reachable: the compiler roots sources atPath(manifest).resolve().parent, which is what the check uses.Iterations: 3 in total, all on the dev set.
No assertion was weakened and no negative control was removed.
Limitations / pre-existing (not changed here)
tests/test_package.py::test_metadata_depth_is_positionedfails on Python ≥3.12 at base too:json.loadsno longer raises RecursionError at depth 2000 (3.10 and 3.11 do). Owner: the compiler lane.IRValidationErrorraised after lowering is not mapped (unreachable: the API re-validates throughNanoModule.from_dict).initandfmtremain deferred.Refs #84, #67
🤖 Generated with Claude Code