Skip to content

Commit 29ef2a7

Browse files
author
teamchong
committed
Bump to 0.5.0: fix schema bug, stream slot GC, release pipeline, CI caching
- parsePartialJson: return "failed-parse" (not "successful-parse") when schema rejects complete JSON — fixes confusing result where state says success but value is undefined - Add FinalizationRegistry for stream parser slots — prevents slot leaks when callers forget .destroy() (hard 4-slot cap) - Fix release.yml: publish to npm BEFORE creating git tag — prevents orphaned tags when npm publish fails (hit this with v0.2.0) - CI: shared build job with artifact upload, bun dep caching — test and benchmark jobs no longer duplicate the full build - ParseResult: proper discriminated union type with typed .free() - Seeker: fix </think> tag split across chunks via pending buffer - embed-wasm.mjs: add WASM magic number validation and existence check - Sync build.zig.zon version with package.json - Add coverage-gaps test suite (22 tests)
1 parent 0208252 commit 29ef2a7

8 files changed

Lines changed: 507 additions & 47 deletions

File tree

.github/workflows/ci.yml

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
branches: [main]
88

99
jobs:
10-
test:
10+
build:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- uses: actions/checkout@v4
@@ -23,12 +23,52 @@ jobs:
2323
- name: Install binaryen (wasm-opt)
2424
run: sudo apt-get install -y binaryen
2525

26+
- name: Cache bun dependencies
27+
uses: actions/cache@v4
28+
with:
29+
path: ~/.bun/install/cache
30+
key: bun-${{ runner.os }}-${{ hashFiles('bun.lock', 'package.json') }}
31+
restore-keys: bun-${{ runner.os }}-
32+
2633
- name: Install
2734
run: bun install
2835

2936
- name: Build
3037
run: bun run build
3138

39+
- name: Upload build artifacts
40+
uses: actions/upload-artifact@v4
41+
with:
42+
name: dist
43+
path: dist/
44+
retention-days: 1
45+
46+
test:
47+
runs-on: ubuntu-latest
48+
needs: build
49+
steps:
50+
- uses: actions/checkout@v4
51+
52+
- uses: oven-sh/setup-bun@v2
53+
with:
54+
bun-version: latest
55+
56+
- name: Cache bun dependencies
57+
uses: actions/cache@v4
58+
with:
59+
path: ~/.bun/install/cache
60+
key: bun-${{ runner.os }}-${{ hashFiles('bun.lock', 'package.json') }}
61+
restore-keys: bun-${{ runner.os }}-
62+
63+
- name: Install
64+
run: bun install
65+
66+
- name: Download build artifacts
67+
uses: actions/download-artifact@v4
68+
with:
69+
name: dist
70+
path: dist/
71+
3272
- name: Test
3373
run: bun run test
3474

@@ -40,26 +80,29 @@ jobs:
4080

4181
benchmark:
4282
runs-on: ubuntu-latest
43-
needs: test
83+
needs: build
4484
steps:
4585
- uses: actions/checkout@v4
4686

4787
- uses: oven-sh/setup-bun@v2
4888
with:
4989
bun-version: latest
5090

51-
- uses: mlugg/setup-zig@v2
91+
- name: Cache bun dependencies
92+
uses: actions/cache@v4
5293
with:
53-
version: 0.15.2
54-
55-
- name: Install binaryen (wasm-opt)
56-
run: sudo apt-get install -y binaryen
94+
path: ~/.bun/install/cache
95+
key: bun-${{ runner.os }}-${{ hashFiles('bun.lock', 'package.json') }}
96+
restore-keys: bun-${{ runner.os }}-
5797

5898
- name: Install
5999
run: bun install
60100

61-
- name: Build
62-
run: bun run build
101+
- name: Download build artifacts
102+
uses: actions/download-artifact@v4
103+
with:
104+
name: dist
105+
path: dist/
63106

64107
- name: Install bench dependencies
65108
run: cd bench/ai-parsers && bun install

.github/workflows/release.yml

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,20 @@ on:
99
- 'package.json'
1010

1111
jobs:
12-
auto-tag:
12+
check-version:
1313
runs-on: ubuntu-latest
14-
permissions:
15-
contents: write
1614
outputs:
17-
tag: ${{ steps.tag.outputs.tag }}
18-
should_release: ${{ steps.tag.outputs.should_release }}
15+
version: ${{ steps.version.outputs.version }}
16+
tag: ${{ steps.version.outputs.tag }}
17+
should_release: ${{ steps.version.outputs.should_release }}
1918

2019
steps:
2120
- uses: actions/checkout@v4
2221
with:
2322
fetch-depth: 0
2423

25-
- name: Get version and create tag
26-
id: tag
24+
- name: Check if version needs release
25+
id: version
2726
run: |
2827
VERSION=$(node -p "require('./package.json').version")
2928
TAG="v$VERSION"
@@ -33,18 +32,15 @@ jobs:
3332
echo "Tag $TAG already exists, skipping release"
3433
echo "should_release=false" >> $GITHUB_OUTPUT
3534
else
36-
echo "Creating tag $TAG"
37-
git config user.name "github-actions[bot]"
38-
git config user.email "github-actions[bot]@users.noreply.github.com"
39-
git tag -a "$TAG" -m "Release $TAG"
40-
git push origin "$TAG"
35+
echo "Version $VERSION not yet released"
36+
echo "version=$VERSION" >> $GITHUB_OUTPUT
4137
echo "tag=$TAG" >> $GITHUB_OUTPUT
4238
echo "should_release=true" >> $GITHUB_OUTPUT
4339
fi
4440
4541
publish-npm:
46-
needs: auto-tag
47-
if: needs.auto-tag.outputs.should_release == 'true'
42+
needs: check-version
43+
if: needs.check-version.outputs.should_release == 'true'
4844
runs-on: ubuntu-latest
4945
permissions:
5046
contents: read
@@ -82,9 +78,29 @@ jobs:
8278
- name: Publish to npm (OIDC)
8379
run: npm publish --provenance --access public
8480

