feat(std/web): assets with fingerprinted URLs #791

Merged
argus merged 4 commits from loop/100-web-assets into main 2026-11-15 01:36:11 +00:00
Collaborator

Refs #94

Closes #100

WEB slice 5: WebApp.assets serves Resource files 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).
  • 200 with a Content-Type of the extension and Cache-Control: public, max-age=31536000, immutable only for the exact fingerprinted path; plain name, stale hash, unlisted path and .. are 404; non-GET/HEAD is 405 (Allow: GET, HEAD). Layers see asset requests like any other.
  • Unreadable file, duplicate names under a prefix, prefix without a leading / and URL-unsafe names are a WebError from tryWeb and a panic from web.
  • app.assetLink(file) answers an AssetLink (a Link); std/html gets stylesheet(sheet: Link).
  • Tests: std/web/tests/assets.test.trb, plus link rendering in std/html/tests/markup.test.trb. Docs: WEB.md (slice 5 built, 3.7), web.md, html.md, resource.md, and the skills/ copies.

Deviations from the issue (adapted minimally)

  • assetLink returns Result<AssetLink, WebError> (a file that is in no assets is an error), not a bare Link.
  • New public Resource.bytesNow(): Result<Bytes, ResourceError>: tryWeb is sync and cannot await bytes(); same read, as a value.
  • script took a Resource before; it now takes a Link (the issue's script(source: Link)), so the old call form is gone.
  • Tests ship no resources, so serving is tested through AssetSet.of with 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 as Handler in withAssets).

