Skip to content

conformance: test the parser against the documented query corpus - #2

Merged
be-thomas merged 4 commits into
mainfrom
feat/spl-corpus
Oct 26, 2026
Merged

be-thomas merged 4 commits into
mainfrom
feat/spl-corpus

Conversation

@be-thomas

@be-thomas be-thomas commented Oct 26, 2026 •

Copy link
Copy Markdown
Owner

What this changes

Adds conformance/corpus/: query collections gathered once and checked in,
plus TestCorpus to run them against both front-ends on every make check.
There are two kinds of collection, and the distinction is recorded in each
metadata.json.

Collection Kind Queries Source
spl1 documented 549 Splunk Enterprise search reference, 9.0 through 10.0
spl1-detections derived 2171 Splunk security_content detections, macro-expanded
spl2 documented 92 Splunk Cloud Platform SPL2 search reference (unversioned)

2,812 queries in total.

  • scripts/gather-corpus.py refreshes all three. It is the only part that
    touches the network and is never run by the tests or CI.
  • conformance/corpus/README.md documents the format, the refresh and
    baseline workflow, and the provenance; CONFORMANCE.md,
    THIRD_PARTY_NOTICES.md and CHANGELOG.md are updated.
  • The eight inline comments from the first review are addressed in d358ee6,
    and the six from the second review in 346331a: multi-line quoted search
    scalars, code fences mistaken for macros, whitespace introduced by macro
    expansion, licence-text checking, queries_per_version reconciliation, and
    cleanup of a failed archive extraction.

The derived collection

Documentation examples are short and usually demonstrate one command. The
detection searches in splunk/security_content are the queries analysts
actually write. Most call macros, so the gatherer expands the repository's own
definitions (with $argument$ substitution, up to eight rounds) and cuts the
pipeline at the first stage that still calls a macro the repository does not
define — those usually come from an app. What is stored is the detection's own
SPL up to that point: nothing invented, nothing reordered, duplicates stored
once with every source detection listed.

The repository is pinned at commit a3f6523eabf696d66e20fdd80766bfae95575577.
It is Apache-2.0, so the collection records kind, transform and license
in metadata.json, ships the licence text beside the queries, and
THIRD_PARTY_NOTICES.md states the changes as section 4(b) requires.

The version is metadata, never inferred

A query file does not say which release it belongs to and the parser cannot
guess it — from is the only textual hint and both dialects use it — so each
collection records dialect, versions, retrieval date and counts in
metadata.json, and each line lists the source versions that contain it. The
derived collection records the security_content commit instead of a Splunk
release; SPL2 is published unversioned and records current.

The test

TestCorpus asserts three properties, aggregated per dialect:

  • Robustness. Every query parses, or is refused with a positioned
    *diag.Error. A panic, an error that is not a *diag.Error, a diagnostic
    without a code, or a position outside the input fails, whatever the query
    says.
  • Stability. The outcome (accepted or error:<code>) matches the
    baseline on each line, so any change in what the parser does with gathered
    syntax shows up as a reviewable diff. make corpus-update re-records it and
    exits 0; the baseline is a snapshot, not a correctness claim.
  • Coverage. Every implemented command starts at least one stage in the
    collections of its dialect. One documented exception: the SPL2 reference
    describes WHERE as a clause of FROM, so no documented query starts a piped
    where stage.

It also validates each collection's kind and what that kind promises: a
derived collection must name its transformation, its licence, and carry the
licence text beside the queries; a documented collection must not claim
either. The corpus floor is 2,000 queries.

Recorded outcomes

Collection Queries Accepted unsupported-command syntax Other
spl1 549 69 434 40 6 (unsupported-subsearch 5, unknown-command 1)
spl1-detections 2171 15 1312 837 7 (unknown-command 4, unsupported-subsearch 3)
spl2 92 0 13 79 —

What the corpus says about the parser