81+
create-tag:
82+
needs: [check-version, publish-npm]
83+
if: needs.check-version.outputs.should_release == 'true'
84+
runs-on: ubuntu-latest
85+
permissions:
86+
contents: write
87+
88+
steps:
89+
- uses: actions/checkout@v4
90+
with:
91+
fetch-depth: 0
92+
93+
- name: Create and push tag
94+
run: |
95+
TAG="${{ needs.check-version.outputs.tag }}"
96+
git config user.name "github-actions[bot]"
97+
git config user.email "github-actions[bot]@users.noreply.github.com"
98+
git tag -a "$TAG" -m "Release $TAG"
99+
git push origin "$TAG"
100+
85101
release:
86-
needs: [auto-tag, publish-npm]
87-
if: needs.auto-tag.outputs.should_release == 'true'
102+
needs: [check-version, publish-npm, create-tag]
103+
if: needs.check-version.outputs.should_release == 'true'
88104
runs-on: ubuntu-latest
89105
permissions:
90106
contents: write
@@ -95,5 +111,5 @@ jobs:
95111
- name: Create GitHub Release
96112
uses: softprops/action-gh-release@v1
97113
with:
98-
tag_name: ${{ needs.auto-tag.outputs.tag }}
114+
tag_name: ${{ needs.check-version.outputs.tag }}
99115
generate_release_notes: true

build.zig.zon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.{
22
.name = .vectorjson,
3-
.version = "0.1.0",
3+
.version = "0.5.0",
44
.fingerprint = 0x7899fe5bdf76f6d8,
55
.minimum_zig_version = "0.14.0",
66
.paths = .{

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vectorjson",
3-
"version": "0.4.7",
3+
"version": "0.5.0",
44
"description": "O(n) WASM SIMD JSON parser for AI agents — stream fields instantly, abort errors early, offload parsing to Workers",
55
"type": "module",
66
"main": "dist/index.js",
@@ -29,7 +29,7 @@
2929
"build:embed": "node scripts/embed-wasm.mjs",
3030
"build:js": "bun build src/js/index.ts --outdir dist --target node --format esm --minify --sourcemap=external && bun run build:types",
3131
"build": "bun run build:zig && bun run build:opt && bun run build:embed && bun run build:js",
32-
"test": "bun test/phase1.mjs && bun test/phase2.mjs && bun test/parse-result.mjs && bun test/is-complete.mjs && bun test/partial-json.mjs && bun test/zerocopy.mjs && bun test/standards.mjs && bun test/event-parser.mjs && bun test/live-doc.mjs && bun test/large-json.mjs && bun test/deep-compare.mjs && bun test/sync-api.mjs && bun test/pick-fields.mjs && bun test/jsonl.mjs && bun test/json5.mjs && bun test/tape-transfer.mjs",
32+
"test": "bun test/phase1.mjs && bun test/phase2.mjs && bun test/parse-result.mjs && bun test/is-complete.mjs && bun test/partial-json.mjs && bun test/zerocopy.mjs && bun test/standards.mjs && bun test/event-parser.mjs && bun test/live-doc.mjs && bun test/large-json.mjs && bun test/deep-compare.mjs && bun test/sync-api.mjs && bun test/pick-fields.mjs && bun test/jsonl.mjs && bun test/json5.mjs && bun test/tape-transfer.mjs && bun test/coverage-gaps.mjs",
3333
"bench": "bun --expose-gc bench/parse-stream.mjs",
3434
"bench:parse": "bun --expose-gc bench/parse-stream.mjs",
3535
"bench:e2e": "bun --expose-gc bench/end-to-end.mjs",

scripts/embed-wasm.mjs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,37 @@
22
* Embed WASM binary as base64 string in a TypeScript module.
33
* Reads dist/engine.wasm → writes src/js/engine-wasm.generated.ts
44
*/
5-
import { readFileSync, writeFileSync } from "node:fs";
5+
import { readFileSync, writeFileSync, existsSync } from "node:fs";
66
import { dirname, join } from "node:path";
77
import { fileURLToPath } from "node:url";
88

99
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
1010
const wasmPath = join(root, "dist", "engine.wasm");
1111
const outPath = join(root, "src", "js", "engine-wasm.generated.ts");
1212

13+
if (!existsSync(wasmPath)) {
14+
console.error(`❌ WASM file not found: ${wasmPath}`);
15+
console.error(" Run 'bun run build:zig && bun run build:opt' first.");
16+
process.exit(1);
17+
}
18+
1319
const wasmBytes = readFileSync(wasmPath);
20+
21+
// Validate WASM magic number: \0asm (0x00 0x61 0x73 0x6d)
22+
if (
23+
wasmBytes.length < 4 ||
24+
wasmBytes[0] !== 0x00 ||
25+
wasmBytes[1] !== 0x61 ||
26+
wasmBytes[2] !== 0x73 ||
27+
wasmBytes[3] !== 0x6d
28+
) {
29+
console.error(`❌ Invalid WASM file: ${wasmPath}`);
30+
console.error(
31+
` Expected magic bytes \\0asm, got: ${wasmBytes.slice(0, 4).toString("hex")}`,
32+
);
33+
process.exit(1);
34+
}
35+
1436
const b64 = wasmBytes.toString("base64");
1537

1638
writeFileSync(

0 commit comments

Comments
 (0)