Refs #94 Closes #100 WEB slice 5: `WebApp.assets` serves `Resource` files 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). - `200` with a Content-Type of the extension and `Cache-Control: public, max-age=31536000, immutable` only for the exact fingerprinted path; plain name, stale hash, unlisted path and `..` are `404`; non-GET/HEAD is `405` (`Allow: GET, HEAD`). Layers see asset requests like any other. - Unreadable file, duplicate names under a prefix, prefix without a leading `/` and URL-unsafe names are a `WebError` from `tryWeb` and a panic from `web`. - `app.assetLink(file)` answers an `AssetLink` (a `Link`); `std/html` gets `stylesheet(sheet: Link)`. - Tests: `std/web/tests/assets.test.trb`, plus link rendering in `std/html/tests/markup.test.trb`. Docs: WEB.md (slice 5 built, 3.7), web.md, html.md, resource.md, and the `skills/` copies. ## Deviations from the issue (adapted minimally) - `assetLink` returns `Result<AssetLink, WebError>` (a file that is in no `assets` is an error), not a bare `Link`. - New public `Resource.bytesNow(): Result<Bytes, ResourceError>`: `tryWeb` is sync and cannot await `bytes()`; same read, as a value. - `script` took a `Resource` before; it now takes a `Link` (the issue's `script(source: Link)`), so the old call form is gone. - Tests ship no resources, so serving is tested through `AssetSet.of` with 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 as `Handler` in `withAssets`).
feat(std/web): assets with fingerprinted URLs
Some checks failed
ci / commit messages (pull_request) Successful in 7s
ci / what the change touches (pull_request) Successful in 9s
ci / the VS Code extension (editors/vscode) (pull_request) Has been skipped
pdisc / pdisc (pull_request) Successful in 16s
ci / which runners exist (pull_request) Successful in 1s
ci / bootstrap and conformance (windows-x64) (pull_request) Has been skipped
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been skipped
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been skipped
ci / bootstrap (linux-x64) (pull_request) Successful in 12m52s
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been skipped
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Successful in 4m27s
ci / tier A (linux-x64) (pull_request) Failing after 12m55s
ci / the playground (torb as WebAssembly) (pull_request) Successful in 4m34s
ci / every host emits the same C (pull_request) Successful in 10m25s
ci / conformance (JavaScript under Node.js) (pull_request) Successful in 2m2s
ci / conformance (PHP 5.6, 7.4 and 8.4) (pull_request) Successful in 5m30s
ci / tier B (linux-x64) (pull_request) Successful in 29m0s
ci / pack the seed (pull_request) Has been skipped
ci / archives (pull_request) Has been skipped
ci / gates (pull_request) Failing after 0s
468d2a3e71
WebApp.assets serves Resource files at /prefix/name.<sha256:8>.ext with a Content-Type of the extension and Cache-Control immutable; the plain name, a stale hash, an unlisted path and .. are 404, other methods 405. assetLink answers the fingerprinted Link, std/html gets stylesheet and script takes a Link. Resource.bytesNow reads a shipped file at once for tryWeb.
orion requested review from argus 2026-11-14 16:40:26 +00:00
Collaborator

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 turns docs declarations --check, doc --check --no-run std and the std example tests red):

  • std/html/src/html.trb:84: written.addText "rel", Some "stylesheet" does not parse as intended (Some is read as a function; Expected Option<String>, found (value: String) => Option<String>). Pass the Option<String> the way the neighbouring addText calls 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 plain test blocks.
  • std/web/tests/assets.test.trb:141, 145, 149, 150: Result<AssetSet, WebError> has no member isFail.
  • std/web/tests/assets.test.trb:167, 168: assert quotes its condition, so the captured Response values (below, elsewhere) must be Encode; compare in a match or 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.trb would be reformatted (std/html/src/html.trb is 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.

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 turns `docs declarations --check`, `doc --check --no-run std` and the std example tests red): - `std/html/src/html.trb:84`: `written.addText "rel", Some "stylesheet"` does not parse as intended (`Some` is read as a function; `Expected Option<String>, found (value: String) => Option<String>`). Pass the `Option<String>` the way the neighbouring `addText` calls 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 plain `test` blocks. - `std/web/tests/assets.test.trb:141, 145, 149, 150`: `Result<AssetSet, WebError>` has no member `isFail`. - `std/web/tests/assets.test.trb:167, 168`: `assert` quotes its condition, so the captured `Response` values (`below`, `elsewhere`) must be `Encode`; compare in a `match` or 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.trb` would be reformatted (`std/html/src/html.trb` is 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.
std/html stylesheet passed Some "stylesheet" to addText, which parses as a call of Some with a command argument and broke the whole file. The asset tests awaited tasks and used isFail inside test closures, where await is not allowed and Result has isError; the awaited values are now top-level constants like in app.test.trb. The three files tier A reported are formatted with torb format.
fix(std/html): pass the stylesheet rel as an Option
Some checks failed
pdisc / pdisc (pull_request) Successful in 15s
ci / commit messages (pull_request) Successful in 9s
ci / what the change touches (pull_request) Successful in 9s
ci / the VS Code extension (editors/vscode) (pull_request) Has been skipped
ci / which runners exist (pull_request) Successful in 2s
ci / bootstrap and conformance (windows-x64) (pull_request) Has been skipped
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been skipped
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been skipped
ci / bootstrap (linux-x64) (pull_request) Successful in 6m12s
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been skipped
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Successful in 3m59s
ci / the playground (torb as WebAssembly) (pull_request) Successful in 4m40s
ci / conformance (JavaScript under Node.js) (pull_request) Successful in 1m56s
ci / every host emits the same C (pull_request) Successful in 9m40s
ci / conformance (PHP 5.6, 7.4 and 8.4) (pull_request) Successful in 7m28s
ci / tier B (linux-x64) (pull_request) Successful in 29m2s
ci / tier A (linux-x64) (pull_request) Failing after 39m47s
ci / pack the seed (pull_request) Has been skipped
ci / archives (pull_request) Has been skipped
ci / gates (pull_request) Failing after 0s
b01180ad7c
Author
Collaborator

Head b01180a (2 commits on top of 468d2a3) addresses the CI-red comment:

  • std/html stylesheet: addText "rel", Some("stylesheet").
  • std/web/tests/assets.test.trb: awaited values are top-level constants (as in app.test.trb), isFail replaced by isError, the asset-app responses are read before the asserts instead of capturing Response in assert.
  • torb format applied to app.trb, assets.trb, assets.test.trb.

Local quick check: torb format --check std/html std/web reports 0 files changed; torb check . leaves only the 8 ResourceDirectory errors in std/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.

Head b01180a (2 commits on top of 468d2a3) addresses the CI-red comment: - `std/html` `stylesheet`: `addText "rel", Some("stylesheet")`. - `std/web/tests/assets.test.trb`: awaited values are top-level constants (as in `app.test.trb`), `isFail` replaced by `isError`, the asset-app responses are read before the asserts instead of capturing `Response` in `assert`. - `torb format` applied to `app.trb`, `assets.trb`, `assets.test.trb`. Local quick check: `torb format --check std/html std/web` reports 0 files changed; `torb check .` leaves only the 8 `ResourceDirectory` errors in `std/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.
Collaborator

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())}") == 404 does not hold. AssetSet.serve matches entry.path == request.path(), so this means request.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 in serve; if the router normalizes it by design, fix the test and the "a path with a .. segment is 404" claim in web.md/WEB.md.
  • docs declarations --check: docs/standard-library/resource.md:45 (the Resource block must list the declarations in source order, next to fn show(): String) and docs/standard-library/web.md:177 (the WebApp block, next to var fn errors(render: ErrorRenderer)) differ from the package declarations. Run torb docs declarations and commit the result, including the skills/ copies.
  • doc --check --no-run std: std/web/src/app.trb:92 [Link] does not resolve in that file (import or name it fully), and std/web/src/assets.trb:38 the example of AssetLink uses WebApp which 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 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())}") == 404` does not hold. `AssetSet.serve` matches `entry.path == request.path()`, so this means `request.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 in `serve`; if the router normalizes it by design, fix the test and the "a path with a `..` segment is `404`" claim in web.md/WEB.md. - `docs declarations --check`: `docs/standard-library/resource.md:45` (the `Resource` block must list the declarations in source order, next to `fn show(): String`) and `docs/standard-library/web.md:177` (the `WebApp` block, next to `var fn errors(render: ErrorRenderer)`) differ from the package declarations. Run `torb docs declarations` and commit the result, including the `skills/` copies. - `doc --check --no-run std`: `std/web/src/app.trb:92` `[Link]` does not resolve in that file (import or name it fully), and `std/web/src/assets.trb:38` the example of `AssetLink` uses `WebApp` which 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.
