Skip to content

fix: a refresh no longer plays a bundle's library as the pack's, and a part is kept only once checked - #61

Merged
alekswebnet merged 1 commit into
mainfrom
fix/pack-refresh-hash-and-inputs
Oct 21, 2026
Merged

alekswebnet merged 1 commit into
mainfrom
fix/pack-refresh-hash-and-inputs

Conversation

@alekswebnet

Copy link
Copy Markdown
Contributor

Closes #58.

Four defects from the same review as #57: two in the player's library pack, one in h5p-embed, one in h5p-verify. Each fix comes with a test that fails without it.

Changes

1. A refresh leaves alone a library that a bundle listed before the pack already has (sw/pack-plan.ts)

  • Before: with libraries="/bundle.h5p pack" on a host with Range, the deep index after the warm planned the refresh with the bundle already attached. planPack withheld the package's folder, then plan(candidate) found the bundle had a folder of that name and planned nothing. The bundle's copy played, reported as the pack's version. When the bundle's minor fell between the package's and the pack's, the part downloaded, but the bundle's folder answered: requests resolve to the lowest compatible minor.
  • Now: a library that an attached archive has at the same major is not refreshed. The package keeps its own copy, as a bundle listed there fills gaps only. Nothing is reported as refreshed.
  • A part attached earlier in the same load doesn't block a refresh it should allow: the package folder it replaced was already withheld, so it is no longer among the package's own libraries.

2. A part is kept only once its hash is checked (jobs/jobs-worker.ts, shared/chunk-store.ts)

  • Before: the chunk writer marked a part complete before checkHash ran, and a later download answered done for any complete archive. A Jobs worker stopped in between (the element removed, the tab closed) left a part with the wrong bytes, served as library code on every load that used it. In the test, without the fix, the bad part also broke the next three tests in the file.
  • Now: a match is recorded on the part (ChunkMeta.checked). A complete part without the mark is checked on its next use, and dropped and downloaded again if it fails. Writing the mark is best-effort: without it, the part is only checked again next time.
  • After an upgrade: parts kept by earlier players have no mark, so each is hashed once on its first use, a few megabytes read back at most.

3. h5p-embed --packages takes plain hosts only (packages/embed/lib/build.mjs, README)

  • Before: any value the URL parser gives back unchanged was accepted, and Node's parser takes *, " and ; in a host. https://*.cdn.example went into the policy, while the page compares exact origins and refused every package. A " ended the policy in nginx.conf, the Caddyfile, .htaccess and the <meta>.
  • Now: a host is letters, digits, hyphens and dots, or a loopback address, as before. The error says there are no wildcards, and the README's options table says so too.

4. h5p-verify --untrusted reads own keys only (packages/verify/lib/verify.mjs)

  • Before: key in b found constructor on every object, so a removed constructor was reported as "x" became function Object()….
  • Now: Object.hasOwn.

AGENTS.md records 1 to 3 beside the split-pack and embed invariants.

Testing

Test Without the fix
pack-plan.test.ts: a bundle with the package's folder name, and one at a minor between the package's and the pack's { parts: [], superseded, refreshed }, the plan the issue describes
pack.test.ts: another part's bytes stored as H5P.OfflineTest-1.2, complete and unmarked, then a content-only export played against the fixture pack that test and three later ones fail ("The library pack kept asking for parts it had already supplied")
build.test.ts (embed): https://*.cdn.example.org, a quote, a semicolon; an IPv4 host still accepted the three are accepted
verify.test.ts: a removed constructor and toString, an added valueOf reported as changed into Object's members

Suites:

  • pnpm typecheck passes for the player, embed and verify.
  • Player unit tests: 345 of 345.
  • Browser, Chromium: 191 of 191, plus the emulated project.
  • Browser, Firefox and WebKit, pack.test.ts: 15 of 15 in each.
  • Embed: 27 of 27.
  • Verify: 16 of 16.

The flaky worker-update test from #59 failed once more locally: on the first run after pnpm test:browser rebuilt the assets, as both times before. It passed on the warm rerun, and CI passed it on #59 and on main.

Not verified: a Jobs worker actually stopped between a part's last write and its check. The test builds the state it leaves behind instead.

Release

🤖 Generated with Claude Code

…a part is kept only once checked

- planPack withheld a library the package carries before planning the
  pack's part, and a bundle listed before the pack that had the library
  at that major then answered for the folder: under the part's own
  folder name, which was never planned, or at a lower minor, which a
  request resolves to first. The bundle's version played, reported as
  the pack's. A library such a bundle has is no longer refreshed.
- A part was marked complete before its hash was checked, and a later
  download took complete as checked. A Jobs worker stopped in between
  left a part with the wrong bytes to be served as library code on
  every load. The match is now recorded on the part; a part without the
  mark is checked on its next use and downloaded again if it fails.
- h5p-embed --packages took any value the URL parser gives back
  unchanged: a wildcard, which the page then refused by exact origin on
  every load, or a quote, which ended the policy in the files that
  quote it. A host is now held to letters, digits, hyphens and dots.
- h5p-verify reported a removed field named constructor or toString as
  changed into Object's own member: own keys only now.

Closes #58.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@alekswebnet
alekswebnet merged commit d726cf3 into main Oct 21, 2026
8 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.

A refresh that can serve an older library, a part hash check that can be skipped, and two input checks in embed and verify

1 participant