@zalosai/zalos-cli 0.2.34 → 0.2.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,6 +8,8 @@ import { ValidationError } from './errors.js';
8
8
  * for agent-studio's private `zalosai.agent_tools`, writing the same
9
9
  * `OUTPUT_DIR` registration manifest and progress lines the Mesh executor
10
10
  * reads. `inputs/` and `tests/` help the author iterate but are never packed.
11
+ * `tests/cases/` starts with one example that must match and one that must
12
+ * fail, the shape `zl codepack test` runs.
11
13
  */
12
14
  const CODEPACK_NAME_PATTERN = /^[a-z][a-z0-9_]{1,62}$/;
13
15
  function titleCase(name) {
@@ -205,6 +207,22 @@ Acme Ltd,1000.00
205
207
  Globex,500.50
206
208
  Initech,250.00
207
209
  `;
210
+ const SAMPLE_CASE_JSON = `{
211
+ "description": "The sample file: three customers",
212
+ "parameters": { "period_end": "2026-10-31" }
213
+ }
214
+ `;
215
+ const SAMPLE_CASE_EXPECTED = `period_end,rows,total_amount
216
+ 2026-10-31,3,1750.5
217
+ `;
218
+ const NO_AMOUNT_CASE_JSON = `{
219
+ "description": "A file without an Amount column is refused with a clear message",
220
+ "expectError": "No Amount column"
221
+ }
222
+ `;
223
+ const NO_AMOUNT_CSV = `Customer,Total
224
+ Acme Ltd,1000.00
225
+ `;
208
226
  const GITIGNORE = `outputs/
209
227
  __pycache__/
210
228
  .venv/
@@ -228,6 +246,11 @@ export async function scaffoldCodepack(name, directory) {
228
246
  'codepack_runtime.py': RUNTIME_PY,
229
247
  'inputs/sample.csv': SAMPLE_CSV,
230
248
  'tests/test_process.py': TEST_PY,
249
+ 'tests/cases/sample/case.json': SAMPLE_CASE_JSON,
250
+ 'tests/cases/sample/inputs/source/sample.csv': SAMPLE_CSV,
251
+ 'tests/cases/sample/expected/summary.csv': SAMPLE_CASE_EXPECTED,
252
+ 'tests/cases/no_amount/case.json': NO_AMOUNT_CASE_JSON,
253
+ 'tests/cases/no_amount/inputs/source/no_amount.csv': NO_AMOUNT_CSV,
231
254
  '.gitignore': GITIGNORE,
232
255
  };
233
256
  for (const [path, contents] of Object.entries(files)) {
@@ -95,9 +95,12 @@ export async function packCodepack(directory) {
95
95
  * caches, local environments and dotfiles. It always contains the runtime
96
96
  * files, so the server can check it matches the published codepack.
97
97
  */
98
- export async function packCodepackSource(directory) {
99
- const files = [];
100
- await collect(directory, directory, files, [], SOURCE_SELECTION);
98
+ export async function packCodepackSource(directory, options = {}) {
99
+ const collected = [];
100
+ await collect(directory, directory, collected, [], SOURCE_SELECTION);
101
+ const files = options.exclude
102
+ ? collected.filter((file) => !options.exclude(file.path))
103
+ : collected;
101
104
  const archive = buildTarGz(files);
102
105
  if (archive.byteLength > MAX_ARCHIVE_BYTES) {
103
106
  throw new ValidationError('codepack', 'Codepack source exceeds 25 MiB; move large fixtures to Team Files or private/');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zalosai/zalos-cli",
3
- "version": "0.2.34",
3
+ "version": "0.2.36",
4
4
  "description": "API-only product command-line interface for Zalos",
5
5
  "repository": {
6
6
  "type": "git",
@@ -18,12 +18,17 @@ the selected team (`zl team list`, `zl team switch <tm_…>`).
18
18
 
19
19
  1. **Scaffold:** `zl codepack init <snake_name>` creates a runnable folder. It is
20
20
  offline and needs no login.
21
- 2. **Build:** edit `config.yaml` and `process.py`, using the contract below.
22
- 3. **Run locally:** run it on sample files exactly as the executor will:
21
+ 2. **Write the cases first:** for each example you know the right answer to, add a
22
+ folder under `tests/cases/` (see "Test cases" below). The cases are the spec:
23
+ ask the user for a real input and the output they expect, and turn every
24
+ example they give into a case.
25
+ 3. **Build:** edit `config.yaml` and `process.py`, using the contract below, until
26
+ `zl codepack test <folder>` passes. It runs `tests/test_*.py` with pytest, then
27
+ every case, with the folder's `.venv` Python (or `--python <path>`), and names
28
+ each cell, row or key that differs. To look at a run by hand:
23
29
  ```bash
24
30
  cd <snake_name>
25
31
  python process.py inputs/<file> --<parameter> <value> # writes ./outputs
26
- python -m pytest tests
27
32
  ```
28
33
  - **Inputs and tests:** put sample files in `inputs/` and tests in `tests/`.
29
34
  Runs never get them. They are kept with the team's copy of the source, so
@@ -33,9 +38,14 @@ the selected team (`zl team list`, `zl team switch <tm_…>`).
33
38
  `python3.12 -m venv .venv && .venv/bin/pip install pandas openpyxl xlsxwriter pytest`.
34
39
  - **Clean runs:** delete `outputs/` between runs, or set `OUTPUT_DIR` to a fresh
35
40
  folder, so stale files don't hide a missing output.
36
- 4. **Validate:** `zl codepack validate <folder>` checks the config and prints the
41
+ 4. **Test on the production runtime:** `zl --environment <env> codepack test <folder> --remote`
42
+ runs the same tests and cases in Mesh, through the executor a workflow uses, on
43
+ its exact Python and packages. Local Python can differ (for example pandas 3
44
+ locally, pandas 2 in the runtime), so run it before publishing. `--case <name>`
45
+ runs only the named cases.
46
+ 5. **Validate:** `zl codepack validate <folder>` checks the config and prints the
37
47
  `codepack:sha256:…` ref it would publish as, plus the files it packs and skips.
38
- 5. **Publish:**
48
+ 6. **Publish:**
39
49
  - **First time:** `zl --environment <env> codepack publish <folder>` prints a
40
50
  Codepack node to paste into workflow JSON (`zl workflow import`/`update`).
41
51
  - **New version of an existing node:** use
@@ -44,7 +54,7 @@ the selected team (`zl team list`, `zl team switch <tm_…>`).
44
54
  named checkpoint.
45
55
  - **Lineage:** `--parent <codepack ref>` records which version this one was changed
46
56
  from, and `--label` records what changed. `zl codepack info <ref>` shows both.
47
- 6. **Make it live:** a workflow with a published version keeps running that version
57
+ 7. **Make it live:** a workflow with a published version keeps running that version
48
58
  until `zl --environment <env> workflow publish <id> --apply`. Then run it with
49
59
  `zl workflow run <id>`, and check the result with `zl execution view <execution-id>`
50
60
  and `zl file download <output-file-id> --output <path>`.
@@ -52,14 +62,50 @@ the selected team (`zl team list`, `zl team switch <tm_…>`).
52
62
  ### Changing a published codepack
53
63
 
54
64
  `zl --environment <env> codepack source <ref> --output <folder>` downloads the
55
- folder a node pins, tests and sample inputs included, into an empty folder. Edit
56
- it, run its tests, then publish it with `--parent <ref> --label "<what changed>"`.
65
+ folder a node pins, tests and sample inputs included, into an empty folder. Add a
66
+ case for the change, edit until `zl codepack test` passes, then publish it with
67
+ `--parent <ref> --label "<what changed>"`.
57
68
  Codepacks published before sources were kept come back without `tests/` and
58
69
  `inputs/` (`"source": "runtime"`).
59
70
 
60
- Always run locally and validate before publishing. After publishing, run the workflow
71
+ Always pass `zl codepack test`, locally and with `--remote`, and validate before publishing. After publishing, run the workflow
61
72
  once on real inputs and check the outputs before telling the user it works.
62
73
 
74
+ ## Test cases
75
+
76
+ A case is an example input with the output it must produce, in its own folder:
77
+
78
+ ```text
79
+ tests/cases/<case>/
80
+ case.json optional
81
+ inputs/<fileInput>/<file> one file per file input, under its fieldName
82
+ expected/<output>.<ext> the expected content of an output, by fieldName
83
+ ```
84
+
85
+ ```json
86
+ {
87
+ "description": "October close: two vendors below the threshold",
88
+ "parameters": { "period_end": "2026-10-31", "threshold": 2500 }
89
+ }
90
+ ```
91
+
92
+ - **Inputs:** every required file input needs a file, and every required parameter
93
+ a value. File names and extensions reach `process.py` unchanged.
94
+ - **Expected outputs:** `expected/summary.csv` is compared with the output
95
+ registered as `summary`. CSV and TSV are compared cell by cell, `.xlsx` cell by
96
+ cell on every sheet (values and formulas, not styling or metadata), JSON and JSONL
97
+ by value, anything else byte for byte. Outputs without an expected file are not
98
+ compared, but the run must still succeed.
99
+ - **Expected failures:** `"expectError": "No Amount column"` passes only when the run
100
+ fails with a message containing that text. Add one for every input the codepack
101
+ must refuse. Such a case has no `expected/` files.
102
+ - **Real data:** copy a past period's inputs and the output the user signed off into
103
+ a case to pin that behaviour. Cases are kept with the published source
104
+ (`zl codepack source` returns them) but never run in a workflow.
105
+ - **Unit tests:** `tests/test_*.py` still suit small rules such as a date parser.
106
+ When the Mesh runtime has no pytest, only the `tmp_path` fixture is available, so
107
+ keep them to plain functions.
108
+
63
109
  ## The contract
64
110
 
65
111
  ### `config.yaml`
@@ -85,6 +85,17 @@ zl --environment <us-prod|eu-prod> file seed --source-team-id <source-team-ref>
85
85
  zl --environment <us-prod|eu-prod> file seed --source-team-id <source-team-ref> --source-path /Fixtures --target-path /Rehearsal --apply --expected-checksum <sha256>
86
86
  ```
87
87
 
88
+ ## Keep workflow step outputs small
89
+
90
+ When authoring or reviewing a workflow that reads worksheets, loops over rows, or waits for review:
91
+
92
+ 1. Save bulk rows, write plans, and readback evidence once as run-scoped file artifacts. Pass references and only the fields the next step uses, such as worksheet ID, row count, and verification status. Resolve an artifact at the step that consumes it.
93
+ 2. At projection steps, set `includeInputFields: false` on Set nodes and map the required fields explicitly. In Python Code, emit only those fields in each returned item. Check expressions for whole-node reads such as `$('Read Rows').first().json`, especially in loops and before Wait nodes.
94
+ 3. Carry a compact review manifest across a Wait. Preserve the locked environment, the artifact reference and hash, and approved action IDs and hashes where the flow uses them. After a write, retain the verification result and its evidence reference.
95
+ 4. Validate the definition, then run a dedicated test workflow with representative test data and sandbox or mocked write integrations. Exercise approval, resume, and post-write verification. Inspect the largest step outputs and confirm the worksheet data appears only where consumed. `workflow run --dry-run` previews invocation. Measure outputs from the test run.
96
+
97
+ For a workbook verification → journal-source planning handoff, pass the readback artifact reference, worksheet ID, row count, and verification result. The planning node can read the artifact when it needs the rows.
98
+
88
99
  ## Pages and Motion work
89
100
 
90
101
  Pages use Markdown files with a revision marker. Export before editing, then preview