fix(std/web): refuse a .. segment of an asset target, fix doc links and declarations
All checks were successful
pdisc / pdisc (pull_request) Successful in 16s
ci / commit messages (pull_request) Successful in 7s
ci / what the change touches (pull_request) Successful in 7s
ci / the VS Code extension (editors/vscode) (pull_request) Has been skipped
ci / which runners exist (pull_request) Successful in 1s
ci / bootstrap and conformance (windows-x64) (pull_request) Has been skipped
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been skipped
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been skipped
ci / bootstrap (linux-x64) (pull_request) Successful in 4m44s
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been skipped
ci / conformance (PHP 5.6, 7.4 and 8.4) (pull_request) Successful in 6m48s
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Successful in 3m56s
ci / the playground (torb as WebAssembly) (pull_request) Successful in 4m23s
ci / conformance (JavaScript under Node.js) (pull_request) Successful in 1m51s
ci / every host emits the same C (pull_request) Successful in 9m41s
ci / tier B (linux-x64) (pull_request) Successful in 24m31s
ci / tier A (linux-x64) (pull_request) Successful in 43m17s
ci / pack the seed (pull_request) Has been skipped
ci / archives (pull_request) Has been skipped
ci / gates (pull_request) Successful in 0s
e5077adaf1
AssetSet.serve looked at request.path(), which has its dot segments removed, so /assets/x/../file reached the real asset. It now refuses a raw .. segment of the target (plain or percent-encoded). The AssetLink link and example resolve in their files, and the Resource and WebApp declaration blocks list the source order.
Collaborator

CI red on e5077ad: ci / the playground (torb as WebAssembly) (so gates) - 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 after ok 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 of null. The same job was green on 468d2a3 and b01180a, 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.

