Skip to content

Add CLI integration tests for create, query and view; fix OWL RL entailment across --data files - #27

Merged
GregHanson merged 2 commits into
mainfrom
cli-integration-tests
Nov 5, 2026
Merged

GregHanson merged 2 commits into
mainfrom
cli-integration-tests

Conversation

@GregHanson

@GregHanson GregHanson commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #26. These tests cover what the per-subcommand suites didn't check end to end, measured against the test methodology:

  • check exact output;
  • check CLI exit codes and error messages;
  • cover every supported format;
  • keep multi-line expected results as committed goldens.

All 20 new tests use committed fixtures and temporary directories. One of them found a bug in OWL RL entailment, which the second commit fixes (see The entailment fix).

view (tests/test-view.rs, +4)

Test Checks
test_view_reports_header_statistics view output names the file and reports triple, subject and predicate counts. The old test_view wrote to /dev/null and only checked that it didn't error.
test_view_shows_graph_iri_metadata create --graph-iri shows up in view, and is absent without it.
test_view_lists_each_file Several files are shown in the order given, each with its own header.
test_view_cli_rejects_missing_and_non_hdt_files Non-zero exit, with a clear message for a missing file and for a non-HDT file.

create (tests/test-create.rs, +3)

Test Checks
test_create_accepts_each_rdf_serialization N-Triples, Turtle, N-Quads, TriG, N3, RDF/XML and JSON-LD fixtures of the same graph produce identical HDTs, compared as triple sets. The new fixtures are hand-written, not generated by de.
test_create_cli_failures_leave_nothing_behind Invalid RDF, a missing input and an unwritable output path each exit non-zero with a reason. None leaves an output file, or anything in TMPDIR beyond hdt's shared lock directory.
test_create_cli_merges_named_graphs_only_when_allowed Quads from two named graphs fail without --allow-merge-named-graphs and merge with it.

query (tests/test-query.rs, +9)

Test Checks
test_query_construct_in_each_rdf_format CONSTRUCT output in N-Triples, N-Quads, Turtle, TriG, N3 and RDF/XML parses back to the source graph.
test_query_ask_result_formats ASK in CSV, TSV, JSON and XML; an RDF format falls back to CSV, as the code intends.
test_query_owl_rl_entailment --entailment owl-rl infers Banana a Food from Fruit rdfs:subClassOf Food, with data and ontology in one HDT; nothing is inferred with entailment off.
test_query_owl_rl_entailment_across_data_files The same inference with the ontology in a separate --data file, as Turtle and as HDT. Failed before the fix below.
test_query_cli_named_graph_bindings --named-graph IRI=PATH feeds GRAPH ?g, and --data doesn't leak into the named graphs.
test_query_mixed_hdt_and_rdf_inputs One HDT and one Turtle file in the same query.
test_query_cli_runs_each_sparql_file_in_order Several --sparql files each print their own result, in order.
test_query_cli_errors A syntax error, a missing data file, a missing query file, and SELECT with an RDF output format: each exits non-zero, writes nothing to stdout and gives a reason on stderr.
test_query_cli_debug_query_plan --debug-query-plan writes JSON to stderr and leaves stdout unchanged.

The entailment fix

Before: de query --data banana.ttl fruit-ontology.ttl --entailment owl-rl inferred nothing. prepare_source_hdt_path prepared each --data file through handle_files on its own, so each file got its own closure, and an ontology in one file never applied to the data in another. It only worked when the data and the ontology were in the same file or HDT. The per-file preparation dates from #7.

After:

  • The default graph is the merge of its files. With entailment on and more than one default-graph file, prepare_default_graph_hdt_paths prepares them together through handle_files, which already computes a single closure over all its inputs.
  • Each named graph (--named-graph, or FROM NAMED) keeps a closure of its own, as SPARQL entailment applies to the active graph. An ontology in the default graph doesn't add inferences inside a named graph.
  • With entailment off, preparation is unchanged: still per file, so a file that is also bound as a named graph is converted only once.

Checked:

  • The W3C suite is unchanged: 2,007 cases, 1,913 pass, 0 fail, 94 unsupported.
  • Through the CLI, the inference now holds for two Turtle files and for two HDTs.
  • A query with entailment leaves nothing in TMPDIR beyond hdt's lock directory.

Also found while writing these

  1. An unwritable output path gives a vague error. de create --output-name /no/such/dir/x.hdt … fails with No such file or directory (os error 2), without naming the path. The test asserts only that message, so it can be tightened when the message names the path.
  2. HDT output isn't byte-reproducible. The header records the creation time (dcterms:issued), so two runs on the same input differ. A reproducibility test would have to compare everything but the header, so this PR doesn't add one.

Left for later

  • The older tests still compare against inline strings; only the new multi-line results use tests/goldens/.
  • FROM / FROM NAMED with local files is unit-tested in src/query.rs but has no CLI test yet.

Checked locally

  • cargo fmt --check.
  • cargo clippy --workspace --all-targets -- -D warnings -W clippy::pedantic, with and without --all-features.
  • cargo nextest run --profile ci: 83 passed.
  • cargo machete: no unused dependencies.
  • --test test-serve: 15 passed.
  • --test w3c-sparql: 1,913 pass, 0 fail, 94 unsupported, as on main.

🤖 Generated with Claude Code

GregHanson and others added 2 commits November 5, 2026 14:03
Covers what the per-subcommand suites didn't check end to end:

- view: header statistics, graph IRI metadata, several files, and missing
  or non-HDT input.
- create: every accepted RDF serialization yields the same graph; failed
  creates exit non-zero and leave no output or temp files; named graphs
  merge only with --allow-merge-named-graphs.
- query: CONSTRUCT in every RDF format, ASK in every results format, OWL RL
  entailment, --named-graph bindings, mixed HDT and RDF inputs, several
  --sparql files, error exits, and --debug-query-plan.

Multi-line expected results are committed under tests/goldens/.
test_query_owl_rl_entailment_across_data_files is #[ignore]d: entailment
is computed per --data file, so an ontology in a separate file is never
applied to the data.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With --entailment owl-rl, each --data file was prepared, and its closure
computed, on its own, so an ontology in one file never applied to the
data in another: `--data data.ttl ontology.ttl` inferred nothing.

The default graph is the merge of its files, so when entailment is on and
it has more than one file, prepare them together with handle_files, which
already computes one closure over all its inputs. Each named graph keeps
a closure of its own, and without entailment preparation is unchanged.

test_query_owl_rl_entailment_across_data_files is no longer ignored, and
now covers the ontology as Turtle and as HDT.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@GregHanson GregHanson changed the title Add CLI integration tests for create, query and view Add CLI integration tests for create, query and view; fix OWL RL entailment across --data files Nov 5, 2026
@GregHanson
GregHanson marked this pull request as ready for review November 5, 2026 19:23
@GregHanson
GregHanson merged commit 94bc7f3 into main Nov 5, 2026
8 checks passed
@GregHanson
GregHanson deleted the cli-integration-tests branch November 5, 2026 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant