test(core): JSON Canvas spec conformance suite (#16, slice 1) - #67
Merged
Conversation
Adds src/core/__tests__/conformance.test.ts (33 tests) targeting the spec
contract directly, complementing the sample-fixture coverage in
serialization.test.ts:
- all four node types in one document + type-specific required fields
- full edge matrix: fromSide×toSide×fromEnd×toEnd (64 combinations) parsed
and preserved through a round-trip
- colour preservation: preset codes 1–6 and hex values verbatim
- minimal docs: {}, {"nodes":[]}, {"nodes":[],"edges":[]}
- malformed-input rejection matrix (18 cases): bad JSON, non-object roots,
nodes/edges not arrays, missing/empty id, bad type tag, non-numeric coords,
missing type-specific fields, bad edge side/end enums
- round-trip property parse(serialize(parse(x))) ≡ parse(x), plus
unknown-field preservation at document / node / edge level, tab indentation
Plus a bundled spec fixture (all-node-types.canvas) exercising text/file/link/
group + a fully-specified edge.
Pure-TS / no ESM deps, so it runs under the existing ts-jest config with no
mocking. Precondition for the Rust port (#6): the same fixtures will validate
the Rust parser accepts/rejects exactly what the TS one does.
Scope: this is slice 1 (core spec). Canvas Candy cssclasses enrichment is
slice 2 (also pure-TS via js-yaml); callouts conformance is deferred — it
pulls in the unified/remark ESM chain that needs the jest-ESM problem solved
once, properly, rather than per-test mocking.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This was referenced Jun 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
First slice of #16 — spec conformance for the core parse/serialize gate. 33 new tests in
conformance.test.ts, complementing the sample-fixture coverage already inserialization.test.ts.Covers the spec checklist:
fromSide×toSide×fromEnd×toEnd(64 combos) parsed and round-trip-preserved1–6and hex values verbatim{},{"nodes":[]},{"nodes":[],"edges":[]}parse(serialize(parse(x))) ≡ parse(x)+ unknown-field preservation (doc/node/edge) + tab indentationPlus a bundled
all-node-types.canvasfixture (text/file/link/group + a fully-specified edge — the sample lacked a file node).Why pure-TS
No
unified/remark/hastimports, so it runs under the existing ts-jest config with zero mocking. Precondition for the Rust port (#6): these fixtures will validate the Rust parser accepts/rejects exactly what the TS one does.Scope (sliced deliberately)
cssclassesenrichment: class→prop mapping, frontmatter forms,displayTextstripping, zero-overhead path. Also pure-TS (js-yamlonly).parseCalloutsconformance: pulls in theunified/remarkESM chain that breaks under ts-jest. Belongs with a one-time jest-ESM solution, not per-test mocking (we learned that lesson on the parse-cache PR).hasCallouts(pure regex) will be covered in slice 2.Test plan
Part of #16.
🤖 Generated with Claude Code