Repository navigation
Port to .cljc for JVM + CLJS support (0.3.0) - #3
Conversation
Source moves from .cljs to .cljc with reader conditionals isolating the only platform-specific bit — the mutable hash-bucket store used during compression. On CLJS that's `js/Map`; on JVM it's `java.util.HashMap`. The algorithm is otherwise platform-agnostic. - core: .cljs -> .cljc. Reader-conditional helpers wrap `js/Map` / `java.util.HashMap` (`bucket-get`, `bucket-set!`, `new-bucket-store`). IMapEntry / IRecord checks switched from `satisfies?` to a small `map-entry?*` / `record?*` helper that picks the right test per platform. Mutable cache-id counter moved from `def` + `set!` (CLJS-only) to an atom so JVM can mutate it too. - test: .cljs -> .cljc. Test framework swapped via reader conditionals (clojure.test on JVM, cljs.test on CLJS) and the EDN reader likewise (clojure.edn vs cljs.reader). `js/process.exitCode` and `*main-cli-fn*` are CLJS-only and stay behind `#?(:cljs …)`. - test-runner: now drives both targets. `clojure -M:test` runs the CLJS suite (compile + Node) and then the JVM suite. The same 9 tests / 43 assertions execute on both platforms, ensuring no platform-conditional drift. - bench/ stays .cljs (Node-only; benchmark is informational, not part of the JVM-reach acceptance). - Version bumped from 0.2.2 to 0.3.0 (project.clj + package.json) to reflect added JVM support. README updated. Unblocks JVM consumers (e.g. story-mcp) wanting to apply structural dedup at the wire boundary; previously the library was unreachable from JVM Clojure because of `js/Map` interop.
Cross-repo PR opened: day8/de-dupe#3
Closes coverage gaps from the cljc-port audit: - nil / empty / single-element round-trips - sets, sorted-map, sorted-set - deeply nested (200 levels) and wide (1000 elements) collections - quoted forms and symbols that collide with the cache namespace - explicit platform-parity shape assertion (cache count + id layout) Suite grows from 9 tests / 43 assertions to 16 tests / 77 assertions on both CLJS (Node) and JVM legs. Hardens test-runner.clj against silent-failure pass: it now parses the clojure.test summary line from each platform and enforces a per-leg floor of 60 assertions. A test namespace that fails to load (broken reader-conditional, missing require) emits "Ran 0 tests" and gets rejected with exit 2 instead of slipping through as exit 0. Cycles are documented as unsupported (immutable Clojure collections cannot express them, and the algorithm walks rather than tracks identity, so cyclic input would not terminate).
Test-coverage audit (rf2-y9p2s)Verified the .cljc port both has good coverage and that CI actually exercises it. What was already solid
Gaps closed in 7d5a7a4
Suite grew from 9 tests / 43 assertions → 16 tests / 77 assertions, identical on both legs. Silent-failure gate (the bigger find)The previous
The runner now parses the CI log on the latest run shows both legs printing their counts and the gate's confirmation line: CyclesDocumented as unsupported in the test file: persistent Clojure collections can't express cycles natively, and the algorithm walks rather than tracks identity, so cyclic input wouldn't terminate. Out of scope for the wire-boundary dedup use case. VerdictPR #3 is good to merge from a test-coverage perspective. story-mcp can adopt this with confidence. |
…EADME install snippets
…loses #2) Addresses long-standing confusion (issue #2, 2015) about the library making small inputs grow. Explains the structural-sharing-preservation purpose, gives three worked examples (tiny no-sharing input, repeated map, real-world pair2-mcp ~89% number), and a rule of thumb for when to reach for the library.
|
Swapped lein → tools.build + deps-deploy (commit 58d201a). Local jar + install verified. |
…-90eft)
Mirror of pair-mcp's rf2-obpa9 wire-boundary structural-dedup transform,
applied selectively to the three story-mcp tools whose payloads carry
repeated subtrees:
- preview-variant / run-variant re-key the same :app-db slice into
:rendered-hiccup and :snapshot (three references collapse into one
cache slot).
- record-as-variant the :captured event vector re-uses argument
shapes across event records.
Measured reduction on a realistic run-variant fixture (256-key
:app-db re-keyed into :rendered-hiccup + :snapshot + assertion
:actual/:expected): raw=340166 chars wrapped=68385 chars = **79.9%
reduction**. Round-trips byte-exact via de-dupe.core/expand.
Pipeline ordering (mirrors pair-mcp): dedup BEFORE cap. Dedup
shrinks the payload first so the cap-honest size is post-dedup.
Wire shape unchanged from pair-mcp: `{:rf.mcp/dedup-table <cache-map>}`,
key sourced from `re-frame.mcp-base.vocab/dedup-table-key`. Cross-MCP
shape pinned by `tools/mcp-conformance/wire-vocab/`'s canonical-marker
fixture; story-mcp added to the marker's `:servers` set with a
representative fixture.
Selective by design the eligibility contract is the descriptor flag
`:dedup-eligible? true`, pinned by `descriptor-dedup-eligibility-
matches-the-documented-set`. The other sixteen tools ship small,
bespoke shapes where the cache-of-one wrap would add bytes for zero
compression; they emit raw `:structuredContent` and carry no `:dedup`
slot. Mirrors pair-mcp's selective `dedup-property` assignment in
`descriptors_data.cljs`.
Sibling change: pair-mcp's day8/de-dupe pin bumps to `v0.3.0` (peeled
commit `367de784...`) the first tagged release carrying the `.cljc`
port (rf2-nw6sj day8/de-dupe#3, merged 2026-05-13). Tags age better
than SHAs; both servers lockstep on the same tag so the two MCPs
can't drift on a dedup-algorithm change. pair-mcp's compiled
`out/server.js` rebuilt.
Spec: `tools/story-mcp/spec/Principles.md` Structural dedup at the
wire boundary section added, modelled on pair-mcp's wording from
rf2-obpa9.
Tests: 171 172 (855 858 assertions) on `clojure -M:test`; pair-mcp
604 tests / 1613 assertions still green; mcp-conformance wire-vocab
45 tests / 518 assertions still green; clj-kondo 0 errors.
Cross-refs:
- rf2-obpa9 (pair-mcp adoption pattern mirrored here)
- rf2-nw6sj (cross-repo .cljc port that unblocked JVM-side reach)
- rf2-rvyzy (the cap pipeline this dedup step composes with)
Summary
.cljsto.cljcwith reader conditionals isolating the only platform-specific bit — the mutable hash-bucket store used during compression (js/Mapon CLJS,java.util.HashMapon JVM).clojure -M:test.Why
JVM Clojure consumers (e.g.
story-mcpin the re-frame2 repo) want to apply structural dedup at their wire boundary. Until now the library has been CLJS-only because ofjs/Mapinterop. The algorithm is platform-agnostic; only the bucket store needed isolation.What changed
src/de_dupe/core(.cljs→.cljc)new-bucket-store/bucket-get/bucket-set!helpers wrapjs/Map(CLJS) andjava.util.HashMap(JVM).IMapEntry/IRecordchecks switched fromsatisfies?to a smallmap-entry?*/record?*helper that picks the right predicate per platform.cache-id-countermoved fromdef+set!(CLJS-only) to anatomso JVM can mutate it too.test/de_dupe/test/core(.cljs→.cljc)clojure.teston JVM,cljs.teston CLJS).clojure.ednvscljs.reader).js/process.exitCodeand*main-cli-fn*are CLJS-only and stay behind#?(:cljs …).test/de_dupe/test_runner.cljclojure -M:testruns the CLJS suite (compile + Node) and the JVM suite.bench/stays.cljs. The benchmark is informational; the JVM-reach acceptance doesn't depend on it.Version:
project.cljandpackage.jsonbumped 0.2.2 → 0.3.0. README updated.Test plan
clojure -M:testpasses on the CLJS suite (9 tests / 43 assertions).clojure -M:testpasses on the JVM suite (9 tests / 43 assertions).de-dupe→expandround-trip (identical?returns true for shared substructures)..github/workflows/test.yml) — already runsclojure -M:test, so the JVM job now exercises both halves once this lands.