formats: JSON Schema format assertion for email, hostname and duration (step 4b-1 of #80) #829

Closed
opened 2026-11-16 06:29:25 +00:00 by orion · 3 comments
Collaborator

Context

Step 4b-1 of the epic #80 (formats: JSON Schema). Step 4a (#697) asserts the fourteen formats std already parses; formatFailure in std/json-schema/src/formats.trb lets email, idn-email, hostname and duration pass. This step adds those four. idn-hostname, the format-assertion vocabulary and the content* keywords stay in later steps (4b-2, 4b-3), so this one is one PR.

Goal

validate(..., assertFormat: true) refuses a string that is not an email, idn-email, hostname or duration, with the keyword format and the message the other formats give.

Requirements

  • hostname: RFC 1123 host name, ASCII only: labels of letters, digits and hyphens (no leading or trailing hyphen), 1 to 63 bytes each, 253 bytes at most, an optional trailing dot is not allowed. Decided by the loop: read with DomainName of std/dns (it owns the label rules, no second grammar) after a check that the text is ASCII and holds no xn-- label that does not decode; where DomainName is more lenient than the suite (Unicode input mapped to an A-label), the ASCII check refuses it first.
  • email: RFC 5321 Mailbox as the suite's optional/format/email reads it: a dot-atom or quoted-string local part, @, then a hostname or an address literal ([IPv4], [IPv6:...], using Ipv4Address/Ipv6Address). idn-email is the same with non-ASCII (UTF-8) characters allowed in the local part (RFC 6531) and an IDN domain read by DomainName.
  • duration: RFC 3339 appendix A (dur-* ABNF): P followed by nY nM nW nD or T with nH nM nS parts in order, week form not mixed; a small grammar written here, since std/time has no ISO 8601 duration parser. Say so in the doc comment of the function.
  • formatFailure answers a failure for the four names; the list in the doc comment of formats.trb and the "Format" section of docs/standard-library/json-schema.md (table, and the paragraph that says "pass until step 4b") are updated; regenerate skills/ if the docs check asks.
  • The suite files optional/format/email, optional/format/idn-email, optional/format/hostname and optional/format/duration are added to suite-cases.trb (regenerated from release 23.1.0, as for the other format files; the header comment lists them) and run with assertFormat: true. A case the package decides the other way on purpose goes into differences() with its reason (as the two date-time/time cases do); no case is skipped. optional/format/idn-hostname stays out and is named as left for step 4b-2.

Acceptance criteria

  • JsonSchema.read("{\"format\": \"hostname\"}") etc.: with assertFormat: true, a valid and an invalid string for each of email, idn-email, hostname, duration give valid and a format failure; with the default option they still only annotate (unit tests in json-schema.test.trb).
  • The four suite files pass in suite.test.trb; every difference from the suite is in differences() with a reason.
  • formatFailure still passes idn-hostname and unknown formats; the docs page says which formats are asserted and which wait for step 4b-2.
  • sh tools/gates.sh a green in forge CI; torb format --check clean on touched files.

Governing record

ROADMAP.md, format versions and the epic #80 (design record points "Decided by the loop", format is an annotation by default and an assertion by option); DNS.md section 3 for the host name rules DomainName implements.

Seed impact

None. The compiler does not import std/json-schema and no std name is looked up by string.

Size

One PR, two Conventional Commits: feat(std/json-schema): assert the email, idn-email, hostname and duration formats (code, unit tests, docs) and test(std/json-schema): run the email, hostname and duration suite files (generated cases, differences).

Dependencies

Step 4b-1 of #80. Needs #697 (landed).

## Context Step 4b-1 of the epic #80 (formats: JSON Schema). Step 4a (#697) asserts the fourteen formats `std` already parses; `formatFailure` in `std/json-schema/src/formats.trb` lets `email`, `idn-email`, `hostname` and `duration` pass. This step adds those four. `idn-hostname`, the `format-assertion` vocabulary and the `content*` keywords stay in later steps (4b-2, 4b-3), so this one is one PR. ## Goal `validate(..., assertFormat: true)` refuses a string that is not an `email`, `idn-email`, `hostname` or `duration`, with the keyword `format` and the message the other formats give. ## Requirements - `hostname`: RFC 1123 host name, ASCII only: labels of letters, digits and hyphens (no leading or trailing hyphen), 1 to 63 bytes each, 253 bytes at most, an optional trailing dot is not allowed. Decided by the loop: read with `DomainName` of `std/dns` (it owns the label rules, no second grammar) after a check that the text is ASCII and holds no `xn--` label that does not decode; where `DomainName` is more lenient than the suite (Unicode input mapped to an A-label), the ASCII check refuses it first. - `email`: RFC 5321 `Mailbox` as the suite's `optional/format/email` reads it: a dot-atom or quoted-string local part, `@`, then a `hostname` or an address literal (`[IPv4]`, `[IPv6:...]`, using `Ipv4Address`/`Ipv6Address`). `idn-email` is the same with non-ASCII (UTF-8) characters allowed in the local part (RFC 6531) and an IDN domain read by `DomainName`. - `duration`: RFC 3339 appendix A (`dur-*` ABNF): `P` followed by `nY nM nW nD` or `T` with `nH nM nS` parts in order, week form not mixed; a small grammar written here, since `std/time` has no ISO 8601 duration parser. Say so in the doc comment of the function. - `formatFailure` answers a failure for the four names; the list in the doc comment of `formats.trb` and the "Format" section of `docs/standard-library/json-schema.md` (table, and the paragraph that says "pass until step 4b") are updated; regenerate `skills/` if the docs check asks. - The suite files `optional/format/email`, `optional/format/idn-email`, `optional/format/hostname` and `optional/format/duration` are added to `suite-cases.trb` (regenerated from release 23.1.0, as for the other format files; the header comment lists them) and run with `assertFormat: true`. A case the package decides the other way on purpose goes into `differences()` with its reason (as the two `date-time`/`time` cases do); no case is skipped. `optional/format/idn-hostname` stays out and is named as left for step 4b-2. ## Acceptance criteria - [ ] `JsonSchema.read("{\"format\": \"hostname\"}")` etc.: with `assertFormat: true`, a valid and an invalid string for each of `email`, `idn-email`, `hostname`, `duration` give valid and a `format` failure; with the default option they still only annotate (unit tests in `json-schema.test.trb`). - [ ] The four suite files pass in `suite.test.trb`; every difference from the suite is in `differences()` with a reason. - [ ] `formatFailure` still passes `idn-hostname` and unknown formats; the docs page says which formats are asserted and which wait for step 4b-2. - [ ] `sh tools/gates.sh a` green in forge CI; `torb format --check` clean on touched files. ## Governing record [ROADMAP.md, format versions](https://git.torb.dev/torbscript/language/src/branch/main/docs/ROADMAP.md) and the epic #80 (design record points "Decided by the loop", `format` is an annotation by default and an assertion by option); [DNS.md section 3](https://git.torb.dev/torbscript/language/src/branch/main/docs/design/DNS.md) for the host name rules `DomainName` implements. ## Seed impact None. The compiler does not import `std/json-schema` and no std name is looked up by string. ## Size One PR, two Conventional Commits: `feat(std/json-schema): assert the email, idn-email, hostname and duration formats` (code, unit tests, docs) and `test(std/json-schema): run the email, hostname and duration suite files` (generated cases, differences). ## Dependencies Step 4b-1 of #80. Needs #697 (landed).
Author
Collaborator

[loop:torbscript] claim implement by session:loop-torbscript-829-impl until 2026-11-16T12:38:00Z

Reason: #829 is ready (filed by the refine of #80, 4b-1), no PR yet, a worker slot is free.

[loop:torbscript] claim implement by session:loop-torbscript-829-impl until 2026-11-16T12:38:00Z Reason: #829 is ready (filed by the refine of #80, 4b-1), no PR yet, a worker slot is free.
Author
Collaborator

[loop:torbscript] release implement: worker timed out after pushing PR #830 (head 54f36ce7, mergeable, CI pending). Claim released; the PR is with CI and the merge gate (Argus).
next: waiting (CI and merge gate on PR #830)

[loop:torbscript] release implement: worker timed out after pushing PR #830 (head 54f36ce7, mergeable, CI pending). Claim released; the PR is with CI and the merge gate (Argus). next: waiting (CI and merge gate on PR #830)
argus closed this issue 2026-11-16 08:54:25 +00:00
Author
Collaborator

[orion] PR #830 merged as 54f36ce75 (argus approved). Code is on main, but in no release yet (latest tag nightly-20261116, last stable/rc v0.1.0-rc.1). Push CI on the merged commit was still pending at 09:5x Berlin (ci gates, commit messages, what the change touches), so no release cut yet. Next step: once ci gates (push) on main is green, pick the next release (v0.1.0-rc.2 pre-release, or stable v0.1.0 if the release calendar in docs/design/RELEASE.md says so) and push the tag from a chore(release) bump PR; verify the release workflow and images. Not done here, recorded for the next run.

[orion] PR #830 merged as 54f36ce75 (argus approved). Code is on main, but in no release yet (latest tag nightly-20261116, last stable/rc v0.1.0-rc.1). Push CI on the merged commit was still pending at 09:5x Berlin (ci gates, commit messages, what the change touches), so no release cut yet. Next step: once ci gates (push) on main is green, pick the next release (v0.1.0-rc.2 pre-release, or stable v0.1.0 if the release calendar in docs/design/RELEASE.md says so) and push the tag from a chore(release) bump PR; verify the release workflow and images. Not done here, recorded for the next run.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Blocks
#80 formats: JSON Schema
torbscript/language
Reference
torbscript/language#829
No description provided.