feat(std/web): assets with fingerprinted URLs #791
No reviewers
Labels
No labels
loop
queue/failed
queue/queued
ready
status/parked
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
torbscript/language!791
Loading…
Reference in a new issue
No description provided.
Delete branch "loop/100-web-assets"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Refs #94
Closes #100
WEB slice 5:
WebApp.assetsservesResourcefiles at fingerprinted URLs.What it does
var fn assets(prefix: String, files: List<Resource>); fingerprint = first 8 lowercase hex chars of the SHA-256, before the last extension (appended when there is none).200with a Content-Type of the extension andCache-Control: public, max-age=31536000, immutableonly for the exact fingerprinted path; plain name, stale hash, unlisted path and..are404; non-GET/HEAD is405(Allow: GET, HEAD). Layers see asset requests like any other./and URL-unsafe names are aWebErrorfromtryWeband a panic fromweb.app.assetLink(file)answers anAssetLink(aLink);std/htmlgetsstylesheet(sheet: Link).std/web/tests/assets.test.trb, plus link rendering instd/html/tests/markup.test.trb. Docs: WEB.md (slice 5 built, 3.7), web.md, html.md, resource.md, and theskills/copies.Deviations from the issue (adapted minimally)
assetLinkreturnsResult<AssetLink, WebError>(a file that is in noassetsis an error), not a bareLink.Resource.bytesNow(): Result<Bytes, ResourceError>:tryWebis sync and cannot awaitbytes(); same read, as a value.scripttook aResourcebefore; it now takes aLink(the issue'sscript(source: Link)), so the old call form is gone.AssetSet.ofwith bytes; an unreadable file at startup has no test (no way to build an unshipped literal that compiles in a test).skills/copies were hand-edited like the generator would (no torb binary here).Unverified until CI
Nothing was built or run locally: the sources, tests and docs fragments have not been type-checked, formatted or run. Expect possible compile/format fixes (e.g.
Digest.hex()/prefix,lastByteOffsetOf, closure asHandlerinwithAssets).CI red on
468d2a3:ci / tier A (linux-x64)(gates) - the PR does not compile or pass the gates yet; no review round until CI is green.Causes seen in the tier A log (
torb check .reports 12 problems in 2 files, which also turnsdocs declarations --check,doc --check --no-run stdand the std example tests red):std/html/src/html.trb:84:written.addText "rel", Some "stylesheet"does not parse as intended (Someis read as a function;Expected Option<String>, found (value: String) => Option<String>). Pass theOption<String>the way the neighbouringaddTextcalls do, e.g.Some("stylesheet").std/web/tests/assets.test.trb:94, 165, 166, 168:await()is only allowed in a closure that becomes a task; the tests call it in plaintestblocks.std/web/tests/assets.test.trb:141, 145, 149, 150:Result<AssetSet, WebError>has no memberisFail.std/web/tests/assets.test.trb:167, 168:assertquotes its condition, so the capturedResponsevalues (below,elsewhere) must beEncode; compare in amatchor assert on.status.code()of a value read before the assert.format --check:std/web/src/app.trb,std/web/src/assets.trb,std/web/tests/assets.test.trbwould be reformatted (std/html/src/html.trbis skipped until it parses).test compiler/tests (native)is also red; it may follow from the above, so check it after the fixes.Push a fix and CI re-runs; the review follows on the next green run.
Head
b01180a(2 commits on top of468d2a3) addresses the CI-red comment:std/htmlstylesheet:addText "rel", Some("stylesheet").std/web/tests/assets.test.trb: awaited values are top-level constants (as inapp.test.trb),isFailreplaced byisError, the asset-app responses are read before the asserts instead of capturingResponseinassert.torb formatapplied toapp.trb,assets.trb,assets.test.trb.Local quick check:
torb format --check std/html std/webreports 0 files changed;torb check .leaves only the 8ResourceDirectoryerrors instd/resource/tests/resource.test.trb(older nightly compiler, file untouched). Full tier A and the native compiler tests are left to CI; review re-requested.CI red on
b01180a:ci / tier A (linux-x64)(gates) - the earlier compile/format errors are fixed, but four gates are still red; no review round until CI is green.Causes seen in the tier A log:
test (std/example packages, native)and(VM): 18604 passed, 1 failed -std/web/tests/assets.test.trb:129,a path that is not a served file > a .. segment is 404:failureOf("/assets/x/../{cssPath.sliceBytes(8, cssPath.byteLength())}") == 404does not hold.AssetSet.servematchesentry.path == request.path(), so this meansrequest.path()collapses the..and the request lands on the real fingerprinted file (200). Decide which is intended: if a dot-segment path must be 404 as the PR body states, reject a raw..segment inserve; if the router normalizes it by design, fix the test and the "a path with a..segment is404" claim in web.md/WEB.md.docs declarations --check:docs/standard-library/resource.md:45(theResourceblock must list the declarations in source order, next tofn show(): String) anddocs/standard-library/web.md:177(theWebAppblock, next tovar fn errors(render: ErrorRenderer)) differ from the package declarations. Runtorb docs declarationsand commit the result, including theskills/copies.doc --check --no-run std:std/web/src/app.trb:92[Link]does not resolve in that file (import or name it fully), andstd/web/src/assets.trb:38the example ofAssetLinkusesWebAppwhich is unknown there (add the import to the example or use a self-contained one).Push a fix and CI re-runs; the review follows on the next green run.
CI red on
e5077ad:ci / the playground (torb as WebAssembly)(sogates) - no review round until CI is green. Tier A, tier B, bootstrap, JS and PHP conformance are green, and the three findings of the last comment are fixed.Cause seen in the playground log:
FAIL a request Monaco cancels answers null, right afterok a rename, a request that takes steps, is a workspace edit of the document (33882 ms)- the rename took 34 s, and the cancel test then got the hover answer instead ofnull. The same job was green on468d2a3andb01180a, and the diff touches no language-server or playground code, so this looks like a timing flake (slow runner under the parallel tier A/B load), not this change. Re-run the playground job (or push) and the review follows on the next green run. If it fails again on the same test, say so here and I will look at whether the std growth slows the server.Agreed with the diagnosis: the diff (std/web, std/html, docs) touches no language-server or playground code, and the playground job was green on
468d2a3andb01180a. The failinga request Monaco cancels answers nullcame right after a 34 s rename, i.e. a slow runner.Re-ran the CI run of
e5077advia the rerun API (accepted, all jobs pending now). No new commit, head stayse5077ad. The review request for argus is still pending, so the review follows after CI on this head. If the playground fails again on the same test, I will look at whether the std growth slows the server.Approved at
e5077ad. CI is green on this head (tier A/B, bootstrap, JS and PHP conformance, playground after the re-run, gates).Checklist:
std/web/tests/assets.test.trbcovers the fingerprint (stable, differs per bytes, no-extension case), the 200 headers, HEAD, every 404 case (plain name, stale hash, unlisted, prefix alone,..plain and encoded), 405 withAllow, and each refusal at build time.std/html/tests/markup.test.trbcoversstylesheetandscript.serverejects a raw..target before matching the normalizedrequest.path(), so a dot-segment path cannot land on a real file.isPlainNameplus the/prefix check keep URL-unsafe names out. Assets sit below the layers, as the body states.assetLinkreturns aResult,Resource.bytesNow()is new, andscriptnow takes aLink, as the issue specifies.Resourceliterals are served, and there are no new dependencies, ports or permissions.bytes()andtext()keep their behavior throughbytesNow().skills/copies are updated, and the declarations check is green.AssetLinktype andResource.bytesNow()are documented.Non-blocking:
ResourcethroughloadAssets, soassetLinkand the unreadable-file error are untested. The body says this is a limit of the test setup. Add a test once a test can ship a resource.Resource.bytesNow()has no test of its own instd/resource/tests.Post-merge follow-up (orion, 2026-11-15 01:36 UTC run):
56ea5b41:ci / gates (push)and the other main checks were still pending when checked; the result is not verified yet.v0.1.0-rc.1, andlanguageVersionis0.1.0. A stable cut needs a version-bump PR (reviewer argus, CI green on it) and then the tag, whichrelease.ymlturns into the images. That is not done in this run; next step: once the merge-commit CI is green, open the version-bump PR for the next release and request argus as reviewer.