From e5c0a4fe0cb3f02134a4a0308fccb6a2b9c440f6 Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Tue, 17 Nov 2026 20:46:53 +0000 Subject: [PATCH] feat: document and validate --json for scriptable commands Add JSON Schema files for why, history, loads, runs, used, usage and pending, wire loads, runs and pending to opt-in --json output, and check every document in tests/test_json_schemas.sh. --- .github/workflows/ci.yml | 3 +- build.zig | 6 + changelog.d/+json-schemas.feature.md | 1 + docs/orgmode/reference/cli.org | 41 ++++-- docs/orgmode/reference/index.org | 1 + docs/orgmode/reference/json-schemas.org | 27 ++++ .../reference/json/history.schema.json | 43 +++++++ docs/orgmode/reference/json/loads.schema.json | 30 +++++ .../reference/json/pending.schema.json | 27 ++++ docs/orgmode/reference/json/runs.schema.json | 30 +++++ docs/orgmode/reference/json/usage.schema.json | 35 +++++ docs/orgmode/reference/json/used.schema.json | 32 +++++ docs/orgmode/reference/json/why.schema.json | 59 +++++++++ eb-keep-logs | 12 +- src/loads.zig | 70 ++++++++-- src/main.zig | 12 +- src/pending.zig | 98 ++++++++++---- src/runs.zig | 120 ++++++++++++++---- tests/json_schema_validate.py | 32 +++++ tests/test_json_schemas.sh | 69 ++++++++++ 20 files changed, 669 insertions(+), 79 deletions(-) create mode 100644 changelog.d/+json-schemas.feature.md create mode 100644 docs/orgmode/reference/json-schemas.org create mode 100644 docs/orgmode/reference/json/history.schema.json create mode 100644 docs/orgmode/reference/json/loads.schema.json create mode 100644 docs/orgmode/reference/json/pending.schema.json create mode 100644 docs/orgmode/reference/json/runs.schema.json create mode 100644 docs/orgmode/reference/json/usage.schema.json create mode 100644 docs/orgmode/reference/json/used.schema.json create mode 100644 docs/orgmode/reference/json/why.schema.json create mode 100755 tests/json_schema_validate.py create mode 100755 tests/test_json_schemas.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2fefe77..e81d7ee 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,6 +35,7 @@ jobs: with: version: 0.17.1 - run: zig fmt --check build.zig build.zig.zon src - - run: shellcheck -S warning tests/differential.sh tests/test_why.sh + - run: shellcheck -S warning tests/differential.sh tests/test_why.sh tests/test_json_schemas.sh + - run: pip install jsonschema - run: zig build test --summary all - run: zig build -Drelease=true -Dcommit=${{ github.sha }} && zig-out/bin/eb-keep-logs --version diff --git a/build.zig b/build.zig index 4d70567..ad7027d 100644 --- a/build.zig +++ b/build.zig @@ -92,6 +92,11 @@ pub fn build(b: *std.Build) void { pending_test.setCwd(b.path(".")); pending_test.expectExitCode(0); pending_test.has_side_effects = true; + const json_schema_test = b.addSystemCommand(&.{ "bash", "-c", "TOOL_BIN=\"$0\" exec bash tests/test_json_schemas.sh" }); + json_schema_test.addArtifactArg(exe); + json_schema_test.setCwd(b.path(".")); + json_schema_test.expectExitCode(0); + json_schema_test.has_side_effects = true; const test_step = b.step("test", "Run the unit tests, the command-line suites and the differential run"); test_step.dependOn(&b.addRunArtifact(unit).step); @@ -104,4 +109,5 @@ pub fn build(b: *std.Build) void { test_step.dependOn(&used_test.step); test_step.dependOn(&usage_test.step); test_step.dependOn(&pending_test.step); + test_step.dependOn(&json_schema_test.step); } diff --git a/changelog.d/+json-schemas.feature.md b/changelog.d/+json-schemas.feature.md new file mode 100644 index 0000000..3ccf933 --- /dev/null +++ b/changelog.d/+json-schemas.feature.md @@ -0,0 +1 @@ +`loads`, `runs` and `pending` accept opt-in `--json` with `schema_version` 1. JSON Schema files under `docs/orgmode/reference/json/` describe every `--json` document (`why`, `history`, `loads`, `runs`, `used`, `usage`, `pending`). `tests/test_json_schemas.sh` validates command output against those schemas in CI. \ No newline at end of file diff --git a/docs/orgmode/reference/cli.org b/docs/orgmode/reference/cli.org index 0e733dc..59bb383 100644 --- a/docs/orgmode/reference/cli.org +++ b/docs/orgmode/reference/cli.org @@ -14,11 +14,11 @@ eb-keep-logs failed [--syslog TARGET] STATUS NAME LOGDIR [TMP_LOGDIR] eb-keep-logs rotate ROOT --compress-after DAYS [--delete-after DAYS] [--lock-timeout SECONDS] [--syslog TARGET] eb-keep-logs why [RUN | --latest] [--target TARGET] [--root ROOT] [--json] eb-keep-logs history PACKAGE [--target TARGET] [--root ROOT] [--json] -eb-keep-logs loads --module NAME FILE -eb-keep-logs runs --exec PATH FILE +eb-keep-logs loads --module NAME [--json] FILE +eb-keep-logs runs --exec PATH [--json] FILE eb-keep-logs used --prefix PREFIX [--json] [--require-none] FILE... eb-keep-logs usage --software DIR --modules DIR [--since EPOCH] [--unused | --active] [--json] FILE... -eb-keep-logs pending FILE +eb-keep-logs pending [--json] FILE eb-keep-logs -h | --help eb-keep-logs --version #+end_example @@ -46,7 +46,7 @@ eb-keep-logs --version | =--latest= | =why= | Read the newest run under =--root=, by its name; with =--target=, the newest that has that target. The default without =RUN=. | | =--target TARGET=, =--target=TARGET= | =why=, =history= | Read only the builds in the run's directory =TARGET=; for =history=, in each run's, a run without one passed over. Without it, those in the run's own directory and then in each directory in it, by name. | | =--root ROOT=, =--root=ROOT= | =why=, =history= | The directory that holds the runs, directories named =YYYYMMDD_HHMMSS=, not symbolic links. Without it, the current directory. | -| =--json= | =why=, =history= | Print one line of JSON instead of the report; its keys are under Files below. | +| =--json= | =why=, =history=, =loads=, =runs=, =pending= | Print one line of JSON instead of the report; its keys are under [[file:json-schemas.org][JSON schemas]] and below. | | =--software DIR=, =--software=DIR= | =usage= | Required. Read installed software from the direct =Name/Version= directories below =DIR=. | | =--modules DIR=, =--modules=DIR= | =usage= | Required. Count an Lmod record only when its module-file path is =DIR= or below it. | | =--since EPOCH=, =--since=EPOCH= | =usage= | Count records at or after the non-negative epoch time; leave out records with no numeric time. | @@ -310,16 +310,19 @@ What =history= cannot read it reports on stderr as =why= does, a run that cannot ** loads -=loads --module NAME FILE= prints who loaded =NAME=, from Lmod's ModuleUsageTracking lines in =FILE=. +=loads --module NAME [--json] FILE= prints who loaded =NAME=, from Lmod's ModuleUsageTracking lines in =FILE=. A record is =user=USER module=NAME path=PATH host=HOST time=TIME=, in any order, with a syslog prefix left in place. Each load is one line, =user=USER host=HOST time=TIME path=PATH=, in the file's order. -A file with no load of =NAME= prints =no load of NAME=. +A file with no load of =NAME= prints =no load of NAME=; with =--json= the =loads= array is empty. A line that is not a record is skipped. The shell script has no =loads=. +With =--json= the document has =schema_version= 1, =kind= ="loads"=, =module=, and a =loads= array in file order. Each element has =user=, =host=, =time= and =path= as the text lines print them. + | Argument | Meaning | |---|---| | =NAME= | The module's full name, as Lmod recorded it, such as =GROMACS/2024.1=. Required, as =--module NAME= or =--module=NAME=. | +| =--json= | Print one line of JSON instead of the text lines. | | =FILE= | The log. A file that cannot be read is refused. | @@ -387,32 +390,38 @@ The shell script has no =usage=. ** runs -=runs --exec PATH FILE= prints who ran =PATH=, from XALT run records in =FILE=. +=runs --exec PATH [--json] FILE= prints who ran =PATH=, from XALT run records in =FILE=. A run record is a JSON object whose =userT= holds =user=, =exec_path= and, when present, =syshost= and =start_time=. A link record is not a run and is skipped. =PATH= matches =exec_path= in full or as its last component. Each run is one line, =user=USER host=HOST time=TIME path=PATH=, in the file's order. -A file with no run of =PATH= prints =no run of PATH=. +A file with no run of =PATH= prints =no run of PATH=; with =--json= the =runs= array is empty. The shell script has no =runs=. It does not record runs. +With =--json= the document has =schema_version= 1, =kind= ="runs"=, =exec= as given, and a =runs= array in file order. Each element has =user=, =host=, =time= and =path= as the text lines print them; fields XALT omitted are empty strings. + | Argument | Meaning | |---|---| | =PATH= | The executable, as a full path or its last component. Required, as =--exec PATH= or =--exec=PATH=. | +| =--json= | Print one line of JSON instead of the text lines. | | =FILE= | One or more JSON objects. An object that is not a run record is skipped. A file that cannot be read, or that is not JSON, is refused. | ** pending -=pending FILE= prints what an EasyBuild dry-run or missing-modules report still has to build. +=pending [--json] FILE= prints what an EasyBuild dry-run or missing-modules report still has to build. A dry-run line is =* [ ] PATH (module: NAME)=, and =[F]= and =[R]= still build. =[x]= is already installed and is not printed. =--terse= prints =x PATH= or =- PATH=. A missing-modules line is =* NAME (FILE.eb)=, or with =--terse= one easyconfig path on each line. Each is one line, =build NAME= or =missing NAME=, in the file's order. -A report with nothing left prints =nothing to build=. +A report with nothing left prints =nothing to build=; with =--json= the =entries= array is empty. The shell script has no =pending=. It does not run =eb=, and it does not resolve dependencies. +With =--json= the document has =schema_version= 1, =kind= ="pending"=, and an =entries= array in file order. Each element has =action= (="build"= or ="missing"=) and =name= as the text lines print them. + | Argument | Meaning | |---|---| +| =--json= | Print one line of JSON instead of the text lines. | | =FILE= | The report, as =eb --dry-run= or =eb --missing-modules= printed it. A file that cannot be read, or that is neither report, is refused. | *** --help @@ -493,7 +502,7 @@ otherwise lose, and keep the pipeline's log tree bounded. directory. --json Print one line of JSON instead, with schema_version 1. - eb-keep-logs loads --module NAME FILE + eb-keep-logs loads --module NAME [--json] FILE Print who loaded NAME, from Lmod's ModuleUsageTracking lines in FILE. Each record is user=USER module=NAME path=PATH host=HOST time=TIME, in any order, and a syslog prefix is left in place. Each load is @@ -503,6 +512,8 @@ otherwise lose, and keep the pipeline's log tree bounded. --module NAME, --module=NAME The module's full name, as Lmod recorded it, such as GROMACS/2024.1. Required. + --json + Print one line of JSON instead, with schema_version 1. FILE The log that holds the records. A line that is not one is skipped. @@ -554,7 +565,7 @@ otherwise lose, and keep the pipeline's log tree bounded. FILE One or more files of concatenated XALT JSON objects and/or Lmod ModuleUsageTracking lines. Required. - eb-keep-logs runs --exec PATH FILE + eb-keep-logs runs --exec PATH [--json] FILE Print who ran PATH, from XALT run records in FILE. A run record is a JSON object whose userT holds user, exec_path and, when present, syshost and start_time. A link record is not a run and is skipped. @@ -564,10 +575,12 @@ otherwise lose, and keep the pipeline's log tree bounded. only. It does not record runs. --exec PATH, --exec=PATH The executable, as a full path or its last component. Required. + --json + Print one line of JSON instead, with schema_version 1. FILE One or more JSON objects. An object that is not a run record is skipped. - eb-keep-logs pending FILE + eb-keep-logs pending [--json] FILE Print what an EasyBuild dry-run or missing-modules report still has to build. A dry-run line is "* [ ] PATH (module: NAME)", and [F] and [R] count as still to build; [x] is already installed and is not @@ -576,6 +589,8 @@ otherwise lose, and keep the pipeline's log tree bounded. line. Each is one line, build NAME or missing NAME, in the file's order. A report with nothing left prints nothing to build. Zig build only. It does not run eb, and it does not resolve dependencies. + --json + Print one line of JSON instead, with schema_version 1. FILE The report, as eb --dry-run or eb --missing-modules printed it. Required. diff --git a/docs/orgmode/reference/index.org b/docs/orgmode/reference/index.org index e88ab06..e34cd87 100644 --- a/docs/orgmode/reference/index.org +++ b/docs/orgmode/reference/index.org @@ -12,6 +12,7 @@ Each page states facts in the order the thing itself has them. :maxdepth: 1 cli + json-schemas compatibility api #+end_export diff --git a/docs/orgmode/reference/json-schemas.org b/docs/orgmode/reference/json-schemas.org new file mode 100644 index 0000000..86ea16d --- /dev/null +++ b/docs/orgmode/reference/json-schemas.org @@ -0,0 +1,27 @@ +#+TITLE: JSON output schemas +#+OPTIONS: toc:nil todo:nil num:nil author:nil title:nil +#+STARTUP: content + +* JSON output schemas + +The Zig build's =--json= on =why=, =history=, =loads=, =runs=, =used=, =usage= and =pending= prints one line of JSON with =schema_version= 1. +The shell script refuses those commands; see [[file:compatibility.org][Compatibility]]. +Each document is validated in CI against a JSON Schema file in the repository tree under =docs/orgmode/reference/json/=. +The schemas use draft 2020-12; a new =schema_version= may drop or rename a key, or change what one means. + +| Command | Schema file in the repository | +|----------+-------------------------------| +| =why= | =docs/orgmode/reference/json/why.schema.json= | +| =history= | =docs/orgmode/reference/json/history.schema.json= | +| =loads= | =docs/orgmode/reference/json/loads.schema.json= | +| =runs= | =docs/orgmode/reference/json/runs.schema.json= | +| =used= | =docs/orgmode/reference/json/used.schema.json= | +| =usage= | =docs/orgmode/reference/json/usage.schema.json= | +| =pending= | =docs/orgmode/reference/json/pending.schema.json= | + +Field names and semantics for =why=, =history=, =used= and =usage= are under [[file:cli.org][The eb-keep-logs command]]. +=loads=, =runs= and =pending= document their JSON shape in the same page. + +** See also + +- [[file:cli.org][The eb-keep-logs command]] \ No newline at end of file diff --git a/docs/orgmode/reference/json/history.schema.json b/docs/orgmode/reference/json/history.schema.json new file mode 100644 index 0000000..8def88d --- /dev/null +++ b/docs/orgmode/reference/json/history.schema.json @@ -0,0 +1,43 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://stackhands.github.io/eb-keep-logs/reference/json/history.schema.json", + "title": "eb-keep-logs history --json", + "type": "object", + "additionalProperties": false, + "required": ["schema_version", "kind", "package", "root", "counts", "builds"], + "properties": { + "schema_version": { "type": "integer", "const": 1 }, + "kind": { "type": "string", "const": "history" }, + "package": { "type": "string" }, + "root": { "type": "string" }, + "counts": { + "type": "object", + "additionalProperties": false, + "required": ["success", "failed", "unknown"], + "properties": { + "success": { "type": "integer", "minimum": 0 }, + "failed": { "type": "integer", "minimum": 0 }, + "unknown": { "type": "integer", "minimum": 0 } + } + }, + "builds": { + "type": "array", + "items": { "$ref": "#/$defs/build" } + } + }, + "$defs": { + "build": { + "type": "object", + "additionalProperties": false, + "required": ["run", "target", "name", "outcome", "duration_s", "log"], + "properties": { + "run": { "type": "string" }, + "target": { "type": ["string", "null"] }, + "name": { "type": "string" }, + "outcome": { "type": "string", "enum": ["success", "failed", "unknown"] }, + "duration_s": { "type": ["integer", "null"], "minimum": 0 }, + "log": { "type": "string" } + } + } + } +} \ No newline at end of file diff --git a/docs/orgmode/reference/json/loads.schema.json b/docs/orgmode/reference/json/loads.schema.json new file mode 100644 index 0000000..d9d8fc4 --- /dev/null +++ b/docs/orgmode/reference/json/loads.schema.json @@ -0,0 +1,30 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://stackhands.github.io/eb-keep-logs/reference/json/loads.schema.json", + "title": "eb-keep-logs loads --json", + "type": "object", + "additionalProperties": false, + "required": ["schema_version", "kind", "module", "loads"], + "properties": { + "schema_version": { "type": "integer", "const": 1 }, + "kind": { "type": "string", "const": "loads" }, + "module": { "type": "string" }, + "loads": { + "type": "array", + "items": { "$ref": "#/$defs/load" } + } + }, + "$defs": { + "load": { + "type": "object", + "additionalProperties": false, + "required": ["user", "host", "time", "path"], + "properties": { + "user": { "type": "string" }, + "host": { "type": "string" }, + "time": { "type": "string" }, + "path": { "type": "string" } + } + } + } +} \ No newline at end of file diff --git a/docs/orgmode/reference/json/pending.schema.json b/docs/orgmode/reference/json/pending.schema.json new file mode 100644 index 0000000..1ea5047 --- /dev/null +++ b/docs/orgmode/reference/json/pending.schema.json @@ -0,0 +1,27 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://stackhands.github.io/eb-keep-logs/reference/json/pending.schema.json", + "title": "eb-keep-logs pending --json", + "type": "object", + "additionalProperties": false, + "required": ["schema_version", "kind", "entries"], + "properties": { + "schema_version": { "type": "integer", "const": 1 }, + "kind": { "type": "string", "const": "pending" }, + "entries": { + "type": "array", + "items": { "$ref": "#/$defs/entry" } + } + }, + "$defs": { + "entry": { + "type": "object", + "additionalProperties": false, + "required": ["action", "name"], + "properties": { + "action": { "type": "string", "enum": ["build", "missing"] }, + "name": { "type": "string" } + } + } + } +} \ No newline at end of file diff --git a/docs/orgmode/reference/json/runs.schema.json b/docs/orgmode/reference/json/runs.schema.json new file mode 100644 index 0000000..d6e15eb --- /dev/null +++ b/docs/orgmode/reference/json/runs.schema.json @@ -0,0 +1,30 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://stackhands.github.io/eb-keep-logs/reference/json/runs.schema.json", + "title": "eb-keep-logs runs --json", + "type": "object", + "additionalProperties": false, + "required": ["schema_version", "kind", "exec", "runs"], + "properties": { + "schema_version": { "type": "integer", "const": 1 }, + "kind": { "type": "string", "const": "runs" }, + "exec": { "type": "string" }, + "runs": { + "type": "array", + "items": { "$ref": "#/$defs/run" } + } + }, + "$defs": { + "run": { + "type": "object", + "additionalProperties": false, + "required": ["user", "host", "time", "path"], + "properties": { + "user": { "type": "string" }, + "host": { "type": "string" }, + "time": { "type": "string" }, + "path": { "type": "string" } + } + } + } +} \ No newline at end of file diff --git a/docs/orgmode/reference/json/usage.schema.json b/docs/orgmode/reference/json/usage.schema.json new file mode 100644 index 0000000..43bbcc4 --- /dev/null +++ b/docs/orgmode/reference/json/usage.schema.json @@ -0,0 +1,35 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://stackhands.github.io/eb-keep-logs/reference/json/usage.schema.json", + "title": "eb-keep-logs usage --json", + "type": "object", + "additionalProperties": false, + "required": ["schema_version", "kind", "software", "modules", "since", "selection", "packages"], + "properties": { + "schema_version": { "type": "integer", "const": 1 }, + "kind": { "type": "string", "const": "usage" }, + "software": { "type": "string" }, + "modules": { "type": "string" }, + "since": { "type": ["string", "null"] }, + "selection": { "type": "string", "enum": ["all", "unused", "active"] }, + "packages": { + "type": "array", + "items": { "$ref": "#/$defs/package" } + } + }, + "$defs": { + "package": { + "type": "object", + "additionalProperties": false, + "required": ["name", "version", "module", "active", "hits", "last"], + "properties": { + "name": { "type": "string" }, + "version": { "type": "string" }, + "module": { "type": "string" }, + "active": { "type": "boolean" }, + "hits": { "type": "integer", "minimum": 0 }, + "last": { "type": ["string", "null"] } + } + } + } +} \ No newline at end of file diff --git a/docs/orgmode/reference/json/used.schema.json b/docs/orgmode/reference/json/used.schema.json new file mode 100644 index 0000000..9c17004 --- /dev/null +++ b/docs/orgmode/reference/json/used.schema.json @@ -0,0 +1,32 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://stackhands.github.io/eb-keep-logs/reference/json/used.schema.json", + "title": "eb-keep-logs used --json", + "type": "object", + "additionalProperties": false, + "required": ["schema_version", "prefix", "uses"], + "properties": { + "schema_version": { "type": "integer", "const": 1 }, + "prefix": { "type": "string" }, + "uses": { + "type": "array", + "items": { "$ref": "#/$defs/use" } + } + }, + "$defs": { + "use": { + "type": "object", + "additionalProperties": false, + "required": ["kind", "path", "last", "count"], + "properties": { + "kind": { + "type": "string", + "enum": ["run", "run-lib", "link", "pkg", "module-load"] + }, + "path": { "type": "string" }, + "last": { "type": "string" }, + "count": { "type": "integer", "minimum": 1 } + } + } + } +} \ No newline at end of file diff --git a/docs/orgmode/reference/json/why.schema.json b/docs/orgmode/reference/json/why.schema.json new file mode 100644 index 0000000..77d0198 --- /dev/null +++ b/docs/orgmode/reference/json/why.schema.json @@ -0,0 +1,59 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://stackhands.github.io/eb-keep-logs/reference/json/why.schema.json", + "title": "eb-keep-logs why --json", + "type": "object", + "additionalProperties": false, + "required": ["schema_version", "kind", "run", "run_dir", "counts", "failures"], + "properties": { + "schema_version": { "type": "integer", "const": 1 }, + "kind": { "type": "string", "const": "why" }, + "run": { "type": "string" }, + "run_dir": { "type": "string" }, + "counts": { + "type": "object", + "additionalProperties": false, + "required": ["success", "failed", "unknown"], + "properties": { + "success": { "type": "integer", "minimum": 0 }, + "failed": { "type": "integer", "minimum": 0 }, + "unknown": { "type": "integer", "minimum": 0 } + } + }, + "failures": { + "type": "array", + "items": { "$ref": "#/$defs/failure" } + } + }, + "$defs": { + "failure": { + "type": "object", + "additionalProperties": false, + "required": ["target", "name", "package", "easyconfig", "step", "message", "duration_s", "log", "error"], + "properties": { + "target": { "type": ["string", "null"] }, + "name": { "type": "string" }, + "package": { "type": ["string", "null"] }, + "easyconfig": { "type": ["string", "null"] }, + "step": { "type": ["string", "null"] }, + "message": { "type": ["string", "null"] }, + "duration_s": { "type": ["integer", "null"], "minimum": 0 }, + "log": { "type": ["string", "null"] }, + "error": { + "oneOf": [{ "type": "null" }, { "$ref": "#/$defs/error_line" }] + } + } + }, + "error_line": { + "type": "object", + "additionalProperties": false, + "required": ["line", "text", "before", "after"], + "properties": { + "line": { "type": "integer", "minimum": 1 }, + "text": { "type": "string" }, + "before": { "type": "array", "items": { "type": "string" } }, + "after": { "type": "array", "items": { "type": "string" } } + } + } + } +} \ No newline at end of file diff --git a/eb-keep-logs b/eb-keep-logs index 710c542..a0d28ee 100755 --- a/eb-keep-logs +++ b/eb-keep-logs @@ -87,7 +87,7 @@ otherwise lose, and keep the pipeline's log tree bounded. directory. --json Print one line of JSON instead, with schema_version 1. - eb-keep-logs loads --module NAME FILE + eb-keep-logs loads --module NAME [--json] FILE Print who loaded NAME, from Lmod's ModuleUsageTracking lines in FILE. Each record is user=USER module=NAME path=PATH host=HOST time=TIME, in any order, and a syslog prefix is left in place. Each load is @@ -97,6 +97,8 @@ otherwise lose, and keep the pipeline's log tree bounded. --module NAME, --module=NAME The module's full name, as Lmod recorded it, such as GROMACS/2024.1. Required. + --json + Print one line of JSON instead, with schema_version 1. FILE The log that holds the records. A line that is not one is skipped. @@ -148,7 +150,7 @@ otherwise lose, and keep the pipeline's log tree bounded. FILE One or more files of concatenated XALT JSON objects and/or Lmod ModuleUsageTracking lines. Required. - eb-keep-logs runs --exec PATH FILE + eb-keep-logs runs --exec PATH [--json] FILE Print who ran PATH, from XALT run records in FILE. A run record is a JSON object whose userT holds user, exec_path and, when present, syshost and start_time. A link record is not a run and is skipped. @@ -158,10 +160,12 @@ otherwise lose, and keep the pipeline's log tree bounded. only. It does not record runs. --exec PATH, --exec=PATH The executable, as a full path or its last component. Required. + --json + Print one line of JSON instead, with schema_version 1. FILE One or more JSON objects. An object that is not a run record is skipped. - eb-keep-logs pending FILE + eb-keep-logs pending [--json] FILE Print what an EasyBuild dry-run or missing-modules report still has to build. A dry-run line is "* [ ] PATH (module: NAME)", and [F] and [R] count as still to build; [x] is already installed and is not @@ -170,6 +174,8 @@ otherwise lose, and keep the pipeline's log tree bounded. line. Each is one line, build NAME or missing NAME, in the file's order. A report with nothing left prints nothing to build. Zig build only. It does not run eb, and it does not resolve dependencies. + --json + Print one line of JSON instead, with schema_version 1. FILE The report, as eb --dry-run or eb --missing-modules printed it. Required. diff --git a/src/loads.zig b/src/loads.zig index 15d5eb8..7003f34 100644 --- a/src/loads.zig +++ b/src/loads.zig @@ -12,6 +12,8 @@ const cli = common.cli; const Allocator = std.mem.Allocator; const tool = "eb-keep-logs"; +/// The `schema_version` of what `--json` prints. +pub const schema_version: u32 = 1; /// A module-usage log larger than this is refused rather than read part way. const read_limit: usize = 64 * 1024 * 1024; @@ -60,21 +62,56 @@ pub fn parseRecord(line: []const u8) ?Record { }; } -/// The loads of `module` in `text`, one line each, in file order. No load -/// is the line `no load of NAME`. -pub fn formatLoads(gpa: Allocator, text: []const u8, module: []const u8) Allocator.Error![]u8 { - var out: std.ArrayList(u8) = .empty; - errdefer out.deinit(gpa); - var n: usize = 0; +const JsonLoad = struct { + user: []const u8, + host: []const u8, + time: []const u8, + path: []const u8, +}; + +const JsonReport = struct { + schema_version: u32 = schema_version, + kind: []const u8 = "loads", + module: []const u8, + loads: []const JsonLoad, +}; + +fn collectLoads(gpa: Allocator, text: []const u8, module: []const u8) Allocator.Error![]JsonLoad { + var loads: std.ArrayList(JsonLoad) = .empty; + errdefer loads.deinit(gpa); var it = std.mem.splitScalar(u8, text, '\n'); while (it.next()) |raw| { const line = std.mem.trimEnd(u8, raw, "\r"); const rec = parseRecord(line) orelse continue; if (!std.mem.eql(u8, rec.module, module)) continue; - try out.print(gpa, "user={s} host={s} time={s} path={s}\n", .{ rec.user, rec.host, rec.time, rec.path }); - n += 1; + try loads.append(gpa, .{ + .user = rec.user, + .host = rec.host, + .time = rec.time, + .path = rec.path, + }); } - if (n == 0) try out.print(gpa, "no load of {s}\n", .{module}); + return try loads.toOwnedSlice(gpa); +} + +pub fn formatJson(gpa: Allocator, module: []const u8, items: []const JsonLoad) ![]u8 { + const report: JsonReport = .{ .module = module, .loads = items }; + var out: std.Io.Writer.Allocating = .init(gpa); + defer out.deinit(); + try std.json.Stringify.value(report, .{}, &out.writer); + try out.writer.writeAll("\n"); + return try out.toOwnedSlice(); +} + +/// The loads of `module` in `text`, one line each, in file order. No load +/// is the line `no load of NAME`. +pub fn formatLoads(gpa: Allocator, text: []const u8, module: []const u8) Allocator.Error![]u8 { + const items = try collectLoads(gpa, text, module); + defer gpa.free(items); + var out: std.ArrayList(u8) = .empty; + errdefer out.deinit(gpa); + for (items) |row| try out.print(gpa, "user={s} host={s} time={s} path={s}\n", .{ row.user, row.host, row.time, row.path }); + if (items.len == 0) try out.print(gpa, "no load of {s}\n", .{module}); return try out.toOwnedSlice(gpa); } @@ -90,14 +127,17 @@ fn readLog(gpa: Allocator, path: []const u8) ?[]u8 { }; } -/// `loads --module NAME FILE`. +/// `loads --module NAME [--json] FILE`. pub fn cmdLoads(gpa: Allocator, args: []const []const u8) u8 { var module: []const u8 = ""; + var json_out = false; var path: []const u8 = ""; var i: usize = 0; while (i < args.len) : (i += 1) { const a = args[i]; - if (std.mem.eql(u8, a, "--module") or std.mem.startsWith(u8, a, "--module=")) { + if (std.mem.eql(u8, a, "--json")) { + json_out = true; + } else if (std.mem.eql(u8, a, "--module") or std.mem.startsWith(u8, a, "--module=")) { const v = if (std.mem.startsWith(u8, a, "--module=")) a["--module=".len..] else blk: { @@ -119,7 +159,13 @@ pub fn cmdLoads(gpa: Allocator, args: []const []const u8) u8 { if (path.len == 0) die("loads needs a log file", .{}); const text = readLog(gpa, path) orelse return 2; defer gpa.free(text); - const body = formatLoads(gpa, text, module) catch die("out of memory", .{}); + const body = if (json_out) blk: { + const items = collectLoads(gpa, text, module) catch die("out of memory", .{}); + defer gpa.free(items); + break :blk formatJson(gpa, module, items) catch die("out of memory", .{}); + } else blk: { + break :blk formatLoads(gpa, text, module) catch die("out of memory", .{}); + }; defer gpa.free(body); cli.out("{s}", .{body}); return 0; diff --git a/src/main.zig b/src/main.zig index 286a955..ef22ba8 100644 --- a/src/main.zig +++ b/src/main.zig @@ -101,7 +101,7 @@ const usage_text = \\ directory. \\ --json \\ Print one line of JSON instead, with schema_version 1. - \\ eb-keep-logs loads --module NAME FILE + \\ eb-keep-logs loads --module NAME [--json] FILE \\ Print who loaded NAME, from Lmod's ModuleUsageTracking lines in FILE. \\ Each record is user=USER module=NAME path=PATH host=HOST time=TIME, \\ in any order, and a syslog prefix is left in place. Each load is @@ -111,6 +111,8 @@ const usage_text = \\ --module NAME, --module=NAME \\ The module's full name, as Lmod recorded it, such as \\ GROMACS/2024.1. Required. + \\ --json + \\ Print one line of JSON instead, with schema_version 1. \\ FILE \\ The log that holds the records. A line that is not one is \\ skipped. @@ -162,7 +164,7 @@ const usage_text = \\ FILE \\ One or more files of concatenated XALT JSON objects and/or Lmod \\ ModuleUsageTracking lines. Required. - \\ eb-keep-logs runs --exec PATH FILE + \\ eb-keep-logs runs --exec PATH [--json] FILE \\ Print who ran PATH, from XALT run records in FILE. A run record is a \\ JSON object whose userT holds user, exec_path and, when present, \\ syshost and start_time. A link record is not a run and is skipped. @@ -172,10 +174,12 @@ const usage_text = \\ only. It does not record runs. \\ --exec PATH, --exec=PATH \\ The executable, as a full path or its last component. Required. + \\ --json + \\ Print one line of JSON instead, with schema_version 1. \\ FILE \\ One or more JSON objects. An object that is not a run record is \\ skipped. - \\ eb-keep-logs pending FILE + \\ eb-keep-logs pending [--json] FILE \\ Print what an EasyBuild dry-run or missing-modules report still has \\ to build. A dry-run line is "* [ ] PATH (module: NAME)", and [F] and \\ [R] count as still to build; [x] is already installed and is not @@ -184,6 +188,8 @@ const usage_text = \\ line. Each is one line, build NAME or missing NAME, in the file's \\ order. A report with nothing left prints nothing to build. Zig build \\ only. It does not run eb, and it does not resolve dependencies. + \\ --json + \\ Print one line of JSON instead, with schema_version 1. \\ FILE \\ The report, as eb --dry-run or eb --missing-modules printed it. \\ Required. diff --git a/src/pending.zig b/src/pending.zig index a7029aa..eb4a9d1 100644 --- a/src/pending.zig +++ b/src/pending.zig @@ -15,6 +15,8 @@ const cli = common.cli; const Allocator = std.mem.Allocator; const tool = "eb-keep-logs"; +/// The `schema_version` of what `--json` prints. +pub const schema_version: u32 = 1; const read_limit: usize = 64 * 1024 * 1024; fn die(comptime fmt: []const u8, args: anytype) noreturn { @@ -89,9 +91,20 @@ fn barePath(line: []const u8) ?[]const u8 { return text; } -/// Lines still to build. `nothing to build` when the report has none. -/// `error.NotAReport` when the text is neither shape. -pub fn formatPending(gpa: Allocator, text: []const u8) (Allocator.Error || error{NotAReport})![]u8 { +const ReportMode = enum { module, terse, missing, bare }; + +const JsonEntry = struct { + action: []const u8, + name: []const u8, +}; + +const JsonReport = struct { + schema_version: u32 = schema_version, + kind: []const u8 = "pending", + entries: []const JsonEntry, +}; + +fn reportMode(text: []const u8) error{NotAReport}!ReportMode { var modules: usize = 0; var terse: usize = 0; var missing: usize = 0; @@ -111,7 +124,7 @@ pub fn formatPending(gpa: Allocator, text: []const u8) (Allocator.Error || error bare += 1; } else other += 1; } - const mode: enum { module, terse, missing, bare } = if (modules > 0) + return if (modules > 0) .module else if (terse > 0) .terse @@ -120,43 +133,66 @@ pub fn formatPending(gpa: Allocator, text: []const u8) (Allocator.Error || error else if (bare > 0 and other == 0) .bare else - return error.NotAReport; + error.NotAReport; +} - var out: std.ArrayList(u8) = .empty; - errdefer out.deinit(gpa); - var n: usize = 0; - it = std.mem.splitScalar(u8, text, '\n'); +fn collectEntries(gpa: Allocator, text: []const u8, mode: ReportMode) Allocator.Error![]JsonEntry { + var entries: std.ArrayList(JsonEntry) = .empty; + errdefer entries.deinit(gpa); + var it = std.mem.splitScalar(u8, text, '\n'); while (it.next()) |raw| { const line = trim(raw); switch (mode) { .module => if (moduleLine(line)) |mark| { if (!mark.build) continue; - try out.print(gpa, "build {s}\n", .{mark.name}); - n += 1; + try entries.append(gpa, .{ .action = "build", .name = mark.name }); }, .terse => if (terseLine(line)) |mark| { if (!mark.build) continue; - try out.print(gpa, "build {s}\n", .{mark.name}); - n += 1; + try entries.append(gpa, .{ .action = "build", .name = mark.name }); }, .missing => if (missingLine(line)) |name| { - try out.print(gpa, "missing {s}\n", .{name}); - n += 1; + try entries.append(gpa, .{ .action = "missing", .name = name }); }, .bare => if (barePath(line)) |path| { - try out.print(gpa, "missing {s}\n", .{path}); - n += 1; + try entries.append(gpa, .{ .action = "missing", .name = path }); }, } } - if (n == 0) try out.appendSlice(gpa, "nothing to build\n"); + return try entries.toOwnedSlice(gpa); +} + +pub fn formatJson(gpa: Allocator, items: []const JsonEntry) ![]u8 { + const report: JsonReport = .{ .entries = items }; + var out: std.Io.Writer.Allocating = .init(gpa); + defer out.deinit(); + try std.json.Stringify.value(report, .{}, &out.writer); + try out.writer.writeAll("\n"); + return try out.toOwnedSlice(); +} + +/// Lines still to build. `nothing to build` when the report has none. +/// `error.NotAReport` when the text is neither shape. +pub fn formatPending(gpa: Allocator, text: []const u8) (Allocator.Error || error{NotAReport})![]u8 { + const mode = try reportMode(text); + const items = try collectEntries(gpa, text, mode); + defer gpa.free(items); + var out: std.ArrayList(u8) = .empty; + errdefer out.deinit(gpa); + for (items) |e| try out.print(gpa, "{s} {s}\n", .{ e.action, e.name }); + if (items.len == 0) try out.appendSlice(gpa, "nothing to build\n"); return try out.toOwnedSlice(gpa); } -/// `pending FILE`. +/// `pending [--json] FILE`. pub fn cmdPending(gpa: Allocator, args: []const []const u8) u8 { + var json_out = false; var path: []const u8 = ""; for (args) |a| { + if (std.mem.eql(u8, a, "--json")) { + json_out = true; + continue; + } if (a.len > 0 and a[0] == '-') die("pending does not know '{s}'", .{a}); if (path.len != 0) die("pending does not know '{s}'", .{a}); path = a; @@ -164,12 +200,24 @@ pub fn cmdPending(gpa: Allocator, args: []const []const u8) u8 { if (path.len == 0) die("pending needs a report", .{}); const text = readLog(gpa, path) orelse return 2; defer gpa.free(text); - const body = formatPending(gpa, text) catch |err| switch (err) { - error.NotAReport => { - warn("pending: {s} is not a dry-run or missing-modules report", .{path}); - return 2; - }, - error.OutOfMemory => die("out of memory", .{}), + const body = if (json_out) blk: { + const mode = reportMode(text) catch |err| switch (err) { + error.NotAReport => { + warn("pending: {s} is not a dry-run or missing-modules report", .{path}); + return 2; + }, + }; + const items = collectEntries(gpa, text, mode) catch die("out of memory", .{}); + defer gpa.free(items); + break :blk formatJson(gpa, items) catch die("out of memory", .{}); + } else blk: { + break :blk formatPending(gpa, text) catch |err| switch (err) { + error.NotAReport => { + warn("pending: {s} is not a dry-run or missing-modules report", .{path}); + return 2; + }, + error.OutOfMemory => die("out of memory", .{}), + }; }; defer gpa.free(body); cli.out("{s}", .{body}); diff --git a/src/runs.zig b/src/runs.zig index b5e4511..bbad2cb 100644 --- a/src/runs.zig +++ b/src/runs.zig @@ -13,6 +13,8 @@ const cli = common.cli; const Allocator = std.mem.Allocator; const tool = "eb-keep-logs"; +/// The `schema_version` of what `--json` prints. +pub const schema_version: u32 = 1; const read_limit: usize = 64 * 1024 * 1024; fn die(comptime fmt: []const u8, args: anytype) noreturn { @@ -91,12 +93,31 @@ fn appendScalar(out: *std.ArrayList(u8), gpa: Allocator, value: std.json.Value) } } -/// The runs of `exec` in `text`, one line each, in file order. No run is -/// the line `no run of PATH`. -pub fn formatRuns(gpa: Allocator, text: []const u8, exec: []const u8) (Allocator.Error || error{BadJson})![]u8 { - var out: std.ArrayList(u8) = .empty; - errdefer out.deinit(gpa); - var n: usize = 0; +fn scalarText(buf: *std.ArrayList(u8), gpa: Allocator, value: std.json.Value) Allocator.Error![]const u8 { + const start = buf.items.len; + try appendScalar(buf, gpa, value); + return buf.items[start..]; +} + +const JsonRun = struct { + user: []const u8, + host: []const u8, + time: []const u8, + path: []const u8, +}; + +const JsonReport = struct { + schema_version: u32 = schema_version, + kind: []const u8 = "runs", + exec: []const u8, + runs: []const JsonRun, +}; + +fn collectRuns(gpa: Allocator, text: []const u8, exec: []const u8) (Allocator.Error || error{BadJson})![]JsonRun { + var runs: std.ArrayList(JsonRun) = .empty; + errdefer runs.deinit(gpa); + var scratch: std.ArrayList(u8) = .empty; + errdefer scratch.deinit(gpa); var at: usize = 0; while (try nextObject(text, at)) |item| { at = item.end; @@ -122,31 +143,72 @@ pub fn formatRuns(gpa: Allocator, text: []const u8, exec: []const u8) (Allocator else => continue, }; if (!execMatches(path, exec)) continue; + const host = blk: { + if (user_t.getPtr("syshost")) |h| { + if (h.* == .string) break :blk try gpa.dupe(u8, h.string); + } + break :blk try gpa.dupe(u8, ""); + }; + const when = blk: { + if (user_t.getPtr("start_time")) |t| { + const slice = try scalarText(&scratch, gpa, t.*); + break :blk try gpa.dupe(u8, slice); + } + break :blk try gpa.dupe(u8, ""); + }; + try runs.append(gpa, .{ + .user = try gpa.dupe(u8, user), + .host = host, + .time = when, + .path = try gpa.dupe(u8, path), + }); + } + return try runs.toOwnedSlice(gpa); +} + +pub fn formatJson(gpa: Allocator, exec: []const u8, items: []const JsonRun) ![]u8 { + const report: JsonReport = .{ .exec = exec, .runs = items }; + var out: std.Io.Writer.Allocating = .init(gpa); + defer out.deinit(); + try std.json.Stringify.value(report, .{}, &out.writer); + try out.writer.writeAll("\n"); + return try out.toOwnedSlice(); +} + +/// The runs of `exec` in `text`, one line each, in file order. No run is +/// the line `no run of PATH`. +pub fn formatRuns(gpa: Allocator, text: []const u8, exec: []const u8) (Allocator.Error || error{BadJson})![]u8 { + var arena = std.heap.ArenaAllocator.init(gpa); + defer arena.deinit(); + const items = try collectRuns(arena.allocator(), text, exec); + var out: std.ArrayList(u8) = .empty; + errdefer out.deinit(gpa); + for (items) |row| { try out.appendSlice(gpa, "user="); - try out.appendSlice(gpa, user); + try out.appendSlice(gpa, row.user); try out.appendSlice(gpa, " host="); - if (user_t.getPtr("syshost")) |host| { - if (host.* == .string) try out.appendSlice(gpa, host.string); - } + try out.appendSlice(gpa, row.host); try out.appendSlice(gpa, " time="); - if (user_t.getPtr("start_time")) |when| try appendScalar(&out, gpa, when.*); + try out.appendSlice(gpa, row.time); try out.appendSlice(gpa, " path="); - try out.appendSlice(gpa, path); + try out.appendSlice(gpa, row.path); try out.append(gpa, '\n'); - n += 1; } - if (n == 0) try out.print(gpa, "no run of {s}\n", .{exec}); + if (items.len == 0) try out.print(gpa, "no run of {s}\n", .{exec}); return try out.toOwnedSlice(gpa); } -/// `runs --exec PATH FILE`. +/// `runs --exec PATH [--json] FILE`. pub fn cmdRuns(gpa: Allocator, args: []const []const u8) u8 { var exec: []const u8 = ""; + var json_out = false; var path: []const u8 = ""; var i: usize = 0; while (i < args.len) : (i += 1) { const a = args[i]; - if (std.mem.eql(u8, a, "--exec") or std.mem.startsWith(u8, a, "--exec=")) { + if (std.mem.eql(u8, a, "--json")) { + json_out = true; + } else if (std.mem.eql(u8, a, "--exec") or std.mem.startsWith(u8, a, "--exec=")) { const v = if (std.mem.startsWith(u8, a, "--exec=")) a["--exec=".len..] else blk: { @@ -168,12 +230,26 @@ pub fn cmdRuns(gpa: Allocator, args: []const []const u8) u8 { if (path.len == 0) die("runs needs a record file", .{}); const text = readLog(gpa, path) orelse return 2; defer gpa.free(text); - const body = formatRuns(gpa, text, exec) catch |err| switch (err) { - error.BadJson => { - warn("runs: {s} is not XALT run JSON", .{path}); - return 2; - }, - error.OutOfMemory => die("out of memory", .{}), + var arena = std.heap.ArenaAllocator.init(gpa); + defer arena.deinit(); + const scan = arena.allocator(); + const body = if (json_out) blk: { + const items = collectRuns(scan, text, exec) catch |err| switch (err) { + error.BadJson => { + warn("runs: {s} is not XALT run JSON", .{path}); + return 2; + }, + error.OutOfMemory => die("out of memory", .{}), + }; + break :blk formatJson(gpa, exec, items) catch die("out of memory", .{}); + } else blk: { + break :blk formatRuns(gpa, text, exec) catch |err| switch (err) { + error.BadJson => { + warn("runs: {s} is not XALT run JSON", .{path}); + return 2; + }, + error.OutOfMemory => die("out of memory", .{}), + }; }; defer gpa.free(body); cli.out("{s}", .{body}); diff --git a/tests/json_schema_validate.py b/tests/json_schema_validate.py new file mode 100755 index 0000000..950c89f --- /dev/null +++ b/tests/json_schema_validate.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 +"""Validate one JSON document against a JSON Schema file.""" +from __future__ import annotations + +import argparse +import json +import sys +from pathlib import Path + +try: + import jsonschema +except ImportError: + sys.stderr.write("json_schema_validate: install the jsonschema package\n") + raise SystemExit(2) from None + + +def main() -> int: + parser = argparse.ArgumentParser() + parser.add_argument("schema", type=Path) + parser.add_argument("document", type=Path, nargs="?", default="-") + args = parser.parse_args() + schema = json.loads(args.schema.read_text(encoding="utf-8")) + if str(args.document) == "-": + payload = json.load(sys.stdin) + else: + payload = json.loads(args.document.read_text(encoding="utf-8")) + jsonschema.validate(payload, schema=schema) + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) \ No newline at end of file diff --git a/tests/test_json_schemas.sh b/tests/test_json_schemas.sh new file mode 100755 index 0000000..f491e62 --- /dev/null +++ b/tests/test_json_schemas.sh @@ -0,0 +1,69 @@ +#!/bin/bash +# Validate --json output against docs/orgmode/reference/json/*.schema.json. +# TOOL_BIN=zig-out/bin/eb-keep-logs bash tests/test_json_schemas.sh +set -u + +repo_root=$(cd "$(dirname "$0")/.." && pwd) +schema_dir="${repo_root}/docs/orgmode/reference/json" +tool="${TOOL_BIN:?TOOL_BIN names the Zig build}" +case "${tool}" in /*) ;; *) tool="${PWD}/${tool}" ;; esac + +if ! python3 -c "import jsonschema" 2>/dev/null; then + python3 -m pip install -q --user jsonschema +fi + +validate() { + local name=$1 + local cmd=$2 + shift 2 + "${tool}" "${cmd}" "$@" | python3 "${repo_root}/tests/json_schema_validate.py" "${schema_dir}/${name}.schema.json" +} + +logs="${repo_root}/tests/fixtures/build-logs" +work=$(mktemp -d "${TMPDIR:-/tmp}/eb-keep-logs-json.XXXXXX") +trap 'rm -rf -- "${work}"' EXIT + +cat > "${work}/moduleUsage.log" <<'EOF' +user=alice module=GROMACS/2024.1 path=/cvmfs/g.lua host=login01 time=1731840001.250000 +user=cara module=GROMACS/2024.1 path=/other.lua host=login01 time=1731840099.5 +EOF + +cat > "${work}/runs.json" <<'EOF' +{"userT":{"user":"ada","exec_path":"/opt/site/bin/gmx","syshost":"login01","start_time":"1428767000.5"}} +EOF + +cat > "${work}/dry.txt" <<'EOF' + * [ ] $CFGS/f/flex/flex-2.6.4.eb (module: flex/2.6.4) + * [R] $CFGS/g/GCC/GCC-13.2.0.eb (module: GCC/13.2.0) +EOF + +software="${work}/software" +modules="${work}/modules" +mkdir -p "${software}/Foo/1.0" "${modules}/Foo" +cat > "${work}/xalt.json" < "${work}/lmod.log" + +fails=0 +run() { + local title=$1 + shift + if "$@"; then + echo "ok ${title}" + else + echo "FAIL ${title}" >&2 + fails=$((fails + 1)) + fi +} + +run "why" validate why why --json "${logs}/20261117_041222" +run "history" validate history history --json --root "${logs}" hello-2.12.1-GCCcore-13.3.0 +run "loads" validate loads loads --module GROMACS/2024.1 --json "${work}/moduleUsage.log" +run "runs" validate runs runs --exec gmx --json "${work}/runs.json" +run "pending dry-run" validate pending pending --json "${work}/dry.txt" +run "used" validate used used --prefix "${software}/Foo/1.0" --json "${work}/xalt.json" +run "usage" validate usage usage --software "${software}" --modules "${modules}" --json "${work}/xalt.json" "${work}/lmod.log" + +echo "${fails} failed" +[ "${fails}" -eq 0 ] \ No newline at end of file