Repository navigation
feat(json-ld)!: run the W3C suites, and read @base, @type and contexts as JSON-LD 1.1 does - #2396
Conversation
aaj3f
left a comment
There was a problem hiding this comment.
@bplatz this is great, and it's the testsuite-sparql pattern again, so no notes on the shape. Claude ran it on a box merged with each fix: #2393 flips nothing, #2397 its nine entries, #2400 its sixteen.
On plain names: my reading is that this turns a long-standing behavior into a promise, which also settles my #2080 item. I'm on board for keys and name-like types, since Cypher depends on them, but it seems to me that a relative @type under @base should resolve as an @id does, not stay #x (te062). I've laid out A against B on compatibility.md:90, and I'm happy to hear the case for A.
I agree with the two smaller decisions, ? strings as variables and the three standing deviations, and would just like your confirmation (below).
I'd land this first, so each fix drops its own entries. The fixes' green runs predate this job and next has no required checks, so each one needs a fresh run after rebasing.
Full review below:
✅ Approving to unblock: before merging, I'd like us to settle the relative-@type question on compatibility.md:90, either with the four register moves and "a name" in the docs, or with your case for keeping them as plain names. This is a clean extension of the testsuite-sparql pattern, and Claude couldn't find a way to make it pass something it shouldn't. Otherwise the notes below are small.
Before merging:
docs/reference/compatibility.md:90: settle whether a relative-reference@typeunder@baseis a plain name (A) or resolves like an@id(B, my recommendation).
Decisions on the record: My reading is that ? strings now sit on the deviation list as variables for keys, @id and @type, as the concepts page has said since #2284, and that the transaction envelope, 1.1-only processing and no rdfDirection are now standing deviations rather than gaps we mean to close. I think both are right, but I'd like your confirmation they're intended.
Notes:
- Merge order with #2393, #2397 and #2400. Claude merged each one onto this head on a box and ran the suite.
- #2393 flips no entries and stays green.
- #2397 flips the nine in its body. After it, expand t0111/t0112 differ only on
?query=works, so they move to the?group. toRdf te111/te112 also keep an ill-formed…rel2##fragment-workspredicate, which is #2395's toRdf cause. - #2400 flips its sixteen, and te120/te121 go from kept to refused.
- All three together flip 25, so the fixes don't interact.
- The only conflicts are in
compatibility.md(#2397 and #2400 with this PR and with each other), and keeping both texts resolves each one. - None of the three has a
testsuite-jsonldrun yet, so whichever lands after this needs a fresh one before merging.
- A defect class this harness starts to measure. Several readers turn expanded JSON-LD into statements, and each re-derives the rules: the adapter, the transaction parser, and the
whereparser. Instances so far: the documented blank-node@typesplit between bulk import and a transaction, #2357 (wheremirroring the insert side for@json), #2360 (node_map.rsreading@directionon its own), #2080 (graph names per reader), #2393'swhere-side value objects, and the transaction parser applying the document's@contexttwice (the compounding relative@vocabon #2397). The class fix would be one expanded-JSON-LD-to-statements path, or running toRdf through the transaction parser too. That's not for this PR; this is the first half of it. main→next. JSON-LD conformance fixes that go tomain(per the #2283 call) reach this register through the periodicmain→nextmerge. Whoever does that merge drops any entries themainfix makes pass.- #1733 (mine). This adds no new conflict there. #1733's one
ci.ymlconflict is the one it already has withnext, and thetestsuite-jsonldjob merges cleanly.
Adherence: Patterns ✔ · Performance ✔ · Deployment targets ✔ · Testing ✔ · Conventions ⚠️ · verification
- Patterns/abstractions: ✔ Extends the
testsuite-sparqlpattern (standalone crate, excluded from the workspace,tests/registers/mod.rs, two-way check, its own CI job), with two extra checks: a duplicate entry and an id the manifest dropped. - Performance (speed first, memory second): ✔ Test crate, CI and docs only. No shipping code is touched, so there's no performance-degradation risk.
- Deployment targets: ✔ n/a: a test-only crate outside the workspace.
- Testing: ✔ The harness's 6 unit tests run in the new job. The two-way register goes red on every comparator and register mutation Claude tried, and the job is green on the exact head.
- Conventions:
⚠️ Multi-line conventional commits, and fmt and clippy are clean intestsuite-jsonld/.CLAUDE.md:29undercounts the fmt/clippy pairs (inline).
Verified at fc38c926d: On EC2 with toolchain 1.97.0, Claude ran the following in testsuite-jsonld/:
cargo fmt --all -- --check,cargo clippy --all-targets -- -D warningsandcargo testall pass.- The suite reports expand 139 passed / 238 registered / 9 1.0-only and toRdf 219 / 237 / 11, with 0 problems.
- Merged with each of #2393, #2397 and #2400 and with all three, the flips are 0 / 9 / 16 / 25.
- Four mutations of the comparators, the register and list order all went red.
- 8 extra isomorphism cases pass.
- CI run
43611894476on this head is green,testsuite-jsonldincluded.
Approving so you can merge when ready, but maybe worth considering a few of these first.
| Fluree extension: a node's own `"@graph": "<graph IRI>"` writes the node, and every node nested in it, to that graph (`"default"` and `"config"` name the default graph and the ledger's config graph). `@index` is accepted and ignored. | ||
|
|
||
| Deviations from the JSON-LD 1.1 expansion algorithm: | ||
| - **Plain names, by design.** A key or `@type` value the context maps to no IRI is stored as written, as a plain name: with no `@vocab` (and no `@base` standing in for one), `{"@type": "Person", "name": "Ann"}` writes the class `Person` and the property `name`. The algorithm drops such a key, and resolves such a type against the base. Fluree keeps both because Cypher reads and writes the same plain names (as a Cypher import does by default), so a JSON-LD write and a Cypher query meet on one ledger. A term defined only in a property-scoped context, used outside it, is a plain name the same way. A misspelled key is stored under its misspelling; a SHACL shape with `sh:closed` refuses properties a class does not declare. |
There was a problem hiding this comment.
Decision on the record: plain names, and the one case I'd like us to treat differently.
My reading is that this commit turns a long-standing behavior into a documented promise: any key or @type the context maps to no IRI is kept as a plain name, by design, rather than being a gap we mean to close. No code changes, but it's still a posture change, because once 5.0 ships with it stated as intent, narrowing it later is a breaking change. It also settles my #2080 item, which I'm glad to check off.
JSON-LD itself does two different things here. An unmapped key is dropped. An unmapped @type is vocabulary-relative: it's joined to @vocab when there is one, and otherwise resolved against the document's base as a relative IRI reference. So plain names depart from the spec in both places. The key half is easy to accept: dropping a key silently loses data, and Cypher reads and writes the same plain names, so a JSON-LD write and a Cypher query agree with no context at all.
Option A (this PR) and option B agree on everything Cypher needs: Person, name and other name-like strings stay plain names either way. They differ only on a @type written as a relative reference (#Person, ../x, /x) in a document that declares an explicit @base:
- A:
"@type": "#Person"is the class#Person, while"@id": "#alice"in the same document resolves to<base>#alice, as it has since feat(rdf)!: JSON-LD @base, scopes and @direction per spec; RDF term equality and document order in Python #2284. A Turtle file with the same base anda <#Person>writes<base>#Person, so the two imports disagree. - B: the
@typeresolves against@basethe way the@iddoes. Everything else stays as this PR has it.
I'd recommend B. A string that looks like a relative reference, in a document that declares a base, reads to any JSON-LD user as relative to that base. That's the case where "plain name" is least likely to be what the writer meant, and under A one document writes one IRI for an @id and a different one for the same string as a @type. B keeps the Cypher rationale whole, since the Cypher import's JSON-LD carries no @base, and it's what the register's own IRI-expansion header already says. In this PR, B costs filing t0029/t0062 and te029/te062 back under #2395 and saying "a name" rather than "a key or @type" in the two doc paragraphs. The code change would ride with #2395 before 5.0, with an upgrade note in the #2284 manner.
That said, A is a defensible one-rule design, and you know the Cypher and import paths better than I do, so if you'd rather keep A, I'd like that case made here. Then the docs should state the relative-@type consequence outright, and the IRI-expansion header should drop "a relative @type", so the register doesn't say both things.
What Claude checked: the plain-names group in the register (testsuite-jsonld/tests/registers/mod.rs:99-105, :377-383) also holds t0029/t0062 and te029/te062. At this head, those tests differ from the spec only on relative-reference @type values (#fragment-works, ../parent, /absolute, //example.org/scheme-relative) and on ?query=works. In te062, with an explicit @base, the same string #fragment-works resolves to <http://example.com/some/deep/directory/and/file#fragment-works> as a list member's @id, but stays <#fragment-works> as an rdf:type. Claude ran each of these with JSONLD_TEST on a box to check.
Meanwhile, the IRI-expansion group's header (registers/mod.rs:218, :489) still lists "a relative @type … is not resolved against the base" as a #2395 gap, so right now the register says both things.
There was a problem hiding this comment.
Addressed in bd155a2. B, for a node's @type and a value object's datatype, in the shared expander (bulk import, rdf::parse, inline shapes). Transactions and queries still read a lone @base as the @vocab, so there a @type joins the base; compatibility.md now lists that as a deviation.
| "https://w3c.github.io/json-ld-api/tests/expand-manifest#t0036", // Expanding @index | ||
| "https://w3c.github.io/json-ld-api/tests/expand-manifest#t0044", // Index maps with language mappings | ||
| "https://w3c.github.io/json-ld-api/tests/expand-manifest#t0063", // Reverse property and index container | ||
| // A key in keyword form that is no keyword (`"@ignoreMe"`) is kept on the node, |
There was a problem hiding this comment.
This is more of a question than a suggestion. I think t0120 and t0121 (and te120/te121 at :363-368) only partly belong to this cause.
In t0120 the context maps "at" to "@" and "foo.bar" to "@foo.bar". Neither is keyword form, and is_keyword_form (fluree-graph-json-ld/src/lib.rs:69-71) agrees. So the spec expands them under @vocab to http://example.orb/vocab/@ and …/@foo.bar, while Fluree keeps @ and @foo.bar as written. That reads like #2395's "terms that begin with @" cause rather than the documented @ignoreMe deviation. Filing it here hides it from #2395's decision list.
Maybe list them under the IRI-expansion group, or name both causes in the comment? Separately, once #2400 lands, te120/te121 are refused rather than kept (Claude checked at the merge), so this comment goes a little stale for them. This is minor and non-blocking, but if you agree it's right, I'd rather see it folded in now than lost in the backlog.
| `working-directory: testsuite-sparql`, which is *excluded* from the workspace. A root | ||
| `cargo fmt --all` never reaches it. If you touched `testsuite-sparql/`, format and lint there | ||
| separately. | ||
| - CI runs **three** fmt/clippy pairs — one over the workspace, and one each with |
There was a problem hiding this comment.
Not a big deal, but I think this is four now, not three: fluree-sql-bridge has its own fmt/clippy pair too (.github/workflows/ci.yml:278-283). The old "two" had been stale since that job landed in 4e2675733.
This is the line agents read before pushing, so maybe name the three excluded crates (testsuite-sparql, testsuite-jsonld, fluree-sql-bridge) instead of a count. Then the next crate that adds a job only appends a name. It's minor, but I'd rather see it in this PR than lost in the backlog.
| - There is no JSON-LD 1.0 processing mode: every document is read as JSON-LD 1.1. | ||
| - The `rdfDirection` option of JSON-LD's conversion to RDF is not offered: a `@direction` is kept in the language tag (see base-direction tags above). | ||
|
|
||
| The W3C json-ld-api expand and toRdf suites run in CI. `testsuite-jsonld/tests/registers/mod.rs` lists each test Fluree fails, with its cause: one of the deviations above, or an open issue (see [the JSON-LD compliance suite](../contributing/jsonld-compliance.md)). |
There was a problem hiding this comment.
This is so minor, but the section's status line (compatibility.md:67) still reads "Status: Compliant, with the deviations listed below". This suite now shows that's only part of the story: of the 475 registered failures, #2395 counts 222 as listed deviations or existing issues, and the rest are its open gaps (@protected not enforced, invalid documents accepted, and so on).
This sentence already says "or an open issue". Maybe the status line could say the same, e.g. "Compliant with the deviations listed below; the open gaps the W3C suite reports are tracked in #2395." I recognize the status line is pre-existing, but this PR is what makes the gap measurable, so I'd rather fold it in here.
Commenting here because compatibility.md:67 is not in this diff.
| toRdf manifests, as the test fns `jsonld_expand` and `jsonld_to_rdf`. It tests | ||
| `fluree-graph-json-ld`, the expander every JSON-LD reader shares | ||
| (transactions, bulk import, `rdf::parse`, inline SHACL shapes), and the | ||
| adapter that turns expanded JSON-LD into RDF statements. |
There was a problem hiding this comment.
This is more of a question than a suggestion. If I'm reading the readers right, toRdf covers the adapter. Bulk import (fluree-db-transact/src/import.rs:249), rdf::parse (fluree-db-api/src/rdf.rs:382) and inline shapes all use it. A JSON-LD transaction expands with the same expander (fluree-db-transact/src/parse/jsonld.rs:434), but then builds its triples with its own parser.
So a toRdf pass says nothing about what an insert writes, and the expand suite doesn't quite either. A transaction parses the document's @context first (fluree-db-transact/src/parse/jsonld.rs:426) and then expands the document, which still carries it, against that result. So the context applies twice (fluree-graph-json-ld/src/expand.rs:818-822), where the harness applies it once (testsuite-jsonld/src/expand.rs:32). Claude reproduced on #2397's head that a relative @vocab then compounds ("@vocab": "rel/" → …/rel/rel/name). Maybe a clause here naming which reader each suite covers, and, cheaply, an expand run that calls the expander the way a transaction does (parse the context, then expand the document still holding it)? It's minor and non-blocking for this PR, but if you agree it's right, I'd rather see it folded in now than lost in the backlog.
| }; | ||
| eprintln!("{} ({}): {detail}\n", test.id, test.name); | ||
| } | ||
| match (result, is_registered) { |
There was a problem hiding this comment.
Really nice. Claude mutation-checked this on a box:
- Forcing
isomorphictotruegives 81 "passes but is in the skip register" problems. - Forcing
equivalenttotruegives 87. - Editing the register (dropping t0003, adding a bogus id, registering a passing test) gives exactly those three problems.
So the two-way check also protects the harness from its own comparators getting too lenient, which is the property I'd most want to keep. The isomorphism check held up too, including two triangles against a hexagon, which colour refinement alone can't tell apart.
CI runs fmt and clippy inside fluree-sql-bridge too, so the count in CLAUDE.md was one short. Naming the crates instead of counting them means the next crate that gets its own job only adds its name.
The JSON-LD 1.1 status read as compliant apart from the listed deviations, but the W3C suite also reports gaps no deviation explains: @Protected is not enforced, some invalid documents are accepted, and so on. The status line now says those are tracked in #2395.
t0119 to t0122 (te119 to te122 in toRdf) sat under the documented deviation for keys in keyword form (`@ignoreMe`), but each of them fails on `@` and `@foo.bar` as well. Those are not in keyword form, so the algorithm treats them as terms and IRIs and expands them; Fluree keeps them as written. That is an open #2395 cause, and filing these tests under a documented deviation took them off its decision list. t0121 and te121 fail on that cause alone. The others also carry `@ignoreMe` (kept on the node in expand, refused by toRdf, or as an `@id` value in t0122), which their entries now note. The IRI-expansion group comment names the `@` cause precisely: begins with `@` but is not in keyword form.
…nsaction does The compliance page said the suites test the expander and the adapter, which read as covering every JSON-LD reader. The expand suite does cover the expander they all share. The toRdf suite covers only the adapter (bulk import, rdf::parse, inline shapes): a JSON-LD transaction builds its statements with its own parser, so a toRdf pass says nothing about what an insert writes. The page now says which reader each suite covers. A transaction also calls the expander differently. It parses the document's @context first, then expands the document, which still holds it, against that result, so the context applies twice. The harness applied it once. A new lane, jsonld_expand_as_transaction, expands every expand input both ways and fails where they differ: one refuses and the other doesn't, or the output differs. A context that resolves differently when applied over itself, such as a relative IRI resolved against the value in effect, then fails the suite. Every test agrees at this head, so its register is empty.
…ser does The checks that run on a JSON-LD transaction before it is parsed read its top-level @context without the parser's rule that a lone @base is also the @vocab, so they could resolve a key differently from the parser. Both now take the context from one helper, top_context. The annotation lowering keeps the context it had, now parsed only when the document has annotations. An invalid @context is reported as before.
The expander read a bare `context` key as the node's @context, on every node and in every JSON-LD reader. JSON-LD has no such alias, and it made a plain-name property called `context` unsafe: an object value was parsed as a context and dropped, and a string value became the node's @vocab, so {"context": "notes", "title": "x"} wrote the property `notes/title`. Only @context is a context now; `context` is a property like any other. A document that relied on the alias no longer gets its prefixes and terms, and a transaction refuses a compact IRI whose prefix only that key defined. The behavior change is noted in compatibility.md. A query's top-level `context` is read by the query parser and is unchanged.
A @type that no term, prefix or @vocab mapped was stored as written, so under an explicit @base `"@type": "#Person"` named the class `#Person` while `"@id": "#Person"` named `<base>#Person`. JSON-LD resolves a @type against @vocab and otherwise against the base (it is both vocabulary- and document-relative), and so does a Turtle file with the same base. The expander now does the same, for a node's @type and a value object's datatype alike, through one helper (vocab_or_base). With no base, a @type is still a plain name, which is what a Cypher import writes. The fallback only consults @base after the term, prefix and @vocab lookups missed, so a plain-name @type with no base pays one extra check. This applies to bulk import, rdf::parse and inline shapes. Transactions and queries read a lone @base as the @vocab too, so they are unchanged; compatibility.md now lists that as a deviation, and notes the change for 5.0. In the W3C register, t0029/t0062 and te029/te062 now differ only on `?query=works`, so they move to the `?`-variable group, the plain-names group covers keys only, and the IRI-expansion group no longer claims a relative @type is unresolved.
A JSON-LD transaction parsed its top-level @context up to four times: two pre-parse checks each read it, the parser read it, and the expander then applied the document's own @context again on top of the parser's result. Applying a context over itself is not a no-op in general (a relative @base or @vocab resolves against the value already in effect), and every copy had its own rule for a lone @base. The parser now reads the root context once (top_context) and every stage takes that one value: the pre-parse checks, the annotation lowering and its delete-clause pre-pass, txn-meta, opts stripping, and expansion. The expander gains expand_with_root_context, which expands a document against an already-parsed root context without applying the document's @context again; the node-object arm of the expander is split out (expand_object) so the root can be expanded with no copy of the document. The checks and the lowering skip the root object's own @context for the same reason. The rule that a lone @base is also the @vocab now lives in one function, fluree_graph_json_ld::with_base_as_vocab, used by transactions, queries, BM25 and datalog rules in place of two copies. The query-side check reads its root context once too. The W3C suite's transaction check now expands each input the way a transaction does, through the parsed root context, and requires the same result as a plain expansion; all 377 inputs agree.
The checks that run on a JSON-LD transaction before it is parsed resolved its compact keys with a copy of the context rules of their own, which applied a node's @context and nothing else. The expander also applies type- and property-scoped contexts, so the two could resolve a key differently, and every rule the expander gains had to be copied. The checks now read the expanded document instead, where every key is the IRI the parser writes, resolved by the expander itself (refuse_reserved_iris). An ordinary transaction is checked on the expansion the parser already makes, so it does no extra work; the compact-form walk that resolved every key is gone. A document with annotations is checked as written, expanded once more before the lowering adds statements of its own; the lowering still runs first, so a document it refuses keeps its reason. An update's `where` and `values` get the query side's check, and txn-meta keys the same predicate check. Bulk import checks the expansion of every document, rather than only those whose text matched a substring. The expander now keeps a value object's `@edge` (an alias of `@annotation`) expanded, as it already did on a node reference, instead of dropping it.
…under
The annotation lowering wrote the annotated edge's predicate into its
slot as `{"@id": <key as written>}`, and the parser resolves an @id
against @base, not @vocab. The edge itself is written under the key
resolved as a key. So under `"@vocab": "http://v.example/"` the edge was
`http://v.example/worksFor` while the annotation's rdf:reifies link named
the plain `worksFor`, and under a lone `"@base": "http://example.org/doc"`
the edge was `…/doc/worksFor` and the link `http://example.org/worksFor`.
The annotation then described a triple that was never written. A key
with a prefix or a term was unaffected.
The slot now holds the key resolved by vocabulary rules, against the
context the parser uses (predicate_slot), for @annotation, @reifies and a
delete clause's annotation alike.
The checks decided from a document's shape whether it was an update: a document whose keys were all `insert`, `delete`, `upsert` and reserved keys was read as an update's clauses, so only the clause values were expanded and checked. An insert may name its own properties that way, and those keys were then never checked. The checks now take the transaction's type from the caller, and read an insert or upsert as one document, all of whose keys are data. An update with annotations was also passed through the insert-only stripping of reserved keys, whose collision check refuses a context term named like a dataset key (`from`). The update is now checked as written.
The expander resolves a @type, and a value object's datatype, against @vocab and otherwise against @base. A JSON-LD query's where resolved them against @vocab only, so with a base and no @vocab (an explicit `"@vocab": null`, or a context array) an update wrote `"#Person"` as `<base>#Person` and its where looked for the IRI `#Person`, and a query missed what the same document wrote. The library exposes the expander's rule as expand_type_iri, and the query parser uses it for a @type value and a datatype, in where and in values.
…'s key does The previous change resolved an annotated edge's predicate in the lowering, against the document's top-level context. That fixed a bare key under @vocab, but the lowering does not see property- or type-scoped contexts, so a key defined in a scoped context named its outer definition in the link while the edge was written under the scoped one. The lowering now writes the predicate as a key, on a helper node in the slot (`{"<key>": {"@id": "_:fluree_ann_predicate"}}`), so the expander resolves it by the rules and contexts a key there gets: a term, a prefix, @vocab, or a plain name, and the property-scoped contexts in force. After expansion, resolve_predicate_slots replaces each helper with a reference to that IRI, before the transaction parser builds statements and before bulk import hands the document to the adapter. The helper's label is in the reserved prefix, so a document cannot write one. A key defined only in its subject's own type-scoped context, which does not propagate to the nodes nested in it, still resolves differently in the slot; that needs the lowering to run on expanded JSON-LD.
A write resolves a node's id, a reference under a term typed @id and a value object typed @id against @base, and a string under a term typed @vocab as a @type is. The query parser resolved several of these against @vocab instead: a graph-select root (`{"alice": ["*"]}`), a `values` `{"@id": …}` and a triple term's subject there, a value object typed @id, a string under a term typed @id, and a property path's object. With an @vocab and an @base that differ, a query then named other IRIs than the same document wrote: under `"@vocab": "http://v/"` and `"@base": "http://b/"`, the root `alice` was `http://v/alice`. Each now resolves as on write: as an @id, against @base, and a string under a term typed @vocab (or a class) as a @type, against @vocab and then @base.
Transactions, queries, datalog rules and BM25 index definitions read a top-level @base with no @vocab as the @vocab too, so a key and a @type joined the base as a string. Bulk import, rdf::parse and inline shapes did not, so the same document wrote different IRIs depending on the reader, and under a base ending in a path segment or `#` the joined IRIs were neither what JSON-LD gives nor what Turtle does (`http://example.org/ns##Person` for `"#Person"`). Every reader now takes the context as written. A key the context maps to no IRI is a plain name; a @type resolves against @vocab and otherwise against the base, as an @id does. To keep keys and types in the base's namespace, set @vocab to the same IRI. with_base_as_vocab is gone; a context that sets @base with no @vocab is logged once per process (note_lone_base), since data written under the old reading no longer matches it. compatibility.md folds this into the 5.0 note on @base and drops the deviation it listed.
The annotation lowering rewrote a transaction's compact JSON before expansion, resolving keys with its own copy of the context rules, and the reserved-predicate check then expanded the document a second time, as written, since the lowered copy holds the slots the lowering writes. The lowering now runs on each clause's one expansion, after the check has read it. An annotation on a property's value becomes a node included in the edge's subject, its f:reifies* slots naming the IRIs the expander resolved: the edge's predicate is the key its value is under, so a key that the subject's type-scoped context defines (a context the annotation node does not see) names the same predicate in the link as in the edge, in an insert and in a delete. A delete's retraction by selector builds its where pattern from the same expansion. Bulk import lowers each expansion the same way. The expander keeps @Ttl / @expiresAt as written, on value objects and on nodes, for the lowering to read. What follows from reading the expansion: - Under a term typed @JSON the whole value is one JSON literal, as JSON-LD expands it, so an @annotation written in it is part of the JSON (it was refused). - An annotation inside @nest annotates the enclosing node's edge (it was refused). - An annotation's body is expanded where its value is, so a property-scoped context reaches it. - An @annotation array holds several annotations, each its own reifier (an array was refused). - A value object's entries other than its value, datatype, language and annotation are dropped by the expander, as for any value object, so a keyword in one is no longer refused.
…ng binds it In an update's delete and insert, a string starting with ? in a value position was always a variable. When the where and values never mentioned it, nothing could bind it, and the triple was silently not written: an update writing the string "?todo" (a GraphQL field, a memory tag, a label) committed without it. A value is now a variable when the where or values mentions its name, in any form (a pattern, a bind or filter expression, the where a retraction by selector adds), and otherwise the string written. A node, property, type or graph is an IRI, which cannot start with ?, so a ? name there that nothing mentions is refused rather than writing nothing. Docs examples that relied on an unbound variable did not do what they said: a delete of "?age", or of "?pred"/"?val", with nothing binding them retracted nothing, and the annotation-metadata update kept the old confidence beside the new one. They bind their variables now. So does the tracing test's update, which meant to replace an age and kept both.
Both intended.
|
Runs the W3C json-ld-api expand and toRdf suites against
fluree-graph-json-ld, and changes the JSON-LD readers where the suites showed them disagreeing with the spec or with each other. The register records where Fluree's JSON-LD reading still differs from the spec; it does not commit Fluree to conforming.The suites
testsuite-jsonldis a standalone crate shaped liketestsuite-sparql.@listas indexed values, so the harness writes each list out as itsrdf:first/rdf:restchain first.@contextparsed once, then applied to the document without being applied again) and the usual way, and fails where the two differ. Its register is empty.tests/registers/mod.rs) lists every current failure, grouped by cause: 236 expand and 235 toRdf, with 141 and 221 passing. Each group is a documented deviation, an existing issue (JSON-LD graph names and scoped contexts: one classifier for every reader, and the context in effect at each node #2080, JSON-LD: a @json-typed term drops null and ignores a @list container #2357, JSON-LD: read @direction from a context and from a term definition #2360), or a cause in JSON-LD: conformance gaps the W3C expand and toRdf suites report #2395.testsuite-sparql. An unregistered failure fails the suite, and so do a registered test that passes, a registered id the manifest no longer has, and a panic.testsuite-jsonldjob (fmt, clippy, test) that fetches only its own submodule.A pass does not check everything:
Reading changes (5.0, breaking)
Each is in
docs/reference/compatibility.md, in the 5.0 section or the JSON-LD 1.1 deviations.@baseresolves references only. A key or@typeno longer resolves against a lone@base: with no@vocab, a key is a plain name, as it is without@base. Set@vocabto the same IRI to keep the earlier IRIs. This holds in every reader: transactions, queries, bulk import,rdf::parse, stored datalog rules and BM25 definitions. A context with@baseand no@vocabis logged once per process. Data written under the earlier reading is not migrated.@typeresolves as JSON-LD 1.1 defines: a term, a compact IRI,@vocab, then the base by RFC 3986. A value object's datatype resolves the same way.@typeand datatypes, and the@idpositions: a select root, avalues@id, a value typed@id, a string under a term typed@id, and a property path's object. Under@vocaband@basetogether, those named other IRIs than the same document wrote.contextkey is data. Only@contextis a context.@contextonce. It was applied a second time to the root node, which compounded a relative@vocab.compatibility.mdalso gains the deviations the suites found that the page didn't list: the transaction envelope, no JSON-LD 1.0 mode, nordfDirectionoption, plain names for keys the context maps to no IRI (as Cypher reads and writes them), and?strings as variables in a key, an@idor a@type.docs/concepts/iri-and-context.mdexplains plain names.Other changes
@json, an@annotationwritten in the value is part of the JSON literal, as JSON-LD expands it.@nestannotates the enclosing node's edge.@annotationarray holds several annotations, each its own reifier.deleteandinsert, a value that starts with?is a variable only when thewhereorvaluesmentions it, and otherwise the string. It was a variable nothing could bind, so the triple was silently not written: GraphQL updates, memory tags and labels that start with?were dropped. A node, property, type or graph variable that nothing mentions is refused. Five doc examples relied on such a variable and are fixed.Merge order with #2397 and #2400
Both fix causes registered here, so some registered tests pass with them. Whichever of this PR and the other merges second removes those entries when it is rebased; until then the
testsuite-jsonldjob fails with "passes but is in the skip register". #2397 also callswith_base_as_vocab, which this PR removes with the lone-@basereading, so rebased, it drops those calls and its test that reads a base as@vocab.Fixes #2358
Follow-up: #2395