The derived collection is where the gaps are visible, and they are the point
of the exercise rather than a regression:

  • 1,022 refusals are tstats alone, 112 are rename, 63 fillnull, 32
    bucket, 27 spath, 14 mstats, 8 lookup.
  • The largest positioned syntax classes are unexpected "-" (248), unexpected "," (179, mostly IN (a, b) value lists), unexpected character "{" (98,
    JSON object literals), and space-separated stats arguments
    (stats count min(_time) AS firstTime …, about 125 across min/max/
    values/dc), plus 0x… numeric literals (21). unexpected character ""`
    (38) is the code-fence prose a few detections quote inside their own search.

Fixing any of these changes exactly one baseline line per query.

Tests run

  • make check — gofmt, go vet, go test ./..., build: pass.
  • go test -race ./...: pass.
  • ./scripts/gather-corpus.py re-run twice: byte-identical output, so the
    checked-in corpus matches the gatherer and the gatherer is idempotent.
  • make corpus-update followed by a clean TestCorpus.
  • Negative checks in a scratch copy: a bogus LICENSE under Apache-2.0 and a
    queries_per_version set to 1 both fail TestCorpus; a non-tar cached body
    exits with the archive error and leaves no temporary directory behind.
  • Two independent reviews were run on this PR, one per head commit; every
    inline comment is fixed or answered and all threads are resolved.

Open questions

  1. Documented SPL2 does not match the supported subset. 79 of the 92
    documented SPL2 queries are syntax refusals. The reference writes clauses
    without a pipe (FROM main WHERE status=200 | stats count() BY host), while
    the subset requires from main | where ... | stats ...; GROUP BY ... SELECT, quoted aliases and stats count AS x are also documented. Should
    the SPL2 grammar accept unpiped clauses before the corpus is widened
    further?
  2. Which parser gaps to take next. The corpus now records them rather than
    hiding them. tstats is the single largest; space-separated stats
    arguments and IN (…) lists are the cheapest syntax wins. Is there an order
    the maintainer prefers, or should this PR stay corpus-only?
  3. Licensing. Documentation-derived blocks are reproduced as short test
    data with page and version provenance, and the detection searches are
    Apache-2.0 with the notice and licence text committed. Is checking both in
    acceptable, or should either be gathered locally instead of committed?

Add conformance/corpus with the example queries from the Splunk SPL and SPL2
search references, gathered once and checked in, and TestCorpus to run them.

A query file does not say which release it belongs to, and the parser cannot
guess: `from` is the only textual hint and both dialects use it. Each
collection therefore records its dialect, documentation versions, retrieval
date and counts in metadata.json, and each line lists the versions that
contain it.

TestCorpus asserts three things. Robustness: every query parses, or is refused
with a positioned *diag.Error; a panic or an unpositioned error fails whatever
the query says. Stability: the outcome matches the recorded baseline, so a
change in what the parser does with documented syntax is a reviewable diff.
The baseline is a snapshot, not a correctness claim, and `make corpus-update`
re-records it. Coverage: every implemented command starts at least one stage
in its collection. That check found 17 real Splunk commands missing from the
known-command table (localop, makemv, sitop, anomalousvalue, audit,
addcoltotals, meventcollect, concurrency, anomalies, gauge, tojson, geoip,
overlap, convert, delta, erex, geom), so they now report unsupported-command
instead of unknown-command; the table is alphabetical for checking against
the reference.

scripts/gather-corpus.py is the only part that touches the network, and
neither the tests nor CI run it. The queries are the documentation's own
example blocks and remain Splunk's material; the provenance is recorded in
conformance/corpus/README.md and THIRD_PARTY_NOTICES.md.

@be-thomas be-thomas left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The corpus is a useful addition, and the harness itself is careful: it checks positioned diagnostics, recovers panics, preserves baselines by query text, and the gatherer reproduces the checked-in files byte-for-byte (I re-ran it offline against the page cache; both queries.jsonl and both metadata.json came out identical). gofmt, go vet and make check are clean, and 26 CLI spot checks matched the recorded expect.

I did find one path that can remove corpus content with no signal (a partial fetch failure silently shrinks the corpus), two classification gaps that make the corpus record success for documented commands the parser does not actually implement, and a filter rule that drops every documented query containing a subsearch or array. There are also two smaller workflow/documentation problems around -update-corpus and running the gatherer.

Finding summary:

  1. scripts/gather-corpus.py: a page whose fetch keeps failing is skipped, and the script still rewrites the corpus with fewer queries and exits cleanly (reproduced: 505 -> 500).
  2. pkg/parser/commands/commands.go: spl1Known is missing seven documented commands that the corpus already contains; they parse as free-text search and are recorded accepted.
  3. conformance/corpus/spl2/queries.jsonl: fieldsummary is a documented SPL2 command but is absent from spl2Known, so two baselines record unknown-command.
  4. scripts/gather-corpus.py: the placeholder rule rejects [...], which in SPL is a subsearch or array, so no committed query contains a bracket.
  5. scripts/gather-corpus.py: the acceptance rule lets syntax templates and REST parameter fragments into the corpus.
  6. conformance/corpus_test.go: -update-corpus rewrites the file and then fails the test.
  7. scripts/gather-corpus.py: the docstring names the wrong flag (-update).
  8. conformance/corpus/README.md: the documented direct invocation fails because the script is not executable.

Verdict: findings to address; the silent-shrink path in item 1 is the one I would block on.

Comment thread scripts/gather-corpus.py Resolved
Comment thread pkg/parser/commands/commands.go Resolved
Comment thread conformance/corpus/spl2/queries.jsonl Resolved
Comment thread scripts/gather-corpus.py Resolved
Comment thread scripts/gather-corpus.py Resolved
Comment thread conformance/corpus_test.go Resolved
Comment thread scripts/gather-corpus.py Resolved
Comment thread conformance/corpus/README.md Resolved
Address the review of the documented corpus:

- gather-corpus.py: a failed page fetch is now an error, not a page
  without queries, so the corpus cannot shrink because the network was
  flaky; --allow-partial overrides it deliberately.
- gather-corpus.py: drop the bracket filter. It removed subsearches and
  array literals along with the configuration stanzas it was meant for.
  A block that starts with a bracket and a block containing the
  commandname metavariable are now refused directly.
- corpus_test.go: -update-corpus rewrites the baseline without also
  failing the run, so `make corpus-update` exits 0 when re-recording.
- commands.go: regenerate spl1Known from the search reference and list
  every documented SPL2 command in spl2Known. Seven SPL1 commands were
  parsed as free text, which emitted a query instead of a refusal, and
  fieldsummary was reported as unknown.

The corpus grows to 549 SPL1 and 92 SPL2 queries; baselines re-recorded
with `make corpus-update`.
The documented corpus has breadth, but a documentation example is short
and usually demonstrates one command. Add a second kind of collection:
the detection searches of the Splunk security_content repository, which
are the queries analysts actually write.

Those searches call macros, so the gatherer expands the repository's own
macro definitions and cuts the pipeline at the first stage that still
calls a macro the repository does not define. What is stored is the
detection's own SPL up to that point, with nothing invented and nothing
reordered. The collection is recorded as kind "derived" with the
transformation and the Apache-2.0 licence, and the licence text ships
beside the queries.

That adds 2145 unique queries, taking the corpus from 641 to 2786. The
recorded baselines show where the parser actually stands: 1019 of the
new refusals are tstats, 113 rename, and the largest syntax classes are
space-separated stats arguments, IN value lists, and JSON object
literals.

TestCorpus now validates the kind and what it promises, requires 2000
queries rather than 200, and checks command coverage per dialect rather
than per collection: a source that documents a single command should not
have to repeat every other command's example.

@be-thomas be-thomas left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the PR delta dc83fd3..f312cd3, concentrating on the new derived spl1-detections collection and its gatherer. Verified that make check and go test -race ./... pass, that a re-run of scripts/gather-corpus.py is byte-identical (git status stays clean), and that spl1-detections/LICENSE is identical to the upstream security_content Apache-2.0 text at the pinned commit. The documented counts (549 / 2145 / 92, total 2786), the layout, and the available flags are accurate. Six defects are reported below: three in how the gatherer derives the queries (a YAML truncation, the backtick cut rule, and the ordering of whitespace normalization), two gaps in what TestCorpus actually validates, and one archive-extraction weakness.

Comment thread scripts/gather-corpus.py Resolved
Comment thread scripts/gather-corpus.py Resolved
Comment thread scripts/gather-corpus.py Resolved
Comment thread conformance/corpus_test.go Resolved
Comment thread scripts/gather-corpus.py Resolved
Fold quoted search scalars that continue on following lines instead of
storing the first line, and refuse a search whose quote never closes.
Cut a pipeline only where a stage still calls a macro, so the triple
backtick code fences inside detection searches are kept rather than
read as unexpanded macros. Normalize whitespace after macro expansion,
which can itself introduce newlines.

Extract the pinned archive only through tarfile's data filter, and
remove the temporary tree when the cached body is not a readable
archive. Check the declared licence text instead of the file's
presence, and reconcile queries_per_version with the versions recorded
on each query line.

Re-gather: 2,812 queries (549 documented SPL1, 2,171 detections,
92 SPL2).
@be-thomas
be-thomas merged commit 0327260 into main Oct 26, 2026
5 checks passed
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