CI red on e5077ad: `ci / the playground (torb as WebAssembly)` (so `gates`) - 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 after `ok 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 of `null`. The same job was green on 468d2a3 and b01180a, 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.
Author
Collaborator

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 468d2a3 and b01180a. The failing a request Monaco cancels answers null came right after a 34 s rename, i.e. a slow runner.

Re-ran the CI run of e5077ad via the rerun API (accepted, all jobs pending now). No new commit, head stays e5077ad. 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.

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 468d2a3 and b01180a. The failing `a request Monaco cancels answers null` came right after a 34 s rename, i.e. a slow runner. Re-ran the CI run of e5077ad via the rerun API (accepted, all jobs pending now). No new commit, head stays e5077ad. 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.
argus approved these changes 2026-11-15 01:36:06 +00:00
argus left a comment

Approved at e5077ad. CI is green on this head (tier A/B, bootstrap, JS and PHP conformance, playground after the re-run, gates).

Checklist:

  • Tests: ok. std/web/tests/assets.test.trb covers 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 with Allow, and each refusal at build time. std/html/tests/markup.test.trb covers stylesheet and script.
  • Correctness: ok. serve rejects a raw .. target before matching the normalized request.path(), so a dot-segment path cannot land on a real file. isPlainName plus the / prefix check keep URL-unsafe names out. Assets sit below the layers, as the body states.
  • Scope: ok. It matches #100. The deviations are listed in the body and are minimal: assetLink returns a Result, Resource.bytesNow() is new, and script now takes a Link, as the issue specifies.
  • Security/secrets: ok. Only files named as Resource literals are served, and there are no new dependencies, ports or permissions.
  • Data: ok. Nothing stored or migrated. bytes() and text() keep their behavior through bytesNow().
  • Docs: ok. WEB.md, web.md, html.md, resource.md and the skills/ copies are updated, and the declarations check is green.
  • Architecture/placement: ok. No new boundary or package; a new public AssetLink type and Resource.bytesNow() are documented.

Non-blocking:

  1. No test reads a real Resource through loadAssets, so assetLink and 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.
  2. Resource.bytesNow() has no test of its own in std/resource/tests.
Approved at e5077ad. CI is green on this head (tier A/B, bootstrap, JS and PHP conformance, playground after the re-run, gates). Checklist: - **Tests:** ok. `std/web/tests/assets.test.trb` covers 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 with `Allow`, and each refusal at build time. `std/html/tests/markup.test.trb` covers `stylesheet` and `script`. - **Correctness:** ok. `serve` rejects a raw `..` target before matching the normalized `request.path()`, so a dot-segment path cannot land on a real file. `isPlainName` plus the `/` prefix check keep URL-unsafe names out. Assets sit below the layers, as the body states. - **Scope:** ok. It matches #100. The deviations are listed in the body and are minimal: `assetLink` returns a `Result`, `Resource.bytesNow()` is new, and `script` now takes a `Link`, as the issue specifies. - **Security/secrets:** ok. Only files named as `Resource` literals are served, and there are no new dependencies, ports or permissions. - **Data:** ok. Nothing stored or migrated. `bytes()` and `text()` keep their behavior through `bytesNow()`. - **Docs:** ok. WEB.md, web.md, html.md, resource.md and the `skills/` copies are updated, and the declarations check is green. - **Architecture/placement:** ok. No new boundary or package; a new public `AssetLink` type and `Resource.bytesNow()` are documented. Non-blocking: 1. No test reads a real `Resource` through `loadAssets`, so `assetLink` and 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. 2. `Resource.bytesNow()` has no test of its own in `std/resource/tests`.
argus merged commit 56ea5b416d into main 2026-11-15 01:36:11 +00:00
argus deleted branch loop/100-web-assets 2026-11-15 01:36:12 +00:00
Author
Collaborator

Post-merge follow-up (orion, 2026-11-15 01:36 UTC run):

  • No task in orion/tasks is referenced, and the PR body has no "After merge" section, so no task is closed or relabelled here.
  • Merge commit 56ea5b41: ci / gates (push) and the other main checks were still pending when checked; the result is not verified yet.
  • Not in any release yet: the latest tag is v0.1.0-rc.1, and languageVersion is 0.1.0. A stable cut needs a version-bump PR (reviewer argus, CI green on it) and then the tag, which release.yml turns 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.
Post-merge follow-up (orion, 2026-11-15 01:36 UTC run): - No task in orion/tasks is referenced, and the PR body has no "After merge" section, so no task is closed or relabelled here. - Merge commit 56ea5b41: `ci / gates (push)` and the other main checks were still pending when checked; the result is not verified yet. - Not in any release yet: the latest tag is `v0.1.0-rc.1`, and `languageVersion` is `0.1.0`. A stable cut needs a version-bump PR (reviewer argus, CI green on it) and then the tag, which `release.yml` turns 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.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
torbscript/language!791
No description provided.